]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Before, this command would make uniq skip 11 fields and print
authorJim Meyering <jim@meyering.net>
Thu, 17 Mar 2005 14:27:12 +0000 (14:27 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 17 Mar 2005 14:27:12 +0000 (14:27 +0000)
only the first line.

  $ _POSIX2_VERSION=1 ./uniq -f1 -1 <(seq --format='1 %g' 2)
  1 1
  1 2

(main): Interpret `uniq -f1 -1' like `uniq -f1', not like `uniq -f11'.

src/uniq.c

index 344245a1ce1e422e5daad1c6aa6fffd4d191e814..a21a5a41c87ee7e56469a270e9f2ff5cb0ef5319 100644 (file)
@@ -401,12 +401,19 @@ check_file (const char *infile, const char *outfile)
   free (lb2.buffer);
 }
 
+enum Skip_field_option_type
+  {
+    SFO_NONE,
+    SFO_OBSOLETE,
+    SFO_NEW
+  };
+
 int
 main (int argc, char **argv)
 {
   int optc = 0;
   bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
-  bool obsolete_skip_fields = false;
+  enum Skip_field_option_type skip_field_option_type = SFO_NONE;
   int nfiles = 0;
   char const *file[2];
 
@@ -481,11 +488,14 @@ main (int argc, char **argv)
        case '9':
          {
            size_t s = skip_fields;
+           if (skip_field_option_type == SFO_NEW)
+             s = 0;
+
            skip_fields = s * 10 + optc - '0';
            if (SIZE_MAX / 10 < s || skip_fields < s)
              error (EXIT_FAILURE, 0, "%s",
                     _("invalid number of fields to skip"));
-           obsolete_skip_fields = true;
+           skip_field_option_type = SFO_OBSOLETE;
          }
          break;
 
@@ -509,6 +519,7 @@ main (int argc, char **argv)
          break;
 
        case 'f':               /* Like '-#'. */
+         skip_field_option_type = SFO_NEW;
          skip_fields = size_opt (optarg,
                                  N_("invalid number of fields to skip"));
          break;
@@ -540,7 +551,7 @@ main (int argc, char **argv)
        }
     }
 
-  if (obsolete_skip_fields && 200112 <= posix2_version ())
+  if (skip_fields == SFO_OBSOLETE && 200112 <= posix2_version ())
     {
       error (0, 0, _("`-%lu' option is obsolete; use `-f %lu'"),
             (unsigned long int) skip_fields, (unsigned long int) skip_fields);