mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-10 06:03:31 +02:00
comm: fix NUL --output-delimiter with --total
* src/comm.c (compare_files): Handle the single character --output-delimeter case separately so that NUL is appropriately handled. * doc/coreutils.texi (comm invocation): Fix the description of --output-delimiter to say an empty delimeter is treated as a NUL separator, rather than being disallowed. * tests/misc/comm.pl: Add a test case. Reported at https://bugs.debian.org/1014008
This commit is contained in:
@@ -5427,7 +5427,8 @@ Other options are:
|
||||
Print @var{str} between adjacent output columns,
|
||||
rather than the default of a single TAB character.
|
||||
|
||||
The delimiter @var{str} may not be empty.
|
||||
The delimiter @var{str} may be empty, in which case
|
||||
the ASCII NUL character is used to delimit output columns.
|
||||
|
||||
@item --total
|
||||
Output a summary at the end.
|
||||
|
||||
21
src/comm.c
21
src/comm.c
@@ -395,11 +395,22 @@ compare_files (char **infiles)
|
||||
char buf1[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
char buf2[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
char buf3[INT_BUFSIZE_BOUND (uintmax_t)];
|
||||
printf ("%s%s%s%s%s%s%s%c",
|
||||
umaxtostr (total[0], buf1), col_sep,
|
||||
umaxtostr (total[1], buf2), col_sep,
|
||||
umaxtostr (total[2], buf3), col_sep,
|
||||
_("total"), delim);
|
||||
if (col_sep_len == 1)
|
||||
{ /* Separate to handle NUL char. */
|
||||
printf ("%s%c%s%c%s%c%s%c",
|
||||
umaxtostr (total[0], buf1), *col_sep,
|
||||
umaxtostr (total[1], buf2), *col_sep,
|
||||
umaxtostr (total[2], buf3), *col_sep,
|
||||
_("total"), delim);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("%s%s%s%s%s%s%s%c",
|
||||
umaxtostr (total[0], buf1), col_sep,
|
||||
umaxtostr (total[1], buf2), col_sep,
|
||||
umaxtostr (total[2], buf3), col_sep,
|
||||
_("total"), delim);
|
||||
}
|
||||
}
|
||||
|
||||
if (issued_disorder_warning[0] || issued_disorder_warning[1])
|
||||
|
||||
@@ -157,6 +157,9 @@ my @Tests =
|
||||
{OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"} ],
|
||||
['zdelim-empty', '-z', '-z --output-delimiter=', @zinputs,
|
||||
{OUT=>"1\000\0002\000\0002\000\000\0003\000\000\0003\000\000\0003\000"} ],
|
||||
['total-delim-empty', '--total --output-delimiter=', @inputs,
|
||||
{OUT=>"1\n\0002\n\0002\n\000\0003\n\000\0003\n\000\0003\n"
|
||||
. "1\0002\0003\000total\n"} ],
|
||||
|
||||
# invalid dual delimiter
|
||||
['delim-dual', '--output-delimiter=,', '--output-delimiter=+', @inputs,
|
||||
|
||||
Reference in New Issue
Block a user