1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-12 17:30:50 +00:00

Keep the config file position in a FilePos structure.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4847 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2010-11-10 19:52:40 +00:00
parent c695829813
commit 7c1094c086
6 changed files with 122 additions and 99 deletions

View File

@ -107,7 +107,7 @@ static ExprNode* Factor (void)
break; break;
default: default:
CfgError ("Invalid expression: %d", CfgTok); CfgError (&CfgErrorPos, "Invalid expression: %d", CfgTok);
break; break;
} }
@ -211,7 +211,7 @@ long CfgConstExpr (void)
/* Check that it's const */ /* Check that it's const */
if (!IsConstExpr (Expr)) { if (!IsConstExpr (Expr)) {
CfgError ("Constant expression expected"); CfgError (&CfgErrorPos, "Constant expression expected");
} }
/* Get the value */ /* Get the value */
@ -236,7 +236,7 @@ long CfgCheckedConstExpr (long Min, long Max)
/* Check the range */ /* Check the range */
if (Val < Min || Val > Max) { if (Val < Min || Val > Max) {
CfgError ("Range error"); CfgError (&CfgErrorPos, "Range error");
} }
/* Return the value */ /* Return the value */

View File

@ -117,9 +117,7 @@ static Collection SegDescList = STATIC_COLLECTION_INITIALIZER;
*/ */
typedef struct Symbol Symbol; typedef struct Symbol Symbol;
struct Symbol { struct Symbol {
const char* CfgName; /* Config file name */ FilePos Pos; /* Config file position */
unsigned CfgLine; /* Config file position */
unsigned CfgCol;
unsigned Name; /* Symbol name */ unsigned Name; /* Symbol name */
unsigned Flags; /* Symbol flags */ unsigned Flags; /* Symbol flags */
long Val; /* Symbol value if any */ long Val; /* Symbol value if any */
@ -216,7 +214,7 @@ static MemoryArea* CfgGetMemory (unsigned Name)
{ {
MemoryArea* M = CfgFindMemory (Name); MemoryArea* M = CfgFindMemory (Name);
if (M == 0) { if (M == 0) {
CfgError ("Invalid memory area `%s'", GetString (Name)); CfgError (&CfgErrorPos, "Invalid memory area `%s'", GetString (Name));
} }
return M; return M;
} }
@ -265,12 +263,10 @@ static Symbol* NewSymbol (unsigned Name, unsigned Flags, long Val)
Symbol* Sym = xmalloc (sizeof (Symbol)); Symbol* Sym = xmalloc (sizeof (Symbol));
/* Initialize the fields */ /* Initialize the fields */
Sym->CfgName = CfgGetName (); Sym->Pos = CfgErrorPos;
Sym->CfgLine = CfgErrorLine; Sym->Name = Name;
Sym->CfgCol = CfgErrorCol; Sym->Flags = Flags;
Sym->Name = Name; Sym->Val = Val;
Sym->Flags = Flags;
Sym->Val = Val;
/* Return the initialized struct */ /* Return the initialized struct */
return Sym; return Sym;
@ -310,17 +306,19 @@ static File* NewFile (unsigned Name)
static MemoryArea* CreateMemoryArea (unsigned Name) static MemoryArea* CreateMemoryArea (const FilePos* Pos, unsigned Name)
/* Create a new memory area and insert it into the list */ /* Create a new memory area and insert it into the list */
{ {
/* Check for duplicate names */ /* Check for duplicate names */
MemoryArea* M = CfgFindMemory (Name); MemoryArea* M = CfgFindMemory (Name);
if (M) { if (M) {
CfgError ("Memory area `%s' defined twice", GetString (Name)); CfgError (&CfgErrorPos,
"Memory area `%s' defined twice",
GetString (Name));
} }
/* Create a new memory area */ /* Create a new memory area */
M = NewMemoryArea (Name); M = NewMemoryArea (Pos, Name);
/* Insert the struct into the list ... */ /* Insert the struct into the list ... */
CollAppend (&MemoryAreas, M); CollAppend (&MemoryAreas, M);
@ -338,7 +336,7 @@ static SegDesc* NewSegDesc (unsigned Name)
/* Check for duplicate names */ /* Check for duplicate names */
SegDesc* S = CfgFindSegDesc (Name); SegDesc* S = CfgFindSegDesc (Name);
if (S) { if (S) {
CfgError ("Segment `%s' defined twice", GetString (Name)); CfgError (&CfgErrorPos, "Segment `%s' defined twice", GetString (Name));
} }
/* Allocate memory */ /* Allocate memory */
@ -380,7 +378,7 @@ static void FlagAttr (unsigned* Flags, unsigned Mask, const char* Name)
*/ */
{ {
if (*Flags & Mask) { if (*Flags & Mask) {
CfgError ("%s is already defined", Name); CfgError (&CfgErrorPos, "%s is already defined", Name);
} }
*Flags |= Mask; *Flags |= Mask;
} }
@ -391,7 +389,7 @@ static void AttrCheck (unsigned Attr, unsigned Mask, const char* Name)
/* Check that a mandatory attribute was given */ /* Check that a mandatory attribute was given */
{ {
if ((Attr & Mask) == 0) { if ((Attr & Mask) == 0) {
CfgError ("%s attribute is missing", Name); CfgError (&CfgErrorPos, "%s attribute is missing", Name);
} }
} }
@ -417,7 +415,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 */
MemoryArea* M = CreateMemoryArea (GetStrBufId (&CfgSVal)); MemoryArea* M = CreateMemoryArea (&CfgErrorPos, GetStrBufId (&CfgSVal));
/* Skip the name and the following colon */ /* Skip the name and the following colon */
CfgNextTok (); CfgNextTok ();
@ -528,7 +526,7 @@ static void ParseFiles (void)
{ "FORMAT", CFGTOK_FORMAT }, { "FORMAT", CFGTOK_FORMAT },
}; };
static const IdentTok Formats [] = { static const IdentTok Formats [] = {
{ "O65", CFGTOK_O65 }, { "O65", CFGTOK_O65 },
{ "BIN", CFGTOK_BIN }, { "BIN", CFGTOK_BIN },
{ "BINARY", CFGTOK_BIN }, { "BINARY", CFGTOK_BIN },
}; };
@ -536,7 +534,7 @@ static void ParseFiles (void)
/* The MEMORY section must preceed the FILES section */ /* The MEMORY section must preceed the FILES section */
if ((SectionsEncountered & SE_MEMORY) == 0) { if ((SectionsEncountered & SE_MEMORY) == 0) {
CfgError ("MEMORY must precede FILES"); CfgError (&CfgErrorPos, "MEMORY must precede FILES");
} }
/* Parse all files */ /* Parse all files */
@ -550,7 +548,8 @@ static void ParseFiles (void)
/* Search for the file, it must exist */ /* Search for the file, it must exist */
F = FindFile (GetStrBufId (&CfgSVal)); F = FindFile (GetStrBufId (&CfgSVal));
if (F == 0) { if (F == 0) {
CfgError ("File `%s' not found in MEMORY section", CfgError (&CfgErrorPos,
"File `%s' not found in MEMORY section",
SB_GetConstBuf (&CfgSVal)); SB_GetConstBuf (&CfgSVal));
} }
@ -576,7 +575,8 @@ static void ParseFiles (void)
case CFGTOK_FORMAT: case CFGTOK_FORMAT:
if (F->Format != BINFMT_DEFAULT) { if (F->Format != BINFMT_DEFAULT) {
/* We've set the format already! */ /* We've set the format already! */
Error ("Cannot set a file format twice"); CfgError (&CfgErrorPos,
"Cannot set a file format twice");
} }
/* Read the format token */ /* Read the format token */
CfgSpecialToken (Formats, ENTRY_COUNT (Formats), "Format"); CfgSpecialToken (Formats, ENTRY_COUNT (Formats), "Format");
@ -642,7 +642,7 @@ static void ParseSegments (void)
/* The MEMORY section must preceed the SEGMENTS section */ /* The MEMORY section must preceed the SEGMENTS section */
if ((SectionsEncountered & SE_MEMORY) == 0) { if ((SectionsEncountered & SE_MEMORY) == 0) {
CfgError ("MEMORY must precede SEGMENTS"); CfgError (&CfgErrorPos, "MEMORY must precede SEGMENTS");
} }
while (CfgTok == CFGTOK_IDENT) { while (CfgTok == CFGTOK_IDENT) {
@ -676,7 +676,7 @@ static void ParseSegments (void)
Val = CfgCheckedConstExpr (1, 0x10000); Val = CfgCheckedConstExpr (1, 0x10000);
S->Align = BitFind (Val); S->Align = BitFind (Val);
if ((0x01L << S->Align) != Val) { if ((0x01L << S->Align) != Val) {
CfgError ("Alignment must be a power of 2"); CfgError (&CfgErrorPos, "Alignment must be a power of 2");
} }
S->Flags |= SF_ALIGN; S->Flags |= SF_ALIGN;
break; break;
@ -686,7 +686,7 @@ static void ParseSegments (void)
Val = CfgCheckedConstExpr (1, 0x10000); Val = CfgCheckedConstExpr (1, 0x10000);
S->AlignLoad = BitFind (Val); S->AlignLoad = BitFind (Val);
if ((0x01L << S->AlignLoad) != Val) { if ((0x01L << S->AlignLoad) != Val) {
CfgError ("Alignment must be a power of 2"); CfgError (&CfgErrorPos, "Alignment must be a power of 2");
} }
S->Flags |= SF_ALIGN_LOAD; S->Flags |= SF_ALIGN_LOAD;
break; break;
@ -769,9 +769,9 @@ static void ParseSegments (void)
* separate run and load memory areas. * separate run and load memory areas.
*/ */
if ((S->Flags & SF_ALIGN_LOAD) != 0 && (S->Load == S->Run)) { if ((S->Flags & SF_ALIGN_LOAD) != 0 && (S->Load == S->Run)) {
Warning ("%s(%u): ALIGN_LOAD attribute specified, but no separate " Warning ("%s(%lu): ALIGN_LOAD attribute specified, but no separate "
"LOAD and RUN memory areas assigned", "LOAD and RUN memory areas assigned",
CfgGetName (), CfgErrorLine); CfgGetName (), CfgErrorPos.Line);
/* Remove the flag */ /* Remove the flag */
S->Flags &= ~SF_ALIGN_LOAD; S->Flags &= ~SF_ALIGN_LOAD;
} }
@ -780,14 +780,15 @@ static void ParseSegments (void)
* load and run memory areas, because it's is never written to disk. * load and run memory areas, because it's is never written to disk.
*/ */
if ((S->Flags & SF_BSS) != 0 && (S->Load != S->Run)) { if ((S->Flags & SF_BSS) != 0 && (S->Load != S->Run)) {
Warning ("%s(%u): Segment with type `bss' has both LOAD and RUN " Warning ("%s(%lu): Segment with type `bss' has both LOAD and RUN "
"memory areas assigned", CfgGetName (), CfgErrorLine); "memory areas assigned", CfgGetName (), CfgErrorPos.Line);
} }
/* Don't allow read/write data to be put into a readonly area */ /* Don't allow read/write data to be put into a readonly area */
if ((S->Flags & SF_RO) == 0) { if ((S->Flags & SF_RO) == 0) {
if (S->Run->Flags & MF_RO) { if (S->Run->Flags & MF_RO) {
CfgError ("Cannot put r/w segment `%s' in r/o memory area `%s'", CfgError (&CfgErrorPos,
"Cannot put r/w segment `%s' in r/o memory area `%s'",
GetString (S->Name), GetString (S->Run->Name)); GetString (S->Name), GetString (S->Run->Name));
} }
} }
@ -797,7 +798,8 @@ static void ParseSegments (void)
((S->Flags & SF_OFFSET) != 0) + ((S->Flags & SF_OFFSET) != 0) +
((S->Flags & SF_START) != 0); ((S->Flags & SF_START) != 0);
if (Count > 1) { if (Count > 1) {
CfgError ("Only one of ALIGN, START, OFFSET may be used"); CfgError (&CfgErrorPos,
"Only one of ALIGN, START, OFFSET may be used");
} }
/* Skip the semicolon */ /* Skip the semicolon */
@ -902,7 +904,7 @@ static void ParseO65 (void)
break; break;
default: default:
CfgError ("Unexpected type token"); CfgError (&CfgErrorPos, "Unexpected type token");
} }
/* Eat the attribute token */ /* Eat the attribute token */
CfgNextTok (); CfgNextTok ();
@ -924,7 +926,7 @@ static void ParseO65 (void)
case CFGTOK_OSA65: OS = O65OS_OSA65; break; case CFGTOK_OSA65: OS = O65OS_OSA65; break;
case CFGTOK_CC65: OS = O65OS_CC65; break; case CFGTOK_CC65: OS = O65OS_CC65; break;
case CFGTOK_OPENCBM: OS = O65OS_OPENCBM; break; case CFGTOK_OPENCBM: OS = O65OS_OPENCBM; break;
default: CfgError ("Unexpected OS token"); default: CfgError (&CfgErrorPos, "Unexpected OS token");
} }
} }
CfgNextTok (); CfgNextTok ();
@ -959,11 +961,13 @@ static void ParseO65 (void)
/* Check for attributes that may not be combined */ /* Check for attributes that may not be combined */
if (OS == O65OS_CC65) { if (OS == O65OS_CC65) {
if ((AttrFlags & (atImport | atExport)) != 0 && ModuleId < 0x8000) { if ((AttrFlags & (atImport | atExport)) != 0 && ModuleId < 0x8000) {
CfgError ("OS type CC65 may not have imports or exports for ids < $8000"); CfgError (&CfgErrorPos,
"OS type CC65 may not have imports or exports for ids < $8000");
} }
} else { } else {
if (AttrFlags & atID) { if (AttrFlags & atID) {
CfgError ("Operating system does not support the ID attribute"); CfgError (&CfgErrorPos,
"Operating system does not support the ID attribute");
} }
} }
@ -1154,7 +1158,9 @@ static void ParseConDes (void)
/* Check if the condes has already attributes defined */ /* Check if the condes has already attributes defined */
if (ConDesHasSegName(Type) || ConDesHasLabel(Type)) { if (ConDesHasSegName(Type) || ConDesHasLabel(Type)) {
CfgError ("CONDES attributes for type %d are already defined", Type); CfgError (&CfgErrorPos,
"CONDES attributes for type %d are already defined",
Type);
} }
/* Define the attributes */ /* Define the attributes */
@ -1502,14 +1508,16 @@ static void ProcessMemory (void)
/* Resolve the expressions */ /* Resolve the expressions */
if (!IsConstExpr (M->StartExpr)) { if (!IsConstExpr (M->StartExpr)) {
Error ("Start address of memory area `%s' is not constant", CfgError (&M->Pos,
GetString (M->Name)); "Start address of memory area `%s' is not constant",
GetString (M->Name));
} }
M->Start = GetExprVal (M->StartExpr); M->Start = GetExprVal (M->StartExpr);
if (!IsConstExpr (M->SizeExpr)) { if (!IsConstExpr (M->SizeExpr)) {
Error ("Size of memory area `%s' is not constant", CfgError (&M->Pos,
GetString (M->Name)); "Size of memory area `%s' is not constant",
GetString (M->Name));
} }
M->Size = GetExprVal (M->SizeExpr); M->Size = GetExprVal (M->SizeExpr);
@ -1567,7 +1575,9 @@ static void ProcessSegments (void)
/* Print a warning if the segment is not optional */ /* Print a warning if the segment is not optional */
if ((S->Flags & SF_OPTIONAL) == 0) { if ((S->Flags & SF_OPTIONAL) == 0) {
CfgWarning ("Segment `%s' does not exist", GetString (S->Name)); CfgWarning (&CfgErrorPos,
"Segment `%s' does not exist",
GetString (S->Name));
} }
/* Discard the descriptor and remove it from the collection */ /* Discard the descriptor and remove it from the collection */
@ -1595,8 +1605,9 @@ static void ProcessO65 (void)
* error message when checking it here. * error message when checking it here.
*/ */
if (O65GetImport (O65FmtDesc, Sym->Name) != 0) { if (O65GetImport (O65FmtDesc, Sym->Name) != 0) {
Error ("%s(%u): Duplicate imported o65 symbol: `%s'", CfgError (&Sym->Pos,
Sym->CfgName, Sym->CfgLine, GetString (Sym->Name)); "Duplicate imported o65 symbol: `%s'",
GetString (Sym->Name));
} }
/* Insert the symbol into the table */ /* Insert the symbol into the table */
@ -1611,8 +1622,9 @@ static void ProcessO65 (void)
/* 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, Sym->Name) != 0) { if (O65GetImport (O65FmtDesc, Sym->Name) != 0) {
Error ("%s(%u): Exported o65 symbol `%s' cannot also be an o65 import", CfgError (&Sym->Pos,
Sym->CfgName, Sym->CfgLine, GetString (Sym->Name)); "Exported o65 symbol `%s' cannot also be an o65 import",
GetString (Sym->Name));
} }
/* Check if we have this symbol defined already. The entry /* Check if we have this symbol defined already. The entry
@ -1620,8 +1632,9 @@ static void ProcessO65 (void)
* error message when checking it here. * error message when checking it here.
*/ */
if (O65GetExport (O65FmtDesc, Sym->Name) != 0) { if (O65GetExport (O65FmtDesc, Sym->Name) != 0) {
Error ("%s(%u): Duplicate exported o65 symbol: `%s'", CfgError (&Sym->Pos,
Sym->CfgName, Sym->CfgLine, GetString (Sym->Name)); "Duplicate exported o65 symbol: `%s'",
GetString (Sym->Name));
} }
/* Insert the symbol into the table */ /* Insert the symbol into the table */
@ -1667,7 +1680,8 @@ static void ProcessSymbols (void)
* Otherwise ignore the symbol from the config. * Otherwise ignore the symbol from the config.
*/ */
if ((Sym->Flags & SYM_WEAK) == 0) { if ((Sym->Flags & SYM_WEAK) == 0) {
CfgError ("Symbol `%s' is already defined", CfgError (&CfgErrorPos,
"Symbol `%s' is already defined",
GetString (Sym->Name)); GetString (Sym->Name));
} }
} else { } else {
@ -1772,11 +1786,15 @@ unsigned CfgProcess (void)
if (Addr > NewAddr) { if (Addr > NewAddr) {
/* Offset already too large */ /* Offset already too large */
if (S->Flags & SF_OFFSET) { if (S->Flags & SF_OFFSET) {
Error ("Offset too small in `%s', segment `%s'", CfgError (&M->Pos,
GetString (M->Name), GetString (S->Name)); "Offset too small in `%s', segment `%s'",
GetString (M->Name),
GetString (S->Name));
} else { } else {
Error ("Start address too low in `%s', segment `%s'", CfgError (&M->Pos,
GetString (M->Name), GetString (S->Name)); "Start address too low in `%s', segment `%s'",
GetString (M->Name),
GetString (S->Name));
} }
} }
Addr = NewAddr; Addr = NewAddr;

View File

@ -47,13 +47,14 @@
MemoryArea* NewMemoryArea (unsigned Name) MemoryArea* NewMemoryArea (const FilePos* Pos, unsigned Name)
/* Create a new memory area and insert it into the list */ /* Create a new memory area and insert it into the list */
{ {
/* Allocate memory */ /* Allocate memory */
MemoryArea* M = xmalloc (sizeof (MemoryArea)); MemoryArea* M = xmalloc (sizeof (MemoryArea));
/* Initialize the fields ... */ /* Initialize the fields ... */
M->Pos = *Pos;
M->Name = Name; M->Name = Name;
M->Attr = 0; M->Attr = 0;
M->Flags = 0; M->Flags = 0;

View File

@ -40,6 +40,7 @@
/* common */ /* common */
#include "coll.h" #include "coll.h"
#include "filepos.h"
@ -56,7 +57,8 @@ struct File;
/* Memory area entry */ /* Memory area entry */
typedef struct MemoryArea MemoryArea; typedef struct MemoryArea MemoryArea;
struct MemoryArea { struct MemoryArea {
unsigned Name; /* Name index of the memory section */ FilePos Pos; /* Where was the area was defined? */
unsigned Name; /* Name index of the memory area */
unsigned Attr; /* Which values are valid? */ unsigned Attr; /* Which values are valid? */
unsigned Flags; /* Set of bitmapped flags */ unsigned Flags; /* Set of bitmapped flags */
struct ExprNode* StartExpr; /* Expression for start address */ struct ExprNode* StartExpr; /* Expression for start address */
@ -85,7 +87,7 @@ struct MemoryArea {
MemoryArea* NewMemoryArea (unsigned Name); MemoryArea* NewMemoryArea (const FilePos* Pos, unsigned Name);
/* Create a new memory area and insert it into the list */ /* Create a new memory area and insert it into the list */

View File

@ -6,7 +6,7 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2009, 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 */
@ -48,6 +48,7 @@
#include "global.h" #include "global.h"
#include "error.h" #include "error.h"
#include "scanner.h" #include "scanner.h"
#include "spool.h"
@ -63,8 +64,7 @@ StrBuf CfgSVal = STATIC_STRBUF_INITIALIZER;
unsigned long CfgIVal; unsigned long CfgIVal;
/* Error location */ /* Error location */
unsigned CfgErrorLine; FilePos CfgErrorPos;
unsigned CfgErrorCol;
/* Input sources for the configuration */ /* Input sources for the configuration */
static const char* CfgName = 0; static const char* CfgName = 0;
@ -72,8 +72,7 @@ static const char* CfgBuf = 0;
/* Other input stuff */ /* Other input stuff */
static int C = ' '; static int C = ' ';
static unsigned InputLine = 1; static FilePos InputPos;
static unsigned InputCol = 0;
static FILE* InputFile = 0; static FILE* InputFile = 0;
@ -84,8 +83,8 @@ static FILE* InputFile = 0;
void CfgWarning (const char* Format, ...) void CfgWarning (const FilePos* Pos, const char* Format, ...)
/* Print a warning message adding file name and line number of the config file */ /* Print a warning message adding file name and line number of a given file */
{ {
StrBuf Buf = STATIC_STRBUF_INITIALIZER; StrBuf Buf = STATIC_STRBUF_INITIALIZER;
va_list ap; va_list ap;
@ -94,14 +93,15 @@ void CfgWarning (const char* Format, ...)
SB_VPrintf (&Buf, Format, ap); SB_VPrintf (&Buf, Format, ap);
va_end (ap); va_end (ap);
Warning ("%s(%u): %s", CfgGetName(), CfgErrorLine, SB_GetConstBuf (&Buf)); Warning ("%s(%lu): %s",
GetString (Pos->Name), Pos->Line, SB_GetConstBuf (&Buf));
SB_Done (&Buf); SB_Done (&Buf);
} }
void CfgError (const char* Format, ...) void CfgError (const FilePos* Pos, const char* Format, ...)
/* Print an error message adding file name and line number of the config file */ /* Print an error message adding file name and line number of a given file */
{ {
StrBuf Buf = STATIC_STRBUF_INITIALIZER; StrBuf Buf = STATIC_STRBUF_INITIALIZER;
va_list ap; va_list ap;
@ -110,7 +110,8 @@ void CfgError (const char* Format, ...)
SB_VPrintf (&Buf, Format, ap); SB_VPrintf (&Buf, Format, ap);
va_end (ap); va_end (ap);
Error ("%s(%u): %s", CfgGetName(), CfgErrorLine, SB_GetConstBuf (&Buf)); Error ("%s(%lu): %s",
GetString (Pos->Name), Pos->Line, SB_GetConstBuf (&Buf));
SB_Done (&Buf); SB_Done (&Buf);
} }
@ -140,13 +141,13 @@ static void NextChar (void)
/* Count columns */ /* Count columns */
if (C != EOF) { if (C != EOF) {
++InputCol; ++InputPos.Col;
} }
/* Count lines */ /* Count lines */
if (C == '\n') { if (C == '\n') {
++InputLine; ++InputPos.Line;
InputCol = 0; InputPos.Col = 0;
} }
} }
@ -177,7 +178,7 @@ static void StrVal (void)
case EOF: case EOF:
case '\n': case '\n':
CfgError ("Unterminated string"); CfgError (&CfgErrorPos, "Unterminated string");
break; break;
case '%': case '%':
@ -187,7 +188,7 @@ static void StrVal (void)
case EOF: case EOF:
case '\n': case '\n':
case '\"': case '\"':
CfgError ("Unterminated '%%' escape sequence"); CfgError (&CfgErrorPos, "Unterminated '%%' escape sequence");
break; break;
case '%': case '%':
@ -205,7 +206,8 @@ static void StrVal (void)
break; break;
default: default:
CfgWarning ("Unkown escape sequence `%%%c'", C); CfgWarning (&CfgErrorPos,
"Unkown escape sequence `%%%c'", C);
SB_AppendChar (&CfgSVal, '%'); SB_AppendChar (&CfgSVal, '%');
SB_AppendChar (&CfgSVal, C); SB_AppendChar (&CfgSVal, C);
NextChar (); NextChar ();
@ -241,8 +243,7 @@ Again:
} }
/* Remember the current position */ /* Remember the current position */
CfgErrorLine = InputLine; CfgErrorPos = InputPos;
CfgErrorCol = InputCol;
/* Identifier? */ /* Identifier? */
if (C == '_' || IsAlpha (C)) { if (C == '_' || IsAlpha (C)) {
@ -262,7 +263,7 @@ Again:
if (C == '$') { if (C == '$') {
NextChar (); NextChar ();
if (!isxdigit (C)) { if (!isxdigit (C)) {
CfgError ("Hex digit expected"); CfgError (&CfgErrorPos, "Hex digit expected");
} }
CfgIVal = 0; CfgIVal = 0;
while (isxdigit (C)) { while (isxdigit (C)) {
@ -390,7 +391,7 @@ Again:
break; break;
default: default:
CfgError ("Invalid format specification"); CfgError (&CfgErrorPos, "Invalid format specification");
} }
break; break;
@ -399,7 +400,7 @@ Again:
break; break;
default: default:
CfgError ("Invalid character `%c'", C); CfgError (&CfgErrorPos, "Invalid character `%c'", C);
} }
} }
@ -410,7 +411,7 @@ void CfgConsume (cfgtok_t T, const char* Msg)
/* Skip a token, print an error message if not found */ /* Skip a token, print an error message if not found */
{ {
if (CfgTok != T) { if (CfgTok != T) {
CfgError ("%s", Msg); CfgError (&CfgErrorPos, "%s", Msg);
} }
CfgNextTok (); CfgNextTok ();
} }
@ -457,7 +458,7 @@ void CfgAssureInt (void)
/* Make sure the next token is an integer */ /* Make sure the next token is an integer */
{ {
if (CfgTok != CFGTOK_INTCON) { if (CfgTok != CFGTOK_INTCON) {
CfgError ("Integer constant expected"); CfgError (&CfgErrorPos, "Integer constant expected");
} }
} }
@ -467,7 +468,7 @@ void CfgAssureStr (void)
/* Make sure the next token is a string constant */ /* Make sure the next token is a string constant */
{ {
if (CfgTok != CFGTOK_STRCON) { if (CfgTok != CFGTOK_STRCON) {
CfgError ("String constant expected"); CfgError (&CfgErrorPos, "String constant expected");
} }
} }
@ -477,7 +478,7 @@ void CfgAssureIdent (void)
/* Make sure the next token is an identifier */ /* Make sure the next token is an identifier */
{ {
if (CfgTok != CFGTOK_IDENT) { if (CfgTok != CFGTOK_IDENT) {
CfgError ("Identifier expected"); CfgError (&CfgErrorPos, "Identifier expected");
} }
} }
@ -487,7 +488,7 @@ void CfgRangeCheck (unsigned long Lo, unsigned long Hi)
/* Check the range of CfgIVal */ /* Check the range of CfgIVal */
{ {
if (CfgIVal < Lo || CfgIVal > Hi) { if (CfgIVal < Lo || CfgIVal > Hi) {
CfgError ("Range error"); CfgError (&CfgErrorPos, "Range error");
} }
} }
@ -515,7 +516,7 @@ void CfgSpecialToken (const IdentTok* Table, unsigned Size, const char* Name)
} }
/* Not found or no identifier */ /* Not found or no identifier */
CfgError ("%s expected", Name); CfgError (&CfgErrorPos, "%s expected", Name);
} }
@ -536,7 +537,7 @@ void CfgBoolToken (void)
} else { } else {
/* We expected an integer here */ /* We expected an integer here */
if (CfgTok != CFGTOK_INTCON) { if (CfgTok != CFGTOK_INTCON) {
CfgError ("Boolean value expected"); CfgError (&CfgErrorPos, "Boolean value expected");
} }
CfgTok = (CfgIVal == 0)? CFGTOK_FALSE : CFGTOK_TRUE; CfgTok = (CfgIVal == 0)? CFGTOK_FALSE : CFGTOK_TRUE;
} }
@ -600,8 +601,9 @@ void CfgOpenInput (void)
/* Initialize variables */ /* Initialize variables */
C = ' '; C = ' ';
InputLine = 1; InputPos.Line = 1;
InputCol = 0; InputPos.Col = 0;
InputPos.Name = GetStringId (CfgBuf? "[builtin config]" : CfgName);
/* Start the ball rolling ... */ /* Start the ball rolling ... */
CfgNextTok (); CfgNextTok ();
@ -621,4 +623,3 @@ void CfgCloseInput (void)

