1 /*****************************************************************************/
5 /* Error handling for the ca65 macroassembler */
9 /* (C) 1998-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
51 /*****************************************************************************/
53 /*****************************************************************************/
58 unsigned WarnLevel = 1;
61 unsigned ErrorCount = 0;
62 unsigned WarningCount = 0;
66 /*****************************************************************************/
68 /*****************************************************************************/
72 void WarningMsg (const FilePos* Pos, unsigned Level, const char* Format, va_list ap)
73 /* Print warning message. */
75 if (Level <= WarnLevel) {
77 StrBuf S = STATIC_STRBUF_INITIALIZER;
78 SB_VPrintf (&S, Format, ap);
81 fprintf (stderr, "%s(%lu): Warning: %s\n",
82 SB_GetConstBuf (GetFileName (Pos->Name)),
93 void Warning (unsigned Level, const char* Format, ...)
94 /* Print warning message. */
97 va_start (ap, Format);
98 WarningMsg (&CurTok.Pos, Level, Format, ap);
104 void PWarning (const FilePos* Pos, unsigned Level, const char* Format, ...)
105 /* Print warning message giving an explicit file and position. */
108 va_start (ap, Format);
109 WarningMsg (Pos, Level, Format, ap);
115 void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format, ...)
116 /* Print warning message using the given line infos */
120 /* The first entry in the collection is that of the actual source pos */
121 const LineInfo* LI = CollConstAt (LineInfos, 0);
123 /* Output a warning for this position */
124 va_start (ap, Format);
125 WarningMsg (&LI->Pos, Level, Format, ap);
131 /*****************************************************************************/
133 /*****************************************************************************/
137 void ErrorMsg (const FilePos* Pos, const char* Format, va_list ap)
138 /* Print an error message */
140 StrBuf S = STATIC_STRBUF_INITIALIZER;
141 SB_VPrintf (&S, Format, ap);
144 fprintf (stderr, "%s(%lu): Error: %s\n",
145 SB_GetConstBuf (GetFileName (Pos->Name)),
147 SB_GetConstBuf (&S));
155 void Error (const char* Format, ...)
156 /* Print an error message */
159 va_start (ap, Format);
160 ErrorMsg (&CurTok.Pos, Format, ap);
166 void PError (const FilePos* Pos, const char* Format, ...)
167 /* Print an error message giving an explicit file and position. */
170 va_start (ap, Format);
171 ErrorMsg (Pos, Format, ap);
177 void LIError (const Collection* LineInfos, const char* Format, ...)
178 /* Print an error message using the given line infos. */
182 /* The first entry in the collection is that of the actual source pos */
183 const LineInfo* LI = CollConstAt (LineInfos, 0);
185 /* Output an error for this position */
186 va_start (ap, Format);
187 ErrorMsg (&LI->Pos, Format, ap);
193 void ErrorSkip (const char* Format, ...)
194 /* Print an error message and skip the rest of the line */
197 va_start (ap, Format);
198 ErrorMsg (&CurTok.Pos, Format, ap);
206 /*****************************************************************************/
208 /*****************************************************************************/
212 void Fatal (const char* Format, ...)
213 /* Print a message about a fatal error and die */
216 StrBuf S = STATIC_STRBUF_INITIALIZER;
218 va_start (ap, Format);
219 SB_VPrintf (&S, Format, ap);
223 fprintf (stderr, "Fatal error: %s\n", SB_GetConstBuf (&S));
233 void Internal (const char* Format, ...)
234 /* Print a message about an internal assembler error and die. */
237 StrBuf S = STATIC_STRBUF_INITIALIZER;
239 va_start (ap, Format);
240 SB_VPrintf (&S, Format, ap);
244 fprintf (stderr, "Internal assembler error: %s\n", SB_GetConstBuf (&S));