diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-06 16:52:50 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-06 16:52:50 +0200 |
| commit | 386bc9fda3fed545a6b78cd2e1c536b2bf98ea24 (patch) | |
| tree | 7caece9f7c56eb5612cdd3557328e1d8d3a0801f | |
| parent | 043b1e5d997d9b582a5aee37bd56e2e4f29be6e4 (diff) | |
| download | busybox-w32-386bc9fda3fed545a6b78cd2e1c536b2bf98ea24.tar.gz busybox-w32-386bc9fda3fed545a6b78cd2e1c536b2bf98ea24.tar.bz2 busybox-w32-386bc9fda3fed545a6b78cd2e1c536b2bf98ea24.zip | |
unzip: more compat if DESKTOP=y
function old new delta
DESKTOP off:
unzip_main 1648 1629 -19
DESKTOP=y:
unzip_main 1939 2197 +258
Without this, midnight commander can't display .zip files
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | archival/unzip.c | 147 |
1 files changed, 118 insertions, 29 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 4201d1dd2..afab3280d 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
| @@ -253,14 +253,16 @@ int unzip_main(int argc, char **argv) | |||
| 253 | enum { O_PROMPT, O_NEVER, O_ALWAYS }; | 253 | enum { O_PROMPT, O_NEVER, O_ALWAYS }; |
| 254 | 254 | ||
| 255 | zip_header_t zip_header; | 255 | zip_header_t zip_header; |
| 256 | smallint verbose = 1; | 256 | smallint quiet = 0; |
| 257 | IF_NOT_DESKTOP(const) smallint verbose = 0; | ||
| 257 | smallint listing = 0; | 258 | smallint listing = 0; |
| 258 | smallint overwrite = O_PROMPT; | 259 | smallint overwrite = O_PROMPT; |
| 259 | #if ENABLE_DESKTOP | 260 | #if ENABLE_DESKTOP |
| 260 | uint32_t cds_offset; | 261 | uint32_t cds_offset; |
| 261 | unsigned cds_entries; | 262 | unsigned cds_entries; |
| 262 | #endif | 263 | #endif |
| 263 | unsigned total_size; | 264 | unsigned long total_usize; |
| 265 | unsigned long total_size; | ||
| 264 | unsigned total_entries; | 266 | unsigned total_entries; |
| 265 | int dst_fd = -1; | 267 | int dst_fd = -1; |
| 266 | char *src_fn = NULL; | 268 | char *src_fn = NULL; |
| @@ -273,8 +275,49 @@ int unzip_main(int argc, char **argv) | |||
| 273 | char key_buf[80]; | 275 | char key_buf[80]; |
| 274 | struct stat stat_buf; | 276 | struct stat stat_buf; |
| 275 | 277 | ||
| 278 | /* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP: | ||
| 279 | * | ||
| 280 | * # /usr/bin/unzip -qq -v decompress_unlzma.i.zip | ||
| 281 | * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i | ||
| 282 | * # /usr/bin/unzip -q -v decompress_unlzma.i.zip | ||
| 283 | * Length Method Size Ratio Date Time CRC-32 Name | ||
| 284 | * -------- ------ ------- ----- ---- ---- ------ ---- | ||
| 285 | * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i | ||
| 286 | * -------- ------- --- ------- | ||
| 287 | * 204372 35278 83% 1 file | ||
| 288 | * # /usr/bin/unzip -v decompress_unlzma.i.zip | ||
| 289 | * Archive: decompress_unlzma.i.zip | ||
| 290 | * Length Method Size Ratio Date Time CRC-32 Name | ||
| 291 | * -------- ------ ------- ----- ---- ---- ------ ---- | ||
| 292 | * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i | ||
| 293 | * -------- ------- --- ------- | ||
| 294 | * 204372 35278 83% 1 file | ||
| 295 | * # unzip -v decompress_unlzma.i.zip | ||
| 296 | * Archive: decompress_unlzma.i.zip | ||
| 297 | * Length Date Time Name | ||
| 298 | * -------- ---- ---- ---- | ||
| 299 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
| 300 | * -------- ------- | ||
| 301 | * 204372 1 files | ||
| 302 | * # /usr/bin/unzip -l -qq decompress_unlzma.i.zip | ||
| 303 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
| 304 | * # /usr/bin/unzip -l -q decompress_unlzma.i.zip | ||
| 305 | * Length Date Time Name | ||
| 306 | * -------- ---- ---- ---- | ||
| 307 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
| 308 | * -------- ------- | ||
| 309 | * 204372 1 file | ||
| 310 | * # /usr/bin/unzip -l decompress_unlzma.i.zip | ||
| 311 | * Archive: decompress_unlzma.i.zip | ||
| 312 | * Length Date Time Name | ||
| 313 | * -------- ---- ---- ---- | ||
| 314 | * 204372 09-06-09 14:23 decompress_unlzma.i | ||
| 315 | * -------- ------- | ||
| 316 | * 204372 1 file | ||
| 317 | */ | ||
| 318 | |||
| 276 | /* '-' makes getopt return 1 for non-options */ | 319 | /* '-' makes getopt return 1 for non-options */ |
| 277 | while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) { | 320 | while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) { |
| 278 | switch (opt_range) { | 321 | switch (opt_range) { |
| 279 | case 0: /* Options */ | 322 | case 0: /* Options */ |
| 280 | switch (opt) { | 323 | switch (opt) { |
| @@ -294,7 +337,12 @@ int unzip_main(int argc, char **argv) | |||
| 294 | dst_fd = STDOUT_FILENO; | 337 | dst_fd = STDOUT_FILENO; |
| 295 | 338 | ||
| 296 | case 'q': /* Be quiet */ | 339 | case 'q': /* Be quiet */ |
| 297 | verbose = 0; | 340 | quiet++; |
| 341 | break; | ||
| 342 | |||
| 343 | case 'v': /* Verbose list */ | ||
| 344 | IF_DESKTOP(verbose++;) | ||
| 345 | listing = 1; | ||
| 298 | break; | 346 | break; |
| 299 | 347 | ||
| 300 | case 1: /* The zip file */ | 348 | case 1: /* The zip file */ |
| @@ -373,14 +421,21 @@ int unzip_main(int argc, char **argv) | |||
| 373 | if (base_dir) | 421 | if (base_dir) |
| 374 | xchdir(base_dir); | 422 | xchdir(base_dir); |
| 375 | 423 | ||
| 376 | if (verbose) { | 424 | if (quiet <= 1) { /* not -qq */ |
| 377 | printf("Archive: %s\n", src_fn); | 425 | if (quiet == 0) |
| 378 | if (listing){ | 426 | printf("Archive: %s\n", src_fn); |
| 379 | puts(" Length Date Time Name\n" | 427 | if (listing) { |
| 380 | " -------- ---- ---- ----"); | 428 | puts(verbose ? |
| 429 | " Length Method Size Ratio Date Time CRC-32 Name\n" | ||
| 430 | "-------- ------ ------- ----- ---- ---- ------ ----" | ||
| 431 | : | ||
| 432 | " Length Date Time Name\n" | ||
| 433 | " -------- ---- ---- ----" | ||
| 434 | ); | ||
| 381 | } | 435 | } |
| 382 | } | 436 | } |
| 383 | 437 | ||
| 438 | total_usize = 0; | ||
| 384 | total_size = 0; | 439 | total_size = 0; |
| 385 | total_entries = 0; | 440 | total_entries = 0; |
| 386 | #if ENABLE_DESKTOP | 441 | #if ENABLE_DESKTOP |
| @@ -449,20 +504,39 @@ int unzip_main(int argc, char **argv) | |||
| 449 | 504 | ||
| 450 | } else { /* Extract entry */ | 505 | } else { /* Extract entry */ |
| 451 | if (listing) { /* List entry */ | 506 | if (listing) { /* List entry */ |
| 452 | if (verbose) { | 507 | unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); |
| 453 | unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); | 508 | if (!verbose) { |
| 454 | printf("%9u %02u-%02u-%02u %02u:%02u %s\n", | 509 | // " Length Date Time Name\n" |
| 455 | zip_header.formatted.ucmpsize, | 510 | // " -------- ---- ---- ----" |
| 456 | (dostime & 0x01e00000) >> 21, | 511 | printf( "%9u %02u-%02u-%02u %02u:%02u %s\n", |
| 457 | (dostime & 0x001f0000) >> 16, | 512 | (unsigned)zip_header.formatted.ucmpsize, |
| 458 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, | 513 | (dostime & 0x01e00000) >> 21, |
| 459 | (dostime & 0x0000f800) >> 11, | 514 | (dostime & 0x001f0000) >> 16, |
| 460 | (dostime & 0x000007e0) >> 5, | 515 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, |
| 461 | dst_fn); | 516 | (dostime & 0x0000f800) >> 11, |
| 462 | total_size += zip_header.formatted.ucmpsize; | 517 | (dostime & 0x000007e0) >> 5, |
| 518 | dst_fn); | ||
| 519 | total_usize += zip_header.formatted.ucmpsize; | ||
| 463 | } else { | 520 | } else { |
| 464 | /* short listing -- filenames only */ | 521 | unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; |
| 465 | puts(dst_fn); | 522 | percents = percents * 100; |
| 523 | if (zip_header.formatted.ucmpsize) | ||
| 524 | percents /= zip_header.formatted.ucmpsize; | ||
| 525 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | ||
| 526 | // "-------- ------ ------- ----- ---- ---- ------ ----" | ||
| 527 | printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", | ||
| 528 | (unsigned)zip_header.formatted.ucmpsize, | ||
| 529 | (unsigned)zip_header.formatted.cmpsize, | ||
| 530 | (unsigned)percents, | ||
| 531 | (dostime & 0x01e00000) >> 21, | ||
| 532 | (dostime & 0x001f0000) >> 16, | ||
| 533 | (((dostime & 0xfe000000) >> 25) + 1980) % 100, | ||
| 534 | (dostime & 0x0000f800) >> 11, | ||
| 535 | (dostime & 0x000007e0) >> 5, | ||
| 536 | zip_header.formatted.crc32, | ||
| 537 | dst_fn); | ||
| 538 | total_usize += zip_header.formatted.ucmpsize; | ||
| 539 | total_size += zip_header.formatted.cmpsize; | ||
| 466 | } | 540 | } |
| 467 | i = 'n'; | 541 | i = 'n'; |
| 468 | } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ | 542 | } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ |
| @@ -472,7 +546,7 @@ int unzip_main(int argc, char **argv) | |||
| 472 | if (errno != ENOENT) { | 546 | if (errno != ENOENT) { |
| 473 | bb_perror_msg_and_die("can't stat '%s'", dst_fn); | 547 | bb_perror_msg_and_die("can't stat '%s'", dst_fn); |
| 474 | } | 548 | } |
| 475 | if (verbose) { | 549 | if (!quiet) { |
| 476 | printf(" creating: %s\n", dst_fn); | 550 | printf(" creating: %s\n", dst_fn); |
| 477 | } | 551 | } |
| 478 | unzip_create_leading_dirs(dst_fn); | 552 | unzip_create_leading_dirs(dst_fn); |
| @@ -520,7 +594,7 @@ int unzip_main(int argc, char **argv) | |||
| 520 | unzip_create_leading_dirs(dst_fn); | 594 | unzip_create_leading_dirs(dst_fn); |
| 521 | dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); | 595 | dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); |
| 522 | case -1: /* Unzip */ | 596 | case -1: /* Unzip */ |
| 523 | if (verbose) { | 597 | if (!quiet) { |
| 524 | printf(" inflating: %s\n", dst_fn); | 598 | printf(" inflating: %s\n", dst_fn); |
| 525 | } | 599 | } |
| 526 | unzip_extract(&zip_header, dst_fd); | 600 | unzip_extract(&zip_header, dst_fd); |
| @@ -549,17 +623,32 @@ int unzip_main(int argc, char **argv) | |||
| 549 | goto check_file; | 623 | goto check_file; |
| 550 | 624 | ||
| 551 | default: | 625 | default: |
| 552 | printf("error: invalid response [%c]\n",(char)i); | 626 | printf("error: invalid response [%c]\n", (char)i); |
| 553 | goto check_file; | 627 | goto check_file; |
| 554 | } | 628 | } |
| 555 | 629 | ||
| 556 | total_entries++; | 630 | total_entries++; |
| 557 | } | 631 | } |
| 558 | 632 | ||
| 559 | if (listing && verbose) { | 633 | if (listing && quiet <= 1) { |
| 560 | printf(" -------- -------\n" | 634 | if (!verbose) { |
| 561 | "%9d %d files\n", | 635 | // " Length Date Time Name\n" |
| 562 | total_size, total_entries); | 636 | // " -------- ---- ---- ----" |
| 637 | printf( " -------- -------\n" | ||
| 638 | "%9lu" " %u files\n", | ||
| 639 | total_usize, total_entries); | ||
| 640 | } else { | ||
| 641 | unsigned long percents = total_usize - total_size; | ||
| 642 | percents = percents * 100; | ||
| 643 | if (total_usize) | ||
| 644 | percents /= total_usize; | ||
| 645 | // " Length Method Size Ratio Date Time CRC-32 Name\n" | ||
| 646 | // "-------- ------ ------- ----- ---- ---- ------ ----" | ||
| 647 | printf( "-------- ------- --- -------\n" | ||
| 648 | "%8lu" "%17lu%4u%% %u files\n", | ||
| 649 | total_usize, total_size, (unsigned)percents, | ||
| 650 | total_entries); | ||
| 651 | } | ||
| 563 | } | 652 | } |
| 564 | 653 | ||
| 565 | return 0; | 654 | return 0; |
