home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / binaries / ibm / pc / 1062 < prev    next >
Encoding:
Text File  |  1993-01-02  |  49.8 KB  |  1,305 lines

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