]> git.sur5r.net Git - cc65/blobdiff - src/cc65/error.c
Fixed a bug
[cc65] / src / cc65 / error.c
index 2f443f28d6a9ae002be25add342f7aa205bc858e..cba0a479e97ecb2dca7979037abf8696655a93c7 100644 (file)
 #include <stdlib.h>
 #include <stdarg.h>
 
+/* common */
+#include "print.h"
+
+/* cc65 */
 #include "global.h"
 #include "input.h"
+#include "lineinfo.h"
 #include "scanner.h"
 #include "stmt.h"
 #include "error.h"
@@ -71,9 +76,7 @@ static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va
        vfprintf (stderr, Msg, ap);
        fprintf (stderr, "\n");
 
-       if (Verbose) {
-           fprintf (stderr, "Line: %s\n", line);
-       }
+       Print (stderr, 1, "Line: %s\n", line);
        ++WarningCount;
     }
 }
@@ -85,7 +88,7 @@ void Warning (const char* Format, ...)
 {
     va_list ap;
     va_start (ap, Format);
-    IntWarning (GetCurrentFile(), curpos, Format, ap);
+    IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
     va_end (ap);
 }
 
@@ -109,9 +112,7 @@ static void IntError (const char* Filename, unsigned Line, const char* Msg, va_l
     vfprintf (stderr, Msg, ap);
     fprintf (stderr, "\n");
 
-    if (Verbose) {
-               fprintf (stderr, "Line: %s\n", line);
-    }
+    Print (stderr, 1, "Line: %s\n", line);
     ++ErrorCount;
     if (ErrorCount > 10) {
                Fatal ("Too many errors");
@@ -125,7 +126,7 @@ void Error (const char* Format, ...)
 {
     va_list ap;
     va_start (ap, Format);
-    IntError (GetCurrentFile(), curpos, Format, ap);
+    IntError (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
     va_end (ap);
 }
 
@@ -147,28 +148,46 @@ void Fatal (const char* Format, ...)
 {
     va_list ap;
 
-    fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos);
+    const char* FileName;
+    unsigned    LineNum;
+    if (CurTok.LI) {
+       FileName = GetInputName (CurTok.LI);
+       LineNum  = GetInputLine (CurTok.LI);
+    } else {
+       FileName = GetCurrentFile ();
+       LineNum  = GetCurrentLine ();
+    }
+
+    fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
 
     va_start (ap, Format);
     vfprintf (stderr, Format, ap);
     va_end (ap);
     fprintf (stderr, "\n");
 
-    if (Verbose) {
-               fprintf (stderr, "Line: %s\n", line);
-    }
+    Print (stderr, 1, "Line: %s\n", line);
     exit (EXIT_FAILURE);
 }
 
 
 
-void Internal (char* Format, ...)
+void Internal (const char* Format, ...)
 /* Print a message about an internal compiler error and die. */
 {
     va_list ap;
 
+    const char* FileName;
+    unsigned    LineNum;
+    if (CurTok.LI) {
+       FileName = GetInputName (CurTok.LI);
+       LineNum  = GetInputLine (CurTok.LI);
+    } else {
+       FileName = GetCurrentFile ();
+       LineNum  = GetCurrentLine ();
+    }
+
     fprintf (stderr, "%s(%u): Internal compiler error:\n",
-            GetCurrentFile(), curpos);
+            FileName, LineNum);
 
     va_start (ap, Format);
     vfprintf (stderr, Format, ap);
@@ -177,14 +196,14 @@ void Internal (char* Format, ...)
 
     /* Use abort to create a core dump */
     abort ();
-}
+}              
 
 
 
 void ErrorReport (void)
 /* Report errors (called at end of compile) */
 {
-    if (ErrorCount == 0 && Verbose) {
+    if (ErrorCount == 0 && Verbosity > 0) {
        printf ("No errors.\n");
     }
 }
@@ -192,3 +211,4 @@ void ErrorReport (void)
 
 
 
+