From 346a1b23518a7270ca90c9d5ec3f8b5e256796d2 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 2 Nov 1994 05:04:17 +0000 Subject: [PATCH] (cut_bytes): Print at least a newline for every line of input. (cut_fields): Print a newline even for lines whose only selected field is empty. But print nothing when using -s without -f1. And print nothing for empty input. Reported by Richard_Sharman@software.mitel.com. --- src/cut.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cut.c b/src/cut.c index 0087880e49..755de7390c 100644 --- a/src/cut.c +++ b/src/cut.c @@ -495,9 +495,7 @@ cut_bytes (stream) FILE *stream; { int byte_idx; /* Number of chars in the line so far. */ - int printed_from_curr_line; - printed_from_curr_line = 0; byte_idx = 0; while (1) { @@ -505,21 +503,22 @@ cut_bytes (stream) c = getc (stream); - if (c == '\n' || c == EOF) + if (c == '\n') { - if (printed_from_curr_line) - putchar ('\n'); - if (c == EOF) - break; - printed_from_curr_line = 0; + putchar ('\n'); byte_idx = 0; } + else if (c == EOF) + { + if (byte_idx > 0) + putchar ('\n'); + break; + } else { ++byte_idx; if (print_kth (byte_idx)) { - printed_from_curr_line = 1; putchar (c); } } @@ -620,7 +619,8 @@ cut_fields (stream) ++field_idx; else if (c == '\n' || c == EOF) { - if (found_any_selected_field) + if (found_any_selected_field + || !(suppress_non_delimited && field_idx == 1)) putchar ('\n'); if (c == EOF) break; -- 2.47.3