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