home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / brik.zoo / brik.2 < prev    next >
Internet Message Format  |  1989-07-22  |  50KB

  1. From ra!tut!draken!kth!mcvax!uunet!allbery Sat Jul 22 13:42:59 EET DST 1989
  2. Article 204 of comp.sources.misc:
  3. Path: chyde!ra!tut!draken!kth!mcvax!uunet!allbery
  4. >From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i095: brik: a general-purpose CRC-32 program (part 02/03)
  7. Message-ID: <61158@uunet.UU.NET>
  8. Date: 22 Jul 89 01:03:37 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
  11. Lines: 1243
  12. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  13.  
  14. Posting-number: Volume 7, Issue 95
  15. Submitted-by: dhesi@bsu-cs.bsu.edu (Rahul Dhesi)
  16. Archive-name: brik2/part02
  17.  
  18. #! /bin/sh
  19. # This is a shell archive, meaning:
  20. # 1. Remove everything above the #! /bin/sh line.
  21. # 2. Save the resulting text in a file.
  22. # 3. Execute the file with /bin/sh (not csh) to create:
  23. #    brik.doc
  24. #    initcrc.c
  25. #    install
  26. #    getopt.c
  27. #    vms.c
  28. # This archive created: Mon Jul 17 01:23:04 1989
  29. export PATH; PATH=/bin:/usr/bin:$PATH
  30. echo shar: "extracting 'brik.doc'" '(29437 characters)'
  31. if test -f 'brik.doc'
  32. then
  33.     echo shar: "will not over-write existing file 'brik.doc'"
  34. else
  35. sed 's/^X//' << \SHAR_EOF > 'brik.doc'
  36. X
  37. X
  38. X     BRIK(1)                    USER MANUAL                    BRIK(1)
  39. X
  40. X
  41. X     NAME
  42. X          brik - calculate 32-bit CRC
  43. X
  44. X     SYNOPSIS
  45. X          brik -h
  46. X          brik -gcGCbafvsqWHT file ...
  47. X
  48. X     DESCRIPTION
  49. X          Brik generates and verifies 32-bit CRC values (checksums).
  50. X          It is designed to generate CRCs for text files that are the
  51. X          same on all computer systems that use the ASCII character
  52. X          set, provided each text file is in the usual text file
  53. X          format for each system. Brik will also optionally use binary
  54. X          CRCs calculated using every byte in a file.  Such binary
  55. X          CRCs are portable across systems for binary files that are
  56. X          moved from system to system without any newline conversion.
  57. X          Brik can be asked to decide by examining each file whether
  58. X          to calculate a text mode or binary mode CRC for it.
  59. X
  60. X          Changes from version 1.0 are summarized at the end of this
  61. X          document.
  62. X
  63. X          The general usage format is:
  64. X
  65. X               brik -gcGCbafvsqWHT [ file ] ...
  66. X
  67. X          The brackets mean that file, which is the name of a file, is
  68. X          optional.  The three dots indicate that more than one
  69. X          filename may be typed (separated by blanks).  Exactly one of
  70. X          the options -c, -C, -g, -G, or -h, is required.  The -h
  71. X          option gives a help screen.
  72. X
  73. X          In addition to -h, the Brik options available (as they
  74. X          appear on the help screen) are:
  75. X
  76. X          -g   look for Checksum: header, generate CRC for rest of
  77. X               file
  78. X
  79. X          -c   get CRC from header, verify CRC of rest of file
  80. X
  81. X          -G   generate CRC for entire file (add -b for binary files)
  82. X
  83. X          -C   verify all file CRCs from output of -G (-f is not
  84. X               needed)
  85. X
  86. X          -b   use binary mode -- read file byte by byte, not line by
  87. X               line
  88. X
  89. X          -a   automatically decide whether each file is text or
  90. X               binary
  91. X
  92. X          -f   read filenames (wildcards ok) from specified files
  93. X
  94. X          -v   be verbose, report all results (else only errors are
  95. X               reported)
  96. X
  97. X          -s   be silent, say nothing, just return status code
  98. X
  99. X          -q   be quiet, don't print header for -G
  100. X
  101. X          -W   after generating CRC with -g, write it to original
  102. X               header
  103. X
  104. X          -H   after generating CRC with -g, print header to stdout
  105. X
  106. X          -T   include trailing empty lines, normally ignored (text
  107. X               mode only)
  108. X
  109. X          VERIFYING CRC HEADERS
  110. X
  111. X          The primary intended use of Brik is to verify Checksum:
  112. X          headers in Usenet postings and in C and Pascal source files.
  113. X          A Checksum: header looks like this:
  114. X
  115. X               Checksum: 9485762645b   (verify with "brik")
  116. X
  117. X          The word Checksum: must occur at the beginning of a line.
  118. X          It is followed by a colon, an optional blank, a ten-digit
  119. X          decimal 32-bit CRC, and any arbitrary optional string such
  120. X          as the comment shown above.  The CRC value may be followed
  121. X          by a one-character suffix identifying the type of the CRC.
  122. X          These suffixes are described later.
  123. X
  124. X          When Brik is invoked with the syntax
  125. X
  126. X               brik -c file ...
  127. X
  128. X          it will search for the Checksum: header in each specified
  129. X          file, read the CRC value from that header, calculate the
  130. X          CRC-32 for all lines in the file (except trailing empty
  131. X          lines) that occur *after* the header line, and report an
  132. X          error if the two values do not match.
  133. X
  134. X          CALCULATING CRC HEADERS
  135. X
  136. X          The command
  137. X
  138. X               brik -g file ...
  139. X
  140. X          tells Brik to look for the Checksum: header in each
  141. X          specified file, calculate the CRC of the lines in the file
  142. X          following the header, and print the CRC and filename without
  143. X          changing the file in any way.  You can also ask Brik to
  144. X          update the Checksum: header with the following command:
  145. X
  146. X               brik -gW file ...
  147. X
  148. X          This causes Brik to update the Checksum: header in the file
  149. X          with the newly-calculated CRC.  If there is not enough space
  150. X          for the CRC in the existing header, Brik reports an error
  151. X          and does not change the existing header.  To initially add a
  152. X          Checksum: header to a file, insert a line of the following
  153. X          form into the file with a text editor:
  154. X
  155. X               Checksum: XXXXXXXXXX  -- this is an optional comment
  156. X
  157. X          The word Checksum must be at the beginning of a line.  The
  158. X          ten `X' characters shown can be any ten characters.  They
  159. X          will be later replaced by the calculated CRC value.  They do
  160. X          not need to be `X'.  The comment following them is optional
  161. X          and can be any arbitrary string of characters after the CRC
  162. X          field, separated from it by blanks.  As an example, in a C
  163. X          source file called main.c, you might have:
  164. X
  165. X               /*
  166. X               Checksum: XXXXXXXXXX  (verify or update with brik)
  167. X               */
  168. X
  169. X          Once a header like this exists in the file, invoke Brik as
  170. X          follows:
  171. X
  172. X               brik -gW main.c
  173. X
  174. X          This will cause the ten `X' characters to be replaced with
  175. X          the calculated checksum, giving something like this:
  176. X
  177. X               /*
  178. X               Checksum: 1922837484  (verify or update with brik)
  179. X               */
  180. X
  181. X          Later you can use the command
  182. X
  183. X               brik -c main.c
  184. X
  185. X          to verify that the contents of the file following the header
  186. X          have the same CRC as the stored value.
  187. X
  188. X          If Brik is invoked with the -c or -g options and it cannot
  189. X          find a Checksum: header in a file, it prints a row of
  190. X          question marks.  If it is invoked with the -gW option and it
  191. X          does not find enough character positions after the Checksum:
  192. X          string to hold the CRC, it does not fill in the CRC and
  193. X          prints an error message.
  194. X
  195. X          Brik can be asked to generate a complete Checksum: header
  196. X          but print it to standard output instead of writing it to the
  197. X          file.  Do this by adding the -H option.  If both -W and -H
  198. X          are given, the Checksum: header will be written both to the
  199. X          file and to standard output.
  200. X
  201. X          WHOLE-FILE CRCS
  202. X
  203. X          A "whole-file" CRC calculation is done for the entire
  204. X          contents of a file, without looking for a Checksum: header.
  205. X          The command
  206. X
  207. X               brik -G file ...
  208. X
  209. X          asks Brik to do this calculation for all specified files.
  210. X          The output from this command is a list of files and their
  211. X          whole-file CRCs.  It is sent to the standard output stream,
  212. X          which in most cases is your screen.  The output should be
  213. X          saved in a file by redirecting it.  For example, the command
  214. X
  215. X               brik -G *.h *.c > crc.lst
  216. X
  217. X          on an MS-DOS system might yield the following in the output
  218. X          file crc.lst:
  219. X
  220. X               # CRC-32        filename
  221. X               # ------        --------
  222. X
  223. X               2566277976      getopt.c
  224. X                100594287      brik.c
  225. X               1151475469      vms.c
  226. X               3929503738      turboc.c
  227. X               2424271922      addbfcrc.c
  228. X               1943472856      assert.h
  229. X               2601923477      brik.h
  230. X
  231. X          The output of the -G option is in free format.  The output
  232. X          file may be edited by hand.  Empty lines and lines beginning
  233. X          with '#' will be ignored by Brik when it is later asked to
  234. X          read this file.
  235. X
  236. X          This list of filenames and whole-file CRCs may be verified
  237. X          by a command like this:
  238. X
  239. X               brik -C crc.lst
  240. X
  241. X          This makes Brik read the file crc.lst, get the CRCs and
  242. X          filenames from it, do the CRC calculation again for each
  243. X          file, and report an error if it does not match the CRC
  244. X          recorded inside crc.lst.
  245. X
  246. X          **IX and MS-DOS users (and others who can pipe the output of
  247. X          one command into another) could use a command like the
  248. X          following to see if Brik's -G and -C options are working:
  249. X
  250. X               brik -G file ... | brik -C
  251. X
  252. X          This invokes "brik -G" on some files, sending the output to
  253. X          a pipe where it becomes the input of "brik -C".  If no
  254. X          filename is specified, Brik reads from standard input, so
  255. X          "brik -C" will read from the pipe and concurrently verify
  256. X          all the CRCs that are being generated by "brik -G".
  257. X
  258. X          Whole-file CRCs are normally generated in text mode, in
  259. X          which a file is treated as lines of text.  You can also
  260. X          generate whole-file CRCs in binary mode.  See below.
  261. X
  262. X          BINARY VERSUS TEXT MODE
  263. X
  264. X          Brik can work in two different modes.  The most common mode,
  265. X          used unless you specify otherwise, is text mode.
  266. X
  267. X          In this mode Brik reads all files line by line, and forces
  268. X          each line of text to be terminated by a newline character of
  269. X          constant value before doing a CRC calculation.  Thus, no
  270. X          matter what newline character is used by your system, the
  271. X          CRC calculation will be unaffected.  This means that whether
  272. X          your operating system uses linefeeds to terminate lines
  273. X          (e.g. **IX), or a carriage return and a linefeed (e.g. MS-
  274. X          DOS) or a carriage return only (e.g. Macintosh) or nothing
  275. X          but a record length field (e.g. VAX/VMS), the CRC
  276. X          calculation in text mode gives the same results.
  277. X
  278. X          If a file is not intended to be a text file, the text mode
  279. X          CRC calculated by Brik may not be reliable and may be
  280. X          different on different systems.  If Brik is calculating a
  281. X          text mode CRC on a file that appears to contain binary data,
  282. X          it still calculates the text-mode CRC but adds a "*"
  283. X          character after the CRC to indicate to warn the user.
  284. X
  285. X          Brik can be asked to operate in binary mode by adding a -b
  286. X          option.  Binary mode is applicable only to the -G command,
  287. X          which acts on whole files.  Thus
  288. X
  289. X               brik -G file ...
  290. X
  291. X          finds whole-file CRCs of all specified files in text mode,
  292. X          while
  293. X
  294. X               brik -Gb file ...
  295. X
  296. X          does the same in binary mode.  In binary mode Brik simply
  297. X          reads and calculates the CRC for all bytes in a file.  If a
  298. X          file is moved from one system to another without any newline
  299. X          conversion or any other changes, Brik should calculate the
  300. X          same binary mode CRC for it on both systems.
  301. X
  302. X          The output from "brik -Gb" includes a trailing b suffix in
  303. X          each CRC, so "brik -C" will correctly use binary mode for
  304. X          such CRCs and it is never necessary to type "brik -Cb"
  305. X          instead.
  306. X
  307. X          In its auto-check mode, Brik will itself examine each file
  308. X          and determine whether it is a text or binary file and
  309. X          calculate a CRC accordingly.  To do this, use the -a option.
  310. X          Although Brik can determine the type of each file with a
  311. X          high degree of reliability, it is still possible for it to
  312. X          come to a wrong conclusion about some files.
  313. X
  314. X          The output from "brik -Ga" will include a trailing b
  315. X          character in the CRC for those files that appeared to be
  316. X          binary to Brik.  You may find both text and binary CRCs in
  317. X          the output.
  318. X
  319. X          TRAILING EMPTY LINES
  320. X
  321. X          The normal behavior of Brik in text mode is to ignore any
  322. X          trailing empty lines in a file.  An empty line is a line
  323. X          that contains nothing, not even blanks or tabs.  (Just
  324. X          hitting a carriage return when you are editing a text file
  325. X          usually produces an empty line.)  If manipulating a text
  326. X          file causes trailing empty lines to be added or deleted, the
  327. X          CRC calculated by Brik will be unaffected.  You can override
  328. X          this if necessary with the -T option, which makes Brik
  329. X          include trailing empty lines in the CRC calculation.  For
  330. X          example,
  331. X
  332. X               brik -gWT
  333. X
  334. X          will update the Checksum: header with a CRC that includes
  335. X          all lines in a text file.  Similarly
  336. X
  337. X               brik -GT
  338. X
  339. X          will find whole-file CRCs that include all lines in a text
  340. X          file.
  341. X
  342. X          When Brik is given the -T option, it adds a T suffix to each
  343. X          generated CRC.  Then, when the CRC is verified with -c or
  344. X          -C, Brik will correctly include trailing empty lines when
  345. X          needed without having to be explicitly told to do so.
  346. X
  347. X          In binary mode Brik always reads all bytes in a file, so it
  348. X          does not ignore trailing empty lines, and the -T switch is
  349. X          not needed.
  350. X
  351. X          The effects of the -T and -b options are mutually exclusive.
  352. X          If both are given, whichever is used later overrides the
  353. X          first.  So -bT is equivalent to -T and -Tb is equivalent to
  354. X          -T.
  355. X
  356. X          FILENAME CONVENTIONS
  357. X
  358. X          Under MS-DOS and VAX/VMS, wildcards are allowed on the
  359. X          command line and will be expanded by Brik.  Under **IX,
  360. X          wildcards are expected to be expanded by the shell and are
  361. X          not expanded by Brik.  If no filename is given, Brik reads
  362. X          its standard input.  By default this is keyboard input, but
  363. X          it is expected that input will usually be redirected to come
  364. X          from a file or a pipe.  Also, if a filename is explicitly
  365. X          specified as a dash ("-"), it stands for standard input.
  366. X
  367. X          The following five commands (valid under the **IX operating
  368. X          system)
  369. X
  370. X               brik -c myfile            # "myfile"
  371. X               brik -c < myfile          # stdin = "myfile"
  372. X               cat myfile | brik -c      # stdin = a pipe
  373. X               brik -c - < myfile        # "-" = stdin = "myfile"
  374. X               cat myfile | brik -c -    # "-" = stdin = a pipe
  375. X
  376. X          all have the effect of verifying the Checksum: header in the
  377. X          file myfile.
  378. X
  379. X          Standard input can also be read when using the -C option.
  380. X          For example, suppose we have already given the command
  381. X
  382. X               brik -G *.c *.h > crc.lst
  383. X
  384. X          to create a file called "crc.lst" that contains a list of
  385. X          whole-file CRCs.  We can now verify the integrity of these
  386. X          files with any of the following commands:
  387. X
  388. X               brik -C crc.lst          # "crc.lst"
  389. X               brik -C < crc.lst        # stdin = "crc.lst"
  390. X               brik -C - < crc.lst      # "-" = stdin = "crc.lst"
  391. X               cat crc.lst | brik -C    # stdin = a pipe
  392. X               cat crc.lst | brik -C -  # "-" = stdin = a pipe
  393. X
  394. X
  395. X          INDIRECT FILE NAMING
  396. X
  397. X          The -f option allows you to have filenames in a list rather
  398. X          than on the command line.  For example, suppose you want to
  399. X          generate whole-file CRCs of files whose names are selected
  400. X          by some other program.  You could use find (under **IX) or
  401. X          Stuff (under MS-DOS) to generate a list of filenames.  When
  402. X          the -f option is given, Brik reads filenames, one per line,
  403. X          from the file(s) specified.  Thus you could do the
  404. X          following:
  405. X
  406. X               find . -mtime +3 -print > flist
  407. X               brik -Gf flist > crc.lst
  408. X
  409. X          The first command asks find to generate a list of names of
  410. X          all files that were modified more than 3 days ago, and sends
  411. X          the output to the file flist.  The contents of flist might
  412. X          now look like this, as an example:
  413. X
  414. X               ./sez.doc
  415. X               ./brik.doc
  416. X               ./stuff.doc
  417. X               ./looz.doc
  418. X
  419. X          The second command above asks Brik to read the file called
  420. X          flist, get a list of filenames from it, one per line, and
  421. X          generate the whole-file CRC of each of these files.  We
  422. X          additionally redirect the output of "brik -Gf" to the file
  423. X          called crc.lst.  Given the above contents of flist, the
  424. X          following two commands are exactly equivalent:
  425. X
  426. X               brik -Gf flist >crc.lst
  427. X               brik -G ./sez.doc ./brik.doc ./stuff.doc ./looz.doc >crc.lst
  428. X
  429. X          The advantage of the -f option is that once you have
  430. X          filenames in a file, you need not type them again at the
  431. X          command line.  The -f option also allows you to feed Brik
  432. X          through a pipe filenames generated by another program.
  433. X          Consider this command:
  434. X
  435. X               find . -mtime +3 -print | brik -Gf - > crc.lst
  436. X
  437. X          Under **IX this concurrently invokes both find and Brik.  As
  438. X          find generates a filename and sends it to its standard
  439. X          output (a pipe), Brik reads the filename from its standard
  440. X          input and generates its whole-file CRC.  The following
  441. X          pipeline
  442. X
  443. X               find . -mtime +3 -print | brik -Gf - | brik -C -
  444. X
  445. X          invokes find to generate filenames, Brik to print the
  446. X          whole-file CRCs of those files, and Brik again to
  447. X          immediately verify them.
  448. X
  449. X          Under MS-DOS and VAX/VMS (and any other operating system
  450. X          under which Brik has been installed to expand wildcards
  451. X          itself), a file specified by the -f option can itself
  452. X          contain wildcards in the filenames.  For example, suppose
  453. X          the file "wildfile" contains the following lines:
  454. X
  455. X               /bin/*.exe
  456. X               /bin/*.com
  457. X               /doc/*.doc
  458. X
  459. X          Now if we invoke Brik with the command
  460. X
  461. X               brik -Gf wildfile
  462. X
  463. X          it will read filespecs from "wildfile," expand wildcards in
  464. X          each filespec, and generate whole-file CRCs for all matching
  465. X          files.
  466. X
  467. X          If you are checking whole-file CRCs with the -C option, you
  468. X          do not normally need to use the -f option.  When used with
  469. X          -C, the -f option introduces an additional level of file
  470. X          naming indirection. For example, the command
  471. X
  472. X               brik -C crc.lst
  473. X
  474. X          takes a list of CRCs and filenames from "crc.lst" and
  475. X          verifies them.  However, the command
  476. X
  477. X               brik -Cf master.lst
  478. X
  479. X          does not do the same thing.  Instead, it takes a list of
  480. X          files from "master.lst," looks inside each of those files
  481. X          for a list of CRCs and filenames, and verifies them.
  482. X
  483. X          As an example of the use of -Cf, consider this sequence:
  484. X
  485. X               brik -Gb /bin/*.exe > exelist
  486. X               brik -Gb /bin/*.com > comlist
  487. X               brik -GT /doc/*.doc > doclist
  488. X               brik -G  /doc/*.man > manlist
  489. X
  490. X          Now we have four files called "exelist," "comlist,"
  491. X          "doclist," and "manlist" containing whole-file CRCs of
  492. X          various types.  We can test the integrity of files listed in
  493. X          these in four separate commands like this:
  494. X
  495. X               brik -C exelist
  496. X               brik -C comlist
  497. X               brik -C doclist
  498. X               brik -C manlist
  499. X
  500. X          But we could also do this in a single step by first creating
  501. X          a file called "biglist" that contains the names of these
  502. X          four files:
  503. X
  504. X               exelist
  505. X               comlist
  506. X               doclist
  507. X               manlist
  508. X
  509. X          and then use -Cf thus:
  510. X
  511. X               brik -Cf biglist
  512. X
  513. X          This causes Brik to read filenames from "biglist," look
  514. X          inside each of those files ("exelist," "comlist," "doclist,"
  515. X          and "manlist") and check the CRCs found there.  A **IX
  516. X          example to do the same thing in a more compact way might be:
  517. X
  518. X               cat exelist comlist doclist manlist | brik -Cf -
  519. X
  520. X          The above examples are somewhat contrived, however.  We
  521. X          could also use the following command:
  522. X
  523. X               brik -C exelist comlist doclist manlist
  524. X
  525. X
  526. X          SILENT VERSUS VERBOSE VERSUS QUIET
  527. X
  528. X          Brik accepts options -s, -q, and -v that control the degree
  529. X          of verbosity.
  530. X
  531. X          Normally Brik prints a message only if it detects an error.
  532. X          For example, if you give the command
  533. X
  534. X               brik -c *.c *.h
  535. X
  536. X          and Brik finds that all Checksum: headers contain CRCs that
  537. X          match the calculated value, it prints nothing.
  538. X
  539. X          The -v switch makes Brik print a message for each file
  540. X          tested that contains the word "ok" if stored and calculated
  541. X          CRCs matched and "BAD" if they did not.
  542. X
  543. X          In all messages reporting file CRCs, Brik prints the actual
  544. X          CRC it calculated, or a row of question marks if it could
  545. X          not calculate one.  Brik fails to calculate a CRC if it is
  546. X          trying to calculate a header-based CRC (commands -c and -g)
  547. X          but does not find a Checksum: header in a file.
  548. X
  549. X          The -s switch tells Brik to be silent.  This will cause
  550. X          nothing to be printed if Brik does not find a Checksum
  551. X          header or if CRCs don't match.  However, the status code on
  552. X          exit is still set.  The -s option is useful for invoking
  553. X          Brik from within a shell script (**IX) or a batch file (MS-
  554. X          DOS) and later testing the error code it returned when it
  555. X          exited.
  556. X
  557. X          The -s switch does not suppress the error message printed if
  558. X          Brik is given a filename and the file cannot be found.  For
  559. X          example, if the command
  560. X
  561. X               brik -cs myfile
  562. X
  563. X          is given but "myfile" does not exist, Brik will print an
  564. X          error message even though the -s option was given.
  565. X
  566. X          The -q switch makes Brik slightly quieter.  Its only effect
  567. X          is to suppress the introductory comments that are otherwise
  568. X          generated by the -C option.
  569. X
  570. X          VAX/VMS BUGS
  571. X
  572. X          o    Under VAX/VMS, file manipulation is unpredictable and
  573. X               the VAX/VMS C runtime library in particular is very
  574. X               unreliable.  One result is that under VAX/VMS, the -gW
  575. X               option will work only for stream-LF files, which are
  576. X               the only type of file that VAX/VMS seems to handle
  577. X               correctly.  Fortunately, the -c option will correctly
  578. X               work for VAX/VMS standard text files.
  579. X
  580. X          o    The VAX/VMS implementation of Brik simply ignores
  581. X               filenames that correspond to nonexistent files instead
  582. X               of giving an error message.  VMS users are invited to
  583. X               fix this bug (probably somewhere in the nextfile()
  584. X               function in the file vms.c) and send me the fix.
  585. X
  586. X          o    To avoid annoying error messages, Brik under VAX/VMS
  587. X               always exits with a status code of 1.
  588. X
  589. X          o    Due to a problem in the VAX/VMS command interpreter, if
  590. X               any uppercase option characters are typed (e.g. -C, -G,
  591. X               -T), Brik will not recognize them as uppercase unless
  592. X               they are enclosed in double quotes.  An example of a
  593. X               correct command under VAX/VMS:
  594. X
  595. X                 brik "-GT" *.*
  596. X
  597. X               An example of a command that won't work:
  598. X
  599. X                 brik -GT *.*
  600. X
  601. X          USAGE HINTS
  602. X
  603. X          This section discusses some ways of using Brik.
  604. X
  605. X          -    Brik is currently used to create and verify checksums
  606. X               of articles posted on the Usenet newsgroup
  607. X               comp.binaries.ibm.pc.  While reading Usenet news with
  608. X               rn, for example, you can verify the Checksum: header of
  609. X               such an article with the command:
  610. X
  611. X                 | brik -cv
  612. X
  613. X               This feeds the current article to Brik as standard
  614. X               input and asks it to verbosely verify the checksum.
  615. X
  616. X          -    C and Pascal source files that are being distributed
  617. X               can be given their own Checksum: headers.  The
  618. X               advantage of this over listing CRCs separately is that
  619. X               each file contains its checksum no matter where it
  620. X               goes.  The recipient can easily verify that each source
  621. X               file was received intact.  This is especially valuable
  622. X               when source files are being sent by electronic mail
  623. X               through an IBM mainframe-based network, such as BITNET,
  624. X               that can cause corruption of text files.
  625. X
  626. X               Create the Checksum header with a text editor and
  627. X               initialize its value with the command:
  628. X
  629. X                 brik -gW file ...
  630. X
  631. X               The recipient can verify the checksum with the command:
  632. X
  633. X                 brik -cv file ...
  634. X
  635. X          -    To keep track of any unexpected filesystem corruption
  636. X               or unauthorized changes to system files, Brik can be
  637. X               used to create a list of checksums.  This should be
  638. X               done using the -b option (all binary checksums) or the
  639. X               -a option (use text or binary as appropriate).  Under
  640. X               **IX this can be done with a command like this one:
  641. X
  642. X                 find /bin /usr/bin /lib /usr/lib /usr/new \
  643. X                  -type f -print | \
  644. X                 grep -v '^/usr/bin/beta' | \
  645. X                 grep -v '^/usr/new/lib/news' | \
  646. X                 brik -Gbf - > crc.list
  647. X
  648. X               This example uses find to print the pathnames of
  649. X               certain files, grep to filter out certain directory
  650. X               subtrees, and then Brik to print checksums of all
  651. X               selected files.  Periodically a background job can be
  652. X               run to compare the file list against current files and
  653. X               report any discrepancies:
  654. X
  655. X                 brik -C crc.lst | mail -s 'brik output' postmaster
  656. X
  657. X               Under MS-DOS, create a list of checksums with the help
  658. X               of Stuff, a find-like file finder program that is
  659. X               distributed with zoo 2.01:
  660. X
  661. X                 stuff /bin /msdos /turboc | brik -Gaf - > crc.list
  662. X
  663. X               This is a simple mechanism that can be used to detect
  664. X               unexpected file changes caused by hardware problems or
  665. X               malicious programs such as viruses and worms.  Be
  666. X               warned, however, that since Brik uses a published CRC
  667. X               algorithm, very clever deviant programs are possible
  668. X               that could change a file without affecting its CRC.
  669. X
  670. X               To avoid too many false alarms, only files that do not
  671. X               change much (such as system binaries) should be
  672. X               selected.
  673. X
  674. X     CHANGES
  675. X          Changes from version 1.0 are as follows.
  676. X
  677. X          -    The CRC calculation has been recoded in 8086 assembly
  678. X               code suitable for Turbo C/MS-DOS.  As a result Brik 2.0
  679. X               under MS-DOS is much faster than version 1.0.
  680. X
  681. X          -    The new -a flag makes Brik automatically determine for
  682. X               each file whether it is text or binary and calculate
  683. X               the CRC accordingly
  684. X
  685. X          -    When Brik is asked to calculate a text mode CRC but the
  686. X               file appears to be binary, it now does not print a
  687. X               warning message but instead adds a "*" suffix to the
  688. X               calculated CRC to indicate that the CRC may not be
  689. X               reliable.
  690. X
  691. X          -    The new -H flag makes Brik print the formatted
  692. X               Checksum: header to standard output.
  693. X
  694. X          -    Detection of binary files is now more reliable under
  695. X               MS-DOS.  If a control Z character occurs near the
  696. X               beginning of a binary file, Brik will not be fooled by
  697. X               the apparent end-of-file but will in most cases
  698. X               reliably detect that the file is binary.
  699. X
  700. X          -    The new -q flag suppresses the introductory comments
  701. X               from the output of the -G command.
  702. X
  703. X     BUGS
  704. X          Brik is designed to work with computer systems that use the
  705. X          7-bit ASCII character set and 8-bit bytes with the eighth
  706. X          (parity) bit set to zero.
  707. X
  708. X          Brik has not been tested with computer systems that use
  709. X          ASCII characters with the eighth bit set or those that use
  710. X          EBCDIC characters.  Although it will calculate a CRC on such
  711. X          machines, the probability of this CRC being the same as the
  712. X          one calculated on machines that use 7-bit ASCII is
  713. X          approximately 0.00000000023.
  714. X
  715. X     DIAGNOSTICS
  716. X          Error messages are intended to be self-explanatory.
  717. X
  718. X          The exit status returned is 1 if Brik was invoked with
  719. X          incorrect arguments, else it is the number of files found
  720. X          with missing or invalid CRCs, but not greater than an
  721. X          operating-system-dependent maximum value.
  722. X
  723. X     COPYRIGHT
  724. X          Both this documentation and Brik are Copyright 1989 Rahul
  725. X          Dhesi, all rights reserved.  Permission is granted to copy,
  726. X          use, and distribute for any commercial or noncommercial
  727. X          purpose in accordance with the requirements of version 1.0
  728. X          of the GNU General Public license.
  729. X
  730. X          Note:  This software has not been endorsed by the Free
  731. X          Software Foundation, the creator of the GNU license, and I
  732. X          am not affiliated with that organization.
  733. X
  734. X     AUTHOR
  735. X          Rahul Dhesi
  736. X          UUCP: {iuvax,pur-ee}!bsu-cs!dhesi
  737. X          Internet: dhesi@bsu-cs.bsu.edu
  738. X
  739. X     BRIK(1)                    USER MANUAL                (1989/07/11)
  740. SHAR_EOF
  741. fi
  742. echo shar: "extracting 'initcrc.c'" '(7919 characters)'
  743. if test -f 'initcrc.c'
  744. then
  745.     echo shar: "will not over-write existing file 'initcrc.c'"
  746. else
  747. sed 's/^X//' << \SHAR_EOF > 'initcrc.c'
  748. X/* ::[[ @(#) initcrc.c 1.1 89/07/08 10:49:00 ]]:: */
  749. X/* Some of the following CRC-32 stuff is from zmodem source code */
  750. X
  751. X#ifndef LINT
  752. Xstatic char sccsid[]="::[[ @(#) initcrc.c 1.1 89/07/08 10:49:00 ]]::";
  753. X#endif
  754. X
  755. X/*
  756. XI claim no copyright over the contents of this file.  However,
  757. Xyou are requested to preserve all author attributions.
  758. X
  759. X                                     -- Rahul Dhesi
  760. X
  761. XChecksum: 2467278882      (check or update this with "brik")
  762. X*/
  763. X
  764. X#include "brik.h"
  765. X#define TABSIZE         256        /* no of entries in table */
  766. Xtypedef unsigned long tcrc;       /* type of crc value -- same as in brik.c */
  767. X
  768. Xtcrc crccode;                     /* holds all crc values */
  769. X
  770. X/*
  771. X * Copyright (C) 1986 Gary S. Brown.  You may use this program, or
  772. X * code or tables extracted from it, as desired without restriction.
  773. X */
  774. X
  775. X/* First, the polynomial itself and its table of feedback terms.  The  */
  776. X/* polynomial is                                                       */
  777. X/* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0 */
  778. X/* Note that we take it "backwards" and put the highest-order term in  */
  779. X/* the lowest-order bit.  The X^32 term is "implied"; the LSB is the   */
  780. X/* X^31 term, etc.  The X^0 term (usually shown as "+1") results in    */
  781. X/* the MSB being 1.                                                    */
  782. X
  783. X/* Note that the usual hardware shift register implementation, which   */
  784. X/* is what we're using (we're merely optimizing it by doing eight-bit  */
  785. X/* chunks at a time) shifts bits into the lowest-order term.  In our   */
  786. X/* implementation, that means shifting towards the right.  Why do we   */
  787. X/* do it this way?  Because the calculated CRC must be transmitted in  */
  788. X/* order from highest-order term to lowest-order term.  UARTs transmit */
  789. X/* characters in order from LSB to MSB.  By storing the CRC this way,  */
  790. X/* we hand it to the UART in the order low-byte to high-byte; the UART */
  791. X/* sends each low-bit to hight-bit; and the result is transmission bit */
  792. X/* by bit from highest- to lowest-order term without requiring any bit */
  793. X/* shuffling on our part.  Reception works similarly.                  */
  794. X
  795. X/* The feedback terms table consists of 256, 32-bit entries.  Notes:   */
  796. X/*                                                                     */
  797. X/*     The table can be generated at runtime if desired; code to do so */
  798. X/*     is shown later.  It might not be obvious, but the feedback      */
  799. X/*     terms simply represent the results of eight shift/xor opera-    */
  800. X/*     tions for all combinations of data and CRC register values.     */
  801. X/*                                                                     */
  802. X/*     The values must be right-shifted by eight bits by the "updcrc"  */
  803. X/*     logic; the shift must be unsigned (bring in zeroes).  On some   */
  804. X/*     hardware you could probably optimize the shift in assembler by  */
  805. X/*     using byte-swap instructions.                                   */
  806. X
  807. X/* if GENTAB is not defined, a static CRC table is used */
  808. X#ifndef GENTAB
  809. Xtcrc crctab[] = { /* CRC polynomial 0xedb88320 */
  810. X      0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
  811. X      0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
  812. X      0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
  813. X      0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
  814. X      0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
  815. X      0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
  816. X      0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
  817. X      0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
  818. X      0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
  819. X      0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
  820. X      0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
  821. X      0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
  822. X      0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
  823. X      0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
  824. X      0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
  825. X      0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
  826. X      0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
  827. X      0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
  828. X      0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
  829. X      0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
  830. X      0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
  831. X      0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
  832. X      0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
  833. X      0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
  834. X      0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
  835. X      0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
  836. X      0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
  837. X      0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
  838. X      0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
  839. X      0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
  840. X      0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
  841. X      0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
  842. X      0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
  843. X      0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
  844. X      0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
  845. X      0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
  846. X      0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
  847. X      0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
  848. X      0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
  849. X      0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
  850. X      0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
  851. X      0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
  852. X      0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
  853. X      0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
  854. X      0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
  855. X      0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
  856. X      0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
  857. X      0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
  858. X      0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
  859. X      0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
  860. X      0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
  861. X      0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
  862. X      0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
  863. X      0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
  864. X      0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
  865. X      0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
  866. X      0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
  867. X      0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
  868. X      0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
  869. X      0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
  870. X      0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
  871. X      0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
  872. X      0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
  873. X      0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
  874. X};
  875. X#else
  876. Xtcrc crctab[TABSIZE];      /* to be filled in below */
  877. X#endif /* GENTAB */
  878. X
  879. X/* If GENTAB is defined, we generate the CRC table at runtime */
  880. X#ifdef GENTAB
  881. X/*
  882. XThe function mkcrctab() generates a CRC-32 table at runtime.  The table
  883. Xgenerated is identical to that shown above.
  884. X
  885. XBased on explanation and code in "C Programmer's Guide to Serial
  886. XCommunications" by Joe Campbell.
  887. X
  888. XRahul Dhesi, 28 March 1989.
  889. X*/
  890. X
  891. X#define CRC_32          0xedb88320L    /* CRC-32 polynomial */
  892. X
  893. X/* calculates CRC of one item */
  894. Xtcrc onecrc (item)
  895. Xint item;
  896. X{
  897. X   int i;
  898. X   tcrc accum = 0;
  899. X   item <<= 1;
  900. X   for (i = 8;  i > 0;  i--) {
  901. X      item >>= 1;
  902. X      if ((item ^ accum) & 0x0001)
  903. X         accum = (accum >> 1) ^ CRC_32;
  904. X      else
  905. X         accum >>= 1;
  906. X   }
  907. X   return (accum);
  908. X}
  909. X
  910. X#ifdef ANSIPROTO
  911. Xtcrc onecrc (int);
  912. X#endif
  913. X
  914. X/* generates CRC table, calling onecrc() to make each term */
  915. Xvoid mkcrctab()
  916. X{
  917. X   int i;
  918. X   for (i = 0;  i < TABSIZE;  i++)
  919. X      crctab[i] = onecrc (i);
  920. X}
  921. X
  922. X#ifdef TESTTAB
  923. X/* test code -- prints entire table to standard output */
  924. X
  925. X#include <stdio.h>
  926. X
  927. Xmain()
  928. X{
  929. X   int i;
  930. X   mkcrctab();       /* make CRC table */
  931. X
  932. X   /* now print it */
  933. X   for (i = 0;  i < TABSIZE;  i ++) {
  934. X      if ((i % 4) == 0 && i > 0)
  935. X         printf ("\n");
  936. X      printf ("0x%08lx   ", (unsigned long) crctab[i]);
  937. X   }
  938. X   printf ("\n");
  939. X}
  940. X#endif /* TESTTAB */
  941. X
  942. X#endif /* GENTAB */
  943. SHAR_EOF
  944. fi
  945. echo shar: "extracting 'install'" '(4069 characters)'
  946. if test -f 'install'
  947. then
  948.     echo shar: "will not over-write existing file 'install'"
  949. else
  950. sed 's/^X//' << \SHAR_EOF > 'install'
  951. X                          
  952. X                             INSTALLING BRIK 2.0
  953. X
  954. XThe following files should be in this package.
  955. X
  956. X  name             description
  957. X  -----------      -----------
  958. X  addbfcrc.c       (generic) brik C source
  959. X  assert.h         (generic) brik C source
  960. X  brik.c           (generic) brik C source
  961. X  brik.h           (generic) brik C source
  962. X  initcrc.c        (generic) brik C source
  963. X  getopt.c         (generic) getopt function C source
  964. X
  965. X  install          (generic) installation instructions
  966. X  brik.doc         (generic) formatted user manual
  967. X  crc.lst          (generic) CRCs -- verify with "brik -Cv"
  968. X
  969. X  makefile.nix     (**IX) make file
  970. X  brik.1           (**IX) manual for formatting with "nroff -man"
  971. X
  972. X  addbfcrc.asm     (MS-DOS/Turbo C) 8086 assembly code
  973. X  brik.prj         (MS-DOS/Turbo C) project file for tc.exe
  974. X  makefile.tcc     (MS-DOS/Turbo C) make file
  975. X  turboc.c         (MS-DOS/Turbo C) brik C source
  976. X  turboc.cfg       (MS-DOS/Turbo C) configuration file for tcc.exe
  977. X
  978. X  descrip.mms      (VAX/VMS) make file
  979. X  makebrik.com     (VAX/VMS) script to compile and link
  980. X  options.opt      (VAX/VMS) options for linker
  981. X  vms.c            (VAX/VMS) brik C source
  982. X
  983. X  makefile.msc     (MS-DOS/MSC) make file (not tested)
  984. X
  985. XBrik is believed to compile and execute in the following environments:
  986. X
  987. X1.   Turbo C 2.0, MS-DOS 2.x or higher
  988. X2.   VAX/VMS 4.7 with VAX/VMS C 2.4
  989. X3.   4.3BSD from Berkeley on a VAX-11/785
  990. X4.   Microport System V/AT version 2.2
  991. X
  992. XMake sure all the needed files are in the current directory.  Then follow
  993. Xinstructions below for your specific type of system.  If doing so doesn't
  994. Xgive you a running copy of brik, read brik.h and experiment with the various
  995. Xcompilation options.
  996. X
  997. X1.   MS-DOS, Turbo C 2.0
  998. X
  999. XExamine the files "makefile.tcc" and "turboc.cfg".  Edit them if necessary
  1000. Xto make sure they have the correct names for your include and library
  1001. Xdirectories.
  1002. X
  1003. XTo use the command-line compiler, you will need a good make program such as
  1004. XNDMAKE (tested with version 4.31).  Rename the file "makefile.tcc" to
  1005. X"makefile" and follow instructions in it.
  1006. X
  1007. XTo use the Turbo C integrated environment, first convert the supplied
  1008. Xconfiguration file "turboc.cfg" to "tcconfig.tc" using the "tcconfig.exe"
  1009. Xprogram supplied with Turbo C.  A project file "brik.prj" is supplied. 
  1010. XAssemble addbfcrc.asm using either Microsoft's assembler or Borland's Turbo
  1011. Xassembler (be sure to use the /mx switch).  Then compile as usual with the
  1012. Xintegrated environment.
  1013. X
  1014. X2.   VAX/VMS
  1015. X
  1016. X2.1.   If you have DEC's make utility called "mms", proceed as follows:
  1017. X
  1018. X     a.   Delete "makefile" so mms won't get confused
  1019. X     b.   Type "mms" at the VMS prompt
  1020. X     c.   If all goes well, mms will compile and link the necessary files,
  1021. X          yielding "brik.exe" in the current directory.
  1022. X     d.   Move "brik.exe" wherever you want it and define a symbol with
  1023. X          a command line of the following type:
  1024. X
  1025. X               $ brik :== $my$disk:[bindir]brik.exe
  1026. X
  1027. X         where my$disk is the name of your device and bindir is the name
  1028. X         of the directory in which "brik.exe" is kept.
  1029. X
  1030. X2.2.  If you don't have "mms", use the command file supplied.  Invoke it as:
  1031. X
  1032. X     $ @makebrik
  1033. X
  1034. XWhen it exits, brik.exe should have been created in your current
  1035. Xdirectory, and the symbol "brik" should also have been defined for
  1036. Xyou.  If you move brik.exe to another directory be sure to redefine the
  1037. Xsymbol "brik" correctly as described above in part I.
  1038. X
  1039. XBe sure to read the section in the manual on VAX/VMS bugs.
  1040. X
  1041. X3.   4.xBSD, System V, and other **IX-like environments
  1042. X
  1043. XRename the file "makefile.nix" to "makefile".
  1044. X
  1045. XGive the command "make sys_v" or "make bsd" as appropriate.
  1046. X
  1047. XIf you are using Ultrix, you may wish to type "make ultrix" rather than "make
  1048. Xbsd" to get around an Ultrix bug described in "brik.h".
  1049. X
  1050. XIf you wish to use the large model library under Microport System V/AT, type
  1051. X"make uport".  To use the default small model library, type "make sys_v".
  1052. X
  1053. X                                  -- Rahul Dhesi
  1054. X                                     1989/07/11
  1055. SHAR_EOF
  1056. fi
  1057. echo shar: "extracting 'getopt.c'" '(2808 characters)'
  1058. if test -f 'getopt.c'
  1059. then
  1060.     echo shar: "will not over-write existing file 'getopt.c'"
  1061. else
  1062. sed 's/^X//' << \SHAR_EOF > 'getopt.c'
  1063. X/* ::[[ @(#) getopt.c 1.5 89/03/11 05:40:23 ]]:: */
  1064. X#ifndef LINT
  1065. Xstatic char sccsid[]="::[[ @(#) getopt.c 1.5 89/03/11 05:40:23 ]]::";
  1066. X#endif
  1067. X
  1068. X/*
  1069. XChecksum: 1099544938      (check or update this with "brik")
  1070. X*/
  1071. X
  1072. X/*
  1073. X * Here's something you've all been waiting for:  the AT&T public domain
  1074. X * source for getopt(3).  It is the code which was given out at the 1985
  1075. X * UNIFORUM conference in Dallas.  I obtained it by electronic mail
  1076. X * directly from AT&T.  The people there assure me that it is indeed
  1077. X * in the public domain.
  1078. X *
  1079. X * There is no manual page.  That is because the one they gave out at
  1080. X * UNIFORUM was slightly different from the current System V Release 2
  1081. X * manual page.  The difference apparently involved a note about the
  1082. X * famous rules 5 and 6, recommending using white space between an option
  1083. X * and its first argument, and not grouping options that have arguments.
  1084. X * Getopt itself is currently lenient about both of these things White
  1085. X * space is allowed, but not mandatory, and the last option in a group can
  1086. X * have an argument.  That particular version of the man page evidently
  1087. X * has no official existence, and my source at AT&T did not send a copy.
  1088. X * The current SVR2 man page reflects the actual behavor of this getopt.
  1089. X * However, I am not about to post a copy of anything licensed by AT&T.
  1090. X */
  1091. X
  1092. X/*
  1093. XMinor modifications by Rahul Dhesi 1989/03/06
  1094. X*/
  1095. X
  1096. X#include "brik.h"
  1097. X
  1098. X#ifdef ANSIPROTO
  1099. Xint strcmp (char *, char *);
  1100. Xchar *strchr (char *, char);
  1101. X#endif
  1102. X
  1103. X#include <stdio.h>
  1104. X
  1105. X/* Avoid possible compiler warning if we simply redefine NULL or EOF */
  1106. X#define XNULL   0
  1107. X#define XEOF (-1)
  1108. X
  1109. X#define ERR(szz,czz) if(opterr){fprintf(stderr,"%s%s%c\n",argv[0],szz,czz);}
  1110. X
  1111. Xextern int strcmp();
  1112. Xextern char *strchr();
  1113. X
  1114. Xint   opterr = 1;
  1115. Xint   optind = 1;
  1116. Xint   optopt;
  1117. Xchar  *optarg;
  1118. X
  1119. Xint
  1120. Xgetopt(argc, argv, opts)
  1121. Xint   argc;
  1122. Xchar  **argv, *opts;
  1123. X{
  1124. X   static int sp = 1;
  1125. X   register int c;
  1126. X   register char *cp;
  1127. X
  1128. X   if(sp == 1)
  1129. X      if(optind >= argc ||
  1130. X         argv[optind][0] != '-' || argv[optind][1] == '\0')
  1131. X         return(XEOF);
  1132. X      else if(strcmp(argv[optind], "--") == XNULL) {
  1133. X         optind++;
  1134. X         return(XEOF);
  1135. X      }
  1136. X   optopt = c = argv[optind][sp];
  1137. X   if(c == ':' || (cp=strchr(opts, c)) == XNULL) {
  1138. X      ERR(": illegal option -- ", c);
  1139. X      if(argv[optind][++sp] == '\0') {
  1140. X         optind++;
  1141. X         sp = 1;
  1142. X      }
  1143. X      return('?');
  1144. X   }
  1145. X   if(*++cp == ':') {
  1146. X      if(argv[optind][sp+1] != '\0')
  1147. X         optarg = &argv[optind++][sp+1];
  1148. X      else if(++optind >= argc) {
  1149. X         ERR(": option requires an argument -- ", c);
  1150. X         sp = 1;
  1151. X         return('?');
  1152. X      } else
  1153. X         optarg = argv[optind++];
  1154. X      sp = 1;
  1155. X   } else {
  1156. X      if(argv[optind][++sp] == '\0') {
  1157. X         sp = 1;
  1158. X         optind++;
  1159. X      }
  1160. X      optarg = XNULL;
  1161. X   }
  1162. X   return(c);
  1163. X}
  1164. SHAR_EOF
  1165. fi
  1166. echo shar: "extracting 'vms.c'" '(2419 characters)'
  1167. if test -f 'vms.c'
  1168. then
  1169.     echo shar: "will not over-write existing file 'vms.c'"
  1170. else
  1171. sed 's/^X//' << \SHAR_EOF > 'vms.c'
  1172. X/*
  1173. X**   A wildcard expansion function for VAX/VMS
  1174. X**   -- Rahul Dhesi
  1175. X*/
  1176. X/* ::[[ @(#) vms.c 1.5 89/03/10 19:09:28 ]]:: */
  1177. X#ifndef LINT
  1178. Xstatic char sccsid[]="::[[ @(#) vms.c 1.5 89/03/10 19:09:28 ]]::";
  1179. X#endif
  1180. X
  1181. X/*
  1182. XChecksum: 3221488897     (verify or update with "brik")
  1183. X*/
  1184. X
  1185. X#include <descrip.h>
  1186. X
  1187. X#define  FMAX  3        /* Number of different filename patterns */
  1188. X#define  PATHSIZE 1024  /* buffer area to store pathname */
  1189. X
  1190. Xchar *nextfile (what, filespec, fileset)
  1191. Xint what;                        /* whether to initialize or match      */
  1192. Xregister char *filespec;         /* filespec to match if initializing   */
  1193. Xregister int fileset;            /* which set of files                  */
  1194. X{
  1195. X   int status;
  1196. X   char *p;                      /* temp ptr */
  1197. X   struct dsc$descriptor_s d_fwild, d_ffound;
  1198. X   static int first_time [FMAX+1];
  1199. X   static char saved_fspec [FMAX+1][PATHSIZE];  /* our own copy of filespec */
  1200. X   static char found_fspec [FMAX+1][PATHSIZE];  /* matched filename */
  1201. X   static unsigned long context [FMAX+1]; /* needed by VMS */
  1202. X   if (what == 0) {
  1203. X      strcpy (saved_fspec[fileset], filespec);  /* save the filespec */
  1204. X      first_time[fileset] = 1;
  1205. X      return (0);
  1206. X   }
  1207. X
  1208. X   /* Reach here if what is not 0, so it must be 1 */
  1209. X
  1210. X   /* Create a descriptor for the wildcarded filespec */
  1211. X   d_fwild.dsc$w_length = strlen (saved_fspec[fileset]);
  1212. X   d_fwild.dsc$a_pointer = saved_fspec[fileset];
  1213. X   d_fwild.dsc$b_class = DSC$K_CLASS_S;
  1214. X   d_fwild.dsc$b_dtype = DSC$K_DTYPE_T;
  1215. X
  1216. X   d_ffound.dsc$w_length = sizeof (found_fspec[fileset]);
  1217. X   d_ffound.dsc$a_pointer = found_fspec[fileset];
  1218. X   d_ffound.dsc$b_class = DSC$K_CLASS_S;
  1219. X   d_ffound.dsc$b_dtype = DSC$K_DTYPE_T;
  1220. X
  1221. X   if (first_time[fileset]) {
  1222. X      first_time[fileset] = 0;
  1223. X      context[fileset] = 0L;   /* tell VMS this is first search */
  1224. X   }
  1225. X   status = LIB$FIND_FILE (&d_fwild, &d_ffound, &context[fileset]);
  1226. X   status = status & 1; /* use only lowest bit */
  1227. X
  1228. X   if (status == 0) {
  1229. X      LIB$FIND_FILE_END (&context[fileset]);
  1230. X      return ((char *) 0);
  1231. X   } else {
  1232. X      found_fspec[fileset][d_ffound.dsc$w_length] = '\0'; /* just in case */
  1233. X      p = found_fspec[fileset];
  1234. X      while (*p != ' ' && *p != '\0')
  1235. X         p++;
  1236. X      if (*p != '\0')
  1237. X         *p = '\0';
  1238. X      return (found_fspec[fileset]);
  1239. X   }
  1240. X}
  1241. X
  1242. X/* Compensate for bug in VAX/VMS C exit() function */
  1243. X
  1244. X#ifdef exit
  1245. X# undef exit
  1246. X#endif
  1247. X
  1248. Xint bugexit (n)
  1249. Xint n;
  1250. X{
  1251. X   exit (1);
  1252. X}
  1253. SHAR_EOF
  1254. fi
  1255. exit 0
  1256. #    End of shell archive
  1257.  
  1258.  
  1259.