home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / BRIK.ZIP / BRIK.DOC < prev    next >
Text File  |  1989-03-13  |  19KB  |  460 lines

  1.                                  Brik  1.0
  2.                             A free CRC-32 program
  3.                                      by
  4.                                  Rahul Dhesi
  5.  
  6. Brik 1.0 generates and verifies 32-bit CRC values (checksums).  It is
  7. designed to generate CRCs for text files that are the same on all computer
  8. systems that use the ASCII character set, provided each text file is in the
  9. usual text file format for each system.  Brik 1.0 will also optionally use
  10. binary CRCs calculated using every byte in a file.  Such binary CRCs are
  11. portable across systems for binary files that are moved from system to system
  12. without any newline conversion.
  13.  
  14. The general usage format is:
  15.  
  16.      brik -gcGCbfvsWT [file] ...
  17.  
  18. The brackets mean that "file", which is the name of a file, is optional.  The
  19. three dots indicate that more than one filenames may be typed (separated by
  20. blanks).  Exactly one of the options -c, -C, -g, -G, or -h is required.  The
  21. -h option gives a help screen.
  22.  
  23. In addition to -h, the brik options available (as they appear on the help
  24. screen) are:
  25.  
  26.    -g     look for Checksum: header, generate CRC for rest of file
  27.    -c     get CRC from header, verify CRC of rest of file
  28.    -G     generate CRC for entire file (add -b for binary files)
  29.    -C     verify all file CRCs from output of -G (-f is not needed)
  30.    -b     use binary mode--read file byte by byte, not line by line
  31.    -f     read filenames (wildcards ok) from specified files
  32.    -v     be verbose, report all results (else only errors are reported)
  33.    -s     be silent, say nothing, just return status code
  34.    -W     after generating CRC with -g, write it to original header
  35.    -T     include trailing empty lines, normally ignored (text mode only)
  36.  
  37.  
  38. VERIFYING CRC HEADERS
  39.  
  40. The primary intended use of brik is to verify Checksum: headers in Usenet
  41. postings and in C and Pascal source files.  A Checksum: header looks like
  42. this:
  43.  
  44.      Checksum: 9485762645   (verify or update this with "brik")
  45.  
  46. The word "Checksum:" must occur at the beginning of a line.  It is followed
  47. by a colon, an optional blank, a ten-digit CRC-32 value, and any arbitrary
  48. optional string such as the comment shown above.  When brik is invoked with
  49. the syntax
  50.  
  51.      brik -c file ...
  52.  
  53. it will search for the Checksum: header in each specified file, read the CRC
  54. value from that header, calculate the CRC-32 for all lines in the file that
  55. occur *after* the header line, and report an error if the two values do not
  56. match.  Brik ignores any trailing empty lines.
  57.  
  58.  
  59. CALCULATING CRC HEADERS
  60.  
  61. The command
  62.  
  63.      brik -g file ...
  64.  
  65. tells brik to look for the Checksum: header in each specified file, calculate
  66. the CRC of the lines in the file following the header, and print the CRC and
  67. filename without changing the file in any way.  You can also ask brik to
  68. update the Checksum: header with the following command:
  69.  
  70.      brik -gW file ...
  71.  
  72. This causes brik to fill in the newly-calculated CRC in the Checksum: header.
  73. If there is not enough space for the CRC value in the existing header, brik
  74. reports an error and does not change the existing header.  To initially add
  75. a Checksum: header to a file, insert a line of the following form into the
  76. file with a text editor:
  77.  
  78.      Checksum: XXXXXXXXXX  -- this is an optional comment
  79.  
  80. The word "Checksum" must be at the beginning of a line.  The ten 'X'
  81. characters shown can be any ten characters.  They will be later replaced by
  82. the calculated CRC value.  They do not need to be 'X'.  The comment
  83. following them is optional and can be any arbitrary string of characters
  84. after the CRC field, separated from it by a blank.  As an example, in a C
  85. source file called "main.c", you might have:
  86.  
  87.      /*
  88.      Checksum: XXXXXXXXXX (verify or update this with brik)
  89.      */
  90.  
  91. Once a header like this exists in the file, invoke brik as follows:
  92.  
  93.      brik -gW main.c
  94.  
  95. This will cause the ten 'X' characters to be replaced with the calculated
  96. checksum, giving something like this:
  97.  
  98.      /*
  99.      Checksum: 1922837484 (verify or update this with brik)
  100.      */
  101.  
  102. Later you can use the command
  103.  
  104.      brik -c main.c
  105.  
  106. to verify that the contents of the file following the header have the same
  107. CRC as the stored value.
  108.  
  109. If brik is invoked with the -c or -g options and it cannot find a Checksum:
  110. header in a file, it prints a row of question marks.  If it is invoked with
  111. the -gW option and it does not find enough character positions after the
  112. "Checksum:" string to hold the CRC, it does not fill in the CRC and prints an
  113. error message.
  114.  
  115. When calculating the CRC to fill in with the -gW option, brik ignores any
  116. trailing empty lines in the file.
  117.  
  118.  
  119. WHOLE-FILE CRCS
  120.  
  121. A "whole-file" CRC calculation is done for the entire contents of a file,
  122. without looking for a Checksum: header.  The command
  123.  
  124.      brik -G file ...
  125.  
  126. asks brik to do this calculation for all specified files.  The output from
  127. this command is a list of files and their whole-file CRCs.  It is sent to the
  128. standard output stream, which in most cases is your screen.  The output
  129. should be saved in a file by redirecting it.  For example, the command
  130. "brik -G *.h *.c > crc.lst" on an MS-DOS system might yield the following in
  131. the output file "crc.lst":
  132.  
  133.      # Whole file CRCs generated by Brik v1.0.  Use "brik -C" to verify them.
  134.  
  135.      # CRC-32        filename
  136.      # ------        --------
  137.  
  138.      2566277976      getopt.c
  139.       100594287      brik.c
  140.      1151475469      vms.c
  141.      3929503738      turboc.c
  142.      2424271922      addbfcrc.c
  143.      1943472856      assert.h
  144.      2601923477      brik.h
  145.  
  146. The output of the -G option is in free format.  The output file may be edited
  147. by hand.  Empty lines and lines beginning with '#' will be ignored by brik
  148. when it is later asked to read this file.
  149.  
  150. This list of filenames and whole-file CRCs may be verified by a command like
  151. this:
  152.  
  153.      brik -C crc.lst
  154.  
  155. This makes brik read the file "crc.lst", get the CRCs and filenames from it,
  156. do the CRC calculation again for each file, and report an error if it does
  157. not match the CRC recorded inside "crc.lst".
  158.  
  159. **IX and MS-DOS users (and others who can pipe the output of one command into
  160. another) could use a command like the following to see if brik's -G and -C
  161. options are working:
  162.  
  163.      brik -G file ... | brik -C
  164.  
  165. This invokes "brik -G" on some files, sending the output to a pipe where it
  166. becomes the input of "brik -C".  If no filename is specified, brik reads from
  167. standard input, so "brik -C" will read from the pipe and concurrently verify
  168. all the CRCs that are being generated by "brik -G".
  169.  
  170. Whole-file CRCs are normally generated in text mode, in which a file is
  171. treated as lines of text.  In this mode brik ignores any trailing empty lines
  172. in a file.  You can also generate whole-file CRCs in binary mode.  See
  173. below.
  174.  
  175.  
  176. BINARY VERSUS TEXT MODE 
  177.  
  178. Brik can work in two different modes.  The most common mode, used by the -g,
  179. -c, and -G options, is text mode.  In this mode brik ignores all trailing
  180. empty lines in files.  (See more about this below.)
  181.  
  182. In text mode, brik reads all files line by line, and forces lines to be
  183. terminated by a newline character of constant value before doing a CRC
  184. calculation.  Thus, no matter what newline character is used by your system,
  185. the CRC calculation will be unaffected.  This means that whether your
  186. operating system uses linefeeds to terminate lines (e.g. **IX), or a carriage
  187. return and a linefeed (e.g.  MS-DOS) or a carriage return only (e.g.
  188. Macintosh) or nothing but a record length field (e.g. VAX/VMS), the CRC
  189. calculation in text mode gives the same results.
  190.  
  191. If a file is not intended to be a text file, the text mode CRC calculated by
  192. brik may not be reliable or the same on all systems for the same file.  Brik
  193. can be asked to operate in binary mode by adding a -b option to the option. 
  194. Binary mode is applicable only to the -G option, which acts on whole files. 
  195. Thus while "brik -G file..." finds whole-file CRCs of all specified files in
  196. text mode, "brik -Gb file ..." does the same in binary mode.  In binary mode
  197. brik attempts no newline compensation, but simply reads and calculates the
  198. CRC for all bytes in a file.  Provided a file is moved from one system to
  199. another without any changes, brik should calculate the same CRC for it on
  200. both systems.
  201.  
  202. The output from "brik -Gb" includes a trailing 'b' character in each CRC, so
  203. "brik -C" will correctly use text or binary mode as needed, and -Cb is
  204. equivalent to just -C.
  205.  
  206.  
  207. TRAILING EMPTY LINES
  208.  
  209. The normal behavior of brik in text mode is to ignore any trailing empty lines
  210. in a file when checking or updating the CRC in a Checksum: header.  An empty
  211. line is a line that contains nothing, not even blanks or tabs.  (Just hitting
  212. a carriage return when you are editing a text file usually produces an empty
  213. line.)   If manipulating a text file causes trailing empty lines to be added
  214. or deleted, the CRC calculated by brik will be unaffected.
  215.  
  216. You can override this if necessary with the -T option, which makes brik
  217. include trailing empty lines in the CRC calculation.  For example,
  218. "brik -gWT" will update the Checksum: header with a CRC value that includes
  219. all lines in a text file.  Similarly "brik -GT" will find whole-file CRCs
  220. that include all lines in a text file.
  221.  
  222. When brik is given the -T option, it adds a 'T' suffix to each generated CRC
  223. value.  Then, when the CRC is verified with "brik -c" or "brik -C", brik will
  224. correctly include trailing empty lines without having to be explicitly told
  225. to do so.
  226.  
  227. In binary mode brik always reads all bytes in a file, so it does not ignore
  228. trailing empty lines, and the -T switch is not needed.
  229.  
  230. The -T and -b options are mutually exclusive, since the first is used only
  231. for text mode and the second is used only for binary mode.  If both are
  232. given, whichever is used later overrides the first.  This "-bT" is equivalent
  233. to "-T" and "-Tb" is equivalent to "-T".
  234.  
  235.  
  236. FILENAME CONVENTIONS
  237.  
  238. Under MS-DOS and VAX/VMS, wildcards are allowed on the command line and will
  239. be expanded by brik.  Under **IX, wildcards are expected to be expanded by
  240. the shell and are not expanded by brik.
  241.  
  242. If no filename is given, brik reads its standard input.  By default this is
  243. keyboard input, but it is expected that input will usually be redirected to
  244. come from a file or a pipe.  Also, if a filename is explicitly specified as a
  245. dash ("-"), it stands for standard input.
  246.  
  247. Thus the following five commands (valid under the **IX operating system)
  248.  
  249.      brik -c myfile           # verify "myfile"
  250.      brik -c < myfile         # verify stdin, which is "myfile"
  251.      cat myfile | brik -c     # verify stdin, which is a pipe
  252.      brik -c - < myfile       # verify "-", which is stdin, which is "myfile"
  253.      cat myfile | brik -c -   # verify "-", which is stdin, which is a pipe
  254.  
  255. all have the effect of verifying the Checksum: header in the file "myfile".
  256.  
  257. Standard input can also be read by "brik -C".  For example, suppose we have
  258. already given the command
  259.  
  260.      brik -G *.c *.h > crc.lst
  261.  
  262. to create a file called "crc.lst" that contains a list of whole-file CRCs.  We
  263. can now verify the integrity of these files with any of the following
  264. commands:
  265.  
  266.      brik -C crc.lst          # read "crc.lst"
  267.      brik -C < crc.lst        # read stdin, which is "crc.lst"
  268.      brik -C - < crc.lst      # read "-", which is stdin, which is "crc.lst"
  269.      cat crc.lst | brik -C    # read stdin, which is a pipe
  270.      cat crc.lst | brik -C -  # read "-" which is stdin which is a pipe
  271.  
  272.  
  273. INDIRECT FILE NAMING
  274.  
  275. The -f option allows you to have filenames in a list rather than on the
  276. command line.  For example, suppose you want to generate whole-file CRCs of
  277. files whose names are selected by some other program.  You could use "find"
  278. (under **IX) or "stuff" (under MS-DOS) to generate a list of filenames.  When
  279. the -f option is given, brik reads filenames, one per line, from the file(s)
  280. specified.  Thus you could do the following:
  281.  
  282.      find . -mtime +3 -print > flist
  283.      brik -Gf flist > crc.lst
  284.  
  285. The first command asks "find" to generate a list of names of all files that
  286. were modified more than 3 days ago, and sends the output to the file "flist".
  287. The contents of "flist" might now look like this, as an example:
  288.  
  289.    ./sez.doc
  290.    ./brik.doc
  291.    ./stuff.doc
  292.    ./looz.doc
  293.    ./fiz.man
  294.  
  295. The second command above asks brik to read the file called "flist", get a 
  296. list of filenames from it, one per line, and generate the whole-file CRC of
  297. each of these files.  We additionally redirect the output of "brik -Gf" to
  298. the file called "crc.lst".  Given the above contents of "flist", the following
  299. two commands are exactly equivalent:
  300.  
  301.      brik -Gf flist > crc.lst
  302.      brik -G ./sez.doc ./brik.doc ./stuff.doc ./looz.doc ./fiz.man > crc.lst
  303.  
  304. The advantage of the -f option is that once you have filenames in a file,
  305. you need not type them again at the command line.  The -f option also allows
  306. you to feed brik filenames generated by another program through a pipe.
  307. Consider this command:
  308.  
  309.      find . -mtime +3 -print | brik -Gf - > crc.lst
  310.  
  311. Under **IX this concurrently invokes both "find" and brik.  As find
  312. generates a filename and sends it to its standard output (a pipe), brik reads
  313. the filename from its standard input and generates its whole-file CRC.
  314. The following pipeline
  315.  
  316.      find . -mtime +3 -print | brik -Gf - | brik -C -
  317.  
  318. invokes "find" to generate filenames, brik to print the whole-file CRCs of
  319. those files, and brik again to immediately verify them.
  320.  
  321. Under MS-DOS and VAX/VMS (and any other operating system under which brik has
  322. been installed to expand wildcards itself), a file specified by the -f option
  323. can itself contain wildcards in the filenames.  For example, suppose the file
  324. "wildfile" contains the following lines:
  325.  
  326.      /bin/*.exe
  327.      /bin/*.com
  328.      /doc/*.doc
  329.  
  330. Now if we invoke brik with the command
  331.  
  332.      brik -Gf wildfile
  333.  
  334. it will read filespecs from "wildfile", expand wildcards in each filespec,
  335. and generate whole-file CRCs for all matching files.
  336.  
  337. If you are checking whole-file CRCs with the -C option, you do *not* normally
  338. need to use the -f option, as the -f option introduces an additional level of
  339. file naming indirection.  For example, the command
  340.  
  341.      brik -C crc.lst
  342.  
  343. takes a list of CRCs and filenames from "crc.lst" and verifies them. 
  344. However, the command
  345.  
  346.      brik -Cf master.lst
  347.  
  348. does not do the same thing.  Instead, it takes a list of files from
  349. "master.lst", looks inside each of *those* files for a list of CRCs and
  350. filenames, and verifies them.
  351.  
  352. As an example of the use of -Cf, consider this sequence:
  353.  
  354.      brik -Gb /bin/*.exe > exelist
  355.      brik -Gb /bin/*.com > comlist
  356.      brik -GT /doc/*.doc > doclist
  357.      brik -G  /doc/*.man > manlist
  358.  
  359. Now we have four files called "exelist", "comlist", "doclist", and "manlist"
  360. containing whole-file CRCs of various types.  We can test the integrity of
  361. files listed in these in four separate commands like this:
  362.  
  363.      brik -C exelist
  364.      brik -C comlist
  365.      brik -C doclist
  366.      brik -C manlist
  367.  
  368. But we could also do this in a single step by first creating a file called
  369. "biglist" that contains the names of these four files:
  370.  
  371.      exelist
  372.      comlist
  373.      doclist
  374.      manlist
  375.  
  376. and then use -Cf thus:
  377.  
  378.      brik -Cf biglist
  379.  
  380. This causes brik to read filenames from "biglist", look inside each of those
  381. files ("exelist", "comlist", "doclist", and "manlist") and check the CRCs
  382. found there.  A **IX example to do the same thing in a more compact
  383. way might be:
  384.  
  385.      cat exelist comlist doclist manlist | brik -Cf -
  386.  
  387.  
  388. SILENT VERSUS VERBOSE
  389.  
  390. Brik accepts options -s and -v that cause it to be more silent or more
  391. verbose than usual.
  392.  
  393. Normally brik prints a message only if it detects an error.  For example,
  394. if you give the command "brik -c *.c *.h" and brik finds that all Checksum:
  395. headers contain CRCs that match the calculated value, it prints nothing.
  396.  
  397. The -v switch makes brik print a message for each file tested that contains the
  398. word "ok" if stored and calculated CRCs matched and "BAD" if they did not.
  399.  
  400. In all messages reporting file CRCs, brik prints the actual CRC it calculated,
  401. or a row of question marks if it could not calculate one.  Brik fails to
  402. calculate a CRC if it is trying to calculate a header-based CRC (commands
  403. -c and -g) but does not find a Checksum: header in a file.
  404.  
  405. The -s switch tells brik to be silent.  This will cause nothing to be printed
  406. if brik does not find a Checksum header or if CRCs don't match.  However, the
  407. status code on exit is still set.  The -s option is useful for invoking brik
  408. from within a shell script (**IX) or a batch file (MS-DOS) and later testing
  409. the error code it returned when it exited.
  410.  
  411. The -s switch does not suppress the error message printed if brik is given a
  412. filename and the file cannot be found.  For example, if the command
  413. "brik -cs myfile" is given but "myfile" does not exist, brik will print an
  414. error message even though the -s option was given.
  415.  
  416.  
  417. VAX/VMS BUGS
  418.  
  419. o    Under VAX/VMS, file manipulation is unpredictable and the VAX/VMS C
  420.      runtime library in particular is very unreliable.  One result is that
  421.      under VAX/VMS, the -gW option will work only for stream-LF files, which
  422.      are the only type of file that VAX/VMS seems to handle correctly.
  423.      Fortunately, the -c option will correctly work for VAX/VMS standard
  424.      text files.
  425.  
  426. o    The VAX/VMS implementation of brik 1.0 simply ignores filenames that
  427.      correspond to nonexistent files instead of giving an error message.
  428.      This bug will be fixed as soon as I figure out why wildcard expansion
  429.      code that used to work properly with VAX/VMS a year ago doesn't work
  430.      any more.
  431.  
  432. o    To avoid annoying error messages, brik under VAX/VMS always exits with
  433.      a status code of 1.
  434.  
  435. o    Due to a problem in the VAX/VMS command interpreter, if any uppercase
  436.      option characters are typed (e.g. -C, -G, -T), brik will not recognize
  437.      them as uppercase unless they are enclosed in double quotes.  An
  438.      example of a correct command under VAX/VMS:
  439.  
  440.           brik "-GT" *.*
  441.  
  442.      An example of a command that won't work:
  443.  
  444.           brik -GT *.*
  445.  
  446.  
  447. PROGRAM LIMITATIONS
  448.  
  449. Brik 1.0 is designed to work with computer systems that use the 7-bit ASCII
  450. character set and 8-bit bytes with the eighth (parity) bit set to zero.
  451.  
  452. Brik 1.0 has not been tested with computer systems that use ASCII characters
  453. with the eighth bit set or those that use EBCDIC characters.  Although
  454. it will calculate a CRC on such machines, the probability of this CRC being
  455. the same as the one calculated on machines that use 7-bit ASCII is
  456. approximately 0.00000000023.
  457.  
  458.                                     -- Rahul Dhesi
  459.                                        1989/03/13
  460.