]> git.sur5r.net Git - cc65/blobdiff - src/ld65/scanner.c
Some changes in debug info generation.
[cc65] / src / ld65 / scanner.c
index 35a7addf9ae2b66c0789b8993624cff95f35e795..b27ec62c5f7661c79f8cfc9e7ba29ba9a9686f74 100644 (file)
@@ -59,7 +59,7 @@
 
 /* Current token and attributes */
 cfgtok_t       CfgTok;
-char                   CfgSVal [CFG_MAX_IDENT_LEN+1];
+StrBuf          CfgSVal = STATIC_STRBUF_INITIALIZER;
 unsigned long   CfgIVal;
 
 /* Error location */
@@ -164,12 +164,75 @@ static unsigned DigitVal (int C)
 
 
 
-void CfgNextTok (void)
-/* Read the next token from the input stream */
+static void StrVal (void)
+/* Parse a string value and expand escape sequences */
 {
-    unsigned I;
+    /* 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 */
+{
 Again:
     /* Skip whitespace */
     while (isspace (C)) {
@@ -184,14 +247,12 @@ Again:
     if (C == '_' || IsAlpha (C)) {
 
        /* Read the identifier */
-       I = 0;
+       SB_Clear (&CfgSVal);
        while (C == '_' || IsAlNum (C)) {
-           if (I < CFG_MAX_IDENT_LEN) {
-               CfgSVal [I++] = C;
-           }
+            SB_AppendChar (&CfgSVal, C);
            NextChar ();
        }
-       CfgSVal [I] = '\0';
+               SB_Terminate (&CfgSVal);
        CfgTok = CFGTOK_IDENT;
        return;
     }
@@ -291,20 +352,7 @@ Again:
            break;
 
         case '\"':
-           NextChar ();
-           I = 0;
-           while (C != '\"') {
-               if (C == EOF || C == '\n') {
-                   CfgError ("Unterminated string");
-               }
-               if (I < CFG_MAX_IDENT_LEN) {
-                   CfgSVal [I++] = C;
-               }
-               NextChar ();
-           }
-                   NextChar ();
-           CfgSVal [I] = '\0';
-           CfgTok = CFGTOK_STRCON;
+            StrVal ();
            break;
 
         case '#':
@@ -325,11 +373,11 @@ Again:
                case 'O':
                    NextChar ();
                    if (OutputName) {
-                       strncpy (CfgSVal, OutputName, CFG_MAX_IDENT_LEN);
-                       CfgSVal [CFG_MAX_IDENT_LEN] = '\0';
+                        SB_CopyStr (&CfgSVal, OutputName);
                    } else {
-                       CfgSVal [0] = '\0';
+                       SB_Clear (&CfgSVal);
                    }
+                    SB_Terminate (&CfgSVal);
                    CfgTok = CFGTOK_STRCON;
                    break;
 
@@ -452,16 +500,12 @@ void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name)
     if (CfgTok == CFGTOK_IDENT) {
 
        /* Make it upper case */
-       I = 0;
-       while (CfgSVal [I]) {
-           CfgSVal [I] = toupper (CfgSVal [I]);
-           ++I;
-       }
+        SB_ToUpper (&CfgSVal);
 
                /* Linear search */
        for (I = 0; I < Size; ++I) {
-           if (strcmp (CfgSVal, Table [I].Ident) == 0) {
-               CfgTok = Table [I].Tok;
+                   if (SB_CompareStr (&CfgSVal, Table[I].Ident) == 0) {
+               CfgTok = Table[I].Tok;
                return;
            }
        }