regan@jacobs.CS.ORST.EDU (Dave Regan) (04/28/89)
The following is a simple program (with documentation suitable for the
help file) which reads the CRC lists that Dr Tanenbaum occasionally
publishes and lets you know what is different.
Dave Regan
regan@jacobs.cs.orst.edu
------------------------ Cut Here ---------------------------
echo x - READ.ME
sed '/^X/s///' > READ.ME << '/'
XWhile bringing up Minix through the various versions using the updates
Xprovided on the network, I wanted to make use of the CRC listings which
XDr Tanenbaum provides. I attempted to put some shell files together
Xusing "diff" and other tools, but wasn't really satisfied.
X
XSo, I hacked together a simple little program to read the CRC lists
Xas published and run "crc" for each file listed, and compare the results.
XThis gives me exactly what I want (undoubtably not what anyone else wants).
XThe main drawback is that it is quite slow.
X
XUse this as you see fit.
X
X Dave Regan
X PO Box 601
X Corvallis OR 97339 USA
X regan@jacobs.cs.orst.edu
X 27 April 1989
/
echo x - check_crc.c
sed '/^X/s///' > check_crc.c << '/'
X/*
X * Check_crc.c -- Check the current file system against a CRC list
X * Version 1.00 27 April 1989
X *
X * Usage:
X * check_crc [directory] <script >differences
X *
X * The report lists the file name, along with the official and obtained
X * crcs and counts. The obtained values are printed in parenthesis.
X * file crc 123 (44), count 33 (23)
X *
X * There are undoubtably better ways of doing this. Perhaps using the
X * shell or AWK. I did it this way anyway.
X *
X * This program is Public Domain. Do what you want with it.
X *
X * Dave Regan
X * regan@jacobs.cs.orst.edu
X * 27 April 1989
X */
X
X/*
X * Notes:
X *
X * I tried a version of this which used "popen" instead of a temporary
X * file. This wasn't any faster, and somewhat less portable.
X */
X
X#include <ctype.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X
X#define LINESIZE 100
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X {
X char cmd[50];
X long cor_count;
X long cor_crc;
X char *cptr;
X long cur_count;
X long cur_crc;
X FILE *fd;
X char *file;
X char line[LINESIZE+1];
X char line2[LINESIZE+1];
X
X if (argc < 1 || argc > 2)
X {
X fprintf(stderr, "Usage: check_crc [directory] <script >differences\n");
X exit(1);
X }
X if (argc == 2)
X chdir(argv[1]);
X
X while (fgets(line, LINESIZE, stdin) != NULL)
X {
X if ((cptr = strchr(line, '\n')) != NULL)
X *cptr = '\0';
X if (line[0] == '\0' || line[0] == '#')
X continue;
X for (cptr = line; isdigit(*cptr); cptr++)
X ;
X while (isspace(*cptr))
X cptr++;
X while (isdigit(*cptr))
X cptr++;
X while (isspace(*cptr))
X cptr++;
X file = cptr;
X
X if (access(file, 0) < 0)
X {
X printf("%-40sDoes not exist\n", file);
X continue;
X }
X
X sprintf(cmd, "crc %s >/tmp/crc%05d", file, getpid());
X system(cmd);
X sprintf(cmd, "/tmp/crc%05d", getpid());
X if ((fd = fopen(cmd, "r")) != NULL)
X {
X fgets(line2, LINESIZE, fd);
X fclose(fd);
X if ((cptr = strchr(line2, '\n')) != NULL)
X *cptr = '\0';
X if (strcmp(line, line2) != 0)
X {
X sscanf(line, "%ld %ld", &cor_crc, &cor_count);
X sscanf(line2, "%ld %ld", &cur_crc, &cur_count);
X printf("%-40scrc %ld (%ld), count %ld (%ld)\n",
X file, cor_crc, cur_crc, cor_count, cur_count);
X }
X }
X }
X sprintf(cmd, "/tmp/crc%05d", getpid());
X unlink(cmd);
X }
/
echo x - check_crc.man
sed '/^X/s///' > check_crc.man << '/'
X# check_crc
XCommand: check_crc - check the current disk against published CRC lists
XSyntax: check_crc [starting_directory] <crc_list >differences
XFlags: (none)
XExample: check_crc /usr <crc.ast >crc.wrong
X
X Check_crc is a program which scans through the CRC lists which
XDr. Tanenbaum occasionally publishes. For each line in the standard
Xinput, "check_crc" forks off a copy of "crc" for the appropriate file
Xand compares the results. If the CRC or byte count do not match, a line
Xis written to standard output describing the difference.
X
X The starting directory is chosen such that when "check_crc" changes
Xto that directory, all the file names in the standard input can be
Xsuccessfully opened.
X
X Blank lines, and line starting with a pound sign ('#') are ignored.
X
X This program is horribly slow, but does get the job done.
/