1 /***********************************************************
3 ***********************************************************/
8 #define CRCPOLY 0xA001 /* ANSI CRC-16 */
11 FILE *arcfile, *infile, *outfile;
15 ushort crctable[UCHAR_MAX + 1];
16 static uint subbitbuf;
25 vfprintf(stderr, fmt, args);
32 message(char *fmt, ...)
37 vfprintf(stderr, fmt, args);
48 vfprintf(stderr, fmt, args);
58 for (i = 0; i <= UCHAR_MAX; i++) {
60 for (j = 0; j < CHAR_BIT; j++)
62 r = (r >> 1) ^ CRCPOLY;
71 { /* Shift bitbuf n bits left, read n bits */
73 while (n > bitcount) {
74 bitbuf |= subbitbuf << (n -= bitcount);
77 subbitbuf = (uchar) getc(arcfile);
83 bitbuf |= subbitbuf >> (bitcount -= n);
91 x = bitbuf >> (BITBUFSIZ - n);
97 putbits(int n, uint x)
98 { /* Write rightmost n bits of x */
100 subbitbuf |= x << (bitcount -= n);
103 if (compsize < origsize) {
104 putc(subbitbuf | (x >> (n -= bitcount)), outfile);
110 subbitbuf = x << (bitcount = CHAR_BIT - n);
113 if (compsize < origsize) {
114 putc(x >> (n - CHAR_BIT), outfile);
119 subbitbuf = x << (bitcount = 2 * CHAR_BIT - n);
125 fread_crc(void *p, int n, FILE * f)
129 i = n = fread(p, 1, n, f);
132 UPDATE_CRC(*(unsigned char*)p++);
137 fwrite_crc(void *p, int n, FILE * f)
139 if (fwrite(p, 1, n, f) < n)
140 error("Unable to write");
142 UPDATE_CRC(*(unsigned char*)p++);