From: jtvolpe Date: Sun, 20 May 2001 03:27:03 +0000 (+0000) Subject: Fixed octal and hex escape sequences in character and string constants X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=785e21d02e7f329fd922f8f8471ea56e4df94150;p=fw%2Fsdcc Fixed octal and hex escape sequences in character and string constants git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@831 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCC.lex b/src/SDCC.lex index b335a917..bb3e7a89 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -328,47 +328,67 @@ int check_type() char strLitBuff[2048] ; +/* + * Change by JTV 2001-05-19 to not concantenate strings + * to support ANSI hex and octal escape sequences in string liteals + */ + char *stringLiteral () + { - int ch; - char *str = strLitBuff ; - - *str++ = '\"' ; - /* put into the buffer till we hit the */ - /* first \" */ - while (1) { - - ch = input() ; - if (!ch) break ; /* end of input */ - /* if it is a \ then everything allowed */ - if (ch == '\\') { - *str++ = ch ; /* backslash in place */ - *str++ = input() ; /* following char in place */ - continue ; /* carry on */ - } - - /* if new line we have a new line break */ - if (ch == '\n') break ; - - /* if this is a quote then we have work to do */ - /* find the next non whitespace character */ - /* if that is a double quote then carry on */ - if (ch == '\"') { - - while ((ch = input()) && isspace(ch)) ; - if (!ch) break ; - if (ch != '\"') { - unput(ch) ; - break ; - } - - continue ; - } - *str++ = ch; - } - *str++ = '\"' ; - *str = '\0'; - return strLitBuff ; +int ch; +char *str = strLitBuff ; + +*str++ = '\"' ; +/* put into the buffer till we hit the */ +/* first \" */ + +while (1) + { + ch = input() ; + + if (!ch) + break ; /* end of input */ + + /* if it is a \ then everything allowed */ + + if (ch == '\\') + { + *str++ = ch ; /* backslash in place */ + *str++ = input() ; /* following char in place */ + continue ; /* carry on */ + } + + /* if new line we have a new line break */ + if (ch == '\n') + break ; + + /* if this is a quote then we have work to do */ + /* find the next non whitespace character */ + /* if that is a double quote then carry on */ + + if (ch == '\"') + { + *str++ = ch ; /* Pass end of this string or substring to evaluator */ + + while ((ch = input()) && isspace(ch)) ; + + if (!ch) + break ; + + if (ch != '\"') + { + unput(ch) ; + break ; + } + } + + *str++ = ch; /* Put next substring introducer into output string */ + } + +*str = '\0'; + +return strLitBuff ; } void doPragma (int op, char *cp)