diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-01-08 15:14:01 +0000 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-01-13 10:59:56 +0000 |
commit | f3b4def577c4eee22f83b72d1310aa1d9155908d (patch) | |
tree | 8347150d38fc5230f76c5a2a074454c9e2ffb2b3 /src | |
parent | 826c98b02486dd9dbbab3d2381d5f778af42dd7a (diff) | |
download | coreutils-f3b4def577c4eee22f83b72d1310aa1d9155908d.tar.xz |
comm: add the -z,--zero-terminated option
* doc/coreutils.texi (comm invocation): Reference option description.
* src/comm.c (main): Use readlinebuffer_delim() to support
a parameterized delimiter.
* tests/misc/comm.pl: Add test cases.
* NEWS: Mention the new feature.
Diffstat (limited to 'src')
-rw-r--r-- | src/comm.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/comm.c b/src/comm.c index 89cee88fc..e66ac81ef 100644 --- a/src/comm.c +++ b/src/comm.c @@ -59,6 +59,9 @@ static bool seen_unpairable; /* If nonzero, we have warned about disorder in that file. */ static bool issued_disorder_warning[2]; +/* line delimiter. */ +static unsigned char delim = '\n'; + /* If nonzero, check that the input is correctly ordered. */ static enum { @@ -86,6 +89,7 @@ static struct option const long_options[] = {"check-order", no_argument, NULL, CHECK_ORDER_OPTION}, {"nocheck-order", no_argument, NULL, NOCHECK_ORDER_OPTION}, {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION}, + {"zero-terminated", no_argument, NULL, 'z'}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -131,6 +135,9 @@ and column three contains lines common to both files.\n\ fputs (_("\ --output-delimiter=STR separate columns with STR\n\ "), stdout); + fputs (_("\ + -z, --zero-terminated line delimiter is NUL, not newline\n\ +"), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); fputs (_("\ @@ -277,7 +284,8 @@ compare_files (char **infiles) fadvise (streams[i], FADVISE_SEQUENTIAL); - thisline[i] = readlinebuffer (all_line[i][alt[i][0]], streams[i]); + thisline[i] = readlinebuffer_delim (all_line[i][alt[i][0]], streams[i], + delim); if (ferror (streams[i])) error (EXIT_FAILURE, errno, "%s", quotef (infiles[i])); } @@ -336,7 +344,8 @@ compare_files (char **infiles) alt[i][1] = alt[i][0]; alt[i][0] = (alt[i][0] + 1) & 0x03; - thisline[i] = readlinebuffer (all_line[i][alt[i][0]], streams[i]); + thisline[i] = readlinebuffer_delim (all_line[i][alt[i][0]], + streams[i], delim); if (thisline[i]) check_order (all_line[i][alt[i][1]], thisline[i], i + 1); @@ -382,7 +391,7 @@ main (int argc, char **argv) issued_disorder_warning[0] = issued_disorder_warning[1] = false; check_input_order = CHECK_ORDER_DEFAULT; - while ((c = getopt_long (argc, argv, "123", long_options, NULL)) != -1) + while ((c = getopt_long (argc, argv, "123z", long_options, NULL)) != -1) switch (c) { case '1': @@ -397,6 +406,10 @@ main (int argc, char **argv) both = false; break; + case 'z': + delim = '\0'; + break; + case NOCHECK_ORDER_OPTION: check_input_order = CHECK_ORDER_DISABLED; break; |