diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2000-09-09 13:38:26 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2000-09-09 13:38:26 +0000 |
commit | 437bf72785cdd8c9d689c241a94c79f1f71a2354 (patch) | |
tree | c9551952cd7d6fe255a6e7f93c3107843eda1130 | |
parent | 6fb88e73f792ad6dfb1c2c08600972988f223012 (diff) | |
download | busybox-w32-437bf72785cdd8c9d689c241a94c79f1f71a2354.tar.gz busybox-w32-437bf72785cdd8c9d689c241a94c79f1f71a2354.tar.bz2 busybox-w32-437bf72785cdd8c9d689c241a94c79f1f71a2354.zip |
Changed getopt so that options can be grouped together, the source
archive is now assumed to be the first non parameter.
This is how GNU ar behaves.
-rw-r--r-- | applets/usage.c | 2 | ||||
-rw-r--r-- | ar.c | 26 | ||||
-rw-r--r-- | archival/ar.c | 26 | ||||
-rw-r--r-- | usage.c | 2 |
4 files changed, 26 insertions, 30 deletions
diff --git a/applets/usage.c b/applets/usage.c index b23f27141..b01c11ef2 100644 --- a/applets/usage.c +++ b/applets/usage.c | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | #if defined BB_AR | 3 | #if defined BB_AR |
4 | const char ar_usage[] = | 4 | const char ar_usage[] = |
5 | "ar [[-ov] -tpv archive] filenames \n" | 5 | "ar -ovtpv archive filenames \n" |
6 | #ifndef BB_FEATURE_TRIVIAL_HELP | 6 | #ifndef BB_FEATURE_TRIVIAL_HELP |
7 | "\nExtract or list files from an ar archive.\n\n" | 7 | "\nExtract or list files from an ar archive.\n\n" |
8 | "Options:\n" | 8 | "Options:\n" |
@@ -239,7 +239,7 @@ extern int ar_main(int argc, char **argv) | |||
239 | int srcFd=0, dstFd=0; | 239 | int srcFd=0, dstFd=0; |
240 | headerL_t *header, *entry, *extractList; | 240 | headerL_t *header, *entry, *extractList; |
241 | 241 | ||
242 | while ((opt = getopt(argc, argv, "ovt:p:x:")) != -1) { | 242 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { |
243 | switch (opt) { | 243 | switch (opt) { |
244 | case 'o': | 244 | case 'o': |
245 | funct = funct | PRESERVE_DATE; | 245 | funct = funct | PRESERVE_DATE; |
@@ -249,31 +249,29 @@ extern int ar_main(int argc, char **argv) | |||
249 | break; | 249 | break; |
250 | case 't': | 250 | case 't': |
251 | funct = funct | DISPLAY; | 251 | funct = funct | DISPLAY; |
252 | break; | ||
252 | case 'x': | 253 | case 'x': |
253 | if (opt=='x') { | 254 | funct = funct | EXT_TO_FILE; |
254 | funct = funct | EXT_TO_FILE; | 255 | break; |
255 | } | ||
256 | case 'p': | 256 | case 'p': |
257 | if (opt=='p') { | 257 | funct = funct | EXT_TO_STDOUT; |
258 | funct = funct | EXT_TO_STDOUT; | ||
259 | } | ||
260 | /* following is common to 't','x' and 'p' */ | ||
261 | if ( (srcFd = open(optarg, O_RDONLY)) < 0) { | ||
262 | errorMsg("Cannot read %s\n", optarg); | ||
263 | return (FALSE); | ||
264 | } | ||
265 | break; | 258 | break; |
266 | default: | 259 | default: |
267 | usage(ar_usage); | 260 | usage(ar_usage); |
268 | } | 261 | } |
269 | } | 262 | } |
270 | 263 | ||
271 | /* check options not just preserve_dates and/or verbose */ | 264 | /* check the src filename was specified */ |
272 | if (funct < 4) { | 265 | if (optind == argc) { |
273 | usage(ar_usage); | 266 | usage(ar_usage); |
274 | return(FALSE); | 267 | return(FALSE); |
275 | } | 268 | } |
276 | 269 | ||
270 | if ( (srcFd = open(argv[optind], O_RDONLY)) < 0) { | ||
271 | errorMsg("Cannot read %s\n", optarg); | ||
272 | return (FALSE); | ||
273 | } | ||
274 | optind++; | ||
277 | entry = (headerL_t *) malloc(sizeof(headerL_t)); | 275 | entry = (headerL_t *) malloc(sizeof(headerL_t)); |
278 | header = (headerL_t *) malloc(sizeof(headerL_t)); | 276 | header = (headerL_t *) malloc(sizeof(headerL_t)); |
279 | extractList = (headerL_t *) malloc(sizeof(headerL_t)); | 277 | extractList = (headerL_t *) malloc(sizeof(headerL_t)); |
diff --git a/archival/ar.c b/archival/ar.c index eaa15a516..41750ac7c 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -239,7 +239,7 @@ extern int ar_main(int argc, char **argv) | |||
239 | int srcFd=0, dstFd=0; | 239 | int srcFd=0, dstFd=0; |
240 | headerL_t *header, *entry, *extractList; | 240 | headerL_t *header, *entry, *extractList; |
241 | 241 | ||
242 | while ((opt = getopt(argc, argv, "ovt:p:x:")) != -1) { | 242 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { |
243 | switch (opt) { | 243 | switch (opt) { |
244 | case 'o': | 244 | case 'o': |
245 | funct = funct | PRESERVE_DATE; | 245 | funct = funct | PRESERVE_DATE; |
@@ -249,31 +249,29 @@ extern int ar_main(int argc, char **argv) | |||
249 | break; | 249 | break; |
250 | case 't': | 250 | case 't': |
251 | funct = funct | DISPLAY; | 251 | funct = funct | DISPLAY; |
252 | break; | ||
252 | case 'x': | 253 | case 'x': |
253 | if (opt=='x') { | 254 | funct = funct | EXT_TO_FILE; |
254 | funct = funct | EXT_TO_FILE; | 255 | break; |
255 | } | ||
256 | case 'p': | 256 | case 'p': |
257 | if (opt=='p') { | 257 | funct = funct | EXT_TO_STDOUT; |
258 | funct = funct | EXT_TO_STDOUT; | ||
259 | } | ||
260 | /* following is common to 't','x' and 'p' */ | ||
261 | if ( (srcFd = open(optarg, O_RDONLY)) < 0) { | ||
262 | errorMsg("Cannot read %s\n", optarg); | ||
263 | return (FALSE); | ||
264 | } | ||
265 | break; | 258 | break; |
266 | default: | 259 | default: |
267 | usage(ar_usage); | 260 | usage(ar_usage); |
268 | } | 261 | } |
269 | } | 262 | } |
270 | 263 | ||
271 | /* check options not just preserve_dates and/or verbose */ | 264 | /* check the src filename was specified */ |
272 | if (funct < 4) { | 265 | if (optind == argc) { |
273 | usage(ar_usage); | 266 | usage(ar_usage); |
274 | return(FALSE); | 267 | return(FALSE); |
275 | } | 268 | } |
276 | 269 | ||
270 | if ( (srcFd = open(argv[optind], O_RDONLY)) < 0) { | ||
271 | errorMsg("Cannot read %s\n", optarg); | ||
272 | return (FALSE); | ||
273 | } | ||
274 | optind++; | ||
277 | entry = (headerL_t *) malloc(sizeof(headerL_t)); | 275 | entry = (headerL_t *) malloc(sizeof(headerL_t)); |
278 | header = (headerL_t *) malloc(sizeof(headerL_t)); | 276 | header = (headerL_t *) malloc(sizeof(headerL_t)); |
279 | extractList = (headerL_t *) malloc(sizeof(headerL_t)); | 277 | extractList = (headerL_t *) malloc(sizeof(headerL_t)); |
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | #if defined BB_AR | 3 | #if defined BB_AR |
4 | const char ar_usage[] = | 4 | const char ar_usage[] = |
5 | "ar [[-ov] -tpv archive] filenames \n" | 5 | "ar -ovtpv archive filenames \n" |
6 | #ifndef BB_FEATURE_TRIVIAL_HELP | 6 | #ifndef BB_FEATURE_TRIVIAL_HELP |
7 | "\nExtract or list files from an ar archive.\n\n" | 7 | "\nExtract or list files from an ar archive.\n\n" |
8 | "Options:\n" | 8 | "Options:\n" |