summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-02-02 09:53:26 +0000
committerJim Meyering <jim@meyering.net>2002-02-02 09:53:26 +0000
commit4166236b533b4e30a4f7d3fd2984415b2a512752 (patch)
tree3c5a86af64a90dcf834b8fccaeb58ceea78259f5
parent1f6bad2b3091648d27855d211828f12332ec2474 (diff)
downloadcoreutils-4166236b533b4e30a4f7d3fd2984415b2a512752.tar.xz
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.
-rw-r--r--src/uniq.c31
1 files changed, 21 insertions, 10 deletions
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,