]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Do not assume EOF == -1.
authorJim Meyering <jim@meyering.net>
Sun, 19 Nov 2000 15:15:38 +0000 (15:15 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 19 Nov 2000 15:15:38 +0000 (15:15 +0000)
Handle the case correctly when digits options immediately precede a
non-option.

src/pr.c

index 7184fb96eafbd97fa82fe4d7307166aa2ce9d3f4..8681957e9dcfedd209581606e05258fcd3bbc1ee 100644 (file)
--- 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)