diff options
Diffstat (limited to 'contrib/minizip/miniunz.c')
-rw-r--r-- | contrib/minizip/miniunz.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index c8cf81e..11b7260 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c | |||
@@ -1,3 +1,11 @@ | |||
1 | /* | ||
2 | miniunz.c | ||
3 | Version 1.01b, May 30th, 2004 | ||
4 | |||
5 | Copyright (C) 1998-2004 Gilles Vollant | ||
6 | */ | ||
7 | |||
8 | |||
1 | #include <stdio.h> | 9 | #include <stdio.h> |
2 | #include <stdlib.h> | 10 | #include <stdlib.h> |
3 | #include <string.h> | 11 | #include <string.h> |
@@ -27,7 +35,7 @@ | |||
27 | mini unzip, demo of unzip package | 35 | mini unzip, demo of unzip package |
28 | 36 | ||
29 | usage : | 37 | usage : |
30 | Usage : miniunz [-exvlo] file.zip [file_to_extract] | 38 | Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] |
31 | 39 | ||
32 | list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT | 40 | list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT |
33 | if it exists | 41 | if it exists |
@@ -140,17 +148,18 @@ int makedir (newdir) | |||
140 | 148 | ||
141 | void do_banner() | 149 | void do_banner() |
142 | { | 150 | { |
143 | printf("MiniUnz 1.00, demo of zLib + Unz package written by Gilles Vollant\n"); | 151 | printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); |
144 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 152 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
145 | } | 153 | } |
146 | 154 | ||
147 | void do_help() | 155 | void do_help() |
148 | { | 156 | { |
149 | printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.]\n\n" \ | 157 | printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ |
150 | " -e Extract without pathname (junk paths)\n" \ | 158 | " -e Extract without pathname (junk paths)\n" \ |
151 | " -x Extract with pathname\n" \ | 159 | " -x Extract with pathname\n" \ |
152 | " -v list files\n" \ | 160 | " -v list files\n" \ |
153 | " -l list files\n" \ | 161 | " -l list files\n" \ |
162 | " -d directory to extract into\n" \ | ||
154 | " -o overwrite files without prompting\n" \ | 163 | " -o overwrite files without prompting\n" \ |
155 | " -p extract crypted file using password\n\n"); | 164 | " -p extract crypted file using password\n\n"); |
156 | } | 165 | } |
@@ -304,8 +313,14 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
304 | do | 313 | do |
305 | { | 314 | { |
306 | char answer[128]; | 315 | char answer[128]; |
307 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | 316 | int ret; |
308 | scanf("%1s",answer); | 317 | |
318 | printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | ||
319 | ret = scanf("%1s",answer); | ||
320 | if (ret != 1) | ||
321 | { | ||
322 | exit(EXIT_FAILURE); | ||
323 | } | ||
309 | rep = answer[0] ; | 324 | rep = answer[0] ; |
310 | if ((rep>='a') && (rep<='z')) | 325 | if ((rep>='a') && (rep<='z')) |
311 | rep -= 0x20; | 326 | rep -= 0x20; |
@@ -459,6 +474,8 @@ int main(argc,argv) | |||
459 | int opt_do_extract=1; | 474 | int opt_do_extract=1; |
460 | int opt_do_extract_withoutpath=0; | 475 | int opt_do_extract_withoutpath=0; |
461 | int opt_overwrite=0; | 476 | int opt_overwrite=0; |
477 | int opt_extractdir=0; | ||
478 | const char *dirname=NULL; | ||
462 | unzFile uf=NULL; | 479 | unzFile uf=NULL; |
463 | 480 | ||
464 | do_banner(); | 481 | do_banner(); |
@@ -488,6 +505,12 @@ int main(argc,argv) | |||
488 | opt_do_extract = opt_do_extract_withoutpath = 1; | 505 | opt_do_extract = opt_do_extract_withoutpath = 1; |
489 | if ((c=='o') || (c=='O')) | 506 | if ((c=='o') || (c=='O')) |
490 | opt_overwrite=1; | 507 | opt_overwrite=1; |
508 | if ((c=='d') || (c=='D')) | ||
509 | { | ||
510 | opt_extractdir=1; | ||
511 | dirname=argv[i+1]; | ||
512 | } | ||
513 | |||
491 | if (((c=='p') || (c=='P')) && (i+1<argc)) | 514 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
492 | { | 515 | { |
493 | password=argv[i+1]; | 516 | password=argv[i+1]; |
@@ -499,7 +522,7 @@ int main(argc,argv) | |||
499 | { | 522 | { |
500 | if (zipfilename == NULL) | 523 | if (zipfilename == NULL) |
501 | zipfilename = argv[i]; | 524 | zipfilename = argv[i]; |
502 | else if (filename_to_extract==NULL) | 525 | else if ((filename_to_extract==NULL) && (!opt_extractdir)) |
503 | filename_to_extract = argv[i] ; | 526 | filename_to_extract = argv[i] ; |
504 | } | 527 | } |
505 | } | 528 | } |
@@ -544,6 +567,12 @@ int main(argc,argv) | |||
544 | return do_list(uf); | 567 | return do_list(uf); |
545 | else if (opt_do_extract==1) | 568 | else if (opt_do_extract==1) |
546 | { | 569 | { |
570 | if (opt_extractdir && chdir(dirname)) | ||
571 | { | ||
572 | printf("Error changing into %s, aborting\n", dirname); | ||
573 | exit(-1); | ||
574 | } | ||
575 | |||
547 | if (filename_to_extract == NULL) | 576 | if (filename_to_extract == NULL) |
548 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); | 577 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); |
549 | else | 578 | else |