From 4166236b533b4e30a4f7d3fd2984415b2a512752 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 2 Feb 2002 09:53:26 +0000 Subject: Add more support for POSIX 1003.1-2001, which requires removal for support of obsolete "-N" option syntax in expand, head, fold, split, tail, unexpand, uniq, and which prohibits options with optional arguments in od and pr. (usage): Document this. (shortopts): New constant. (main): Check for obsolete options. --- src/uniq.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/uniq.c b/src/uniq.c index b3b16ffb3..26e2b7501 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -107,6 +107,12 @@ static enum delimit_method const delimit_method_map[] = /* Select whether/how to delimit groups of duplicate lines. */ static enum delimit_method delimit_groups; +static char const shortopts[] = "-cdDf:is:uw:" +#if POSIX2_VERSION < 200112 +"0123456789" +#endif +; + static struct option const longopts[] = { {"count", no_argument, NULL, 'c'}, @@ -157,11 +163,11 @@ Mandatory arguments to long options are mandatory for short options too.\n\ "), stdout); fputs (_("\ -w, --check-chars=N compare no more than N characters in lines\n\ - -N same as -f N\n\ "), stdout); if (POSIX2_VERSION < 200112) fputs (_("\ - +N same as -s N (obsolete; will be withdrawn)\n\ + -N (obsolete) same as -f N\n\ + +N (obsolete) same as -s N\n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); @@ -393,7 +399,8 @@ int main (int argc, char **argv) { int optc = 0; - int posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL); + bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL); + bool obsolete_skip_fields = false; int nfiles = 0; char const *file[2]; @@ -414,15 +421,12 @@ main (int argc, char **argv) for (;;) { - /* Parse an operand with leading "+" as a file after "--" was - seen; or if pedantic and a file was seen. POSIX 1003.1-200x - d7 removes support for such operands, so when it becomes - official the code will need to be changed. */ + /* If obsolete, parse an operand with leading "+" as a file + after "--" was seen; or if pedantic and a file was seen. */ if (optc == -1 || (posixly_correct && nfiles != 0) - || ((optc = getopt_long (argc, argv, - "-0123456789cdDf:is:uw:", longopts, NULL)) + || ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) == -1)) { if (optind == argc) @@ -444,7 +448,7 @@ main (int argc, char **argv) && xstrtoul (optarg, NULL, 10, &size, "") == LONGINT_OK && size <= SIZE_MAX) { - if (! posixly_correct) + if (OBSOLETE_OPTION_WARNINGS && ! posixly_correct) error (0, 0, _("warning: `uniq %s' is obsolete; use `uniq -s %s' instead"), optarg, optarg + 1); @@ -460,6 +464,7 @@ main (int argc, char **argv) } break; +#if POSIX2_VERSION < 200112 case '0': case '1': case '2': @@ -476,8 +481,10 @@ main (int argc, char **argv) if (SIZE_MAX / 10 < s || skip_fields < s) error (EXIT_FAILURE, 0, "%s", _("invalid number of fields to skip")); + obsolete_skip_fields = true; } break; +#endif case 'c': countmode = count_occurrences; @@ -529,6 +536,10 @@ main (int argc, char **argv) } } + if (OBSOLETE_OPTION_WARNINGS && obsolete_skip_fields) + error (0, 0, _("`uniq -%lu' is obsolete; use `uniq -f %lu'"), + (unsigned long) skip_fields, (unsigned long) skip_fields); + if (countmode == count_occurrences && mode == output_all_repeated) { error (0, 0, -- cgit v1.2.3-70-g09d2