home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / linux / tools / amiga / gzip-1.1.2.lha / gzip-1.1.2 / gzip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-01  |  9.9 KB  |  303 lines

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