From bf7f690202a78bc4e1588302f9ba6a10a4c273af Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 26 Feb 2023 17:30:15 -0500 Subject: Directly handle $\ line endings Previously we used the fact that this line ending expanded to "$ " which would then expand to the empty string. This has problems if you enable warnings for undefined variables, so directly implement this special (but documented) trick in the GNU Make parser. As a side-effect this also removes all previous whitespace when in GNU Make mode (not in POSIX mode) just as it would without "$". * src/misc.c (collapse_continuations): Check for "$\" and remove it. * tests/scripts/variables/flavors: Add regression tests including with previous whitespace, and escaped/unescaped "$" --- src/misc.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/misc.c b/src/misc.c index c362e87e..80fd63ac 100644 --- a/src/misc.c +++ b/src/misc.c @@ -131,7 +131,7 @@ collapse_continuations (char *line) char *q; q = strchr(in, '\n'); - if (q == 0) + if (!q) return; do @@ -162,17 +162,33 @@ collapse_continuations (char *line) if (i & 1) { - /* Backslash/newline handling: - In traditional GNU Make all trailing whitespace, consecutive - backslash/newlines, and any leading non-newline whitespace on the - next line is reduced to a single space. - In POSIX, each backslash/newline and is replaced by a space. */ + unsigned int dollar; + + /* Backslash/newline handling: out points to the final "\". + In POSIX, each backslash/newline is replaced by a space. + In GNU Make all trailing whitespace, consecutive backslash + + newlines, and any leading non-newline whitespace on the next line + is reduced to a single space. + As a special case, replace "$\" with the empty string. */ while (ISBLANK (*in)) ++in; - if (! posix_pedantic) + + { + const char *dp = out; + while (dp > line && dp[-1] == '$') + --dp; + dollar = (out - dp) % 2; + } + + if (dollar) + --out; + + if (!posix_pedantic) while (out > line && ISBLANK (out[-1])) --out; - *out++ = ' '; + + if (!dollar) + *out++ = ' '; } else { -- cgit v1.2.1