1
2
3
4
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
20 #if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
21 # include <string.h>
22 # define memzero(s, n) memset ((s), 0, (n))
23 #else
24 # include <strings.h>
25 # define strchr index
26 # define strrchr rindex
27 # define memcpy(d, s, n) bcopy((s), (d), (n))
28 # define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
29 # define memzero(s, n) bzero((s), (n))
30 #endif
31
32 #if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
33 # include <memory.h>
34 #endif
35
36 #ifndef RETSIGTYPE
37 # define RETSIGTYPE void
38 #endif
39
40 #define local static
41
42 typedef unsigned char uch;
43 typedef unsigned short ush;
44 typedef unsigned long ulg;
45
46
47 #define OK 0
48 #define ERROR 1
49 #define WARNING 2
50
51
52 #define STORED 0
53 #define COMPRESSED 1
54 #define PACKED 2
55
56 #define DEFLATED 8
57 extern int method;
58
59
60
61
62
63
64
65
66
67
68
69 #ifndef INBUFSIZ
70 # define INBUFSIZ 0x8000
71 #endif
72 #define INBUF_EXTRA 64
73
74 #ifndef OUTBUFSIZ
75 # define OUTBUFSIZ 16384
76 #endif
77 #define OUTBUF_EXTRA 2048
78
79 #define DIST_BUFSIZE 0x8000
80
81 #ifdef DYN_ALLOC
82 # define EXTERN(type, array) extern type * near array
83 # define DECLARE(type, array, size) type * near array
84 # define ALLOC(type, array, size) { \
85 array = (type*)fcalloc((unsigned)(((size)+1L)/2), 2*sizeof(type)); \
86 if (array == NULL) error("insufficient memory"); \
87 }
88 # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
89 #else
90 # define EXTERN(type, array) extern type array[]
91 # define DECLARE(type, array, size) type array[size]
92 # define ALLOC(type, array, size)
93 # define FREE(array)
94 #endif
95
96 EXTERN(uch, inbuf);
97 EXTERN(uch, outbuf);
98 EXTERN(ush, d_buf);
99 EXTERN(uch, window);
100 #define tab_suffix window
101 #ifndef MAXSEG_64K
102 # define tab_prefix prev
103 # define head (prev+WSIZE)
104 EXTERN(ush, tab_prefix);
105 #else
106 # define tab_prefix0 prev
107 # define head tab_prefix1
108 EXTERN(ush, tab_prefix0);
109 EXTERN(ush, tab_prefix1);
110 #endif
111
112 extern unsigned insize;
113 extern unsigned inptr;
114 extern unsigned outcnt;
115
116 extern long bytes_in;
117 extern long bytes_out;
118 extern long overhead;
119
120 #define isize bytes_in
121
122
123 extern int ifd;
124 extern int ofd;
125 extern char ifname[];
126 extern char ofname[];
127
128 extern ulg time_stamp;
129 extern long ifile_size;
130
131 extern int exit_code;
132
133 typedef int file_t;
134 #define NO_FILE (-1)
135
136
137 #define GZIP_MAGIC "\037\213"
138 #define OLD_GZIP_MAGIC "\037\236"
139 #define PKZIP_MAGIC "PK\003\004"
140 #define PACK_MAGIC "\037\036"
141
142
143 #define ASCII_FLAG 0x01
144 #define CONTINUATION 0x02
145 #define EXTRA_FIELD 0x04
146 #define ORIG_NAME 0x08
147 #define COMMENT 0x10
148 #define ENCRYPTED 0x20
149 #define RESERVED 0xC0
150
151
152 #define UNKNOWN (-1)
153 #define BINARY 0
154 #define ASCII 1
155
156 #ifndef WSIZE
157 # define WSIZE 0x8000
158 #endif
159
160 #define MIN_MATCH 3
161 #define MAX_MATCH 258
162
163
164 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
165
166
167
168
169 #define MAX_DIST (WSIZE-MIN_LOOKAHEAD)
170
171
172
173
174 extern int decrypt;
175 extern int save_orig_name;
176 extern int verbose;
177 extern int level;
178 extern int test;
179 extern int to_stdout;
180
181 #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf())
182
183
184
185
186
187
188 #define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\
189 flush_outbuf();}
190 #define put_char(c) {window[outcnt++]=(uch)(c); if (outcnt==WSIZE)\
191 flush_window();}
192
193
194 #define put_short(w) \
195 { if (outcnt < OUTBUFSIZ-2) { \
196 outbuf[outcnt++] = (uch) ((w) & 0xff); \
197 outbuf[outcnt++] = (uch) ((ush)(w) >> 8); \
198 } else { \
199 put_byte((uch)((w) & 0xff)); \
200 put_byte((uch)((ush)(w) >> 8)); \
201 } \
202 }
203
204
205 #define put_long(n) { \
206 put_short((n) & 0xffff); \
207 put_short(((ulg)(n)) >> 16); \
208 }
209
210 #define seekable() 0
211 #define translate_eol 0
212
213 #define tolow(c) (isupper(c) ? (c)-'A'+'a' : (c))
214
215
216 #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
217 #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
218
219
220 #ifdef DEBUG
221 # define Assert(cond,msg) {if(!(cond)) error(msg);}
222 # define Trace(x) fprintf x
223 # define Tracev(x) {if (verbose) fprintf x ;}
224 # define Tracevv(x) {if (verbose>1) fprintf x ;}
225 # define Tracec(c,x) {if (verbose && (c)) fprintf x ;}
226 # define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;}
227 #else
228 # define Assert(cond,msg)
229 # define Trace(x)
230 # define Tracev(x)
231 # define Tracevv(x)
232 # define Tracec(c,x)
233 # define Tracecv(c,x)
234 #endif
235
236
237 extern void zip OF((int in, int out));
238 extern int file_read OF((char *buf, unsigned size));
239
240
241 extern void unzip OF((int in, int out));
242 extern int check_zipfile OF((int in));
243
244
245 extern void unpack OF((int in, int out));
246
247
248 RETSIGTYPE abort_gzip OF((void));
249
250
251 void lm_init OF((int pack_level, ush *flags));
252 ulg deflate OF((void));
253
254
255 void ct_init OF((ush *attr, int *method));
256 int ct_tally OF((int dist, int lc));
257 ulg flush_block OF((char *buf, ulg stored_len, int eof));
258
259
260 void bi_init OF((file_t zipfile));
261 void send_bits OF((int value, int length));
262 unsigned bi_reverse OF((unsigned value, int length));
263 void bi_windup OF((void));
264 void copy_block OF((char *buf, unsigned len, int header));
265 extern int (*read_buf) OF((char *buf, unsigned size));
266
267
268 extern ulg updcrc OF((uch *s, unsigned n));
269 extern void clear_bufs OF((void));
270 extern int fill_inbuf OF((void));
271 extern void flush_outbuf OF((void));
272 extern void flush_window OF((void));
273 extern char *strlwr OF((char *s));
274 extern char *basename OF((char *fname));
275 extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
276 extern void error OF((char *m));
277 extern void warn OF((char *a, char *b));
278 extern void read_error OF((void));
279 extern void write_error OF((void));
280 extern void display_ratio OF((long num, long den));
281 extern voidp xmalloc OF((unsigned int size));
282
283
284 extern int inflate OF((void));