home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / savesrc / note < prev    next >
Encoding:
Text File  |  1986-11-30  |  2.2 KB  |  145 lines

  1. #!/bin/sh
  2. #
  3. #    Note:     manage notes on program sources
  4. #
  5. #             Copyright (c) Chris Robertson 1985
  6. #
  7. #    This script adds lines from standard input to a file called NOTES
  8. #    in the current directory, or views/edits the file.  It is intended
  9. #    for keeping notes on software slurped from the net.
  10. #    The format of NOTES is:
  11. #    
  12. #    progname:    [date] comments ...
  13. #    (1 tab)    more comments
  14. #    (blank line)
  15. #
  16. #    Usage:  note [-e] [-s] [-r [program ...]]
  17. #
  18. #    No options:        add a NOTE.
  19. #    -e:                edit the NOTES file.
  20. #    -r:                show all notes on the given program(s), or the entire
  21. #                    NOTES file (unsorted) if no program is given.
  22. #    -s:                show the entire NOTES file, sorted so all notes on a
  23. #                    given program occur together.
  24. #
  25.  
  26. PAGER=${PAGER-/usr/local/bin/more}
  27. case "$PAGER" in
  28.     "")                        # in case it's explicitly set to nothing
  29.         PAGER=cat
  30.         ;;
  31. esac
  32.  
  33. case "$VISUAL" in
  34.     "")
  35.         case "$EDITOR" in
  36.             "")
  37.                 ;;
  38.             *)
  39.                 VISUAL=$EDITOR
  40.                 ;;
  41.         esac
  42.         ;;
  43. esac
  44. VISUAL=${VISUAL-/usr/bin/vi}
  45. case "$VISUAL" in
  46.     "")                        # in case it's explicitly set to nothing
  47.         VISUAL=/bin/ed
  48.         ;;
  49. esac
  50.  
  51. trap "rm -f /tmp/note$$;exit" 0 1 2 3
  52.  
  53. # find which echo we're using
  54.  
  55. case "`echo -n foo`" in
  56.     -n*)
  57.         c="\c"
  58.         n=""
  59.         ;;
  60.     foo)
  61.         c=""
  62.         n="-n"
  63.         ;;
  64.     *)
  65.         echo "Your echo command is broken!"
  66.         c=
  67.         n=
  68.         ;;
  69. esac
  70.  
  71. usage="Usage: $0 [-e] [-s] [-r [prog ...]]"
  72.  
  73. case "$#" in
  74.     0)
  75.         ;;
  76.     1)
  77.         case "$1" in
  78.             -r)
  79.                 $PAGER NOTES
  80.                 exit 0
  81.                 ;;
  82.             -s)
  83.                 list="`sed -e '/^    /d' -e 's/:.*//' NOTES | sort -u`"
  84.                 for i in $list
  85.                     do
  86.                     note -r $i >> /tmp/note$$
  87.                 done
  88.                 $PAGER /tmp/note$$
  89.                 rm -f /tmp/note$$
  90.                 exit 0
  91.                 ;;
  92.             -e)
  93.                 $VISUAL NOTES
  94.                 exit 0
  95.                 ;;
  96.             *)
  97.                 echo $usage
  98.                 exit 1
  99.                 ;;
  100.         esac
  101.         ;;
  102.     *)
  103.         case "$1" in
  104.             -r)
  105.                 shift
  106.                 for prog in $*
  107.                     do
  108.                     case "$PAGER" in
  109.                         *cat)
  110.                             sed -n -e "/^${prog}:/,/^\$/p" NOTES
  111.                             ;;
  112.                         *)
  113.                             sed -n -e "/^${prog}:/,/^\$/p" NOTES | $PAGER
  114.                             ;;
  115.                     esac
  116.                 done
  117.                 exit 0
  118.                 ;;
  119.             *)
  120.                 echo $usage
  121.                 exit 1
  122.                 ;;
  123.         esac
  124.         ;;
  125. esac
  126. date="`set - \`date\`;echo $2 $3 $6`"
  127. echo $n "Program name: $c"
  128. read prog
  129. echo $n "> $c"
  130. read line
  131. echo "${prog}:    [$date] $line" >> NOTES
  132. line=
  133. while :
  134.     do
  135.     echo $n "> $c"
  136.     read line
  137.     case "$line" in
  138.         .)
  139.             break
  140.             ;;
  141.     esac
  142.     echo "    $line" >> NOTES
  143. done
  144. echo "" >> NOTES
  145.