Use getopt instead of hand-rolled argument parsing. Usage remains

the same, no man page changes required.

PR:		bin/48313
Submitted by:	Stefan Farfeleder <stefan@fafoe.dyndns.org>
Reviewed by:	joe@
This commit is contained in:
Wes Peters 2004-03-05 01:52:09 +00:00
parent a11a407515
commit 0d1bf85301
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=126623

View File

@ -168,32 +168,15 @@ getargs(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
{ {
int i; int ch;
char *s;
for (i = 1; i < argc; ++i) while ((ch = getopt(argc, argv, "b:dlo:p:rtv")) != -1)
{ {
s = argv[i]; switch (ch)
if (*s != '-') break;
switch (*++s)
{ {
case '\0':
input_file = stdin;
if (i + 1 < argc) usage();
return;
case '-':
++i;
goto no_more_options;
case 'b': case 'b':
if (*++s) file_prefix = optarg;
file_prefix = s; break;
else if (++i < argc)
file_prefix = argv[i];
else
usage();
continue;
case 'd': case 'd':
dflag = 1; dflag = 1;
@ -204,22 +187,12 @@ char *argv[];
break; break;
case 'o': case 'o':
if (*++s) output_file_name = optarg;
output_file_name = s; break;
else if (++i < argc)
output_file_name = argv[i];
else
usage();
continue;
case 'p': case 'p':
if (*++s) symbol_prefix = optarg;
symbol_prefix = s; break;
else if (++i < argc)
symbol_prefix = argv[i];
else
usage();
continue;
case 'r': case 'r':
rflag = 1; rflag = 1;
@ -236,44 +209,14 @@ char *argv[];
default: default:
usage(); usage();
} }
for (;;)
{
switch (*++s)
{
case '\0':
goto end_of_option;
case 'd':
dflag = 1;
break;
case 'l':
lflag = 1;
break;
case 'r':
rflag = 1;
break;
case 't':
tflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
usage();
}
}
end_of_option:;
} }
no_more_options:; if (optind + 1 != argc)
if (i + 1 != argc) usage(); usage();
input_file_name = argv[i]; if (strcmp(argv[optind], "-") == 0)
input_file = stdin;
else
input_file_name = argv[optind];
} }