summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2007-02-19 22:11:18 +0100
committerJim Meyering <jim@meyering.net>2007-02-19 22:11:18 +0100
commitc363fcb9f06cec38040cf4294521096aa70179d9 (patch)
treebce2a2960c9016ec2979efad9a1572c1f9471d83 /src
parente189deb855253b184b64fc1e532c2f00f438ae64 (diff)
downloadcoreutils-c363fcb9f06cec38040cf4294521096aa70179d9.tar.xz
* NEWS: sort now uses a --compress-program option rather than
an environment variable. * doc/coreutils.texi (sort invocation): Document this. * src/sort.c (usage): Likewise. (COMPRESS_PROGRAM_OPTION): New const. (long_options, create_temp, main): Support new option. * tests/misc/sort-compress: Test it.
Diffstat (limited to 'src')
-rw-r--r--src/sort.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/sort.c b/src/sort.c
index c7ae0c8c0..6a7de9c52 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -281,7 +281,7 @@ static bool have_read_stdin;
static struct keyfield *keylist;
/* Program used to (de)compress temp files. Must accept -d. */
-static const char *compress_program;
+static char const *compress_program;
static void sortlines_temp (struct line *, size_t, struct line *);
@@ -339,6 +339,8 @@ Other options:\n\
\n\
-c, --check, --check=diagnose-first check for sorted input; do not sort\n\
-C, --check=quiet, --check=silent like -c, but do not report first bad line\n\
+ --compress-program=PROG compress temporaries with PROG;\n\
+ decompress them with PROG -d\n\
-k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1)\n\
-m, --merge merge already sorted files; do not sort\n\
"), stdout);
@@ -390,6 +392,7 @@ native byte values.\n\
enum
{
CHECK_OPTION = CHAR_MAX + 1,
+ COMPRESS_PROGRAM_OPTION,
RANDOM_SOURCE_OPTION
};
@@ -399,6 +402,7 @@ static struct option const long_options[] =
{
{"ignore-leading-blanks", no_argument, NULL, 'b'},
{"check", optional_argument, NULL, CHECK_OPTION},
+ {"compress-program", required_argument, NULL, COMPRESS_PROGRAM_OPTION},
{"dictionary-order", no_argument, NULL, 'd'},
{"ignore-case", no_argument, NULL, 'f'},
{"general-numeric-sort", no_argument, NULL, 'g'},
@@ -839,29 +843,18 @@ pipe_fork (int pipefds[2], size_t tries)
static char *
create_temp (FILE **pfp, pid_t *ppid)
{
- static bool compress_program_known;
int tempfd;
struct tempnode *node = create_temp_file (&tempfd);
char *name = node->name;
- if (! compress_program_known)
+ if (! compress_program)
{
- compress_program = getenv ("GNUSORT_COMPRESSOR");
- if (compress_program == NULL)
- {
- static const char *default_program = "gzip";
- const char *path_program = find_in_path (default_program);
-
- if (path_program != default_program)
- compress_program = path_program;
- }
- else if (*compress_program == '\0')
- compress_program = NULL;
-
- compress_program_known = true;
+ static char const default_compress_program[] = "gzip";
+ char const *prog = find_in_path (default_compress_program);
+ compress_program = (prog == default_compress_program ? "" : prog);
}
- if (compress_program)
+ if (*compress_program)
{
int pipefds[2];
@@ -2946,6 +2939,12 @@ main (int argc, char **argv)
checkonly = c;
break;
+ case COMPRESS_PROGRAM_OPTION:
+ if (compress_program && strcmp (compress_program, optarg) != 0)
+ error (SORT_FAILURE, 0, _("multiple compress programs specified"));
+ compress_program = optarg;
+ break;
+
case 'k':
key = key_init (&key_buf);