diff options
author | Jim Meyering <jim@meyering.net> | 1996-04-05 13:32:39 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-04-05 13:32:39 +0000 |
commit | 0e199278c1fac7a69951f55d67f4c7d098f60e9b (patch) | |
tree | 47f68b9c680e2bff36c8877681493564b71ba8a8 | |
parent | 9d22ab92f9b00be7eb403561604124cc0bc0016f (diff) | |
download | coreutils-0e199278c1fac7a69951f55d67f4c7d098f60e9b.tar.xz |
(main): Use `if' stmt, not while loop, around getopt invocation.
Otherwise, `./nice --a=1 -1 ./nice' (in which old-style option
follows a long option) gets an error.
-rw-r--r-- | src/nice.c | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/src/nice.c b/src/nice.c index 7a9352106..348e4f291 100644 --- a/src/nice.c +++ b/src/nice.c @@ -79,46 +79,43 @@ main (int argc, char **argv) error (1, 0, _("invalid option `%s'"), s); minusflag = 1; - /* FIXME: use strtol */ + /* FIXME: use xstrtol */ adjustment = atoi (&s[2]); adjustment_given = 1; ++optind; } + else if (s[0] == '-' && ISDIGIT (s[1])) + { + if (!isinteger (&s[1])) + error (1, 0, _("invalid option `%s'"), s); + /* FIXME: use xstrtol */ + adjustment = atoi (&s[1]); + adjustment_given = 1; + ++optind; + } else { - if (s[0] == '-' && ISDIGIT (s[1])) + int optc; + if ((optc = getopt_long (argc, argv, "+n:", + longopts, (int *) 0)) != EOF) { - if (!isinteger (&s[1])) - error (1, 0, _("invalid option `%s'"), s); - /* FIXME: use strtol */ - adjustment = atoi (&s[1]); - adjustment_given = 1; - ++optind; - } - else - { - int optc; - while ((optc = getopt_long (argc, argv, "+n:", - longopts, (int *) 0)) != EOF) + switch (optc) { - switch (optc) - { - case '?': - usage (1); - - case 'n': - if (!isinteger (optarg)) - error (1, 0, _("invalid priority `%s'"), optarg); - /* FIXME: use strtol */ - adjustment = atoi (optarg); - adjustment_given = 1; - break; - } + case '?': + usage (1); + + case 'n': + if (!isinteger (optarg)) + error (1, 0, _("invalid priority `%s'"), optarg); + /* FIXME: use xstrtol */ + adjustment = atoi (optarg); + adjustment_given = 1; + break; } - - if (optc == EOF) - break; } + + if (optc == EOF) + break; } } @@ -143,6 +140,7 @@ main (int argc, char **argv) exit (0); } + printf ("adjustment = %d\n", adjustment); #ifndef NICE_PRIORITY errno = 0; current_priority = GET_PRIORITY (); |