From b759e753e415134f6889383afcaee65b70f3023a Mon Sep 17 00:00:00 2001 From: uz Date: Sat, 20 Mar 2010 17:23:51 +0000 Subject: [PATCH] Changed the type of CfgSVal to a string buffer and removed the upper limit for the length. git-svn-id: svn://svn.cc65.org/cc65/trunk@4627 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ld65/cfgexpr.c | 12 +++++++----- src/ld65/config.c | 45 +++++++++++++++++++++++++-------------------- src/ld65/scanner.c | 37 +++++++++++++------------------------ src/ld65/scanner.h | 11 +++++++---- 4 files changed, 52 insertions(+), 53 deletions(-) diff --git a/src/ld65/cfgexpr.c b/src/ld65/cfgexpr.c index 2a59bfa37..6d06389a4 100644 --- a/src/ld65/cfgexpr.c +++ b/src/ld65/cfgexpr.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2005-2008, Ullrich von Bassewitz */ +/* (C) 2005-2010, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -123,13 +123,15 @@ static void Factor (CfgExpr* E) case CFGTOK_IDENT: /* An identifier - search an export with the given name */ - Sym = FindExport (GetStringId (CfgSVal)); + Sym = FindExport (GetStrBufId (&CfgSVal)); if (Sym == 0) { - CfgError ("Unknown symbol in expression: `%s'", CfgSVal); + CfgError ("Unknown symbol in expression: `%s'", + SB_GetConstBuf (&CfgSVal)); } /* We can only handle constants */ if (!IsConstExport (Sym)) { - CfgError ("Value for symbol `%s' is not constant", CfgSVal); + CfgError ("Value for symbol `%s' is not constant", + SB_GetConstBuf (&CfgSVal)); } /* Use the symbol value */ @@ -149,7 +151,7 @@ static void Factor (CfgExpr* E) case CFGTOK_STRCON: /* A string constant */ - SB_CopyStr (&E->SVal, CfgSVal); + SB_Copy (&E->SVal, &CfgSVal); E->Type = ceString; CfgNextTok (); break; diff --git a/src/ld65/config.c b/src/ld65/config.c index c626f38c1..75cfdc0ab 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ +/* (C) 1998-2010 Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -203,7 +203,7 @@ static Memory* CfgFindMemory (unsigned Name) static Memory* CfgGetMemory (unsigned Name) /* Find the memory are with the given name. Print an error on an invalid name */ { - Memory* M = CfgFindMemory (Name); + Memory* M = CfgFindMemory (Name); if (M == 0) { CfgError ("Invalid memory area `%s'", GetString (Name)); } @@ -423,7 +423,7 @@ static void ParseMemory (void) while (CfgTok == CFGTOK_IDENT) { /* Create a new entry on the heap */ - Memory* M = NewMemory (GetStringId (CfgSVal)); + Memory* M = NewMemory (GetStrBufId (&CfgSVal)); /* Skip the name and the following colon */ CfgNextTok (); @@ -467,7 +467,7 @@ static void ParseMemory (void) FlagAttr (&M->Attr, MA_FILE, "FILE"); CfgAssureStr (); /* Get the file entry and insert the memory area */ - FileInsert (GetFile (GetStringId (CfgSVal)), M); + FileInsert (GetFile (GetStrBufId (&CfgSVal)), M); CfgNextTok (); break; @@ -553,9 +553,10 @@ static void ParseFiles (void) CfgAssureStr (); /* Search for the file, it must exist */ - F = FindFile (GetStringId (CfgSVal)); + F = FindFile (GetStrBufId (&CfgSVal)); if (F == 0) { - CfgError ("File `%s' not found in MEMORY section", CfgSVal); + CfgError ("File `%s' not found in MEMORY section", + SB_GetConstBuf (&CfgSVal)); } /* Skip the token and the following colon */ @@ -654,7 +655,7 @@ static void ParseSegments (void) SegDesc* S; /* Create a new entry on the heap */ - S = NewSegDesc (GetStringId (CfgSVal)); + S = NewSegDesc (GetStrBufId (&CfgSVal)); /* Skip the name and the following colon */ CfgNextTok (); @@ -707,7 +708,7 @@ static void ParseSegments (void) case CFGTOK_LOAD: FlagAttr (&S->Attr, SA_LOAD, "LOAD"); - S->Load = CfgGetMemory (GetStringId (CfgSVal)); + S->Load = CfgGetMemory (GetStrBufId (&CfgSVal)); CfgNextTok (); break; @@ -728,7 +729,7 @@ static void ParseSegments (void) case CFGTOK_RUN: FlagAttr (&S->Attr, SA_RUN, "RUN"); - S->Run = CfgGetMemory (GetStringId (CfgSVal)); + S->Run = CfgGetMemory (GetStrBufId (&CfgSVal)); CfgNextTok (); break; @@ -907,17 +908,19 @@ static void ParseO65 (void) /* We expect an identifier */ CfgAssureIdent (); /* Convert the string into a string index */ - CfgSValId = GetStringId (CfgSVal); + CfgSValId = GetStrBufId (&CfgSVal); /* Check if the export symbol is also defined as an import. */ if (O65GetImport (O65FmtDesc, CfgSValId) != 0) { - CfgError ("Exported symbol `%s' cannot be an import", CfgSVal); + CfgError ("Exported symbol `%s' cannot be an import", + SB_GetConstBuf (&CfgSVal)); } /* Check if we have this symbol defined already. The entry * routine will check this also, but we get a more verbose * error message when checking it here. */ if (O65GetExport (O65FmtDesc, CfgSValId) != 0) { - CfgError ("Duplicate exported symbol: `%s'", CfgSVal); + CfgError ("Duplicate exported symbol: `%s'", + SB_GetConstBuf (&CfgSVal)); } /* Insert the symbol into the table */ O65SetExport (O65FmtDesc, CfgSValId); @@ -931,17 +934,19 @@ static void ParseO65 (void) /* We expect an identifier */ CfgAssureIdent (); /* Convert the string into a string index */ - CfgSValId = GetStringId (CfgSVal); + CfgSValId = GetStrBufId (&CfgSVal); /* Check if the imported symbol is also defined as an export. */ if (O65GetExport (O65FmtDesc, CfgSValId) != 0) { - CfgError ("Imported symbol `%s' cannot be an export", CfgSVal); + CfgError ("Imported symbol `%s' cannot be an export", + SB_GetConstBuf (&CfgSVal)); } /* Check if we have this symbol defined already. The entry * routine will check this also, but we get a more verbose * error message when checking it here. */ if (O65GetImport (O65FmtDesc, CfgSValId) != 0) { - CfgError ("Duplicate imported symbol: `%s'", CfgSVal); + CfgError ("Duplicate imported symbol: `%s'", + SB_GetConstBuf (&CfgSVal)); } /* Insert the symbol into the table */ O65SetImport (O65FmtDesc, CfgSValId); @@ -1144,7 +1149,7 @@ static void ParseConDes (void) /* We expect an identifier */ CfgAssureIdent (); /* Remember the value for later */ - SegName = GetStringId (CfgSVal); + SegName = GetStrBufId (&CfgSVal); break; case CFGTOK_LABEL: @@ -1153,7 +1158,7 @@ static void ParseConDes (void) /* We expect an identifier */ CfgAssureIdent (); /* Remember the value for later */ - Label = GetStringId (CfgSVal); + Label = GetStrBufId (&CfgSVal); break; case CFGTOK_COUNT: @@ -1162,8 +1167,8 @@ static void ParseConDes (void) /* We expect an identifier */ CfgAssureIdent (); /* Remember the value for later */ - Count = GetStringId (CfgSVal); - break; + Count = GetStrBufId (&CfgSVal); + break; case CFGTOK_TYPE: /* Don't allow this twice */ @@ -1359,7 +1364,7 @@ static void ParseSymbols (void) Export* E; /* Remember the name */ - unsigned Name = GetStringId (CfgSVal); + unsigned Name = GetStrBufId (&CfgSVal); CfgNextTok (); /* Support both, old and new syntax here. New syntax is a colon diff --git a/src/ld65/scanner.c b/src/ld65/scanner.c index 35a7addf9..d84ab27f0 100644 --- a/src/ld65/scanner.c +++ b/src/ld65/scanner.c @@ -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 */ @@ -167,9 +167,6 @@ static unsigned DigitVal (int C) void CfgNextTok (void) /* Read the next token from the input stream */ { - unsigned I; - - Again: /* Skip whitespace */ while (isspace (C)) { @@ -184,14 +181,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; } @@ -292,18 +287,16 @@ Again: case '\"': NextChar (); - I = 0; + SB_Clear (&CfgSVal); while (C != '\"') { if (C == EOF || C == '\n') { CfgError ("Unterminated string"); } - if (I < CFG_MAX_IDENT_LEN) { - CfgSVal [I++] = C; - } + SB_AppendChar (&CfgSVal, C); NextChar (); } NextChar (); - CfgSVal [I] = '\0'; + SB_Terminate (&CfgSVal); CfgTok = CFGTOK_STRCON; break; @@ -325,11 +318,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 +445,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; } } diff --git a/src/ld65/scanner.h b/src/ld65/scanner.h index f7f6caca5..b27bf4ef9 100644 --- a/src/ld65/scanner.h +++ b/src/ld65/scanner.h @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 1998-2005 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 1998-2010 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -38,6 +38,10 @@ +#include "strbuf.h" + + + /*****************************************************************************/ /* Data */ /*****************************************************************************/ @@ -148,9 +152,8 @@ struct IdentTok { /* Current token and attributes */ -#define CFG_MAX_IDENT_LEN 255 extern cfgtok_t CfgTok; -extern char CfgSVal [CFG_MAX_IDENT_LEN+1]; +extern StrBuf CfgSVal; extern unsigned long CfgIVal; /* Error location */ -- 2.39.2