: "shed by Dan Martin (DRM/CTG) Mon Aug 15 07:41:37 CDT 1994" # A small, but hard working, SHell EDitor # Comments & Suggestions: drmartin@tyrell.net -OR- Compuserve: 75046,1331 # Version 1.4 - 07/14/96: Corrects a "quoting" bug in Chg command. # Version 1.3 - 08/28/95: Provides Bak (Back-Up) command # Version 1.2 - 07/25/95: Provides Get (read-in file) Command # Version 1.1 - Provides Range-Delete VER=1.4 # TEMP FILES: sf1="/tmp/shedA$$"; # file of [ab]User's EDITED textual data sf2="/tmp/shedB$$"; # shed scratch-file sf3=$1 # F3 = User's Save-To File; $1 = Command Line Argument #### BEGIN FUNCTION DEFINITION #### eraser() { rm -f $sf1 $sf2 # DON'T remove $sf3: that's the [ab]User's Original! } # EOF eraser() trap 'echo "\n PROGRAM \"$0\" CANCELLED!!\n"; eraser; sleep 2; exit 1' 2 lister() { # Required Argument: $1 = Header Blabbery clear echo "$1" if [ -s "$sf1" ] then pr -n" "2 -t $sf1 | pg -f -p " = Next Screen, = Quit " -es else echo "\n File \"$sf1\" is empty!\n" fi } # EOF lister() helper() { clear cat << MEOW | pg -f -p " = Next Screen, = Quit " -es ==================< HELP FOR "shed" LINE-EDITOR Ver $VER >================== FEATURES: - tedious with long files. ========= - can't Word-Wrap. Proper line-length is up to you. - can't Join adjacent lines, or Break one line into two. - leading spaces are ignored during Add, Chg, and Ins. - any change requires that an entire line be retyped. - reveals major deficits if keys are used. - easy to use: just READ THE SCREEN! COMMANDS: ========= dd = ADD new lines to end of Current File: "$sf3". End every line with the key (no word-wrap). Enter "stop" or "." on any new line to cancel Add. ak = BACKUP edited contents of "$sf3" into another File. hg = CHANGE the contents of any one line. el = DELETE One line, or a Range of lines. Enter Line-Range as: #,# Example: 12,27 deletes lines 12 through 27 inclusive. et = GET another file and read it into "$sf3". elp = HELP You're reading it right now. ns = INSERT one new line (only) between two existing lines. st = LIST all lines now in "$sf3". ew = NEW file to edit, with optional prior Save.

