Move the functions to output config file errors from scanner.c to error.c.

This commit is contained in:
Kugel Fuhr
2025-07-08 20:55:58 +02:00
parent 6f45af3c9e
commit 96f8ce4cee
4 changed files with 48 additions and 49 deletions

View File

@@ -43,6 +43,7 @@
/* ld65 */
#include "error.h"
#include "spool.h"
@@ -121,3 +122,43 @@ void Internal (const char* Format, ...)
exit (EXIT_FAILURE);
}
void CfgWarning (const FilePos* Pos, const char* Format, ...)
/* Print a warning message adding file name and line number of a given file */
{
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
va_list ap;
va_start (ap, Format);
SB_VPrintf (&Buf, Format, ap);
va_end (ap);
Warning ("%s:%u: %s",
GetString (Pos->Name), Pos->Line, SB_GetConstBuf (&Buf));
SB_Done (&Buf);
/* Count warnings */
++WarningCount;
}
void CfgError (const FilePos* Pos, const char* Format, ...)
/* Print an error message adding file name and line number of a given file */
{
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
va_list ap;
va_start (ap, Format);
SB_VPrintf (&Buf, Format, ap);
va_end (ap);
Error ("%s:%u: %s",
GetString (Pos->Name), Pos->Line, SB_GetConstBuf (&Buf));
SB_Done (&Buf);
}

View File

@@ -40,6 +40,7 @@
/* common */
#include "attrib.h"
#include "filepos.h"
@@ -69,6 +70,12 @@ void Error (const char* Format, ...) attribute((noreturn, format(printf,1,2)));
void Internal (const char* Format, ...) attribute((noreturn, format(printf,1,2)));
/* Print an internal error message and die */
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 */
void CfgError (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
/* Print an error message adding file name and line number of a given file */
/* End of error.h */

View File

@@ -76,49 +76,6 @@ static FILE* InputFile = 0;
/*****************************************************************************/
/* Error handling */
/*****************************************************************************/
void CfgWarning (const FilePos* Pos, const char* Format, ...)
/* Print a warning message adding file name and line number of a given file */
{
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
va_list ap;
va_start (ap, Format);
SB_VPrintf (&Buf, Format, ap);
va_end (ap);
Warning ("%s:%u: %s",
GetString (Pos->Name), Pos->Line, SB_GetConstBuf (&Buf));
SB_Done (&Buf);
/* Count warnings */
++WarningCount;
}
void CfgError (const FilePos* Pos, const char* Format, ...)
/* Print an error message adding file name and line number of a given file */
{
StrBuf Buf = STATIC_STRBUF_INITIALIZER;
va_list ap;
va_start (ap, Format);
SB_VPrintf (&Buf, Format, ap);
va_end (ap);
Error ("%s:%u: %s",
GetString (Pos->Name), Pos->Line, SB_GetConstBuf (&Buf));
SB_Done (&Buf);
}
/*****************************************************************************/
/* Code */
/*****************************************************************************/

View File

@@ -186,12 +186,6 @@ extern FilePos CfgErrorPos;
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 */
void CfgError (const FilePos* Pos, const char* Format, ...) attribute((format(printf,2,3)));
/* Print an error message adding file name and line number of a given file */
void CfgNextTok (void);
/* Read the next token from the input stream */