My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
compress.h
1 /* compress.h -- definitions for the decompression routines used in CFITSIO */
2 
3 /* Blatantly copied and modified from the original gzip-1.2.4 source code. */
4 
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <ctype.h>
9 
10 /* 'near' is only relevant for 16-bit PC with small memory model */
11 # define near
12 
13 #if defined(VAXC) || defined(VMS)
14 # define RECORD_IO 1
15 #else
16 # define RECORD_IO 0
17 #endif
18 
19 #define get_char() get_byte()
20 
21 /* gzip.h -- common declarations for all gzip modules */
22 
23 #define OF(args) args
24 typedef void *voidp;
25 
26 #define memzero(s, n) memset ((voidp)(s), 0, (n))
27 
28 typedef unsigned char uch;
29 typedef unsigned short ush;
30 typedef unsigned long ulg;
31 
32 /* Return codes from gzip */
33 #define OK 0
34 #define ERROR 1
35 #define WARNING 2
36 
37 /* Compression methods (see algorithm.doc) */
38 #define STORED 0
39 #define COMPRESSED 1
40 #define PACKED 2
41 #define LZHED 3
42 /* methods 4 to 7 reserved */
43 #define DEFLATED 8
44 #define MAX_METHODS 9
45 
46 #define INBUFSIZ 0x8000 /* input buffer size */
47 #define INBUF_EXTRA 64 /* required by unlzw() */
48 #define OUTBUFSIZ 16384 /* output buffer size */
49 #define OUTBUF_EXTRA 2048 /* required by unlzw() */
50 #define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */
51 #define WSIZE 0x8000 /* window size--must be a power of two, and */
52 
53 #define DECLARE(type, array, size) type array[size]
54 
55 #define tab_suffix window
56 #define tab_prefix prev /* hash link (see deflate.c) */
57 #define head (prev+WSIZE) /* hash head (see deflate.c) */
58 
59 #define PACK_MAGIC "\037\036" /* Magic header for packed files */
60 #define GZIP_MAGIC "\037\213" /* Magic header for gzip files, 1F 8B */
61 #define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */
62 #define LZH_MAGIC "\037\240" /* Magic header for SCO LZH Compress files*/
63 #define LZW_MAGIC "\037\235" /* Magic header for lzw files, 1F 9D */
64 #define PKZIP_MAGIC "\120\113\003\004" /* Magic header for pkzip files */
65 
66 /* gzip flag byte */
67 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
68 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
69 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
70 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
71 #define COMMENT 0x10 /* bit 4 set: file comment present */
72 #define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
73 #define RESERVED 0xC0 /* bit 6,7: reserved */
74 
75 #define MIN_MATCH 3
76 #define MAX_MATCH 258
77 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
78 #define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
79 #define translate_eol 0 /* no option -a yet */
80 
81 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
82 #define try_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
83 #define put_ubyte(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
84  flush_window();}
85 
86 /* Macros for getting two-byte and four-byte header values */
87 #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
88 #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
89 
90 /* Diagnostic functions */
91 # define Assert(cond,msg)
92 # define Trace(x)
93 # define Tracev(x)
94 # define Tracevv(x)
95 # define Tracec(c,x)
96 # define Tracecv(c,x)
97 
98 /* lzw.h -- define the lzw functions. */
99 
100 #ifndef BITS
101 # define BITS 16
102 #endif
103 #define INIT_BITS 9 /* Initial number of bits per code */
104 #define BIT_MASK 0x1f /* Mask for 'number of compression bits' */
105 #define BLOCK_MODE 0x80
106 #define LZW_RESERVED 0x60 /* reserved bits */
107 #define CLEAR 256 /* flush the dictionary */
108 #define FIRST (CLEAR+1) /* first free entry */
109 
110 /* prototypes */
111 
112 #define local static
113 void ffpmsg(const char *err_message);
114 
115 local int get_method OF((FILE *in));
116 
117 local ulg updcrc OF((uch *s, unsigned n));
118 local int fill_inbuf OF((int eof_ok));
119 local void flush_outbuf OF((void));
120 local void flush_window OF((void));
121 local void write_buf OF((voidp buf, unsigned cnt));
122 local void error OF((char *m));
123 local ulg flush_block OF((char *buf, ulg stored_len, int eof));
124 typedef int file_t; /* Do not use stdio */
125 #define NO_FILE (-1) /* in memory compression */
126 local int file_read OF((char *buf, unsigned size));
127 local void send_bits OF((int value, int length));
128 local unsigned bi_reverse OF((unsigned value, int length));
129 local void bi_windup OF((void));
130 local void copy_block OF((char *buf, unsigned len, int header));
131 local int (*read_buf) OF((char *buf, unsigned size));
132 local void lm_init OF((int pack_level, ush *flags));
133 local ulg deflate OF((void));
134 local void ct_init OF((ush *attr, int *method));
135 local int ct_tally OF((int dist, int lc));
136 local void bi_init OF((file_t zipfile));
137 
138 #define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
139  flush_outbuf();}
140 
141 /* Output a 16 bit value, lsb first */
142 #define put_short(w) \
143 { if (outcnt < OUTBUFSIZ-2) { \
144  outbuf[outcnt++] = (uch) ((w) & 0xff); \
145  outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
146  } else { \
147  put_byte((uch)((w) & 0xff)); \
148  put_byte((uch)((ush)(w) >> 8)); \
149  } \
150 }
151 
152 /* Output a 32 bit value to the bit stream, lsb first */
153 #define put_long(n) { \
154  put_short((n) & 0xffff); \
155  put_short(((ulg)(n)) >> 16); \
156 }
157 
158 #define seekable() 0 /* force sequential output */
159 
160 /* io.c */
161 local void fillbuf OF((int n));
162 local unsigned getbits OF((int n));
163 local void init_getbits OF((void));
164 
165 /* maketbl.c */
166 local void make_table OF((int nchar, uch bitlen[],
167  int tablebits, ush table[]));
168 
169 /* huf.c */
170 local void read_pt_len OF((int nn, int nbit, int i_special));
171 local void read_c_len OF((void));
172 local unsigned decode_c OF((void));
173 local unsigned decode_p OF((void));
174 local void huf_decode_start OF((void));
175 
176 /* decode.c */
177 local void decode_start OF((void));
178 local unsigned decode OF((unsigned count, uch buffer[]));
179 
180 local int unlzh OF((FILE *in, FILE *out));
181 local int unlzw OF((FILE *in, FILE *out));
182 
183 local void read_tree OF((void));
184 local void build_tree_unpack OF((void));
185 
186 local int unpack OF((FILE *in, FILE *out));
187 local int check_zipfile OF((FILE *in));
188 local int unzip OF((FILE *in, FILE *out));
189 
190 int (*work) OF((FILE *infile, FILE *outfile)) = unzip; /* function to call */
191 
192 /* inflate.c */
193 struct huft {
194  uch e; /* number of extra bits or operation */
195  uch b; /* number of bits in this code or subcode */
196  union {
197  ush n; /* literal, length base, or distance base */
198  struct huft *t; /* pointer to next level of table */
199  } v;
200 };
201 
202 local int huft_build OF((unsigned *, unsigned, unsigned, ush *, ush *,
203  struct huft **, int *));
204 local int huft_free OF((struct huft *));
205 local int inflate_codes OF((struct huft *, struct huft *, int, int));
206 local int inflate_stored OF((void));
207 local int inflate_fixed OF((void));
208 local int inflate_dynamic OF((void));
209 local int inflate_block OF((int *));
210 local int inflate OF((void));
211 
212 /* end of compress.h include file */
Definition: compress.h:193
Definition: tVideoCapabilitiesEml.cc:67