root/zBoot/gzip.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   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(HAVE_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(HAVE_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 extern int exit_code;   /* program exit code */
 132 
 133 typedef int file_t;     /* Do not use stdio */
 134 #define NO_FILE  (-1)   /* in memory compression */
 135 
 136 
 137 #define GZIP_MAGIC     "\037\213" /* Magic header for gzip files, 1F 8B */
 138 #define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
 139 #define PKZIP_MAGIC  "PK\003\004" /* Magic header for pkzip files */
 140 #define PACK_MAGIC     "\037\036" /* Magic header for packed files */
 141 
 142 /* gzip flag byte */
 143 #define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
 144 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
 145 #define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
 146 #define ORIG_NAME    0x08 /* bit 3 set: original file name present */
 147 #define COMMENT      0x10 /* bit 4 set: file comment present */
 148 #define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
 149 #define RESERVED     0xC0 /* bit 6,7:   reserved */
 150 
 151 /* internal file attribute */
 152 #define UNKNOWN (-1)
 153 #define BINARY  0
 154 #define ASCII   1
 155 
 156 #ifndef WSIZE
 157 #  define WSIZE 0x8000     /* window size--must be a power of two, and */
 158 #endif                     /*  at least 32K for zip's deflate method */
 159 
 160 #define MIN_MATCH  3
 161 #define MAX_MATCH  258
 162 /* The minimum and maximum match lengths */
 163 
 164 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
 165 /* Minimum amount of lookahead, except at the end of the input file.
 166  * See deflate.c for comments about the MIN_MATCH+1.
 167  */
 168 
 169 #define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
 170 /* In order to simplify the code, particularly on 16 bit machines, match
 171  * distances are limited to MAX_DIST instead of WSIZE.
 172  */
 173 
 174 extern int decrypt;        /* flag to turn on decryption */
 175 extern int save_orig_name; /* set if original name must be saved */
 176 extern int verbose;        /* be verbose (-v) */
 177 extern int level;          /* compression level */
 178 extern int test;           /* check .z file integrity */
 179 extern int to_stdout;      /* output to stdout (-c) */
 180 
 181 #define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf())
 182 
 183 /* put_byte is used for the compressed output, put_char for the
 184  * uncompressed output. However unlzw() uses window for its
 185  * suffix table instead of its output buffer, so it does not use put_char.
 186  * (to be cleaned up).
 187  */
 188 #define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
 189    flush_outbuf();}
 190 #define put_char(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
 191    flush_window();}
 192 
 193 /* Output a 16 bit value, lsb first */
 194 #define put_short(w) \
 195 { if (outcnt < OUTBUFSIZ-2) { \
 196     outbuf[outcnt++] = (uch) ((w) & 0xff); \
 197     outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
 198   } else { \
 199     put_byte((uch)((w) & 0xff)); \
 200     put_byte((uch)((ush)(w) >> 8)); \
 201   } \
 202 }
 203 
 204 /* Output a 32 bit value to the bit stream, lsb first */
 205 #define put_long(n) { \
 206     put_short((n) & 0xffff); \
 207     put_short(((ulg)(n)) >> 16); \
 208 }
 209 
 210 #define seekable()    0  /* force sequential output */
 211 #define translate_eol 0  /* no option -a yet */
 212 
 213 #define tolow(c)  (isupper(c) ? (c)-'A'+'a' : (c))    /* force to lower case */
 214 
 215 /* Macros for getting two-byte and four-byte header values */
 216 #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
 217 #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
 218 
 219 /* Diagnostic functions */
 220 #ifdef DEBUG
 221 #  define Assert(cond,msg) {if(!(cond)) error(msg);}
 222 #  define Trace(x) fprintf x
 223 #  define Tracev(x) {if (verbose) fprintf x ;}
 224 #  define Tracevv(x) {if (verbose>1) fprintf x ;}
 225 #  define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
 226 #  define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
 227 #else
 228 #  define Assert(cond,msg)
 229 #  define Trace(x)
 230 #  define Tracev(x)
 231 #  define Tracevv(x)
 232 #  define Tracec(c,x)
 233 #  define Tracecv(c,x)
 234 #endif
 235 
 236         /* in zip.c: */
 237 extern void zip    OF((int in, int out));
 238 extern int file_read  OF((char *buf,  unsigned size));
 239 
 240         /* in unzip.c */
 241 extern void unzip        OF((int in, int out));
 242 extern int check_zipfile OF((int in));
 243 
 244         /* in unpack.c */
 245 extern void unpack        OF((int in, int out));
 246 
 247         /* in gzip.c */
 248 RETSIGTYPE abort_gzip   OF((void));
 249 
 250         /* in deflate.c */
 251 void lm_init OF((int pack_level, ush *flags));
 252 ulg  deflate OF((void));
 253 
 254         /* in trees.c */
 255 void ct_init     OF((ush *attr, int *method));
 256 int  ct_tally    OF((int dist, int lc));
 257 ulg  flush_block OF((char *buf, ulg stored_len, int eof));
 258 
 259         /* in bits.c */
 260 void     bi_init    OF((file_t zipfile));
 261 void     send_bits  OF((int value, int length));
 262 unsigned bi_reverse OF((unsigned value, int length));
 263 void     bi_windup  OF((void));
 264 void     copy_block OF((char *buf, unsigned len, int header));
 265 extern   int (*read_buf) OF((char *buf, unsigned size));
 266 
 267         /* in util.c: */
 268 extern ulg  updcrc        OF((uch *s, unsigned n));
 269 extern void clear_bufs    OF((void));
 270 extern int  fill_inbuf    OF((void));
 271 extern void flush_outbuf  OF((void));
 272 extern void flush_window  OF((void));
 273 extern char *strlwr       OF((char *s));
 274 extern char *basename     OF((char *fname));
 275 extern char *add_envopt   OF((int *argcp, char ***argvp, char *env));
 276 extern void error         OF((char *m));
 277 extern void warn          OF((char *a, char *b));
 278 extern void read_error    OF((void));
 279 extern void write_error   OF((void));
 280 extern void display_ratio OF((long num, long den));
 281 extern voidp xmalloc      OF((unsigned int size));
 282 
 283         /* in inflate.c */
 284 extern int inflate OF((void));

/* [previous][next][first][last][top][bottom][index][help] */