#include #include "global.h" // errorCount maintains the number of errors reported. int errorCount = 0; // errorsFound() merely returns the value of errorCount. int errorsFound() { return errorCount; } // The function error() receives a variable number of parameters // depending on the specification of the format string. It thus relies // on the va_start() and va_arg() functions as defined in void error(errorKind mode, char* format, ...) { static char *prefix[] = { "warning: ", "", "abort: ", "internal error: " }; va_list ap; va_start(ap, format); fprintf(stderr, "%s", prefix[mode]); if (mode == ERROR) errorCount++; while (*format) if (*format == '%') { switch (*++format) { case 's': { char *p = va_arg(ap, char *); fprintf(stderr, "%s", p); break; } case 'd': { int p = va_arg(ap, int); fprintf(stderr, "%d", (int) p); break; } case '^': { int count = va_arg(ap, int); for (int i = 1; i