X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Fsegment.c;h=9c2c9b11e8eba18e34b13f40124e3eb3439a97ae;hb=76e0b3df102f54672f8d4dfcc19c144e52a8ff4e;hp=2689811593f4b515682e21c8c315d4a44562d9b4;hpb=e246f73b3dfceae79a23056fee0a18bb4a08bc33;p=pspp diff --git a/src/language/lexer/segment.c b/src/language/lexer/segment.c index 2689811593..9c2c9b11e8 100644 --- a/src/language/lexer/segment.c +++ b/src/language/lexer/segment.c @@ -1579,11 +1579,33 @@ find_enddefine (struct substring input) { size_t n = input.length; const struct substring enddefine = ss_cstr ("!ENDDEFINE"); - for (size_t i = 0; i + enddefine.length <= n; i++) - if (input.string[i] == '!' - && ss_equals_case (ss_substr (input, i, enddefine.length), enddefine)) - return i; - return SIZE_MAX; + for (int ofs = 0;;) + { + /* Skip !ENDDEFINE in comment. */ + ofs = skip_spaces_and_comments (input.string, n, true, ofs); + if (ofs + enddefine.length > n) + return SIZE_MAX; + + char c = input.string[ofs]; + if (c == '!' + && ss_equals_case (ss_substr (input, ofs, enddefine.length), + enddefine)) + return ofs; + else if (c == '\'' || c == '"') + { + /* Skip quoted !ENDDEFINE. */ + ofs++; + for (;;) + { + if (ofs >= n) + return SIZE_MAX; + else if (input.string[ofs++] == c) + break; + } + } + else + ofs++; + } } /* We are in the body of a macro definition, looking for additional lines of