home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / shellforms / part01 / Lib < prev    next >
Encoding:
Text File  |  1988-05-09  |  8.5 KB  |  283 lines

  1. #! /bin/csh -f
  2. #
  3. #-    gsglib - GSG library on-line query
  4. #-
  5. #    Author:        Paul Lew, General Systems Group, Inc.
  6. #    Created at:    08/15/86  04:18 PM
  7. #    Last update:    01/26/88  12:31 PM  (Edition: 8)
  8. #
  9. #-    Usage:        gsglib <CR>
  10. #
  11. #---------------------------------------------------------------#
  12. #          Display help if requested by user            #
  13. #---------------------------------------------------------------#
  14. switch ( "$1" )
  15.     case -H[xX]:
  16.         set echo; set verbose; shift
  17.         breaksw
  18.     case -H*:
  19.         show_help `which $0` $1
  20.         goto end
  21.     default:
  22.     endsw
  23. #---------------------------------------------------------------#
  24. #            Process Arguments            #
  25. #---------------------------------------------------------------#
  26. set libfile = '/gsg/lew/dat/gsglib.dat'
  27. set tmpfile = "/tmp/gsglib.$$"
  28. unsetenv LESS
  29. #---------------------------------------------------------------#
  30. #    Display main menu and get user input (use sf)        #
  31. #---------------------------------------------------------------#
  32. loop:
  33. set srcfile = "/tmp/gsglib$$"
  34. sf -o ${srcfile} -u << sf_eof
  35.     General Systems Group Library Directory
  36.  
  37.      Operation: ~~~~~~~    [choice: find add new print keyword help quit]
  38.  
  39.  
  40.      Book number:   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41.      ~~~  Keyword:      ~~~~~~~~~~~~~~~
  42.      ~~~  Author:      ~~~~~~~~~~~~~~~~~~~~~~~~
  43.      ~~~  Title:      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44.      ~~~  Date published: ~~~~~~~~~~~~~
  45.      ~~~  Publisher:      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46.      ~~~  Book id:      ~~~~~~~~~~~~~~~~~~~~~~~
  47.      ~~~  Number of pages:~~~~~
  48.  
  49.      ^
  50.      +------ enter "y" to include in the output list
  51.  
  52.     [Press TAB to move to next field, RETURN to execute]
  53.  
  54. .v=opcode.s=/find/add/new/print/keyword/help/quit.
  55. .h=find out what books has the data we want.
  56. .h=add new books to library.
  57. .h=see what are the new books since last use.
  58. .h=print out previous output to printer.
  59. .h=display all the predefined keywords that are valid for keyword search field.
  60. .h=display help message about how to use this program.
  61. .h=quit, exit back to Unix.
  62. .v=bookno.
  63. .v=selkw.s=/No/Yes.v=keyword.
  64. .v=selau.s=/Yes/No.v=author.
  65. .v=selti.s=/Yes/No.v=title.
  66. .v=selpd.s=/Yes/No.v=pdate.
  67. .v=selpu.s=/Yes/No.v=pub.
  68. .v=selbi.s=/No/Yes.v=bookid.
  69. .v=selsz.s=/No/Yes.v=size.
  70. sf_eof
  71. #---------------------------------------------------------------#
  72. #    Get symbol defined for the current process        #
  73. #---------------------------------------------------------------#
  74. if ( ! -e ${srcfile} ) goto end
  75. source ${srcfile}
  76. /bin/rm -f ${srcfile}
  77. #---------------------------------------------------------------#
  78. #            Execute user request            #
  79. #---------------------------------------------------------------#
  80. #echo "author=[${author}] output select=[${selau}]"
  81. #echo "keyword=[${keyword}] output select=[${selkw}]"
  82. #echo "title=[${title}] output select=[${selti}]"
  83. #echo "pdate=[${pdate}] output select=[${selpd}]"
  84. #echo "pub=[${pub}] output select=[${selpu}]"
  85. #echo "press return: "
  86. #set yon = "$<"
  87. if ( "${bookno}" == "vi" ) then
  88.     goto libvi
  89.     endif
  90. switch ( "${opcode}" )
  91.     case "find":
  92.         goto libfind
  93.     case "add":
  94.         goto libadd
  95.     case "new":
  96.         goto libnew
  97.     case "print":
  98.         goto libprint
  99.     case "keyword":
  100.         goto libkeyword
  101.     case "help":
  102.         goto libhelp
  103.     case "quit":
  104.         goto end
  105.     default:
  106.         echo "Unknown command: ${opcode}"
  107.         sleep 2
  108.         goto loop
  109.         breaksw
  110.     endsw
  111. #---------------------------------------------------------------#
  112. #        add a new record to library file        #
  113. #---------------------------------------------------------------#
  114. libfind:
  115.     cat /dev/null > ${tmpfile}
  116.     set outsel
  117.     if ( "${selkw}" == "Yes" ) set outsel = "${outsel}K"
  118.     if ( "${selau}" == "Yes" ) set outsel = "${outsel}A"
  119.     if ( "${selti}" == "Yes" ) set outsel = "${outsel}T"
  120.     if ( "${selpd}" == "Yes" ) set outsel = "${outsel}D"
  121.     if ( "${selpu}" == "Yes" ) set outsel = "${outsel}P"
  122.     if ( "${selbi}" == "Yes" ) set outsel = "${outsel}N"
  123.     if ( "${selsz}" == "Yes" ) set outsel = "${outsel}S"
  124.     if ( "${outsel}" == "" ) then
  125.         echo -n "No output selection"
  126.         goto getret
  127.         endif
  128.     if ( "${bookno}" != "" ) then
  129.         set recno = (${bookno})
  130.         goto grepno
  131.         endif
  132.     if ( "${keyword}" != "" ) then
  133.         grep '^#K' ${libfile} | grep -i "${keyword}" >> ${tmpfile}
  134.         endif
  135.     if ( "${author}" != "" ) then
  136.         grep '^#A' ${libfile} | grep -i "${author}" >> ${tmpfile}
  137.         endif
  138.     if ( "${title}" != "" ) then
  139.         grep '^#T' ${libfile} | grep -i "${title}" >> ${tmpfile}
  140.         endif
  141.     if ( "${pdate}" != "" ) then
  142.         grep '^#D' ${libfile} | grep -i "${pdate}" >> ${tmpfile}
  143.         endif
  144.     if ( "${pub}" != "" ) then
  145.         grep '^#P' ${libfile} | grep -i "${pub}" >> ${tmpfile}
  146.         endif
  147.     if ( "${bookid}" != "" ) then
  148.         grep '^#N' ${libfile} | grep -i "${bookid}" >> ${tmpfile}
  149.         endif
  150.     if ( "${size}" != "" ) then
  151.         grep '^#S' ${libfile} | grep -i "${size}" >> ${tmpfile}
  152.         endif
  153.     if ( -z ${tmpfile} ) then
  154.         echo -n "No related information"
  155.         goto getret
  156.     else
  157.         set recno = `awk '{ print $2 }' ${tmpfile} | sort -u`
  158.         cat /dev/null > ${tmpfile}
  159. grepno:
  160.         foreach rec (${recno})
  161.             bm "${rec}" ${libfile} | awk 'NF>2' | \
  162.             grep "^#[${outsel}]" >> ${tmpfile}
  163.             echo "---------------------------" >> ${tmpfile}
  164.             end
  165.         less -pcu ${tmpfile}
  166.         endif
  167.     goto loop
  168. #---------------------------------------------------------------#
  169. #        add a new record to library file        #
  170. #---------------------------------------------------------------#
  171. libadd:
  172.     if ( "${user}" != "secrtary" && "${user}" != "chicca" && ${user} != "lew" ) then
  173. err:
  174.         echo -n '...Sorry, only secretary can update library info'
  175.         goto getret
  176.         breaksw
  177.         endif
  178.     if ( "${title}" == "" ) then
  179.         echo "...You can not add a record without title..."
  180.         sleep 1
  181.         goto loop
  182.         endif
  183.     @ rec = `tail -1 ${libfile} | awk '{print $2}'`
  184.     @ rec ++
  185.     set recno = "${rec}"
  186.     if ( $rec < 1000 ) set recno = "0${recno}"
  187.     if ( $rec < 100 ) set recno = "0${recno}"
  188.     if ( $rec < 10 ) set recno = "0${recno}"
  189.     cat >> ${libfile} << cat_eof
  190.  
  191. #K ${recno}    ${keyword}
  192. #A ${recno}    ${author}
  193. #P ${recno}    ${pub}
  194. #T ${recno}    ${title}
  195. #N ${recno}    ${bookid}
  196. #D ${recno}    ${pdate}
  197. #S ${recno}    ${size}
  198. #R ${recno}    `date`
  199. cat_eof
  200.     echo "Record ${recno} has been added successfully"
  201.     sleep 1
  202.     goto loop
  203. #---------------------------------------------------------------#
  204. #        show all new books since last check            #
  205. #---------------------------------------------------------------#
  206. libnew:
  207.     if ( ! -e ~/.gsgbook ) then
  208.         @ old = 0
  209.     else
  210.         @ old = `cat ~/.gsgbook`
  211.         endif
  212.     grep '^#T' ${libfile} | awk        \
  213.     'BEGIN            { p = 0 }    \
  214.      p == 1            { print }    \
  215.      $2 ~ /'"${old}"'/    { p = 1 }' | less -pcu
  216.     tail -1 ${libfile} | awk '{ print $2 }' > ~/.gsgbook
  217.     goto loop
  218. #---------------------------------------------------------------#
  219. #       display all possible keyword defined            #
  220. #---------------------------------------------------------------#
  221. libkeyword:
  222.     (echo "...Possible Keywords List in Library...";    \
  223.      grep '^#K' ${libfile} | awk                \
  224.      '{ for (i=3; i<=NF; i++) {                \
  225.         print $i;                    \
  226.         }                        \
  227.       }') | sort -u | awk                    \
  228.     'NR == 1 { print }                    \
  229.      NR > 1    {                        \
  230.         printf "%-18s", $0;                \
  231.         if (++i % 4 == 0) printf "\n";            \
  232.         }                        \
  233.      END    { if (i % 4 != 0) printf "\n"; }' | less -pcu
  234.     goto loop
  235. #---------------------------------------------------------------#
  236. #        print previous located collection of data        #
  237. #---------------------------------------------------------------#
  238. libprint:
  239.     if ( -e ${tmpfile} && ! -z ${tmpfile} ) then
  240.         print ${tmpfile}
  241.     else
  242.         echo -n "Nothing to print"
  243. getret:
  244.         echo -n ", press RETURN to continue: "
  245.         set yon = "$<"
  246.         endif
  247.     goto loop
  248. #---------------------------------------------------------------#
  249. #      run vi on the library file (undocumented feature)    #
  250. #---------------------------------------------------------------#
  251. libvi:
  252.     vi ${libfile}
  253.     goto loop
  254. #---------------------------------------------------------------#
  255. #       display usage guide for inexperience users        #
  256. #---------------------------------------------------------------#
  257. libhelp:
  258.     cat << cat_eof
  259. add    add a new record into library database, privilege required
  260. new    display what new books has arrived since last use
  261. find    search for proper information
  262. help    display this usage guide
  263. keyword    show all current available keywords
  264. print    print the result from the last find command
  265. quit    exit
  266.  
  267. You may enter search string in any of the fields (grep -i will be used
  268. in each occassion). If you specify book numbers, all the other fields
  269. will be ignored.
  270.  
  271. The one character fields at the beginning of each field is output
  272. select, if it is 'y', it will be included in the output.
  273.  
  274. cat_eof
  275.     echo -n "End of help info"
  276.     goto getret
  277. #---------------------------------------------------------------#
  278. #        Clean up and exit here...            #
  279. #---------------------------------------------------------------#
  280. end:
  281.     /bin/rm -f ${tmpfile}
  282.     unset fnames fname srcfile tmpfile
  283.