home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4225 / rfcget < prev   
Encoding:
Text File  |  1992-12-21  |  5.1 KB  |  253 lines

  1. #! /bin/csh -f
  2.  
  3. ########################################################################
  4. #
  5. #       Copyright 1992 by the Massachusetts Institute of Technology.
  6. #       All rights reserved.
  7. #
  8. #       Developed by the Intelligent Engineering Systems Laboratory
  9. #       M.I.T., Cambridge, Massachusetts.
  10. #
  11. #    THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
  12. #       OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not 
  13. #       limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF 
  14. #       MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR 
  15. #    THAT THE USE OF THE LISCENCED SOFTWARE OR DOCUMENTATION WILL NOT 
  16. #    INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER 
  17. #       RIGHTS.
  18. #
  19. #    The name of Massachusetts Institute of Technology or M.I.T. may
  20. #    NOT be used in advertising or publicity pertaining to distribution
  21. #    of the software. Title to copyright in this software and any 
  22. #    associated documentation shall at all times remain with M.I.T., 
  23. #    and USER agrees to preserve the same.
  24. #
  25. #    Permission to use, copy, modify, and distribute this material 
  26. #    for any purpose and without fee is hereby granted, provided that 
  27. #    the above copyright notice and this permission notice appear in 
  28. #    all copies.
  29. #
  30. ########################################################################
  31.  
  32.  
  33.  
  34.  
  35. #look for environment variable for dumping directory......
  36.  
  37. setenv | grep RFC_DIR >&! /dev/null
  38. if ( $status ) then
  39.     setenv RFC_DIR `pwd`
  40.     echo "You have not specified a directory to place the"
  41.     echo "rfc index and retrieved rfc files. These will be"
  42.     echo "placed in $RFC_DIR."
  43.     echo "To specify a directory set the RFC_DIR environment variable"
  44.     echo ""
  45.     echo ""
  46. endif
  47.  
  48. ##################################################################
  49. #    archive site
  50. #
  51. #    CHANGE THIS VARIABLE TO ACCESS A DIFFERENT ARCHIVE SITE!!!
  52. #
  53. ##################################################################
  54.  
  55. set rfc_archive = ftp.nisc.sri.com
  56.  
  57. #Various and sundry other variables
  58.  
  59. #set index_name = rfc-index-title-first.txt
  60. set index_name = rfc-index.txt
  61. set local_dir = $RFC_DIR
  62. set remote_dir = rfc 
  63. set rfcnum = ()
  64. set resp = y
  65.  
  66. # this is another hack that I should fix someday....
  67. set charlist = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
  68.  
  69. # Look for local copy of rfc index.
  70.  
  71. if ( ! -e $RFC_DIR/$index_name ) then
  72.     echo "Local copy of rfc index not found in $RFC_DIR."
  73.     echo "(Forget to set your RFC_DIR environment variable?)."
  74.     echo "This command will force a sync."
  75.     setenv SYNC_ME 1
  76. else
  77.     setenv SYNC_ME 0
  78. endif
  79.  
  80. # Usage statement
  81.  
  82. if $#argv == 0 then
  83.     echo "Usage: get_rfc [options] [rfc-num list]"
  84.     echo "options"
  85.     echo "    -i    interactive file request"
  86.     echo "    -t    search for internet topic"
  87.     echo "    -s    sync local index with archive site"
  88.     goto DONE
  89. endif
  90.  
  91. #process topic and sync before processing interactive
  92.  
  93. # If there is no index we do a sync. First
  94. # scan arglist and delete sync requests. Then
  95. # prepend sync option. It works anyway.....
  96.  
  97. if $SYNC_ME then
  98.     set cpy = ( $argv )
  99.     set cpy1 = ""
  100.     while ( $#cpy > 0 )
  101.         switch ( $cpy[1] )
  102.  
  103.             case "-s":
  104.                 breaksw
  105.  
  106.             default:
  107.                 set cpy1 = "$cpy1 $cpy[1]"
  108.         endsw
  109.     shift cpy
  110.     end
  111.  
  112.     set cpy1 = "-s $cpy1"
  113.     set argv = ( $cpy1 )
  114. endif
  115.  
  116. set cpy = ( $argv )
  117.  
  118. FIRST_ARG_LOOP:
  119. while ( $#cpy > 0 )
  120. switch ( $cpy[1] )
  121.  
  122.     case "-t":
  123.         shift cpy
  124.         set again = y
  125.         while ( $again == y )
  126.             echo -n "Enter topic: "
  127.             set resp = "$<"
  128.             if ( "$resp" != "" ) then
  129.                 egrep -i "$resp" $RFC_DIR/$index_name
  130.             endif
  131.             set again = "n"
  132.             echo -n "Search again? (y/n) [n]: "
  133.             set again = $<
  134.             if ( "$again" != "" ) then
  135.                 set again = `expr substr "$again" 1 1`
  136.             endif
  137.         end
  138.         breaksw
  139.  
  140.     case "-s":
  141.         shift cpy
  142.         echo "Syncing local index with copy at $rfc_archive"
  143.         set file_list = $index_name
  144.         goto DO_FETCH
  145.         breaksw        
  146.  
  147.     default:
  148.         shift cpy
  149. endsw
  150. end
  151.  
  152. set cpy = ( $argv )
  153.  
  154. SECOND_ARG_LOOP:
  155. while ( $#cpy > 0 )
  156. switch ( $cpy[1] )
  157.  
  158.     case "-s":
  159.     case "-t":
  160.         shift cpy
  161.         breaksw
  162.  
  163.     case "-i"
  164.         shift cpy
  165.         echo -n "Get RFC Number(s): "
  166.         set rfcnum =  ( $< )
  167.  
  168.     default:
  169.         set num_list = ( $cpy $rfcnum )
  170.  
  171.         while( $#num_list > 0 )
  172.             set not_num = `expr index $num_list[1] $charlist`
  173.             if ( $not_num ) then
  174.                 echo Bad rfc number $num_list[1]. EXIT.
  175.                 exit 1
  176.             endif
  177.  
  178.             shift num_list
  179.         end
  180.         set rfcnum = ( $cpy $rfcnum )
  181.         break
  182. endsw
  183. end
  184.  
  185.  
  186. FETCH:
  187. #
  188. # if there's nothing in the rfcnum variable, quit.
  189. #
  190.  
  191. if ( $#rfcnum == 0 ) goto DONE
  192.  
  193. #
  194. # Build the file list from the index number list
  195. #
  196.  
  197. set file_list = ()
  198. foreach f_index ( $rfcnum )
  199.     set file_list = ( $file_list rfc$f_index.txt )
  200. end
  201.  
  202. echo "Getting the following files from from $rfc_archive;"
  203. foreach file ( $file_list )
  204.     echo $file
  205. end 
  206.  
  207. echo -n "Continue? y/n [y]: "
  208. set resp = $<
  209. if ( "$resp" == "n" ) then
  210.     echo ABORT
  211.     goto DONE
  212. endif
  213.  
  214.  
  215. #
  216. # Do the fetch!!
  217. #
  218.  
  219. DO_FETCH:
  220.  
  221. ftp -n -i << +
  222. open $rfc_archive
  223. user anonymous culbert@iesl.mit.edu
  224. cd $remote_dir
  225. lcd $local_dir
  226. bin
  227. mget $file_list
  228. bye
  229. +
  230.  
  231. # If this was a forced sync, return to the argument processing loops.
  232.  
  233. if $SYNC_ME then 
  234.     setenv SYNC_ME 0
  235.     goto FIRST_ARG_LOOP
  236. endif
  237.  
  238. #
  239. # List the files locally to give a little confidence that all went well...
  240.  
  241. pushd $local_dir >&! /dev/null
  242. ls -l $file_list
  243. popd >&! /dev/null
  244.  
  245. #
  246. # BYE!!!!
  247. #
  248.  
  249. DONE:
  250.  
  251. exit 0
  252.  
  253.