Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-09-09 17:38:26 +0400
committerGlenn L McGrath <bug1@ihug.co.nz>2000-09-09 17:38:26 +0400
commit437bf72785cdd8c9d689c241a94c79f1f71a2354 (patch)
treec9551952cd7d6fe255a6e7f93c3107843eda1130
parent6fb88e73f792ad6dfb1c2c08600972988f223012 (diff)
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.c2
-rw-r--r--ar.c26
-rw-r--r--archival/ar.c26
-rw-r--r--usage.c2
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 @@
#if defined BB_AR
const char ar_usage[] =
- "ar [[-ov] -tpv archive] filenames \n"
+ "ar -ovtpv archive filenames \n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nExtract or list files from an ar archive.\n\n"
"Options:\n"
diff --git a/ar.c b/ar.c
index eaa15a516..41750ac7c 100644
--- a/ar.c
+++ b/ar.c
@@ -239,7 +239,7 @@ extern int ar_main(int argc, char **argv)
int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList;
- while ((opt = getopt(argc, argv, "ovt:p:x:")) != -1) {
+ while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
switch (opt) {
case 'o':
funct = funct | PRESERVE_DATE;
@@ -249,31 +249,29 @@ extern int ar_main(int argc, char **argv)
break;
case 't':
funct = funct | DISPLAY;
+ break;
case 'x':
- if (opt=='x') {
- funct = funct | EXT_TO_FILE;
- }
+ funct = funct | EXT_TO_FILE;
+ break;
case 'p':
- if (opt=='p') {
- funct = funct | EXT_TO_STDOUT;
- }
- /* following is common to 't','x' and 'p' */
- if ( (srcFd = open(optarg, O_RDONLY)) < 0) {
- errorMsg("Cannot read %s\n", optarg);
- return (FALSE);
- }
+ funct = funct | EXT_TO_STDOUT;
break;
default:
usage(ar_usage);
}
}
- /* check options not just preserve_dates and/or verbose */
- if (funct < 4) {
+ /* check the src filename was specified */
+ if (optind == argc) {
usage(ar_usage);
return(FALSE);
}
+ if ( (srcFd = open(argv[optind], O_RDONLY)) < 0) {
+ errorMsg("Cannot read %s\n", optarg);
+ return (FALSE);
+ }
+ optind++;
entry = (headerL_t *) malloc(sizeof(headerL_t));
header = (headerL_t *) malloc(sizeof(headerL_t));
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)
int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList;
- while ((opt = getopt(argc, argv, "ovt:p:x:")) != -1) {
+ while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
switch (opt) {
case 'o':
funct = funct | PRESERVE_DATE;
@@ -249,31 +249,29 @@ extern int ar_main(int argc, char **argv)
break;
case 't':
funct = funct | DISPLAY;
+ break;
case 'x':
- if (opt=='x') {
- funct = funct | EXT_TO_FILE;
- }
+ funct = funct | EXT_TO_FILE;
+ break;
case 'p':
- if (opt=='p') {
- funct = funct | EXT_TO_STDOUT;
- }
- /* following is common to 't','x' and 'p' */
- if ( (srcFd = open(optarg, O_RDONLY)) < 0) {
- errorMsg("Cannot read %s\n", optarg);
- return (FALSE);
- }
+ funct = funct | EXT_TO_STDOUT;
break;
default:
usage(ar_usage);
}
}
- /* check options not just preserve_dates and/or verbose */
- if (funct < 4) {
+ /* check the src filename was specified */
+ if (optind == argc) {
usage(ar_usage);
return(FALSE);
}
+ if ( (srcFd = open(argv[optind], O_RDONLY)) < 0) {
+ errorMsg("Cannot read %s\n", optarg);
+ return (FALSE);
+ }
+ optind++;
entry = (headerL_t *) malloc(sizeof(headerL_t));
header = (headerL_t *) malloc(sizeof(headerL_t));
extractList = (headerL_t *) malloc(sizeof(headerL_t));
diff --git a/usage.c b/usage.c
index b23f27141..b01c11ef2 100644
--- a/usage.c
+++ b/usage.c
@@ -2,7 +2,7 @@
#if defined BB_AR
const char ar_usage[] =
- "ar [[-ov] -tpv archive] filenames \n"
+ "ar -ovtpv archive filenames \n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nExtract or list files from an ar archive.\n\n"
"Options:\n"