Fixed missing error reporting on fixup stage.
authorShamus Hammons <jlhamm@acm.org>
Sun, 3 Feb 2013 17:59:21 +0000 (11:59 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sun, 3 Feb 2013 17:59:21 +0000 (11:59 -0600)
procln.c
rmac.c
sect.c
token.c
token.h

index 6963086c9f18e69e3a3ace6004ae1a24f8404678..5e84c4118fe260c709d41851dcd43ccb58d3b437 100644 (file)
--- a/procln.c
+++ b/procln.c
@@ -134,6 +134,7 @@ loop:                                                       // Line processing loop label
        // Get another line of tokens
        if (tokln() == TKEOF)
        {
+if (verb_flag) printf("Assemble: Found TKEOF flag...\n");
                if (list_flag && listflag)                      // Flush last line of source
                        listeol();
 
diff --git a/rmac.c b/rmac.c
index fa64f777c72f866e5601ab7f305b897b23ea0c7b..7239af2b622bb5d872b8e597ca4a0e544f662eed 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -573,7 +573,7 @@ int process(int argc, char ** argv)
        init_list();                                    // Listing generator
 
        // Process command line arguments and assemble source files
-       for(argno = 0; argno < argc; ++argno)
+       for(argno=0; argno<argc; ++argno)
        {
                if (*argv[argno] == '-')
                {
diff --git a/sect.c b/sect.c
index 66219b6833bac65d9fd489b640076bb3900df352..7edbfb6410c3c8b301d8d4dcab4ba2960987d66b 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -455,6 +455,9 @@ int ResolveFixups(int sno)
                        cfileno = *fup.wp++;
                        curlineno = (int)*fup.wp++;
 DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
+                       // This is based on global vars cfileno, curfname :-P
+                       // This approach is kinda meh as well. I think we can do better than this.
+                       SetFilenameForErrorReporting();
 
                        esym = NULL;
 
diff --git a/token.c b/token.c
index 2877b481172bb209c3deae622e100629fa126e6a..a1d3be8203501a32bb1c5420a6251918aed6f0e9 100644 (file)
--- a/token.c
+++ b/token.c
@@ -170,6 +170,36 @@ void setfnum(WORD fnum)
        curfname = fr->frec_name;
 #endif
 }
+#else
+void SetFilenameForErrorReporting(void)
+{
+       WORD fnum = cfileno;
+
+       // Check for absolute top filename (this should never happen)
+       if (fnum == -1)
+       {
+               curfname = "(*top*)";
+               return;
+       }
+
+       FILEREC * 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)
+       {
+               curfname = "(*NOT FOUND*)";
+               return;
+       }
+
+       curfname = fr->frec_name;
+}
 #endif
 
 
@@ -686,13 +716,14 @@ int include(int handle, char * fname)
        ifile->ifoldlineno = curlineno;                 // Save old line number
        ifile->ifoldfname = curfname;                   // Save old filename
        ifile->ifno = cfileno;                                  // Save old file number
+
 //     cfileno = filecount++;                                  // Compute new file number
-       cfileno = ++filecount;                                  // Compute new file number
+       // NB: This *must* be preincrement, we're adding one to the filecount here!
+       cfileno = ++filecount;                                  // Compute NEW file number
        curfname = strdup(fname);                               // Set current filename (alloc storage)
        curlineno = 0;                                                  // Start on line zero
 
        // Add another file to the file-record
-//     fr = (FILEREC *)amem((LONG)sizeof(FILEREC));
        fr = (FILEREC *)malloc(sizeof(FILEREC));
        fr->frec_next = NULL;
        fr->frec_name = curfname;
@@ -703,9 +734,7 @@ int include(int handle, char * fname)
                last_fr->frec_next = fr;                        // Append to list of filerecs 
 
        last_fr = fr;
-
-       if (verb_flag)
-               printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno);
+       DEBUG printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno);
 
        return OK;
 }
@@ -795,10 +824,11 @@ int fpop(void)
 if (verb_flag) printf("[fpop (pre):  curfname=%s]\n", curfname);
                        curfname = ifile->ifoldfname;   // Set current filename
 if (verb_flag) printf("[fpop (post): curfname=%s]\n", curfname);
+if (verb_flag) printf("[fpop: (pre)  cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
                        curlineno = ifile->ifoldlineno; // Set current line# 
                        DEBUG printf("cfileno=%d ifile->ifno=%d\n", (int)cfileno, (int)ifile->ifno);
-if (verb_flag) printf("[fpop:        cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
                        cfileno = ifile->ifno;                  // Restore current file number
+if (verb_flag) printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
                        break;
                case SRC_IMACRO:                                        // Pop and release an IMACRO
                        imacro = inobj->inobj.imacro;
@@ -947,6 +977,7 @@ int tokln(void)
        case SRC_IFILE:
                if ((ln = getln()) == NULL)
                {
+if (verb_flag) printf("tokln: Calling fpop() from SRC_IFILE...\n");
                        fpop();                                                 // Pop input level
                        goto retry;                                             // Try for more lines 
                }
@@ -993,6 +1024,7 @@ int tokln(void)
        case SRC_IREPT:
                if ((ln = getrln()) == NULL)
                {
+if (verb_flag) printf("tokln: Calling fpop() from SRC_IREPT...\n");
                        fpop();
                        goto retry;
                }
diff --git a/token.h b/token.h
index 2daf6445c1426113d5ec60de3807ea8e969c457c..becd0747f9a6ba93e79566ef258025afad109feb 100644 (file)
--- a/token.h
+++ b/token.h
@@ -156,7 +156,7 @@ extern char * string[];
 // Prototypes
 int include(int, char *);
 void init_token(void);
-//void setfnum(WORD);
+void SetFilenameForErrorReporting(void);
 int tokln(void);
 int fpop(void);
 int d_goto(WORD);