From: Yu Watanabe Date: Mon, 6 Jan 2025 19:06:35 +0000 (+0900) Subject: pretty-print: make cat_file() also highlight the trailing backslash for line continuation X-Git-Tag: v258-rc1~1519^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e244e724f7990436d5ec099abab780d9317b6d1;p=thirdparty%2Fsystemd.git pretty-print: make cat_file() also highlight the trailing backslash for line continuation --- diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index e7360352b36..4eb4858931e 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -250,13 +250,23 @@ static int cat_file(const char *filename, bool newline, CatFlags flags) { /* Check if the line ends with a backslash. */ bool escaped = false; - for (const char *e = line; *e != '\0'; e++) { + char *e; + for (e = line; *e != '\0'; e++) { if (escaped) escaped = false; else if (*e == '\\') escaped = true; } + /* Highlight the trailing backslash. */ + if (escaped) { + assert(e > line); + *(e-1) = '\0'; + + if (!strextend(&line, ansi_highlight_red(), "\\", ansi_normal())) + return log_oom(); + } + /* Highlight the left side (directive) of a Foo=bar assignment */ if (FLAGS_SET(flags, CAT_FORMAT_HAS_SECTIONS) && !continued) { const char *p = strchr(line, '=');