diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-08-22 18:41:20 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-08-22 18:41:20 +0000 |
commit | 3371630cd7e810c89081aafc9017ea1f59bae814 (patch) | |
tree | 87eca9d8c978b9ea4736e05e4c480d51097e0319 /libbb | |
parent | 6eb64b91699e8d6b4f7601c89ef8a5dcdeeb4855 (diff) | |
download | busybox-w32-3371630cd7e810c89081aafc9017ea1f59bae814.tar.gz busybox-w32-3371630cd7e810c89081aafc9017ea1f59bae814.tar.bz2 busybox-w32-3371630cd7e810c89081aafc9017ea1f59bae814.zip |
Run through indent, fix comments
git-svn-id: svn://busybox.net/trunk/busybox@5342 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/dump.c | 398 | ||||
-rw-r--r-- | libbb/unzip.c | 755 |
2 files changed, 604 insertions, 549 deletions
diff --git a/libbb/dump.c b/libbb/dump.c index 8bd683f44..1afad83fd 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
@@ -30,21 +30,21 @@ | |||
30 | 30 | ||
31 | enum _vflag vflag = FIRST; | 31 | enum _vflag vflag = FIRST; |
32 | FS *fshead; /* head of format strings */ | 32 | FS *fshead; /* head of format strings */ |
33 | extern FS *fshead; /* head of format strings */ | 33 | extern FS *fshead; /* head of format strings */ |
34 | extern int blocksize; | 34 | extern int blocksize; |
35 | static FU *endfu; | 35 | static FU *endfu; |
36 | static char **_argv; | 36 | static char **_argv; |
37 | static off_t savaddress; /* saved address/offset in stream */ | 37 | static off_t savaddress; /* saved address/offset in stream */ |
38 | static off_t eaddress; /* end address */ | 38 | static off_t eaddress; /* end address */ |
39 | static off_t address; /* address/offset in stream */ | 39 | static off_t address; /* address/offset in stream */ |
40 | off_t skip; /* bytes to skip */ | 40 | off_t skip; /* bytes to skip */ |
41 | off_t saveaddress; | 41 | off_t saveaddress; |
42 | int exitval; /* final exit value */ | 42 | int exitval; /* final exit value */ |
43 | int blocksize; /* data block size */ | 43 | int blocksize; /* data block size */ |
44 | int length = -1; /* max bytes to read */ | 44 | int length = -1; /* max bytes to read */ |
45 | 45 | ||
46 | 46 | ||
47 | int size(FS *fs) | 47 | int size(FS * fs) |
48 | { | 48 | { |
49 | register FU *fu; | 49 | register FU *fu; |
50 | register int bcnt, cursize; | 50 | register int bcnt, cursize; |
@@ -69,23 +69,33 @@ int size(FS *fs) | |||
69 | prec = atoi(fmt); | 69 | prec = atoi(fmt); |
70 | while (isdigit(*++fmt)); | 70 | while (isdigit(*++fmt)); |
71 | } | 71 | } |
72 | switch(*fmt) { | 72 | switch (*fmt) { |
73 | case 'c': | 73 | case 'c': |
74 | bcnt += 1; | 74 | bcnt += 1; |
75 | break; | 75 | break; |
76 | case 'd': case 'i': case 'o': case 'u': | 76 | case 'd': |
77 | case 'x': case 'X': | 77 | case 'i': |
78 | case 'o': | ||
79 | case 'u': | ||
80 | case 'x': | ||
81 | case 'X': | ||
78 | bcnt += 4; | 82 | bcnt += 4; |
79 | break; | 83 | break; |
80 | case 'e': case 'E': case 'f': case 'g': case 'G': | 84 | case 'e': |
85 | case 'E': | ||
86 | case 'f': | ||
87 | case 'g': | ||
88 | case 'G': | ||
81 | bcnt += 8; | 89 | bcnt += 8; |
82 | break; | 90 | break; |
83 | case 's': | 91 | case 's': |
84 | bcnt += prec; | 92 | bcnt += prec; |
85 | break; | 93 | break; |
86 | case '_': | 94 | case '_': |
87 | switch(*++fmt) { | 95 | switch (*++fmt) { |
88 | case 'c': case 'p': case 'u': | 96 | case 'c': |
97 | case 'p': | ||
98 | case 'u': | ||
89 | bcnt += 1; | 99 | bcnt += 1; |
90 | break; | 100 | break; |
91 | } | 101 | } |
@@ -93,10 +103,10 @@ int size(FS *fs) | |||
93 | } | 103 | } |
94 | cursize += bcnt * fu->reps; | 104 | cursize += bcnt * fu->reps; |
95 | } | 105 | } |
96 | return(cursize); | 106 | return (cursize); |
97 | } | 107 | } |
98 | 108 | ||
99 | void rewrite(FS *fs) | 109 | void rewrite(FS * fs) |
100 | { | 110 | { |
101 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; | 111 | enum { NOTOKAY, USEBCNT, USEPREC } sokay; |
102 | register PR *pr, **nextpr = NULL; | 112 | register PR *pr, **nextpr = NULL; |
@@ -112,7 +122,7 @@ void rewrite(FS *fs) | |||
112 | */ | 122 | */ |
113 | for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { | 123 | for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) { |
114 | /* NOSTRICT */ | 124 | /* NOSTRICT */ |
115 | pr = (PR *)xmalloc(sizeof(PR)); | 125 | pr = (PR *) xmalloc(sizeof(PR)); |
116 | if (!fu->nextpr) | 126 | if (!fu->nextpr) |
117 | fu->nextpr = pr; | 127 | fu->nextpr = pr; |
118 | else | 128 | else |
@@ -143,53 +153,64 @@ void rewrite(FS *fs) | |||
143 | sokay = USEPREC; | 153 | sokay = USEPREC; |
144 | prec = atoi(p1); | 154 | prec = atoi(p1); |
145 | while (isdigit(*++p1)); | 155 | while (isdigit(*++p1)); |
146 | } | 156 | } else |
147 | else | ||
148 | sokay = NOTOKAY; | 157 | sokay = NOTOKAY; |
149 | } | 158 | } |
150 | 159 | ||
151 | p2 = p1 + 1; /* set end pointer */ | 160 | p2 = p1 + 1; /* set end pointer */ |
152 | 161 | ||
153 | /* | 162 | /* |
154 | * figure out the byte count for each conversion; | 163 | * figure out the byte count for each conversion; |
155 | * rewrite the format as necessary, set up blank- | 164 | * rewrite the format as necessary, set up blank- |
156 | * padding for end of data. | 165 | * padding for end of data. |
157 | */ | 166 | */ |
158 | switch(*p1) { | 167 | switch (*p1) { |
159 | case 'c': | 168 | case 'c': |
160 | pr->flags = F_CHAR; | 169 | pr->flags = F_CHAR; |
161 | switch(fu->bcnt) { | 170 | switch (fu->bcnt) { |
162 | case 0: case 1: | 171 | case 0: |
172 | case 1: | ||
163 | pr->bcnt = 1; | 173 | pr->bcnt = 1; |
164 | break; | 174 | break; |
165 | default: | 175 | default: |
166 | p1[1] = '\0'; | 176 | p1[1] = '\0'; |
167 | error_msg_and_die("bad byte count for conversion character %s.", p1); | 177 | error_msg_and_die |
178 | ("bad byte count for conversion character %s.", p1); | ||
168 | } | 179 | } |
169 | break; | 180 | break; |
170 | case 'd': case 'i': | 181 | case 'd': |
182 | case 'i': | ||
171 | pr->flags = F_INT; | 183 | pr->flags = F_INT; |
172 | goto sw1; | 184 | goto sw1; |
173 | case 'l': | 185 | case 'l': |
174 | ++p2; | 186 | ++p2; |
175 | switch(p1[1]) { | 187 | switch (p1[1]) { |
176 | case 'd': case 'i': | 188 | case 'd': |
189 | case 'i': | ||
177 | ++p1; | 190 | ++p1; |
178 | pr->flags = F_INT; | 191 | pr->flags = F_INT; |
179 | goto sw1; | 192 | goto sw1; |
180 | case 'o': case 'u': case 'x': case 'X': | 193 | case 'o': |
194 | case 'u': | ||
195 | case 'x': | ||
196 | case 'X': | ||
181 | ++p1; | 197 | ++p1; |
182 | pr->flags = F_UINT; | 198 | pr->flags = F_UINT; |
183 | goto sw1; | 199 | goto sw1; |
184 | default: | 200 | default: |
185 | p1[2] = '\0'; | 201 | p1[2] = '\0'; |
186 | error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1); | 202 | error_msg_and_die |
203 | ("hexdump: bad conversion character %%%s.\n", p1); | ||
187 | } | 204 | } |
188 | /* NOTREACHED */ | 205 | /* NOTREACHED */ |
189 | case 'o': case 'u': case 'x': case 'X': | 206 | case 'o': |
207 | case 'u': | ||
208 | case 'x': | ||
209 | case 'X': | ||
190 | pr->flags = F_UINT; | 210 | pr->flags = F_UINT; |
191 | sw1: switch(fu->bcnt) { | 211 | sw1:switch (fu->bcnt) { |
192 | case 0: case 4: | 212 | case 0: |
213 | case 4: | ||
193 | pr->bcnt = 4; | 214 | pr->bcnt = 4; |
194 | break; | 215 | break; |
195 | case 1: | 216 | case 1: |
@@ -200,13 +221,19 @@ sw1: switch(fu->bcnt) { | |||
200 | break; | 221 | break; |
201 | default: | 222 | default: |
202 | p1[1] = '\0'; | 223 | p1[1] = '\0'; |
203 | error_msg_and_die("bad byte count for conversion character %s.", p1); | 224 | error_msg_and_die |
225 | ("bad byte count for conversion character %s.", p1); | ||
204 | } | 226 | } |
205 | break; | 227 | break; |
206 | case 'e': case 'E': case 'f': case 'g': case 'G': | 228 | case 'e': |
229 | case 'E': | ||
230 | case 'f': | ||
231 | case 'g': | ||
232 | case 'G': | ||
207 | pr->flags = F_DBL; | 233 | pr->flags = F_DBL; |
208 | switch(fu->bcnt) { | 234 | switch (fu->bcnt) { |
209 | case 0: case 8: | 235 | case 0: |
236 | case 8: | ||
210 | pr->bcnt = 8; | 237 | pr->bcnt = 8; |
211 | break; | 238 | break; |
212 | case 4: | 239 | case 4: |
@@ -214,14 +241,16 @@ sw1: switch(fu->bcnt) { | |||
214 | break; | 241 | break; |
215 | default: | 242 | default: |
216 | p1[1] = '\0'; | 243 | p1[1] = '\0'; |
217 | error_msg_and_die("bad byte count for conversion character %s.", p1); | 244 | error_msg_and_die |
245 | ("bad byte count for conversion character %s.", p1); | ||
218 | } | 246 | } |
219 | break; | 247 | break; |
220 | case 's': | 248 | case 's': |
221 | pr->flags = F_STR; | 249 | pr->flags = F_STR; |
222 | switch(sokay) { | 250 | switch (sokay) { |
223 | case NOTOKAY: | 251 | case NOTOKAY: |
224 | error_msg_and_die("%%s requires a precision or a byte count."); | 252 | error_msg_and_die |
253 | ("%%s requires a precision or a byte count."); | ||
225 | case USEBCNT: | 254 | case USEBCNT: |
226 | pr->bcnt = fu->bcnt; | 255 | pr->bcnt = fu->bcnt; |
227 | break; | 256 | break; |
@@ -232,7 +261,7 @@ sw1: switch(fu->bcnt) { | |||
232 | break; | 261 | break; |
233 | case '_': | 262 | case '_': |
234 | ++p2; | 263 | ++p2; |
235 | switch(p1[1]) { | 264 | switch (p1[1]) { |
236 | case 'A': | 265 | case 'A': |
237 | endfu = fu; | 266 | endfu = fu; |
238 | fu->flags |= F_IGNORE; | 267 | fu->flags |= F_IGNORE; |
@@ -240,18 +269,21 @@ sw1: switch(fu->bcnt) { | |||
240 | case 'a': | 269 | case 'a': |
241 | pr->flags = F_ADDRESS; | 270 | pr->flags = F_ADDRESS; |
242 | ++p2; | 271 | ++p2; |
243 | switch(p1[2]) { | 272 | switch (p1[2]) { |
244 | case 'd': case 'o': case'x': | 273 | case 'd': |
274 | case 'o': | ||
275 | case 'x': | ||
245 | *p1 = p1[2]; | 276 | *p1 = p1[2]; |
246 | break; | 277 | break; |
247 | default: | 278 | default: |
248 | p1[3] = '\0'; | 279 | p1[3] = '\0'; |
249 | error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1); | 280 | error_msg_and_die |
281 | ("hexdump: bad conversion character %%%s.\n", p1); | ||
250 | } | 282 | } |
251 | break; | 283 | break; |
252 | case 'c': | 284 | case 'c': |
253 | pr->flags = F_C; | 285 | pr->flags = F_C; |
254 | /* *p1 = 'c'; set in conv_c */ | 286 | /* *p1 = 'c'; set in conv_c */ |
255 | goto sw2; | 287 | goto sw2; |
256 | case 'p': | 288 | case 'p': |
257 | pr->flags = F_P; | 289 | pr->flags = F_P; |
@@ -259,24 +291,29 @@ sw1: switch(fu->bcnt) { | |||
259 | goto sw2; | 291 | goto sw2; |
260 | case 'u': | 292 | case 'u': |
261 | pr->flags = F_U; | 293 | pr->flags = F_U; |
262 | /* *p1 = 'c'; set in conv_u */ | 294 | /* *p1 = 'c'; set in conv_u */ |
263 | sw2: switch(fu->bcnt) { | 295 | sw2:switch (fu->bcnt) { |
264 | case 0: case 1: | 296 | case 0: |
297 | case 1: | ||
265 | pr->bcnt = 1; | 298 | pr->bcnt = 1; |
266 | break; | 299 | break; |
267 | default: | 300 | default: |
268 | p1[2] = '\0'; | 301 | p1[2] = '\0'; |
269 | error_msg_and_die("bad byte count for conversion character %s.", p1); | 302 | error_msg_and_die |
303 | ("bad byte count for conversion character %s.", | ||
304 | p1); | ||
270 | } | 305 | } |
271 | break; | 306 | break; |
272 | default: | 307 | default: |
273 | p1[2] = '\0'; | 308 | p1[2] = '\0'; |
274 | error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1); | 309 | error_msg_and_die |
310 | ("hexdump: bad conversion character %%%s.\n", p1); | ||
275 | } | 311 | } |
276 | break; | 312 | break; |
277 | default: | 313 | default: |
278 | p1[1] = '\0'; | 314 | p1[1] = '\0'; |
279 | error_msg_and_die("hexdump: bad conversion character %%%s.\n", p1); | 315 | error_msg_and_die("hexdump: bad conversion character %%%s.\n", |
316 | p1); | ||
280 | } | 317 | } |
281 | 318 | ||
282 | /* | 319 | /* |
@@ -292,8 +329,9 @@ sw2: switch(fu->bcnt) { | |||
292 | fmtp = p2; | 329 | fmtp = p2; |
293 | 330 | ||
294 | /* only one conversion character if byte count */ | 331 | /* only one conversion character if byte count */ |
295 | if (!(pr->flags&F_ADDRESS) && fu->bcnt && nconv++) { | 332 | if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) { |
296 | error_msg_and_die("hexdump: byte count with multiple conversion characters.\n"); | 333 | error_msg_and_die |
334 | ("hexdump: byte count with multiple conversion characters.\n"); | ||
297 | } | 335 | } |
298 | } | 336 | } |
299 | /* | 337 | /* |
@@ -315,7 +353,7 @@ sw2: switch(fu->bcnt) { | |||
315 | */ | 353 | */ |
316 | for (fu = fs->nextfu;; fu = fu->nextfu) { | 354 | for (fu = fs->nextfu;; fu = fu->nextfu) { |
317 | if (!fu->nextfu && fs->bcnt < blocksize && | 355 | if (!fu->nextfu && fs->bcnt < blocksize && |
318 | !(fu->flags&F_SETREP) && fu->bcnt) | 356 | !(fu->flags & F_SETREP) && fu->bcnt) |
319 | fu->reps += (blocksize - fs->bcnt) / fu->bcnt; | 357 | fu->reps += (blocksize - fs->bcnt) / fu->bcnt; |
320 | if (fu->reps > 1) { | 358 | if (fu->reps > 1) { |
321 | for (pr = fu->nextpr;; pr = pr->nextpr) | 359 | for (pr = fu->nextpr;; pr = pr->nextpr) |
@@ -339,11 +377,10 @@ static void doskip(char *fname, int statok) | |||
339 | if (fstat(fileno(stdin), &sbuf)) { | 377 | if (fstat(fileno(stdin), &sbuf)) { |
340 | perror_msg_and_die("hexdump: %s", fname); | 378 | perror_msg_and_die("hexdump: %s", fname); |
341 | } | 379 | } |
342 | if ( ( ! (S_ISCHR(sbuf.st_mode) || | 380 | if ((!(S_ISCHR(sbuf.st_mode) || |
343 | S_ISBLK(sbuf.st_mode) || | 381 | S_ISBLK(sbuf.st_mode) || |
344 | S_ISFIFO(sbuf.st_mode)) ) && | 382 | S_ISFIFO(sbuf.st_mode))) && skip >= sbuf.st_size) { |
345 | skip >= sbuf.st_size) { | 383 | /* If size valid and skip >= size */ |
346 | /* If size valid and skip >= size */ | ||
347 | skip -= sbuf.st_size; | 384 | skip -= sbuf.st_size; |
348 | address += sbuf.st_size; | 385 | address += sbuf.st_size; |
349 | return; | 386 | return; |
@@ -363,7 +400,7 @@ int next(char **argv) | |||
363 | 400 | ||
364 | if (argv) { | 401 | if (argv) { |
365 | _argv = argv; | 402 | _argv = argv; |
366 | return(1); | 403 | return (1); |
367 | } | 404 | } |
368 | for (;;) { | 405 | for (;;) { |
369 | if (*_argv) { | 406 | if (*_argv) { |
@@ -376,7 +413,7 @@ int next(char **argv) | |||
376 | statok = done = 1; | 413 | statok = done = 1; |
377 | } else { | 414 | } else { |
378 | if (done++) | 415 | if (done++) |
379 | return(0); | 416 | return (0); |
380 | statok = 0; | 417 | statok = 0; |
381 | } | 418 | } |
382 | if (skip) | 419 | if (skip) |
@@ -384,13 +421,12 @@ int next(char **argv) | |||
384 | if (*_argv) | 421 | if (*_argv) |
385 | ++_argv; | 422 | ++_argv; |
386 | if (!skip) | 423 | if (!skip) |
387 | return(1); | 424 | return (1); |
388 | } | 425 | } |
389 | /* NOTREACHED */ | 426 | /* NOTREACHED */ |
390 | } | 427 | } |
391 | 428 | ||
392 | static u_char * | 429 | static u_char *get(void) |
393 | get(void) | ||
394 | { | 430 | { |
395 | static int ateof = 1; | 431 | static int ateof = 1; |
396 | static u_char *curp, *savp; | 432 | static u_char *curp, *savp; |
@@ -399,8 +435,8 @@ get(void) | |||
399 | u_char *tmpp; | 435 | u_char *tmpp; |
400 | 436 | ||
401 | if (!curp) { | 437 | if (!curp) { |
402 | curp = (u_char *)xmalloc(blocksize); | 438 | curp = (u_char *) xmalloc(blocksize); |
403 | savp = (u_char *)xmalloc(blocksize); | 439 | savp = (u_char *) xmalloc(blocksize); |
404 | } else { | 440 | } else { |
405 | tmpp = curp; | 441 | tmpp = curp; |
406 | curp = savp; | 442 | curp = savp; |
@@ -413,22 +449,22 @@ get(void) | |||
413 | * and no other files are available, zero-pad the rest of the | 449 | * and no other files are available, zero-pad the rest of the |
414 | * block and set the end flag. | 450 | * block and set the end flag. |
415 | */ | 451 | */ |
416 | if (!length || (ateof && !next((char **)NULL))) { | 452 | if (!length || (ateof && !next((char **) NULL))) { |
417 | if (need == blocksize) { | 453 | if (need == blocksize) { |
418 | return((u_char *)NULL); | 454 | return ((u_char *) NULL); |
419 | } | 455 | } |
420 | if (vflag != ALL && !bcmp(curp, savp, nread)) { | 456 | if (vflag != ALL && !bcmp(curp, savp, nread)) { |
421 | if (vflag != DUP) { | 457 | if (vflag != DUP) { |
422 | printf("*\n"); | 458 | printf("*\n"); |
423 | } | 459 | } |
424 | return((u_char *)NULL); | 460 | return ((u_char *) NULL); |
425 | } | 461 | } |
426 | bzero((char *)curp + nread, need); | 462 | bzero((char *) curp + nread, need); |
427 | eaddress = address + nread; | 463 | eaddress = address + nread; |
428 | return(curp); | 464 | return (curp); |
429 | } | 465 | } |
430 | n = fread((char *)curp + nread, sizeof(u_char), | 466 | n = fread((char *) curp + nread, sizeof(u_char), |
431 | length == -1 ? need : MIN(length, need), stdin); | 467 | length == -1 ? need : MIN(length, need), stdin); |
432 | if (!n) { | 468 | if (!n) { |
433 | if (ferror(stdin)) { | 469 | if (ferror(stdin)) { |
434 | perror_msg("%s", _argv[-1]); | 470 | perror_msg("%s", _argv[-1]); |
@@ -441,12 +477,11 @@ get(void) | |||
441 | length -= n; | 477 | length -= n; |
442 | } | 478 | } |
443 | if (!(need -= n)) { | 479 | if (!(need -= n)) { |
444 | if (vflag == ALL || vflag == FIRST || | 480 | if (vflag == ALL || vflag == FIRST || bcmp(curp, savp, blocksize)) { |
445 | bcmp(curp, savp, blocksize)) { | ||
446 | if (vflag == DUP || vflag == FIRST) { | 481 | if (vflag == DUP || vflag == FIRST) { |
447 | vflag = WAIT; | 482 | vflag = WAIT; |
448 | } | 483 | } |
449 | return(curp); | 484 | return (curp); |
450 | } | 485 | } |
451 | if (vflag == WAIT) { | 486 | if (vflag == WAIT) { |
452 | printf("*\n"); | 487 | printf("*\n"); |
@@ -461,7 +496,7 @@ get(void) | |||
461 | } | 496 | } |
462 | } | 497 | } |
463 | 498 | ||
464 | static void bpad(PR *pr) | 499 | static void bpad(PR * pr) |
465 | { | 500 | { |
466 | register char *p1, *p2; | 501 | register char *p1, *p2; |
467 | 502 | ||
@@ -473,18 +508,18 @@ static void bpad(PR *pr) | |||
473 | *pr->cchar = 's'; | 508 | *pr->cchar = 's'; |
474 | for (p1 = pr->fmt; *p1 != '%'; ++p1); | 509 | for (p1 = pr->fmt; *p1 != '%'; ++p1); |
475 | for (p2 = ++p1; *p1 && index(" -0+#", *p1); ++p1); | 510 | for (p2 = ++p1; *p1 && index(" -0+#", *p1); ++p1); |
476 | while ((*p2++ = *p1++) != 0) ; | 511 | while ((*p2++ = *p1++) != 0); |
477 | } | 512 | } |
478 | 513 | ||
479 | void conv_c(PR *pr, u_char *p) | 514 | void conv_c(PR * pr, u_char * p) |
480 | { | 515 | { |
481 | char buf[10], *str; | 516 | char buf[10], *str; |
482 | 517 | ||
483 | switch(*p) { | 518 | switch (*p) { |
484 | case '\0': | 519 | case '\0': |
485 | str = "\\0"; | 520 | str = "\\0"; |
486 | goto strpr; | 521 | goto strpr; |
487 | /* case '\a': */ | 522 | /* case '\a': */ |
488 | case '\007': | 523 | case '\007': |
489 | str = "\\a"; | 524 | str = "\\a"; |
490 | goto strpr; | 525 | goto strpr; |
@@ -511,22 +546,22 @@ void conv_c(PR *pr, u_char *p) | |||
511 | } | 546 | } |
512 | if (isprint(*p)) { | 547 | if (isprint(*p)) { |
513 | *pr->cchar = 'c'; | 548 | *pr->cchar = 'c'; |
514 | (void)printf(pr->fmt, *p); | 549 | (void) printf(pr->fmt, *p); |
515 | } else { | 550 | } else { |
516 | sprintf(str = buf, "%03o", (int)*p); | 551 | sprintf(str = buf, "%03o", (int) *p); |
517 | strpr: | 552 | strpr: |
518 | *pr->cchar = 's'; | 553 | *pr->cchar = 's'; |
519 | printf(pr->fmt, str); | 554 | printf(pr->fmt, str); |
520 | } | 555 | } |
521 | } | 556 | } |
522 | 557 | ||
523 | void conv_u(PR *pr, u_char *p) | 558 | void conv_u(PR * pr, u_char * p) |
524 | { | 559 | { |
525 | static char *list[] = { | 560 | static char *list[] = { |
526 | "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", | 561 | "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", |
527 | "bs", "ht", "lf", "vt", "ff", "cr", "so", "si", | 562 | "bs", "ht", "lf", "vt", "ff", "cr", "so", "si", |
528 | "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb", | 563 | "dle", "dcl", "dc2", "dc3", "dc4", "nak", "syn", "etb", |
529 | "can", "em", "sub", "esc", "fs", "gs", "rs", "us", | 564 | "can", "em", "sub", "esc", "fs", "gs", "rs", "us", |
530 | }; | 565 | }; |
531 | 566 | ||
532 | /* od used nl, not lf */ | 567 | /* od used nl, not lf */ |
@@ -541,118 +576,128 @@ void conv_u(PR *pr, u_char *p) | |||
541 | printf(pr->fmt, *p); | 576 | printf(pr->fmt, *p); |
542 | } else { | 577 | } else { |
543 | *pr->cchar = 'x'; | 578 | *pr->cchar = 'x'; |
544 | printf(pr->fmt, (int)*p); | 579 | printf(pr->fmt, (int) *p); |
545 | } | 580 | } |
546 | } | 581 | } |
547 | 582 | ||
548 | void display(void) | 583 | void display(void) |
549 | { | 584 | { |
550 | // extern FU *endfu; | 585 | /* extern FU *endfu; */ |
551 | register FS *fs; | 586 | register FS *fs; |
552 | register FU *fu; | 587 | register FU *fu; |
553 | register PR *pr; | 588 | register PR *pr; |
554 | register int cnt; | 589 | register int cnt; |
555 | register u_char *bp; | 590 | register u_char *bp; |
556 | // off_t saveaddress; | 591 | |
592 | /* off_t saveaddress; */ | ||
557 | u_char savech = 0, *savebp; | 593 | u_char savech = 0, *savebp; |
558 | 594 | ||
559 | while ((bp = get()) != NULL) { | 595 | while ((bp = get()) != NULL) { |
560 | for (fs = fshead, savebp = bp, saveaddress = address; fs; | 596 | for (fs = fshead, savebp = bp, saveaddress = address; fs; |
561 | fs = fs->nextfs, bp = savebp, address = saveaddress) { | 597 | fs = fs->nextfs, bp = savebp, address = saveaddress) { |
562 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { | 598 | for (fu = fs->nextfu; fu; fu = fu->nextfu) { |
563 | if (fu->flags & F_IGNORE) { | 599 | if (fu->flags & F_IGNORE) { |
564 | break; | 600 | break; |
565 | } | 601 | } |
566 | for (cnt = fu->reps; cnt; --cnt) { | 602 | for (cnt = fu->reps; cnt; --cnt) { |
567 | for (pr = fu->nextpr; pr; address += pr->bcnt, | 603 | for (pr = fu->nextpr; pr; address += pr->bcnt, |
568 | bp += pr->bcnt, pr = pr->nextpr) { | 604 | bp += pr->bcnt, pr = pr->nextpr) { |
569 | if (eaddress && address >= eaddress && | 605 | if (eaddress && address >= eaddress && |
570 | !(pr->flags&(F_TEXT|F_BPAD))) { | 606 | !(pr->flags & (F_TEXT | F_BPAD))) { |
571 | bpad(pr); | 607 | bpad(pr); |
572 | } | 608 | } |
573 | if (cnt == 1 && pr->nospace) { | 609 | if (cnt == 1 && pr->nospace) { |
574 | savech = *pr->nospace; | 610 | savech = *pr->nospace; |
575 | *pr->nospace = '\0'; | 611 | *pr->nospace = '\0'; |
576 | } | 612 | } |
577 | // PRINT; | 613 | /* PRINT; */ |
578 | switch(pr->flags) { | 614 | switch (pr->flags) { |
579 | case F_ADDRESS: | 615 | case F_ADDRESS: |
580 | printf(pr->fmt, address); | 616 | printf(pr->fmt, address); |
581 | break; | 617 | break; |
582 | case F_BPAD: | 618 | case F_BPAD: |
583 | printf(pr->fmt, ""); | 619 | printf(pr->fmt, ""); |
584 | break; | 620 | break; |
585 | case F_C: | 621 | case F_C: |
586 | conv_c(pr, bp); | 622 | conv_c(pr, bp); |
587 | break; | 623 | break; |
588 | case F_CHAR: | 624 | case F_CHAR: |
589 | printf(pr->fmt, *bp); | 625 | printf(pr->fmt, *bp); |
626 | break; | ||
627 | case F_DBL:{ | ||
628 | double dval; | ||
629 | float fval; | ||
630 | |||
631 | switch (pr->bcnt) { | ||
632 | case 4: | ||
633 | bcopy((char *) bp, (char *) &fval, | ||
634 | sizeof(fval)); | ||
635 | printf(pr->fmt, fval); | ||
590 | break; | 636 | break; |
591 | case F_DBL: { | 637 | case 8: |
592 | double dval; | 638 | bcopy((char *) bp, (char *) &dval, |
593 | float fval; | 639 | sizeof(dval)); |
594 | switch(pr->bcnt) { | 640 | printf(pr->fmt, dval); |
595 | case 4: | ||
596 | bcopy((char *)bp, (char *)&fval, sizeof(fval)); | ||
597 | printf(pr->fmt, fval); | ||
598 | break; | ||
599 | case 8: | ||
600 | bcopy((char *)bp, (char *)&dval, sizeof(dval)); | ||
601 | printf(pr->fmt, dval); | ||
602 | break; | ||
603 | } | ||
604 | break; | 641 | break; |
605 | } | 642 | } |
606 | case F_INT: { | 643 | break; |
607 | int ival; | 644 | } |
608 | short sval; | 645 | case F_INT:{ |
609 | switch(pr->bcnt) { | 646 | int ival; |
610 | case 1: | 647 | short sval; |
611 | printf(pr->fmt, (int)*bp); | 648 | |
612 | break; | 649 | switch (pr->bcnt) { |
613 | case 2: | 650 | case 1: |
614 | bcopy((char *)bp, (char *)&sval, sizeof(sval)); | 651 | printf(pr->fmt, (int) *bp); |
615 | printf(pr->fmt, (int)sval); | ||
616 | break; | ||
617 | case 4: | ||
618 | bcopy((char *)bp, (char *)&ival, sizeof(ival)); | ||
619 | printf(pr->fmt, ival); | ||
620 | break; | ||
621 | } | ||
622 | break; | 652 | break; |
623 | } | 653 | case 2: |
624 | case F_P: | 654 | bcopy((char *) bp, (char *) &sval, |
625 | printf(pr->fmt, isprint(*bp) ? *bp : '.'); | 655 | sizeof(sval)); |
656 | printf(pr->fmt, (int) sval); | ||
626 | break; | 657 | break; |
627 | case F_STR: | 658 | case 4: |
628 | printf(pr->fmt, (char *)bp); | 659 | bcopy((char *) bp, (char *) &ival, |
660 | sizeof(ival)); | ||
661 | printf(pr->fmt, ival); | ||
629 | break; | 662 | break; |
630 | case F_TEXT: | 663 | } |
631 | printf(pr->fmt); | 664 | break; |
665 | } | ||
666 | case F_P: | ||
667 | printf(pr->fmt, isprint(*bp) ? *bp : '.'); | ||
668 | break; | ||
669 | case F_STR: | ||
670 | printf(pr->fmt, (char *) bp); | ||
671 | break; | ||
672 | case F_TEXT: | ||
673 | printf(pr->fmt); | ||
674 | break; | ||
675 | case F_U: | ||
676 | conv_u(pr, bp); | ||
677 | break; | ||
678 | case F_UINT:{ | ||
679 | u_int ival; | ||
680 | u_short sval; | ||
681 | |||
682 | switch (pr->bcnt) { | ||
683 | case 1: | ||
684 | printf(pr->fmt, (u_int) * bp); | ||
632 | break; | 685 | break; |
633 | case F_U: | 686 | case 2: |
634 | conv_u(pr, bp); | 687 | bcopy((char *) bp, (char *) &sval, |
688 | sizeof(sval)); | ||
689 | printf(pr->fmt, (u_int) sval); | ||
635 | break; | 690 | break; |
636 | case F_UINT: { | 691 | case 4: |
637 | u_int ival; | 692 | bcopy((char *) bp, (char *) &ival, |
638 | u_short sval; | 693 | sizeof(ival)); |
639 | switch(pr->bcnt) { | 694 | printf(pr->fmt, ival); |
640 | case 1: | ||
641 | printf(pr->fmt, (u_int)*bp); | ||
642 | break; | ||
643 | case 2: | ||
644 | bcopy((char *)bp, (char *)&sval, sizeof(sval)); | ||
645 | printf(pr->fmt, (u_int)sval); | ||
646 | break; | ||
647 | case 4: | ||
648 | bcopy((char *)bp, (char *)&ival, sizeof(ival)); | ||
649 | printf(pr->fmt, ival); | ||
650 | break; | ||
651 | } | ||
652 | break; | 695 | break; |
653 | } | 696 | } |
697 | break; | ||
654 | } | 698 | } |
655 | if (cnt == 1 && pr->nospace) { | 699 | } |
700 | if (cnt == 1 && pr->nospace) { | ||
656 | *pr->nospace = savech; | 701 | *pr->nospace = savech; |
657 | } | 702 | } |
658 | } | 703 | } |
@@ -672,12 +717,12 @@ void display(void) | |||
672 | eaddress = address; | 717 | eaddress = address; |
673 | } | 718 | } |
674 | for (pr = endfu->nextpr; pr; pr = pr->nextpr) { | 719 | for (pr = endfu->nextpr; pr; pr = pr->nextpr) { |
675 | switch(pr->flags) { | 720 | switch (pr->flags) { |
676 | case F_ADDRESS: | 721 | case F_ADDRESS: |
677 | (void)printf(pr->fmt, eaddress); | 722 | (void) printf(pr->fmt, eaddress); |
678 | break; | 723 | break; |
679 | case F_TEXT: | 724 | case F_TEXT: |
680 | (void)printf(pr->fmt); | 725 | (void) printf(pr->fmt); |
681 | break; | 726 | break; |
682 | } | 727 | } |
683 | } | 728 | } |
@@ -703,7 +748,7 @@ int dump(char **argv) | |||
703 | next(argv); | 748 | next(argv); |
704 | display(); | 749 | display(); |
705 | 750 | ||
706 | return(exitval); | 751 | return (exitval); |
707 | } | 752 | } |
708 | 753 | ||
709 | void add(char *fmt) | 754 | void add(char *fmt) |
@@ -718,7 +763,7 @@ void add(char *fmt) | |||
718 | 763 | ||
719 | /* start new linked list of format units */ | 764 | /* start new linked list of format units */ |
720 | /* NOSTRICT */ | 765 | /* NOSTRICT */ |
721 | tfs = (FS *)xmalloc(sizeof(FS)); | 766 | tfs = (FS *) xmalloc(sizeof(FS)); |
722 | if (!fshead) { | 767 | if (!fshead) { |
723 | fshead = tfs; | 768 | fshead = tfs; |
724 | } else { | 769 | } else { |
@@ -737,7 +782,7 @@ void add(char *fmt) | |||
737 | 782 | ||
738 | /* allocate a new format unit and link it in */ | 783 | /* allocate a new format unit and link it in */ |
739 | /* NOSTRICT */ | 784 | /* NOSTRICT */ |
740 | tfu = (FU *)xmalloc(sizeof(FU)); | 785 | tfu = (FU *) xmalloc(sizeof(FU)); |
741 | *nextfu = tfu; | 786 | *nextfu = tfu; |
742 | nextfu = &tfu->nextfu; | 787 | nextfu = &tfu->nextfu; |
743 | tfu->reps = 1; | 788 | tfu->reps = 1; |
@@ -785,7 +830,7 @@ void add(char *fmt) | |||
785 | } | 830 | } |
786 | strncpy(tfu->fmt, savep, p - savep); | 831 | strncpy(tfu->fmt, savep, p - savep); |
787 | tfu->fmt[p - savep] = '\0'; | 832 | tfu->fmt[p - savep] = '\0'; |
788 | // escape(tfu->fmt); | 833 | /* escape(tfu->fmt); */ |
789 | 834 | ||
790 | p1 = tfu->fmt; | 835 | p1 = tfu->fmt; |
791 | 836 | ||
@@ -796,9 +841,9 @@ void add(char *fmt) | |||
796 | break; | 841 | break; |
797 | } | 842 | } |
798 | if (*p1 == '\\') { | 843 | if (*p1 == '\\') { |
799 | switch(*++p1) { | 844 | switch (*++p1) { |
800 | case 'a': | 845 | case 'a': |
801 | /* *p2 = '\a'; */ | 846 | /* *p2 = '\a'; */ |
802 | *p2 = '\007'; | 847 | *p2 = '\007'; |
803 | break; | 848 | break; |
804 | case 'b': | 849 | case 'b': |
@@ -829,6 +874,7 @@ void add(char *fmt) | |||
829 | p++; | 874 | p++; |
830 | } | 875 | } |
831 | } | 876 | } |
877 | |||
832 | /* | 878 | /* |
833 | * Copyright (c) 1989 The Regents of the University of California. | 879 | * Copyright (c) 1989 The Regents of the University of California. |
834 | * All rights reserved. | 880 | * All rights reserved. |
diff --git a/libbb/unzip.c b/libbb/unzip.c index cde16d067..76fb86285 100644 --- a/libbb/unzip.c +++ b/libbb/unzip.c | |||
@@ -69,7 +69,7 @@ static char *license_msg[] = { | |||
69 | #include "libbb.h" | 69 | #include "libbb.h" |
70 | 70 | ||
71 | #ifdef CONFIG_FEATURE_UNCOMPRESS | 71 | #ifdef CONFIG_FEATURE_UNCOMPRESS |
72 | int uncompress ( FILE *in, FILE *out ); | 72 | int uncompress(FILE * in, FILE * out); |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | static FILE *in_file, *out_file; | 75 | static FILE *in_file, *out_file; |
@@ -78,7 +78,7 @@ static FILE *in_file, *out_file; | |||
78 | static unsigned char *window; | 78 | static unsigned char *window; |
79 | static unsigned long *crc_table; | 79 | static unsigned long *crc_table; |
80 | 80 | ||
81 | static unsigned long crc; /* shift register contents */ | 81 | static unsigned long crc; /* shift register contents */ |
82 | 82 | ||
83 | /* Return codes from gzip */ | 83 | /* Return codes from gzip */ |
84 | static const int ERROR = 1; | 84 | static const int ERROR = 1; |
@@ -90,21 +90,21 @@ static const int ERROR = 1; | |||
90 | static const int WSIZE = 0x8000; | 90 | static const int WSIZE = 0x8000; |
91 | 91 | ||
92 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ | 92 | /* If BMAX needs to be larger than 16, then h and x[] should be ulg. */ |
93 | static const int BMAX = 16; /* maximum bit length of any code (16 for explode) */ | 93 | static const int BMAX = 16; /* maximum bit length of any code (16 for explode) */ |
94 | static const int N_MAX = 288; /* maximum number of codes in any set */ | 94 | static const int N_MAX = 288; /* maximum number of codes in any set */ |
95 | 95 | ||
96 | static long bytes_out; /* number of output bytes */ | 96 | static long bytes_out; /* number of output bytes */ |
97 | static unsigned long outcnt; /* bytes in output buffer */ | 97 | static unsigned long outcnt; /* bytes in output buffer */ |
98 | 98 | ||
99 | static unsigned hufts; /* track memory usage */ | 99 | static unsigned hufts; /* track memory usage */ |
100 | static unsigned long bb; /* bit buffer */ | 100 | static unsigned long bb; /* bit buffer */ |
101 | static unsigned bk; /* bits in bit buffer */ | 101 | static unsigned bk; /* bits in bit buffer */ |
102 | 102 | ||
103 | typedef struct huft_s { | 103 | typedef struct huft_s { |
104 | unsigned char e; /* number of extra bits or operation */ | 104 | unsigned char e; /* number of extra bits or operation */ |
105 | unsigned char b; /* number of bits in this code or subcode */ | 105 | unsigned char b; /* number of bits in this code or subcode */ |
106 | union { | 106 | union { |
107 | unsigned short n; /* literal, length base, or distance base */ | 107 | unsigned short n; /* literal, length base, or distance base */ |
108 | struct huft_s *t; /* pointer to next level of table */ | 108 | struct huft_s *t; /* pointer to next level of table */ |
109 | } v; | 109 | } v; |
110 | } huft_t; | 110 | } huft_t; |
@@ -115,11 +115,11 @@ static const unsigned short mask_bits[] = { | |||
115 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 115 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
116 | }; | 116 | }; |
117 | 117 | ||
118 | //static int error_number = 0; | 118 | /* static int error_number = 0; */ |
119 | /* ======================================================================== | 119 | /* ======================================================================== |
120 | * Signal and error handler. | 120 | * Signal and error handler. |
121 | */ | 121 | */ |
122 | 122 | ||
123 | static void abort_gzip(void) | 123 | static void abort_gzip(void) |
124 | { | 124 | { |
125 | error_msg("gzip aborted\n"); | 125 | error_msg("gzip aborted\n"); |
@@ -128,26 +128,28 @@ static void abort_gzip(void) | |||
128 | 128 | ||
129 | static void make_crc_table(void) | 129 | static void make_crc_table(void) |
130 | { | 130 | { |
131 | const unsigned long poly = 0xedb88320; /* polynomial exclusive-or pattern */ | 131 | const unsigned long poly = 0xedb88320; /* polynomial exclusive-or pattern */ |
132 | unsigned short i; /* counter for all possible eight bit values */ | 132 | unsigned short i; /* counter for all possible eight bit values */ |
133 | 133 | ||
134 | /* initial shift register value */ | 134 | /* initial shift register value */ |
135 | crc = 0xffffffffL; | 135 | crc = 0xffffffffL; |
136 | crc_table = (unsigned long *) malloc(256 * sizeof(unsigned long)); | 136 | crc_table = (unsigned long *) malloc(256 * sizeof(unsigned long)); |
137 | 137 | ||
138 | /* Compute and print table of CRC's, five per line */ | 138 | /* Compute and print table of CRC's, five per line */ |
139 | for (i = 0; i < 256; i++) { | 139 | for (i = 0; i < 256; i++) { |
140 | unsigned long table_entry; /* crc shift register */ | 140 | unsigned long table_entry; /* crc shift register */ |
141 | char k; /* byte being shifted into crc apparatus */ | 141 | char k; /* byte being shifted into crc apparatus */ |
142 | 142 | ||
143 | table_entry = i; | 143 | table_entry = i; |
144 | /* The idea to initialize the register with the byte instead of | 144 | /* The idea to initialize the register with the byte instead of |
145 | * zero was stolen from Haruhiko Okumura's ar002 | 145 | * zero was stolen from Haruhiko Okumura's ar002 |
146 | */ | 146 | */ |
147 | for (k = 8; k; k--) { | 147 | for (k = 8; k; k--) { |
148 | table_entry = table_entry & 1 ? (table_entry >> 1) ^ poly : table_entry >> 1; | 148 | table_entry = |
149 | table_entry & 1 ? (table_entry >> 1) ^ poly : table_entry >> | ||
150 | 1; | ||
149 | } | 151 | } |
150 | crc_table[i]=table_entry; | 152 | crc_table[i] = table_entry; |
151 | } | 153 | } |
152 | } | 154 | } |
153 | 155 | ||
@@ -179,7 +181,7 @@ static void flush_window(void) | |||
179 | * each table. | 181 | * each table. |
180 | * t: table to free | 182 | * t: table to free |
181 | */ | 183 | */ |
182 | static int huft_free(huft_t *t) | 184 | static int huft_free(huft_t * t) |
183 | { | 185 | { |
184 | huft_t *p, *q; | 186 | huft_t *p, *q; |
185 | 187 | ||
@@ -209,36 +211,37 @@ typedef unsigned char extra_bits_t; | |||
209 | * t: result: starting table | 211 | * t: result: starting table |
210 | * m: maximum lookup bits, returns actual | 212 | * m: maximum lookup bits, returns actual |
211 | */ | 213 | */ |
212 | static int huft_build(unsigned int *b, const unsigned int n, const unsigned int s, | 214 | static int huft_build(unsigned int *b, const unsigned int n, |
213 | const unsigned short *d, const extra_bits_t *e, huft_t **t, int *m) | 215 | const unsigned int s, const unsigned short *d, |
216 | const extra_bits_t * e, huft_t ** t, int *m) | ||
214 | { | 217 | { |
215 | unsigned a; /* counter for codes of length k */ | 218 | unsigned a; /* counter for codes of length k */ |
216 | unsigned c[BMAX + 1]; /* bit length count table */ | 219 | unsigned c[BMAX + 1]; /* bit length count table */ |
217 | unsigned f; /* i repeats in table every f entries */ | 220 | unsigned f; /* i repeats in table every f entries */ |
218 | int g; /* maximum code length */ | 221 | int g; /* maximum code length */ |
219 | int h; /* table level */ | 222 | int h; /* table level */ |
220 | register unsigned i; /* counter, current code */ | 223 | register unsigned i; /* counter, current code */ |
221 | register unsigned j; /* counter */ | 224 | register unsigned j; /* counter */ |
222 | register int k; /* number of bits in current code */ | 225 | register int k; /* number of bits in current code */ |
223 | int l; /* bits per table (returned in m) */ | 226 | int l; /* bits per table (returned in m) */ |
224 | register unsigned *p; /* pointer into c[], b[], or v[] */ | 227 | register unsigned *p; /* pointer into c[], b[], or v[] */ |
225 | register huft_t *q; /* points to current table */ | 228 | register huft_t *q; /* points to current table */ |
226 | huft_t r; /* table entry for structure assignment */ | 229 | huft_t r; /* table entry for structure assignment */ |
227 | huft_t *u[BMAX]; /* table stack */ | 230 | huft_t *u[BMAX]; /* table stack */ |
228 | unsigned v[N_MAX]; /* values in order of bit length */ | 231 | unsigned v[N_MAX]; /* values in order of bit length */ |
229 | register int w; /* bits before this table == (l * h) */ | 232 | register int w; /* bits before this table == (l * h) */ |
230 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ | 233 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ |
231 | unsigned *xp; /* pointer into x */ | 234 | unsigned *xp; /* pointer into x */ |
232 | int y; /* number of dummy codes added */ | 235 | int y; /* number of dummy codes added */ |
233 | unsigned z; /* number of entries in current table */ | 236 | unsigned z; /* number of entries in current table */ |
234 | 237 | ||
235 | /* Generate counts for each bit length */ | 238 | /* Generate counts for each bit length */ |
236 | memset ((void *)(c), 0, sizeof(c)); | 239 | memset((void *) (c), 0, sizeof(c)); |
237 | p = b; | 240 | p = b; |
238 | i = n; | 241 | i = n; |
239 | do { | 242 | do { |
240 | c[*p]++; /* assume all entries <= BMAX */ | 243 | c[*p]++; /* assume all entries <= BMAX */ |
241 | p++; /* Can't combine with above line (Solaris bug) */ | 244 | p++; /* Can't combine with above line (Solaris bug) */ |
242 | } while (--i); | 245 | } while (--i); |
243 | if (c[0] == n) { /* null input--all zero length codes */ | 246 | if (c[0] == n) { /* null input--all zero length codes */ |
244 | *t = (huft_t *) NULL; | 247 | *t = (huft_t *) NULL; |
@@ -274,7 +277,7 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
274 | x[1] = j = 0; | 277 | x[1] = j = 0; |
275 | p = c + 1; | 278 | p = c + 1; |
276 | xp = x + 2; | 279 | xp = x + 2; |
277 | while (--i) { /* note that i == g from above */ | 280 | while (--i) { /* note that i == g from above */ |
278 | *xp++ = (j += *p++); | 281 | *xp++ = (j += *p++); |
279 | } | 282 | } |
280 | 283 | ||
@@ -287,7 +290,7 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
287 | } while (++i < n); | 290 | } while (++i < n); |
288 | 291 | ||
289 | /* Generate the Huffman codes and for each, make the table entries */ | 292 | /* Generate the Huffman codes and for each, make the table entries */ |
290 | x[0] = i = 0; /* first Huffman code is zero */ | 293 | x[0] = i = 0; /* first Huffman code is zero */ |
291 | p = v; /* grab values in bit order */ | 294 | p = v; /* grab values in bit order */ |
292 | h = -1; /* no tables yet--level -1 */ | 295 | h = -1; /* no tables yet--level -1 */ |
293 | w = -l; /* bits decoded == (l * h) */ | 296 | w = -l; /* bits decoded == (l * h) */ |
@@ -303,7 +306,7 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
303 | /* make tables up to required level */ | 306 | /* make tables up to required level */ |
304 | while (k > w + l) { | 307 | while (k > w + l) { |
305 | h++; | 308 | h++; |
306 | w += l; /* previous table always l bits */ | 309 | w += l; /* previous table always l bits */ |
307 | 310 | ||
308 | /* compute minimum size table less than or equal to l bits */ | 311 | /* compute minimum size table less than or equal to l bits */ |
309 | z = (z = g - w) > (unsigned) l ? l : z; /* upper limit on table size */ | 312 | z = (z = g - w) > (unsigned) l ? l : z; /* upper limit on table size */ |
@@ -316,15 +319,15 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
316 | f -= *xp; /* else deduct codes from patterns */ | 319 | f -= *xp; /* else deduct codes from patterns */ |
317 | } | 320 | } |
318 | } | 321 | } |
319 | z = 1 << j; /* table entries for j-bit table */ | 322 | z = 1 << j; /* table entries for j-bit table */ |
320 | 323 | ||
321 | /* allocate and link in new table */ | 324 | /* allocate and link in new table */ |
322 | q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t)); | 325 | q = (huft_t *) xmalloc((z + 1) * sizeof(huft_t)); |
323 | 326 | ||
324 | hufts += z + 1; /* track memory usage */ | 327 | hufts += z + 1; /* track memory usage */ |
325 | *t = q + 1; /* link to list for huft_free() */ | 328 | *t = q + 1; /* link to list for huft_free() */ |
326 | *(t = &(q->v.t)) = NULL; | 329 | *(t = &(q->v.t)) = NULL; |
327 | u[h] = ++q; /* table starts after link */ | 330 | u[h] = ++q; /* table starts after link */ |
328 | 331 | ||
329 | /* connect to last table, if there is one */ | 332 | /* connect to last table, if there is one */ |
330 | if (h) { | 333 | if (h) { |
@@ -340,11 +343,11 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
340 | /* set up table entry in r */ | 343 | /* set up table entry in r */ |
341 | r.b = (unsigned char) (k - w); | 344 | r.b = (unsigned char) (k - w); |
342 | if (p >= v + n) | 345 | if (p >= v + n) |
343 | r.e = 99; /* out of values--invalid code */ | 346 | r.e = 99; /* out of values--invalid code */ |
344 | else if (*p < s) { | 347 | else if (*p < s) { |
345 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */ | 348 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is end-of-block code */ |
346 | r.v.n = (unsigned short) (*p); /* simple code is just the value */ | 349 | r.v.n = (unsigned short) (*p); /* simple code is just the value */ |
347 | p++; /* one compiler does not like *p++ */ | 350 | p++; /* one compiler does not like *p++ */ |
348 | } else { | 351 | } else { |
349 | r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */ | 352 | r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */ |
350 | r.v.n = d[*p++ - s]; | 353 | r.v.n = d[*p++ - s]; |
@@ -362,7 +365,7 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
362 | 365 | ||
363 | /* backup over finished tables */ | 366 | /* backup over finished tables */ |
364 | while ((i & ((1 << w) - 1)) != x[h]) { | 367 | while ((i & ((1 << w) - 1)) != x[h]) { |
365 | h--; /* don't need to update q */ | 368 | h--; /* don't need to update q */ |
366 | w -= l; | 369 | w -= l; |
367 | } | 370 | } |
368 | } | 371 | } |
@@ -378,52 +381,52 @@ static int huft_build(unsigned int *b, const unsigned int n, const unsigned int | |||
378 | * tl, td: literal/length and distance decoder tables | 381 | * tl, td: literal/length and distance decoder tables |
379 | * bl, bd: number of bits decoded by tl[] and td[] | 382 | * bl, bd: number of bits decoded by tl[] and td[] |
380 | */ | 383 | */ |
381 | static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd) | 384 | static int inflate_codes(huft_t * tl, huft_t * td, int bl, int bd) |
382 | { | 385 | { |
383 | register unsigned long e; /* table entry flag/number of extra bits */ | 386 | register unsigned long e; /* table entry flag/number of extra bits */ |
384 | unsigned long n, d; /* length and index for copy */ | 387 | unsigned long n, d; /* length and index for copy */ |
385 | unsigned long w; /* current window position */ | 388 | unsigned long w; /* current window position */ |
386 | huft_t *t; /* pointer to table entry */ | 389 | huft_t *t; /* pointer to table entry */ |
387 | unsigned ml, md; /* masks for bl and bd bits */ | 390 | unsigned ml, md; /* masks for bl and bd bits */ |
388 | register unsigned long b; /* bit buffer */ | 391 | register unsigned long b; /* bit buffer */ |
389 | register unsigned k; /* number of bits in bit buffer */ | 392 | register unsigned k; /* number of bits in bit buffer */ |
390 | 393 | ||
391 | /* make local copies of globals */ | 394 | /* make local copies of globals */ |
392 | b = bb; /* initialize bit buffer */ | 395 | b = bb; /* initialize bit buffer */ |
393 | k = bk; | 396 | k = bk; |
394 | w = outcnt; /* initialize window position */ | 397 | w = outcnt; /* initialize window position */ |
395 | 398 | ||
396 | /* inflate the coded data */ | 399 | /* inflate the coded data */ |
397 | ml = mask_bits[bl]; /* precompute masks for speed */ | 400 | ml = mask_bits[bl]; /* precompute masks for speed */ |
398 | md = mask_bits[bd]; | 401 | md = mask_bits[bd]; |
399 | for (;;) { /* do until end of block */ | 402 | for (;;) { /* do until end of block */ |
400 | while (k < (unsigned) bl) { | 403 | while (k < (unsigned) bl) { |
401 | b |= ((unsigned long)fgetc(in_file)) << k; | 404 | b |= ((unsigned long) fgetc(in_file)) << k; |
402 | k += 8; | 405 | k += 8; |
403 | } | 406 | } |
404 | if ((e = (t = tl + ((unsigned) b & ml))->e) > 16) | 407 | if ((e = (t = tl + ((unsigned) b & ml))->e) > 16) |
405 | do { | 408 | do { |
406 | if (e == 99) { | 409 | if (e == 99) { |
407 | return 1; | 410 | return 1; |
408 | } | 411 | } |
409 | b >>= t->b; | 412 | b >>= t->b; |
410 | k -= t->b; | 413 | k -= t->b; |
411 | e -= 16; | 414 | e -= 16; |
412 | while (k < e) { | 415 | while (k < e) { |
413 | b |= ((unsigned long)fgetc(in_file)) << k; | 416 | b |= ((unsigned long) fgetc(in_file)) << k; |
414 | k += 8; | 417 | k += 8; |
415 | } | 418 | } |
416 | } while ((e = (t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16); | 419 | } while ((e = |
420 | (t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16); | ||
417 | b >>= t->b; | 421 | b >>= t->b; |
418 | k -= t->b; | 422 | k -= t->b; |
419 | if (e == 16) { /* then it's a literal */ | 423 | if (e == 16) { /* then it's a literal */ |
420 | window[w++] = (unsigned char) t->v.n; | 424 | window[w++] = (unsigned char) t->v.n; |
421 | if (w == WSIZE) { | 425 | if (w == WSIZE) { |
422 | outcnt=(w), | 426 | outcnt = (w), flush_window(); |
423 | flush_window(); | ||
424 | w = 0; | 427 | w = 0; |
425 | } | 428 | } |
426 | } else { /* it's an EOB or a length */ | 429 | } else { /* it's an EOB or a length */ |
427 | 430 | ||
428 | /* exit if end of block */ | 431 | /* exit if end of block */ |
429 | if (e == 15) { | 432 | if (e == 15) { |
@@ -432,7 +435,7 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd) | |||
432 | 435 | ||
433 | /* get length of block to copy */ | 436 | /* get length of block to copy */ |
434 | while (k < e) { | 437 | while (k < e) { |
435 | b |= ((unsigned long)fgetc(in_file)) << k; | 438 | b |= ((unsigned long) fgetc(in_file)) << k; |
436 | k += 8; | 439 | k += 8; |
437 | } | 440 | } |
438 | n = t->v.n + ((unsigned) b & mask_bits[e]); | 441 | n = t->v.n + ((unsigned) b & mask_bits[e]); |
@@ -441,7 +444,7 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd) | |||
441 | 444 | ||
442 | /* decode distance of block to copy */ | 445 | /* decode distance of block to copy */ |
443 | while (k < (unsigned) bd) { | 446 | while (k < (unsigned) bd) { |
444 | b |= ((unsigned long)fgetc(in_file)) << k; | 447 | b |= ((unsigned long) fgetc(in_file)) << k; |
445 | k += 8; | 448 | k += 8; |
446 | } | 449 | } |
447 | 450 | ||
@@ -453,14 +456,16 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd) | |||
453 | k -= t->b; | 456 | k -= t->b; |
454 | e -= 16; | 457 | e -= 16; |
455 | while (k < e) { | 458 | while (k < e) { |
456 | b |= ((unsigned long)fgetc(in_file)) << k; | 459 | b |= ((unsigned long) fgetc(in_file)) << k; |
457 | k += 8; | 460 | k += 8; |
458 | } | 461 | } |
459 | } while ((e = (t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16); | 462 | } while ((e = |
463 | (t = | ||
464 | t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16); | ||
460 | b >>= t->b; | 465 | b >>= t->b; |
461 | k -= t->b; | 466 | k -= t->b; |
462 | while (k < e) { | 467 | while (k < e) { |
463 | b |= ((unsigned long)fgetc(in_file)) << k; | 468 | b |= ((unsigned long) fgetc(in_file)) << k; |
464 | k += 8; | 469 | k += 8; |
465 | } | 470 | } |
466 | d = w - t->v.n - ((unsigned) b & mask_bits[e]); | 471 | d = w - t->v.n - ((unsigned) b & mask_bits[e]); |
@@ -469,20 +474,21 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd) | |||
469 | 474 | ||
470 | /* do the copy */ | 475 | /* do the copy */ |
471 | do { | 476 | do { |
472 | n -= (e = (e = WSIZE - ((d &= WSIZE - 1) > w ? d : w)) > n ? n : e); | 477 | n -= (e = |
478 | (e = | ||
479 | WSIZE - ((d &= WSIZE - 1) > w ? d : w)) > n ? n : e); | ||
473 | #if !defined(NOMEMCPY) && !defined(DEBUG) | 480 | #if !defined(NOMEMCPY) && !defined(DEBUG) |
474 | if (w - d >= e) { /* (this test assumes unsigned comparison) */ | 481 | if (w - d >= e) { /* (this test assumes unsigned comparison) */ |
475 | memcpy(window + w, window + d, e); | 482 | memcpy(window + w, window + d, e); |
476 | w += e; | 483 | w += e; |
477 | d += e; | 484 | d += e; |
478 | } else /* do it slow to avoid memcpy() overlap */ | 485 | } else /* do it slow to avoid memcpy() overlap */ |
479 | #endif /* !NOMEMCPY */ | 486 | #endif /* !NOMEMCPY */ |
480 | do { | 487 | do { |
481 | window[w++] = window[d++]; | 488 | window[w++] = window[d++]; |
482 | } while (--e); | 489 | } while (--e); |
483 | if (w == WSIZE) { | 490 | if (w == WSIZE) { |
484 | outcnt=(w), | 491 | outcnt = (w), flush_window(); |
485 | flush_window(); | ||
486 | w = 0; | 492 | w = 0; |
487 | } | 493 | } |
488 | } while (n); | 494 | } while (n); |
@@ -498,28 +504,30 @@ static int inflate_codes(huft_t *tl, huft_t *td, int bl, int bd) | |||
498 | return 0; | 504 | return 0; |
499 | } | 505 | } |
500 | 506 | ||
501 | static const unsigned short cplens[] = { /* Copy lengths for literal codes 257..285 */ | 507 | static const unsigned short cplens[] = { /* Copy lengths for literal codes 257..285 */ |
502 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, | 508 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, |
503 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 | 509 | 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 |
504 | }; | 510 | }; |
511 | |||
505 | /* note: see note #13 above about the 258 in this list. */ | 512 | /* note: see note #13 above about the 258 in this list. */ |
506 | static const extra_bits_t cplext[] = { /* Extra bits for literal codes 257..285 */ | 513 | static const extra_bits_t cplext[] = { /* Extra bits for literal codes 257..285 */ |
507 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, | 514 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, |
508 | 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 | 515 | 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 |
509 | }; /* 99==invalid */ | 516 | }; /* 99==invalid */ |
510 | static const unsigned short cpdist[] = { /* Copy offsets for distance codes 0..29 */ | 517 | static const unsigned short cpdist[] = { /* Copy offsets for distance codes 0..29 */ |
511 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, | 518 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, |
512 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, | 519 | 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, |
513 | 8193, 12289, 16385, 24577 | 520 | 8193, 12289, 16385, 24577 |
514 | }; | 521 | }; |
515 | static const extra_bits_t cpdext[] = { /* Extra bits for distance codes */ | 522 | static const extra_bits_t cpdext[] = { /* Extra bits for distance codes */ |
516 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, | 523 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, |
517 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, | 524 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, |
518 | 12, 12, 13, 13 | 525 | 12, 12, 13, 13 |
519 | }; | 526 | }; |
527 | |||
520 | /* Tables for deflate from PKZIP's appnote.txt. */ | 528 | /* Tables for deflate from PKZIP's appnote.txt. */ |
521 | static const extra_bits_t border[] = { /* Order of the bit length code lengths */ | 529 | static const extra_bits_t border[] = { /* Order of the bit length code lengths */ |
522 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 | 530 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
523 | }; | 531 | }; |
524 | 532 | ||
525 | /* | 533 | /* |
@@ -531,8 +539,8 @@ static const extra_bits_t border[] = { /* Order of the bit length code lengths | |||
531 | static int inflate_block(int *e) | 539 | static int inflate_block(int *e) |
532 | { | 540 | { |
533 | unsigned t; /* block type */ | 541 | unsigned t; /* block type */ |
534 | register unsigned long b; /* bit buffer */ | 542 | register unsigned long b; /* bit buffer */ |
535 | register unsigned k; /* number of bits in bit buffer */ | 543 | register unsigned k; /* number of bits in bit buffer */ |
536 | 544 | ||
537 | /* make local bit buffer */ | 545 | /* make local bit buffer */ |
538 | b = bb; | 546 | b = bb; |
@@ -540,7 +548,7 @@ static int inflate_block(int *e) | |||
540 | 548 | ||
541 | /* read in last block bit */ | 549 | /* read in last block bit */ |
542 | while (k < 1) { | 550 | while (k < 1) { |
543 | b |= ((unsigned long)fgetc(in_file)) << k; | 551 | b |= ((unsigned long) fgetc(in_file)) << k; |
544 | k += 8; | 552 | k += 8; |
545 | } | 553 | } |
546 | *e = (int) b & 1; | 554 | *e = (int) b & 1; |
@@ -549,7 +557,7 @@ static int inflate_block(int *e) | |||
549 | 557 | ||
550 | /* read in block type */ | 558 | /* read in block type */ |
551 | while (k < 2) { | 559 | while (k < 2) { |
552 | b |= ((unsigned long)fgetc(in_file)) << k; | 560 | b |= ((unsigned long) fgetc(in_file)) << k; |
553 | k += 8; | 561 | k += 8; |
554 | } | 562 | } |
555 | t = (unsigned) b & 3; | 563 | t = (unsigned) b & 3; |
@@ -562,286 +570,287 @@ static int inflate_block(int *e) | |||
562 | 570 | ||
563 | /* inflate that block type */ | 571 | /* inflate that block type */ |
564 | switch (t) { | 572 | switch (t) { |
565 | case 0: /* Inflate stored */ | 573 | case 0: /* Inflate stored */ |
566 | { | 574 | { |
567 | unsigned long n; /* number of bytes in block */ | 575 | unsigned long n; /* number of bytes in block */ |
568 | unsigned long w; /* current window position */ | 576 | unsigned long w; /* current window position */ |
569 | register unsigned long b_stored; /* bit buffer */ | 577 | register unsigned long b_stored; /* bit buffer */ |
570 | register unsigned long k_stored; /* number of bits in bit buffer */ | 578 | register unsigned long k_stored; /* number of bits in bit buffer */ |
571 | 579 | ||
572 | /* make local copies of globals */ | 580 | /* make local copies of globals */ |
573 | b_stored = bb; /* initialize bit buffer */ | 581 | b_stored = bb; /* initialize bit buffer */ |
574 | k_stored = bk; | 582 | k_stored = bk; |
575 | w = outcnt; /* initialize window position */ | 583 | w = outcnt; /* initialize window position */ |
576 | 584 | ||
577 | /* go to byte boundary */ | 585 | /* go to byte boundary */ |
578 | n = k_stored & 7; | 586 | n = k_stored & 7; |
579 | b_stored >>= n; | 587 | b_stored >>= n; |
580 | k_stored -= n; | 588 | k_stored -= n; |
581 | 589 | ||
582 | /* get the length and its complement */ | 590 | /* get the length and its complement */ |
583 | while (k_stored < 16) { | 591 | while (k_stored < 16) { |
584 | b_stored |= ((unsigned long)fgetc(in_file)) << k_stored; | 592 | b_stored |= ((unsigned long) fgetc(in_file)) << k_stored; |
585 | k_stored += 8; | 593 | k_stored += 8; |
586 | } | 594 | } |
587 | n = ((unsigned) b_stored & 0xffff); | 595 | n = ((unsigned) b_stored & 0xffff); |
588 | b_stored >>= 16; | 596 | b_stored >>= 16; |
589 | k_stored -= 16; | 597 | k_stored -= 16; |
590 | while (k_stored < 16) { | 598 | while (k_stored < 16) { |
591 | b_stored |= ((unsigned long)fgetc(in_file)) << k_stored; | 599 | b_stored |= ((unsigned long) fgetc(in_file)) << k_stored; |
600 | k_stored += 8; | ||
601 | } | ||
602 | if (n != (unsigned) ((~b_stored) & 0xffff)) { | ||
603 | return 1; /* error in compressed data */ | ||
604 | } | ||
605 | b_stored >>= 16; | ||
606 | k_stored -= 16; | ||
607 | |||
608 | /* read and output the compressed data */ | ||
609 | while (n--) { | ||
610 | while (k_stored < 8) { | ||
611 | b_stored |= ((unsigned long) fgetc(in_file)) << k_stored; | ||
592 | k_stored += 8; | 612 | k_stored += 8; |
593 | } | 613 | } |
594 | if (n != (unsigned) ((~b_stored) & 0xffff)) { | 614 | window[w++] = (unsigned char) b_stored; |
595 | return 1; /* error in compressed data */ | 615 | if (w == (unsigned long) WSIZE) { |
596 | } | 616 | outcnt = (w), flush_window(); |
597 | b_stored >>= 16; | 617 | w = 0; |
598 | k_stored -= 16; | ||
599 | |||
600 | /* read and output the compressed data */ | ||
601 | while (n--) { | ||
602 | while (k_stored < 8) { | ||
603 | b_stored |= ((unsigned long)fgetc(in_file)) << k_stored; | ||
604 | k_stored += 8; | ||
605 | } | ||
606 | window[w++] = (unsigned char) b_stored; | ||
607 | if (w == (unsigned long)WSIZE) { | ||
608 | outcnt=(w), | ||
609 | flush_window(); | ||
610 | w = 0; | ||
611 | } | ||
612 | b_stored >>= 8; | ||
613 | k_stored -= 8; | ||
614 | } | 618 | } |
619 | b_stored >>= 8; | ||
620 | k_stored -= 8; | ||
621 | } | ||
615 | 622 | ||
616 | /* restore the globals from the locals */ | 623 | /* restore the globals from the locals */ |
617 | outcnt = w; /* restore global window pointer */ | 624 | outcnt = w; /* restore global window pointer */ |
618 | bb = b_stored; /* restore global bit buffer */ | 625 | bb = b_stored; /* restore global bit buffer */ |
619 | bk = k_stored; | 626 | bk = k_stored; |
620 | return 0; | 627 | return 0; |
628 | } | ||
629 | case 1: /* Inflate fixed | ||
630 | * decompress an inflated type 1 (fixed Huffman codes) block. We should | ||
631 | * either replace this with a custom decoder, or at least precompute the | ||
632 | * Huffman tables. | ||
633 | */ | ||
634 | { | ||
635 | int i; /* temporary variable */ | ||
636 | huft_t *tl; /* literal/length code table */ | ||
637 | huft_t *td; /* distance code table */ | ||
638 | int bl; /* lookup bits for tl */ | ||
639 | int bd; /* lookup bits for td */ | ||
640 | unsigned int l[288]; /* length list for huft_build */ | ||
641 | |||
642 | /* set up literal table */ | ||
643 | for (i = 0; i < 144; i++) { | ||
644 | l[i] = 8; | ||
645 | } | ||
646 | for (; i < 256; i++) { | ||
647 | l[i] = 9; | ||
648 | } | ||
649 | for (; i < 280; i++) { | ||
650 | l[i] = 7; | ||
651 | } | ||
652 | for (; i < 288; i++) { /* make a complete, but wrong code set */ | ||
653 | l[i] = 8; | ||
654 | } | ||
655 | bl = 7; | ||
656 | if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0) { | ||
657 | return i; | ||
621 | } | 658 | } |
622 | case 1: /* Inflate fixed | ||
623 | * decompress an inflated type 1 (fixed Huffman codes) block. We should | ||
624 | * either replace this with a custom decoder, or at least precompute the | ||
625 | * Huffman tables. | ||
626 | */ | ||
627 | { | ||
628 | int i; /* temporary variable */ | ||
629 | huft_t *tl; /* literal/length code table */ | ||
630 | huft_t *td; /* distance code table */ | ||
631 | int bl; /* lookup bits for tl */ | ||
632 | int bd; /* lookup bits for td */ | ||
633 | unsigned int l[288]; /* length list for huft_build */ | ||
634 | |||
635 | /* set up literal table */ | ||
636 | for (i = 0; i < 144; i++) { | ||
637 | l[i] = 8; | ||
638 | } | ||
639 | for (; i < 256; i++) { | ||
640 | l[i] = 9; | ||
641 | } | ||
642 | for (; i < 280; i++) { | ||
643 | l[i] = 7; | ||
644 | } | ||
645 | for (; i < 288; i++) { /* make a complete, but wrong code set */ | ||
646 | l[i] = 8; | ||
647 | } | ||
648 | bl = 7; | ||
649 | if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0) { | ||
650 | return i; | ||
651 | } | ||
652 | 659 | ||
653 | /* set up distance table */ | 660 | /* set up distance table */ |
654 | for (i = 0; i < 30; i++) { /* make an incomplete code set */ | 661 | for (i = 0; i < 30; i++) { /* make an incomplete code set */ |
655 | l[i] = 5; | 662 | l[i] = 5; |
656 | } | 663 | } |
657 | bd = 5; | 664 | bd = 5; |
658 | if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) { | 665 | if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) { |
659 | huft_free(tl); | 666 | huft_free(tl); |
660 | return i; | 667 | return i; |
661 | } | 668 | } |
662 | 669 | ||
663 | /* decompress until an end-of-block code */ | 670 | /* decompress until an end-of-block code */ |
664 | if (inflate_codes(tl, td, bl, bd)) | 671 | if (inflate_codes(tl, td, bl, bd)) |
665 | return 1; | 672 | return 1; |
666 | 673 | ||
667 | /* free the decoding tables, return */ | 674 | /* free the decoding tables, return */ |
668 | huft_free(tl); | 675 | huft_free(tl); |
669 | huft_free(td); | 676 | huft_free(td); |
670 | return 0; | 677 | return 0; |
678 | } | ||
679 | case 2: /* Inflate dynamic */ | ||
680 | { | ||
681 | const int dbits = 6; /* bits in base distance lookup table */ | ||
682 | const int lbits = 9; /* bits in base literal/length lookup table */ | ||
683 | |||
684 | int i; /* temporary variables */ | ||
685 | unsigned j; | ||
686 | unsigned l; /* last length */ | ||
687 | unsigned m; /* mask for bit lengths table */ | ||
688 | unsigned n; /* number of lengths to get */ | ||
689 | huft_t *tl; /* literal/length code table */ | ||
690 | huft_t *td; /* distance code table */ | ||
691 | int bl; /* lookup bits for tl */ | ||
692 | int bd; /* lookup bits for td */ | ||
693 | unsigned nb; /* number of bit length codes */ | ||
694 | unsigned nl; /* number of literal/length codes */ | ||
695 | unsigned nd; /* number of distance codes */ | ||
696 | |||
697 | unsigned ll[286 + 30]; /* literal/length and distance code lengths */ | ||
698 | register unsigned long b_dynamic; /* bit buffer */ | ||
699 | register unsigned k_dynamic; /* number of bits in bit buffer */ | ||
700 | |||
701 | /* make local bit buffer */ | ||
702 | b_dynamic = bb; | ||
703 | k_dynamic = bk; | ||
704 | |||
705 | /* read in table lengths */ | ||
706 | while (k_dynamic < 5) { | ||
707 | b_dynamic |= ((unsigned long) fgetc(in_file)) << k_dynamic; | ||
708 | k_dynamic += 8; | ||
709 | } | ||
710 | nl = 257 + ((unsigned) b_dynamic & 0x1f); /* number of literal/length codes */ | ||
711 | b_dynamic >>= 5; | ||
712 | k_dynamic -= 5; | ||
713 | while (k_dynamic < 5) { | ||
714 | b_dynamic |= ((unsigned long) fgetc(in_file)) << k_dynamic; | ||
715 | k_dynamic += 8; | ||
716 | } | ||
717 | nd = 1 + ((unsigned) b_dynamic & 0x1f); /* number of distance codes */ | ||
718 | b_dynamic >>= 5; | ||
719 | k_dynamic -= 5; | ||
720 | while (k_dynamic < 4) { | ||
721 | b_dynamic |= ((unsigned long) fgetc(in_file)) << k_dynamic; | ||
722 | k_dynamic += 8; | ||
723 | } | ||
724 | nb = 4 + ((unsigned) b_dynamic & 0xf); /* number of bit length codes */ | ||
725 | b_dynamic >>= 4; | ||
726 | k_dynamic -= 4; | ||
727 | if (nl > 286 || nd > 30) { | ||
728 | return 1; /* bad lengths */ | ||
671 | } | 729 | } |
672 | case 2: /* Inflate dynamic */ | 730 | |
673 | { | 731 | /* read in bit-length-code lengths */ |
674 | const int dbits = 6; /* bits in base distance lookup table */ | 732 | for (j = 0; j < nb; j++) { |
675 | const int lbits = 9; /* bits in base literal/length lookup table */ | 733 | while (k_dynamic < 3) { |
676 | 734 | b_dynamic |= ((unsigned long) fgetc(in_file)) << k_dynamic; | |
677 | int i; /* temporary variables */ | ||
678 | unsigned j; | ||
679 | unsigned l; /* last length */ | ||
680 | unsigned m; /* mask for bit lengths table */ | ||
681 | unsigned n; /* number of lengths to get */ | ||
682 | huft_t *tl; /* literal/length code table */ | ||
683 | huft_t *td; /* distance code table */ | ||
684 | int bl; /* lookup bits for tl */ | ||
685 | int bd; /* lookup bits for td */ | ||
686 | unsigned nb; /* number of bit length codes */ | ||
687 | unsigned nl; /* number of literal/length codes */ | ||
688 | unsigned nd; /* number of distance codes */ | ||
689 | |||
690 | unsigned ll[286 + 30]; /* literal/length and distance code lengths */ | ||
691 | register unsigned long b_dynamic; /* bit buffer */ | ||
692 | register unsigned k_dynamic; /* number of bits in bit buffer */ | ||
693 | |||
694 | /* make local bit buffer */ | ||
695 | b_dynamic = bb; | ||
696 | k_dynamic = bk; | ||
697 | |||
698 | /* read in table lengths */ | ||
699 | while (k_dynamic < 5) { | ||
700 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | ||
701 | k_dynamic += 8; | 735 | k_dynamic += 8; |
702 | } | 736 | } |
703 | nl = 257 + ((unsigned) b_dynamic & 0x1f); /* number of literal/length codes */ | 737 | ll[border[j]] = (unsigned) b_dynamic & 7; |
704 | b_dynamic >>= 5; | 738 | b_dynamic >>= 3; |
705 | k_dynamic -= 5; | 739 | k_dynamic -= 3; |
706 | while (k_dynamic < 5) { | 740 | } |
707 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | 741 | for (; j < 19; j++) { |
708 | k_dynamic += 8; | 742 | ll[border[j]] = 0; |
743 | } | ||
744 | |||
745 | /* build decoding table for trees--single level, 7 bit lookup */ | ||
746 | bl = 7; | ||
747 | if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) { | ||
748 | if (i == 1) { | ||
749 | huft_free(tl); | ||
709 | } | 750 | } |
710 | nd = 1 + ((unsigned) b_dynamic & 0x1f); /* number of distance codes */ | 751 | return i; /* incomplete code set */ |
711 | b_dynamic >>= 5; | 752 | } |
712 | k_dynamic -= 5; | 753 | |
713 | while (k_dynamic < 4) { | 754 | /* read in literal and distance code lengths */ |
714 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | 755 | n = nl + nd; |
756 | m = mask_bits[bl]; | ||
757 | i = l = 0; | ||
758 | while ((unsigned) i < n) { | ||
759 | while (k_dynamic < (unsigned) bl) { | ||
760 | b_dynamic |= ((unsigned long) fgetc(in_file)) << k_dynamic; | ||
715 | k_dynamic += 8; | 761 | k_dynamic += 8; |
716 | } | 762 | } |
717 | nb = 4 + ((unsigned) b_dynamic & 0xf); /* number of bit length codes */ | 763 | j = (td = tl + ((unsigned) b_dynamic & m))->b; |
718 | b_dynamic >>= 4; | 764 | b_dynamic >>= j; |
719 | k_dynamic -= 4; | 765 | k_dynamic -= j; |
720 | if (nl > 286 || nd > 30) { | 766 | j = td->v.n; |
721 | return 1; /* bad lengths */ | 767 | if (j < 16) { /* length of code in bits (0..15) */ |
722 | } | 768 | ll[i++] = l = j; /* save last length in l */ |
723 | 769 | } else if (j == 16) { /* repeat last length 3 to 6 times */ | |
724 | /* read in bit-length-code lengths */ | 770 | while (k_dynamic < 2) { |
725 | for (j = 0; j < nb; j++) { | 771 | b_dynamic |= |
772 | ((unsigned long) fgetc(in_file)) << k_dynamic; | ||
773 | k_dynamic += 8; | ||
774 | } | ||
775 | j = 3 + ((unsigned) b_dynamic & 3); | ||
776 | b_dynamic >>= 2; | ||
777 | k_dynamic -= 2; | ||
778 | if ((unsigned) i + j > n) { | ||
779 | return 1; | ||
780 | } | ||
781 | while (j--) { | ||
782 | ll[i++] = l; | ||
783 | } | ||
784 | } else if (j == 17) { /* 3 to 10 zero length codes */ | ||
726 | while (k_dynamic < 3) { | 785 | while (k_dynamic < 3) { |
727 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | 786 | b_dynamic |= |
787 | ((unsigned long) fgetc(in_file)) << k_dynamic; | ||
728 | k_dynamic += 8; | 788 | k_dynamic += 8; |
729 | } | 789 | } |
730 | ll[border[j]] = (unsigned) b_dynamic & 7; | 790 | j = 3 + ((unsigned) b_dynamic & 7); |
731 | b_dynamic >>= 3; | 791 | b_dynamic >>= 3; |
732 | k_dynamic -= 3; | 792 | k_dynamic -= 3; |
733 | } | 793 | if ((unsigned) i + j > n) { |
734 | for (; j < 19; j++) { | 794 | return 1; |
735 | ll[border[j]] = 0; | ||
736 | } | ||
737 | |||
738 | /* build decoding table for trees--single level, 7 bit lookup */ | ||
739 | bl = 7; | ||
740 | if ((i = huft_build(ll, 19, 19, NULL, NULL, &tl, &bl)) != 0) { | ||
741 | if (i == 1) { | ||
742 | huft_free(tl); | ||
743 | } | 795 | } |
744 | return i; /* incomplete code set */ | 796 | while (j--) { |
745 | } | 797 | ll[i++] = 0; |
746 | 798 | } | |
747 | /* read in literal and distance code lengths */ | 799 | l = 0; |
748 | n = nl + nd; | 800 | } else { /* j == 18: 11 to 138 zero length codes */ |
749 | m = mask_bits[bl]; | 801 | while (k_dynamic < 7) { |
750 | i = l = 0; | 802 | b_dynamic |= |
751 | while ((unsigned) i < n) { | 803 | ((unsigned long) fgetc(in_file)) << k_dynamic; |
752 | while (k_dynamic < (unsigned) bl) { | ||
753 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | ||
754 | k_dynamic += 8; | 804 | k_dynamic += 8; |
755 | } | 805 | } |
756 | j = (td = tl + ((unsigned) b_dynamic & m))->b; | 806 | j = 11 + ((unsigned) b_dynamic & 0x7f); |
757 | b_dynamic >>= j; | 807 | b_dynamic >>= 7; |
758 | k_dynamic -= j; | 808 | k_dynamic -= 7; |
759 | j = td->v.n; | 809 | if ((unsigned) i + j > n) { |
760 | if (j < 16) { /* length of code in bits (0..15) */ | 810 | return 1; |
761 | ll[i++] = l = j; /* save last length in l */ | ||
762 | } | 811 | } |
763 | else if (j == 16) { /* repeat last length 3 to 6 times */ | 812 | while (j--) { |
764 | while (k_dynamic < 2) { | 813 | ll[i++] = 0; |
765 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | ||
766 | k_dynamic += 8; | ||
767 | } | ||
768 | j = 3 + ((unsigned) b_dynamic & 3); | ||
769 | b_dynamic >>= 2; | ||
770 | k_dynamic -= 2; | ||
771 | if ((unsigned) i + j > n) { | ||
772 | return 1; | ||
773 | } | ||
774 | while (j--) { | ||
775 | ll[i++] = l; | ||
776 | } | ||
777 | } else if (j == 17) { /* 3 to 10 zero length codes */ | ||
778 | while (k_dynamic < 3) { | ||
779 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | ||
780 | k_dynamic += 8; | ||
781 | } | ||
782 | j = 3 + ((unsigned) b_dynamic & 7); | ||
783 | b_dynamic >>= 3; | ||
784 | k_dynamic -= 3; | ||
785 | if ((unsigned) i + j > n) { | ||
786 | return 1; | ||
787 | } | ||
788 | while (j--) { | ||
789 | ll[i++] = 0; | ||
790 | } | ||
791 | l = 0; | ||
792 | } else { /* j == 18: 11 to 138 zero length codes */ | ||
793 | while (k_dynamic < 7) { | ||
794 | b_dynamic |= ((unsigned long)fgetc(in_file)) << k_dynamic; | ||
795 | k_dynamic += 8; | ||
796 | } | ||
797 | j = 11 + ((unsigned) b_dynamic & 0x7f); | ||
798 | b_dynamic >>= 7; | ||
799 | k_dynamic -= 7; | ||
800 | if ((unsigned) i + j > n) { | ||
801 | return 1; | ||
802 | } | ||
803 | while (j--) { | ||
804 | ll[i++] = 0; | ||
805 | } | ||
806 | l = 0; | ||
807 | } | 814 | } |
815 | l = 0; | ||
808 | } | 816 | } |
817 | } | ||
809 | 818 | ||
810 | /* free decoding table for trees */ | 819 | /* free decoding table for trees */ |
811 | huft_free(tl); | 820 | huft_free(tl); |
812 | 821 | ||
813 | /* restore the global bit buffer */ | 822 | /* restore the global bit buffer */ |
814 | bb = b_dynamic; | 823 | bb = b_dynamic; |
815 | bk = k_dynamic; | 824 | bk = k_dynamic; |
816 | 825 | ||
817 | /* build the decoding tables for literal/length and distance codes */ | 826 | /* build the decoding tables for literal/length and distance codes */ |
818 | bl = lbits; | 827 | bl = lbits; |
819 | if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) { | 828 | if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) { |
820 | if (i == 1) { | 829 | if (i == 1) { |
821 | error_msg("Incomplete literal tree"); | 830 | error_msg("Incomplete literal tree"); |
822 | huft_free(tl); | ||
823 | } | ||
824 | return i; /* incomplete code set */ | ||
825 | } | ||
826 | bd = dbits; | ||
827 | if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) { | ||
828 | if (i == 1) { | ||
829 | error_msg("incomplete distance tree"); | ||
830 | huft_free(td); | ||
831 | } | ||
832 | huft_free(tl); | 831 | huft_free(tl); |
833 | return i; /* incomplete code set */ | ||
834 | } | 832 | } |
835 | 833 | return i; /* incomplete code set */ | |
836 | /* decompress until an end-of-block code */ | 834 | } |
837 | if (inflate_codes(tl, td, bl, bd)) | 835 | bd = dbits; |
838 | return 1; | 836 | if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) { |
839 | 837 | if (i == 1) { | |
840 | /* free the decoding tables, return */ | 838 | error_msg("incomplete distance tree"); |
839 | huft_free(td); | ||
840 | } | ||
841 | huft_free(tl); | 841 | huft_free(tl); |
842 | huft_free(td); | 842 | return i; /* incomplete code set */ |
843 | return 0; | ||
844 | } | 843 | } |
844 | |||
845 | /* decompress until an end-of-block code */ | ||
846 | if (inflate_codes(tl, td, bl, bd)) | ||
847 | return 1; | ||
848 | |||
849 | /* free the decoding tables, return */ | ||
850 | huft_free(tl); | ||
851 | huft_free(td); | ||
852 | return 0; | ||
853 | } | ||
845 | default: | 854 | default: |
846 | /* bad block type */ | 855 | /* bad block type */ |
847 | return 2; | 856 | return 2; |
@@ -853,7 +862,7 @@ static int inflate_block(int *e) | |||
853 | * | 862 | * |
854 | * GLOBAL VARIABLES: outcnt, bk, bb, hufts, inptr | 863 | * GLOBAL VARIABLES: outcnt, bk, bb, hufts, inptr |
855 | */ | 864 | */ |
856 | extern int inflate(FILE *in, FILE *out) | 865 | extern int inflate(FILE * in, FILE * out) |
857 | { | 866 | { |
858 | int e; /* last block flag */ | 867 | int e; /* last block flag */ |
859 | int r; /* result code */ | 868 | int r; /* result code */ |
@@ -868,7 +877,7 @@ extern int inflate(FILE *in, FILE *out) | |||
868 | out_file = out; | 877 | out_file = out; |
869 | 878 | ||
870 | /* Allocate all global buffers (for DYN_ALLOC option) */ | 879 | /* Allocate all global buffers (for DYN_ALLOC option) */ |
871 | window = xmalloc((size_t)(((2L*WSIZE)+1L)*sizeof(unsigned char))); | 880 | window = xmalloc((size_t) (((2L * WSIZE) + 1L) * sizeof(unsigned char))); |
872 | bytes_out = 0L; | 881 | bytes_out = 0L; |
873 | 882 | ||
874 | /* Create the crc table */ | 883 | /* Create the crc table */ |
@@ -910,40 +919,35 @@ extern int inflate(FILE *in, FILE *out) | |||
910 | * The magic header has already been checked. The output buffer is cleared. | 919 | * The magic header has already been checked. The output buffer is cleared. |
911 | * in, out: input and output file descriptors | 920 | * in, out: input and output file descriptors |
912 | */ | 921 | */ |
913 | extern int unzip(FILE *l_in_file, FILE *l_out_file) | 922 | extern int unzip(FILE * l_in_file, FILE * l_out_file) |
914 | { | 923 | { |
915 | unsigned char buf[8]; /* extended local header */ | 924 | unsigned char buf[8]; /* extended local header */ |
916 | unsigned char flags; /* compression flags */ | 925 | unsigned char flags; /* compression flags */ |
917 | typedef void (*sig_type) (int); | 926 | typedef void (*sig_type) (int); |
918 | unsigned short i; | 927 | unsigned short i; |
919 | unsigned char magic [2]; | 928 | unsigned char magic[2]; |
920 | 929 | ||
921 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { | 930 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { |
922 | (void) signal(SIGINT, (sig_type) abort_gzip); | 931 | (void) signal(SIGINT, (sig_type) abort_gzip); |
923 | } | 932 | } |
924 | #ifdef SIGTERM | ||
925 | // if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { | ||
926 | // (void) signal(SIGTERM, (sig_type) abort_gzip); | ||
927 | // } | ||
928 | #endif | ||
929 | #ifdef SIGHUP | 933 | #ifdef SIGHUP |
930 | if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { | 934 | if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { |
931 | (void) signal(SIGHUP, (sig_type) abort_gzip); | 935 | (void) signal(SIGHUP, (sig_type) abort_gzip); |
932 | } | 936 | } |
933 | #endif | 937 | #endif |
934 | 938 | ||
935 | magic [0] = fgetc(l_in_file); | 939 | magic[0] = fgetc(l_in_file); |
936 | magic [1] = fgetc(l_in_file); | 940 | magic[1] = fgetc(l_in_file); |
937 | 941 | ||
938 | #ifdef CONFIG_FEATURE_UNCOMPRESS | 942 | #ifdef CONFIG_FEATURE_UNCOMPRESS |
939 | /* Magic header for compress files, 1F 9d = \037\235 */ | 943 | /* Magic header for compress files, 1F 9d = \037\235 */ |
940 | if (( magic [0] == 0x1F ) && ( magic [1] == 0x9d)) { | 944 | if ((magic[0] == 0x1F) && (magic[1] == 0x9d)) { |
941 | return uncompress ( l_in_file, l_out_file ); | 945 | return uncompress(l_in_file, l_out_file); |
942 | } | 946 | } |
943 | #endif | 947 | #endif |
944 | 948 | ||
945 | /* Magic header for gzip files, 1F 8B = \037\213 */ | 949 | /* Magic header for gzip files, 1F 8B = \037\213 */ |
946 | if (( magic [0] != 0x1F ) || ( magic [1] != 0x8b)) { | 950 | if ((magic[0] != 0x1F) || (magic[1] != 0x8b)) { |
947 | error_msg("Invalid gzip magic"); | 951 | error_msg("Invalid gzip magic"); |
948 | return EXIT_FAILURE; | 952 | return EXIT_FAILURE; |
949 | } | 953 | } |
@@ -951,7 +955,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
951 | /* Check the compression method */ | 955 | /* Check the compression method */ |
952 | if (fgetc(l_in_file) != 8) { | 956 | if (fgetc(l_in_file) != 8) { |
953 | error_msg("Unknown compression method"); | 957 | error_msg("Unknown compression method"); |
954 | return(-1); | 958 | return (-1); |
955 | } | 959 | } |
956 | 960 | ||
957 | flags = (unsigned char) fgetc(l_in_file); | 961 | flags = (unsigned char) fgetc(l_in_file); |
@@ -963,7 +967,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
963 | 967 | ||
964 | if (flags & 0x04) { | 968 | if (flags & 0x04) { |
965 | /* bit 2 set: extra field present */ | 969 | /* bit 2 set: extra field present */ |
966 | const unsigned short extra = fgetc(l_in_file) + (fgetc(l_in_file) << 8); | 970 | const unsigned short extra = |
971 | fgetc(l_in_file) + (fgetc(l_in_file) << 8); | ||
967 | 972 | ||
968 | for (i = 0; i < extra; i++) { | 973 | for (i = 0; i < extra; i++) { |
969 | fgetc(l_in_file); | 974 | fgetc(l_in_file); |
@@ -994,11 +999,14 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
994 | fread(buf, 1, 8, l_in_file); | 999 | fread(buf, 1, 8, l_in_file); |
995 | 1000 | ||
996 | /* Validate decompression - crc */ | 1001 | /* Validate decompression - crc */ |
997 | if ((unsigned int)((buf[0] | (buf[1] << 8)) |((buf[2] | (buf[3] << 8)) << 16)) != (crc ^ 0xffffffffL)) { | 1002 | if ((unsigned int) ((buf[0] | (buf[1] << 8)) | |
1003 | ((buf[2] | (buf[3] << 8)) << 16)) != | ||
1004 | (crc ^ 0xffffffffL)) { | ||
998 | error_msg("invalid compressed data--crc error"); | 1005 | error_msg("invalid compressed data--crc error"); |
999 | } | 1006 | } |
1000 | /* Validate decompression - size */ | 1007 | /* Validate decompression - size */ |
1001 | if (((buf[4] | (buf[5] << 8)) |((buf[6] | (buf[7] << 8)) << 16)) != (unsigned long) bytes_out) { | 1008 | if (((buf[4] | (buf[5] << 8)) | ((buf[6] | (buf[7] << 8)) << 16)) != |
1009 | (unsigned long) bytes_out) { | ||
1002 | error_msg("invalid compressed data--length error"); | 1010 | error_msg("invalid compressed data--length error"); |
1003 | } | 1011 | } |
1004 | 1012 | ||
@@ -1011,7 +1019,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
1011 | extern void gz_close(int gunzip_pid) | 1019 | extern void gz_close(int gunzip_pid) |
1012 | { | 1020 | { |
1013 | if (kill(gunzip_pid, SIGTERM) == -1) { | 1021 | if (kill(gunzip_pid, SIGTERM) == -1) { |
1014 | error_msg_and_die("*** Couldnt kill old gunzip process *** aborting"); | 1022 | error_msg_and_die |
1023 | ("*** Couldnt kill old gunzip process *** aborting"); | ||
1015 | } | 1024 | } |
1016 | 1025 | ||
1017 | if (waitpid(gunzip_pid, NULL, 0) == -1) { | 1026 | if (waitpid(gunzip_pid, NULL, 0) == -1) { |