summaryrefslogtreecommitdiff
path: root/archival/unzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/unzip.c')
-rw-r--r--archival/unzip.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/archival/unzip.c b/archival/unzip.c
index ef58cd463..97c743c43 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -97,7 +97,10 @@ int unzip_main(int argc, char **argv);
97int unzip_main(int argc, char **argv) 97int unzip_main(int argc, char **argv)
98{ 98{
99 zip_header_t zip_header; 99 zip_header_t zip_header;
100 enum {v_silent, v_normal, v_list} verbosity = v_normal; 100 smallint verbose = 1;
101 smallint listing = 0;
102 smallint list_header_done = 0;
103 smallint failed;
101 enum {o_prompt, o_never, o_always} overwrite = o_prompt; 104 enum {o_prompt, o_never, o_always} overwrite = o_prompt;
102 unsigned int total_size = 0; 105 unsigned int total_size = 0;
103 unsigned int total_entries = 0; 106 unsigned int total_entries = 0;
@@ -106,7 +109,7 @@ int unzip_main(int argc, char **argv)
106 llist_t *zaccept = NULL; 109 llist_t *zaccept = NULL;
107 llist_t *zreject = NULL; 110 llist_t *zreject = NULL;
108 char *base_dir = NULL; 111 char *base_dir = NULL;
109 int failed, i, opt, opt_range = 0, list_header_done = 0; 112 int i, opt, opt_range = 0;
110 char key_buf[512]; 113 char key_buf[512];
111 struct stat stat_buf; 114 struct stat stat_buf;
112 115
@@ -115,7 +118,7 @@ int unzip_main(int argc, char **argv)
115 case 0: /* Options */ 118 case 0: /* Options */
116 switch (opt) { 119 switch (opt) {
117 case 'l': /* List */ 120 case 'l': /* List */
118 verbosity = v_list; 121 listing = 1;
119 break; 122 break;
120 123
121 case 'n': /* Never overwrite existing files */ 124 case 'n': /* Never overwrite existing files */
@@ -130,7 +133,7 @@ int unzip_main(int argc, char **argv)
130 dst_fd = STDOUT_FILENO; 133 dst_fd = STDOUT_FILENO;
131 134
132 case 'q': /* Be quiet */ 135 case 'q': /* Be quiet */
133 verbosity = (verbosity == v_normal) ? v_silent : verbosity; 136 verbose = 0;
134 break; 137 break;
135 138
136 case 1 : /* The zip file */ 139 case 1 : /* The zip file */
@@ -205,7 +208,7 @@ int unzip_main(int argc, char **argv)
205 if (base_dir) 208 if (base_dir)
206 xchdir(base_dir); 209 xchdir(base_dir);
207 210
208 if (verbosity != v_silent) 211 if (verbose)
209 printf("Archive: %s\n", src_fn); 212 printf("Archive: %s\n", src_fn);
210 213
211 failed = 0; 214 failed = 0;
@@ -245,7 +248,7 @@ int unzip_main(int argc, char **argv)
245 /* Skip extra header bytes */ 248 /* Skip extra header bytes */
246 unzip_skip(src_fd, zip_header.formatted.extra_len); 249 unzip_skip(src_fd, zip_header.formatted.extra_len);
247 250
248 if ((verbosity == v_list) && !list_header_done){ 251 if (listing && verbose && !list_header_done){
249 puts(" Length Date Time Name\n" 252 puts(" Length Date Time Name\n"
250 " -------- ---- ---- ----"); 253 " -------- ---- ---- ----");
251 list_header_done = 1; 254 list_header_done = 1;
@@ -259,7 +262,8 @@ int unzip_main(int argc, char **argv)
259 } else { /* Extract entry */ 262 } else { /* Extract entry */
260 total_size += zip_header.formatted.ucmpsize; 263 total_size += zip_header.formatted.ucmpsize;
261 264
262 if (verbosity == v_list) { /* List entry */ 265 if (listing) { /* List entry */
266 if (verbose) {
263 unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16); 267 unsigned int dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
264 printf("%9u %02u-%02u-%02u %02u:%02u %s\n", 268 printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
265 zip_header.formatted.ucmpsize, 269 zip_header.formatted.ucmpsize,
@@ -270,7 +274,11 @@ int unzip_main(int argc, char **argv)
270 (dostime & 0x000007e0) >> 5, 274 (dostime & 0x000007e0) >> 5,
271 dst_fn); 275 dst_fn);
272 total_entries++; 276 total_entries++;
273 i = 'n'; 277 } else {
278 /* short listing -- filenames only */
279 printf("%s\n", dst_fn);
280 }
281 i = 'n';
274 } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */ 282 } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
275 i = -1; 283 i = -1;
276 } else if (last_char_is(dst_fn, '/')) { /* Extract directory */ 284 } else if (last_char_is(dst_fn, '/')) { /* Extract directory */
@@ -278,7 +286,7 @@ int unzip_main(int argc, char **argv)
278 if (errno != ENOENT) { 286 if (errno != ENOENT) {
279 bb_perror_msg_and_die("cannot stat '%s'",dst_fn); 287 bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
280 } 288 }
281 if (verbosity == v_normal) { 289 if (verbose) {
282 printf(" creating: %s\n", dst_fn); 290 printf(" creating: %s\n", dst_fn);
283 } 291 }
284 unzip_create_leading_dirs(dst_fn); 292 unzip_create_leading_dirs(dst_fn);
@@ -326,7 +334,7 @@ int unzip_main(int argc, char **argv)
326 unzip_create_leading_dirs(dst_fn); 334 unzip_create_leading_dirs(dst_fn);
327 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC); 335 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
328 case -1: /* Unzip */ 336 case -1: /* Unzip */
329 if (verbosity == v_normal) { 337 if (verbose) {
330 printf(" inflating: %s\n", dst_fn); 338 printf(" inflating: %s\n", dst_fn);
331 } 339 }
332 if (unzip_extract(&zip_header, src_fd, dst_fd)) { 340 if (unzip_extract(&zip_header, src_fd, dst_fd)) {
@@ -368,7 +376,7 @@ int unzip_main(int argc, char **argv)
368 } 376 }
369 } 377 }
370 378
371 if (verbosity == v_list) { 379 if (listing && verbose) {
372 printf(" -------- -------\n" 380 printf(" -------- -------\n"
373 "%9d %d files\n", total_size, total_entries); 381 "%9d %d files\n", total_size, total_entries);
374 } 382 }