home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 June / Vpr9806a.iso / OLS / Windows / TAR32031 / tar32031.exe / SRC / SRC / GZIP.H < prev    next >
C/C++ Source or Header  |  1998-01-15  |  12KB  |  343 lines

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