-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);
/* Insert the builtin package */
NewInputData (MacPackages[Id].Package, 0);
+ /* Always successful */
+ RetCode = 1;
+
} else {
StrBuf Filename = AUTO_STRBUF_INITIALIZER;
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;
}
* -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
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 ();
+ }
}
}
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 ();
+ }
}
-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 */
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 */
UseCharSource (S);
}
+ /* File successfully opened */
+ RetCode = 1;
+
+ExitPoint:
/* Free an allocated name buffer */
xfree (PathName);
+
+ /* Return the success code */
+ return RetCode;
}
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 */