+ print_line (bold, colors, line, 0);
+ }
+ }
+}
+
+static void
+merge_print_line (bool bold, const struct color **colors, const char *line, const char *p, FILE *stream)
+{
+ char *buf = NULL;
+ char *merged_part_line = NULL;
+ const char *part_line;
+
+ complete_part_line (p + 1, &buf, stream);
+
+ if (buf)
+ part_line = merged_part_line = str_concat (line, buf);
+ else
+ part_line = line;
+ free (buf);
+
+#ifdef TEST_MERGE_PART_LINE
+ printf ("%s", part_line);
+ free (merged_part_line);
+ exit (EXIT_SUCCESS);
+#else
+ print_line (bold, colors, part_line, 0);
+ free (merged_part_line);
+#endif
+}
+
+static void
+complete_part_line (const char *p, char **buf, FILE *stream)
+{
+ bool got_next_char = false, read_from_stream;
+ char ch;
+ unsigned long i = 0;
+ size_t size;
+
+ if (get_next_char (&ch, &p, stream, &read_from_stream))
+ {
+ if (ch == '[')
+ {
+ if (read_from_stream)
+ save_char (ch, buf, &i, &size);
+ }
+ else
+ {
+ if (read_from_stream)
+ ungetc ((int)ch, stream);
+ return; /* cancel */
+ }
+ }
+ else
+ return; /* cancel */
+
+ while (get_next_char (&ch, &p, stream, &read_from_stream))
+ {
+ if (isdigit (ch) || ch == ';')
+ {
+ if (read_from_stream)
+ save_char (ch, buf, &i, &size);
+ }
+ else /* read next character */
+ {
+ got_next_char = true;
+ break;
+ }
+ }
+
+ if (got_next_char)
+ {
+ if (ch == 'm')
+ {
+ if (read_from_stream)
+ save_char (ch, buf, &i, &size);
+ }
+ else
+ {
+ if (read_from_stream)
+ ungetc ((int)ch, stream);
+ return; /* cancel */