mirror of
https://github.com/cc65/cc65.git
synced 2024-10-01 00:57:11 +00:00
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
This commit is contained in:
parent
bf12833d12
commit
b759e753e4
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2005-2008, Ullrich von Bassewitz */
|
/* (C) 2005-2010, Ullrich von Bassewitz */
|
||||||
/* Roemerstrasse 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -123,13 +123,15 @@ static void Factor (CfgExpr* E)
|
|||||||
|
|
||||||
case CFGTOK_IDENT:
|
case CFGTOK_IDENT:
|
||||||
/* An identifier - search an export with the given name */
|
/* An identifier - search an export with the given name */
|
||||||
Sym = FindExport (GetStringId (CfgSVal));
|
Sym = FindExport (GetStrBufId (&CfgSVal));
|
||||||
if (Sym == 0) {
|
if (Sym == 0) {
|
||||||
CfgError ("Unknown symbol in expression: `%s'", CfgSVal);
|
CfgError ("Unknown symbol in expression: `%s'",
|
||||||
|
SB_GetConstBuf (&CfgSVal));
|
||||||
}
|
}
|
||||||
/* We can only handle constants */
|
/* We can only handle constants */
|
||||||
if (!IsConstExport (Sym)) {
|
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 */
|
/* Use the symbol value */
|
||||||
@ -149,7 +151,7 @@ static void Factor (CfgExpr* E)
|
|||||||
|
|
||||||
case CFGTOK_STRCON:
|
case CFGTOK_STRCON:
|
||||||
/* A string constant */
|
/* A string constant */
|
||||||
SB_CopyStr (&E->SVal, CfgSVal);
|
SB_Copy (&E->SVal, &CfgSVal);
|
||||||
E->Type = ceString;
|
E->Type = ceString;
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2008 Ullrich von Bassewitz */
|
/* (C) 1998-2010 Ullrich von Bassewitz */
|
||||||
/* Roemerstrasse 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
@ -203,7 +203,7 @@ static Memory* CfgFindMemory (unsigned Name)
|
|||||||
static Memory* CfgGetMemory (unsigned Name)
|
static Memory* CfgGetMemory (unsigned Name)
|
||||||
/* Find the memory are with the given name. Print an error on an invalid 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) {
|
if (M == 0) {
|
||||||
CfgError ("Invalid memory area `%s'", GetString (Name));
|
CfgError ("Invalid memory area `%s'", GetString (Name));
|
||||||
}
|
}
|
||||||
@ -423,7 +423,7 @@ static void ParseMemory (void)
|
|||||||
while (CfgTok == CFGTOK_IDENT) {
|
while (CfgTok == CFGTOK_IDENT) {
|
||||||
|
|
||||||
/* Create a new entry on the heap */
|
/* Create a new entry on the heap */
|
||||||
Memory* M = NewMemory (GetStringId (CfgSVal));
|
Memory* M = NewMemory (GetStrBufId (&CfgSVal));
|
||||||
|
|
||||||
/* Skip the name and the following colon */
|
/* Skip the name and the following colon */
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
@ -467,7 +467,7 @@ static void ParseMemory (void)
|
|||||||
FlagAttr (&M->Attr, MA_FILE, "FILE");
|
FlagAttr (&M->Attr, MA_FILE, "FILE");
|
||||||
CfgAssureStr ();
|
CfgAssureStr ();
|
||||||
/* Get the file entry and insert the memory area */
|
/* Get the file entry and insert the memory area */
|
||||||
FileInsert (GetFile (GetStringId (CfgSVal)), M);
|
FileInsert (GetFile (GetStrBufId (&CfgSVal)), M);
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -553,9 +553,10 @@ static void ParseFiles (void)
|
|||||||
CfgAssureStr ();
|
CfgAssureStr ();
|
||||||
|
|
||||||
/* Search for the file, it must exist */
|
/* Search for the file, it must exist */
|
||||||
F = FindFile (GetStringId (CfgSVal));
|
F = FindFile (GetStrBufId (&CfgSVal));
|
||||||
if (F == 0) {
|
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 */
|
/* Skip the token and the following colon */
|
||||||
@ -654,7 +655,7 @@ static void ParseSegments (void)
|
|||||||
SegDesc* S;
|
SegDesc* S;
|
||||||
|
|
||||||
/* Create a new entry on the heap */
|
/* Create a new entry on the heap */
|
||||||
S = NewSegDesc (GetStringId (CfgSVal));
|
S = NewSegDesc (GetStrBufId (&CfgSVal));
|
||||||
|
|
||||||
/* Skip the name and the following colon */
|
/* Skip the name and the following colon */
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
@ -707,7 +708,7 @@ static void ParseSegments (void)
|
|||||||
|
|
||||||
case CFGTOK_LOAD:
|
case CFGTOK_LOAD:
|
||||||
FlagAttr (&S->Attr, SA_LOAD, "LOAD");
|
FlagAttr (&S->Attr, SA_LOAD, "LOAD");
|
||||||
S->Load = CfgGetMemory (GetStringId (CfgSVal));
|
S->Load = CfgGetMemory (GetStrBufId (&CfgSVal));
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -728,7 +729,7 @@ static void ParseSegments (void)
|
|||||||
|
|
||||||
case CFGTOK_RUN:
|
case CFGTOK_RUN:
|
||||||
FlagAttr (&S->Attr, SA_RUN, "RUN");
|
FlagAttr (&S->Attr, SA_RUN, "RUN");
|
||||||
S->Run = CfgGetMemory (GetStringId (CfgSVal));
|
S->Run = CfgGetMemory (GetStrBufId (&CfgSVal));
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -907,17 +908,19 @@ static void ParseO65 (void)
|
|||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Convert the string into a string index */
|
/* Convert the string into a string index */
|
||||||
CfgSValId = GetStringId (CfgSVal);
|
CfgSValId = GetStrBufId (&CfgSVal);
|
||||||
/* Check if the export symbol is also defined as an import. */
|
/* Check if the export symbol is also defined as an import. */
|
||||||
if (O65GetImport (O65FmtDesc, CfgSValId) != 0) {
|
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
|
/* Check if we have this symbol defined already. The entry
|
||||||
* routine will check this also, but we get a more verbose
|
* routine will check this also, but we get a more verbose
|
||||||
* error message when checking it here.
|
* error message when checking it here.
|
||||||
*/
|
*/
|
||||||
if (O65GetExport (O65FmtDesc, CfgSValId) != 0) {
|
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 */
|
/* Insert the symbol into the table */
|
||||||
O65SetExport (O65FmtDesc, CfgSValId);
|
O65SetExport (O65FmtDesc, CfgSValId);
|
||||||
@ -931,17 +934,19 @@ static void ParseO65 (void)
|
|||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Convert the string into a string index */
|
/* Convert the string into a string index */
|
||||||
CfgSValId = GetStringId (CfgSVal);
|
CfgSValId = GetStrBufId (&CfgSVal);
|
||||||
/* Check if the imported symbol is also defined as an export. */
|
/* Check if the imported symbol is also defined as an export. */
|
||||||
if (O65GetExport (O65FmtDesc, CfgSValId) != 0) {
|
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
|
/* Check if we have this symbol defined already. The entry
|
||||||
* routine will check this also, but we get a more verbose
|
* routine will check this also, but we get a more verbose
|
||||||
* error message when checking it here.
|
* error message when checking it here.
|
||||||
*/
|
*/
|
||||||
if (O65GetImport (O65FmtDesc, CfgSValId) != 0) {
|
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 */
|
/* Insert the symbol into the table */
|
||||||
O65SetImport (O65FmtDesc, CfgSValId);
|
O65SetImport (O65FmtDesc, CfgSValId);
|
||||||
@ -1144,7 +1149,7 @@ static void ParseConDes (void)
|
|||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Remember the value for later */
|
/* Remember the value for later */
|
||||||
SegName = GetStringId (CfgSVal);
|
SegName = GetStrBufId (&CfgSVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_LABEL:
|
case CFGTOK_LABEL:
|
||||||
@ -1153,7 +1158,7 @@ static void ParseConDes (void)
|
|||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Remember the value for later */
|
/* Remember the value for later */
|
||||||
Label = GetStringId (CfgSVal);
|
Label = GetStrBufId (&CfgSVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_COUNT:
|
case CFGTOK_COUNT:
|
||||||
@ -1162,8 +1167,8 @@ static void ParseConDes (void)
|
|||||||
/* We expect an identifier */
|
/* We expect an identifier */
|
||||||
CfgAssureIdent ();
|
CfgAssureIdent ();
|
||||||
/* Remember the value for later */
|
/* Remember the value for later */
|
||||||
Count = GetStringId (CfgSVal);
|
Count = GetStrBufId (&CfgSVal);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CFGTOK_TYPE:
|
case CFGTOK_TYPE:
|
||||||
/* Don't allow this twice */
|
/* Don't allow this twice */
|
||||||
@ -1359,7 +1364,7 @@ static void ParseSymbols (void)
|
|||||||
Export* E;
|
Export* E;
|
||||||
|
|
||||||
/* Remember the name */
|
/* Remember the name */
|
||||||
unsigned Name = GetStringId (CfgSVal);
|
unsigned Name = GetStrBufId (&CfgSVal);
|
||||||
CfgNextTok ();
|
CfgNextTok ();
|
||||||
|
|
||||||
/* Support both, old and new syntax here. New syntax is a colon
|
/* Support both, old and new syntax here. New syntax is a colon
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
/* Current token and attributes */
|
/* Current token and attributes */
|
||||||
cfgtok_t CfgTok;
|
cfgtok_t CfgTok;
|
||||||
char CfgSVal [CFG_MAX_IDENT_LEN+1];
|
StrBuf CfgSVal = STATIC_STRBUF_INITIALIZER;
|
||||||
unsigned long CfgIVal;
|
unsigned long CfgIVal;
|
||||||
|
|
||||||
/* Error location */
|
/* Error location */
|
||||||
@ -167,9 +167,6 @@ static unsigned DigitVal (int C)
|
|||||||
void CfgNextTok (void)
|
void CfgNextTok (void)
|
||||||
/* Read the next token from the input stream */
|
/* Read the next token from the input stream */
|
||||||
{
|
{
|
||||||
unsigned I;
|
|
||||||
|
|
||||||
|
|
||||||
Again:
|
Again:
|
||||||
/* Skip whitespace */
|
/* Skip whitespace */
|
||||||
while (isspace (C)) {
|
while (isspace (C)) {
|
||||||
@ -184,14 +181,12 @@ Again:
|
|||||||
if (C == '_' || IsAlpha (C)) {
|
if (C == '_' || IsAlpha (C)) {
|
||||||
|
|
||||||
/* Read the identifier */
|
/* Read the identifier */
|
||||||
I = 0;
|
SB_Clear (&CfgSVal);
|
||||||
while (C == '_' || IsAlNum (C)) {
|
while (C == '_' || IsAlNum (C)) {
|
||||||
if (I < CFG_MAX_IDENT_LEN) {
|
SB_AppendChar (&CfgSVal, C);
|
||||||
CfgSVal [I++] = C;
|
|
||||||
}
|
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
CfgSVal [I] = '\0';
|
SB_Terminate (&CfgSVal);
|
||||||
CfgTok = CFGTOK_IDENT;
|
CfgTok = CFGTOK_IDENT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -292,18 +287,16 @@ Again:
|
|||||||
|
|
||||||
case '\"':
|
case '\"':
|
||||||
NextChar ();
|
NextChar ();
|
||||||
I = 0;
|
SB_Clear (&CfgSVal);
|
||||||
while (C != '\"') {
|
while (C != '\"') {
|
||||||
if (C == EOF || C == '\n') {
|
if (C == EOF || C == '\n') {
|
||||||
CfgError ("Unterminated string");
|
CfgError ("Unterminated string");
|
||||||
}
|
}
|
||||||
if (I < CFG_MAX_IDENT_LEN) {
|
SB_AppendChar (&CfgSVal, C);
|
||||||
CfgSVal [I++] = C;
|
|
||||||
}
|
|
||||||
NextChar ();
|
NextChar ();
|
||||||
}
|
}
|
||||||
NextChar ();
|
NextChar ();
|
||||||
CfgSVal [I] = '\0';
|
SB_Terminate (&CfgSVal);
|
||||||
CfgTok = CFGTOK_STRCON;
|
CfgTok = CFGTOK_STRCON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -325,11 +318,11 @@ Again:
|
|||||||
case 'O':
|
case 'O':
|
||||||
NextChar ();
|
NextChar ();
|
||||||
if (OutputName) {
|
if (OutputName) {
|
||||||
strncpy (CfgSVal, OutputName, CFG_MAX_IDENT_LEN);
|
SB_CopyStr (&CfgSVal, OutputName);
|
||||||
CfgSVal [CFG_MAX_IDENT_LEN] = '\0';
|
|
||||||
} else {
|
} else {
|
||||||
CfgSVal [0] = '\0';
|
SB_Clear (&CfgSVal);
|
||||||
}
|
}
|
||||||
|
SB_Terminate (&CfgSVal);
|
||||||
CfgTok = CFGTOK_STRCON;
|
CfgTok = CFGTOK_STRCON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -452,16 +445,12 @@ void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name)
|
|||||||
if (CfgTok == CFGTOK_IDENT) {
|
if (CfgTok == CFGTOK_IDENT) {
|
||||||
|
|
||||||
/* Make it upper case */
|
/* Make it upper case */
|
||||||
I = 0;
|
SB_ToUpper (&CfgSVal);
|
||||||
while (CfgSVal [I]) {
|
|
||||||
CfgSVal [I] = toupper (CfgSVal [I]);
|
|
||||||
++I;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Linear search */
|
/* Linear search */
|
||||||
for (I = 0; I < Size; ++I) {
|
for (I = 0; I < Size; ++I) {
|
||||||
if (strcmp (CfgSVal, Table [I].Ident) == 0) {
|
if (SB_CompareStr (&CfgSVal, Table[I].Ident) == 0) {
|
||||||
CfgTok = Table [I].Tok;
|
CfgTok = Table[I].Tok;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 1998-2005 Ullrich von Bassewitz */
|
/* (C) 1998-2010 Ullrich von Bassewitz */
|
||||||
/* Römerstrasse 52 */
|
/* Roemerstrasse 52 */
|
||||||
/* D-70794 Filderstadt */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
@ -38,6 +38,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "strbuf.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Data */
|
/* Data */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@ -148,9 +152,8 @@ struct IdentTok {
|
|||||||
|
|
||||||
|
|
||||||
/* Current token and attributes */
|
/* Current token and attributes */
|
||||||
#define CFG_MAX_IDENT_LEN 255
|
|
||||||
extern cfgtok_t CfgTok;
|
extern cfgtok_t CfgTok;
|
||||||
extern char CfgSVal [CFG_MAX_IDENT_LEN+1];
|
extern StrBuf CfgSVal;
|
||||||
extern unsigned long CfgIVal;
|
extern unsigned long CfgIVal;
|
||||||
|
|
||||||
/* Error location */
|
/* Error location */
|
||||||
|
Loading…
Reference in New Issue
Block a user