]> git.sur5r.net Git - cc65/blobdiff - src/ca65/error.c
Address size fixes
[cc65] / src / ca65 / error.c
index 86fd96b2985971c1f39accbf04a1ff5463155ec9..06bbf26153bf48b3d3f84e68b8acbbffa21733b4 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 error.c                                  */
+/*                                 error.c                                  */
 /*                                                                           */
-/*               Error handling for the ca65 macroassembler                 */
+/*               Error handling for the ca65 macroassembler                 */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/*               Römerstraße 52                                              */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -37,6 +37,8 @@
 #include <stdlib.h>
 #include <stdarg.h>
 
+/* ca65 */
+#include "filetab.h"
 #include "nexttok.h"
 #include "error.h"
 
 
 
 /* Warning level */
-unsigned WarnLevel         = 1;
-
-/* Messages for internal compiler errors */
-const char _MsgCheckFailed [] =
-    "Check failed: `%s' (= %d), file `%s', line %u\n";
-const char _MsgPrecondition [] =
-    "Precondition violated: `%s' (= %d), file `%s', line %u\n";
-const char _MsgFail [] =
-    "%s, file `%s', line %u\n";
-
+unsigned WarnLevel     = 1;
 
 /* Statistics */
 unsigned ErrorCount    = 0;
@@ -72,24 +65,13 @@ unsigned WarningCount       = 0;
 
 
 
