From 4228ba6e8a3dc0c4b5d8872edd36e1501ec8a4a5 Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Mon, 16 Oct 2023 10:16:59 +0100 Subject: [PATCH] Ignore end-of-line comments in quoted strings. --- src/frontend/inpcom.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index f3ede2101..8e5ffe1d2 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -3184,8 +3184,6 @@ static void inp_stripcomments_deck(struct card *c, bool cf) If there is only white space before the end-of-line comment the the whole line is converted to a normal comment line (i.e. one that begins with a '*'). - BUG: comment characters in side of string literals are not ignored - ('$' outside of .control section is o.k. however). If the comaptibility mode is PS, LTPS or LTPSA, '$' is treated as a valid character, not as end-of-line comment delimiter, except for that it is @@ -3202,6 +3200,24 @@ static void inp_stripcomments_line(char *s, bool cs) /* look for comments */ while ((c = *d) != '\0') { d++; + + /* Skip over single or double-quoted strings. */ + + if (c == '"') { + while ((c = *d) && (c != '"' || d[-1] == '\\')) + ++d; + if (c) + ++d; + continue; + } + if (c == '\'') { + while ((c = *d) && (c != '\'' || d[-1] == '\\')) + ++d; + if (c) + ++d; + continue; + } + if (*d == ';') { break; }