5959#ifdef HAVE_FNMATCH_H
6060#include <fnmatch.h>
6161#endif
62- #ifdef HAVE_GETOPT_H
63- #include <getopt.h>
64- #endif
6562#ifdef HAVE_STDARG_H
6663#include <stdarg.h>
6764#endif
8279#endif
8380#endif
8481
85- #include <archive.h>
86- #include <archive_entry.h>
82+ #include "bsdunzip.h"
8783#include "passphrase.h"
8884#include "err.h"
8985
@@ -93,13 +89,13 @@ static int C_opt; /* match case-insensitively */
9389static int c_opt ; /* extract to stdout */
9490static const char * d_arg ; /* directory */
9591static int f_opt ; /* update existing files only */
96- static char * O_arg ; /* encoding */
92+ static const char * O_arg ; /* encoding */
9793static int j_opt ; /* junk directories */
9894static int L_opt ; /* lowercase names */
9995static int n_opt ; /* never overwrite */
10096static int o_opt ; /* always overwrite */
10197static int p_opt ; /* extract to stdout, quiet */
102- static char * P_arg ; /* passphrase */
98+ static const char * P_arg ; /* passphrase */
10399static int q_opt ; /* quiet */
104100static int t_opt ; /* test */
105101static int u_opt ; /* update */
@@ -117,6 +113,8 @@ static int zipinfo_mode;
117113/* running on tty? */
118114static int tty ;
119115
116+ int bsdunzip_optind ;
117+
120118/* convenience macro */
121119/* XXX should differentiate between ARCHIVE_{WARN,FAIL,RETRY} */
122120#define ac (call ) \
@@ -1105,25 +1103,18 @@ version(void)
11051103static int
11061104getopts (int argc , char * argv [])
11071105{
1106+ struct bsdunzip * bsdunzip , bsdunzip_storage ;
11081107 int opt ;
1108+ bsdunzip_optind = 1 ;
11091109
1110- static struct option longopts [] = {
1111- { "version" , no_argument , & version_opt , 1 },
1112- { 0 , 0 , 0 , 0 }
1113- };
1110+ bsdunzip = & bsdunzip_storage ;
1111+ memset (bsdunzip , 0 , sizeof (* bsdunzip ));
11141112
1115- optind = 1 ;
1116- #ifdef HAVE_GETOPT_OPTRESET
1117- optreset = 1 ;
1118- #endif
1119- while ((opt = getopt_long (argc , argv ,
1120- "aCcd:fI:jLlnO:opP:qtuvx:yZ1" , longopts , NULL )) != -1 ) {
1113+ bsdunzip -> argv = argv ;
1114+ bsdunzip -> argc = argc ;
1115+
1116+ while ((opt = bsdunzip_getopt (bsdunzip )) != -1 ) {
11211117 switch (opt ) {
1122- case 0 :
1123- break ;
1124- case '1' :
1125- Z1_opt = 1 ;
1126- break ;
11271118 case 'a' :
11281119 a_opt = 1 ;
11291120 break ;
@@ -1134,14 +1125,14 @@ getopts(int argc, char *argv[])
11341125 c_opt = 1 ;
11351126 break ;
11361127 case 'd' :
1137- d_arg = optarg ;
1128+ d_arg = bsdunzip -> argument ;
11381129 break ;
11391130 case 'f' :
11401131 f_opt = 1 ;
11411132 break ;
11421133 case 'I' :
11431134 case 'O' :
1144- O_arg = optarg ;
1135+ O_arg = bsdunzip -> argument ;
11451136 break ;
11461137 case 'j' :
11471138 j_opt = 1 ;
@@ -1164,7 +1155,7 @@ getopts(int argc, char *argv[])
11641155 p_opt = 1 ;
11651156 break ;
11661157 case 'P' :
1167- P_arg = optarg ;
1158+ P_arg = bsdunzip -> argument ;
11681159 break ;
11691160 case 'q' :
11701161 q_opt = 1 ;
@@ -1179,19 +1170,30 @@ getopts(int argc, char *argv[])
11791170 v_opt = 2 ;
11801171 break ;
11811172 case 'x' :
1182- add_pattern (& exclude , optarg );
1173+ add_pattern (& exclude , bsdunzip -> argument );
11831174 break ;
11841175 case 'y' :
11851176 y_str = " " ;
11861177 break ;
11871178 case 'Z' :
11881179 zipinfo_mode = 1 ;
1180+ if (bsdunzip -> argument != NULL &&
1181+ strcmp (bsdunzip -> argument , "1" ) == 0 ) {
1182+ Z1_opt = 1 ;
1183+ }
1184+ break ;
1185+ case OPTION_VERSION :
1186+ version_opt = 1 ;
1187+ break ;
1188+ case OPTION_NONE :
11891189 break ;
11901190 default :
11911191 usage ();
11921192 }
1193+ if (opt == OPTION_NONE )
1194+ break ;
11931195 }
1194- return (optind );
1196+ return (bsdunzip_optind );
11951197}
11961198
11971199int
0 commit comments