home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / utils / djtar / zread.h < prev   
Encoding:
C/C++ Source or Header  |  1995-11-16  |  6.9 KB  |  205 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. /* zread.h -- common declarations for djtarx with decompression support
  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. #ifndef __zread_h_
  8. #define __zread_h_
  9.  
  10. #include <stdio.h>
  11. #include <stddef.h>
  12. #include <string.h>
  13. #define memzero(s, n)   memset ((void *)(s), 0, (n))
  14.  
  15. #define local static
  16.  
  17. typedef unsigned char  uch;
  18. typedef unsigned short ush;
  19. typedef unsigned long  ulg;
  20.  
  21. /* Return codes from djtarx */
  22. #define OK      0
  23. #define ERROR   1
  24. #define WARNING 2
  25.  
  26. /* Compression methods */
  27. #define STORED      0
  28. #define COMPRESSED  1
  29. #define PACKED      2
  30. #define LZHED       3
  31. /* methods 4 to 7 reserved */
  32. #define DEFLATED    8
  33. #define MAX_METHODS 9
  34. extern int method;        /* compression method */
  35.  
  36. extern FILE *log_out;     /* the stream to output messages */
  37.  
  38. /* To save memory for 16 bit systems, some arrays are overlaid between
  39.  * the various modules:
  40.  * deflate:  prev+head   window      d_buf  l_buf  outbuf
  41.  * unlzw:    tab_prefix  tab_suffix  stack  inbuf  outbuf
  42.  * inflate:              window             inbuf
  43.  * unpack:               window             inbuf  prefix_len
  44.  * unlzh:    left+right  window      c_table inbuf c_len
  45.  * For compression, input is done in window[]. For decompression, output
  46.  * is done in window except for unlzw.
  47.  */
  48.  
  49. #ifndef    INBUFSIZ
  50. #define INBUFSIZ  0x8000     /* input buffer size */
  51. #endif
  52. #define INBUF_EXTRA  64      /* required by unlzw() */
  53.  
  54. #ifndef    OUTBUFSIZ
  55. #define OUTBUFSIZ  16384     /* output buffer size */
  56. #endif
  57. #define OUTBUF_EXTRA 2048    /* required by unlzw() */
  58.  
  59. #ifndef DIST_BUFSIZE
  60. #define DIST_BUFSIZE 0x8000  /* buffer for distances, see trees.c */
  61. #endif
  62.  
  63. extern uch inbuf[];
  64. extern uch outbuf[];         /* output buffer */
  65. extern ush d_buf[];          /* buffer for distances, see trees.c */
  66. extern uch window[];         /* Sliding window and suffix table (unlzw) */
  67. #define tab_suffix window
  68. #define tab_prefix prev      /* hash link (see deflate.c) */
  69. #define head (prev+WSIZE)    /* hash head (see deflate.c) */
  70. extern ush tab_prefix[];     /* prefix code (see unlzw.c) */
  71.  
  72. extern unsigned insize;      /* valid bytes in inbuf */
  73. extern unsigned inptr;       /* index of next byte to be processed in inbuf */
  74. extern unsigned outcnt;      /* bytes in output buffer */
  75. extern long bytes_out;       /* number of bytes after decompression */
  76. extern long header_bytes;    /* number of bytes in gzip header */
  77. extern int part_nb;
  78.  
  79. extern void *ifd;           /* input file/diskette descriptor */
  80. extern char *ifname;        /* input file name or "-" */
  81. extern char *progname;      /* program name */
  82. extern int  pkzip;          /* set for a pkzip file */
  83.  
  84. #define    PACK_MAGIC     "\037\036" /* Magic header for packed files */
  85. #define    GZIP_MAGIC     "\037\213" /* Magic header for gzip files, 1F 8B */
  86. #define    OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
  87. #define    LZH_MAGIC      "\037\240" /* Magic header for SCO LZH Compress files*/
  88. #define PKZIP_MAGIC    "\120\113\003\004" /* Magic header for pkzip files */
  89.  
  90. /* gzip flag byte */
  91. #define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
  92. #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
  93. #define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
  94. #define ORIG_NAME    0x08 /* bit 3 set: original file name present */
  95. #define COMMENT      0x10 /* bit 4 set: file comment present */
  96. #define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
  97. #define RESERVED     0xC0 /* bit 6,7:   reserved */
  98.  
  99. /* internal file attribute */
  100. #define UNKNOWN 0xffff
  101. #define BINARY  0
  102. #define ASCII   1
  103.  
  104. #ifndef WSIZE
  105. #  define WSIZE 0x8000     /* window size--must be a power of two, and */
  106. #endif                     /*  at least 32K for zip's deflate method */
  107.  
  108. #define MIN_MATCH  3
  109. #define MAX_MATCH  258
  110. /* The minimum and maximum match lengths */
  111.  
  112. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  113. /* Minimum amount of lookahead, except at the end of the input file.
  114.  * See deflate.c for comments about the MIN_MATCH+1.
  115.  */
  116.  
  117. #define MAX_DIST  (WSIZE-MIN_LOOKAHEAD)
  118. /* In order to simplify the code, particularly on 16 bit machines, match
  119.  * distances are limited to MAX_DIST instead of WSIZE.
  120.  */
  121.  
  122. extern int v_switch;        /* be verbose (-v) */
  123. extern int test;
  124. extern int exit_code;      /* program exit code */
  125. extern int z_switch;
  126.  
  127. #define get_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
  128. #define try_byte()  (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
  129.  
  130. #define put_ubyte(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
  131.    flush_window();}
  132.  
  133. /* Macros for getting two-byte and four-byte header values */
  134. #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
  135. #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
  136.  
  137. /* Diagnostic functions */
  138. #ifdef DEBUG
  139. #  define Assert(cond,msg) {if(!(cond)) error(msg);}
  140. #  define Trace(x) fprintf x
  141. #  define Tracev(x) {if (v_switch) fprintf x ;}
  142. #  define Tracevv(x) {if (v_switch) fprintf x ;}
  143. #  define Tracec(c,x) {if (v_switch && (c)) fprintf x ;}
  144. #  define Tracecv(c,x) {if (v_switch && (c)) fprintf x ;}
  145. #else
  146. #  define Assert(cond,msg)
  147. #  define Trace(x)
  148. #  define Tracev(x)
  149. #  define Tracevv(x)
  150. #  define Tracec(c,x)
  151. #  define Tracecv(c,x)
  152. #endif
  153.  
  154. #define WARN(msg) {if (v_switch) fprintf msg ; \
  155.            if (exit_code == OK) exit_code = WARNING;}
  156.  
  157. int (*decompressor)(void *);
  158.  
  159.     /* in djtarx.c */
  160. extern int tarread       (char *, long);
  161.  
  162.     /* in zmethod.c */
  163. extern int get_method    (void *);
  164.  
  165.     /* in unzip.c */
  166. extern int unzip         (void *);
  167. extern int check_zipfile (void);
  168.  
  169.     /* in unpack.c */
  170. extern int unpack        (void *);
  171.  
  172.     /* in unlzh.c */
  173. extern int unlzh         (void *);
  174.  
  175.         /* in trees.c */
  176. void ct_init             (ush *_attr, int *_method);
  177. int  ct_tally            (int _dist, int _lc);
  178. ulg  flush_block         (char *_buf, ulg _stored_len, int _eof);
  179.  
  180.         /* in bits.c */
  181. void     bi_init         (void);
  182. void     send_bits       (int value, int length);
  183. unsigned bi_reverse      (unsigned value, int length);
  184. void     bi_windup       (void);
  185. void     copy_block      (char *buf, unsigned len, int header);
  186. extern   int (*read_buf) (char *buf, unsigned size);
  187.  
  188.     /* in util.c: */
  189. extern int  copy         (void *);
  190. extern ulg  updcrc       (uch *s, unsigned n);
  191. extern void clear_bufs   (void);
  192. extern int  fill_inbuf   (int eof_ok);
  193. extern void flush_outbuf (void);
  194. extern void flush_window (void);
  195. extern char *basename    (char *fname);
  196. extern void error        (const char *m);
  197. extern void warn         (char *a, char *b);
  198. extern void read_error   (void);
  199. extern void *xmalloc     (unsigned int size);
  200.  
  201.     /* in inflate.c */
  202. extern int inflate       (void);
  203.  
  204. #endif  /* __zread_h_ */
  205.