1 /*****************************************************************************/
5 /* Error handling for the cc65 C compiler */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
54 /* Count of errors/warnings */
55 unsigned ErrorCount = 0;
56 unsigned WarningCount = 0;
60 /*****************************************************************************/
62 /*****************************************************************************/
66 static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
67 /* Print warning message - internal function. */
70 fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
71 vfprintf (stderr, Msg, ap);
72 fprintf (stderr, "\n");
75 fprintf (stderr, "Line: %s\n", line);
83 void Warning (const char* Format, ...)
84 /* Print warning message. */
87 va_start (ap, Format);
88 IntWarning (GetCurrentFile(), curpos, Format, ap);
94 void PPWarning (const char* Format, ...)
95 /* Print warning message. For use within the preprocessor. */
98 va_start (ap, Format);
99 IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
105 static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
106 /* Print an error message - internal function*/
108 fprintf (stderr, "%s(%u): Error: ", Filename, Line);
109 vfprintf (stderr, Msg, ap);
110 fprintf (stderr, "\n");
113 fprintf (stderr, "Line: %s\n", line);
116 if (ErrorCount > 10) {
117 Fatal ("Too many errors");
123 void Error (const char* Format, ...)
124 /* Print an error message */
127 va_start (ap, Format);
128 IntError (GetCurrentFile(), curpos, Format, ap);
134 void PPError (const char* Format, ...)
135 /* Print an error message. For use within the preprocessor. */
138 va_start (ap, Format);
139 IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
145 void Fatal (const char* Format, ...)
146 /* Print a message about a fatal error and die */
150 fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos);
152 va_start (ap, Format);
153 vfprintf (stderr, Format, ap);
155 fprintf (stderr, "\n");
158 fprintf (stderr, "Line: %s\n", line);
165 void Internal (char* Format, ...)
166 /* Print a message about an internal compiler error and die. */
170 fprintf (stderr, "%s(%u): Internal compiler error:\n",
171 GetCurrentFile(), curpos);
173 va_start (ap, Format);
174 vfprintf (stderr, Format, ap);
176 fprintf (stderr, "\nLine: %s\n", line);
178 /* Use abort to create a core dump */
184 void ErrorReport (void)
185 /* Report errors (called at end of compile) */
187 if (ErrorCount == 0 && Verbose) {
188 printf ("No errors.\n");