mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 05:58:57 +00:00
Make example for handling "-##" work and comply with style(9). Still
doesn't handle nastier corner cases such as "-j3 -33" correctly. <shrug> PR: docs/12994 (James Howard <howardjp@wam.umd.edu>)
This commit is contained in:
parent
dac2aaa459
commit
838fb327f2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=55490
@ -243,10 +243,10 @@ as an option.
|
|||||||
This practice is wrong, and should not be used in any current development.
|
This practice is wrong, and should not be used in any current development.
|
||||||
It is provided for backward compatibility
|
It is provided for backward compatibility
|
||||||
.Em only .
|
.Em only .
|
||||||
The following code fragment works in most cases.
|
The following code fragment works in most (but not all) cases.
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
int length;
|
int length;
|
||||||
char *p;
|
char *p, *ep;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "0123456789")) != -1)
|
while ((ch = getopt(argc, argv, "0123456789")) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@ -254,9 +254,16 @@ while ((ch = getopt(argc, argv, "0123456789")) != -1)
|
|||||||
case '5': case '6': case '7': case '8': case '9':
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
p = argv[optind - 1];
|
p = argv[optind - 1];
|
||||||
if (p[0] == '-' && p[1] == ch && !p[2])
|
if (p[0] == '-' && p[1] == ch && !p[2])
|
||||||
length = atoi(++p);
|
length = strtol(++p, &ep, 10);
|
||||||
else
|
else if (argv[optind] && argv[optind][1] == ch) {
|
||||||
length = atoi(argv[optind] + 1);
|
length = strtol((p = argv[optind] + 1),
|
||||||
|
&ep, 10);
|
||||||
|
optind++;
|
||||||
|
optreset = 1;
|
||||||
|
} else
|
||||||
|
usage();
|
||||||
|
if (*ep != '\0')
|
||||||
|
errx(EX_USAGE, "illegal number -- %s", p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
.Ed
|
.Ed
|
||||||
|
Loading…
Reference in New Issue
Block a user