From c594490db9f2f1712274bb1357882b184f894db5 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Sat, 23 Jan 2016 17:35:49 +0100 Subject: [PATCH] Convert macross error-handling functions to varargs --- errorStuff.c | 75 ++++++++++++++++++++++++++-------------------------- parserMisc.c | 12 ++++----- parserMisc.h | 2 +- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/errorStuff.c b/errorStuff.c index a855027..968fe56 100644 --- a/errorStuff.c +++ b/errorStuff.c @@ -30,6 +30,8 @@ #include "macrossTypes.h" #include "macrossGlobals.h" +#include + 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(); } diff --git a/parserMisc.c b/parserMisc.c index 51982a4..5ec73a9 100644 --- a/parserMisc.c +++ b/parserMisc.c @@ -34,6 +34,7 @@ #include "y.tab.h" #include "parserMisc.h" +#include #include 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(); } diff --git a/parserMisc.h b/parserMisc.h index fc08c53..c2ed5d0 100644 --- a/parserMisc.h +++ b/parserMisc.h @@ -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);