From 7450c25404f73a4f5b209198562788b748f159ba Mon Sep 17 00:00:00 2001 From: uz Date: Sat, 20 Mar 2010 17:48:15 +0000 Subject: [PATCH] Allow escape sequences prefixed by '%' in strings. '%%' denotes a single percent sign, %O is the name of the output file. git-svn-id: svn://svn.cc65.org/cc65/trunk@4628 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/scanner.c | 79 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/src/ld65/scanner.c b/src/ld65/scanner.c index d84ab27f0..b27ec62c5 100644 --- a/src/ld65/scanner.c +++ b/src/ld65/scanner.c @@ -164,6 +164,72 @@ static unsigned DigitVal (int C) +static void StrVal (void) +/* Parse a string value and expand escape sequences */ +{ + /* Skip the starting double quotes */ + NextChar (); + + /* Read input chars */ + SB_Clear (&CfgSVal); + while (C != '\"') { + switch (C) { + + case EOF: + case '\n': + CfgError ("Unterminated string"); + break; + + case '%': + NextChar (); + switch (C) { + + case EOF: + case '\n': + case '\"': + CfgError ("Unterminated '%%' escape sequence"); + break; + + case '%': + SB_AppendChar (&CfgSVal, '%'); + NextChar (); + break; + + case 'O': + /* Replace by output file */ + if (OutputName) { + SB_AppendStr (&CfgSVal, OutputName); + } + NextChar (); + break; + + default: + CfgWarning ("Unkown escape sequence `%%%c'", C); + SB_AppendChar (&CfgSVal, '%'); + SB_AppendChar (&CfgSVal, C); + NextChar (); + break; + } + break; + + default: + SB_AppendChar (&CfgSVal, C); + NextChar (); + } + } + + /* Skip the terminating double quotes */ + NextChar (); + + /* Terminate the string */ + SB_Terminate (&CfgSVal); + + /* We've read a string value */ + CfgTok = CFGTOK_STRCON; +} + + + void CfgNextTok (void) /* Read the next token from the input stream */ { @@ -286,18 +352,7 @@ Again: break; case '\"': - NextChar (); - SB_Clear (&CfgSVal); - while (C != '\"') { - if (C == EOF || C == '\n') { - CfgError ("Unterminated string"); - } - SB_AppendChar (&CfgSVal, C); - NextChar (); - } - NextChar (); - SB_Terminate (&CfgSVal); - CfgTok = CFGTOK_STRCON; + StrVal (); break; case '#': -- 2.39.5