rt = PRINT "$sf3" using printer "$LPDEST" uit = QUIT (exit) gracefully, with optional prior Save. av = SAVE edited contents of "$sf3". >>>>>>> To activate any command above, type its "letter" <<<<<<< >>>>>>> (e.g., A for dd) followed by the key. <<<<<<< * PLEASE ENTER YOUR CHOICE OF COMMANDS (A B C D G H I L N P Q S) NOW: MEOW } # EOF helper() fileit() { # Argument: $1 = blabbery echo [ -z "$1" ] && yak=" Enter the name of the File to Edit: " || yak="$1" FOK=NOK while [ "$FOK" = "NOK" ] do fiel="" while [ -z "$fiel" ] do echo "${yak}\c" read fiel done if [ -d "$fiel" ] then echo "\n ERROR: \"$fiel\" is a directory: cannot edit!\n" elif [ "`basename $fiel`" = "unix" ] then echo "\n PERVERT!! DON'T EVER TOUCH MY \"$fiel\"!!\n" elif [ -x "$fiel" ] then echo "\n ERROR: File \"$fiel\" is a program file and cannot be edited!\n" else [ ! -s "$fiel" ] && echo "\n ALERT: FILE \"$fiel\" IS EMPTY.\n" FOK="OK" fi done } # EOF fileit() prit() { while [ -z "$LPDEST" ] # [ab]User has no default printer do lpstat -a | cut -f1 -d' ' | sort | pr -6to8 echo "\n Enter a Printer-name from the list above: \c" read LPDEST done [ -s "$sf1" -a -r "$sf1" ] && /usr/bin/lp -d $LPDEST $sf1 } # EOF prit saver() { # cp $sf1 $sf3 # old, simple way. New way strips Esc and other stuff cat $sf1 | tr -d '\033' | tr -d ' ' | tr -d ' ' >$sf3 if [ "$?" = "0" ] then echo "\n All Modifications to File \"$sf3\" have been saved.\n" else echo "\n There was a problem - Modifications to File \"$sf3\" NOT saved!\n" fi sleep 1 } # EOF saver() adder() { if [ -s "$sf1" ] then lct=`awk 'END {printf("%d", NR)}' $sf1` # Line-Count so far else lct=0 fi [ "$lct" -lt "10" ] && spc=" " [ "$lct" -ge "9" ] && spc=" " # tput clear echo "\n ADDING LINES TO END OF FILE \"$sf3\":" echo "\n${spc}*TYPOS: Use ONLY [backspace] key for corrections: NO ARROWS!!*" echo "${spc}*Enter STOP at the BEGINNING of any line to finish your Notes*" echo "${spc}[------------------------------------------------------------]" doit="OK" while [ "$doit" = "OK" ] do lct=`expr $lct + 1` echo "$lct \c> " # Line-Entry prompt read liner case "$liner" in .|stop|STOP) doit=STOP;; *) echo "$liner" >>$sf1;; # append line to file esac done } # EOF adder() chger() { echo lino="" while [ -z "$lino" ] do echo " ENTER LINE-NUMBER TO CHANGE: \c" read lino done mline=`sed -n ${lino}p $sf1` echo "\n Retype all of Line ${lino} exactly as you wish it to appear.\n" [ "$lino" -lt "10" ] && spc=" " [ "$lino" -ge "9" ] && spc=" " echo " ${lino} $mline" echo "${spc}[------------------------------------------------------------]" echo " ${lino} \c" read modln awk "{if (NR == $lino) print nuli else print \$0}" nuli="$modln" $sf1 > $sf2 mv $sf2 $sf1 echo "\n Line ${lino} has been changed.\n" } # EOF chger() deler() { echo rag="" while [ -z "$rag" ] do echo " Enter Line-Number or Line-Range to DELETE (# or #,#): \c" read rag done sed "${rag}d" $sf1 >$sf2 if [ "$?" = 0 ] # SUCCESS (sed was happy) then mv $sf2 $sf1 echo "\n Line Number(s) \"$rag\" Deleted!\n" else echo "\n ERROR IN LINE ENTRY \"$rag\". NO LINES DELETED.\n" fi } # EOF deler() getit() { FOK="NOK" fileit ' FILE TO "GET" (i.e., path to the file to be read-in): ' echo "\n File \"$fiel\" will be inserted into \"$sf3\" AFTER Line # chosen.\n" ll=`awk 'END {print NR}' $sf1` lino="" while [ -z "$lino" ] do echo " LINE-NUMBER (0 thru $ll) FOR FILE-INSERTION: \c" read lino done awk '{if (NR <= lin) print $0}' lin="$lino" $sf1 >$sf2 cat $fiel >>$sf2 awk '{if (NR > lin) print $0}' lin="$lino" $sf1 >>$sf2 cp $sf2 $sf1 echo "\n File \"$fiel\" has been read into Current File \"$sf3\".\n" } # EOF getit() inner() { echo "\n The New Line will be inserted AFTER the Line Number entered below:\n" lino="" while [ -z "$lino" ] do echo " LINE-NUMBER FOR INSERTION: \c" read lino done nuno=`expr $lino + 1` mline=`sed -n ${lino}p $sf1` [ "$lino" -lt "10" ] && spc=" " [ "$lino" -ge "9" ] && spc=" " echo " ${lino} $mline" echo "${spc} [------------------------------------------------------------]" echo " ${nuno} \c" read newln awk "{if (NR == $nuno) print \"$newln\" print \$0}" $sf1 > $sf2 mv $sf2 $sf1 echo "\n New Line ${nuno} has been inserted.\n" } # EOF inner() rescue() { if [ "$SAVE_ME" = "Y" ] then echo "\n WARNING: Changes to file \"$sf3\" HAVE NOT BEEN SAVED!!!\n" savit="" while [ -z "$savit" ] do echo " SAVE THEM NOW? (Y/N): \c" read savit done case "$savit" in n|N) echo "\n Changes to file \"$sf3\" NOT SAVED\n"; sleep 1 ;; *) saver ;; esac fi } # EOF rescue() note() { # Required Argument: $1 = User Info string echo "\n NOTE: $1" } # EOF note() sugg="/tmp/`logname`.bak" [ "$sugg" = "$sf3" ] && sugg="/tmp/bak_`logname`" aorr="A" # Append Current File to Back-Up File if it exists. yak="APPENDED WITH THOSE OF" bakit() { echo "\nALERT: About to Back-Up (i.e., write) edited contents of \"$sf3\"." OK="NOK" while [ "$OK" = "NOK" ] do echo "\n A suggested Back-Up File Name is: $sugg\n" uuh="" while [ -z "$uuh" ] do echo ' Enter the full Back-Up File Name: \c' read uuh done if [ "$sf3" = "$uuh" ] then note " Back-Up File Name can not be \"$sf3\". Please try again." continue fi htap=`dirname $uuh` if [ "$htap" = "/" ] then note "Back-Up File cannot reside in the root directory! Please try again." continue elif [ "$htap" = "." ] then if [ -w "`pwd`" ] then OK="SOK" note "Back-Up File will reside in Current Directory: \"`pwd`\"." else note " Your Login cannot write into the Current Directory:" echo " \"`pwd`\". Please try again." continue fi fi if [ ! -s "$uuh" ] then note "Back-Up file chosen (\"$uuh\") is a New File," yak="COPIED-IN FROM" aorr="R" fi OK="SOK" sugg="$uuh" done # end while [ "$OK" = "NOK" ] if [ -s "$uuh" ] then note "Back-Up file chosen (\"$uuh\") Exists:" ls -l $uuh echo dawk="" while [ -z "$dawk" ] do echo "ppend or eplace it? (A/R): \c" read dawk done case "$dawk" in r|R) aorr="R"; yak="REPLACED BY THOSE OF" ;; *) aorr="A"; yak="APPENDED WITH THOSE OF" ;; esac fi [ "$aorr" = "A" ] && cat $sf1 >>$uuh || cp $sf1 $uuh if [ "$?" = "0" ] then echo "\nCONTENTS OF \"$uuh\" HAVE BEEN $yak \"$sf3\".\n" else echo "\nWARNING: The Back-Up of \"$sf1\" to \"$uuh\" FAILED!\n" fi OK="NOK" } # EOF bakit() #### END ALL FUNCTION DEFINITIONS #### #### CHECK & INITIALIZE EDIT-FILE #### if [ -z "$1" ] then fileit sf3="$fiel" else sf3=$1 fi if [ -d "$sf3" ] then echo "\n ERROR: \"$1\" is a directory: cannot edit!\n" exit 1 elif [ "`basename $sf3`" = "unix" ] then echo "\n PERVERT!! DON'T EVER TOUCH MY \"$sf3\"!!\n" exit 1 elif [ -x "$sf3" ] then echo "\n ERROR: File \"$1\" is a program file and cannot be edited!\n" exit 1 fi cp $sf3 $sf1 2>/dev/null # We'll Edit $sf1 and Save to $sf3 # Any additional argument(s) to shed cause the file to be Listed [ ! -z "$2" ] && lister " *** CONTENTS OF FILE \"$sf3\": ***" # List File [ ! -f "$sf1" ] && >$sf1 echo #### COMMAND-LOOP BEGINS HERE #### while true do duh="" while [ -z "$duh" ] do # Command Line: echo "\"$sf3\": Add Bak Chg Del Get Help Ins Lst New Prt Quit Sav: \c" read duh done case "$duh" in a|A) SAVE_ME="Y"; adder ;; b|B) bakit ;; c|C) SAVE_ME="Y"; chger ;; d|D) SAVE_ME="Y"; deler ;; g|G) SAVE_ME="Y"; getit ;; i|I) SAVE_ME="Y"; inner ;; l|L) lister " *** CONTENTS OF FILE \"$sf3\": ***" ;; n|N) rescue; FOK="NOK"; sf3="" while [ "$FOK" = "NOK" ] do fileit ' ENTER THE [PATH]NAME OF THE NEW FILE YOU WISH TO EDIT: ' done sf3="$fiel" if [ -s "$sf3" ] then cp $sf3 $sf1 else >$sf1 fi [ "$sugg" = "$sf3" ] && sugg="/tmp/bak_`logname`" SAVE_ME="N"; lister " *** CONTENTS OF NEW FILE \"$sf3\": ***" ;; p|P) prit ;; 0|e|E|q|Q) rescue; eraser; break ;; s|S) SAVE_ME="N"; saver ;; *) helper ;; esac done #### End of Command-Loop #### # EOF shed