]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pretty-print: make cat_file() also highlight the trailing backslash for line continuation
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 6 Jan 2025 19:06:35 +0000 (04:06 +0900)
committerLuca Boccassi <bluca@debian.org>
Wed, 22 Jan 2025 20:43:16 +0000 (20:43 +0000)
src/shared/pretty-print.c

index e7360352b361acdfc28cc24324f39b94c4c1ff19..4eb4858931e88b7292d37ccf1672008bb125e699 100644 (file)
@@ -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, '=');