From 0aceca8673c1d9a8bc34faa460389768efa08eb7 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 1 Nov 2022 14:18:00 +0000 Subject: make: comments in macro expansions and command lines The POSIX specification says: There are three kinds of comments: blank lines, empty lines, and a ('#') and all following characters up to the first unescaped character. Most implementations don't treat '#' in a macro expansion or a command line as the start of a comment. POSIX doesn't mention either of these exceptions. Permit the exceptions as a non-POSIX extension. --- miscutils/make.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'miscutils') diff --git a/miscutils/make.c b/miscutils/make.c index 111ab2914..daad75f5c 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -1120,7 +1120,11 @@ process_line(char *s) r = s; // Strip comment - t = strchr(s, '#'); + // don't treat '#' in macro expansion as a comment + if (!posix) + t = find_char(s, '#'); + else + t = strchr(s, '#'); if (t) *t = '\0'; @@ -1401,9 +1405,18 @@ static char * process_command(char *s) { char *t, *u; - int len = strlen(s) + 1; - char *outside = xzalloc(len); + int len; + char *outside; + + if (posix) { + // POSIX strips comments from command lines + t = strchr(s, '#'); + if (t) + *t = '\0'; + } + len = strlen(s) + 1; + outside = xzalloc(len); for (t = skip_macro(s); *t; t = skip_macro(t + 1)) { outside[t - s] = 1; } -- cgit v1.2.3-55-g6feb