summaryrefslogtreecommitdiff
path: root/src/pr.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-11-19 15:15:38 +0000
committerJim Meyering <jim@meyering.net>2000-11-19 15:15:38 +0000
commitf2f5e30bc2f37fbdf79239df5ed857abefb7bd15 (patch)
tree5604e2c5e7d48c1d02964d465bfc769d084aa792 /src/pr.c
parent6c1ee8402c6b8f375e38fd101c6932e33ce0a539 (diff)
downloadcoreutils-f2f5e30bc2f37fbdf79239df5ed857abefb7bd15.tar.xz
(main): Do not assume EOF == -1.
Handle the case correctly when digits options immediately precede a non-option.
Diffstat (limited to 'src/pr.c')
-rw-r--r--src/pr.c63
1 files changed, 23 insertions, 40 deletions
diff --git a/src/pr.c b/src/pr.c
index 7184fb96e..8681957e9 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -861,57 +861,40 @@ main (int argc, char **argv)
? (char **) xmalloc ((argc - 1) * sizeof (char *))
: NULL);
- while (1)
+ while ((c = getopt_long (argc, argv,
+ "-0123456789abcde::fFh:i::Jl:mn::N:o:rs::S::tTvw:W:",
+ long_options, NULL))
+ != -1)
{
- c = getopt_long (argc, argv,
- "-0123456789abcde::fFh:i::Jl:mn::N:o:rs::S::tTvw:W:",
- long_options, NULL);
- if (c == 1) /* Non-option argument. */
+ if (ISDIGIT (c))
{
- char *s;
- s = optarg;
- if (*s == '+')
- {
- /* long option --page dominates old `+FIRST_PAGE ...' */
- if (first_page_number > 0 || last_page_number > 0)
- continue;
- ++s;
- first_last_page (s);
- }
- else
- {
- file_names[n_files++] = optarg;
- }
+ accum = accum * 10 + c - '0';
+ continue;
}
- else
+
+ if (accum > 0)
{
- if (ISDIGIT (c))
- {
- accum = accum * 10 + c - '0';
- continue;
- }
- else
- {
- if (accum > 0)
- {
- columns = accum;
- explicit_columns = TRUE;
- accum = 0;
- }
- }
+ columns = accum;
+ explicit_columns = TRUE;
+ accum = 0;
}
- if (c == 1)
- continue;
-
- if (c == EOF)
- break;
-
switch (c)
{
case 0: /* getopt long option */
break;
+ case 1: /* Non-option argument. */
+ if (*optarg == '+')
+ {
+ /* long option --page dominates old `+FIRST_PAGE ...' */
+ if (first_page_number <= 0 && last_page_number <= 0)
+ first_last_page (optarg);
+ }
+ else
+ file_names[n_files++] = optarg;
+ break;
+
case PAGES_OPTION: /* --pages=FIRST_PAGE[:LAST_PAGE] */
{ /* dominates old opt +... */
if (optarg)