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.
This commit is contained in:
Glenn L McGrath 2000-09-09 13:38:26 +00:00
parent 6fb88e73f7
commit 437bf72785
4 changed files with 26 additions and 30 deletions

View File

@ -2,7 +2,7 @@
#if defined BB_AR #if defined BB_AR
const char ar_usage[] = const char ar_usage[] =
"ar [[-ov] -tpv archive] filenames \n" "ar -ovtpv archive filenames \n"
#ifndef BB_FEATURE_TRIVIAL_HELP #ifndef BB_FEATURE_TRIVIAL_HELP
"\nExtract or list files from an ar archive.\n\n" "\nExtract or list files from an ar archive.\n\n"
"Options:\n" "Options:\n"

26
ar.c
View File

@ -239,7 +239,7 @@ extern int ar_main(int argc, char **argv)
int srcFd=0, dstFd=0; int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList; headerL_t *header, *entry, *extractList;
while ((opt = getopt(argc, argv, "ovt:p:x:")) != -1) { while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
switch (opt) { switch (opt) {
case 'o': case 'o':
funct = funct | PRESERVE_DATE; funct = funct | PRESERVE_DATE;
@ -249,31 +249,29 @@ extern int ar_main(int argc, char **argv)
break; break;
case 't': case 't':
funct = funct | DISPLAY; funct = funct | DISPLAY;
break;
case 'x': case 'x':
if (opt=='x') { funct = funct | EXT_TO_FILE;
funct = funct | EXT_TO_FILE; break;
}
case 'p': case 'p':
if (opt=='p') { funct = funct | EXT_TO_STDOUT;
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);
}
break; break;
default: default:
usage(ar_usage); usage(ar_usage);
} }
} }
/* check options not just preserve_dates and/or verbose */ /* check the src filename was specified */
if (funct < 4) { if (optind == argc) {
usage(ar_usage); usage(ar_usage);
return(FALSE); 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)); entry = (headerL_t *) malloc(sizeof(headerL_t));
header = (headerL_t *) malloc(sizeof(headerL_t)); header = (headerL_t *) malloc(sizeof(headerL_t));
extractList = (headerL_t *) malloc(sizeof(headerL_t)); extractList = (headerL_t *) malloc(sizeof(headerL_t));

View File

@ -239,7 +239,7 @@ extern int ar_main(int argc, char **argv)
int srcFd=0, dstFd=0; int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList; headerL_t *header, *entry, *extractList;
while ((opt = getopt(argc, argv, "ovt:p:x:")) != -1) { while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
switch (opt) { switch (opt) {
case 'o': case 'o':
funct = funct | PRESERVE_DATE; funct = funct | PRESERVE_DATE;
@ -249,31 +249,29 @@ extern int ar_main(int argc, char **argv)
break; break;
case 't': case 't':
funct = funct | DISPLAY; funct = funct | DISPLAY;
break;
case 'x': case 'x':
if (opt=='x') { funct = funct | EXT_TO_FILE;
funct = funct | EXT_TO_FILE; break;
}
case 'p': case 'p':
if (opt=='p') { funct = funct | EXT_TO_STDOUT;
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);
}
break; break;
default: default:
usage(ar_usage); usage(ar_usage);
} }
} }
/* check options not just preserve_dates and/or verbose */ /* check the src filename was specified */
if (funct < 4) { if (optind == argc) {
usage(ar_usage); usage(ar_usage);
return(FALSE); 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)); entry = (headerL_t *) malloc(sizeof(headerL_t));
header = (headerL_t *) malloc(sizeof(headerL_t)); header = (headerL_t *) malloc(sizeof(headerL_t));
extractList = (headerL_t *) malloc(sizeof(headerL_t)); extractList = (headerL_t *) malloc(sizeof(headerL_t));

View File

@ -2,7 +2,7 @@
#if defined BB_AR #if defined BB_AR
const char ar_usage[] = const char ar_usage[] =
"ar [[-ov] -tpv archive] filenames \n" "ar -ovtpv archive filenames \n"
#ifndef BB_FEATURE_TRIVIAL_HELP #ifndef BB_FEATURE_TRIVIAL_HELP
"\nExtract or list files from an ar archive.\n\n" "\nExtract or list files from an ar archive.\n\n"
"Options:\n" "Options:\n"