summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-02-23 01:03:55 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2016-02-23 01:05:10 -0800
commita7f5d3d6d671bb4e9117b1f72971a19eed135fed (patch)
tree2f993165a5edfc026e631e17ad3506475ae54de6 /src
parent4c1995f1b673b0e1eae73a9db4e28016b86dee9e (diff)
downloadcoreutils-a7f5d3d6d671bb4e9117b1f72971a19eed135fed.tar.xz
all: be less strict about usage if POSIX 2008
sort, tail, and uniq now support traditional usage like 'sort +2' and 'tail +10' on systems conforming to POSIX 1003.1-2008 and later. * NEWS: Document this. * doc/coreutils.texi (Standards conformance, tail invocation) (sort invocation, uniq invocation, touch invocation): Document new behavior, or behavior's dependence on POSIX 1003.1-2001. * src/sort.c (struct keyfield.traditional_used): Rename from obsolete_used, since implementations are now allowed to support it. All uses changed. (main): Allow traditional usage if _POSIX2_VERSION is 200809. * src/tail.c (parse_obsolete_option): Distinguish between traditional usage (which POSIX 2008 and later allows) and obsolete (which it still does not). * src/uniq.c (strict_posix2): New function. (main): Allow traditional usage if _POSIX2_VERSION is 200809. * tests/misc/tail.pl: Test for new behavior.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c17
-rw-r--r--src/tail.c11
-rw-r--r--src/uniq.c9
3 files changed, 23 insertions, 14 deletions
diff --git a/src/sort.c b/src/sort.c
index 62acb6298..aa52b7569 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -224,7 +224,7 @@ struct keyfield
bool month; /* Flag for comparison by month name. */
bool reverse; /* Reverse the sense of comparison. */
bool version; /* sort by version number */
- bool obsolete_used; /* obsolescent key option format is used. */
+ bool traditional_used; /* Traditional key option format is used. */
struct keyfield *next; /* Next keyfield to try. */
};
@@ -2394,7 +2394,7 @@ key_warnings (struct keyfield const *gkey, bool gkey_only)
for (key = keylist; key; key = key->next, keynum++)
{
- if (key->obsolete_used)
+ if (key->traditional_used)
{
size_t sword = key->sword;
size_t eword = key->eword;
@@ -4183,7 +4183,8 @@ main (int argc, char **argv)
size_t nthreads = 0;
size_t nfiles = 0;
bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
- bool obsolete_usage = (posix2_version () < 200112);
+ int posix_ver = posix2_version ();
+ bool traditional_usage = ! (200112 <= posix_ver && posix_ver < 200809);
char **files;
char *files_from = NULL;
struct Tokens tok;
@@ -4288,13 +4289,13 @@ main (int argc, char **argv)
{
/* Parse an operand as a file after "--" was seen; or if
pedantic and a file was seen, unless the POSIX version
- predates 1003.1-2001 and -c was not seen and the operand is
+ is not 1003.1-2001 and -c was not seen and the operand is
"-o FILE" or "-oFILE". */
int oi = -1;
if (c == -1
|| (posixly_correct && nfiles != 0
- && ! (obsolete_usage
+ && ! (traditional_usage
&& ! checkonly
&& optind != argc
&& argv[optind][0] == '-' && argv[optind][1] == 'o'
@@ -4315,8 +4316,8 @@ main (int argc, char **argv)
{
bool minus_pos_usage = (optind != argc && argv[optind][0] == '-'
&& ISDIGIT (argv[optind][1]));
- obsolete_usage |= minus_pos_usage && !posixly_correct;
- if (obsolete_usage)
+ traditional_usage |= minus_pos_usage && !posixly_correct;
+ if (traditional_usage)
{
/* Treat +POS1 [-POS2] as a key if possible; but silently
treat an operand as a file if it is not a valid +POS1. */
@@ -4356,7 +4357,7 @@ main (int argc, char **argv)
badfieldspec (optarg1,
N_("stray character in field spec"));
}
- key->obsolete_used = true;
+ key->traditional_used = true;
insertkey (key);
}
}
diff --git a/src/tail.c b/src/tail.c
index 2a72a93f0..caa54076a 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1981,7 +1981,6 @@ parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
const char *p;
const char *n_string;
const char *n_string_end;
- bool obsolete_usage;
int default_count = DEFAULT_N_LINES;
bool t_from_start;
bool t_count_lines = true;
@@ -1994,7 +1993,9 @@ parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
|| (3 <= argc && argc <= 4 && STREQ (argv[2], "--"))))
return false;
- obsolete_usage = (posix2_version () < 200112);
+ int posix_ver = posix2_version ();
+ bool obsolete_usage = posix_ver < 200112;
+ bool traditional_usage = obsolete_usage || 200809 <= posix_ver;
p = argv[1];
switch (*p++)
@@ -2003,8 +2004,8 @@ parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
return false;
case '+':
- /* Leading "+" is a file name in the non-obsolete form. */
- if (!obsolete_usage)
+ /* Leading "+" is a file name in the standard form. */
+ if (!traditional_usage)
return false;
t_from_start = true;
@@ -2014,7 +2015,7 @@ parse_obsolete_option (int argc, char * const *argv, uintmax_t *n_units)
/* In the non-obsolete form, "-" is standard input and "-c"
requires an option-argument. The obsolete multidigit options
are supported as a GNU extension even when conforming to
- POSIX 1003.1-2001, so don't complain about them. */
+ POSIX 1003.1-2001 or later, so don't complain about them. */
if (!obsolete_usage && !p[p[0] == 'c'])
return false;
diff --git a/src/uniq.c b/src/uniq.c
index 0e118da9d..896ce938f 100644
--- a/src/uniq.c
+++ b/src/uniq.c
@@ -226,6 +226,13 @@ Also, comparisons honor the rules specified by 'LC_COLLATE'.\n\
exit (status);
}
+static bool
+strict_posix2 (void)
+{
+ int posix_ver = posix2_version ();
+ return 200112 <= posix_ver && posix_ver < 200809;
+}
+
/* Convert OPT to size_t, reporting an error using MSGID if OPT is
invalid. Silently convert too-large values to SIZE_MAX. */
@@ -533,7 +540,7 @@ main (int argc, char **argv)
{
unsigned long int size;
if (optarg[0] == '+'
- && posix2_version () < 200112
+ && ! strict_posix2 ()
&& xstrtoul (optarg, NULL, 10, &size, "") == LONGINT_OK
&& size <= SIZE_MAX)
skip_chars = size;