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);
47 for (i = 0; i <= UCHAR_MAX; i++) {
49 for (j = 0; j < CHAR_BIT; j++)
51 r = (r >> 1) ^ CRCPOLY;
60 { /* Shift bitbuf n bits left, read n bits */
62 while (n > bitcount) {
63 bitbuf |= subbitbuf << (n -= bitcount);
66 subbitbuf = (uchar) getc(arcfile);
72 bitbuf |= subbitbuf >> (bitcount -= n);
80 x = bitbuf >> (BITBUFSIZ - n);
86 putbits(int n, uint x)
87 { /* Write rightmost n bits of x */
89 subbitbuf |= x << (bitcount -= n);
92 if (compsize < origsize) {
93 putc(subbitbuf | (x >> (n -= bitcount)), outfile);
99 subbitbuf = x << (bitcount = CHAR_BIT - n);
102 if (compsize < origsize) {
103 putc(x >> (n - CHAR_BIT), outfile);
108 subbitbuf = x << (bitcount = 2 * CHAR_BIT - n);
114 fread_crc(uchar * p, int n, FILE * f)
118 i = n = fread(p, 1, n, f);
126 fwrite_crc(uchar * p, int n, FILE * f)
128 if (fwrite(p, 1, n, f) < n)
129 error("Unable to write");