1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
/* -*- c -*- */
/*
* error.c
*
* chpp
*
* Copyright (C) 1997-1998 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <assert.h>
#include <stdarg.h>
#include "dynstring.h"
#include "main.h"
#include "error.h"
#include "error.h"
char *frontendWarnings[] =
{
};
char *frontendErrors[] =
{
"only one output file is allowed",
"could not open output file '%s': %s",
"could not open input file '%s': %s"
};
char *commandWarnings[] =
{
"command %s should not have arguments",
"unknown command %s"
};
char *commandErrors[] =
{
"unmatched %s",
"could not open include file: %s",
"expected ')' .. found '\\n' or '\\0'",
"%s expects only one argument",
"%s"
};
char *macroWarnings[] =
{
"%s",
"key '%s' already defined in hash",
"possibly unbound variable '%s'",
"possibly wrong number (%d) of arguments for macro %s",
"suspect character '%c'"
};
char *macroErrors[] =
{
"symbol '%s' not defined",
"unmatched '<'",
"division by zero",
"malformed arithmetic expression '%s'",
"cannot set internal variable '%s'",
"invalid regular expression '%s'",
"invalid argument to macro '%s': '%s'",
"call to '%s' failed: '%s'",
"'%s' is an internal, not a hash",
"key '%s' is not contained in hash",
"cannot redefine built-in '%s'",
"%s",
"increment in for-loop cannot be zero",
"feature not yet implemented: %s",
"list index %d out of bounds",
"'%s' is an internal, not an array",
"'%s' is of type %s instead of expected type %s",
"value is of type %s instead of expected type %s",
"value is not an lvalue",
"wrong number of arguments for macro '%s'",
"user-defined macro called with %d instead of expected %d arguments",
"unbound variable '%s'",
"cannot get internal variable '%s'",
"list indexed as hash with index '%s'",
"unexpected character '%c': expected '%c'",
"premature end of file or string"
};
int errorsOccured = 0,
warningsOccured = 0;
static char printfString[1024];
void
issueWarningInLine (const char *filename, int lineNumber, int num, ...)
{
va_list ap;
char *warningString = 0;
assert(num < 3000);
if (num < 1000)
warningString = frontendWarnings[num];
else if (num < 2000)
warningString = commandWarnings[num - 1000];
else if (num < 3000)
warningString = macroWarnings[num - 2000];
if (num < 1000)
sprintf(printfString, "%s: warning: %s\n", executableName, warningString);
else
sprintf(printfString, "%s:%d: warning: %s\n", filename, lineNumber,
warningString);
va_start(ap, num);
vfprintf(stderr, printfString, ap);
va_end(ap);
++warningsOccured;
}
void
issueErrorInLine (const char *filename, int lineNumber, int num, ...)
{
va_list ap;
char *errorString = 0;
assert(num < 3000);
if (num < 1000)
errorString = frontendErrors[num];
else if (num < 2000)
errorString = commandErrors[num - 1000];
else if (num < 3000)
errorString = macroErrors[num - 2000];
if (num < 1000)
sprintf(printfString, "%s: %s\n", executableName, errorString);
else
sprintf(printfString, "%s:%d: %s\n", filename, lineNumber, errorString);
va_start(ap, num);
vfprintf(stderr, printfString, ap);
va_end(ap);
++errorsOccured;
}
void
issueWarning (int num, ...)
{
va_list ap;
char *warningString = 0;
const char *filename = irPreprocessorFileName(&toplevelInputReader);
int lineNumber = irPreprocessorLineNumber(&toplevelInputReader);
assert(num < 3000);
if (num < 1000)
warningString = frontendWarnings[num];
else if (num < 2000)
warningString = commandWarnings[num - 1000];
else if (num < 3000)
warningString = macroWarnings[num - 2000];
if (num < 1000)
sprintf(printfString, "%s: warning: %s\n", executableName, warningString);
else
sprintf(printfString, "%s:%d: warning: %s\n", filename, lineNumber,
warningString);
va_start(ap, num);
vfprintf(stderr, printfString, ap);
va_end(ap);
++warningsOccured;
}
void
issueError (int num, ...)
{
va_list ap;
char *errorString = 0;
const char *filename = irPreprocessorFileName(&toplevelInputReader);
int lineNumber = irPreprocessorLineNumber(&toplevelInputReader);
assert(num < 3000);
if (num < 1000)
errorString = frontendErrors[num];
else if (num < 2000)
errorString = commandErrors[num - 1000];
else if (num < 3000)
errorString = macroErrors[num - 2000];
if (num < 1000)
sprintf(printfString, "%s: %s\n", executableName, errorString);
else
sprintf(printfString, "%s:%d: %s\n", filename, lineNumber, errorString);
va_start(ap, num);
vfprintf(stderr, printfString, ap);
va_end(ap);
++errorsOccured;
}
|