]> git.sur5r.net Git - cc65/commitdiff
Allow escape sequences prefixed by '%' in strings. '%%' denotes a single
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 20 Mar 2010 17:48:15 +0000 (17:48 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 20 Mar 2010 17:48:15 +0000 (17:48 +0000)
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

index d84ab27f0c9c86868360ab3a8bf04c7fcbef3636..b27ec62c5f7661c79f8cfc9e7ba29ba9a9686f74 100644 (file)
@@ -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 '#':