home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume34 / rfcget / part01 < prev    next >
Encoding:
Text File  |  1992-12-20  |  10.4 KB  |  408 lines

  1. Newsgroups: comp.sources.misc
  2. From: culbert@ninja-turtle.MIT.EDU (Jim Culbert)
  3. Subject: v34i084:  rfcget - RFC retrieval mechanism, Part01/01
  4. Message-ID: <1992Dec21.161305.27677@sparky.imd.sterling.com>
  5. X-Md4-Signature: d27192d930926b39de7b3fd85154b98f
  6. Date: Mon, 21 Dec 1992 16:13:05 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: culbert@ninja-turtle.MIT.EDU (Jim Culbert)
  10. Posting-number: Volume 34, Issue 84
  11. Archive-name: rfcget/part01
  12. Environment: Internet, C-shell
  13.  
  14. rfcget is a c-shell script which facilitates  the  retrieval
  15. of Request For Comments (RFC) Documents. The script supports
  16. two functions; topic searching, rfc document retrieval.  The
  17. script  uses  a  local  copy of the rfc index file for topic
  18. searches. This index must be located in a directory named by
  19. the  environment  variable RFC_DIR. If you choose not to set
  20. this variable, the script uses the local directory.  RFC_DIR
  21. is  also  used as the location where retrieved documents are
  22. placed. You are warned by the script if this variable  isn't
  23. set.  If the index file is not found when the script is run,
  24. the tool "syncs" with a nic server copy then  proceeds  with
  25. argument processing.
  26.  
  27. Jim
  28. ---------
  29. #! /bin/sh
  30. # This is a shell archive.  Remove anything before this line, then feed it
  31. # into a shell via "sh file" or similar.  To overwrite existing files,
  32. # type "sh file -c".
  33. # Contents:  rfcget rfcget.1
  34. # Wrapped by kent@sparky on Mon Dec 21 10:07:09 1992
  35. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  36. echo If this archive is complete, you will see the following message:
  37. echo '          "shar: End of archive 1 (of 1)."'
  38. if test -f 'rfcget' -a "${1}" != "-c" ; then 
  39.   echo shar: Will not clobber existing file \"'rfcget'\"
  40. else
  41.   echo shar: Extracting \"'rfcget'\" \(5258 characters\)
  42.   sed "s/^X//" >'rfcget' <<'END_OF_FILE'
  43. X#! /bin/csh -f
  44. X
  45. X########################################################################
  46. X#
  47. X#       Copyright 1992 by the Massachusetts Institute of Technology.
  48. X#       All rights reserved.
  49. X#
  50. X#       Developed by the Intelligent Engineering Systems Laboratory
  51. X#       M.I.T., Cambridge, Massachusetts.
  52. X#
  53. X#    THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
  54. X#       OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not 
  55. X#       limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF 
  56. X#       MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR 
  57. X#    THAT THE USE OF THE LISCENCED SOFTWARE OR DOCUMENTATION WILL NOT 
  58. X#    INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER 
  59. X#       RIGHTS.
  60. X#
  61. X#    The name of Massachusetts Institute of Technology or M.I.T. may
  62. X#    NOT be used in advertising or publicity pertaining to distribution
  63. X#    of the software. Title to copyright in this software and any 
  64. X#    associated documentation shall at all times remain with M.I.T., 
  65. X#    and USER agrees to preserve the same.
  66. X#
  67. X#    Permission to use, copy, modify, and distribute this material 
  68. X#    for any purpose and without fee is hereby granted, provided that 
  69. X#    the above copyright notice and this permission notice appear in 
  70. X#    all copies.
  71. X#
  72. X########################################################################
  73. X
  74. X
  75. X
  76. X
  77. X#look for environment variable for dumping directory......
  78. X
  79. Xsetenv | grep RFC_DIR >&! /dev/null
  80. Xif ( $status ) then
  81. X    setenv RFC_DIR `pwd`
  82. X    echo "You have not specified a directory to place the"
  83. X    echo "rfc index and retrieved rfc files. These will be"
  84. X    echo "placed in $RFC_DIR."
  85. X    echo "To specify a directory set the RFC_DIR environment variable"
  86. X    echo ""
  87. X    echo ""
  88. Xendif
  89. X
  90. X##################################################################
  91. X#    archive site
  92. X#
  93. X#    CHANGE THIS VARIABLE TO ACCESS A DIFFERENT ARCHIVE SITE!!!
  94. X#
  95. X##################################################################
  96. X
  97. Xset rfc_archive = ftp.nisc.sri.com
  98. X
  99. X#Various and sundry other variables
  100. X
  101. X#set index_name = rfc-index-title-first.txt
  102. Xset index_name = rfc-index.txt
  103. Xset local_dir = $RFC_DIR
  104. Xset remote_dir = rfc 
  105. Xset rfcnum = ()
  106. Xset resp = y
  107. X
  108. X# this is another hack that I should fix someday....
  109. Xset charlist = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
  110. X
  111. X# Look for local copy of rfc index.
  112. X
  113. Xif ( ! -e $RFC_DIR/$index_name ) then
  114. X    echo "Local copy of rfc index not found in $RFC_DIR."
  115. X    echo "(Forget to set your RFC_DIR environment variable?)."
  116. X    echo "This command will force a sync."
  117. X    setenv SYNC_ME 1
  118. Xelse
  119. X    setenv SYNC_ME 0
  120. Xendif
  121. X
  122. X# Usage statement
  123. X
  124. Xif $#argv == 0 then
  125. X    echo "Usage: get_rfc [options] [rfc-num list]"
  126. X    echo "options"
  127. X    echo "    -i    interactive file request"
  128. X    echo "    -t    search for internet topic"
  129. X    echo "    -s    sync local index with archive site"
  130. X    goto DONE
  131. Xendif
  132. X
  133. X#process topic and sync before processing interactive
  134. X
  135. X# If there is no index we do a sync. First
  136. X# scan arglist and delete sync requests. Then
  137. X# prepend sync option. It works anyway.....
  138. X
  139. Xif $SYNC_ME then
  140. X    set cpy = ( $argv )
  141. X    set cpy1 = ""
  142. X    while ( $#cpy > 0 )
  143. X        switch ( $cpy[1] )
  144. X
  145. X            case "-s":
  146. X                breaksw
  147. X
  148. X            default:
  149. X                set cpy1 = "$cpy1 $cpy[1]"
  150. X        endsw
  151. X    shift cpy
  152. X    end
  153. X
  154. X    set cpy1 = "-s $cpy1"
  155. X    set argv = ( $cpy1 )
  156. Xendif
  157. X
  158. Xset cpy = ( $argv )
  159. X
  160. XFIRST_ARG_LOOP:
  161. Xwhile ( $#cpy > 0 )
  162. Xswitch ( $cpy[1] )
  163. X
  164. X    case "-t":
  165. X        shift cpy
  166. X        set again = y
  167. X        while ( $again == y )
  168. X            echo -n "Enter topic: "
  169. X            set resp = "$<"
  170. X            if ( "$resp" != "" ) then
  171. X                egrep -i "$resp" $RFC_DIR/$index_name
  172. X            endif
  173. X            set again = "n"
  174. X            echo -n "Search again? (y/n) [n]: "
  175. X            set again = $<
  176. X            if ( "$again" != "" ) then
  177. X                set again = `expr substr "$again" 1 1`
  178. X            endif
  179. X        end
  180. X        breaksw
  181. X
  182. X    case "-s":
  183. X        shift cpy
  184. X        echo "Syncing local index with copy at $rfc_archive"
  185. X        set file_list = $index_name
  186. X        goto DO_FETCH
  187. X        breaksw        
  188. X
  189. X    default:
  190. X        shift cpy
  191. Xendsw
  192. Xend
  193. X
  194. Xset cpy = ( $argv )
  195. X
  196. XSECOND_ARG_LOOP:
  197. Xwhile ( $#cpy > 0 )
  198. Xswitch ( $cpy[1] )
  199. X
  200. X    case "-s":
  201. X    case "-t":
  202. X        shift cpy
  203. X        breaksw
  204. X
  205. X    case "-i"
  206. X        shift cpy
  207. X        echo -n "Get RFC Number(s): "
  208. X        set rfcnum =  ( $< )
  209. X
  210. X    default:
  211. X        set num_list = ( $cpy $rfcnum )
  212. X
  213. X        while( $#num_list > 0 )
  214. X            set not_num = `expr index $num_list[1] $charlist`
  215. X            if ( $not_num ) then
  216. X                echo Bad rfc number $num_list[1]. EXIT.
  217. X                exit 1
  218. X            endif
  219. X
  220. X            shift num_list
  221. X        end
  222. X        set rfcnum = ( $cpy $rfcnum )
  223. X        break
  224. Xendsw
  225. Xend
  226. X
  227. X
  228. XFETCH:
  229. X#
  230. X# if there's nothing in the rfcnum variable, quit.
  231. X#
  232. X
  233. Xif ( $#rfcnum == 0 ) goto DONE
  234. X
  235. X#
  236. X# Build the file list from the index number list
  237. X#
  238. X
  239. Xset file_list = ()
  240. Xforeach f_index ( $rfcnum )
  241. X    set file_list = ( $file_list rfc$f_index.txt )
  242. Xend
  243. X
  244. Xecho "Getting the following files from from $rfc_archive;"
  245. Xforeach file ( $file_list )
  246. X    echo $file
  247. Xend 
  248. X
  249. Xecho -n "Continue? y/n [y]: "
  250. Xset resp = $<
  251. Xif ( "$resp" == "n" ) then
  252. X    echo ABORT
  253. X    goto DONE
  254. Xendif
  255. X
  256. X
  257. X#
  258. X# Do the fetch!!
  259. X#
  260. X
  261. XDO_FETCH:
  262. X
  263. Xftp -n -i << +
  264. Xopen $rfc_archive
  265. Xuser anonymous culbert@iesl.mit.edu
  266. Xcd $remote_dir
  267. Xlcd $local_dir
  268. Xbin
  269. Xmget $file_list
  270. Xbye
  271. X+
  272. X
  273. X# If this was a forced sync, return to the argument processing loops.
  274. X
  275. Xif $SYNC_ME then 
  276. X    setenv SYNC_ME 0
  277. X    goto FIRST_ARG_LOOP
  278. Xendif
  279. X
  280. X#
  281. X# List the files locally to give a little confidence that all went well...
  282. X
  283. Xpushd $local_dir >&! /dev/null
  284. Xls -l $file_list
  285. Xpopd >&! /dev/null
  286. X
  287. X#
  288. X# BYE!!!!
  289. X#
  290. X
  291. XDONE:
  292. X
  293. Xexit 0
  294. X
  295. END_OF_FILE
  296.   if test 5258 -ne `wc -c <'rfcget'`; then
  297.     echo shar: \"'rfcget'\" unpacked with wrong size!
  298.   fi
  299.   chmod +x 'rfcget'
  300.   # end of 'rfcget'
  301. fi
  302. if test -f 'rfcget.1' -a "${1}" != "-c" ; then 
  303.   echo shar: Will not clobber existing file \"'rfcget.1'\"
  304. else
  305.   echo shar: Extracting \"'rfcget.1'\" \(2368 characters\)
  306.   sed "s/^X//" >'rfcget.1' <<'END_OF_FILE'
  307. X.TH RFCGET 1  "17 Dec 1992"
  308. X.SH NAME
  309. Xrfcget \- Simple rfc retrieval tool
  310. X.SH SYNOPSIS
  311. X.na
  312. X.B rfcget
  313. X[ options ] [
  314. X.I rfc-number
  315. X]
  316. X.br
  317. X.ad
  318. X.SH DESCRIPTION
  319. X.LP
  320. X.I rfcget
  321. Xis a c-shell script which facilitates the retrieval of Request For Comments
  322. X(RFC) Documents. The script supports two functions; topic searching, rfc 
  323. Xdocument retrieval. The script uses a local copy of the rfc index file for 
  324. Xtopic searches. This index must be located in a directory named by the 
  325. Xenvironment variable RFC_DIR. If you choose not to set this variable,
  326. Xthe script uses the local directory. RFC_DIR is also used as the location
  327. Xwhere retrieved documents are placed. You are warned by the script if this
  328. Xvariable isn't set. If the index file is not found when the script is
  329. Xrun, the tool "syncs" with a nic server copy then proceeds with argument 
  330. Xprocessing.
  331. X
  332. X
  333. X.SH OPTIONS
  334. X.I rfcget
  335. Xallows you to specify three options on the command line. The options 
  336. Xsupported are as follows:
  337. X
  338. X.TP
  339. X-i
  340. XRun the program in interactive mode prompting the user for the numbers
  341. Xof the rfc documents to retrieve from the server.
  342. X.TP
  343. X-t
  344. XPrompt the user for a topic to search in the index file.
  345. X.TP
  346. X-s
  347. XSynchronize local index file with the one found at the nic.
  348. X
  349. X.SH EXAMPLE
  350. X.nf
  351. X% rfcget -i -t
  352. XEnter topic: DVMRP
  353. XSearch again? (y/n) [n]: y
  354. XEnter topic: distance vector
  355. X1075  Distance Vector Multicast Routing Protocol. Waitzman,D.;Partridge,C.;
  356. XSearch again? (y/n) [n]: n
  357. XGet RFC Number(s): 1075
  358. XGetting the following files from from ftp.nisc.sri.com;
  359. Xrfc1075.txt
  360. XContinue? y/n [y]: y
  361. XLocal directory now /mit/staff/RFC
  362. X-rw-rw-r--  1 staff     53385 Dec 18 13:33 rfc1075.txt
  363. X
  364. X
  365. X.SH FILES
  366. X$RFC_DIR/rfc-index.txt
  367. X
  368. X.SH AUTHOR
  369. XJim Culbert (culbert@iesl.mit.edu)
  370. X.SH BUGS
  371. XThe script has hardwired references to a specific nic and a specific
  372. Xindex file name. If these change, the script will break. The user 
  373. Xmust modify script variables if the nic becomes unavailable or if 
  374. Xthe index is put into another file name. It should be possible to 
  375. Xoverride these parameters via options or a configuration file.
  376. XThe current site accessed is ftp.nisc.sri.com and the index file
  377. Xsearched for is rfc-index.txt.
  378. X
  379. XSimilarly, the script assumes a file name format of rfcxxxx.txt for
  380. Xthe files to be retrieved. Problems will arise if this ever changes.
  381. X
  382. XThere should be an option to search for .ps files as well as .txt 
  383. Xfiles.
  384. X
  385. END_OF_FILE
  386.   if test 2368 -ne `wc -c <'rfcget.1'`; then
  387.     echo shar: \"'rfcget.1'\" unpacked with wrong size!
  388.   fi
  389.   # end of 'rfcget.1'
  390. fi
  391. echo shar: End of archive 1 \(of 1\).
  392. cp /dev/null ark1isdone
  393. MISSING=""
  394. for I in 1 ; do
  395.     if test ! -f ark${I}isdone ; then
  396.     MISSING="${MISSING} ${I}"
  397.     fi
  398. done
  399. if test "${MISSING}" = "" ; then
  400.     echo You have the archive.
  401.     rm -f ark[1-9]isdone
  402. else
  403.     echo You still must unpack the following archives:
  404.     echo "        " ${MISSING}
  405. fi
  406. exit 0
  407. exit 0 # Just in case...
  408.