make: Accept character # in command lines - scc - simple c99 compiler (HTM) git clone git://git.simple-cc.org/scc (DIR) Log (DIR) Files (DIR) Refs (DIR) Submodules (DIR) README (DIR) LICENSE --- (DIR) commit 333469edcd129d9bbc25832d900d27d3b6a340eb (DIR) parent 21c3b7490331139d994775aa00fe96f407cf960e (HTM) Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Sun, 21 Jan 2024 11:41:52 +0100 make: Accept character # in command lines The specification allows the use of the character # in command lines, allowing comments only in the first column of the line. To allow that we cannot handle comments in nextline() and we have to move the logic about comments to the different places where the lines are read, and add the correct different handling in every case. Diffstat: M src/cmd/make/parser.c | 42 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) --- (DIR) diff --git a/src/cmd/make/parser.c b/src/cmd/make/parser.c @@ -267,17 +267,6 @@ end: free(fil); } -static void -comment(FILE *fp) -{ - int c; - - while ((c = getc(fp)) != EOF && c != '\n') { - if (c == '\\' && getc(fp) == EOF) - break; - } -} - static char * nextline(void) { @@ -300,11 +289,6 @@ repeat: *s++ = '\n'; break; } - if (c == '#') { - comment(fp); - *s++ = '\n'; - break; - } if (c > UCHAR_MAX || c < 0) error("invalid character '%c' (%d)", c, c); } @@ -377,6 +361,17 @@ back(int c) } static void +comment(void) +{ + int c; + + while ((c = nextc()) != EOF && c != '\n') { + if (c == '\\' && nextc() == EOF) + break; + } +} + +static void skipspaces(void) { int c; @@ -653,6 +648,9 @@ repeat: back(c); expansion(NULL); goto repeat; + case '#': + comment(); + c = '\n'; case ';': case ':': case '=': @@ -685,6 +683,10 @@ readmacrodef(void) line = erealloc(line, n+1); if (c == '\n') break; + if (c == '#') { + comment(); + break; + } if (c == '\\') { if ((c = nextc()) != '\n') { back(c); @@ -761,7 +763,13 @@ rule(char *targets[], int ntargets) actions[nactions-1] = readcmd(); } - while ((c = nextc()) == '\t') { + for (;;) { + if ((c = nextc()) == '#') { + comment(); + continue; + } + if (c != '\t') + break; nactions++; actions = erealloc(actions, nactions * sizeof(char *)); actions[nactions-1] = readcmd();