]> git.refcnt.org Git - colorize.git/commitdiff
Don't print pair of sequences at end-of-file
authorSteven Schubiger <stsc@refcnt.org>
Sun, 3 Mar 2013 12:34:44 +0000 (13:34 +0100)
committerSteven Schubiger <stsc@refcnt.org>
Sun, 3 Mar 2013 12:34:44 +0000 (13:34 +0100)
colorize.c

index 20f0c095c5a57073f7c510ac9c953490152e2ae6..a3e9b03e9a372bfb777f58121fd20a5318803100 100644 (file)
@@ -561,15 +561,17 @@ process_file_option (const char *file_string, const char **file, FILE **stream)
     assert (*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
 } 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';
                 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)) {
             line = p;
           }
         if (feof (stream)) {
-          MERGE_PRINT_LINE (part_line, line, 0);
+          MERGE_PRINT_LINE (part_line, line, 0, true);
         }
         else
           {
         }
         else
           {