]> git.sur5r.net Git - cc65/commitdiff
Check segment in in #pragma for validity
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 29 Jul 2000 12:03:29 +0000 (12:03 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 29 Jul 2000 12:03:29 +0000 (12:03 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@223 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/error.c
src/cc65/error.h
src/cc65/pragma.c

index 437b127630199f6591cd65da0e2bf7b1ef12b247..a668814dacd84e089418694fbcef564a0f9fd05a 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -136,6 +136,7 @@ static char* ErrMsg [ERR_COUNT-1] = {
     "Illegal character constant",
     "Illegal modifier",
     "Illegal storage class",
+    "Illegal segment name: `%s'",
     "Division by zero",
     "Modulo operation with zero",
     "Range error",
index e5e72ece207c0ac8344b8300079d1ec043b6db82..0d41463424f6119c1ba8c3926a121e2259fcdc3f 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -131,6 +131,7 @@ enum Errors {
     ERR_ILLEGAL_CHARCONST,
     ERR_ILLEGAL_MODIFIER,
     ERR_ILLEGAL_STORAGE_CLASS,
+    ERR_ILLEGAL_SEG_NAME,
     ERR_DIV_BY_ZERO,
     ERR_MOD_BY_ZERO,
     ERR_RANGE,
index c88a951160d661d0b1ae98e199206aad26d342d2..27ed3a53d86c22730313517ba8b4b0863e4cfdd2 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 1998-2000 Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #include <stdlib.h>
 #include <ctype.h>
 
-#include "global.h"
+#include "codegen.h"
 #include "error.h"
+#include "expr.h"
+#include "global.h"
 #include "litpool.h"
-#include "symtab.h"
 #include "scanner.h"
-#include "codegen.h"
-#include "expr.h"
+#include "segname.h"
+#include "symtab.h"
 #include "pragma.h"
 
 
@@ -134,6 +135,38 @@ static void StringPragma (void (*Func) (const char*))
 
 
 
+static void SegNamePragma (void (*Func) (const char*))
+/* Handle a pragma that expects a segment name parameter */
+{
+    if (curtok != TOK_SCONST) {
+       Error (ERR_STRLIT_EXPECTED);
+    } else {
+       /* Get the segment name */
+       const char* Name = GetLiteral (curval);
+
+       /* Check if the name is valid */
+       if (ValidSegName (Name)) {
+
+                   /* Call the given function to set the name */
+           Func (Name);
+
+       } else {
+                          
+           /* Segment name is invalid */
+           Error (ERR_ILLEGAL_SEG_NAME, Name);
+
+       }
+
+       /* Reset the string pointer, removing the string from the pool */
+       ResetLiteralOffs (curval);
+    }
+
+    /* Skip the string (or error) token */
+    NextToken ();
+}
+
+
+
 static void FlagPragma (unsigned char* Flag)
 /* Handle a pragma that expects a boolean paramater */
 {
@@ -180,15 +213,15 @@ void DoPragma (void)
     switch (Pragma) {
 
        case PR_BSSSEG:
-           StringPragma (g_bssname);
+           SegNamePragma (g_bssname);
            break;
 
        case PR_CODESEG:
-           StringPragma (g_codename);
+           SegNamePragma (g_codename);
            break;
 
        case PR_DATASEG:
-           StringPragma (g_dataname);
+           SegNamePragma (g_dataname);
            break;
 
        case PR_REGVARADDR:
@@ -196,7 +229,7 @@ void DoPragma (void)
            break;
 
        case PR_RODATASEG:
-           StringPragma (g_rodataname);
+           SegNamePragma (g_rodataname);
            break;
 
        case PR_SIGNEDCHARS: