Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!uwvax!oddjob!gargoyle!ihnp4!cbatt!cwruecmp!hal!ncoast!allbery From: karl@mstar.UUCP Newsgroups: comp.sources.misc Subject: Very small ZCAT program for decompressing *.Z files Message-ID: <8705141214.AA19848@mstar.UUCP> Date: Thu, 14-May-87 11:14:37 EDT Article-I.D.: mstar.8705141214.AA19848 Posted: Thu May 14 11:14:37 1987 Date-Received: Tue, 19-May-87 04:41:34 EDT References: <3655@mirror.TMC.COM> Sender: allbery@ncoast.UUCP Reply-To: karl@mstar.UUCP (Karl Fox) Organization: Morning Star Technologies, Columbus, Ohio Lines: 57 Approved: allbery@ncoast.UUCP Status: R Sorry if this is too short -- I didn't know where else to put it. This 'zcat' program works much like the standard public domain zcat (which is usually linked to compress and uncompress), except that it is only a filter -- no command line arguments are used. We use it frequently when shipping compressed software to customers over UUCP, many of whom are not UNIX wizards and don't routinely get good stuff like compress.c from usenet. I was going to submit it to the Obfuscated C contest until I saw the requirement about entries being original work. This program is derived directly from the public domain compress.c. It requires that your machine be able to support 16-bit decompression, which uses very large arrays for hashing. If somebody wanted to make a SHAR that could compress and uuencode files, then include a small program (like this, but with uudecode, too?) that could transform it back, I would kiss their feet. #!/bin/sh # # This is a SHAR archive. To extract, remove everything # above the #!/bin/sh line and type "sh filename" # if `test ! -s ./zcat.c` then echo "Writing ./zcat.c" sed 's/^X//' > ./zcat.c << '\End\of\File\ ./zcat.c' X#include X#define d define X#d G getchar() X#d I if X#d H(n) ((C*)h)[n] X#d C char X#d U unsigned long X#d u unsigned short X#d R register C* X#d B(n) (1<<(n)) X#d V(a,b) (a&(B(b)-1)) X#d E {fprintf(stderr,"Bad COMPRESS file format\n");exit(1);} Xint i,q,b,n,k=16,e=128,j=0,O=0,S=0;u t[69001];long o,v,c,m,M=B(16),f=0;U h[ X69001];C D[16];long g(){R p=D;I(j>0||O>=S||f>m){I(f>m)m= ++n==k?M:B(n)-1;I(j>0) Xm=B(n=9)-1,j=0;S=fread(D,1,n,stdin);I(S<=0)return-1;O=0;S=(S<<3)-n+1;}q=O;b=n;p X+=q>>3;q&=7;c=V(*p++>>q,8-q);q=8-q;b-=q;I(b>=8)c|=(*p++&255)< X16)E;z();exit(0);}z(){long w;R s;m=B(n=9)-1;for(w=255;w>=0;w--)t[w]=0,H(w)=(C)w X;f=e?257:256;i=o=g();I(o==-1)return;putchar((C)i);s=(C*)&H(B(16));while((w=g()) X>-1){I(w==256&&e){for(w=255;w>=0;w--)t[w]=0;j=1;f=256;I((w=g())==-1)break;}v=w; XI(w>=f)*s++=i,w=o;while((U)w>=(U)256)*s++=H(w),w=t[w];*s++=i=H(w);do putchar(* X--s);while(s>&H(B(16)));I((w=f)