diff options
author | Denys Vlasenko | 2009-09-07 12:44:56 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-09-07 12:44:56 +0200 |
commit | 40c221334fca24acca35f372aef18c0c768c86cc (patch) | |
tree | a6e11e6bb521c04875b01486f6d2aabdc4896939 | |
parent | 3de3f57c6d0200b49a5e31e80421e36272035e15 (diff) | |
parent | 0c6914e50c913b54632b7279dbe3544ca7e633d0 (diff) | |
download | busybox-40c221334fca24acca35f372aef18c0c768c86cc.zip busybox-40c221334fca24acca35f372aef18c0c768c86cc.tar.gz |
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
-rw-r--r-- | archival/unzip.c | 147 | ||||
-rw-r--r-- | include/usage.h | 17 | ||||
-rw-r--r-- | modutils/modprobe-small.c | 39 |
3 files changed, 155 insertions, 48 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 4201d1d..afab328 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -253,14 +253,16 @@ int unzip_main(int argc, char **argv) enum { O_PROMPT, O_NEVER, O_ALWAYS }; zip_header_t zip_header; - smallint verbose = 1; + smallint quiet = 0; + IF_NOT_DESKTOP(const) smallint verbose = 0; smallint listing = 0; smallint overwrite = O_PROMPT; #if ENABLE_DESKTOP uint32_t cds_offset; unsigned cds_entries; #endif - unsigned total_size; + unsigned long total_usize; + unsigned long total_size; unsigned total_entries; int dst_fd = -1; char *src_fn = NULL; @@ -273,8 +275,49 @@ int unzip_main(int argc, char **argv) char key_buf[80]; struct stat stat_buf; +/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP: + * + * # /usr/bin/unzip -qq -v decompress_unlzma.i.zip + * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i + * # /usr/bin/unzip -q -v decompress_unlzma.i.zip + * Length Method Size Ratio Date Time CRC-32 Name + * -------- ------ ------- ----- ---- ---- ------ ---- + * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i + * -------- ------- --- ------- + * 204372 35278 83% 1 file + * # /usr/bin/unzip -v decompress_unlzma.i.zip + * Archive: decompress_unlzma.i.zip + * Length Method Size Ratio Date Time CRC-32 Name + * -------- ------ ------- ----- ---- ---- ------ ---- + * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i + * -------- ------- --- ------- + * 204372 35278 83% 1 file + * # unzip -v decompress_unlzma.i.zip + * Archive: decompress_unlzma.i.zip + * Length Date Time Name + * -------- ---- ---- ---- + * 204372 09-06-09 14:23 decompress_unlzma.i + * -------- ------- + * 204372 1 files + * # /usr/bin/unzip -l -qq decompress_unlzma.i.zip + * 204372 09-06-09 14:23 decompress_unlzma.i + * # /usr/bin/unzip -l -q decompress_unlzma.i.zip + * Length Date Time Name + * -------- ---- ---- ---- + * 204372 09-06-09 14:23 decompress_unlzma.i + * -------- ------- + * 204372 1 file + * # /usr/bin/unzip -l decompress_unlzma.i.zip + * Archive: decompress_unlzma.i.zip + * Length Date Time Name + * -------- ---- ---- ---- + * 204372 09-06-09 14:23 decompress_unlzma.i + * -------- ------- + * 204372 1 file + */ + /* '-' makes getopt return 1 for non-options */ - while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) { + while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) { switch (opt_range) { case 0: /* Options */ switch (opt) { @@ -294,7 +337,12 @@ int unzip_main(int argc, char **argv) dst_fd = STDOUT_FILENO; case 'q': /* Be quiet */ - verbose = 0; + quiet++; + break; + + case 'v': /* Verbose list */ + IF_DESKTOP(verbose++;) + listing = 1; break; case 1: /* The zip file */ @@ -373,14 +421,21 @@ int unzip_main(int argc, char **argv) if (base_dir) xchdir(base_dir); - if (verbose) { - printf("Archive: %s\n", src_fn); - if (listing){ - puts(" Length Date Time Name\n" - " -------- ---- ---- ----"); + if (quiet <= 1) { /* not -qq */ + if (quiet == 0) + printf("Archive: %s\n", src_fn); + if (listing) { + puts(verbose ? + " Length Method Size Ratio Date Time CRC-32 Name\n" + "-------- ------ ------- ----- ---- ---- ------ ----" + : + " Length Date Time Name\n" + " -------- ---- ---- ----" + ); } } + total_usize = 0; total_size = 0; total_entries = 0; #if ENABLE_DESKTOP @@ -449,20 +504,39 @@ int unzip_main(int argc, char **argv) } else { /* Extract entry */ if (listing) { /* List entry */ - if (verbose) { - unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); - printf("%9u %02u-%02u-%02u %02u:%02u %s\n", - zip_header.formatted.ucmpsize, - (dostime & 0x01e00000) >> 21, - (dostime & 0x001f0000) >> 16, - (((dostime & 0xfe000000) >> 25) + 1980) % 100, - (dostime & 0x0000f800) >> 11, - (dostime & 0x000007e0) >> 5, - dst_fn); - total_size += zip_header.formatted.ucmpsize; + unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); + if (!verbose) { + // " Length Date Time Name\n" + // " -------- ---- ---- ----" + printf( "%9u %02u-%02u-%02u %02u:%02u %s\n", + (unsigned)zip_header.formatted.ucmpsize, + (dostime & 0x01e00000) >> 21, + (dostime & 0x001f0000) >> 16, + (((dostime & 0xfe000000) >> 25) + 1980) % 100, + (dostime & 0x0000f800) >> 11, + (dostime & 0x000007e0) >> 5, + dst_fn); + total_usize += zip_header.formatted.ucmpsize; } else { - /* short listing -- filenames only */ - puts(dst_fn); + unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize; + percents = percents * 100; + if (zip_header.formatted.ucmpsize) + percents /= zip_header.formatted.ucmpsize; + // " Length Method Size Ratio Date Time CRC-32 Name\n" + // "-------- ------ ------- ----- ---- ---- ------ ----" + printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n", + (unsigned)zip_header.formatted.ucmpsize, + (unsigned)zip_header.formatted.cmpsize, + (unsigned)percents, + (dostime & 0x01e00000) >> 21, + (dostime & 0x001f0000) >> 16, + (((dostime & 0xfe000000) >> 25) + 1980) % 100, + (dostime & 0x0000f800) >> 11, + (dostime & 0x000007e0) >> 5, + zip_header.formatted.crc32, + dst_fn); + total_usize += zip_header.formatted.ucmpsize; + total_size += zip_header.formatted.cmpsize; } i = 'n'; } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ @@ -472,7 +546,7 @@ int unzip_main(int argc, char **argv) if (errno != ENOENT) { bb_perror_msg_and_die("can't stat '%s'", dst_fn); } - if (verbose) { + if (!quiet) { printf(" creating: %s\n", dst_fn); } unzip_create_leading_dirs(dst_fn); @@ -520,7 +594,7 @@ int unzip_main(int argc, char **argv) unzip_create_leading_dirs(dst_fn); dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); case -1: /* Unzip */ - if (verbose) { + if (!quiet) { printf(" inflating: %s\n", dst_fn); } unzip_extract(&zip_header, dst_fd); @@ -549,17 +623,32 @@ int unzip_main(int argc, char **argv) goto check_file; default: - printf("error: invalid response [%c]\n",(char)i); + printf("error: invalid response [%c]\n", (char)i); goto check_file; } total_entries++; } - if (listing && verbose) { - printf(" -------- -------\n" - "%9d %d files\n", - total_size, total_entries); + if (listing && quiet <= 1) { + if (!verbose) { + // " Length Date Time Name\n" + // " -------- ---- ---- ----" + printf( " -------- -------\n" + "%9lu" " %u files\n", + total_usize, total_entries); + } else { + unsigned long percents = total_usize - total_size; + percents = percents * 100; + if (total_usize) + percents /= total_usize; + // " Length Method Size Ratio Date Time CRC-32 Name\n" + // "-------- ------ ------- ----- ---- ---- ------ ----" + printf( "-------- ------- --- -------\n" + "%8lu" "%17lu%4u%% %u files\n", + total_usize, total_size, (unsigned)percents, + total_entries); + } } return 0; diff --git a/include/usage.h b/include/usage.h index e571d2b..036cf9d 100644 --- a/include/usage.h +++ b/include/usage.h @@ -2824,9 +2824,21 @@ "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n" #define modprobe_trivial_usage \ - "[-knqrsv] MODULE [symbol=value...]" + IF_MODPROBE_SMALL("[-qfwrsv] MODULE [symbol=value...]") \ + IF_NOT_MODPROBE_SMALL("[-" \ + IF_FEATURE_2_4_MODULES("k")"nqrsv" \ + IF_FEATURE_MODPROBE_BLACKLIST("b")"] MODULE [symbol=value...]") #define modprobe_full_usage "\n\n" \ "Options:" \ + IF_MODPROBE_SMALL( \ + "\n -q Quiet" \ + "\n -f Force" \ + "\n -w Wait for unload" \ + "\n -r Remove module (stacks) or do autoclean" \ + "\n -s Report via syslog instead of stderr" \ + "\n -v Verbose" \ + ) \ + IF_NOT_MODPROBE_SMALL( \ IF_FEATURE_2_4_MODULES( \ "\n -k Make module autoclean-able" \ ) \ @@ -2837,7 +2849,8 @@ "\n -v Verbose" \ IF_FEATURE_MODPROBE_BLACKLIST( \ "\n -b Apply blacklist to module names too" \ - ) + ) \ + ) #define modprobe_notes_usage \ "modprobe can (un)load a stack of modules, passing each module options (when\n" \ diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index 02d8fbd..e2359d0 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c @@ -44,11 +44,13 @@ struct globals { char *module_load_options; smallint dep_bb_seen; smallint wrote_dep_bb_ok; - int module_count; + unsigned module_count; int module_found_idx; - int stringbuf_idx; - char stringbuf[32 * 1024]; /* some modules have lots of stuff */ + unsigned stringbuf_idx; + unsigned stringbuf_size; + char *stringbuf; /* some modules have lots of stuff */ /* for example, drivers/media/video/saa7134/saa7134.ko */ + /* therefore having a fixed biggish buffer is not wise */ }; #define G (*ptr_to_globals) #define modinfo (G.modinfo ) @@ -58,16 +60,29 @@ struct globals { #define module_found_idx (G.module_found_idx ) #define module_load_options (G.module_load_options) #define stringbuf_idx (G.stringbuf_idx ) +#define stringbuf_size (G.stringbuf_size ) #define stringbuf (G.stringbuf ) #define INIT_G() do { \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ } while (0) +static void append(const char *s) +{ + unsigned len = strlen(s); + if (stringbuf_idx + len + 15 > stringbuf_size) { + stringbuf_size = stringbuf_idx + len + 127; + dbg2_error_msg("grow stringbuf to %u", stringbuf_size); + stringbuf = xrealloc(stringbuf, stringbuf_size); + } + memcpy(stringbuf + stringbuf_idx, s, len); + stringbuf_idx += len; +} static void appendc(char c) { - if (stringbuf_idx < sizeof(stringbuf)) - stringbuf[stringbuf_idx++] = c; + /* We appendc() only after append(), + 15 trick in append() + * makes it unnecessary to check for overflow here */ + stringbuf[stringbuf_idx++] = c; } static void bksp(void) @@ -76,15 +91,6 @@ static void bksp(void) stringbuf_idx--; } -static void append(const char *s) -{ - size_t len = strlen(s); - if (stringbuf_idx + len < sizeof(stringbuf)) { - memcpy(stringbuf + stringbuf_idx, s, len); - stringbuf_idx += len; - } -} - static void reset_stringbuf(void) { stringbuf_idx = 0; @@ -92,7 +98,7 @@ static void reset_stringbuf(void) static char* copy_stringbuf(void) { - char *copy = xmalloc(stringbuf_idx); + char *copy = xzalloc(stringbuf_idx + 1); /* terminating NUL */ return memcpy(copy, stringbuf, stringbuf_idx); } @@ -216,8 +222,8 @@ static void parse_module(module_info *info, const char *pathname) pos = (ptr - module_image); } bksp(); /* remove last ' ' */ - appendc('\0'); info->aliases = copy_stringbuf(); + replace(info->aliases, '-', '_'); /* "dependency1 depandency2" */ reset_stringbuf(); @@ -228,7 +234,6 @@ static void parse_module(module_info *info, const char *pathname) dbg2_error_msg("dep:'%s'", ptr); append(ptr); } - appendc('\0'); info->deps = copy_stringbuf(); free(module_image); |