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 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
59 /* Count of errors/warnings */
60 unsigned ErrorCount = 0;
61 unsigned WarningCount = 0;
65 /*****************************************************************************/
67 /*****************************************************************************/
71 static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
72 /* Print warning message - internal function. */
75 fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
76 vfprintf (stderr, Msg, ap);
77 fprintf (stderr, "\n");
79 Print (stderr, 1, "Line: %s\n", line);
86 void Warning (const char* Format, ...)
87 /* Print warning message. */
90 va_start (ap, Format);
91 IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
97 void PPWarning (const char* Format, ...)
98 /* Print warning message. For use within the preprocessor. */
101 va_start (ap, Format);
102 IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
108 static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
109 /* Print an error message - internal function*/
111 fprintf (stderr, "%s(%u): Error: ", Filename, Line);
112 vfprintf (stderr, Msg, ap);
113 fprintf (stderr, "\n");
115 Print (stderr, 1, "Line: %s\n", line);
117 if (ErrorCount > 10) {
118 Fatal ("Too many errors");
124 void Error (const char* Format, ...)
125 /* Print an error message */
128 va_start (ap, Format);
129 IntError (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
135 void PPError (const char* Format, ...)
136 /* Print an error message. For use within the preprocessor. */
139 va_start (ap, Format);
140 IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
146 void Fatal (const char* Format, ...)
147 /* Print a message about a fatal error and die */
151 const char* FileName;
154 FileName = GetInputName (CurTok.LI);
155 LineNum = GetInputLine (CurTok.LI);
157 FileName = GetCurrentFile ();
158 LineNum = GetCurrentLine ();
161 fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
163 va_start (ap, Format);
164 vfprintf (stderr, Format, ap);
166 fprintf (stderr, "\n");
168 Print (stderr, 1, "Line: %s\n", line);
174 void Internal (char* Format, ...)
175 /* Print a message about an internal compiler error and die. */
179 const char* FileName;
182 FileName = GetInputName (CurTok.LI);
183 LineNum = GetInputLine (CurTok.LI);
185 FileName = GetCurrentFile ();
186 LineNum = GetCurrentLine ();
189 fprintf (stderr, "%s(%u): Internal compiler error:\n",
192 va_start (ap, Format);
193 vfprintf (stderr, Format, ap);
195 fprintf (stderr, "\nLine: %s\n", line);
197 /* Use abort to create a core dump */
203 void ErrorReport (void)
204 /* Report errors (called at end of compile) */
206 if (ErrorCount == 0 && Verbosity > 0) {
207 printf ("No errors.\n");