diff options
author | Jim Meyering <jim@meyering.net> | 2005-03-17 14:27:12 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2005-03-17 14:27:12 +0000 |
commit | cee4fe1969a01cff621976f14545c27a0629dc53 (patch) | |
tree | 39ea304bbf280e3f65f392ee78107823883f9447 | |
parent | 581b437d32ead17ed2deab9c995406b74624170f (diff) | |
download | coreutils-cee4fe1969a01cff621976f14545c27a0629dc53.tar.xz |
Before, this command would make uniq skip 11 fields and print
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'.
-rw-r--r-- | src/uniq.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/uniq.c b/src/uniq.c index 344245a1c..a21a5a41c 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -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); |