From: uz Date: Sun, 18 Jan 2009 15:07:55 +0000 (+0000) Subject: Avoid spurious subsequent errors if an include file wasn't found. X-Git-Tag: V2.13.0rc1~347 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=30f88d26464da4bfc763018e5beddf413fa554b2;p=cc65 Avoid spurious subsequent errors if an include file wasn't found. git-svn-id: svn://svn.cc65.org/cc65/trunk@3908 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ca65/macpack.c b/src/ca65/macpack.c index ee46d3e6f..7efd9a563 100644 --- a/src/ca65/macpack.c +++ b/src/ca65/macpack.c @@ -102,9 +102,14 @@ int MacPackFind (const StrBuf* Name) -void MacPackInsert (int Id) -/* Insert the macro package with the given id in the input stream */ -{ +int MacPackInsert (int Id) +/* Insert the macro package with the given id in the input stream. Returns + * true if the macro package was found and successfully inserted. Returns + * false otherwise. + */ +{ + int RetCode; + /* Check the parameter */ CHECK (Id >= 0 && Id < MAC_COUNT); @@ -116,6 +121,9 @@ void MacPackInsert (int Id) /* Insert the builtin package */ NewInputData (MacPackages[Id].Package, 0); + /* Always successful */ + RetCode = 1; + } else { StrBuf Filename = AUTO_STRBUF_INITIALIZER; @@ -127,12 +135,15 @@ void MacPackInsert (int Id) SB_Terminate (&Filename); /* Open the macro package as include file */ - NewInputFile (SB_GetConstBuf (&Filename)); + RetCode = NewInputFile (SB_GetConstBuf (&Filename)); /* Destroy the contents of Filename */ SB_Done (&Filename); } + + /* Return the success code */ + return RetCode; } diff --git a/src/ca65/macpack.h b/src/ca65/macpack.h index 72b47a73c..3433198d1 100644 --- a/src/ca65/macpack.h +++ b/src/ca65/macpack.h @@ -74,8 +74,11 @@ int MacPackFind (const StrBuf* Name); * -1 if the package name was not found. */ -void MacPackInsert (int Id); -/* Insert the macro package with the given id in the input stream */ +int MacPackInsert (int Id); +/* Insert the macro package with the given id in the input stream. Returns + * true if the macro package was found and successfully inserted. Returns + * false otherwise. + */ void MacPackSetDir (const StrBuf* Dir); /* Set a directory where files for macro packages can be found. Standard is diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index a5f1d8402..3128231ec 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1146,7 +1146,10 @@ static void DoInclude (void) ErrorSkip ("String constant expected"); } else { SB_Terminate (&SVal); - NewInputFile (SB_GetConstBuf (&SVal)); + if (NewInputFile (SB_GetConstBuf (&SVal)) == 0) { + /* Error opening the file, skip remainder of line */ + SkipUntilSep (); + } } } @@ -1258,8 +1261,12 @@ static void DoMacPack (void) return; } - /* Insert the package */ - MacPackInsert (Package); + /* Insert the package. If this fails, skip the remainder of the line to + * avoid additional error messages. + */ + if (MacPackInsert (Package) == 0) { + SkipUntilSep (); + } } diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index c1fe25189..9649f4ed3 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -429,9 +429,12 @@ static const CharSourceFunctions IFFunc = { -void NewInputFile (const char* Name) -/* Open a new input file */ +int NewInputFile (const char* Name) +/* Open a new input file. Returns true if the file could be successfully opened + * and false otherwise. + */ { + int RetCode = 0; /* Return code. Assume an error. */ char* PathName = 0; /* First try to open the file */ @@ -450,6 +453,7 @@ void NewInputFile (const char* Name) if (PathName == 0 || (F = fopen (PathName, "r")) == 0) { /* Not found or cannot open, print an error and bail out */ Error ("Cannot open include file `%s': %s", Name, strerror (errno)); + goto ExitPoint; } /* Use the path name from now on */ @@ -495,8 +499,15 @@ void NewInputFile (const char* Name) UseCharSource (S); } + /* File successfully opened */ + RetCode = 1; + +ExitPoint: /* Free an allocated name buffer */ xfree (PathName); + + /* Return the success code */ + return RetCode; } diff --git a/src/ca65/scanner.h b/src/ca65/scanner.h index 17492766e..37522e915 100644 --- a/src/ca65/scanner.h +++ b/src/ca65/scanner.h @@ -78,8 +78,10 @@ int IsIdChar (int C); int IsIdStart (int C); /* Return true if the character may start an identifier */ -void NewInputFile (const char* Name); -/* Open a new input file */ +int NewInputFile (const char* Name); +/* Open a new input file. Returns true if the file could be successfully opened + * and false otherwise. + */ void NewInputData (char* Text, int Malloced); /* Add a chunk of input data to the input stream */