View File

@ -6,10 +6,10 @@
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 1998-2010 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 */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
@ -38,6 +38,8 @@
/* common */
#include "filepos.h"
#include "strbuf.h" #include "strbuf.h"
@ -152,13 +154,12 @@ struct IdentTok {
/* Current token and attributes */ /* Current token and attributes */
extern cfgtok_t CfgTok; extern cfgtok_t CfgTok;
extern StrBuf CfgSVal; extern StrBuf CfgSVal;
extern unsigned long CfgIVal; extern unsigned long CfgIVal;
/* Error location */ /* Error location */
extern unsigned CfgErrorLine; extern FilePos CfgErrorPos;
extern unsigned CfgErrorCol;
@ -168,11 +169,11 @@ extern unsigned CfgErrorCol;
void CfgWarning (const char* Format, ...) attribute((format(printf,1,2))); void CfgWarning (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
/* Print a warning message adding file name and line number of the config file */ /* Print a warning message adding file name and line number of the config file */
void CfgError (const char* Format, ...) attribute((format(printf,1,2))); void CfgError (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
/* Print an error message adding file name and line number of the config file */ /* Print an error message adding file name and line number of a given file */
void CfgNextTok (void); void CfgNextTok (void);
/* Read the next token from the input stream */ /* Read the next token from the input stream */