[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#7305: sort command not working in version 5.5 as it did in 4.7
From: |
Paul Eggert |
Subject: |
bug#7305: sort command not working in version 5.5 as it did in 4.7 |
Date: |
Wed, 17 Nov 2010 15:51:59 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.15) Gecko/20101027 Thunderbird/3.0.10 |
On 11/17/10 14:33, Pádraig Brady wrote:
> Note it scans command line args twice which
> adds some overhead in all cases.
> The first scan is to find --debug so we're not
> dependent on the position of --debug
I have some qualms about that patch. It's not just the extra overhead:
the patch causes --debug to change the semantics of argument processing
(as opposed to merely outputting debugging info), which could lead to
Heisenbugs. "The script started working when I added --debug"
is a bug report that we never want to hear.
Also, if we want to suggest portable usage, it's better to suggest ./+FOO
rather than -- FOO, as the former is a bit shorter and works better with
pre-POSIX sorts.
How about something like the following patch instead, along with the obvious
changes to the test cases that you proposed?
diff --git a/src/sort.c b/src/sort.c
index 7e25f6a..86cd51c 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -3990,6 +3990,7 @@ main (int argc, char **argv)
bool need_random = false;
unsigned long int nthreads = 0;
size_t nfiles = 0;
+ size_t unprotected_file_names = 0;
bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
bool obsolete_usage = (posix2_version () < 200112);
char **files;
@@ -4113,6 +4114,7 @@ main (int argc, char **argv)
if (argc <= optind)
break;
files[nfiles++] = argv[optind++];
+ unprotected_file_names += (c != -1);
}
else switch (c)
{
@@ -4165,7 +4167,10 @@ main (int argc, char **argv)
}
}
if (! key)
- files[nfiles++] = optarg;
+ {
+ files[nfiles++] = optarg;
+ unprotected_file_names++;
+ }
break;
case SORT_OPTION:
@@ -4470,6 +4475,15 @@ main (int argc, char **argv)
quote (setlocale (LC_COLLATE, NULL)));
else
error (0, 0, _("using simple byte comparison"));
+
+ for (size_t i = 0; i < unprotected_file_names; i++)
+ if (files[i][0] == '+')
+ {
+ char const *q = quotearg_style (shell_quoting_style, files[i]);
+ error (0, 0, _("Unportable file name %s; use ./%s instead"),
+ q, q);
+ }
+
key_warnings (&gkey, gkey_only);
}
- bug#7305: sort command not working in version 5.5 as it did in 4.7,
Paul Eggert <=