diff options
-rw-r--r-- | archival/bunzip2.c | 616 |
1 files changed, 54 insertions, 562 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c index f2d514912..d24f383cf 100644 --- a/archival/bunzip2.c +++ b/archival/bunzip2.c | |||
@@ -71,19 +71,12 @@ | |||
71 | #define BZ_MAX_ALPHA_SIZE 258 | 71 | #define BZ_MAX_ALPHA_SIZE 258 |
72 | 72 | ||
73 | #define BZ_OK 0 | 73 | #define BZ_OK 0 |
74 | #define BZ_RUN_OK 1 | ||
75 | #define BZ_FLUSH_OK 2 | ||
76 | #define BZ_FINISH_OK 3 | ||
77 | #define BZ_STREAM_END 4 | 74 | #define BZ_STREAM_END 4 |
78 | #define BZ_SEQUENCE_ERROR (-1) | 75 | #define BZ_SEQUENCE_ERROR (-1) |
79 | #define BZ_PARAM_ERROR (-2) | ||
80 | #define BZ_MEM_ERROR (-3) | ||
81 | #define BZ_DATA_ERROR (-4) | 76 | #define BZ_DATA_ERROR (-4) |
82 | #define BZ_DATA_ERROR_MAGIC (-5) | 77 | #define BZ_DATA_ERROR_MAGIC (-5) |
83 | #define BZ_IO_ERROR (-6) | 78 | #define BZ_IO_ERROR (-6) |
84 | #define BZ_UNEXPECTED_EOF (-7) | 79 | #define BZ_UNEXPECTED_EOF (-7) |
85 | #define BZ_OUTBUFF_FULL (-8) | ||
86 | #define BZ_CONFIG_ERROR (-9) | ||
87 | 80 | ||
88 | #define BZ_RUNA 0 | 81 | #define BZ_RUNA 0 |
89 | #define BZ_RUNB 1 | 82 | #define BZ_RUNB 1 |
@@ -138,33 +131,24 @@ | |||
138 | #define BZ_X_CCRC_4 50 | 131 | #define BZ_X_CCRC_4 50 |
139 | 132 | ||
140 | #define BZ_MAX_CODE_LEN 23 | 133 | #define BZ_MAX_CODE_LEN 23 |
141 | #define BZ_VERSION "1.0.1, 23-June-2000" | ||
142 | #define OM_TEST 3 | 134 | #define OM_TEST 3 |
143 | #define SM_F2F 3 | 135 | #define SM_F2F 3 |
144 | 136 | ||
145 | typedef struct { | 137 | typedef struct { |
146 | char *next_in; | 138 | char *next_in; |
147 | unsigned int avail_in; | 139 | unsigned int avail_in; |
148 | unsigned int total_in_lo32; | ||
149 | unsigned int total_in_hi32; | ||
150 | 140 | ||
151 | char *next_out; | 141 | char *next_out; |
152 | unsigned int avail_out; | 142 | unsigned int avail_out; |
153 | unsigned int total_out_lo32; | ||
154 | unsigned int total_out_hi32; | ||
155 | 143 | ||
156 | void *state; | 144 | void *state; |
157 | 145 | ||
158 | void *(*bzalloc)(void *,int,int); | ||
159 | void (*bzfree)(void *,void *); | ||
160 | void *opaque; | ||
161 | } bz_stream; | 146 | } bz_stream; |
162 | 147 | ||
163 | typedef struct { | 148 | typedef struct { |
164 | bz_stream strm; | 149 | bz_stream strm; |
165 | FILE *handle; | 150 | FILE *handle; |
166 | unsigned char initialisedOk; | 151 | unsigned char initialisedOk; |
167 | unsigned char writing; | ||
168 | char buf[BZ_MAX_UNUSED]; | 152 | char buf[BZ_MAX_UNUSED]; |
169 | int lastErr; | 153 | int lastErr; |
170 | int bufN; | 154 | int bufN; |
@@ -191,9 +175,7 @@ typedef struct { | |||
191 | 175 | ||
192 | /* misc administratium */ | 176 | /* misc administratium */ |
193 | int blockSize100k; | 177 | int blockSize100k; |
194 | unsigned char smallDecompress; | ||
195 | int currBlockNo; | 178 | int currBlockNo; |
196 | int verbosity; | ||
197 | 179 | ||
198 | /* for undoing the Burrows-Wheeler transform */ | 180 | /* for undoing the Burrows-Wheeler transform */ |
199 | int origPtr; | 181 | int origPtr; |
@@ -207,10 +189,6 @@ typedef struct { | |||
207 | /* for undoing the Burrows-Wheeler transform (FAST) */ | 189 | /* for undoing the Burrows-Wheeler transform (FAST) */ |
208 | unsigned int *tt; | 190 | unsigned int *tt; |
209 | 191 | ||
210 | /* for undoing the Burrows-Wheeler transform (SMALL) */ | ||
211 | unsigned short *ll16; | ||
212 | unsigned char *ll4; | ||
213 | |||
214 | /* stored and calculated CRCs */ | 192 | /* stored and calculated CRCs */ |
215 | unsigned int storedBlockCRC; | 193 | unsigned int storedBlockCRC; |
216 | unsigned int storedCombinedCRC; | 194 | unsigned int storedCombinedCRC; |
@@ -263,10 +241,6 @@ typedef struct { | |||
263 | } DState; | 241 | } DState; |
264 | 242 | ||
265 | int BZ2_rNums[512]; | 243 | int BZ2_rNums[512]; |
266 | //int verbosity_level; | ||
267 | unsigned char smallMode; | ||
268 | unsigned char noisy; | ||
269 | char *progName; | ||
270 | char inName[FILE_NAME_LEN]; | 244 | char inName[FILE_NAME_LEN]; |
271 | char outName[FILE_NAME_LEN]; | 245 | char outName[FILE_NAME_LEN]; |
272 | int srcMode; | 246 | int srcMode; |
@@ -374,37 +348,19 @@ static void cleanUpAndFail(int ec) | |||
374 | int retVal; | 348 | int retVal; |
375 | 349 | ||
376 | if ((srcMode == SM_F2F) && (opMode != OM_TEST) && deleteOutputOnInterrupt) { | 350 | if ((srcMode == SM_F2F) && (opMode != OM_TEST) && deleteOutputOnInterrupt) { |
377 | if (noisy) { | ||
378 | error_msg("%s: Deleting output file %s, if it exists.\n", progName, outName); | ||
379 | } | ||
380 | if (outputHandleJustInCase != NULL) { | 351 | if (outputHandleJustInCase != NULL) { |
381 | fclose(outputHandleJustInCase); | 352 | fclose(outputHandleJustInCase); |
382 | } | 353 | } |
383 | retVal = remove(outName); | 354 | retVal = remove(outName); |
384 | if (retVal != 0) { | 355 | if (retVal != 0) { |
385 | error_msg("%s: WARNING: deletion of output file (apparently) failed.\n", progName); | 356 | error_msg("%s: WARNING: deletion of output file (apparently) failed.\n", applet_name); |
386 | } | 357 | } |
387 | } | 358 | } |
388 | if (noisy && (numFileNames > 0) && (numFilesProcessed < numFileNames)) { | ||
389 | error_msg("%s: WARNING: some files have not been processed:\n" | ||
390 | "\t%d specified on command line, %d not processed yet.\n\n", | ||
391 | progName, numFileNames, numFileNames - numFilesProcessed ); | ||
392 | } | ||
393 | 359 | ||
394 | exit(ec); | 360 | exit(ec); |
395 | } | 361 | } |
396 | 362 | ||
397 | 363 | ||
398 | void panic(char *s) | ||
399 | { | ||
400 | error_msg("\n%s: PANIC -- internal consistency error:\n" | ||
401 | "\t%s\n" | ||
402 | "\tThis is a BUG. Please report it to me at:\n" | ||
403 | "\tjseward@acm.org\n", | ||
404 | progName, s); | ||
405 | cleanUpAndFail( 3 ); | ||
406 | } | ||
407 | |||
408 | void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *length, int minLen, int maxLen, int alphaSize ) | 364 | void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *length, int minLen, int maxLen, int alphaSize ) |
409 | { | 365 | { |
410 | int pp, i, j, vec; | 366 | int pp, i, j, vec; |
@@ -446,40 +402,6 @@ void BZ2_hbCreateDecodeTables(int *limit, int *base, int *perm, unsigned char *l | |||
446 | } | 402 | } |
447 | } | 403 | } |
448 | 404 | ||
449 | int bz_get_small(DState *s) | ||
450 | { | ||
451 | int cccc; | ||
452 | int nb, na, mid; | ||
453 | nb = 0; | ||
454 | na = 256; | ||
455 | do { | ||
456 | mid = (nb + na) >> 1; | ||
457 | if (s->tPos >= s->cftab[mid]) { | ||
458 | nb = mid; | ||
459 | } else { | ||
460 | na = mid; | ||
461 | } | ||
462 | } | ||
463 | while (na - nb != 1); | ||
464 | cccc = nb; | ||
465 | s->tPos = (((unsigned int)s->ll16[s->tPos]) | | ||
466 | (((((unsigned int)(s->ll4[(s->tPos) >> 1])) >> | ||
467 | (((s->tPos) << 2) & 0x4)) & 0xF) << 16)); | ||
468 | return(cccc); | ||
469 | } | ||
470 | |||
471 | void assert_h(int errcode) | ||
472 | { | ||
473 | error_msg_and_die("\n\nbzip2/libbzip2: internal error number %d.\n" | ||
474 | "This is a bug in bzip2/libbzip2, %s.\n" | ||
475 | "Please report it to me at: jseward@acm.org. If this happened\n" | ||
476 | "when you were using some program which uses libbzip2 as a\n" | ||
477 | "component, you should also report this bug to the author(s)\n" | ||
478 | "of that program. Please make an effort to report this bug;\n" | ||
479 | "timely and accurate bug reports eventually lead to higher\n" | ||
480 | "quality software. Thanks. Julian Seward, 21 March 2000.\n\n", | ||
481 | errcode, BZ_VERSION); | ||
482 | } | ||
483 | 405 | ||
484 | static int get_bits(DState *s, int *vvv, char nnn) | 406 | static int get_bits(DState *s, int *vvv, char nnn) |
485 | { | 407 | { |
@@ -496,10 +418,6 @@ static int get_bits(DState *s, int *vvv, char nnn) | |||
496 | s->bsLive += 8; | 418 | s->bsLive += 8; |
497 | s->strm->next_in++; | 419 | s->strm->next_in++; |
498 | s->strm->avail_in--; | 420 | s->strm->avail_in--; |
499 | s->strm->total_in_lo32++; | ||
500 | if (s->strm->total_in_lo32 == 0) { | ||
501 | s->strm->total_in_hi32++; | ||
502 | } | ||
503 | } | 421 | } |
504 | return(TRUE); | 422 | return(TRUE); |
505 | } | 423 | } |
@@ -519,7 +437,6 @@ int BZ2_decompress(DState *s) | |||
519 | int uc = 0; | 437 | int uc = 0; |
520 | int retVal; | 438 | int retVal; |
521 | int minLen, maxLen; | 439 | int minLen, maxLen; |
522 | bz_stream *strm = s->strm; | ||
523 | 440 | ||
524 | /* stuff that needs to be saved/restored */ | 441 | /* stuff that needs to be saved/restored */ |
525 | int i; | 442 | int i; |
@@ -670,21 +587,7 @@ int BZ2_decompress(DState *s) | |||
670 | } | 587 | } |
671 | s->blockSize100k -= '0'; | 588 | s->blockSize100k -= '0'; |
672 | 589 | ||
673 | if (s->smallDecompress) { | 590 | s->tt = xmalloc(s->blockSize100k * 100000 * sizeof(int)); |
674 | s->ll16 = (strm->bzalloc)(strm->opaque, s->blockSize100k * 100000 * sizeof(unsigned short), 1); | ||
675 | s->ll4 = (strm->bzalloc)(strm->opaque, ((1 + s->blockSize100k * 100000) >> 1) * sizeof(unsigned char), 1); | ||
676 | |||
677 | if (s->ll16 == NULL || s->ll4 == NULL) { | ||
678 | retVal = BZ_MEM_ERROR; | ||
679 | goto save_state_and_return; | ||
680 | } | ||
681 | } else { | ||
682 | s->tt = (strm->bzalloc)(strm->opaque, s->blockSize100k * 100000 * sizeof(int), 1); | ||
683 | if (s->tt == NULL) { | ||
684 | retVal = BZ_MEM_ERROR; | ||
685 | goto save_state_and_return; | ||
686 | } | ||
687 | } | ||
688 | 591 | ||
689 | case BZ_X_BLKHDR_1: | 592 | case BZ_X_BLKHDR_1: |
690 | s->state = BZ_X_BLKHDR_1; | 593 | s->state = BZ_X_BLKHDR_1; |
@@ -757,9 +660,6 @@ int BZ2_decompress(DState *s) | |||
757 | } | 660 | } |
758 | 661 | ||
759 | s->currBlockNo++; | 662 | s->currBlockNo++; |
760 | if (s->verbosity >= 2) { | ||
761 | error_msg("\n [%d: huff+mtf ", s->currBlockNo); | ||
762 | } | ||
763 | s->storedBlockCRC = 0; | 663 | s->storedBlockCRC = 0; |
764 | 664 | ||
765 | case BZ_X_BCRC_1: | 665 | case BZ_X_BCRC_1: |
@@ -1135,26 +1035,14 @@ int BZ2_decompress(DState *s) | |||
1135 | uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ]; | 1035 | uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ]; |
1136 | s->unzftab[uc] += es; | 1036 | s->unzftab[uc] += es; |
1137 | 1037 | ||
1138 | if (s->smallDecompress) { | 1038 | while (es > 0) { |
1139 | while (es > 0) { | 1039 | if (nblock >= nblockMAX) { |
1140 | if (nblock >= nblockMAX) { | 1040 | retVal = BZ_DATA_ERROR; |
1141 | retVal = BZ_DATA_ERROR; | 1041 | goto save_state_and_return; |
1142 | goto save_state_and_return; | ||
1143 | } | ||
1144 | s->ll16[nblock] = (unsigned short)uc; | ||
1145 | nblock++; | ||
1146 | es--; | ||
1147 | } | ||
1148 | } else { | ||
1149 | while (es > 0) { | ||
1150 | if (nblock >= nblockMAX) { | ||
1151 | retVal = BZ_DATA_ERROR; | ||
1152 | goto save_state_and_return; | ||
1153 | } | ||
1154 | s->tt[nblock] = (unsigned int)uc; | ||
1155 | nblock++; | ||
1156 | es--; | ||
1157 | } | 1042 | } |
1043 | s->tt[nblock] = (unsigned int)uc; | ||
1044 | nblock++; | ||
1045 | es--; | ||
1158 | } | 1046 | } |
1159 | continue; | 1047 | continue; |
1160 | } else { | 1048 | } else { |
@@ -1217,11 +1105,7 @@ int BZ2_decompress(DState *s) | |||
1217 | /*-- end uc = MTF ( nextSym-1 ) --*/ | 1105 | /*-- end uc = MTF ( nextSym-1 ) --*/ |
1218 | 1106 | ||
1219 | s->unzftab[s->seqToUnseq[uc]]++; | 1107 | s->unzftab[s->seqToUnseq[uc]]++; |
1220 | if (s->smallDecompress) { | 1108 | s->tt[nblock] = (unsigned int)(s->seqToUnseq[uc]); |
1221 | s->ll16[nblock] = (unsigned short)(s->seqToUnseq[uc]); | ||
1222 | } else { | ||
1223 | s->tt[nblock] = (unsigned int)(s->seqToUnseq[uc]); | ||
1224 | } | ||
1225 | nblock++; | 1109 | nblock++; |
1226 | 1110 | ||
1227 | if (! get_mtf_val_init()) { | 1111 | if (! get_mtf_val_init()) { |
@@ -1271,9 +1155,6 @@ int BZ2_decompress(DState *s) | |||
1271 | s->state_out_ch = 0; | 1155 | s->state_out_ch = 0; |
1272 | s->calculatedBlockCRC = 0xffffffffL; | 1156 | s->calculatedBlockCRC = 0xffffffffL; |
1273 | s->state = BZ_X_OUTPUT; | 1157 | s->state = BZ_X_OUTPUT; |
1274 | if (s->verbosity >= 2) { | ||
1275 | error_msg("rt+rld"); | ||
1276 | } | ||
1277 | 1158 | ||
1278 | /*-- Set up cftab to facilitate generation of T^(-1) --*/ | 1159 | /*-- Set up cftab to facilitate generation of T^(-1) --*/ |
1279 | s->cftab[0] = 0; | 1160 | s->cftab[0] = 0; |
@@ -1284,82 +1165,27 @@ int BZ2_decompress(DState *s) | |||
1284 | s->cftab[i] += s->cftab[i-1]; | 1165 | s->cftab[i] += s->cftab[i-1]; |
1285 | } | 1166 | } |
1286 | 1167 | ||
1287 | if (s->smallDecompress) { | 1168 | /*-- compute the T^(-1) vector --*/ |
1288 | 1169 | for (i = 0; i < nblock; i++) { | |
1289 | /*-- Make a copy of cftab, used in generation of T --*/ | 1170 | uc = (unsigned char)(s->tt[i] & 0xff); |
1290 | for (i = 0; i <= 256; i++) { | 1171 | s->tt[s->cftab[uc]] |= (i << 8); |
1291 | s->cftabCopy[i] = s->cftab[i]; | 1172 | s->cftab[uc]++; |
1292 | } | 1173 | } |
1293 | |||
1294 | /*-- compute the T vector --*/ | ||
1295 | for (i = 0; i < nblock; i++) { | ||
1296 | uc = (unsigned char)(s->ll16[i]); | ||
1297 | s->ll16[i] = (unsigned short)(s->cftabCopy[uc] & 0x0000ffff); | ||
1298 | if (((i) & 0x1) == 0) { | ||
1299 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (s->cftabCopy[uc] >> 16); | ||
1300 | } else { | ||
1301 | s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((s->cftabCopy[uc] >> 16) << 4); | ||
1302 | } | ||
1303 | s->cftabCopy[uc]++; | ||
1304 | } | ||
1305 | |||
1306 | /*-- Compute T^(-1) by pointer reversal on T --*/ | ||
1307 | i = s->origPtr; | ||
1308 | j = (((unsigned int)s->ll16[i]) | | ||
1309 | (((((unsigned int)(s->ll4[(i) >> 1])) >> | ||
1310 | (((i) << 2) & 0x4)) & 0xF) << 16)); | ||
1311 | 1174 | ||
1312 | do { | 1175 | s->tPos = s->tt[s->origPtr] >> 8; |
1313 | const int tmp = (((unsigned int)s->ll16[j]) | | 1176 | s->nblock_used = 0; |
1314 | (((((unsigned int)(s->ll4[(j) >> 1])) >> | 1177 | if (s->blockRandomised) { |
1315 | (((j) << 2) & 0x4)) & 0xF) << 16)); | 1178 | s->rNToGo = 0; |
1179 | s->rTPos = 0; | ||
1180 | s->k0 = bz_get_fast(s); | ||
1316 | 1181 | ||
1317 | s->ll16[j] = (unsigned short)(i & 0x0000ffff); | 1182 | s->nblock_used++; |
1318 | if (((j) & 0x1) == 0) { | 1183 | bz_rand_udp_mask(s); |
1319 | s->ll4[(j) >> 1] = (s->ll4[(j) >> 1] & 0xf0) | (i >> 16); | 1184 | s->k0 ^= ((s->rNToGo == 1) ? 1 : 0); |
1320 | } else { | 1185 | } else { |
1321 | s->ll4[(j) >> 1] = (s->ll4[(j) >> 1] & 0x0f) | ((i >> 16) << 4); | 1186 | s->k0 = bz_get_fast(s); |
1322 | } | 1187 | s->nblock_used++; |
1323 | i = j; | 1188 | } |
1324 | j = tmp; | ||
1325 | } | ||
1326 | while (i != s->origPtr); | ||
1327 | s->tPos = s->origPtr; | ||
1328 | s->nblock_used = 0; | ||
1329 | if (s->blockRandomised) { | ||
1330 | s->rNToGo = 0; | ||
1331 | s->rTPos = 0; | ||
1332 | s->k0 = bz_get_small(s); | ||
1333 | s->nblock_used++; | ||
1334 | bz_rand_udp_mask(s); | ||
1335 | s->k0 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1336 | } else { | ||
1337 | s->k0 = bz_get_small(s); | ||
1338 | s->nblock_used++; | ||
1339 | } | ||
1340 | } else { | ||
1341 | /*-- compute the T^(-1) vector --*/ | ||
1342 | for (i = 0; i < nblock; i++) { | ||
1343 | uc = (unsigned char)(s->tt[i] & 0xff); | ||
1344 | s->tt[s->cftab[uc]] |= (i << 8); | ||
1345 | s->cftab[uc]++; | ||
1346 | } | ||
1347 | |||
1348 | s->tPos = s->tt[s->origPtr] >> 8; | ||
1349 | s->nblock_used = 0; | ||
1350 | if (s->blockRandomised) { | ||
1351 | s->rNToGo = 0; | ||
1352 | s->rTPos = 0; | ||
1353 | s->k0 = bz_get_fast(s); | ||
1354 | |||
1355 | s->nblock_used++; | ||
1356 | bz_rand_udp_mask(s); | ||
1357 | s->k0 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1358 | } else { | ||
1359 | s->k0 = bz_get_fast(s); | ||
1360 | s->nblock_used++; | ||
1361 | } | ||
1362 | } | ||
1363 | 1189 | ||
1364 | retVal = BZ_OK; | 1190 | retVal = BZ_OK; |
1365 | goto save_state_and_return; | 1191 | goto save_state_and_return; |
@@ -1456,13 +1282,8 @@ endhdr_2: | |||
1456 | retVal = BZ_STREAM_END; | 1282 | retVal = BZ_STREAM_END; |
1457 | goto save_state_and_return; | 1283 | goto save_state_and_return; |
1458 | 1284 | ||
1459 | default: | ||
1460 | printf("switch val is %d\n", switch_val); | ||
1461 | assert_h(4001); | ||
1462 | } | 1285 | } |
1463 | 1286 | ||
1464 | assert_h(4002); | ||
1465 | |||
1466 | save_state_and_return: | 1287 | save_state_and_return: |
1467 | s->save_i = i; | 1288 | s->save_i = i; |
1468 | s->save_j = j; | 1289 | s->save_j = j; |
@@ -1492,68 +1313,23 @@ save_state_and_return: | |||
1492 | return retVal; | 1313 | return retVal; |
1493 | } | 1314 | } |
1494 | 1315 | ||
1495 | static void *default_bzalloc(void *opaque, int items, int size) | ||
1496 | { | ||
1497 | void *v = xmalloc(items *size); | ||
1498 | return v; | ||
1499 | } | ||
1500 | |||
1501 | static void default_bzfree(void *opaque, void *addr) | ||
1502 | { | ||
1503 | if (addr != NULL) { | ||
1504 | free(addr); | ||
1505 | } | ||
1506 | } | ||
1507 | |||
1508 | //int BZ2_bzDecompressInit(bz_stream* strm, int verbosity_level, int small) | 1316 | //int BZ2_bzDecompressInit(bz_stream* strm, int verbosity_level, int small) |
1509 | int BZ2_bzDecompressInit(bz_stream* strm, int small) | 1317 | int BZ2_bzDecompressInit(bz_stream* strm) |
1510 | { | 1318 | { |
1511 | DState* s; | 1319 | DState* s; |
1512 | 1320 | ||
1513 | if (sizeof(int) != 4) { | ||
1514 | return BZ_CONFIG_ERROR; | ||
1515 | } | ||
1516 | if (sizeof(short) != 2) { | ||
1517 | return BZ_CONFIG_ERROR; | ||
1518 | } | ||
1519 | if (sizeof(char) != 1) { | ||
1520 | return BZ_CONFIG_ERROR; | ||
1521 | } | ||
1522 | if (strm == NULL) { | ||
1523 | return BZ_PARAM_ERROR; | ||
1524 | } | ||
1525 | if (small != 0 && small != 1) { | ||
1526 | return BZ_PARAM_ERROR; | ||
1527 | } | ||
1528 | // if (verbosity_level < 0 || verbosity_level > 4) { | 1321 | // if (verbosity_level < 0 || verbosity_level > 4) { |
1529 | // return BZ_PARAM_ERROR; | 1322 | // return BZ_PARAM_ERROR; |
1530 | // } | 1323 | // } |
1531 | if (strm->bzalloc == NULL) { | 1324 | s = xmalloc(sizeof(DState)); |
1532 | strm->bzalloc = default_bzalloc; | ||
1533 | } | ||
1534 | if (strm->bzfree == NULL) { | ||
1535 | strm->bzfree = default_bzfree; | ||
1536 | } | ||
1537 | s = (strm->bzalloc)(strm->opaque, sizeof(DState), 1); | ||
1538 | if (s == NULL) { | ||
1539 | return BZ_MEM_ERROR; | ||
1540 | } | ||
1541 | s->strm = strm; | 1325 | s->strm = strm; |
1542 | strm->state = s; | 1326 | strm->state = s; |
1543 | s->state = BZ_X_MAGIC_1; | 1327 | s->state = BZ_X_MAGIC_1; |
1544 | s->bsLive = 0; | 1328 | s->bsLive = 0; |
1545 | s->bsBuff = 0; | 1329 | s->bsBuff = 0; |
1546 | s->calculatedCombinedCRC = 0; | 1330 | s->calculatedCombinedCRC = 0; |
1547 | strm->total_in_lo32 = 0; | ||
1548 | strm->total_in_hi32 = 0; | ||
1549 | strm->total_out_lo32 = 0; | ||
1550 | strm->total_out_hi32 = 0; | ||
1551 | s->smallDecompress = (unsigned char)small; | ||
1552 | s->ll4 = NULL; | ||
1553 | s->ll16 = NULL; | ||
1554 | s->tt = NULL; | 1331 | s->tt = NULL; |
1555 | s->currBlockNo = 0; | 1332 | s->currBlockNo = 0; |
1556 | // s->verbosity = verbosity_level; | ||
1557 | 1333 | ||
1558 | return BZ_OK; | 1334 | return BZ_OK; |
1559 | } | 1335 | } |
@@ -1568,20 +1344,11 @@ void bz_seterr(int eee, int *bzerror, bzFile **bzf) | |||
1568 | } | 1344 | } |
1569 | } | 1345 | } |
1570 | 1346 | ||
1571 | void BZ2_bzReadClose(int *bzerror, void *b) | 1347 | static void BZ2_bzReadClose(int *bzerror, void *b) |
1572 | { | 1348 | { |
1573 | bzFile* bzf = (bzFile*)b; | 1349 | bzFile* bzf = (bzFile*)b; |
1574 | 1350 | ||
1575 | bz_seterr(BZ_OK, bzerror, &bzf); | 1351 | bz_seterr(BZ_OK, bzerror, &bzf); |
1576 | if (bzf == NULL) { | ||
1577 | bz_seterr(BZ_OK, bzerror, &bzf); | ||
1578 | return; | ||
1579 | } | ||
1580 | |||
1581 | if (bzf->writing) { | ||
1582 | bz_seterr(BZ_SEQUENCE_ERROR, bzerror, &bzf); | ||
1583 | return; | ||
1584 | } | ||
1585 | 1352 | ||
1586 | if (bzf->initialisedOk) { | 1353 | if (bzf->initialisedOk) { |
1587 | bz_stream *strm = &(bzf->strm); | 1354 | bz_stream *strm = &(bzf->strm); |
@@ -1593,16 +1360,8 @@ void BZ2_bzReadClose(int *bzerror, void *b) | |||
1593 | if ((s == NULL) || (s->strm != strm)) { | 1360 | if ((s == NULL) || (s->strm != strm)) { |
1594 | return; | 1361 | return; |
1595 | } | 1362 | } |
1596 | if (s->tt != NULL) { | 1363 | free(s->tt); |
1597 | (strm->bzfree)(strm->opaque,(s->tt)); | 1364 | free(strm->state); |
1598 | } | ||
1599 | if (s->ll16 != NULL) { | ||
1600 | (strm->bzfree)(strm->opaque,(s->ll16)); | ||
1601 | } | ||
1602 | if (s->ll4 != NULL) { | ||
1603 | (strm->bzfree)(strm->opaque,(s->ll4)); | ||
1604 | } | ||
1605 | (strm->bzfree)(strm->opaque,(strm->state)); | ||
1606 | strm->state = NULL; | 1365 | strm->state = NULL; |
1607 | return; | 1366 | return; |
1608 | } | 1367 | } |
@@ -1630,10 +1389,6 @@ static void unRLE_obuf_to_output_FAST(DState *s) | |||
1630 | s->state_out_len--; | 1389 | s->state_out_len--; |
1631 | s->strm->next_out++; | 1390 | s->strm->next_out++; |
1632 | s->strm->avail_out--; | 1391 | s->strm->avail_out--; |
1633 | s->strm->total_out_lo32++; | ||
1634 | if (s->strm->total_out_lo32 == 0) { | ||
1635 | s->strm->total_out_hi32++; | ||
1636 | } | ||
1637 | } | 1392 | } |
1638 | 1393 | ||
1639 | /* can a new run be started? */ | 1394 | /* can a new run be started? */ |
@@ -1702,9 +1457,7 @@ static void unRLE_obuf_to_output_FAST(DState *s) | |||
1702 | unsigned int cs_avail_out = s->strm->avail_out; | 1457 | unsigned int cs_avail_out = s->strm->avail_out; |
1703 | /* end restore */ | 1458 | /* end restore */ |
1704 | 1459 | ||
1705 | unsigned int avail_out_INIT = cs_avail_out; | ||
1706 | int s_save_nblockPP = s->save_nblock+1; | 1460 | int s_save_nblockPP = s->save_nblock+1; |
1707 | unsigned int total_out_lo32_old; | ||
1708 | 1461 | ||
1709 | while (1) { | 1462 | while (1) { |
1710 | /* try to finish existing run */ | 1463 | /* try to finish existing run */ |
@@ -1801,11 +1554,6 @@ s_state_out_len_eq_one: | |||
1801 | } | 1554 | } |
1802 | 1555 | ||
1803 | return_notr: | 1556 | return_notr: |
1804 | total_out_lo32_old = s->strm->total_out_lo32; | ||
1805 | s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out); | ||
1806 | if (s->strm->total_out_lo32 < total_out_lo32_old) { | ||
1807 | s->strm->total_out_hi32++; | ||
1808 | } | ||
1809 | 1557 | ||
1810 | /* save */ | 1558 | /* save */ |
1811 | s->calculatedBlockCRC = c_calculatedBlockCRC; | 1559 | s->calculatedBlockCRC = c_calculatedBlockCRC; |
@@ -1821,190 +1569,19 @@ return_notr: | |||
1821 | } | 1569 | } |
1822 | } | 1570 | } |
1823 | 1571 | ||
1824 | static void unRLE_obuf_to_output_SMALL(DState *s) | ||
1825 | { | ||
1826 | unsigned char k1; | ||
1827 | |||
1828 | if (s->blockRandomised) { | ||
1829 | while (1) { | ||
1830 | /* try to finish existing run */ | ||
1831 | while (1) { | ||
1832 | if (s->strm->avail_out == 0) { | ||
1833 | return; | ||
1834 | } | ||
1835 | if (s->state_out_len == 0) { | ||
1836 | break; | ||
1837 | } | ||
1838 | *((unsigned char *)(s->strm->next_out)) = s->state_out_ch; | ||
1839 | s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^ | ||
1840 | BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^ | ||
1841 | ((unsigned char)s->state_out_ch)]; | ||
1842 | s->state_out_len--; | ||
1843 | s->strm->next_out++; | ||
1844 | s->strm->avail_out--; | ||
1845 | s->strm->total_out_lo32++; | ||
1846 | if (s->strm->total_out_lo32 == 0) { | ||
1847 | s->strm->total_out_hi32++; | ||
1848 | } | ||
1849 | } | ||
1850 | |||
1851 | /* can a new run be started? */ | ||
1852 | if (s->nblock_used == s->save_nblock+1) { | ||
1853 | return; | ||
1854 | } | ||
1855 | |||
1856 | s->state_out_len = 1; | ||
1857 | s->state_out_ch = s->k0; | ||
1858 | k1 = bz_get_small(s); | ||
1859 | bz_rand_udp_mask(s); | ||
1860 | k1 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1861 | s->nblock_used++; | ||
1862 | if (s->nblock_used == s->save_nblock+1) { | ||
1863 | continue; | ||
1864 | } | ||
1865 | if (k1 != s->k0) { | ||
1866 | s->k0 = k1; | ||
1867 | continue; | ||
1868 | } | ||
1869 | |||
1870 | s->state_out_len = 2; | ||
1871 | k1 = bz_get_small(s); | ||
1872 | bz_rand_udp_mask(s); | ||
1873 | k1 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1874 | s->nblock_used++; | ||
1875 | if (s->nblock_used == s->save_nblock+1) { | ||
1876 | continue; | ||
1877 | } | ||
1878 | if (k1 != s->k0) { | ||
1879 | s->k0 = k1; | ||
1880 | continue; | ||
1881 | } | ||
1882 | |||
1883 | s->state_out_len = 3; | ||
1884 | k1 = bz_get_small(s); | ||
1885 | bz_rand_udp_mask(s); | ||
1886 | k1 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1887 | s->nblock_used++; | ||
1888 | if (s->nblock_used == s->save_nblock+1) { | ||
1889 | continue; | ||
1890 | } | ||
1891 | if (k1 != s->k0) { | ||
1892 | s->k0 = k1; | ||
1893 | continue; | ||
1894 | } | ||
1895 | k1 = bz_get_small(s); | ||
1896 | bz_rand_udp_mask(s); | ||
1897 | k1 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1898 | s->nblock_used++; | ||
1899 | s->state_out_len = ((int)k1) + 4; | ||
1900 | s->k0 = bz_get_small(s); | ||
1901 | bz_rand_udp_mask(s); | ||
1902 | s->k0 ^= ((s->rNToGo == 1) ? 1 : 0); | ||
1903 | s->nblock_used++; | ||
1904 | } | ||
1905 | } else { | ||
1906 | while (1) { | ||
1907 | /* try to finish existing run */ | ||
1908 | while (1) { | ||
1909 | if (s->strm->avail_out == 0) { | ||
1910 | return; | ||
1911 | } | ||
1912 | if (s->state_out_len == 0) { | ||
1913 | break; | ||
1914 | } | ||
1915 | *((unsigned char *)(s->strm->next_out)) = s->state_out_ch; | ||
1916 | s->calculatedBlockCRC = (s->calculatedBlockCRC << 8) ^ | ||
1917 | BZ2_crc32Table[(s->calculatedBlockCRC >> 24) ^ | ||
1918 | ((unsigned char)s->state_out_ch)]; | ||
1919 | s->state_out_len--; | ||
1920 | s->strm->next_out++; | ||
1921 | s->strm->avail_out--; | ||
1922 | s->strm->total_out_lo32++; | ||
1923 | if (s->strm->total_out_lo32 == 0) { | ||
1924 | s->strm->total_out_hi32++; | ||
1925 | } | ||
1926 | } | ||
1927 | |||
1928 | /* can a new run be started? */ | ||
1929 | if (s->nblock_used == s->save_nblock+1) { | ||
1930 | return; | ||
1931 | } | ||
1932 | |||
1933 | s->state_out_len = 1; | ||
1934 | s->state_out_ch = s->k0; | ||
1935 | k1 = bz_get_small(s); | ||
1936 | s->nblock_used++; | ||
1937 | if (s->nblock_used == s->save_nblock+1) { | ||
1938 | continue; | ||
1939 | } | ||
1940 | if (k1 != s->k0) { | ||
1941 | s->k0 = k1; | ||
1942 | continue; | ||
1943 | } | ||
1944 | |||
1945 | s->state_out_len = 2; | ||
1946 | k1 = bz_get_small(s); | ||
1947 | s->nblock_used++; | ||
1948 | if (s->nblock_used == s->save_nblock+1) { | ||
1949 | continue; | ||
1950 | } | ||
1951 | if (k1 != s->k0) { | ||
1952 | s->k0 = k1; | ||
1953 | continue; | ||
1954 | } | ||
1955 | |||
1956 | s->state_out_len = 3; | ||
1957 | k1 = bz_get_small(s); | ||
1958 | s->nblock_used++; | ||
1959 | if (s->nblock_used == s->save_nblock+1) { | ||
1960 | continue; | ||
1961 | } | ||
1962 | if (k1 != s->k0) { | ||
1963 | s->k0 = k1; | ||
1964 | continue; | ||
1965 | } | ||
1966 | |||
1967 | k1 = bz_get_small(s); | ||
1968 | s->nblock_used++; | ||
1969 | s->state_out_len = ((int)k1) + 4; | ||
1970 | s->k0 = bz_get_small(s); | ||
1971 | s->nblock_used++; | ||
1972 | } | ||
1973 | } | ||
1974 | } | ||
1975 | |||
1976 | int BZ2_bzDecompress(bz_stream *strm) | 1572 | int BZ2_bzDecompress(bz_stream *strm) |
1977 | { | 1573 | { |
1978 | DState* s; | 1574 | DState* s; |
1979 | if (strm == NULL) { | ||
1980 | return BZ_PARAM_ERROR; | ||
1981 | } | ||
1982 | s = strm->state; | 1575 | s = strm->state; |
1983 | if (s == NULL) { | ||
1984 | return BZ_PARAM_ERROR; | ||
1985 | } | ||
1986 | if (s->strm != strm) { | ||
1987 | return BZ_PARAM_ERROR; | ||
1988 | } | ||
1989 | 1576 | ||
1990 | while (1) { | 1577 | while (1) { |
1991 | if (s->state == BZ_X_IDLE) { | 1578 | if (s->state == BZ_X_IDLE) { |
1992 | return BZ_SEQUENCE_ERROR; | 1579 | return BZ_SEQUENCE_ERROR; |
1993 | } | 1580 | } |
1994 | if (s->state == BZ_X_OUTPUT) { | 1581 | if (s->state == BZ_X_OUTPUT) { |
1995 | if (s->smallDecompress) { | 1582 | unRLE_obuf_to_output_FAST(s); |
1996 | unRLE_obuf_to_output_SMALL(s); | ||
1997 | } else { | ||
1998 | unRLE_obuf_to_output_FAST(s); | ||
1999 | } | ||
2000 | if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) { | 1583 | if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) { |
2001 | s->calculatedBlockCRC = ~(s->calculatedBlockCRC); | 1584 | s->calculatedBlockCRC = ~(s->calculatedBlockCRC); |
2002 | if (s->verbosity >= 3) { | ||
2003 | error_msg("{0x%x, 0x%x}", s->storedBlockCRC, s->calculatedBlockCRC); | ||
2004 | } | ||
2005 | if (s->verbosity >= 2) { | ||
2006 | error_msg("]"); | ||
2007 | } | ||
2008 | if (s->calculatedBlockCRC != s->storedBlockCRC) { | 1585 | if (s->calculatedBlockCRC != s->storedBlockCRC) { |
2009 | return BZ_DATA_ERROR; | 1586 | return BZ_DATA_ERROR; |
2010 | } | 1587 | } |
@@ -2018,10 +1595,6 @@ int BZ2_bzDecompress(bz_stream *strm) | |||
2018 | if (s->state >= BZ_X_MAGIC_1) { | 1595 | if (s->state >= BZ_X_MAGIC_1) { |
2019 | int r = BZ2_decompress(s); | 1596 | int r = BZ2_decompress(s); |
2020 | if (r == BZ_STREAM_END) { | 1597 | if (r == BZ_STREAM_END) { |
2021 | if (s->verbosity >= 3) { | ||
2022 | error_msg("\n combined CRCs: stored = 0x%x, computed = 0x%x", | ||
2023 | s->storedCombinedCRC, s->calculatedCombinedCRC ); | ||
2024 | } | ||
2025 | if (s->calculatedCombinedCRC != s->storedCombinedCRC) { | 1598 | if (s->calculatedCombinedCRC != s->storedCombinedCRC) { |
2026 | return BZ_DATA_ERROR; | 1599 | return BZ_DATA_ERROR; |
2027 | } | 1600 | } |
@@ -2033,8 +1606,6 @@ int BZ2_bzDecompress(bz_stream *strm) | |||
2033 | } | 1606 | } |
2034 | } | 1607 | } |
2035 | 1608 | ||
2036 | assert_h(6001); | ||
2037 | |||
2038 | return(0); /*NOTREACHED*/ | 1609 | return(0); /*NOTREACHED*/ |
2039 | } | 1610 | } |
2040 | 1611 | ||
@@ -2045,16 +1616,6 @@ int BZ2_bzRead(int *bzerror, void *b, void *buf, int len) | |||
2045 | 1616 | ||
2046 | bz_seterr(BZ_OK, bzerror, &bzf); | 1617 | bz_seterr(BZ_OK, bzerror, &bzf); |
2047 | 1618 | ||
2048 | if (bzf == NULL || buf == NULL || len < 0) { | ||
2049 | bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf); | ||
2050 | return 0; | ||
2051 | } | ||
2052 | |||
2053 | if (bzf->writing) { | ||
2054 | bz_seterr(BZ_SEQUENCE_ERROR, bzerror, &bzf); | ||
2055 | return 0; | ||
2056 | } | ||
2057 | |||
2058 | if (len == 0) { | 1619 | if (len == 0) { |
2059 | bz_seterr(BZ_OK, bzerror, &bzf); | 1620 | bz_seterr(BZ_OK, bzerror, &bzf); |
2060 | return 0; | 1621 | return 0; |
@@ -2104,75 +1665,29 @@ int BZ2_bzRead(int *bzerror, void *b, void *buf, int len) | |||
2104 | return(0); /*not reached*/ | 1665 | return(0); /*not reached*/ |
2105 | } | 1666 | } |
2106 | 1667 | ||
2107 | void BZ2_bzReadGetUnused(int *bzerror, void *b, void **unused, int *nUnused) | 1668 | void *BZ2_bzReadOpen(int *bzerror, FILE *f, void *unused, int nUnused) |
2108 | { | ||
2109 | bzFile *bzf = (bzFile*)b; | ||
2110 | if (bzf == NULL) { | ||
2111 | bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf); | ||
2112 | return; | ||
2113 | } | ||
2114 | if (bzf->lastErr != BZ_STREAM_END) { | ||
2115 | bz_seterr(BZ_SEQUENCE_ERROR, bzerror, &bzf); | ||
2116 | return; | ||
2117 | } | ||
2118 | if (unused == NULL || nUnused == NULL) { | ||
2119 | bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf); | ||
2120 | return; | ||
2121 | } | ||
2122 | |||
2123 | bz_seterr(BZ_OK, bzerror, &bzf); | ||
2124 | *nUnused = bzf->strm.avail_in; | ||
2125 | *unused = bzf->strm.next_in; | ||
2126 | } | ||
2127 | |||
2128 | void *BZ2_bzReadOpen(int *bzerror, FILE *f, int small, void *unused, int nUnused) | ||
2129 | { | 1669 | { |
2130 | bzFile *bzf = NULL; | 1670 | bzFile *bzf = xmalloc(sizeof(bzFile)); |
2131 | int ret; | 1671 | int ret; |
2132 | 1672 | ||
2133 | bz_seterr(BZ_OK, bzerror, &bzf); | 1673 | bz_seterr(BZ_OK, bzerror, &bzf); |
2134 | 1674 | ||
2135 | if (f == NULL || (small != 0 && small != 1) || | ||
2136 | (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)) || | ||
2137 | // (verbosity_level < 0 || verbosity_level > 4) || | ||
2138 | (unused == NULL && nUnused != 0)) { | ||
2139 | bz_seterr(BZ_PARAM_ERROR, bzerror, &bzf); | ||
2140 | return NULL; | ||
2141 | } | ||
2142 | |||
2143 | if (ferror(f)) { | ||
2144 | bz_seterr(BZ_IO_ERROR, bzerror, &bzf); | ||
2145 | return NULL; | ||
2146 | } | ||
2147 | |||
2148 | bzf = xmalloc(sizeof(bzFile)); | ||
2149 | if (bzf == NULL) { | ||
2150 | bz_seterr(BZ_MEM_ERROR, bzerror, &bzf); | ||
2151 | return NULL; | ||
2152 | } | ||
2153 | bz_seterr(BZ_OK, bzerror, &bzf); | ||
2154 | |||
2155 | bzf->initialisedOk = FALSE; | 1675 | bzf->initialisedOk = FALSE; |
2156 | bzf->handle = f; | 1676 | bzf->handle = f; |
2157 | bzf->bufN = 0; | 1677 | bzf->bufN = 0; |
2158 | bzf->writing = FALSE; | ||
2159 | bzf->strm.bzalloc = NULL; | ||
2160 | bzf->strm.bzfree = NULL; | ||
2161 | bzf->strm.opaque = NULL; | ||
2162 | |||
2163 | while (nUnused > 0) { | ||
2164 | bzf->buf[bzf->bufN] = *((unsigned char *)(unused)); bzf->bufN++; | ||
2165 | unused = ((void *)( 1 + ((unsigned char *)(unused)) )); | ||
2166 | nUnused--; | ||
2167 | } | ||
2168 | 1678 | ||
2169 | ret = BZ2_bzDecompressInit(&(bzf->strm), small); | 1679 | ret = BZ2_bzDecompressInit(&(bzf->strm)); |
2170 | if (ret != BZ_OK) { | 1680 | if (ret != BZ_OK) { |
2171 | bz_seterr(ret, bzerror, &bzf); | 1681 | bz_seterr(ret, bzerror, &bzf); |
2172 | free(bzf); | 1682 | free(bzf); |
2173 | return NULL; | 1683 | return NULL; |
2174 | } | 1684 | } |
2175 | 1685 | ||
1686 | while (nUnused > 0) { | ||
1687 | bzf->buf[bzf->bufN] = *((unsigned char *)(unused)); bzf->bufN++; | ||
1688 | unused = ((void *)( 1 + ((unsigned char *)(unused)) )); | ||
1689 | nUnused--; | ||
1690 | } | ||
2176 | bzf->strm.avail_in = bzf->bufN; | 1691 | bzf->strm.avail_in = bzf->bufN; |
2177 | bzf->strm.next_in = bzf->buf; | 1692 | bzf->strm.next_in = bzf->buf; |
2178 | 1693 | ||
@@ -2185,7 +1700,7 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream) | |||
2185 | unsigned char unused[BZ_MAX_UNUSED]; | 1700 | unsigned char unused[BZ_MAX_UNUSED]; |
2186 | unsigned char *unusedTmp; | 1701 | unsigned char *unusedTmp; |
2187 | unsigned char obuf[5000]; | 1702 | unsigned char obuf[5000]; |
2188 | void *bzf = NULL; | 1703 | bzFile *bzf = NULL; |
2189 | int bzerr_dummy; | 1704 | int bzerr_dummy; |
2190 | int bzerr; | 1705 | int bzerr; |
2191 | int nread; | 1706 | int nread; |
@@ -2205,7 +1720,7 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream) | |||
2205 | } | 1720 | } |
2206 | 1721 | ||
2207 | while(1) { | 1722 | while(1) { |
2208 | bzf = BZ2_bzReadOpen(&bzerr, zStream, (int)smallMode, unused, nUnused); | 1723 | bzf = BZ2_bzReadOpen(&bzerr, zStream, unused, nUnused); |
2209 | if (bzf == NULL || bzerr != BZ_OK) { | 1724 | if (bzf == NULL || bzerr != BZ_OK) { |
2210 | goto errhandler; | 1725 | goto errhandler; |
2211 | } | 1726 | } |
@@ -2226,17 +1741,13 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream) | |||
2226 | if (bzerr != BZ_STREAM_END) { | 1741 | if (bzerr != BZ_STREAM_END) { |
2227 | goto errhandler; | 1742 | goto errhandler; |
2228 | } | 1743 | } |
2229 | BZ2_bzReadGetUnused(&bzerr, bzf, (void **)(&unusedTmp), &nUnused); | 1744 | nUnused = bzf->strm.avail_in; |
2230 | if (bzerr != BZ_OK) { | 1745 | unusedTmp = bzf->strm.next_in; |
2231 | panic("decompress:bzReadGetUnused"); | 1746 | bz_seterr(BZ_OK, &bzerr, &bzf); |
2232 | } | ||
2233 | for (i = 0; i < nUnused; i++) { | 1747 | for (i = 0; i < nUnused; i++) { |
2234 | unused[i] = unusedTmp[i]; | 1748 | unused[i] = unusedTmp[i]; |
2235 | } | 1749 | } |
2236 | BZ2_bzReadClose(&bzerr, bzf); | 1750 | BZ2_bzReadClose(&bzerr, bzf); |
2237 | if (bzerr != BZ_OK) { | ||
2238 | panic("decompress:bzReadGetUnused"); | ||
2239 | } | ||
2240 | if ((nUnused == 0) && myfeof(zStream)) { | 1751 | if ((nUnused == 0) && myfeof(zStream)) { |
2241 | break; | 1752 | break; |
2242 | } | 1753 | } |
@@ -2262,37 +1773,24 @@ static unsigned char uncompressStream(FILE *zStream, FILE *stream) | |||
2262 | goto errhandler_io; | 1773 | goto errhandler_io; |
2263 | } | 1774 | } |
2264 | } | 1775 | } |
2265 | // if (verbosity_level >= 2) { | ||
2266 | // fprintf(stderr,"\n "); | ||
2267 | // } | ||
2268 | return TRUE; | 1776 | return TRUE; |
2269 | 1777 | ||
2270 | errhandler: | 1778 | errhandler: |
2271 | BZ2_bzReadClose ( &bzerr_dummy, bzf ); | 1779 | BZ2_bzReadClose ( &bzerr_dummy, bzf ); |
2272 | switch (bzerr) { | 1780 | switch (bzerr) { |
2273 | case BZ_CONFIG_ERROR: | ||
2274 | error_msg("bzip2: I'm not configured correctly for this platform!\n" | ||
2275 | "\tI require Int32, Int16 and Char to have sizes\n" | ||
2276 | "\tof 4, 2 and 1 bytes to run properly, and they don't.\n" | ||
2277 | "\tProbably you can fix this by defining them correctly,\n" | ||
2278 | "\tand recompiling. Bye!\n" ); | ||
2279 | exit(3); | ||
2280 | case BZ_IO_ERROR: | 1781 | case BZ_IO_ERROR: |
2281 | errhandler_io: | 1782 | errhandler_io: |
2282 | error_msg("\n%s: I/O or other error, bailing out. " | 1783 | error_msg("\n%s: I/O or other error, bailing out. " |
2283 | "Possible reason follows.\n", progName); | 1784 | "Possible reason follows.\n", applet_name); |
2284 | perror(progName); | 1785 | perror(applet_name); |
2285 | cleanUpAndFail(1); | 1786 | cleanUpAndFail(1); |
2286 | case BZ_DATA_ERROR: | 1787 | case BZ_DATA_ERROR: |
2287 | error_msg("\n%s: Data integrity error when decompressing.\n", progName); | 1788 | error_msg("\n%s: Data integrity error when decompressing.\n", applet_name); |
2288 | cleanUpAndFail(2); | 1789 | cleanUpAndFail(2); |
2289 | case BZ_MEM_ERROR: | ||
2290 | error_msg("\n%s: couldn't allocate enough memory\n", progName); | ||
2291 | cleanUpAndFail(1); | ||
2292 | case BZ_UNEXPECTED_EOF: | 1790 | case BZ_UNEXPECTED_EOF: |
2293 | error_msg("\n%s: Compressed file ends unexpectedly;\n\t" | 1791 | error_msg("\n%s: Compressed file ends unexpectedly;\n\t" |
2294 | "perhaps it is corrupted? *Possible* reason follows.\n", progName); | 1792 | "perhaps it is corrupted? *Possible* reason follows.\n", applet_name); |
2295 | perror(progName); | 1793 | perror(applet_name); |
2296 | cleanUpAndFail(2); | 1794 | cleanUpAndFail(2); |
2297 | case BZ_DATA_ERROR_MAGIC: | 1795 | case BZ_DATA_ERROR_MAGIC: |
2298 | if (zStream != stdin) { | 1796 | if (zStream != stdin) { |
@@ -2304,16 +1802,10 @@ errhandler_io: | |||
2304 | if (streamNo == 1) { | 1802 | if (streamNo == 1) { |
2305 | return FALSE; | 1803 | return FALSE; |
2306 | } else { | 1804 | } else { |
2307 | if (noisy) { | 1805 | return TRUE; |
2308 | error_msg("\n%s: %s: trailing garbage after EOF ignored\n", progName, inName ); | ||
2309 | } | ||
2310 | return TRUE; | ||
2311 | } | 1806 | } |
2312 | default: | ||
2313 | panic ( "decompress:unexpected error" ); | ||
2314 | } | 1807 | } |
2315 | 1808 | ||
2316 | panic("decompress:end"); | ||
2317 | return(TRUE); /*notreached*/ | 1809 | return(TRUE); /*notreached*/ |
2318 | } | 1810 | } |
2319 | 1811 | ||