]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
* src/sort.c (main): Support obsolete usages like "sort +1 -2" even when
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jun 2006 23:51:13 +0000 (23:51 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 28 Jun 2006 23:51:13 +0000 (23:51 +0000)
conforming to POSIX 1003.1-2001, since this is a pure extension to
POSIX.

src/sort.c

index d3a37f3d15ce91f71b46b8759c12cf9908a22e46..a266bd557e94414ee949bc4758415ff24037751e 100644 (file)
@@ -2320,37 +2320,42 @@ main (int argc, char **argv)
        {
        case 1:
          key = NULL;
-         if (obsolete_usage && optarg[0] == '+')
+         if (optarg[0] == '+')
            {
-             /* Treat +POS1 [-POS2] as a key if possible; but silently
-                treat an operand as a file if it is not a valid +POS1.  */
-             key = new_key ();
-             s = parse_field_count (optarg + 1, &key->sword, NULL);
-             if (s && *s == '.')
-               s = parse_field_count (s + 1, &key->schar, NULL);
-             if (! (key->sword | key->schar))
-               key->sword = SIZE_MAX;
-             if (! s || *set_ordering (s, key, bl_start))
+             bool minus_pos_usage = (optind != argc && argv[optind][0] == '-'
+                                     && ISDIGIT (argv[optind][1]));
+             obsolete_usage |= minus_pos_usage & ~posixly_correct;
+             if (obsolete_usage)
                {
-                 free (key);
-                 key = NULL;
-               }
-             else
-               {
-                 if (optind != argc && argv[optind][0] == '-'
-                     && ISDIGIT (argv[optind][1]))
+                 /* Treat +POS1 [-POS2] as a key if possible; but silently
+                    treat an operand as a file if it is not a valid +POS1.  */
+                 key = new_key ();
+                 s = parse_field_count (optarg + 1, &key->sword, NULL);
+                 if (s && *s == '.')
+                   s = parse_field_count (s + 1, &key->schar, NULL);
+                 if (! (key->sword | key->schar))
+                   key->sword = SIZE_MAX;
+                 if (! s || *set_ordering (s, key, bl_start))
+                   {
+                     free (key);
+                     key = NULL;
+                   }
+                 else
                    {
-                     char const *optarg1 = argv[optind++];
-                     s = parse_field_count (optarg1 + 1, &key->eword,
+                     if (minus_pos_usage)
+                       {
+                         char const *optarg1 = argv[optind++];
+                         s = parse_field_count (optarg1 + 1, &key->eword,
                                             N_("invalid number after `-'"));
-                     if (*s == '.')
-                       s = parse_field_count (s + 1, &key->echar,
+                         if (*s == '.')
+                           s = parse_field_count (s + 1, &key->echar,
                                               N_("invalid number after `.'"));
-                     if (*set_ordering (s, key, bl_end))
-                       badfieldspec (optarg1,
+                         if (*set_ordering (s, key, bl_end))
+                           badfieldspec (optarg1,
                                      N_("stray character in field spec"));
+                       }
+                     insertkey (key);
                    }
-                 insertkey (key);
                }
            }
          if (! key)