File coreutils-output_delimiter.patch of Package coreutils.import5176
Index: src/cut.c
===================================================================
--- src/cut.c.orig 2011-09-20 14:41:53.301708252 +0200
+++ src/cut.c 2011-09-20 14:52:16.063215689 +0200
@@ -674,15 +674,19 @@ cut_bytes (FILE *stream)
static void
cut_characters_or_cut_bytes_no_split (FILE *stream)
{
- int idx; /* number of bytes or characters in the line so far. */
- char buf[MB_LEN_MAX + BUFSIZ]; /* For spooling a read byte sequence. */
- char *bufpos; /* Next read position of BUF. */
- size_t buflen; /* The length of the byte sequence in buf. */
- wint_t wc; /* A gotten wide character. */
- size_t mblength; /* The byte size of a multibyte character which shows
- as same character as WC. */
- mbstate_t state; /* State of the stream. */
- int convfail; /* 1, when conversion is failed. Otherwise 0. */
+ int idx; /* number of bytes or characters in the line so far. */
+ char buf[MB_LEN_MAX + BUFSIZ]; /* For spooling a read byte sequence. */
+ char *bufpos; /* Next read position of BUF. */
+ size_t buflen; /* The length of the byte sequence in buf. */
+ wint_t wc; /* A gotten wide character. */
+ size_t mblength; /* The byte size of a multibyte character which shows
+ as same character as WC. */
+ mbstate_t state; /* State of the stream. */
+ int convfail = 0; /* 1, when conversion is failed. Otherwise 0. */
+
+ /* Whether to begin printing delimiters between ranges for the current line.
+ Set after we've begun printing data corresponding to the first range. */
+ bool print_delimiter = false;
idx = 0;
buflen = 0;
@@ -705,12 +709,24 @@ cut_characters_or_cut_bytes_no_split (FI
{
putchar ('\n');
idx = 0;
+ print_delimiter = false;
}
else
{
+ bool range_start;
+ bool *rs = output_delimiter_specified ? &range_start : NULL;
idx += (operating_mode == byte_mode) ? mblength : 1;
- if (print_kth (idx, NULL))
- fwrite (bufpos, mblength, sizeof(char), stdout);
+ if (print_kth (idx, rs))
+ {
+ if (rs && *rs && print_delimiter)
+ {
+ fwrite (output_delimiter_string, sizeof (char),
+ output_delimiter_length, stdout);
+ }
+
+ print_delimiter = true;
+ fwrite (bufpos, mblength, sizeof(char), stdout);
+ }
}
buflen -= mblength;