From c0f16c531b797755b9fd50338d5447f14245c5c2 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 29 Jul 2000 12:03:29 +0000 Subject: [PATCH] Check segment in in #pragma for validity git-svn-id: svn://svn.cc65.org/cc65/trunk@223 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/error.c | 9 ++++---- src/cc65/error.h | 9 ++++---- src/cc65/pragma.c | 57 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/cc65/error.c b/src/cc65/error.c index 437b12763..a668814da 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -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", diff --git a/src/cc65/error.h b/src/cc65/error.h index e5e72ece2..0d4146342 100644 --- a/src/cc65/error.h +++ b/src/cc65/error.h @@ -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, diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index c88a95116..27ed3a53d 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -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 */ @@ -36,13 +36,14 @@ #include #include -#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: -- 2.39.5