aboutsummaryrefslogtreecommitdiffstats
path: root/colorize.c
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2013-03-03 13:34:44 +0100
committerGravatar Steven Schubiger <stsc@refcnt.org> 2013-03-03 13:34:44 +0100
commiteb0992cd2850cbb12690c5cc74425d4ef7251556 (patch)
tree132a6ebc5bc8e6b9b7e5428e4fc85ef5994bd903 /colorize.c
parent02ee8b6227ea13399a77f5d4d4853d75633de5c8 (diff)
downloadcolorize-eb0992cd2850cbb12690c5cc74425d4ef7251556.tar.gz
colorize-eb0992cd2850cbb12690c5cc74425d4ef7251556.tar.bz2
Don't print pair of sequences at end-of-file
Diffstat (limited to 'colorize.c')
-rw-r--r--colorize.c24
1 files changed, 13 insertions, 11 deletions
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
{