summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2016-01-08 15:42:56 +0000
committerPádraig Brady <P@draigBrady.com>2016-01-13 10:59:56 +0000
commit0e46753d7c9519d7378cd3a4e0951a36ac32ffe7 (patch)
treeec8de30ef6b0ef37cf149f11c1c690d1dc4c66ae /src
parentf3b4def577c4eee22f83b72d1310aa1d9155908d (diff)
downloadcoreutils-0e46753d7c9519d7378cd3a4e0951a36ac32ffe7.tar.xz
comm: support NUL --output-delimiter for consistency
* src/comm.c (main): Track the output delimiter length, so that it can be adjusted to 1 for the NUL delimiter. Also rename the global variable from "delimiter" to "col_sep" so its use is more obvious, and to distinguish from the recently added "delim" global variable. * tests/misc/comm.pl: Adjust accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/comm.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/comm.c b/src/comm.c
index e66ac81ef..802bf909a 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -71,9 +71,9 @@ static enum
} check_input_order;
/* Output columns will be delimited with this string, which may be set
- on the command-line with --output-delimiter=STR. The default is a
- single TAB character. */
-static char const *delimiter;
+ on the command-line with --output-delimiter=STR. */
+static char const *col_sep = "\t";
+static size_t col_sep_len = 0;
/* For long options that have no equivalent short option, use a
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
@@ -174,20 +174,17 @@ writeline (struct linebuffer const *line, FILE *stream, int class)
case 2:
if (!only_file_2)
return;
- /* Print a delimiter if we are printing lines from file 1. */
if (only_file_1)
- fputs (delimiter, stream);
+ fwrite (col_sep, 1, col_sep_len, stream);
break;
case 3:
if (!both)
return;
- /* Print a delimiter if we are printing lines from file 1. */
if (only_file_1)
- fputs (delimiter, stream);
- /* Print a delimiter if we are printing lines from file 2. */
+ fwrite (col_sep, 1, col_sep_len, stream);
if (only_file_2)
- fputs (delimiter, stream);
+ fwrite (col_sep, 1, col_sep_len, stream);
break;
}
@@ -419,14 +416,10 @@ main (int argc, char **argv)
break;
case OUTPUT_DELIMITER_OPTION:
- if (delimiter && !STREQ (delimiter, optarg))
- error (EXIT_FAILURE, 0, _("multiple delimiters specified"));
- delimiter = optarg;
- if (!*delimiter)
- {
- error (EXIT_FAILURE, 0, _("empty %s not allowed"),
- quote ("--output-delimiter"));
- }
+ if (col_sep_len && !STREQ (col_sep, optarg))
+ error (EXIT_FAILURE, 0, _("multiple output delimiters specified"));
+ col_sep = optarg;
+ col_sep_len = *optarg ? strlen (optarg) : 1;
break;
case_GETOPT_HELP_CHAR;
@@ -437,6 +430,9 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
+ if (! col_sep_len)
+ col_sep_len = 1;
+
if (argc - optind < 2)
{
if (argc <= optind)
@@ -452,10 +448,6 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
- /* The default delimiter is a TAB. */
- if (!delimiter)
- delimiter = "\t";
-
compare_files (argv + optind);
if (issued_disorder_warning[0] || issued_disorder_warning[1])