[comp.compression] uncompress.c - uncompress files in Unix `compress' format

eggert@twinsun.com (Paul Eggert) (05/04/91)

Here is a short C program that accepts standard input in Unix
`compress' format and generates the corresponding uncompressed standard
output.  It is a strictly conforming ANSI C program, compiles in
traditional C, and is portable to a wide variety of machines.  It is
derived from code in the compressed archiving program `shark', in which
understandability has been sacrificed for brevity.

/*uncompress.c by James A. Woods and Paul Eggert*/
#include<stdio.h>
#define G getchar()
#define H (w=g())
#define K [69001]
#define P putchar
#define Q 256
#define W while
#define X return 0
#define Z w=Q;W(w--)t[w]=0
long c,f,m,o,w;int O,S,e,i,k,n,q,t K;char D K,h K;long
g(){char*p;if(m<f&n<k&&(m=(1l<<++n)-1)||O>=S){O=0;S=fread(D,1,n,stdin)*8;if(S<8
)X-1;S-=n-1;}p=D+O/8;q=O&7;O+=n;X,(1<<8-q)-1&*p>>q|m&((15<n+q)*p[2]*Q|p[1]&255)
<<8-q;}main(){char*p=D+Q;G;G;k=G;e=k>>7&1;k&=31;if(k>16)X,perror("uncompress"),
1;Z,h[w]=w;n=8;f=Q+e;i=o=H;if(o<0)X,1;P(i);W(H+1){if(w==Q&e){Z;m=n=8;f=Q;if(H<0
)X;}c=w;if(w>=f)*p++=i,w=o;W(w>=Q)*p++=h[w],w=t[w];P(i=h[w]);W(p>D+Q)P(*--p);if
((w=f)<1l<<k)t[w]=o,h[f++]=i;o=c;}X;}