#define VERSION "ZTYPE - Zipfile Typer, Vers. 1.0 by C. Wilson" #define STRSIZ 20 #define EIGHTK 8192 #define FOURK 4096 #define ONEK 1024 #define HALFK 512 #define PAGE 256 char lres[4]; /* junk storage for ladd, etc. */ char loffset[4]; char longone[4]; char LOneK[4]; char LZero[4]; char skipflag; char moreflag; char scrline; char nextprop; char propch[4]; /* "-,\,|,/" */ int lastout; int scrcnt; int inch; char jmpbuf[JBUFSIZE]; /* for setjmp() */ int count; unsigned mask; /* ----------------------------------------------------------- */ /* * Zipfile layout declarations * */ #define LOCAL0 0x4B50 /* local signature */ #define LOCAL1 0x0403 struct local_file_header { unsigned version_needed_to_extract; unsigned general_purpose_bit_flag; unsigned compression_method; unsigned time_last_file_mod; unsigned last_mod_file_date; char crc32[4]; char compr_size[4]; char uncompressed_size[4]; unsigned fname_length; unsigned extra_field_length; }; #define CENTRAL0 0x4B50 /* central signature */ #define CENTRAL1 0x0201 struct central_directory_file_header { unsigned version_made_by; unsigned cent_version_needed_to_extract; unsigned cent_general_purpose_bit_flag; unsigned cent_compression_method; unsigned cent_time_last_file_mod; unsigned cent_last_mod_file_date; char cent_crc32[4]; char cent_c_size[4]; char cent_uncompressed_size[4]; unsigned cent_filename_length; unsigned cent_extra_field_length; unsigned file_comment_length; unsigned disk_number_start; unsigned internal_file_attributes; char external_file_attributes[4]; char relative_offset_local_header[4]; }; #define END0 0x4B50 /* end signature */ #define END1 0x0605 struct end_central_dir_record { unsigned number_this_disk; unsigned number_disk_with_start_central_directory; unsigned this_disk_total_entries_central_dir; unsigned total_entries_central_dir; char size_central_directory[4]; char offset_start_central_directory[4]; unsigned zipfile_comment_length; }; /* ----------------------------------------------------------- */ /* * input file variables * */ #define INBUFSIZ 0x100 char inputbuf[INBUFSIZ]; char *inbuf; char *inptr; int incnt; int bitbuf; int bits_left; char zipeof; int zipfd; char zipfn[STRSIZ]; char zipmn[STRSIZ]; struct local_file_header lrec; /* ----------------------------------------------------------- */ /* * output stream variables * */ char *outbuf; /* buffer for rle look-back */ char *outptr; char outpos[4]; /* absolute position in outfile */ char outcnt[4]; /* current position in outbuf */ int outfd; char *filename[STRSIZ]; #define DLE 144 #define max_bits 13 #define init_bits 9 #define FIRST_ENT 257 #define clear 256 int codesize; int maxcode; int free_ent; int maxcodemax; int offset; int sizex; /* MACROS */ /* generic READBIT */ #define READBIT(nbits,zdest) {if(nbits<=bits_left) {zdest=(bitbuf&mask_bits[nbits]); bitbuf>>=nbits;bits_left-=nbits;} else zdest=FillBitBuffer(nbits);} /* hard-coded for 8 bits, etc. */ #define READ8B(zdest) {if(bits_left > 7) { zdest=(bitbuf & 0x00FF); bitbuf >>= 8; bits_left -= 8;} else zdest=FillBitBuffer(8);} #define READ6B(zdest) {if(bits_left > 5) { zdest=(bitbuf & 0x003F); bitbuf >>= 6; bits_left -= 6;} else zdest=FillBitBuffer(6);} #define READ4B(zdest) {if(bits_left > 3) { zdest=(bitbuf & 0x000F); bitbuf >>= 4; bits_left -= 4;} else zdest=FillBitBuffer(4);} #define READ2B(zdest) {if(bits_left > 1) { zdest=(bitbuf & 0x0003); bitbuf >>= 2; bits_left -= 2;} else zdest=FillBitBuffer(2);} #define READ1B(zdest) {if(bits_left) { zdest=(bitbuf & 1); bitbuf >>= 1; bits_left-- ;} else zdest=FillBitBuffer(1);} /* note: "0x02" hard coded in OUTBHK */ #define OUTBHK(intc) { *outptr++ = intc; long(2,outcnt,outcnt,longone); if (outcnt[2] == 0x02) FlushOutput(HALFK); } /* note: "0x04" hard coded in OUTB */ #define OUTB(intc) { *outptr++ = intc; long(2,outcnt,outcnt,longone); if (outcnt[2] == 0x04) FlushOutput(ONEK); } /* note: "0x10" hard coded in OUTB4 */ #define OUTB4(intc) { *outptr++ = intc; long(2,outcnt,outcnt,longone); if (outcnt[2] == 0x10) FlushOutput(FOURK); } #define OUTB8(intc) { *outptr++ = intc; long(2,outcnt,outcnt,longone); if (++scrcnt == 2048) FlushOutput(EIGHTK); } int mask_bits[16]; /* External data for exploding */ char lit_tr_present; char eightK_dictionary; int minimum_match_length; int dict_bits;