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 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 /* Count of errors/warnings */
59 unsigned ErrorCount = 0;
60 unsigned WarningCount = 0;
64 /*****************************************************************************/
66 /*****************************************************************************/
70 static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
71 /* Print warning message - internal function. */
74 fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
75 vfprintf (stderr, Msg, ap);
76 fprintf (stderr, "\n");
78 Print (stderr, 1, "Line: %s\n", line);
85 void Warning (const char* Format, ...)
86 /* Print warning message. */
89 va_start (ap, Format);
90 IntWarning (GetCurrentFile(), curpos, Format, ap);
96 void PPWarning (const char* Format, ...)
97 /* Print warning message. For use within the preprocessor. */
100 va_start (ap, Format);
101 IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
107 static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
108 /* Print an error message - internal function*/
110 fprintf (stderr, "%s(%u): Error: ", Filename, Line);
111 vfprintf (stderr, Msg, ap);
112 fprintf (stderr, "\n");
114 Print (stderr, 1, "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");
157 Print (stderr, 1, "Line: %s\n", line);
163 void Internal (char* Format, ...)
164 /* Print a message about an internal compiler error and die. */
168 fprintf (stderr, "%s(%u): Internal compiler error:\n",
169 GetCurrentFile(), curpos);
171 va_start (ap, Format);
172 vfprintf (stderr, Format, ap);
174 fprintf (stderr, "\nLine: %s\n", line);
176 /* Use abort to create a core dump */
182 void ErrorReport (void)
183 /* Report errors (called at end of compile) */
185 if (ErrorCount == 0 && Verbosity > 0) {
186 printf ("No errors.\n");