home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / blachman / part02 < prev    next >
Internet Message Format  |  1989-02-03  |  56KB

  1. Path: xanth!mcnc!gatech!cwjcc!hal!ncoast!allbery
  2. From: karl@cs.duke.edu (Karl Ramm)
  3. Newsgroups: comp.sources.misc
  4. Subject: v04i041: collected sh/csh/awk/etc. goodies (2 of 3)
  5. Message-ID: <8808281546.AA09320@romeo.cs.duke.edu>
  6. Date: 28 Aug 88 15:46:24 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: karl@cs.duke.edu (Karl Ramm)
  9. Lines: 2604
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 4, Issue 41
  13. Submitted-by: "Karl Ramm" <karl@cs.duke.edu>
  14. Archive-name: blachman/Part2
  15.  
  16. From: Nancy Blachman <decvax!decwrl!sun!idi!resonex!nancy@Ucb-Vax.ARPA>
  17. To: net.unix,net.unix-wizards,net.sources
  18. Subject: Actual Tricks, shells, csh aliases and the like, 2 of 3
  19. Date: 16 Oct 84 21:22:55 GMT
  20. Organization: Resonex Inc., Sunnyvale, CA
  21.  
  22. > [Know anybody with a GREAT .login or .cshrc?]
  23.  
  24. > I'm interested in collecting the little tricks, shell scripts, awk
  25. > hacks, csh aliases, and such that people have built to make their daily
  26. > life a little easier or more automatic.  Being a fairly new system
  27. > administrator I don't have the big toolbox that years of messing around
  28. > will leave you with.  If you have any hacks you're proud of (or that
  29. > you aren't proud of, but which work anyway), and you're willing to make
  30. > them public, mail them to me.  I'll collect, collate, shuffle, sort,
  31. > munge, judge, select and discard them and then "summarize to the net".
  32.  
  33. This article focuses shell scripts I received in response to my solicitation.  
  34. The first article of this series concentrates on  aliases, and .cshrc and 
  35. .login files. The third article centers on C programs and awk scripts.
  36.  
  37. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  38. > Nancy Blachman {allegra,hplabs,ihnp4,sun}!resonex!nancy  (408)720 8600 x37 <
  39. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/
  40.  
  41. ::::::::::::::
  42. shells/1
  43. ::::::::::::::
  44. Date: Thu, 13 Sep 84 12:49:57 edt
  45. From: allegra!vax135!cornell!tesla!mac (Michael Mc Namara)
  46. To: cornell!vax135!houxm!mhuxl!ulysses!allegra!resonex!nancy
  47. Subject: Cute cshell - sh scripts
  48.  
  49.     If your are like most UNIX systems, you have a plethora of different
  50. terminals that  your system  is supposed to support.  Sure, with termcap
  51. and terminfo, and programs written to use them, the interface gets easier.
  52. If you only ever login to one particular terminal, you can 
  53.  
  54. set term = "vt131"
  55.  
  56. or 
  57.  
  58. TERM=vt131
  59. export TERM
  60.  
  61. in your .login or .profile.
  62.  
  63. But what if you,  or some of your users,  drift  around using different
  64. terminal types-- You have a terminal room with many different terminals.
  65.  
  66. Here is a set of shell scripts & C programs that use the "echo terminal
  67. type" command that many terminals support, to do automatic terminal type
  68. identification and setting:  (of course I've only made it work for  the 
  69. terminals we have here at Cornell, and some day I should write more of it
  70. in C...)
  71.  
  72.     This one is written for cshell:
  73.  
  74. ##########################################
  75. #    Identify and set terminal type (csh)#
  76. ##########################################
  77. set noglob
  78. echo Please wait...
  79. stty cbreak -echo
  80. # this sequence will cause all terminals we have to echo something
  81. # except for adm's; those users are told to hit 'a' when they see
  82. # please wait
  83. echo ' CZ[c'
  84. sleep 1      
  85. # this calls a c program to grab the id string from the terminal 
  86. # program is included later...
  87. set type = `/usr/new/rin.login`
  88. stty -cbreak echo new crt
  89. #########################
  90. # the or in the vt100 terminal type is because vt100's respond
  91. # to both ^[Z and ^[[c, but DEC threatens to eliminate one of 
  92. # the responces (I forget which).. The extra stty back you see
  93. # with DG terminals (Data General) is because their backspace is
  94. # ^Y instead of ^H ( Home on DG terminals) This involves a modification
  95. # of stty, which you would care about only if you have them--Write to me.
  96. ##################
  97. if ( $type == "[?1;0c" || $type == "[?1;0c[?1;0c" ) then
  98.      set term = vt100
  99.      echo "VT101"                            
  100. else if ( $type == "[?1;2c" || $type == "[?1;2c[?1;2c" ) then
  101.      set term = vt100
  102.      echo "VT100"
  103. else if ( $type == "[?1;11c[?1;11c") then
  104.      set term = ct500
  105.      echo "[7mCIT - 500[m"
  106. else if ( $type == "[?12;5;0;102c" ) then
  107.      set term = vt100
  108.      echo "VT125"
  109. else if ($type == "[?1;2c[?1;2c") then
  110.      set term = vt100
  111.      echo "VT100, with Selenar Graphics"
  112. else if ( $type == "o#\!R" ) then
  113.      set term = dg200
  114.      stty stop undef start undef back  
  115.      echo "DDG200E"
  116. else if ( $type == "o#'C3" ) then
  117.      set term = dg450
  118.      stty back  
  119.      echo "FS11BFS00 DATA GENERAL DASHER D450" 
  120. else if ( $type == "o#'K3" ) then 
  121.      set term = dg450
  122.      stty back  
  123.      echo "FS11BFS00 DATA GENERAL DASHER D450" 
  124. else if ( $type == "/K" ) then
  125.      set term = vt52
  126.      echo "Visual 50"
  127. else if ( $type =~ "\\4*" ) then
  128.      set term = hp2621          
  129.      echo HP2621
  130. else if ( $type =~ "a" ) then
  131.      set term = adm3a
  132.      echo "adm3a"
  133. else if ($type == "50" ) then
  134.      set term = w50
  135.      echo "WYSE50"
  136. else
  137. # Ask user for terminal type -- for some reason the above didn't work
  138. set no_name_yet=1
  139. set no_name_yet = 1;
  140. while( $no_name_yet )
  141.    echo -n "Please enter terminal type (hit return for menu) "
  142.    set ttyname = ($< );
  143.    switch( $ttyname )
  144.    case d450:
  145.    case dg450:
  146.       set term=dg450;
  147.       stty back 
  148.       set no_name_yet = 0;
  149.       breaksw;
  150.    case vt100:
  151.       set term=vt100;
  152.       set no_name_yet = 0;
  153.       breaksw;
  154.    case v50:
  155.    case vt52:
  156.       set term=vt52;
  157.       set no_name_yet = 0;
  158.       breaksw;
  159.    case hp2621:
  160.    case hp:
  161.       set term=hp2621;
  162.       set no_name_yet = 0;
  163.       breaksw;
  164.    case wyse50:
  165.       set term=w100;
  166.       set no_name_yet = 0;
  167.       breaksw;
  168.    case adm5:
  169.       set term=adm5;  
  170.       set no_name_yet = 0;
  171.       breaksw;
  172.    case adm3+:                 
  173.    case adm3:
  174.    case adm3a:
  175.       set term=adm3+;
  176.       set no_name_yet = 0;
  177.    case d200:
  178.    case dg200:
  179.       set term=dg200;
  180.       stty stop undef start undef back ;
  181.       set no_name_yet = 0;
  182.       breaksw;
  183.    case other:
  184.       echo -n "Enter terminal name: "
  185.       set term=($< );
  186.       set no_name_yet = 0;
  187.       breaksw;
  188.    case '':
  189.       echo Terminal abbreviations are:
  190.       echo "Dasher 450 : dg450"
  191.       echo "Dasher 200 : dg200"
  192.       echo "Visual 50  : v50"
  193.       echo "VT100      : vt100"
  194.       echo "HP 2621    : hp2621"
  195.       echo "ADM5       : adm5"
  196.       echo "ADM3+      : adm3+"
  197.       echo "Use 'other' to specify terminals not on this menu"
  198.       breaksw;
  199.    default:
  200.       echo "I didn't understand that. Hit return for a menu."
  201.    endsw
  202. end
  203. unset no_name_yet
  204. unset ttyname
  205. endif
  206. stty -cbreak
  207. stty echo
  208. unset noglob
  209.  
  210. Ok, This one is used for Bourne shell lovers:  (I used /bin/test because
  211. one user had an executable file called test somewhere in his path ahead
  212. of where this program lived...That one took days to track down...)
  213.  
  214.  
  215. echo "Please Wait..."
  216. stty start  stop   crt new back  -echo cbreak
  217. echo ' CZ[c'
  218. sleep 1
  219. TYPE=`/usr/new/rin.login`
  220. stty echo -cbreak
  221. if ( /bin/test \( $TYPE = "[?1;0c" \) -o \( $TYPE = "[?1;0c[?1;0c" \) ) then
  222.      TERM=vt100
  223.      echo "[7mVT101[m" 
  224. elif ( /bin/test \( $TYPE = "[?1;2c" \) -o \( $TYPE = "[?1;2c[?1;2c" \)  ) then
  225.      TERM=vt100
  226.      echo "#3[7mVT100[m"
  227.      echo "#4?[7mVT100[m"
  228. elif ( /bin/test  $TYPE = "[?1;11c[?1;11c") then
  229.      TERM=ct500
  230.      echo "CT 500"
  231. elif ( /bin/test  $TYPE = "o#!R" ) then
  232.      TERM=dg200
  233.      stty stop undef
  234.      stty start undef
  235.      stty crt
  236.      stty back 
  237.      echo "D DATA GENERAL DASHER D200E"
  238. elif ( /bin/test $TYPE = "o#'C3" )  then
  239.      TERM=dg450
  240.      stty crt   
  241.      stty back 
  242.      echo "FS11BFS00 DATA GENERAL DASHER D450"
  243. elif ( /bin/test $TYPE = "/K" ) then
  244.      TERM=vt52
  245.      echo "UVisual 50T"
  246. elif ( /bin/test $TYPE = "50" ) then
  247.      TERM=w50
  248.      clear
  249.      echo "WYSE 50"
  250. elif ( /bin/test $TYPE = "\4088000" ) then
  251.      TERM=hp2621
  252.      echo HP2621
  253. elif ( /bin/test $TYPE = "a" ) then
  254.      TERM=adm3a
  255.      echo ADM3a
  256. else
  257.      stty start 
  258.      stty stop  
  259.      stty new crt
  260.      set no_name_yet=1
  261. echo
  262. while ($no_name_yet) do {
  263.   echo
  264.   echo Which terminal do you have?
  265.   echo       Hit return for a menu.
  266.   read INP
  267.   case $INP
  268.     in
  269. 100 | v | vt100) {
  270.                   TERM=vt100
  271.                   break
  272.              } ;;
  273. adm5)            {
  274.                  TERM=adm5
  275.                  break
  276.              } ;;
  277. adm3+)           {
  278.                  TERM=adm3+
  279.                  break
  280.              } ;;
  281. 450 | dg450 | d450)  {
  282.                   TERM=dg450
  283.                   stty back 
  284.                   break
  285.              } ;;
  286. 200 | dg200 | d200)  {
  287.                   TERM=dg200
  288.                   stty stop undef
  289.                   stty start undef
  290.                   stty back 
  291.                   break
  292.              }  ;;
  293.  50 | vt52 | v50)   { 
  294.                   TERM=vt52
  295.                   break
  296.              } ;;
  297.  2621 | hp2621 | hp) {
  298.                   TERM=hp2621
  299.                   break
  300.              } ;;
  301.       other) {
  302.                   echo -n Enter terminal name:
  303.                   read tname
  304.                   TERM=$tname
  305.                   break
  306.              } ;;
  307.  ''|?|help)  {    echo Terminal abbreviations are:
  308.                   echo 
  309.                   echo Dasher 450:  dg450
  310.                   echo Dasher 200:  dg200
  311.                   echo Visual  50:  vt52
  312.                   echo VT100     :  vt100
  313.                   echo HP 2621   :  hp2621
  314.                   echo ADM3+     :  adm3+
  315.                   echo ADM5      :  adm5
  316.                   echo "Use 'other' to specify other terminals."
  317.                   echo
  318.              } ;;
  319.         * )  {   echo "I did not understand that."
  320.              } ;;
  321.   esac
  322.   }
  323. done
  324. fi
  325. export TERM
  326.  
  327. *********
  328. And here is the c program that read's in the terminal ID string:
  329.  
  330.  
  331. /* rin -- read in a char string which may not be terminated */
  332. char buf[256];
  333. int n;
  334. main ()
  335. {
  336. n = read(0,buf,256);
  337. write(1,buf,n);
  338. printf("\n");
  339. }
  340.  
  341. ***************
  342.  
  343.  
  344.         Use them, abuse them.  Of course you have to paw through
  345. your terminal manuanls to discover what (if any) string they respond to,
  346. and test for the response accordingly...
  347.  
  348.                                         ---MAC
  349.  
  350.  
  351.  
  352. ::::::::::::::
  353. shells/2
  354. ::::::::::::::
  355. From: hplabs!azure!billp
  356. To: tektronix!hplabs!resonex!nancy
  357. Date: Thursday, 13 Sep 84 09:23:49 PDT
  358. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  359.  
  360. Here are some that I like and use a lot.  'del' and 'undelete' are just two
  361. links to the same file.  This way if somebody copies one, they get the
  362. other too
  363. -------------------------------------------------------------------------------
  364. ::::::::::::::
  365. : mv
  366. ::::::::::::::
  367. : 'prompts if the destination file already exists'
  368. /bin/mv -i $*
  369. -------------------------------------------------------------------------------
  370. ::::::::::::::
  371. : cp
  372. ::::::::::::::
  373. : 'prompts if the destination file already exists'
  374. /bin/cp -i $*
  375. -------------------------------------------------------------------------------
  376. ::::::::::::::
  377. : del, undelete
  378. ::::::::::::::
  379. : '"del" throws files into the waste basket'
  380. : 'files preceded by "," are automagically removed after 7 days'
  381. : '"undelete" pulls files out of the waste basket'
  382. : 'if invoked without an argument, both commands list the contents of the'
  383. : 'waste basket.'
  384.  
  385. case $0 in
  386. *del)
  387.     if test -z "$1"
  388.     then
  389.     ls -lus $HOME/.waste_basket
  390.     else
  391.     for i
  392.     do
  393.         echo -n "deleting "
  394.         tmp=`basename $i`
  395.         /bin/mv -i $i $HOME/.waste_basket/,$tmp
  396.         echo $i
  397.     done
  398.     fi;;
  399.  
  400. *undelete)
  401.     if test -z "$1"
  402.     then
  403.     ls -lus $HOME/.waste_basket
  404.     else
  405.     for i
  406.     do
  407.         echo -n "recovering "
  408.         tmp=`basename $i`
  409.         /bin/mv -i $HOME/.waste_basket/,$tmp $i
  410.         echo $i
  411.     done
  412.     fi;;
  413. esac
  414. -------------------------------------------------------------------------------
  415. ::::::::::::::
  416. : vi
  417. ::::::::::::::
  418. : 'backs up file(s) before editing them'
  419. : 'files preceded by "," are automagically removed after 7 days'
  420. for i
  421. do
  422.     if test -f $i
  423.     then
  424.     echo -n "backing up "
  425.     tmp=`basename $i`
  426.     /bin/cp -i $i $HOME/.vi_backup/,$tmp
  427.     echo $i
  428.     fi
  429. done
  430. /usr/ucb/vi $*
  431. -------------------------------------------------------------------------------
  432.  
  433.     Bill Pfeifer
  434. {ucbvax,decvax,ihnp4,allegra,uw-beaver,hplabs} !tektronix!tekmdp!billp
  435.  
  436. ::::::::::::::
  437. shells/3
  438. ::::::::::::::
  439. Date: Thu, 13 Sep 84 13:58:09 pdt
  440. From: turtlevax!ken (Ken Turkowski)
  441. To: resonex!nancy
  442. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  443.  
  444. You asked for it, you've got it!  Here's ALL of my personal nifties:
  445.             Ken
  446. **************************************************
  447.  
  448. echo x - bin
  449. mkdir bin
  450. echo x - bin/CC
  451. cat >bin/CC <<'!Funky!Stuff!'
  452. #
  453. set outname=a.out
  454. foreach file ($argv)
  455.     if ("$file" =~ *.[cso]) then
  456.     set outname=$file:r
  457.         break
  458.     endif
  459. end
  460. echo cc -o $outname $*
  461. exec cc -o $outname $*
  462. !Funky!Stuff!
  463. echo x - bin/appt
  464. cat >bin/appt <<'!Funky!Stuff!'
  465. #
  466. set notetype=$0
  467. set notetype=$notetype:t
  468. set notefile=~/.$notetype
  469. # if ($notetype == appt) then
  470. #     set notetype=appointment
  471. #     set notefile=~/calendar
  472. # endif
  473.  
  474. if ($#argv == 0) then
  475.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  476.     echo ' ' >> $notefile
  477.     exec cat >> $notefile
  478. endif
  479.  
  480. switch ($1)
  481.     case -:
  482.     exec vi $notefile
  483.     case -rm:
  484.     cat /dev/null > $notefile
  485.     exec echo The ${notetype}s are removed.
  486.     case -what:
  487.     exec cat $notefile
  488.     default:
  489.     echo '' >> $notefile
  490.     echo "$*" >> $notefile
  491. endsw
  492. !Funky!Stuff!
  493. echo x - bin/asfix
  494. cat >bin/asfix <<'!Funky!Stuff!'
  495. case $# in
  496.     0)
  497.     file=/tmp/afix$$
  498.     trap "cat $file; rm $file; exit" 0
  499.     trap "rm $file; exit" 3 9
  500.     cat > $file ;;
  501.     1)
  502.     file=$1 ;;
  503.     *)
  504.     echo Usage `basename $0` ' [ <file> ]' ;;
  505. esac
  506. ed - $file << EOF
  507. v/[:\.]/s/^/    /
  508. g/:./s/:/:    /
  509. wq
  510. EOF
  511. !Funky!Stuff!
  512. echo x - bin/atcat
  513. cat >bin/atcat <<'!Funky!Stuff!'
  514. #
  515. if ($#argv < 2) then
  516.     set cmd=$0
  517.     echo Usage: "$cmd:t <time> <word> [ <word> ... ]"
  518.     exit
  519. endif
  520. set atcmd="echo $argv[2-] > `tty`"
  521. at $1 << EOF
  522. $atcmd
  523. EOF
  524. !Funky!Stuff!
  525. echo x - bin/atecho
  526. cat >bin/atecho <<'!Funky!Stuff!'
  527. #
  528. if ($#argv < 2) then
  529.     set cmd=$0
  530.     echo Usage: "$cmd:t <time> <word> [ <word> ... ]"
  531.     exit
  532. endif
  533. set atcmd="echo $argv[2-] > `tty`"
  534. at $1 << EOF
  535. $atcmd
  536. EOF
  537. !Funky!Stuff!
  538. echo x - bin/beautify
  539. cat >bin/beautify <<'!Funky!Stuff!'
  540. #
  541. set TMP=/tmp/cb$$
  542. foreach file (argv)
  543.     echo Beautifying $file:
  544.     cb < $file > $TMP
  545.     cat $TMP > $file
  546. end
  547. rm $TMP
  548. !Funky!Stuff!
  549. echo x - bin/blankclean
  550. cat >bin/blankclean <<'!Funky!Stuff!'
  551. sed -e 's/^    $//' -e 's/ *$//' $*
  552. !Funky!Stuff!
  553. echo x - bin/bphone
  554. cat >bin/bphone <<'!Funky!Stuff!'
  555. phonefile=$HOME/.`basename $0`s
  556.  
  557. echo ' '
  558.  
  559. case $# in
  560.     0)
  561.     ed - $phonefile << EOF
  562. g/./s/$/\\
  563. /
  564. g/    /s//\\
  565. /g
  566. g/;/s//    /g
  567. 1,\$p
  568. q
  569. EOF
  570.     exit ;;
  571. esac
  572.  
  573. case $1 in
  574.     -)
  575.     chmod 644 $phonefile
  576.     vi $phonefile
  577.     chmod 444 $phonefile
  578.     exit ;;
  579. esac
  580.  
  581. trap "rm /tmp/data$$; exit" 0 2
  582. for name
  583. do
  584.     grep -y "$name" $phonefile >> /tmp/data$$
  585. done
  586. ed - /tmp/data$$ << EOF
  587. g/./s/$/\\
  588. /
  589. g/    /s//\\
  590. /g
  591. g/;/s//    /g
  592. 1,\$p
  593. q
  594. EOF
  595. !Funky!Stuff!
  596. echo x - bin/catalog
  597. cat >bin/catalog <<'!Funky!Stuff!'
  598. # catalog - produce complete file structure list from directory
  599. # Parameters:     1: directory name (optional)
  600. #         2: indentation string (empty on first call)
  601. # Produces on standard output the file structure emanating from
  602. #   the current directory.  Each descent into a subdirectory
  603. #    is indicated by further indentation.  Directories are indicated
  604. #    by surrounding [], and executable files are prefaced with a *.
  605. if ( $#argv == 0) then
  606.    echo "file structure from directory `pwd`"
  607.    date
  608.    echo ''
  609. else
  610.    cd $1
  611. endif
  612. foreach i ( * )
  613.    if ( -d $i ) then
  614.      echo "${2}[ $i ]"
  615.      $0 $i "$2  . "
  616.    endif
  617.      if ( "$i" != '*' ) then
  618.         if ( -x $i ) then
  619.            echo "${2} *$i "
  620.         else
  621.            echo "${2}  $i "
  622.         endif
  623.      endif
  624.    endif
  625. end
  626. !Funky!Stuff!
  627. echo x - bin/circum
  628. cat >bin/circum <<'!Funky!Stuff!'
  629. there=$1
  630. shift
  631. otherstuff="$*"
  632. back=`whoami`
  633. last=`hostname`
  634. IFS='     !    
  635. '
  636. for link in $there
  637. do
  638.     back="$last!$back"
  639.     last=$link
  640. done
  641. IFS='     
  642. '
  643. echo mail $there!$back
  644. (date; echo "$otherstuff") | mail -s "Circumlocution to $last" $there!$back
  645. !Funky!Stuff!
  646. echo x - bin/comfmt
  647. cat >bin/comfmt <<'!Funky!Stuff!'
  648. exec fmt | \
  649. sed -e '1s/^\([     ]*\)/\1\/\* /' -e '2,$s/^\([     ]*\)/\1 \* /' -e '${P
  650. s/\*.*/*\//
  651. }'
  652. !Funky!Stuff!
  653. echo x - bin/comstrip
  654. cat >bin/comstrip <<'!Funky!Stuff!'
  655. exec sed -e 's/\/\*//' -e 's/\*\///' -e 's/^[     ]*\** *//'
  656. !Funky!Stuff!
  657. echo x - bin/decvert
  658. cat >bin/decvert <<'!Funky!Stuff!'
  659. #
  660. if ($#argv == 0) then
  661.     set args=`cat`
  662.     if ($#args != 0) $0 $args
  663.     exit
  664. endif
  665.  
  666. foreach hexnum ($argv)
  667. dc << EOF
  668. 16i
  669. ${hexnum}p
  670. EOF
  671. end
  672. !Funky!Stuff!
  673. echo x - bin/f77
  674. cat >bin/f77 <<'!Funky!Stuff!'
  675. PATH=/usr/bin
  676. SPECLIB=/usr/ken/cmd/lib/libc.a
  677. exec f77 "$@" $SPECLIB
  678. !Funky!Stuff!
  679. echo x - bin/famove
  680. cat >bin/famove <<'!Funky!Stuff!'
  681. #
  682. if ($#argv != 2) then
  683.     echo Usage: $0 '<source family root> <destination family root>'
  684.     exit
  685. endif
  686. foreach file ($1.*)
  687.     set suffix=`expr $file : "$1\.\(.*\)"`
  688.     echo mv $file $2.$suffix
  689.     mv $file $2.$suffix
  690. end
  691. if (-e $1) then
  692.     echo mv $1 $2
  693.     mv $1 $2
  694. endif
  695. !Funky!Stuff!
  696. echo x - bin/gredit
  697. cat >bin/gredit <<'!Funky!Stuff!'
  698. #
  699. set CAESAR=/mnt/cad/bin/caesar
  700. set SEARCHPATH=(-p ::/usr/ken/caesar/symlib)
  701. set COLORMAP=(-c mumap.cmap)
  702. set GRTERM=ttyh7
  703. set caesarfile=()
  704. foreach parm ($argv)
  705.     if ($?flag) then
  706.     switch ($flag)
  707.         case g:
  708.         set GRTERM=$parm
  709.         breaksw
  710.         case p:
  711.         set SEARCHPATH=(-p "$parm")
  712.         breaksw
  713.         case R:
  714.         set SEARCHPATH=($SEARCHPATH:$parm)
  715.         breaksw
  716.         case c:
  717.         set COLORMAP=(-c $parm)
  718.         breaksw
  719.     endsw
  720.     unset flag
  721.     continue
  722.     endif
  723.     if ($parm =~ -*) then
  724.     switch ($parm)
  725.         case -g:
  726.         set flag=g
  727.         continue
  728.         case -p:
  729.         set flag=p
  730.         continue
  731.         case -P:
  732.         set SEARCHPATH=()
  733.         continue
  734.         case -R:
  735.         set flag=R
  736.         continue
  737.         case -C:
  738.         set COLORMAP=()
  739.         continue
  740.         case -c:
  741.         set flag=c
  742.         continue
  743.     endsw
  744.     else
  745.     set caesarfile=($caesarfile $parm)
  746.     endif
  747. end
  748. onintr -
  749. $CAESAR -g $GRTERM $SEARCHPATH $COLORMAP $caesarfile
  750. !Funky!Stuff!
  751. echo x - bin/grindall
  752. cat >bin/grindall <<'!Funky!Stuff!'
  753. #
  754. set flags=
  755. set fileargs=
  756. onintr cleanup
  757. foreach file ($argv)
  758.     if ($file =~ -*) then
  759.     if ($file == -t) then
  760.         set stdout
  761.     else
  762.         set flags=($flags $file)
  763.     endif
  764.     else
  765.     set fileargs=($fileargs $file)
  766.     endif
  767. end
  768.  
  769. if ($?stdout) then
  770.     foreach file ($fileargs)
  771.     vgrind -t $flags $file
  772.     end
  773. else
  774.     foreach file ($fileargs)
  775.     vgrind -t $flags $file >> /usr/tmp/grind$$
  776.     end
  777.     vpr -T $fileargs[1] -t /usr/tmp/grind$$
  778. endif
  779.  
  780. cleanup:
  781. rm /usr/tmp/grind$$
  782. !Funky!Stuff!
  783. echo x - bin/hardasm
  784. cat >bin/hardasm <<'!Funky!Stuff!'
  785. #
  786. grasm -1 -l -x $* |& pr -f -h "grasm -l -x $*" | vpr -l
  787. !Funky!Stuff!
  788. echo x - bin/hexvert
  789. cat >bin/hexvert <<'!Funky!Stuff!'
  790. #
  791. if ($#argv == 0) then
  792.     set args=`cat`
  793.     if ($#args != 0) $0 $args
  794.     exit
  795. endif
  796.  
  797. foreach decnum ($argv)
  798. dc << EOF
  799. 16o
  800. ${decnum}p
  801. EOF
  802. end
  803. !Funky!Stuff!
  804. echo x - bin/job
  805. cat >bin/job <<'!Funky!Stuff!'
  806. PATH=/usr/ken/cmd/bin:/usr/ucb:/bin:/usr/bin
  807. case $# in
  808.     0)
  809.     exec echo Usage: `basename $0` '-;' or $0 '<job description>' ;;
  810. esac
  811. case $1 in
  812.     -)
  813.     exec ex $HOME/.joblog ;;
  814.     -h | -hr | -hrs)
  815.     shift
  816.     hrs=$1
  817.     shift
  818.     exec echo '   job:' $hrs hours # $* >> $HOME/.joblog ;;
  819.     -tail)
  820.     exec tail -22 $HOME/.joblog ;;
  821.     -today)
  822.     {
  823.         while read line
  824.         do
  825.         case $line in
  826.             *login*)
  827.             login="$line" ;;
  828.         esac
  829.         done
  830.         echo -n "$login" "for "
  831.         diffdate "$login" "`date`"
  832.     } < $HOME/.joblog ;;
  833.     -login)
  834.     echo ' login:' "`date`" >> $HOME/.joblog ;;
  835.     -summary)
  836.     cat $HOME/.joblog |
  837.         while read line
  838.         do
  839.         case $line in
  840.             *login*)
  841.             login="$line" ;;
  842.             *logout*)
  843.             logout="$line"
  844.             echo -n "$login" "for "
  845.             diffdate "$login" "$logout"
  846.         esac
  847.         done ;;
  848.     *)
  849.     exec echo '   job:' "`date`" # $* >> $HOME/.joblog ;;
  850. esac
  851. !Funky!Stuff!
  852. echo x - bin/ledger
  853. cat >bin/ledger <<'!Funky!Stuff!'
  854. #
  855. set notetype=$0
  856. set notetype=$notetype:t
  857. set notefile=~/.$notetype
  858. # if ($notetype == appt) then
  859. #     set notetype=appointment
  860. #     set notefile=~/calendar
  861. # endif
  862.  
  863. if ($#argv == 0) then
  864.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  865.     echo ' ' >> $notefile
  866.     exec cat >> $notefile
  867. endif
  868.  
  869. switch ($1)
  870.     case -:
  871.     exec vi $notefile
  872.     case -rm:
  873.     cat /dev/null > $notefile
  874.     exec echo The ${notetype}s are removed.
  875.     case -what:
  876.     exec cat $notefile
  877.     default:
  878.     echo '' >> $notefile
  879.     echo "$*" >> $notefile
  880. endsw
  881. !Funky!Stuff!
  882. echo x - bin/lstree
  883. cat >bin/lstree <<'!Funky!Stuff!'
  884. #
  885. if ($#argv == 0) then
  886.     set root=.
  887. else
  888.     set root=($*)
  889. endif
  890. exec find $root -print | sort | sed -e 's/[^ \/]*\//    /g'
  891. !Funky!Stuff!
  892. echo x - bin/match
  893. cat >bin/match <<'!Funky!Stuff!'
  894. cat $2 |
  895. while read x
  896. do
  897.     for word in $x
  898.     do
  899.     case $word in
  900.         $1)
  901.         echo $word ;;
  902.     esac
  903.     done
  904. done
  905. !Funky!Stuff!
  906. echo x - bin/narrow
  907. cat >bin/narrow <<'!Funky!Stuff!'
  908. echo \!
  909. !Funky!Stuff!
  910. echo x - bin/outmesg
  911. cat >bin/outmesg <<'!Funky!Stuff!'
  912. #
  913. set notetype=$0
  914. set notetype=$notetype:t
  915. set notefile=~/.$notetype
  916. # if ($notetype == appt) then
  917. #     set notetype=appointment
  918. #     set notefile=~/calendar
  919. # endif
  920.  
  921. if ($#argv == 0) then
  922.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  923.     echo ' ' >> $notefile
  924.     exec cat >> $notefile
  925. endif
  926.  
  927. switch ($1)
  928.     case -:
  929.     exec vi $notefile
  930.     case -rm:
  931.     cat /dev/null > $notefile
  932.     exec echo The ${notetype}s are removed.
  933.     case -what:
  934.     exec cat $notefile
  935.     default:
  936.     echo '' >> $notefile
  937.     echo "$*" >> $notefile
  938. endsw
  939. !Funky!Stuff!
  940. echo x - bin/path
  941. cat >bin/path <<'!Funky!Stuff!'
  942. IFS="${IFS}:"
  943. for cmddir in $PATH
  944. do
  945.     test -s $cmddir/$1 && echo "    $cmddir/$1"
  946. done
  947. !Funky!Stuff!
  948. echo x - bin/pphone
  949. cat >bin/pphone <<'!Funky!Stuff!'
  950. phonefile=$HOME/.`basename $0`s
  951.  
  952. echo ' '
  953.  
  954. case $# in
  955.     0)
  956.     ed - $phonefile << EOF
  957. g/./s/$/\\
  958. /
  959. g/    /s//\\
  960. /g
  961. g/;/s//    /g
  962. 1,\$p
  963. q
  964. EOF
  965.     exit ;;
  966. esac
  967.  
  968. case $1 in
  969.     -)
  970.     chmod 644 $phonefile
  971.     vi $phonefile
  972.     chmod 444 $phonefile
  973.     exit ;;
  974. esac
  975.  
  976. trap "rm /tmp/data$$; exit" 0 2
  977. for name
  978. do
  979.     grep -y "$name" $phonefile >> /tmp/data$$
  980. done
  981. ed - /tmp/data$$ << EOF
  982. g/./s/$/\\
  983. /
  984. g/    /s//\\
  985. /g
  986. g/;/s//    /g
  987. 1,\$p
  988. q
  989. EOF
  990. !Funky!Stuff!
  991. echo x - bin/progression
  992. cat >bin/progression <<'!Funky!Stuff!'
  993. last=
  994. for backup in $1_??
  995. do
  996.     case $last in
  997.     "")
  998.         last=$backup
  999.         continue;
  1000.     esac
  1001.     echo ''
  1002.     echo From $last to $backup:
  1003.     diff $last $backup
  1004.     last=$backup
  1005. done
  1006. echo ''
  1007. echo From $last to $1:
  1008. diff $last $1
  1009. !Funky!Stuff!
  1010. echo x - bin/query
  1011. cat >bin/query <<'!Funky!Stuff!'
  1012. #
  1013. set notetype=$0
  1014. set notetype=$notetype:t
  1015. set notefile=~/.$notetype
  1016. # if ($notetype == appt) then
  1017. #     set notetype=appointment
  1018. #     set notefile=~/calendar
  1019. # endif
  1020.  
  1021. if ($#argv == 0) then
  1022.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  1023.     echo ' ' >> $notefile
  1024.     exec cat >> $notefile
  1025. endif
  1026.  
  1027. switch ($1)
  1028.     case -:
  1029.     exec vi $notefile
  1030.     case -rm:
  1031.     cat /dev/null > $notefile
  1032.     exec echo The ${notetype}s are removed.
  1033.     case -what:
  1034.     exec cat $notefile
  1035.     default:
  1036.     echo '' >> $notefile
  1037.     echo "$*" >> $notefile
  1038. endsw
  1039. !Funky!Stuff!
  1040. echo x - bin/releave
  1041. cat >bin/releave <<'!Funky!Stuff!'
  1042. #
  1043. set tty=`tty`
  1044. set tty=`expr $tty : '.*tty\(.*\)'`
  1045. set leaveproc=`ps gt$tty | grep -w leave`
  1046. kill -9 $leaveproc[1]
  1047. date
  1048. leave $*
  1049. !Funky!Stuff!
  1050. echo x - bin/reminder
  1051. cat >bin/reminder <<'!Funky!Stuff!'
  1052. #
  1053. set notetype=$0
  1054. set notetype=$notetype:t
  1055. set notefile=~/.$notetype
  1056. # if ($notetype == appt) then
  1057. #     set notetype=appointment
  1058. #     set notefile=~/calendar
  1059. # endif
  1060.  
  1061. if ($#argv == 0) then
  1062.     test -t 0 && echo Please enter your $notetype entry '(^D to end):'
  1063.     echo ' ' >> $notefile
  1064.     exec cat >> $notefile
  1065. endif
  1066.  
  1067. switch ($1)
  1068.     case -:
  1069.     exec vi $notefile
  1070.     case -rm:
  1071.     cat /dev/null > $notefile
  1072.     exec echo The ${notetype}s are removed.
  1073.     case -what:
  1074.     exec cat $notefile
  1075.     default:
  1076.     echo '' >> $notefile
  1077.     echo "$*" >> $notefile
  1078. endsw
  1079. !Funky!Stuff!
  1080. echo x - bin/reremind
  1081. cat >bin/reremind <<'!Funky!Stuff!'
  1082. #
  1083. set tty=`tty`
  1084. set tty=`expr $tty : '.*tty\(.*\)'`
  1085. set leaveproc=`ps gt$tty | awk '$5 ~ /^remind$/ { print $1 }'`
  1086. if ($#leaveproc > 1) echo $#leaveproc reminds were running
  1087. kill -9 $leaveproc
  1088. date
  1089. if ($#argv <= 1) then
  1090.     remind $*
  1091. else
  1092.     set time=$1
  1093.     shift
  1094.     remind $time "$*"
  1095. endif
  1096. !Funky!Stuff!
  1097. echo x - bin/restore
  1098. cat >bin/restore <<'!Funky!Stuff!'
  1099. # Truncate filename if necessary
  1100. set file=$1
  1101. if (`expr $file:t : '.*'` >= 11) then
  1102.     set savename=`expr $file : '\(.*\)'$file:t`
  1103.     set savename=$savename`expr $file:t : '\(...........\)'`
  1104. else
  1105.     set savename=$file
  1106. endif
  1107.  
  1108. switch ($#argv)
  1109.     case 1:
  1110.     set nonomatch
  1111.     set backup=(${savename}_[0-9][0-9])
  1112.     if ("$backup" == "${savename}_[0-9][0-9]") then
  1113.         echo Error: No backups found for $file
  1114.         exit
  1115.     endif
  1116.     set backup=$backup[$#backup]
  1117.     echo No backup number specified. Using latest: $backup
  1118.     breaksw
  1119.     case 2:
  1120.     set backup=${savename}_$2
  1121.     breaksw
  1122.     default:
  1123.     exec echo Usage: `basename $0` '<file>' '[<backup number>]'
  1124. endsw
  1125.  
  1126. if ( { cp $backup $file } ) then
  1127.     echo $file restored from $backup.
  1128.     echo -n Do you wish to keep "$backup? "
  1129.     set response=$<
  1130.     if ($response !~ y*) then
  1131.     rm $backup
  1132.     endif
  1133. endif
  1134. !Funky!Stuff!
  1135. echo x - bin/rot13
  1136. cat >bin/rot13 <<'!Funky!Stuff!'
  1137. tr "A-Za-z" "N-ZA-Mn-za-m"
  1138. !Funky!Stuff!
  1139. echo x - bin/shufcol
  1140. cat >bin/shufcol <<'!Funky!Stuff!'
  1141. trap 'rm /tmp/$$.*; exit' 0 2
  1142. cat > /tmp/$$.0
  1143. i=1
  1144. for cols
  1145. do
  1146.     cut -f$cols < /tmp/$$.0 > /tmp/$$.$i
  1147.     filelist="$filelist /tmp/$$.$i"
  1148.     i=`expr $i + 1`
  1149. done
  1150. paste $filelist
  1151. !Funky!Stuff!
  1152. echo x - bin/signature
  1153. cat >bin/signature <<'!Funky!Stuff!'
  1154. PATH=/bin:/usr/bin
  1155. cat
  1156. echo --
  1157. cat $HOME/.signature
  1158. !Funky!Stuff!
  1159. echo x - bin/swab
  1160. cat >bin/swab <<'!Funky!Stuff!'
  1161. #
  1162. if ($#argv == 0) then
  1163.     dd conv=swab
  1164. else
  1165.     onintr cleanup
  1166.     foreach file ($argv)
  1167.     cp $file /tmp/swab$$
  1168.     dd if=/tmp/swab$$ of=$file conv=swab
  1169.     end
  1170.     cleanup:
  1171.     rm /tmp/swab$$
  1172. endif
  1173. !Funky!Stuff!
  1174. echo x - bin/what
  1175. cat >bin/what <<'!Funky!Stuff!'
  1176. cat $HOME/.query
  1177. echo -n 'save? (n or d to delete, e to edit) '
  1178. read response
  1179. case $response in
  1180.     n | no | d | delete)
  1181.     rm $HOME/.query && echo The query is removed. ;;
  1182.     "" | y | yes | s | save)
  1183.     exit ;;
  1184.     e | edit)
  1185.     exec vi $HOME/.query < /dev/tty
  1186.     exit ;;
  1187.     *)
  1188.     echo Bad response: "$response"
  1189.     exec $0 ;;
  1190. esac
  1191. !Funky!Stuff!
  1192. echo x - bin/whereis
  1193. cat >bin/whereis <<'!Funky!Stuff!'
  1194. N=$#
  1195. command=echo
  1196. case "$1" in
  1197.     -*)
  1198.     command=`expr "$1" : '-\(.*\)'`
  1199.     shift
  1200.     N=`expr $N - 1` ;;
  1201. esac
  1202. case $N in
  1203.     0)
  1204.     exec echo Usage: `basename $0` [ -command ] pattern file ...  ;;
  1205.     1)
  1206.     files=`fgrep -l "$1" *` ;;
  1207.     *)
  1208.     files=`fgrep -l "$@"` ;;
  1209. esac
  1210. case $files in
  1211.     "")
  1212.         echo $1 not found in any files.
  1213.         exit ;;
  1214. esac
  1215. exec $command $files
  1216. !Funky!Stuff!
  1217. echo x - bin/wide
  1218. cat >bin/wide <<'!Funky!Stuff!'
  1219. echo \"
  1220. !Funky!Stuff!
  1221. echo x - bin/xprint
  1222. cat >bin/xprint <<'!Funky!Stuff!'
  1223. case $# in
  1224.     1)
  1225.     eval $1 | eval pr -f -h \"$1\" | vpr -l ;;
  1226.     *)
  1227.     command='cat $file'
  1228.     for file
  1229.     do
  1230.         case $file in
  1231.         -*)
  1232.             command=`expr "$file" : '-\(.*\)'`
  1233.             case $command in
  1234.             *\$file*)
  1235.                 ;;
  1236.             *)
  1237.                 command="$command \$file" ;;
  1238.             esac ;;
  1239.         *)
  1240.             eval $command | eval pr -f -h \"$command\" | vpr -l ;;
  1241.         esac
  1242.     done
  1243. esac
  1244. !Funky!Stuff!
  1245. echo x - bin/archives
  1246. mkdir bin/archives
  1247. echo x - bin/archives/newsweed
  1248. cat >bin/archives/newsweed <<'!Funky!Stuff!'
  1249. #
  1250. cd
  1251. if ($#argv == 0) then
  1252.     if (-e .newsweed) then
  1253.     set WEEDGROUPS=`cat .newsweed`
  1254.     else
  1255.     set WEEDGROUPS=
  1256.     endif
  1257. else
  1258.     set WEEDGROUPS=$*
  1259. endif
  1260. if ($#WEEDGROUPS == 0) then
  1261.     onintr
  1262.     echo Searching for articles in all newsgroups
  1263.     readnews -l | \
  1264.     grep Subject | \
  1265.     sed -e 's/Subject: *//' -e 's/^[rR][eE]:*  *//' | \
  1266.     sort -u > /tmp/weed$$a
  1267.     if (-z /tmp/weed$$a) then
  1268.     echo No news.
  1269.     else
  1270.     cp /tmp/weed$$a /tmp/weed$$b
  1271.     echo Please remove article titles which you do not wish to read
  1272.     sleep 1
  1273.     onintr -
  1274.     vi /tmp/weed$$b
  1275.     onintr cleanup
  1276.     comm -23 /tmp/weed$$a /tmp/weed$$b > /tmp/weed$$c
  1277.     echo Removing unwanted articles
  1278.     newsec -f /tmp/weed$$c
  1279.     endif
  1280. else
  1281.     foreach group ($WEEDGROUPS)
  1282.     echo Searching for articles in group\(s\):
  1283.     echo $group
  1284.     readnews -l -n $group | \
  1285.     grep Subject | \
  1286.     sed -e 's/Subject: *//' -e 's/^[rR]e:*  *//' | \
  1287.     sort -u > /tmp/weed$$a
  1288.     if (-z /tmp/weed$$a) then
  1289.         echo in newsgroups $group.
  1290.     else
  1291.         cp /tmp/weed$$a /tmp/weed$$b
  1292.         echo Please remove article titles which you do not wish to read
  1293.         sleep 1
  1294.         onintr -
  1295.         vi /tmp/weed$$b
  1296.         onintr cleanup
  1297.         comm -23 /tmp/weed$$a /tmp/weed$$b > /tmp/weed$$c
  1298.         echo Removing unwanted articles
  1299.         newsec -f /tmp/weed$$c
  1300.     endif
  1301.     end
  1302. endif
  1303.  
  1304. cleanup:
  1305. rm /tmp/weed$$?
  1306. !Funky!Stuff!
  1307. echo x - bin/archives/pk_01
  1308. cat >bin/archives/pk_01 <<'!Funky!Stuff!'
  1309. : Roff, nroff, or eqn input text
  1310. for file in `file $* | sed -n '/eqn input text$/s/:[^:]*$//p'`
  1311. do
  1312.     echo "echo x - $file"
  1313.     echo "sed 's/^x//' >$file <<'!Funky!Stuff!'"
  1314.     sed 's/^/x/' $file; echo "!Funky!Stuff!"
  1315. done
  1316. : Text files
  1317. for file in `file $* | sed -n -e '/commands text$/s/:[^:]*$//p' -e '/ascii text$/s/:[^:]*$//p'`
  1318. do
  1319.     echo "echo x - $file"
  1320.     echo "cat >$file <<'!Funky!Stuff!'"
  1321.     cat $file; echo "!Funky!Stuff!"
  1322. done
  1323. : Directories, recursively
  1324. for dir in `file $* | sed -n '/directory$/s/:.*//p'`
  1325. do
  1326.     echo "echo x - $dir"
  1327.     echo "mkdir $dir"
  1328.     file=`echo $dir/*`
  1329.     test "$file" != "$dir/*" && $0 $file
  1330. done
  1331. !Funky!Stuff!
  1332. echo x - bin/archives/pkf
  1333. cat >bin/archives/pkf <<'!Funky!Stuff!'
  1334.  
  1335. for dir
  1336. do
  1337.     echo "echo x - $dir"
  1338.     echo "mkdir $dir";
  1339.     for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'`
  1340.     do
  1341.         echo "echo x - $file"
  1342.         echo "cat >$file <<'!Funky!Stuff!'"
  1343.         cat $file; echo "!Funky!Stuff!"
  1344.     done
  1345.     $0 `file $dir/* | sed -n '/directory$/s/:.*//p'`
  1346. done
  1347. !Funky!Stuff!
  1348. echo x - bin/archives/pkg
  1349. cat >bin/archives/pkg <<'!Funky!Stuff!'
  1350. for file
  1351. do
  1352.     echo "echo x - $file"
  1353.     echo "cat >$file <<'!Funky!Stuff!'"
  1354.     cat $file; echo "!Funky!Stuff!"
  1355. done
  1356. !Funky!Stuff!
  1357. echo x - bin/archives/pkn
  1358. cat >bin/archives/pkn <<'!Funky!Stuff!'
  1359.  
  1360. for dir
  1361. do
  1362.     echo "echo x - $dir"
  1363.     echo "mkdir $dir";
  1364.     for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'`
  1365.     do
  1366.         echo "echo x - $file"
  1367.         echo "sed 's/^x//' >$file <<'!Funky!Stuff!'"
  1368.         sed 's/^/x/' $file; echo "!Funky!Stuff!"
  1369.     done
  1370.     $0 `file $dir/* | sed -n '/directory$/s/:.*//p'`
  1371. done
  1372. !Funky!Stuff!
  1373. echo x - bin/archives/prod
  1374. cat >bin/archives/prod <<'!Funky!Stuff!'
  1375. #
  1376. set flags=()
  1377. set syslist=()
  1378. foreach arg ($argv)
  1379.     switch ($arg)
  1380.     case -s*:
  1381.         if (`expr $arg : '.*'` > 9) then
  1382.         rm -f /usr/spool/uucp/STST.`expr $arg : '-s\(.......\)'`
  1383.         else
  1384.         rm -f /usr/spool/uucp/STST.`expr $arg : '-s\(.*\)'`
  1385.         endif
  1386.         set syslist=($syslist $arg)
  1387.         breaksw
  1388.     case -*:
  1389.         set flags=($flags $arg)
  1390.         breaksw
  1391.     default:
  1392.         if (`expr $arg : '.*'` > 7) then
  1393.         rm -f /usr/spool/uucp/STST.`expr $arg : '\(.......\)'`
  1394.         else
  1395.         rm -f /usr/spool/uucp/STST.$arg
  1396.         endif
  1397.         set syslist=($syslist -s$arg)
  1398.         breaksw
  1399.     endsw
  1400. end
  1401. foreach sys ($syslist)
  1402.     /usr/lib/uucp/uucico -r1 $flags $sys
  1403. end
  1404. !Funky!Stuff!
  1405. echo x - bin/bourne_scripts
  1406. mkdir bin/bourne_scripts
  1407. echo x - bin/bourne_scripts/lookdoc
  1408. sed 's/^x//' >bin/bourne_scripts/lookdoc <<'!Funky!Stuff!'
  1409. xtrap exit 2
  1410. xcase $# in
  1411. x    0)
  1412. x    ul | more
  1413. x    exit ;;
  1414. xesac
  1415. xfor names
  1416. xdo
  1417. x    case $names in
  1418. x    -n)
  1419. x        default=n ;;
  1420. x    -t)
  1421. x        default=t ;;
  1422. x    -m*)
  1423. x        macros="$macros $names" ;;
  1424. x    *.n | *.nr)
  1425. x        nroff $macros $names | ul | more ;;
  1426. x    *.t | *.tbl)
  1427. x        soelim $names | tbl | nroff $macros - | ul | more ;;
  1428. x    *)
  1429. x        case $default in
  1430. x        n)
  1431. x            nroff $macros $names | ul | more ;;
  1432. x        t)
  1433. x            soelim $names | tbl | nroff $macros - | ul | more ;;
  1434. x        "")
  1435. x            ul $names | more ;;
  1436. x        esac
  1437. x    esac
  1438. xdone
  1439. !Funky!Stuff!
  1440. echo x - bin/bourne_scripts/CC
  1441. cat >bin/bourne_scripts/CC <<'!Funky!Stuff!'
  1442. outname=a.out
  1443. for argv
  1444. do
  1445.     case $argv in
  1446.     *.[cos])
  1447.         outname=`expr $argv : '\(.*\)\.'`
  1448.         break ;;
  1449.     esac
  1450. done
  1451. cc -o $outname $*
  1452. !Funky!Stuff!
  1453. echo x - bin/bourne_scripts/appt
  1454. cat >bin/bourne_scripts/appt <<'!Funky!Stuff!'
  1455. case $0 in
  1456.     appt)
  1457.     notetype=appointment
  1458.     notefile=$HOME/calendar ;;
  1459.     *)
  1460.     notetype=$0
  1461.     notefile=$HOME/.$0 ;;
  1462. esac
  1463.  
  1464. case $# in
  1465.     0)
  1466.     test -t 0 && echo Please enter your $notetype '(^D to end):'
  1467.     echo '' >> $notefile
  1468.     exec cat >> $notefile ;;
  1469. esac
  1470. case $1 in
  1471.     -)
  1472.     exec vi $notefile ;;
  1473.     -rm)
  1474.     cat /dev/null > $notefile
  1475.     exec echo The ${notetype}s are removed. ;;
  1476.     -what)
  1477.     exec cat $notefile ;;
  1478.     *)
  1479.     echo '' >> $notefile
  1480.     exec echo "$*" >> $notefile ;;
  1481. esac
  1482. !Funky!Stuff!
  1483. echo x - bin/bourne_scripts/beautify
  1484. cat >bin/bourne_scripts/beautify <<'!Funky!Stuff!'
  1485. for files
  1486. do
  1487.     echo $files:
  1488.     cb < $files > /tmp/cb$$
  1489.     cat /tmp/cb$$ > $files
  1490. done
  1491. rm /tmp/cb$$
  1492. !Funky!Stuff!
  1493. echo x - bin/bourne_scripts/format
  1494. cat >bin/bourne_scripts/format <<'!Funky!Stuff!'
  1495. case $# in
  1496.     0)
  1497.     echo "Usage: `basename $0` [-flags] <filename> [ <filename> ... ]"
  1498.     exit 1 ;;
  1499. esac
  1500. for names
  1501. do
  1502.     case $names in
  1503.     -*)
  1504.         flags="$flags $names" ;;
  1505.     *.t)
  1506.         outfile=`expr $names : '\(.*\)\.'`.d
  1507.         soelim $names | tbl | nroff $flags - > $outfile ;;
  1508.     *.tbl)
  1509.         outfile=`expr $names : '\(.*\)\.'`.doc
  1510.         soelim $names | tbl | nroff $flags - > $outfile ;;
  1511.     *.n)
  1512.         outfile=`expr $names : '\(.*\)\.'`.d
  1513.         nroff $flags $names > $outfile ;;
  1514.     *.nr)
  1515.         outfile=`expr $names : '\(.*\)\.'`.doc
  1516.         nroff $flags $names > $outfile ;;
  1517.     *)
  1518.         echo Don\'t know what to do with $names ;;
  1519.     esac
  1520. done
  1521. !Funky!Stuff!
  1522. echo x - bin/bourne_scripts/print
  1523. cat >bin/bourne_scripts/print <<'!Funky!Stuff!'
  1524. PATH=/avsd/ava/turk/bin:/usr/local/bin:/usr/bin
  1525. indent=0
  1526. for names
  1527. do
  1528.     case $names in
  1529.     -i)
  1530.         indent=1 ;;
  1531.     *)
  1532.         args="$args $names" ;;
  1533.     esac
  1534. done
  1535. case $indent in
  1536.     0)
  1537.     pr $args | lpr ;;
  1538.     *)
  1539.     pr $args | indent | lpr ;;
  1540. esac
  1541. !Funky!Stuff!
  1542. echo x - bin/bourne_scripts/repeat
  1543. cat >bin/bourne_scripts/repeat <<'!Funky!Stuff!'
  1544. case $1 in
  1545.     -[0-9]*)
  1546.     number=`expr $1 : '-\(.*\)'`
  1547.     shift
  1548.     while test $number -gt 0
  1549.     do
  1550.         eval $*
  1551.         number=`expr $number - 1`
  1552.     done
  1553.     exit ;;
  1554.     *)
  1555.     echo Executing forever: $* 1>&2
  1556.     number=0
  1557.     trap 'echo Executed $number times.; exit' 2
  1558.     while true
  1559.     do
  1560.         eval $*
  1561.         number=`expr $number + 1`
  1562.     done ;;
  1563. esac
  1564. !Funky!Stuff!
  1565. echo x - bin/bourne_scripts/restore
  1566. cat >bin/bourne_scripts/restore <<'!Funky!Stuff!'
  1567. case $# in
  1568.     2) ;;
  1569.     *)
  1570.     exec echo Usage: `basename $0` '<file>' '<version>' ;;
  1571. esac
  1572. : Truncate filename if necessary
  1573. if test `expr $1 : '.*'` -gt 11
  1574. then
  1575.     savename=`expr $1 : '\(...........\)'`
  1576. else
  1577.     savename=$1
  1578. fi
  1579. savename=${savename}_$2
  1580. cp $savename $1 && rm $savename && echo $1 restored from $savename
  1581. !Funky!Stuff!
  1582. echo x - bin/bourne_scripts/save
  1583. cat >bin/bourne_scripts/save <<'!Funky!Stuff!'
  1584. for file
  1585. do
  1586.     if test `expr $file : '.*'` -gt 11
  1587.     then
  1588.     savename=`expr $file : '\(...........\)'`
  1589.     else
  1590.     savename=$file
  1591.     fi
  1592.     for copy in ${savename}_??
  1593.     do
  1594.     latest=$copy
  1595.     done
  1596.     if test $latest = "${savename}_??"
  1597.     then
  1598.     latest=${savename}_01
  1599.     else
  1600.     latest=`expr $latest : '.*_\([0123456789]*\)$' + 1`
  1601.     case $latest in
  1602.         ?)
  1603.         latest=0$latest
  1604.         ;;
  1605.     esac
  1606.     latest=${savename}_$latest
  1607.     fi
  1608.     cp $file $latest && echo $file saved as $latest
  1609. done
  1610. !Funky!Stuff!
  1611. echo x - bin/csh_scripts
  1612. mkdir bin/csh_scripts
  1613. echo x - bin/csh_scripts/newsweed
  1614. cat >bin/csh_scripts/newsweed <<'!Funky!Stuff!'
  1615. #
  1616. set TEMP=/tmp/weed$$
  1617. set NEWSRC=~/.newsrc
  1618. set AWKFILE=/usr/ken/cmd/lib/newsweed.awk
  1619. onintr
  1620. echo Searching for articles in all newsgroups
  1621. readnews -l $* | sort -o ${TEMP}a
  1622. if (-z ${TEMP}a) then
  1623.     echo No news.
  1624. else
  1625.     cp ${TEMP}a ${TEMP}b
  1626.     echo Please remove article titles which you do not wish to read
  1627.     sleep 1
  1628.     onintr -
  1629.     vi ${TEMP}b
  1630.     onintr cleanup
  1631.     if ( { cmp -s ${TEMP}a ${TEMP}b } ) then
  1632.     echo No articles deleted.
  1633.     else
  1634.     comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c
  1635.     echo Removing unwanted articles
  1636.     cp $NEWSRC $NEWSRC.old
  1637.     awk -f $AWKFILE $NEWSRC.old ${TEMP}c > ${TEMP}d
  1638.     cp ${TEMP}d $NEWSRC
  1639.     endif
  1640. endif
  1641. cleanup:
  1642. rm ${TEMP}?
  1643. !Funky!Stuff!
  1644. echo x - bin/csh_scripts/pathname
  1645. cat >bin/csh_scripts/pathname <<'!Funky!Stuff!'
  1646. #
  1647. foreach cmddir ($path)
  1648.     if ( -e $cmddir/$1 ) echo "    $cmddir/$1"
  1649. end
  1650. !Funky!Stuff!
  1651. echo x - bin/local
  1652. mkdir bin/local
  1653. echo x - bin/local/format
  1654. cat >bin/local/format <<'!Funky!Stuff!'
  1655. #
  1656. if ($#argv == 0) then
  1657.     set progname=$0
  1658.     set progname=$progname:t
  1659.     echo 'Usage:' $progname '[-v] [-n] [-print] [-troffflags] <filename> [ <filename> ... ]'
  1660.     exit (1)
  1661. endif
  1662. set flags
  1663. set formatter="vtroff -t"
  1664. set eqnsetter=eqn
  1665. set docsuf=v
  1666. set longdocsuf=vpr
  1667. set more=0
  1668. foreach name ($argv)
  1669.     if ($more > 0) then
  1670.     set flags="$flags $name"
  1671.     @ more--
  1672.     continue
  1673.     endif
  1674.     switch ($name)
  1675.     case -*:
  1676.         switch ($name)
  1677.         case -print:
  1678.             set print
  1679.             continue
  1680.         case -v:
  1681.             set formatter="vtroff -t"
  1682.             set eqnsetter=eqn
  1683.             set docsuf=v
  1684.             set longdocsuf=vpr
  1685.             continue
  1686.         case -n:
  1687.             set formatter=nroff
  1688.             set eqnsetter=neqn
  1689.             set docsuf=d
  1690.             set longdocsuf=doc
  1691.             continue
  1692.         case -[F123]:
  1693.             set more=1
  1694.         default:
  1695.             set flags="$flags $name"
  1696.         endsw
  1697.         continue
  1698.     case *.et:
  1699.         set outfile=$name:r.$docsuf
  1700.         eval soelim $name | tbl | $eqnsetter | $formatter $flags > $outfile
  1701.         breaksw
  1702.     case *.t:
  1703.         set outfile=$name:r.$docsuf
  1704.         eval soelim $name | tbl | $formatter $flags > $outfile
  1705.         breaksw
  1706.     case *.tbl:
  1707.         set outfile=$name:r.$longdocsuf
  1708.         eval soelim $name | tbl | $formatter $flags > $outfile
  1709.         breaksw
  1710.     case *.e:
  1711.         set outfile=$name:r.$docsuf
  1712.         eval $eqnsetter $name | $formatter $flags > $outfile
  1713.         breaksw
  1714.     case *.eqn:
  1715.         set outfile=$name:r.$longdocsuf
  1716.         eval $eqnsetter $name | $formatter $flags > $outfile
  1717.         breaksw
  1718.     case *.n:
  1719.         set outfile=$name:r.$docsuf
  1720.         eval $formatter $flags $name > $outfile
  1721.         breaksw
  1722.     case *.nr:
  1723.         set outfile=$name:r.$longdocsuf
  1724.         eval $formatter $flags $name > $outfile
  1725.         breaksw
  1726.     default:
  1727.         echo Don\'t know what to do with $name
  1728.         continue
  1729.     endsw
  1730.     if ($?print) then
  1731.     if ("$formatter" == nroff) then
  1732.         vpr $outfile
  1733.     else
  1734.         vpr -t $outfile
  1735.     endif
  1736.     endif
  1737. end
  1738. !Funky!Stuff!
  1739. echo x - bin/local/lntree
  1740. cat >bin/local/lntree <<'!Funky!Stuff!'
  1741. PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin
  1742. if test $1 = -v
  1743. then
  1744.     verbose=1
  1745.     shift
  1746. else
  1747.     verbose=0
  1748. fi
  1749. case $2 in
  1750.     /*)
  1751.     target=$2 ;;
  1752.     *)
  1753.     target=`pwd`/$2 ;;
  1754. esac
  1755. if test -f $2
  1756. then
  1757.     echo Error: $2 is not a directory
  1758.     exit 1
  1759. fi
  1760. cd $1
  1761. source=`pwd`
  1762. if test `expr $target : $source/` != 0
  1763. then
  1764.     echo Error: $2 may be a subdirectory of $1
  1765.     echo Try using the full path name of $2 \(no ..\'s\)
  1766.     exit 1
  1767. fi
  1768. if test $verbose = 1
  1769. then
  1770.     set -x
  1771. fi
  1772. files=`type -f`
  1773. case $files in
  1774.     "") ;;
  1775.     *)
  1776.     ln $files $target ;;
  1777. esac
  1778. for directory in `find '' -type d -a -print`
  1779. do
  1780.     mkdir $target$directory
  1781.     cd $source$directory
  1782.     files=`type -f`
  1783.     case $files in
  1784.     "") ;;
  1785.     *)
  1786.         ln $files $target$directory ;;
  1787.     esac
  1788. done
  1789. !Funky!Stuff!
  1790. echo x - bin/local/lookdoc
  1791. cat >bin/local/lookdoc <<'!Funky!Stuff!'
  1792. #
  1793. if ($#argv == 0) then
  1794.     more
  1795.     exit
  1796. endif
  1797. set macros pipespec args
  1798. foreach name ($argv)
  1799.     switch ($name)
  1800.     case -n:
  1801.         set pipespec=n
  1802.         breaksw
  1803.     case -t:
  1804.         set pipespec=t
  1805.         breaksw
  1806.     case -m*:
  1807.         set macros="$macros $name"
  1808.         breaksw
  1809.     case *.n:
  1810.     case *.nr:
  1811.         if ($pipespec != t) set pipespec=n
  1812.         set args="$args $name"
  1813.         breaksw
  1814.     case *.t:
  1815.     case *.tbl:
  1816.         set pipespec=t
  1817.         set args="$args $name"
  1818.         breaksw
  1819.     default:
  1820.         set args="$args $name"
  1821.     endsw
  1822. end
  1823.  
  1824. switch ($pipespec)
  1825.     case n:
  1826.     nroff $macros $args | more
  1827.     breaksw
  1828.     case t:
  1829.     soelim $args | tbl | nroff $macros - | col | more
  1830.     breaksw
  1831.     default:
  1832.     more $name
  1833.     breaksw
  1834. endsw
  1835. !Funky!Stuff!
  1836. echo x - bin/local/newsweed
  1837. cat >bin/local/newsweed <<'!Funky!Stuff!'
  1838. TEMP=/tmp/weed$$
  1839. NEWSRC=$HOME/.newsrc
  1840. AWKFILE=/usr/local/lib/newsweed.awk
  1841. trap 'rm ${TEMP}?; exit' 0 2
  1842. echo Making list of article titles
  1843. readnews -l $* | sort -o ${TEMP}a
  1844. if test -s ${TEMP}a
  1845. then
  1846.     cp ${TEMP}a ${TEMP}b
  1847.     echo Please remove article titles which you do not wish to read
  1848.     sleep 1
  1849.     reset    # So that vi's CRLF doesn't get trashed by another vi
  1850.     ${EDITOR-vi} ${TEMP}b
  1851.     if cmp -s ${TEMP}a ${TEMP}b
  1852.     then
  1853.     echo No articles deleted.
  1854.     else
  1855.     comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c
  1856.     echo Removing unwanted articles
  1857.     cp $NEWSRC $NEWSRC.old
  1858.     awk -f $AWKFILE $NEWSRC.old ${TEMP}c > ${TEMP}d
  1859.     cp ${TEMP}d $NEWSRC
  1860.     fi
  1861. else
  1862.     echo No news.
  1863. fi
  1864. !Funky!Stuff!
  1865. echo x - bin/local/nmail
  1866. cat >bin/local/nmail <<'!Funky!Stuff!'
  1867. #/bin/csh
  1868. set found = 0
  1869. set arg = 1
  1870. while($arg <= $#argv)
  1871.     if(`echo $argv[$arg] | grep \!` != "") then
  1872.         set tuple = `echo $argv[$arg] | sed s/\\!/\ /`
  1873.         set upath = `uupath $tuple[1]`
  1874.         set found = $status
  1875.         set argv[$arg] = "$upath\!$tuple[2]"
  1876.     else
  1877.         set found = 0
  1878.     endif
  1879.     if($found != 0) then
  1880.         set argv[$arg]
  1881.     endif
  1882.     @ arg = $arg + 1
  1883. end
  1884. echo "mail $argv"
  1885. mail $argv
  1886.  
  1887. !Funky!Stuff!
  1888. echo x - bin/local/peopledata
  1889. cat >bin/local/peopledata <<'!Funky!Stuff!'
  1890. peoplefile=$HOME/.peopledata
  1891.  
  1892. echo ' '
  1893.  
  1894. case $# in
  1895.     0)
  1896.     ed - $peoplefile << EOF
  1897. g/./s/$/\\
  1898. /
  1899. g/    /s//\\
  1900. /g
  1901. 1,\$p
  1902. q
  1903. EOF
  1904.     exit ;;
  1905. esac
  1906.  
  1907. case $1 in
  1908.     -)
  1909.     chmod 600 $peoplefile
  1910.     vi $peoplefile
  1911.     chmod 400 $peoplefile
  1912.     exit ;;
  1913. esac
  1914. trap "rm /tmp/data$$; exit" 0 2
  1915. for name
  1916. do
  1917.     grep -y "$name" $peoplefile >> /tmp/data$$
  1918. done
  1919. ed - /tmp/data$$ << EOF
  1920. g/./s/$/\\
  1921. /
  1922. g/    /s//\\
  1923. /g
  1924. 1,\$p
  1925. q
  1926. EOF
  1927. !Funky!Stuff!
  1928. echo x - bin/local/phone
  1929. cat >bin/local/phone <<'!Funky!Stuff!'
  1930. peoplefile=$HOME/.peopledata
  1931.  
  1932. case $# in
  1933.     0)
  1934.     ed - $peoplefile << EOF
  1935.     v/-/d
  1936.     g/./s/\([^    ]*\)[^-]*    \(.*-.*\)/\1    \2/
  1937.     1,\$p
  1938. EOF
  1939.     exit ;;
  1940. esac
  1941.  
  1942. case $1 in
  1943.     -)
  1944.     chmod 600 $peoplefile
  1945.     vi $peoplefile
  1946.     chmod 400 $peoplefile
  1947.     exit ;;
  1948. esac
  1949.  
  1950. trap "rm /tmp/data$$; exit" 0 2
  1951. for name
  1952. do
  1953.     grep -y "$name" $peoplefile >> /tmp/data$$
  1954. done
  1955. ed - /tmp/data$$ << EOF
  1956. g/./s/\([^    ]*\)[^-]*    \(.*-.*\)/\1    \2/
  1957. 1,\$p
  1958. q
  1959. EOF
  1960. !Funky!Stuff!
  1961. echo x - bin/local/pk
  1962. cat >bin/local/pk <<'!Funky!Stuff!'
  1963. for dir
  1964. do echo "mkdir $dir";
  1965.     for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'`
  1966.     do    echo "echo x - $file"
  1967.         echo "cat >$file <<'#EOF#'"
  1968.         cat $file; echo "#EOF#"
  1969.     done
  1970.     pk `file $dir/* | sed -n '/directory$/s/:.*//p'`
  1971. done
  1972. !Funky!Stuff!
  1973. echo x - bin/local/save
  1974. cat >bin/local/save <<'!Funky!Stuff!'
  1975. #
  1976. if ("$1" =~ -*) then
  1977.     set suffix=`expr $1 : '-\(.*\)'`
  1978.     shift
  1979.     foreach file ($argv)
  1980.     if (`expr $file:t : '.*'` >= 11) then
  1981.         set savename=`expr $file : '\(.*\)'$file:t`
  1982.         set savename=$savename`expr $file:t : '\(...........\)'`
  1983.     else
  1984.         set savename=$file
  1985.     endif
  1986.     cp $file ${savename}_$suffix && \
  1987.         echo $file saved as ${savename}_$suffix
  1988.     end
  1989.     exit
  1990. endif
  1991. foreach file ($argv)
  1992.     if (`expr $file:t : '.*'` >= 11) then
  1993.     set savename=`expr $file : '\(.*\)'$file:t`
  1994.     set savename=$savename`expr $file:t : '\(...........\)'`
  1995.     else
  1996.     set savename=$file
  1997.     endif
  1998.  
  1999.     set nonomatch
  2000.     set latest=(${savename}_[0-9][0-9])
  2001.     if ("$latest" == "${savename}_[0-9][0-9]") then
  2002.     set latest=${savename}_01
  2003.     else
  2004.     set latest=$latest[$#latest]
  2005.     set latest=`expr $latest : '.*_\([0123456789]*\)$' + 1`
  2006.     if ($latest < 10) set latest=0$latest
  2007.     set latest=${savename}_$latest
  2008.     endif
  2009.     cp $file $latest && echo $file saved as $latest
  2010. end
  2011. !Funky!Stuff!
  2012. echo x - bin/local/shar
  2013. cat >bin/local/shar <<'!Funky!Stuff!'
  2014. : Roff, nroff, or eqn input text
  2015. for file in `file $* | sed -n '/eqn input text$/s/:[^:]*$//p'`
  2016. do
  2017.     echo "echo x - $file"
  2018.     echo "sed 's/^x//' >$file <<'!Funky!Stuff!'"
  2019.     sed 's/^/x/' $file; echo "!Funky!Stuff!"
  2020. done
  2021. : Text files
  2022. for file in `file $* | sed -n -e '/eqn input text$/d' -e '/text$/s/:[^:]*$//p'`
  2023. do
  2024.     echo "echo x - $file"
  2025.     echo "cat >$file <<'!Funky!Stuff!'"
  2026.     cat $file; echo "!Funky!Stuff!"
  2027. done
  2028. : Directories, recursively
  2029. for dir in `file $* | sed -n '/directory$/s/:.*//p'`
  2030. do
  2031.     echo "echo x - $dir"
  2032.     echo "mkdir $dir"
  2033.     file=`echo $dir/*`
  2034.     test "$file" != "$dir/*" && $0 $file
  2035. done
  2036. !Funky!Stuff!
  2037. echo x - bin/local/uuhosts
  2038. cat >bin/local/uuhosts <<'!Funky!Stuff!'
  2039. #!/bin/sh
  2040. # '@(#) uuhosts.sh 1.22 84/08/07'
  2041.  
  2042. # PATH will have to be adjusted for non-BSD systems.
  2043. PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin
  2044. LIB=/usr/lib
  2045.  
  2046. # Routing information produced by pathalias.
  2047. paths=$LIB/nmail.paths
  2048.  
  2049. # The directory $NEWSMAP should contain the USENET news map information
  2050. # from newsgroup net.news.map that is posted about once a month from
  2051. # cbosgd!map, extracted by a line like this in $LIB/news/sys:
  2052. #
  2053. #    newsmap:net.news.map:B:/usr/local/uuhosts -x
  2054. #
  2055. # Locally-known information should go in $LIB/news/net.news.map/Local.
  2056. # The directory $MAILMAP is extracted by the same command from the
  2057. # UUCP mail information posted to the same newsgroup.
  2058. NEWSMAP=$LIB/news/net.news.map
  2059. MAILMAP=$LIB/news/net.mail.map
  2060. cd $NEWSMAP
  2061.  
  2062. case $1 in
  2063.     -x)
  2064.         # extract a new map piece into the map directory
  2065.         temphead=/tmp/maphead.$$
  2066.         temptext=/tmp/maptext.$$
  2067.         awk '
  2068. BEGIN    {
  2069.     temphead = "'$temphead'";
  2070.     isnewsmap = 0; ismailmap = 0;
  2071.     shead = 0; stext = 1; snews = 2; smail = 3; scat = 4; scatting = 5;
  2072.     state = shead;
  2073.     print "Reply-To: news" >> temphead;
  2074. }
  2075. state == shead && /^From: /    {
  2076.     print "Original-" $0 >> temphead;
  2077. }
  2078. state == shead && /^Subject: /    {
  2079.     if ($2 != "Re:")
  2080.     for (x = 2; x <= NF; x++) {
  2081.         if ($x == "UUCPmap" || $x == "uucpmap" || $x == "UUCPMAP") {
  2082.             ismailmap = 1;
  2083.             break;
  2084.         }
  2085.         if ($x == "map" || $x == "Map" || $x == "MAP") {
  2086.             if (x <= 2)
  2087.                 continue;
  2088.             x--;
  2089.             if ($x == "USENET") {
  2090.                 isnewsmap = 1;
  2091.                 break;
  2092.             }
  2093.             if ($x == "UUCP") {
  2094.                 ismailmap = 1;
  2095.                 break;
  2096.             }
  2097.             x++;
  2098.         }
  2099.     }
  2100.     if (!isnewsmap && !ismailmap) {
  2101.         print "Subject:  not a map update" >> temphead;
  2102.         print "Original-" $0 >> temphead;
  2103.     } else
  2104.         print $0 >> temphead;
  2105. }
  2106. state == shead && /^$/    {
  2107.     if (isnewsmap != 0)
  2108.         state = snews;
  2109.     else if (ismailmap != 0) {
  2110.         state = scat;
  2111.     } else
  2112.         state = stext;
  2113.     next;
  2114. }
  2115. state == scat    {
  2116.     if ($1 != "cat")
  2117.         state = scatting;
  2118.     else
  2119.         state = smail;
  2120. }
  2121. state == scatting {
  2122.     if ($1 == ":")
  2123.         state = smail;
  2124.     else
  2125.         print;
  2126. }
  2127. state == smail    {
  2128.     print | "uuhosts -u";
  2129. }
  2130. state == snews    {
  2131.     print | "/bin/sh";
  2132. }
  2133. state == stext    {
  2134.     print;
  2135. }
  2136. ' > $temptext 2>&1
  2137.         cat $temphead $temptext | /bin/mail news
  2138.         rm -f $temphead $temptext
  2139.         exit 0
  2140.     ;;
  2141.  
  2142.     -u)
  2143.         # extract a UUCP map piece
  2144.         cd $MAILMAP
  2145.         /bin/sh
  2146.         for f in *map*.a *map*.ar
  2147.         do
  2148.             ar xv $f
  2149.             rm $f
  2150.         done
  2151.     ;;
  2152.  
  2153.     -g)
  2154.         # by geographical region
  2155.         shift
  2156.         if test $# -eq 0
  2157.         then
  2158.             exec ls
  2159.             exit 1
  2160.         fi
  2161.         exec cat $*
  2162.         exit 1
  2163.     ;;
  2164.  
  2165.     -k)
  2166.         # by keyword
  2167.         shift
  2168.         exec awk '
  2169. BEGIN        { inside = 1; outside = 0; state = outside; }
  2170. /^Name:/    { state = inside; count = 0; useit = 0; }
  2171. state == inside    { block[count++] = $0; }
  2172. /'"$*"'/    { useit = 1; }
  2173. /^$/ && state == inside    {
  2174.     if (useit == 1) {
  2175.         for (i = 0; i < count; i++) {
  2176.             print block[i];
  2177.         }
  2178.     }
  2179.     state = outside;
  2180. }
  2181. ' *
  2182.         exit 1
  2183.     ;;
  2184.  
  2185.     -*)
  2186.         # unknown option
  2187.     ;;
  2188.  
  2189.     "")
  2190.         # no arguments
  2191.     ;;
  2192.  
  2193.     *)
  2194.         # by site name
  2195.         for arg in $*
  2196.         do
  2197.             echo 'UUCP mail path:'
  2198.             grep '^'${arg} $paths
  2199.             echo '
  2200. UUCP mail host information:'
  2201.             cat $MAILMAP/${arg}* | tr % '\012'
  2202.             echo '
  2203. USENET news host information:'
  2204.             sed -n -e "/^Name:[     ]*${arg}/,/^$/p" *
  2205.         done
  2206.         exit 0
  2207.     ;;
  2208. esac
  2209.  
  2210. echo 'Usage:    'uuhosts' hostname ...
  2211. for information about a particular UUCP or USENET host or hosts, or
  2212.  
  2213.     'uuhosts' -g geographical-region
  2214. for information about USENET news sites in a geographical region, or
  2215.  
  2216.     'uuhosts' -g
  2217. for a list of known USENET geographical-regions.
  2218. '
  2219. exit 1
  2220. !Funky!Stuff!
  2221.  
  2222. ::::::::::::::
  2223. shells/4
  2224. ::::::::::::::
  2225. Date: Fri, 14 Sep 84 15:06:07 pdt
  2226. From: hplabs!sdcrdcf!sdcsvax!celerity!barto (David Barto)
  2227. To: sdcsvax!sdcrdcf!hplabs!resonex!nancy
  2228. Subject: Re: Tricks, shell and awk scripts, csh aliases and the like
  2229.  
  2230. Hi Nancy,
  2231.     I too am a 'new' system admin, and belive me, it won't take
  2232.     you too long to get quite a bag of tricks put together.
  2233.  
  2234.     Most of mine relate to source programs put together in
  2235.     shell scripts to keep track of things.
  2236.  
  2237.     I have 1 for news (at the end of the article) which keeps
  2238.     the active list up to date.
  2239.  
  2240.     Another nice program is one I call '#'.  It is owned by root
  2241.     and setuid/setgid to root/daemon.  I use it to 'become' root
  2242.     while doing 1 command
  2243.             # mv file1 file2
  2244.     which requires root permission.  It checks to see the normal
  2245.     userid is 'me' and then allows the command.  I will send it
  2246.     along if you want it.
  2247.  
  2248.     I have shell scripts for doing things such as 'rootedit'
  2249.     a file.  This is an alias for "alias re  '# vi -v \!*'"
  2250.  
  2251.     I too would love to see the things you get back from the
  2252.     net.  As well I have a sendmail config setup for making
  2253.     your configuration a breeze.  If you want it I can send
  2254.     it under seperate cover.
  2255.  
  2256.  
  2257.     barto (david barto)    Tele : (619) 271 9940
  2258.     uucp : {decvax || ucbvax || ihnp4}!sdcsvax!celerity!barto
  2259.     uucp : akgua!celerity!barto
  2260.     arpa : sdcsvax!celerity!barto@NOSC
  2261.  
  2262.  
  2263. : This is a shar archive.  Extract with sh, not csh.
  2264. echo x - Mkactive
  2265. cat > Mkactive << '!Funky!Stuff!'
  2266. #!/bin/sh
  2267. # see Update.active for this usage
  2268. #
  2269. sed -e '1,/---/d'\
  2270.     -e '1,/---/d'\
  2271.     -e 's/^[    ]//'\
  2272.     -e 's/    \(.*\)//'\
  2273.     active.current | sort | sed -e '1,/Newsgroup/d' > current
  2274. sed -e 's/ \(.*\)//' /usr/new/lib/news/active | sort > active
  2275. diff active current > /tmp/active.diff
  2276. echo "# active newsgroups not in local active file:"
  2277. fgrep ">" /tmp/active.diff
  2278. echo "# defunct newsgroups still in active file (also local groups):"
  2279. fgrep "<" /tmp/active.diff
  2280. /bin/rm current active /tmp/active.diff
  2281. !Funky!Stuff!
  2282. echo x - Mkdead
  2283. cat > Mkdead << '!Funky!Stuff!'
  2284. #!/bin/sh
  2285. # see Update.active for usage
  2286. # change all groups that we have (but shouldn't) to be removed,
  2287. # and change all groups that we dont have (but sould) to be a comment
  2288. sed    -e '/general/d'\
  2289.     -e '/control/d' \
  2290.     -e '/junk/d' \
  2291.     -e 's/</rmgroup/' \
  2292.     -e 's/>/#/'
  2293. !Funky!Stuff!
  2294. echo x - rmgroup
  2295. cat > rmgroup << '!Funky!Stuff!'
  2296. #! /bin/sh
  2297. # from : sdcsvax!sdcrdcf!hplabs!hao!seismo!rlgvax!cvl!umcp-cs!eneevax!chris
  2298. #
  2299. # @(#)rmgroup.sh    (U of Maryland) FLB 28-Jun-1983
  2300. #            Bug fixes 5 June 1984 Chris Torek
  2301. #
  2302. # Delete a newsgroup
  2303.  
  2304. lib=/usr/new/lib/news
  2305. spool=/usr/spool/news
  2306.  
  2307. group=$*
  2308.  
  2309. for group
  2310. do
  2311.     qgrp="`echo $group | sed 's/\./\\\./g'`"
  2312.     if
  2313.         grep -s "^$qgrp [0-9][0-9][0-9][0-9][0-9]$" $lib/active
  2314.     then
  2315.         ed - $lib/active << xxxFOOxxx
  2316. /^$qgrp [0-9][0-9][0-9][0-9][0-9]$/d
  2317. w
  2318. q
  2319. xxxFOOxxx
  2320.     else
  2321.         echo "$0: $group: no such active line" 2>&1
  2322.     fi
  2323.  
  2324.     dir=$spool/"`echo $group | sed 's/\./\//g'`"
  2325.     if
  2326.         [ -d "$dir" ]
  2327.     then
  2328.         /bin/rm -fr "$dir"
  2329.     else
  2330.         echo "$0: $dir: no spool directory" 2>&1
  2331.     fi
  2332. done
  2333. exit 0
  2334. !Funky!Stuff!
  2335.  
  2336. ::::::::::::::
  2337. shells/5
  2338. ::::::::::::::
  2339. Date: Thu, 20 Sep 84 01:20:29 pdt
  2340. From: turtlevax!ken (Ken Turkowski)
  2341. To: resonex!nancy
  2342. Subject: Handy new uucp utility: uuque
  2343.  
  2344. cat << EOF
  2345. I just completed a new useful uucp utility which lets you know what kind
  2346. of uucp work is in progress.  While uusnap just tells you the number of
  2347. files to be processed, uuque tells you exactly what kind of work is to
  2348. be performed.  I've only tried it on three kinds of work, namely mail,
  2349. news, and standard uucp transfers.  Give it a try, and see if it breaks
  2350. on any new types of uucp work.
  2351.                 Ken
  2352. P.S. This really should be a C program.
  2353. EOF
  2354. echo x - uuque
  2355. cat >uuque <<'!Funky!Stuff!'
  2356. #! /bin/sh
  2357. # uusnap
  2358. cd /usr/spool/uucp
  2359. LUUNAME=`uuname -l`
  2360.  
  2361. # Check for outgoing work
  2362. for cmdfile in C./*
  2363. do
  2364.     test -f $cmdfile || continue
  2365.     othersys=`expr $cmdfile : 'C./C.\(.*\).....'`
  2366.     cmd=
  2367.     dfile=
  2368.     xfile=
  2369.     ufile=
  2370.     cat $cmdfile | {
  2371.     while read cmd arg1 arg2 arg3 extra
  2372.     do
  2373.         case $cmd in
  2374.         S) ;;
  2375.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra
  2376.             exit ;;
  2377.         esac
  2378.         case $arg1 in
  2379.         D.${LUUNAME}X????)    # Remote execute file
  2380.             xfile=$arg1
  2381.             ;;
  2382.         D.${LUUNAME}?????)    # Data file ref'd by the execute file
  2383.             dfile=$arg1
  2384.             ;;
  2385.         *)            # Just a uucp
  2386.             dfile=$arg1
  2387.             ufile=$arg2
  2388.             from=$arg3
  2389.             ;;
  2390.         esac
  2391.     done
  2392.     case $xfile in
  2393.         "")            # uucp transfer
  2394.         echo `wc -c < $dfile`\     uucp $dfile $othersys!$ufile \($from\)
  2395.         ;;
  2396.         *)            # complex transfer
  2397.         cat D.${LUUNAME}X/$xfile | {
  2398.             while read xcmd arg1 arg2 extra
  2399.             do
  2400.             case $xcmd in
  2401.                 U)
  2402.                 from=$arg2!$arg1
  2403.                 ;;
  2404.                 F)
  2405.                 ;;
  2406.                 I)
  2407.                 ;;
  2408.                 C)
  2409.                 echo `wc -c < D.${LUUNAME}/$dfile`\     $arg1 $othersys!$arg2 \($from\)
  2410.                 ;;
  2411.                 *)
  2412.                 echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2
  2413.                 exit
  2414.                 ;;
  2415.             esac
  2416.             done
  2417.         }
  2418.         ;;
  2419.     esac
  2420.     }
  2421. done
  2422.  
  2423. # Check for incoming work
  2424. for cmdfile in X./*
  2425. do
  2426.     test -f $cmdfile || continue
  2427.     othersys=`expr $cmdfile : 'X./X.\(.*\).....'`
  2428.     cat $cmdfile | {
  2429.     while read cmd arg1 arg2 extra
  2430.     do
  2431.         case $cmd in
  2432.         U)
  2433.             from=$arg2!$arg1
  2434.             ;;
  2435.         Z)
  2436.             ;;
  2437.         F)
  2438.             if test -f D./$arg1
  2439.             then
  2440.             dfile=D./$arg1
  2441.             elif test -f D./$arg2
  2442.             then
  2443.             dfile=D./$arg2
  2444.             else
  2445.             continue 2
  2446.             fi
  2447.             ;;
  2448.         C)
  2449.             xcmd=$arg1
  2450.             ;;
  2451.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra
  2452.             exit ;;
  2453.         esac
  2454.     done
  2455.     echo `wc -c < $dfile`\     $xcmd $dfile \($from\)
  2456.     }
  2457. done
  2458. !Funky!Stuff!
  2459.  
  2460. ::::::::::::::
  2461. shells/6
  2462. ::::::::::::::
  2463. Date: Sat, 22 Sep 84 01:22:39 pdt
  2464. From: turtlevax!ken (Ken Turkowski)
  2465. To: resonex!nancy
  2466. Subject: Re:  uuque 
  2467.  
  2468. I've updated uuque to the point where it should probably instead be called
  2469. uusnoop.  Of course, it's not that interesting unless there are others on
  2470. your system that use uucp and net mail.
  2471.  
  2472.             Ken
  2473.  
  2474. echo x - uuque
  2475. cat >uuque <<'!Funky!Stuff!'
  2476. #! /bin/sh
  2477. # The user must have access to the /usr/spool/uucp/* directories and files.
  2478. # This can be easily done by making certain users members of the daemon
  2479. # and/or uucp groups, or by becoming super-user.
  2480. # uusnap
  2481. cd /usr/spool/uucp
  2482. LUUNAME=`uuname -l`
  2483.  
  2484. # Check for outgoing work
  2485. for cmdfile in C./*
  2486. do
  2487.     test -f $cmdfile || continue
  2488.     othersys=`expr $cmdfile : 'C./C.\(.*\).....'`
  2489.     cmd=
  2490.     dfile=
  2491.     xfile=
  2492.     ufile=
  2493.     cat $cmdfile | {
  2494.     while read cmd arg1 arg2 arg3 extra
  2495.     do
  2496.         case $cmd in
  2497.         S)                # uucp send
  2498.             case $arg1 in
  2499.             D.${LUUNAME}X????)    # Remote execute file
  2500.                 xfile=$arg1
  2501.                 ;;
  2502.             D.${LUUNAME}?????)    # Data file ref'd by xfile
  2503.                 dfile=D.${LUUNAME}/$arg1
  2504.                 ;;
  2505.             *)        # Just a uucp -- no intertpretation
  2506.                 echo `wc -c < $arg1`\     uucp $arg1 $othersys!$arg2 \($arg3\)
  2507.                 ;;
  2508.             esac
  2509.             ;;
  2510.         R)        # uucp receive
  2511.             echo '    ' uucp $othersys!$arg1 $arg2 \($arg3\)
  2512.             ;;
  2513.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra
  2514.             continue ;;
  2515.         esac
  2516.     done
  2517.     case $xfile in
  2518.         "")            # uucp transfer
  2519.         continue
  2520.         ;;
  2521.     esac
  2522.     cat D.${LUUNAME}X/$xfile | {    # complex transfer -- interpret xfile
  2523.         while read xcmd arg1 arg2 extra
  2524.         do
  2525.         case $xcmd in
  2526.             U)
  2527.             from=$arg2!$arg1
  2528.             ;;
  2529.             F)
  2530.             ;;
  2531.             I)
  2532.             ;;
  2533.             Z)
  2534.             ;;
  2535.             C)
  2536.             case $arg1 in
  2537.                 rmail)
  2538.                 from=`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )`
  2539.                 echo `wc -c < $dfile`\     $arg1 $othersys!$arg2 \($from\)
  2540.                 echo -n '     '
  2541.                 grep '^Subject:' $dfile || echo ''
  2542.                 ;;
  2543.                 rnews)
  2544.                 echo `wc -c < $dfile`\     $arg1 $othersys  \($from\)
  2545.                 echo -n '     '
  2546.                 grep '^Newsgroups:' $dfile
  2547.                 echo -n '     '
  2548.                 grep '^Subject:' $dfile
  2549.                 ;;
  2550.                 *)
  2551.                 echo `wc -c < $dfile`\     $arg1 $arg2 $extra [$othersys $dfile] \($from\)
  2552.                 ;;
  2553.             esac
  2554.             ;;
  2555.             *)
  2556.             echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2
  2557.             exit
  2558.             ;;
  2559.         esac
  2560.         done
  2561.     }
  2562.     }
  2563. done
  2564.  
  2565. # Check for incoming work
  2566. for cmdfile in X./*
  2567. do
  2568.     test -f $cmdfile || continue
  2569.     othersys=`expr $cmdfile : 'X./X.\(.*\).....'`
  2570.     comment=
  2571.     cat $cmdfile | {
  2572.     while read cmd arg1 arg2 extra
  2573.     do
  2574.         case $cmd in
  2575.         U)
  2576.             from=$arg2!$arg1
  2577.             ;;
  2578.         Z)
  2579.             ;;
  2580.         I)
  2581.             ;;
  2582.         F)
  2583.             if test -f D./$arg1
  2584.             then
  2585.             dfile=D./$arg1
  2586.             elif test -f XTMP/$arg2
  2587.             then
  2588.             dfile=XTMP/$arg2
  2589.             comment="(EXECUTING)"
  2590.             else
  2591.             continue 2
  2592.             fi
  2593.             ;;
  2594.         C)
  2595.             xcmd=$arg1
  2596.             xargs="$arg2 $extra"
  2597.             case $arg1 in
  2598.             rmail)
  2599.                 from=$othersys!`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )`
  2600.                 echo -n '     '
  2601.                 grep '^Subject:' $dfile || echo ''
  2602.                 ;;
  2603.             esac
  2604.             ;;
  2605.         *)  echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra
  2606.             continue ;;
  2607.         esac
  2608.     done
  2609.     echo `wc -c < $dfile`\     $xcmd $xargs $comment \($from\)
  2610.     }
  2611. done
  2612. !Funky!Stuff!
  2613.