]> Shamusworld >> Repos - rmac/blobdiff - error.c
Remove all remaining traces of "as68_flag" from the codebase (issue #186)
[rmac] / error.c
diff --git a/error.c b/error.c
index d0edaf400240ef95a6270aa566af8a9a690d7d27..6945fc458e408afd476e6e4e3a6d307e28a98805 100644 (file)
--- a/error.c
+++ b/error.c
@@ -8,6 +8,7 @@
 
 #include "error.h"
 #include <stdarg.h>
+#include <token.h>
 #include "listing.h"
 #include "token.h"
 
@@ -18,7 +19,6 @@ char * err_fname;                             // Name of error message file
 // Internal variables
 static long unused;                            // For supressing 'write' warnings
 
-
 //
 // Report error if not at EOL
 //
@@ -39,7 +39,6 @@ int ErrorIfNotAtEOL(void)
        return 0;
 }
 
-
 //
 // Cannot create a file
 //
@@ -49,7 +48,6 @@ void CantCreateFile(const char * fn)
        exit(1);
 }
 
-
 //
 // Setup for error message
 //  o  Create error listing file (if necessary)
@@ -75,7 +73,6 @@ void err_setup(void)
        }
 }
 
-
 //
 // Display error message (uses printf() style variable arguments)
 //
@@ -102,7 +99,37 @@ int error(const char * text, ...)
                        sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
                        break;
                case SRC_IMACRO:
-                       sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf);
+               {
+                       // This is basically SetFilenameForErrorReporting() but we don't
+                       // call it here as it will clobber curfname. That function is used
+                       // during fixups only so it really doesn't matter at that point...
+                       char * filename;
+                       FILEREC * fr;
+                       uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
+
+                       // Check for absolute top filename (this should never happen)
+                       if (fnum == -1)
+                               interror(8);
+                       else
+                       {
+                               fr = filerec;
+
+                               // Advance to the correct record...
+                               while (fr != NULL && fnum != 0)
+                               {
+                                       fr = fr->frec_next;
+                                       fnum--;
+                               }
+                       }
+                       // Check for file # record not found (this should never happen either)
+                       if (fr == NULL)
+                               interror(8);
+
+                       filename = fr->frec_name;
+
+                       sprintf(buf1, "%s %d: Error: %s\nCalled from: %s %d\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf,
+                       curfname, curlineno);
+               }
                        break;
                case SRC_IREPT:
                        sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
@@ -124,7 +151,6 @@ int error(const char * text, ...)
        return ERROR;
 }
 
-
 //
 // Display warning message (uses printf() style variable arguments)
 //
@@ -154,7 +180,6 @@ int warn(const char * text, ...)
        return OK;
 }
 
-
 int fatal(const char * s)
 {
        char buf[EBUFSIZ];
@@ -174,7 +199,6 @@ int fatal(const char * s)
        exit(1);
 }
 
-
 int interror(int n)
 {
        char buf[EBUFSIZ];
@@ -192,4 +216,3 @@ int interror(int n)
 
        exit(1);
 }
-