/* The following routines can be used to interpret the crc_table. First use init_crc; then add_crc for each character, from first to last; and finally, as report_crc to yield the result. It is probably much more convenient to code these routines inline; this file serves primarily as documentation. */ #include #include "crc_tab.h" static unsigned short crc; void init_crc() { crc = 0; } void add_crc(c) unsigned char c; { crc = crc_table[(crc & 0x00ff) ^ c] ^ (crc >> 8); } unsigned short report_crc() { return crc; } void crcfile(name) char *name; { FILE *f; int c; unsigned short ck; printf("crc %s ", name); f = fopen(name, "rb"); if (!f) { printf("cannot find %s\n", name); return; } init_crc(); while((c = getc(f)) >= 0) { add_crc(c); } ck = report_crc(); #ifdef AMIGA printf("0x%x %d\n", ck, ck); #else printf("%#.4x %d\n", ck, ck); #endif fclose(f); return; } void main(argc, argv) int argc; char *argv[]; { int i; char **c; if (argc < 2){ printf("crc filenames\n"); exit(1); } c = &(argv[1]); i=argc; while(--i) crcfile(*c++); exit(0); }