From: Kenneth G. Cavness <kcavness@stargoat.proxicom.com>
To: kcavness@proxicom.com <kcavness@proxicom.com>
Date: Fri, 22 Aug 1997 17:23:29 -0400

#!/usr/bin/perl

#bunch v2.0 ... a Perl shell script program made to fit most any UNIX-style
#or even Win style architecture with perl.

# I put no burdens of copyright on this--it's too simplistic....I only ask that
# you give me a little note of thanks if this is actually helpful to you.

# Oftentimes I want to edit the IDEAS, BUGS or TYPOS files in the 
# circle/lib/text portion of the Circle2.0 code... but you can't do that
# directly while the MUD is running or you'll run into file-sharing violations
# that could keep any modifications you make(line deletions etc) from going
# through.

# say you have two files for ideas... ideas.old and ideas. You can't modify
# ideas conveniently while the MUD is running for the above reasons...so
# you use bunch to put these two files together and reset the ideas file.

# bunch defaults to the "ideas" file and defaults to the extension "fix".
# if you don't like these defaults, search for "default" in this file.

# usage:
# bunch [-[-]ibt] [extension]
# example:
# bunch -i fix
# or just
# bunch
# to get the identical behavior.

# bunch -b old
# will either create a file called 'bugs.old' and put "bugs" in it, clearing
# "bugs", or will print information regarding it.

# bunch will concatenate ideas and ideas.old, and put it in the file ideas.fix
# it will also make sure that you aren't trying to put ideas.old and ideas
# in ideas.old...because that causes major problems.
# it also won't run if ideas is already empty...this indicates that the file
# bunch has already been run OR that it doesn't need to be run. :)

# BTW: YES, I know I could have chosen to allow this to work for any file VERY
# easily (perhaps easier than this)...but I think this is an easier and faster
# way for the user. You can see how I add switches...just add ones of your own
# if'n ya wanna :)


# Kenneth Cavness, Questor of StrangeMUD, strangemud.org 9332

$CALLHELP="Type bunch -help if you want information on how to use this program.";
$FORM="bunch <-i b t help> [new suffix]";
$defaultext = "fix";
$defaulttodo = "ideas";

sub printError {
   die <<"END_ERROR";
On program: $0 -- Wrong format

The correct format follows:
$FORM

$CALLHELP

END_ERROR
}

sub printNoFile {
   local($exitWith) = @_;
   die <<"END_ERROR";
You're missing file $todo! Get it up before your MUD has some real problems.
$exitWith
END_ERROR
}

sub printHelp {
    die <<"END_HELP";
Format:
$FORM
[-ibt] stands for (use ONLY ONE):
-i\tideas
-b\tbugs
-t\ttypos
-help\tthis information
[new suffix]\tanything you want the new extension to be -- defaults to "fix"

WARNING! This CANNOT be one of the suffixes already used.
WARNING! You must use this in the directory with the ideas, bugs, and
typos working directory.

END_HELP
}

&printHelp if($ARGV[0] =~ /^-+(h|he|hel|help)$/);
&printError if( $ARGV[2] );

if($ARGV[0] =~ /^-/) {
    $todo = "ideas" if($ARGV[0] =~ /^-+(i|id|ide|idea|ideas)$/);
    $todo = "bugs"  if($ARGV[0] =~ /^-+(b|bu|bug|bugs)$/);
    $todo = "typos" if($ARGV[0] =~ /^-+(t|ty|typ|typo|typos)$/);
}

!$todo && ($todo = $defaulttodo);

!$ARGV[1] && ($ARGV[1] = $ARGV[0]);

open(TODO, $todo) || &printNoFile("$0: No file $todo!");

$new_suffix = $ARGV[1] ? $ARGV[1] : $defaultext;

if(-z $todo) {
   die <<"END_ERROR";
Bunch doesn't need to be run! This file has
already been taken care of and is empty.
Program: $0 exiting...
END_ERROR
}

$newfile = "${todo}.${new_suffix}";

if( !(-e $newfile) || (-z $newfile) ) {
  open(PUTINTO, "> $newfile") || die("Can't open file: $newfile\n");
} else {
  open(PUTINTO, ">> $newfile") || die("Can't open file: $oldfile\n");
}

while(<TODO>) {
    print PUTINTO $_;
}

close(TODO);
close(PUTINTO);

unlink $todo || warn("Can't delete file: $todo\n");
open(TODO, "> $todo") || warn("Can't touch file: $todo\n");
close(TODO);
