|
|
1.1 ! root 1: /* gzip.h -- common declarations for all gzip modules ! 2: * Copyright (C) 1992-1993 Jean-loup Gailly. ! 3: * This is free software; you can redistribute it and/or modify it under the ! 4: * terms of the GNU General Public License, see the file COPYING. ! 5: */ ! 6: ! 7: #if defined(__STDC__) || defined(PROTO) ! 8: # define OF(args) args ! 9: #else ! 10: # define OF(args) () ! 11: #endif ! 12: ! 13: #ifdef __STDC__ ! 14: typedef void *voidp; ! 15: #else ! 16: typedef char *voidp; ! 17: #endif ! 18: ! 19: /* I don't like nested includes, but the string functions are used too often */ ! 20: #if !defined(NO_STRING_H) || defined(STDC_HEADERS) ! 21: # include <string.h> ! 22: # define memzero(s, n) memset ((s), 0, (n)) ! 23: #else ! 24: # include <strings.h> ! 25: # define strchr index ! 26: # define strrchr rindex ! 27: # define memcpy(d, s, n) bcopy((s), (d), (n)) ! 28: # define memcmp(s1, s2, n) bcmp((s1), (s2), (n)) ! 29: # define memzero(s, n) bzero((s), (n)) ! 30: #endif ! 31: ! 32: #if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) ! 33: # include <memory.h> ! 34: #endif ! 35: ! 36: #ifndef RETSIGTYPE ! 37: # define RETSIGTYPE void ! 38: #endif ! 39: ! 40: #define local static ! 41: ! 42: typedef unsigned char uch; ! 43: typedef unsigned short ush; ! 44: typedef unsigned long ulg; ! 45: ! 46: /* Return codes from gzip */ ! 47: #define OK 0 ! 48: #define ERROR 1 ! 49: #define WARNING 2 ! 50: ! 51: /* Compression methods (see algorithm.doc) */ ! 52: #define STORED 0 ! 53: #define COMPRESSED 1 ! 54: #define PACKED 2 ! 55: /* methods 3 to 7 reserved */ ! 56: #define DEFLATED 8 ! 57: extern int method; /* compression method */ ! 58: ! 59: /* To save memory for 16 bit systems, some arrays are overlayed between ! 60: * the various modules: ! 61: * deflate: prev+head window d_buf l_buf outbuf ! 62: * unlzw: tab_prefix tab_suffix stack inbuf outbuf ! 63: * inflate: window inbuf ! 64: * unpack: window inbuf ! 65: * For compression, input is done in window[]. For decompression, output ! 66: * is done in window except for unlzw. ! 67: */ ! 68: ! 69: #ifndef INBUFSIZ ! 70: # define INBUFSIZ 0x8000 /* input buffer size */ ! 71: #endif ! 72: #define INBUF_EXTRA 64 /* required by unlzw() */ ! 73: ! 74: #ifndef OUTBUFSIZ ! 75: # define OUTBUFSIZ 16384 /* output buffer size */ ! 76: #endif ! 77: #define OUTBUF_EXTRA 2048 /* required by unlzw() */ ! 78: ! 79: #define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */ ! 80: ! 81: #ifdef DYN_ALLOC ! 82: # define EXTERN(type, array) extern type * near array ! 83: # define DECLARE(type, array, size) type * near array ! 84: # define ALLOC(type, array, size) { \ ! 85: array = (type*)fcalloc((unsigned)(((size)+1L)/2), 2*sizeof(type)); \ ! 86: if (array == NULL) error("insufficient memory"); \ ! 87: } ! 88: # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;} ! 89: #else ! 90: # define EXTERN(type, array) extern type array[] ! 91: # define DECLARE(type, array, size) type array[size] ! 92: # define ALLOC(type, array, size) ! 93: # define FREE(array) ! 94: #endif ! 95: ! 96: EXTERN(uch, inbuf); /* input buffer */ ! 97: EXTERN(uch, outbuf); /* output buffer */ ! 98: EXTERN(ush, d_buf); /* buffer for distances, see trees.c */ ! 99: EXTERN(uch, window); /* Sliding window and suffix table (unlzw) */ ! 100: #define tab_suffix window ! 101: #ifndef MAXSEG_64K ! 102: # define tab_prefix prev /* hash link (see deflate.c) */ ! 103: # define head (prev+WSIZE) /* hash head (see deflate.c) */ ! 104: EXTERN(ush, tab_prefix); /* prefix code (see unlzw.c) */ ! 105: #else ! 106: # define tab_prefix0 prev ! 107: # define head tab_prefix1 ! 108: EXTERN(ush, tab_prefix0); /* prefix for even codes */ ! 109: EXTERN(ush, tab_prefix1); /* prefix for odd codes */ ! 110: #endif ! 111: ! 112: extern unsigned insize; /* valid bytes in inbuf */ ! 113: extern unsigned inptr; /* index of next byte to be processed in inbuf */ ! 114: extern unsigned outcnt; /* bytes in output buffer */ ! 115: ! 116: extern long bytes_in; /* number of input bytes */ ! 117: extern long bytes_out; /* number of output bytes */ ! 118: extern long overhead; /* number of bytes in gzip header */ ! 119: ! 120: #define isize bytes_in ! 121: /* for compatibility with old zip sources (to be cleaned) */ ! 122: ! 123: extern int ifd; /* input file descriptor */ ! 124: extern int ofd; /* output file descriptor */ ! 125: extern char ifname[]; /* input filename or "stdin" */ ! 126: extern char ofname[]; /* output filename or "stdout" */ ! 127: ! 128: extern ulg time_stamp; /* original time stamp (modification time) */ ! 129: extern long ifile_size; /* input file size, -1 for devices (debug only) */ ! 130: ! 131: typedef int file_t; /* Do not use stdio */ ! 132: #define NO_FILE (-1) /* in memory compression */ ! 133: ! 134: ! 135: #define GZIP_MAGIC "\037\213" /* Magic header for gzip files, 1F 8B */ ! 136: #define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */ ! 137: #define PKZIP_MAGIC "PK\003\004" /* Magic header for pkzip files */ ! 138: #define PACK_MAGIC "\037\036" /* Magic header for packed files */ ! 139: ! 140: /* gzip flag byte */ ! 141: #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ ! 142: #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ ! 143: #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ ! 144: #define ORIG_NAME 0x08 /* bit 3 set: original file name present */ ! 145: #define COMMENT 0x10 /* bit 4 set: file comment present */ ! 146: #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ ! 147: #define RESERVED 0xC0 /* bit 6,7: reserved */ ! 148: ! 149: /* internal file attribute */ ! 150: #define UNKNOWN (-1) ! 151: #define BINARY 0 ! 152: #define ASCII 1 ! 153: ! 154: #ifndef WSIZE ! 155: # define WSIZE 0x8000 /* window size--must be a power of two, and */ ! 156: #endif /* at least 32K for zip's deflate method */ ! 157: ! 158: #define MIN_MATCH 3 ! 159: #define MAX_MATCH 258 ! 160: /* The minimum and maximum match lengths */ ! 161: ! 162: #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) ! 163: /* Minimum amount of lookahead, except at the end of the input file. ! 164: * See deflate.c for comments about the MIN_MATCH+1. ! 165: */ ! 166: ! 167: #define MAX_DIST (WSIZE-MIN_LOOKAHEAD) ! 168: /* In order to simplify the code, particularly on 16 bit machines, match ! 169: * distances are limited to MAX_DIST instead of WSIZE. ! 170: */ ! 171: ! 172: extern int decrypt; /* flag to turn on decryption */ ! 173: extern int exit_code; /* program exit code */ ! 174: extern int verbose; /* be verbose (-v) */ ! 175: extern int quiet; /* be quiet (-q) */ ! 176: extern int level; /* compression level */ ! 177: extern int test; /* check .z file integrity */ ! 178: extern int to_stdout; /* output to stdout (-c) */ ! 179: extern int save_orig_name; /* set if original name must be saved */ ! 180: extern int text_mode; /* set if original file is a text file (in variable ! 181: record format for VMS). Must stay 0 if unknown. */ ! 182: ! 183: #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) ! 184: ! 185: /* put_byte is used for the compressed output, put_char for the ! 186: * uncompressed output. However unlzw() uses window for its ! 187: * suffix table instead of its output buffer, so it does not use put_char. ! 188: * (to be cleaned up). ! 189: */ ! 190: #define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\ ! 191: flush_outbuf();} ! 192: #define put_char(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\ ! 193: flush_window();} ! 194: ! 195: /* Output a 16 bit value, lsb first */ ! 196: #define put_short(w) \ ! 197: { if (outcnt < OUTBUFSIZ-2) { \ ! 198: outbuf[outcnt++] = (uch) ((w) & 0xff); \ ! 199: outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \ ! 200: } else { \ ! 201: put_byte((uch)((w) & 0xff)); \ ! 202: put_byte((uch)((ush)(w) >> 8)); \ ! 203: } \ ! 204: } ! 205: ! 206: /* Output a 32 bit value to the bit stream, lsb first */ ! 207: #define put_long(n) { \ ! 208: put_short((n) & 0xffff); \ ! 209: put_short(((ulg)(n)) >> 16); \ ! 210: } ! 211: ! 212: #define seekable() 0 /* force sequential output */ ! 213: #define translate_eol 0 /* no option -a yet */ ! 214: ! 215: #define tolow(c) (isupper(c) ? (c)-'A'+'a' : (c)) /* force to lower case */ ! 216: ! 217: /* Macros for getting two-byte and four-byte header values */ ! 218: #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8)) ! 219: #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16)) ! 220: ! 221: /* Diagnostic functions */ ! 222: #ifdef DEBUG ! 223: # define Assert(cond,msg) {if(!(cond)) error(msg);} ! 224: # define Trace(x) fprintf x ! 225: # define Tracev(x) {if (verbose) fprintf x ;} ! 226: # define Tracevv(x) {if (verbose>1) fprintf x ;} ! 227: # define Tracec(c,x) {if (verbose && (c)) fprintf x ;} ! 228: # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;} ! 229: #else ! 230: # define Assert(cond,msg) ! 231: # define Trace(x) ! 232: # define Tracev(x) ! 233: # define Tracevv(x) ! 234: # define Tracec(c,x) ! 235: # define Tracecv(c,x) ! 236: #endif ! 237: ! 238: #define WARN(msg) {if (!quiet) fprintf msg ; \ ! 239: if (exit_code == OK) exit_code = WARNING;} ! 240: ! 241: /* in zip.c: */ ! 242: extern void zip OF((int in, int out)); ! 243: extern int file_read OF((char *buf, unsigned size)); ! 244: ! 245: /* in unzip.c */ ! 246: extern void unzip OF((int in, int out)); ! 247: extern int check_zipfile OF((int in)); ! 248: ! 249: /* in unpack.c */ ! 250: extern void unpack OF((int in, int out)); ! 251: ! 252: /* in gzip.c */ ! 253: RETSIGTYPE abort_gzip OF((void)); ! 254: ! 255: /* in deflate.c */ ! 256: void lm_init OF((int pack_level, ush *flags)); ! 257: ulg deflate OF((void)); ! 258: ! 259: /* in trees.c */ ! 260: void ct_init OF((ush *attr, int *method)); ! 261: int ct_tally OF((int dist, int lc)); ! 262: ulg flush_block OF((char *buf, ulg stored_len, int eof)); ! 263: ! 264: /* in bits.c */ ! 265: void bi_init OF((file_t zipfile)); ! 266: void send_bits OF((int value, int length)); ! 267: unsigned bi_reverse OF((unsigned value, int length)); ! 268: void bi_windup OF((void)); ! 269: void copy_block OF((char *buf, unsigned len, int header)); ! 270: extern int (*read_buf) OF((char *buf, unsigned size)); ! 271: ! 272: /* in util.c: */ ! 273: extern ulg updcrc OF((uch *s, unsigned n)); ! 274: extern void clear_bufs OF((void)); ! 275: extern int fill_inbuf OF((void)); ! 276: extern void flush_outbuf OF((void)); ! 277: extern void flush_window OF((void)); ! 278: extern char *strlwr OF((char *s)); ! 279: extern char *basename OF((char *fname)); ! 280: extern char *add_envopt OF((int *argcp, char ***argvp, char *env)); ! 281: extern void error OF((char *m)); ! 282: extern void warn OF((char *a, char *b)); ! 283: extern void read_error OF((void)); ! 284: extern void write_error OF((void)); ! 285: extern void display_ratio OF((long num, long den)); ! 286: extern voidp xmalloc OF((unsigned int size)); ! 287: ! 288: /* in inflate.c */ ! 289: extern int inflate OF((void));
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.