From 5ce94c2964afb6e66070f6dbfc8b8de8ab1d77d0 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Sat, 24 May 1997 08:04:42 +0000 Subject: [PATCH] (literalchar): Fix the code for escaping \, " and '. (lex): Avoid trouble when there are many chars to discard in a char literal with just several chars in it. --- src/lex.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lex.c b/src/lex.c index 71922941..ad06ea6a 100644 --- a/src/lex.c +++ b/src/lex.c @@ -268,11 +268,11 @@ literalchar(pp, pcode, term) so that `\012' and `\n' can be interchangeable. */ p = *pp; - if (code >= 040 && code < 0177) - *p++ = code; - else if (code == '\\') {*p++ = '\\'; *p++ = '\\';} + if (code == '\\') {*p++ = '\\'; *p++ = '\\';} else if (code == '\'') {*p++ = '\\'; *p++ = '\'';} else if (code == '\"') {*p++ = '\\'; *p++ = '\"';} + else if (code >= 040 && code < 0177) + *p++ = code; else if (code == '\t') {*p++ = '\\'; *p++ = 't';} else if (code == '\n') {*p++ = '\\'; *p++ = 'n';} else if (code == '\r') {*p++ = '\\'; *p++ = 'r';} @@ -381,6 +381,7 @@ lex() { int code, discode; char discard[10], *dp; + p = token_buffer; *p++ = '\''; literalchar(&p, &code, '\''); @@ -389,8 +390,12 @@ lex() if (c != '\'') { warn(_("use \"...\" for multi-character literal tokens")); - dp = discard; - while (literalchar(&dp, &discode, '\'')) {} + while (1) + { + dp = discard; + if (! literalchar(&dp, &discode, '\'')) + break; + } } *p++ = '\''; *p = 0; -- 2.45.2