a stupid little program

CAVNESS@utxvms.cc.utexas.edu
Date: 04/30/94


#!/bin/sh

# bunch v1.0 ... a Bourne Shell Script program for UNIX... made to fit
# almost any UNIX-style architecture including LINUX, 386BSD, ULTRIX, etc etc
#
#
# I put no burdons of copyright on this (how could I? :) )...I only ask that
# you give me a little note of thanks if this is actually helpful to you.
#
# I have ultra-commented this program for one main reason: I like for beginners
# to alter it just as much as me. :) Since I'm only a beginner in shell script
# coding myself, it may be totally useless :) but here's what it does anyways.
#
# 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. SO...I made this little program.
#
# 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.
# example:
# files: ideas ideas.old ...you want to make a file called ideas.fix that has
#        the info from BOTH files.
# you COULD do it the 3-line way, which isn't too hard...but it's quite time
# consuming...and there's the chance for a messup :) here, there isn't.
# bunch -i ideas old fix
# 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. :)
#
# You can, of course, cut all of this commenting out as it's really unneeded :)
# this is a VERY simple program but it has made MY life much easier. :)
# i've tried to idiotproof as much of it as I can but there are things I'm
# sure to have missed...so find them for me! :) Thanks.
# 
# 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, sleepy.cc.utexas.edu 9332




# two semisorta constants...just help messages to change at will
# CALLHELP just shows what to do if you want more information about bunch
# FORM is the actual format of bunch
#
CALLHELP="Type bunch -help if you want information on how to use this program."
readonly
FORM="bunch <-i bu t help> <old suffix> <new suffix>"
readonly


# the function printerror gives a little warning message
# to the user telling them how to use the program.
printerror()
{
  echo On program: bunch
  echo
  echo Wrong format...
  echo 
  echo The correct format follows:
  echo "$FORM" 
  echo
  echo "$CALLHELP"
  exit
}

printnofile()
{ 
  echo This means something is majorly wrong with your mud.
  echo You need to immediately get a file named $TODO up or your MUD will 
  echo have real problems!
}


# if there's no initial argument, call function printerror (above)
if [ ! "$1" ]
  then
     printerror
fi


# if there is no second argument and the first argument isn't -help, 
# call function printerror (above)
if [ "$1" != "-help" ]
then
  if [ ! "$2" ]
    then
      printerror
  fi
fi


#if there is no third argument and the first argument isn't -help,
#call function printerror (above)
if [ "$1" != "-help" ]
then 
  if [ ! "$3" ]
     then
        printerror
   fi
fi

#if there IS a fourth argument and the first argument isn't -help,
#call function printerror (above)
#(this keeps extraneous information from interfering with the program)
if [ "$1" != "-help" ]
   then
    if [ "$4" ]
      then
        printerror
    fi
fi


#if the first argument is -help, then print the help stuffs
if [ "$1" = "-help" ]
  then
    echo Format:
    echo "$FORM"
    echo "[-ibt] stands for (use ONLY ONE):"
    echo "-i    ideas"
    echo "-bu    bugs"
    echo "-t    typos"
    echo "-help  this info :)"
    echo "[old suffix] is the current old suffix of the file."
    echo "[new suffix] is anything you want the .after to be"
    echo WARNING! This CANNOT be one of the suffixes already used.
    echo WARNING! You must use this in the directory with the ideas, bugs, and 
    echo typos working directory.
    exit
elif [ "$1" = "-i" ] 
    then
# set the variable TODO to "ideas"
    if [ -f "ideas" ]
      then 
        TODO=ideas
      else
         echo Bunch: no file ideas!
         printnofile
         exit
    fi
elif [ "$1" = "-bu" ]
    then
#set the variable TODO to "bugs"
    if [ -f "bugs" ]
      then 
        TODO=bugs
      else
         echo Bunch: no file bugs!
         exit
    fi
       
elif [ "$1" = "-t" ]
    then 
#set the variable TODO to "typos"
    if [ -f "typos" ]
      then 
        TODO=typos
      else
         echo Bunch: no file typos!
         exit
    fi
else 
   printerror
fi 
    
#set the second argument to be the old suffix
O_SUFFIX="$2"
#set the third argument to be the new suffix
N_SUFFIX="$3"

#if the old suffix and the new suffix are the same, print an error messgage
#this is because the program CAT would write over the old one if you set it
#as the destination file...thus getting rid of ALL the information in your
#old file.
if [ "$O_SUFFIX" = "$N_SUFFIX" ]
  then
     echo "$O_SUFFIX and $N_SUFFIX are the same thing!"
     echo "You must supply TWO DIFFERENT suffixes, or the damn thing"
     echo "will majorly mess up :)"
     echo "Try again. :P"
     exit
fi
#this neat little trick basically sets the command line variables to 
#the output from ls...a good example would be this:
#ls -l ideas
#the information it prints out would be:
#permission num links   user  disk usage <last time changed>   <file>
#-rw-------    1      nevarez    171     Apr 29 22:11           ideas
# the variables will now be:
# $1 = -rw-------
# $2 = 1
# $3 = nevarez
# $4 = 171
#etc etc... all I really need is the disk usage tho... so...

set -- `ls -l "$TODO" 2> /dev/null`
# if the original file is empty, then give an error message and exit the system
if [ "$4" = "0" ]
  then
    echo "Bunch doesn't need to be run! This file has already been"
    echo "taken care of and is as empty as can be. :)"
    echo "Program: [bunch] exiting..."
    exit
fi

set -- `ls -l "$TODO.$O_SUFFIX" 2> /dev/null`
if [ "$4" = "0" ]
  then
    echo "Bunch doesn't need to be run! The older file doesn't have anything"
    echo "in it. Just delete the older file. :)"
    echo "Thanks for using Bunch v1.0"
    exit
fi

#print a little message letting them know that YES it is working :)
echo "Starting program...editing $TODO"

#add file1 and file2 and put them in file3
cat "$TODO" "$TODO.$O_SUFFIX" > "$TODO.$N_SUFFIX" 2> /dev/null

#remove both file1 and file2 (to clear file1)
rm "$TODO" "$TODO.$O_SUFFIX" 2> /dev/null

#just put an empty file with file1's name in it
touch "$TODO" 2> /dev/null

#HALLELIEUA WE'RE DONE!
exit


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cavness@utxvms.cc.utexas.edu        |       The Great Holy Star Goat
Kenneth G. Cavness                  |          is with all of us,
"Supreme Diva"                      |         braised be Its name.
"I'm pro-choice--please don't       |
shoot me in the back."              |     Braise the name of Our Lard!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    



This archive was generated by hypermail 2b30 : 12/07/00 PST