]> git.sur5r.net Git - cc65/blobdiff - src/cc65/pragma.c
Move default segment names into segnames.h
[cc65] / src / cc65 / pragma.c
index b26ef7bc81d7ea989fea8cee011f419f50beb097..9a546efc7254d837ba693f827f2514779a665098 100644 (file)
@@ -37,6 +37,7 @@
 #include <string.h>
 
 /* common */
+#include "segdefs.h"
 #include "tgttrans.h"
 
 /* cc65 */
@@ -47,7 +48,6 @@
 #include "litpool.h"
 #include "scanner.h"
 #include "scanstrbuf.h"
-#include "segments.h"
 #include "symtab.h"
 #include "pragma.h"
 
@@ -175,7 +175,7 @@ static void SegNamePragma (StrBuf* B, segment_t Seg)
 
     } else {
        Error ("String literal expected");
-    }             
+    }
 
     /* Call the string buf destructor */
     DoneStrBuf (&S);
@@ -186,33 +186,36 @@ static void SegNamePragma (StrBuf* B, segment_t Seg)
 static void CharMapPragma (StrBuf* B)
 /* Change the character map */
 {
-    unsigned Index, C;
-
-    ExprDesc Val;
+    long Index, C;
 
     /* Read the character index */
-    ConstIntExpr (&Val);
-    if (Val.ConstVal < 1 || Val.ConstVal > 255) {
-       Error ("Character index out of range");
-       Index = 'A';
-    } else {
-       Index = Val.ConstVal;
+    if (!SB_GetNumber (B, &Index)) {
+        return;
+    }
+    if (Index < 1 || Index > 255) {
+       Error ("Character index out of range");
+       return;
     }
 
     /* Comma follows */
-    ConsumeComma ();
+    SB_SkipWhite (B);
+    if (SB_Get (B) != ',') {
+        Error ("Comma expected");
+        return;
+    }
+    SB_SkipWhite (B);
 
     /* Read the character code */
-    ConstIntExpr (&Val);
-    if (Val.ConstVal < 1 || Val.ConstVal > 255) {
+    if (!SB_GetNumber (B, &C)) {
+        return;
+    }
+    if (C < 1 || C > 255) {
        Error ("Character code out of range");
-       C = 'A';
-    } else {
-       C = Val.ConstVal;
+       return;
     }
 
     /* Remap the character */
-    TgtTranslateSet (Index, C);
+    TgtTranslateSet ((unsigned) Index, (unsigned char) C);
 }
 
 
@@ -221,14 +224,9 @@ static void FlagPragma (StrBuf* B, unsigned char* Flag)
 /* Handle a pragma that expects a boolean paramater */
 {
     ident Ident;
+    long  Val;
 
-    if (SB_Peek (B) == '0') {
-        SB_Skip (B);
-        *Flag = 0;
-    } else if (SB_Peek (B) == '1') {
-        SB_Skip (B);
-        *Flag = 1;
-    } else if (SB_GetSym (B, Ident)) {
+    if (SB_GetSym (B, Ident)) {
         if (strcmp (Ident, "true") == 0 || strcmp (Ident, "on") == 0) {
             *Flag = 1;
         } else if (strcmp (Ident, "false") == 0 || strcmp (Ident, "off") == 0) {
@@ -236,6 +234,8 @@ static void FlagPragma (StrBuf* B, unsigned char* Flag)
         } else {
             Error ("Pragma argument must be one of `on', `off', `true' or `false'");
         }
+    } else if (SB_GetNumber (B, &Val)) {
+       *Flag = (Val != 0);
     } else {
         Error ("Invalid pragma argument");
     }
@@ -346,9 +346,15 @@ static void ParsePragma (void)
         Error ("')' expected");
         return;
     }
+    SB_SkipWhite (&B);
+
+    /* Allow an optional semicolon to be compatible with the old syntax */
+    if (SB_Peek (&B) == ';') {
+        SB_Skip (&B);
+        SB_SkipWhite (&B);
+    }
 
     /* Make sure nothing follows */
-    SB_SkipWhite (&B);
     if (SB_Peek (&B) != '\0') {
         Error ("Unexpected input following pragma directive");
     }