Convert macross error-handling functions to varargs

This commit is contained in:
Peter De Wachter 2016-01-23 17:35:49 +01:00
parent e8b97b38d7
commit c594490db9
3 changed files with 44 additions and 45 deletions

View File

@ -30,6 +30,8 @@
#include "macrossTypes.h"
#include "macrossGlobals.h"
#include <stdarg.h>
bool nullStatementFlag;
/* puntOnError handles syntax errors and the like encountered during parsing
@ -38,34 +40,28 @@ bool nullStatementFlag;
from the booboo. */
void
puntOnError(theError, arg1, arg2, arg3)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
puntOnError(errorType theError, ...)
{
va_list ap;
char c;
void error();
while ((c = getc(input))!='\n' && c!=EOF)
;
ungetc(c, input);
error(theError, arg1, arg2, arg3);
va_start(ap, theError);
verror(theError, ap);
va_end(ap);
}
/* printErrorMessage is the general error message handler */
void
printErrorMessage(theError, arg1, arg2, arg3)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
printErrorMessage(errorType theError, va_list ap)
{
/* This table MUST be maintained congruently with the definition of the
enumerated type 'errorType'. */
void fatalError();
static bool dying = FALSE;
static char *errorMessageStrings[] = {
@ -232,7 +228,7 @@ printErrorMessage(theError, arg1, arg2, arg3)
lastErrorLine = currentLineNumber;
printf("\"%s\", line %d: ", currentFileName, currentLineNumber
-1);
printf(errorMessageStrings[(int)theError], arg1, arg2, arg3);
vprintf(errorMessageStrings[(int)theError], ap);
printf("\n");
fflush(stdout);
}
@ -243,45 +239,48 @@ printErrorMessage(theError, arg1, arg2, arg3)
}
void
error(theError, arg1, arg2, arg3)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
error(errorType theError, ...)
{
printErrorMessage(theError, arg1, arg2, arg3);
va_list ap;
va_start(ap, theError);
printErrorMessage(theError, ap);
va_end(ap);
errorFlag = TRUE;
}
void
warning(theError, arg1, arg2, arg3)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
verror(errorType theError, va_list ap)
{
printErrorMessage(theError, arg1, arg2, arg3);
printErrorMessage(theError, ap);
errorFlag = TRUE;
}
void
fatalError(theError, arg1, arg2, arg3)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
warning(errorType theError, ...)
{
printErrorMessage(theError, arg1, arg2, arg3);
va_list ap;
va_start(ap, theError);
printErrorMessage(theError, ap);
va_end(ap);
}
void
fatalError(errorType theError, ...)
{
va_list ap;
va_start(ap, theError);
printErrorMessage(theError, ap);
va_end(ap);
chokePukeAndDie();
}
void
fatalSystemError(theError, arg1, arg2, arg3)
errorType theError;
anyOldThing *arg1;
anyOldThing *arg2;
anyOldThing *arg3;
fatalSystemError(errorType theError, ...)
{
printErrorMessage(theError, arg1, arg2, arg3);
va_list ap;
va_start(ap, theError);
printErrorMessage(theError, ap);
va_end(ap);
perror("Unix says");
chokePukeAndDie();
}

View File

@ -34,6 +34,7 @@
#include "y.tab.h"
#include "parserMisc.h"
#include <stdarg.h>
#include <string.h>
statementType *
@ -54,14 +55,13 @@ addLabelToStatement(labelList, statement)
* function does almost exactly what we want. */
void
botch(message, arg1, arg2, arg3)
char *message;
int arg1;
int arg2;
int arg3;
botch(char *message, ...)
{
va_list ap;
printf("Macross horrible terrible internal botch: ");
printf(message, arg1, arg2, arg3);
va_start(ap, message);
vprintf(message, ap);
va_end(ap);
chokePukeAndDie();
}

View File

@ -3,7 +3,7 @@
#include "macrossTypes.h"
statementType *addLabelToSatement(labelListType *labelList, statementType *statement);
void botch(char *message, int arg1, int arg2, int arg3);
void botch(char *message, ...);
void checkDefineAssignmentOperator(assignmentKindType assignmentOperator);
void convertDefineToMDefine(statementType *defineStatement);
ifStatementBodyType *extractIfBody(statementType *ifStatement);