From eb0992cd2850cbb12690c5cc74425d4ef7251556 Mon Sep 17 00:00:00 2001 From: Steven Schubiger Date: Sun, 3 Mar 2013 13:34:44 +0100 Subject: Don't print pair of sequences at end-of-file --- colorize.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'colorize.c') diff --git a/colorize.c b/colorize.c index 20f0c09..a3e9b03 100644 --- a/colorize.c +++ b/colorize.c @@ -561,15 +561,17 @@ process_file_option (const char *file_string, const char **file, FILE **stream) assert (*stream); } -#define MERGE_PRINT_LINE(part_line, line, flags) do { \ - char *merged_line = NULL; \ - if (part_line) \ - { \ - merged_line = str_concat (part_line, line); \ - free_null (part_line); \ - } \ - print_line (colors, bold, merged_line ? merged_line : line, flags); \ - free (merged_line); \ +#define MERGE_PRINT_LINE(part_line, line, flags, check_eof) do { \ + char *current_line, *merged_line = NULL; \ + if (part_line) \ + { \ + merged_line = str_concat (part_line, line); \ + free_null (part_line); \ + } \ + current_line = merged_line ? merged_line : (char *)line; \ + if (!check_eof || *current_line != '\0') \ + print_line (colors, bold, current_line, flags); \ + free (merged_line); \ } while (false); static void @@ -642,11 +644,11 @@ read_print_stream (bool bold, const struct color **colors, const char *file, FIL p = eol + SKIP_LINE_ENDINGS (flags); } *eol = '\0'; - MERGE_PRINT_LINE (part_line, line, flags); + MERGE_PRINT_LINE (part_line, line, flags, false); line = p; } if (feof (stream)) { - MERGE_PRINT_LINE (part_line, line, 0); + MERGE_PRINT_LINE (part_line, line, 0, true); } else { -- cgit v1.2.3