// Uncompress a file compressed with 7bit.c. #include #include int bitbuffer, bufptr; int consume(int nbits, int *where) { while (bufptr < nbits) { bitbuffer <<= 8; int byte = getchar(); if (byte == EOF) return 0; bitbuffer |= (byte & 0xff); bufptr += 8; } bufptr -= nbits; *where = (bitbuffer>> bufptr) & ((1 << nbits) - 1); return 1; } void decompress() { int chunk; while (consume(7, &chunk)) { if (chunk == 0x7f) { if (!consume(8, &chunk)) break; // escape padding at EOF } if (putchar(chunk) == EOF) abort(); } } int usage(char *argv0) { fprintf(stderr, "Usage: %s < infile> outfile\n", argv0); return 1; } int main(int argc, char **argv) { if (argc != 1) return usage(argv[0]); decompress(); return 0; }

AltStyle によって変換されたページ (->オリジナル) /