-void WarningMsg (const FilePos* Pos, unsigned WarnNum, va_list ap)
+void WarningMsg (const FilePos* Pos, unsigned Level, const char* Format, va_list ap)
 /* Print warning message. */
 {
-    static const struct {
-       unsigned char   Level;
-       const char*     Msg;
-    } Warnings [WARN_COUNT-1] = {
-       {   1,  "Mask error"                                    },
-               {   2,  "Symbol `%s' is defined but never used"         },
-        {   2,  "Symbol `%s' is imported but never used"       },
-       {   1,  "Cannot track processor status byte"            },
-               {   0,  "User warning: %s"                              },
-    };
-
-    if (Warnings [WarnNum-1].Level <= WarnLevel) {
-       fprintf (stderr, "%s(%lu): Warning #%u: ",
-                GetFileName (Pos->Name), Pos->Line, WarnNum);
-       vfprintf (stderr, Warnings [WarnNum-1].Msg, ap);
+    if (Level <= WarnLevel) {
+       fprintf (stderr, "%s(%lu): Warning: ",
+                GetFileName (Pos->Name), Pos->Line);
+       vfprintf (stderr, Format, ap);
        fprintf (stderr, "\n");
        ++WarningCount;
     }
@@ -97,23 +79,23 @@ void WarningMsg (const FilePos* Pos, unsigned WarnNum, va_list ap)
 
 
 
-void Warning (unsigned WarnNum, ...)
+void Warning (unsigned Level, const char* Format, ...)
 /* Print warning message. */
 {
     va_list ap;
-    va_start (ap, WarnNum);
-    WarningMsg (&CurPos, WarnNum, ap);
+    va_start (ap, Format);
+    WarningMsg (&CurPos, Level, Format, ap);
     va_end (ap);
 }
 
 
 
-void PWarning (const FilePos* Pos, unsigned WarnNum, ...)
+void PWarning (const FilePos* Pos, unsigned Level, const char* Format, ...)
 /* Print warning message giving an explicit file and position. */
 {
     va_list ap;
-    va_start (ap, WarnNum);
-    WarningMsg (Pos, WarnNum, ap);
+    va_start (ap, Format);
+    WarningMsg (Pos, Level, Format, ap);
     va_end (ap);
 }
 
@@ -125,113 +107,46 @@ void PWarning (const FilePos* Pos, unsigned WarnNum, ...)
 
 
 
-void ErrorMsg (const FilePos* Pos, unsigned ErrNum, va_list ap)
+void ErrorMsg (const FilePos* Pos, const char* Format, va_list ap)
 /* Print an error message */
 {
-    static const char* Msgs [ERR_COUNT-1] = {
-       "Command/operation not implemented",
-       "Cannot open include file `%s': %s",
-       "Include nesting too deep",
-        "Invalid input character: %02X",
-       "Hex digit expected",
-       "Digit expected",
-       "`0' or `1' expected",
-       "Numerical overflow",
-        "Control statement expected",
-       "Too many characters",
-       "`:' expected",
-               "`(' expected",
-       "`)' expected",
-       "`]' expected",
-       "`,' expected",
-        "Boolean switch value expected (on/off/+/-)",
-       "`Y' expected",
-       "`X' expected",
-       "Integer constant expected",
-       "String constant expected",
-       "Character constant expected",
-       "Constant expression expected",
-       "Identifier expected",
-       "`.endmacro' expected",
-       "Option key expected",
-       "Command is only valid in 65816 mode",
-       "User error: %s",
-       "String constant too long",
-       "Newline in string constant",
-       "Illegal character constant",
-       "Illegal addressing mode",
-       "Illegal character to start local symbols",
-       "Illegal use of local symbol",
-       "Illegal segment name: `%s'",
-       "Illegal segment attribute",
-       "Illegal macro package name",
-       "Illegal emulation feature",
-       "Syntax error",
-       "Symbol `%s' is already defined",
-       "Undefined symbol `%s'",
-       "Symbol `%s' is marked as import",
-        "Symbol `%s' is marked as export",
-       "Exported symbol `%s' is undefined",
-       "Exported values must be constant",
-       ".IF nesting too deep",
-       "Unexpected end of file",
-       "Unexpected end of line",
-       "Unexpected `%s'",
-       "Division by zero",
-       "Modulo operation with zero",
-        "Range error",
-       "Too many macro parameters",
-       "Macro parameter expected",
-       "Circular reference in symbol definition",
-               "Symbol redeclaration mismatch",
-        "Alignment value must be a power of 2",
-       "Duplicate `.ELSE'",
-               "Conditional assembly branch was never closed",
-       "Lexical level was not terminated correctly",
-       "Segment attribute mismatch",
-       "CPU not supported",
-       "Counter underflow",
-       "Undefined label",
-       "Open `%s´",
-    };
-
-    fprintf (stderr, "%s(%lu): Error #%u: ",
-            GetFileName (Pos->Name), Pos->Line, ErrNum);
-    vfprintf (stderr, Msgs [ErrNum-1], ap);
+    fprintf (stderr, "%s(%lu): Error: ",
+            GetFileName (Pos->Name), Pos->Line);
+    vfprintf (stderr, Format, ap);
     fprintf (stderr, "\n");
     ++ErrorCount;
 }
 
 
 
-void Error (unsigned ErrNum, ...)
+void Error (const char* Format, ...)
 /* Print an error message */
 {
     va_list ap;
-    va_start (ap, ErrNum);
-    ErrorMsg (&CurPos, ErrNum, ap);
+    va_start (ap, Format);
+    ErrorMsg (&CurPos, Format, ap);
     va_end (ap);
 }
 
 
 
-void PError (const FilePos* Pos, unsigned ErrNum, ...)
+void PError (const FilePos* Pos, const char* Format, ...)
 /* Print an error message giving an explicit file and position. */
 {
     va_list ap;
-    va_start (ap, ErrNum);
-    ErrorMsg (Pos, ErrNum, ap);
+    va_start (ap, Format);
+    ErrorMsg (Pos, Format, ap);
     va_end (ap);
 }
 
 
 
-void ErrorSkip (unsigned ErrNum, ...)
+void ErrorSkip (const char* Format, ...)
 /* Print an error message and skip the rest of the line */
 {
     va_list ap;
-    va_start (ap, ErrNum);
-    ErrorMsg (&CurPos, ErrNum, ap);
+    va_start (ap, Format);
+    ErrorMsg (&CurPos, Format, ap);
     va_end (ap);
 
     SkipUntilSep ();
@@ -245,29 +160,14 @@ void ErrorSkip (unsigned ErrNum, ...)
 
 
 
-void Fatal (unsigned FatNum, ...)
+void Fatal (const char* Format, ...)
 /* Print a message about a fatal error and die */
 {
-    static const char* Msgs [FAT_COUNT-1] = {
-       "Maximum number of input files reached",
-       "Out of memory",
-       "Too many segments",
-       "String too long",
-       "Cannot open input file `%s': %s",
-       "Cannot stat input file `%s': %s",
-       "Cannot open output file `%s': %s",
-       "Cannot write to output file `%s': %s",
-       "Cannot open listing file: %s",
-       "Cannot write to listing file: %s",
-       "Cannot read from listing file: %s",
-       "Too many nested constructs",
-       "Too many symbols",
-    };
     va_list ap;
 
-    va_start (ap, FatNum);
-    fprintf (stderr, "Fatal #%u: ", FatNum);
-    vfprintf (stderr, Msgs [FatNum-1], ap);
+    va_start (ap, Format);
+    fprintf (stderr, "Fatal error: ");
+    vfprintf (stderr, Format, ap);
     fprintf (stderr, "\n");
     va_end (ap);
 
@@ -282,7 +182,7 @@ void Internal (const char* Format, ...)
 {
     va_list ap;
     va_start (ap, Format);
-    fprintf (stderr, "Internal assembler error\n");
+    fprintf (stderr, "Internal assembler error:\n");
     vfprintf (stderr, Format, ap);
     va_end (ap);
     fprintf (stderr, "\n");