Fixed error reporting wrong file, off-by-one error in file record system.
authorShamus Hammons <jlhamm@acm.org>
Sun, 3 Feb 2013 16:39:51 +0000 (10:39 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sun, 3 Feb 2013 16:39:51 +0000 (10:39 -0600)
error.c
sect.c
token.c
token.h

diff --git a/error.c b/error.c
index e17dcc7cd1c832600c24e43f4dfb57b1228ddd38..fa4ceb54a7ee8c64346f70ffaa53660eb2090df3 100644 (file)
--- a/error.c
+++ b/error.c
@@ -47,7 +47,9 @@ void err_setup(void)
 {
        char fnbuf[FNSIZ];
 
-       setfnum(cfileno);
+// This seems like it's unnecessary, as token.c seems to take care of this all by itself.
+// Can restore if it's really needed. If not, into the bit bucket it goes. :-)
+//     setfnum(cfileno);
 
        if (err_fname != NULL)
        {
@@ -79,7 +81,7 @@ int error(const char * s)
        if (listing > 0)
                ship_ln(s);
 
-       sprintf(buf, "%s%d: Error: %s%s", curfname, curlineno, s, nl);
+       sprintf(buf, "%s %d: Error: %s%s", curfname, curlineno, s, nl);
        length = strlen(buf);
 
        if (err_flag)
@@ -93,6 +95,7 @@ int error(const char * s)
        return ERROR;
 }
 
+
 int errors(char * s, char * s1)
 {
        char buf[EBUFSIZ];
@@ -104,7 +107,7 @@ int errors(char * s, char * s1)
        if (listing > 0)
                ship_ln(buf);
 
-       sprintf(buf1, "%s%d: Error: %s%s", curfname, curlineno, buf, nl);
+       sprintf(buf1, "%s %d: Error: %s%s", curfname, curlineno, buf, nl);
 
        if (err_flag)
                write(err_fd, buf1, (LONG)strlen(buf1));
@@ -117,6 +120,7 @@ int errors(char * s, char * s1)
        return ERROR;
 }
 
+
 int warn(char * s)
 {
        char buf[EBUFSIZ];
@@ -126,7 +130,7 @@ int warn(char * s)
        if (listing > 0)
                ship_ln(s);
 
-       sprintf(buf, "%s%d: Warning: %s%s", curfname, curlineno, s, nl);
+       sprintf(buf, "%s %d: Warning: %s%s", curfname, curlineno, s, nl);
 
        if (err_flag)
                write(err_fd, buf, (LONG)strlen(buf));
@@ -138,6 +142,7 @@ int warn(char * s)
        return OK;
 }
 
+
 int warns(char * s, char * s1)
 {
        char buf[EBUFSIZ];
@@ -149,7 +154,7 @@ int warns(char * s, char * s1)
        if (listing > 0)
                ship_ln(s);
 
-       sprintf(buf1, "%s%d: Warning: %s%s", curfname, curlineno, buf, nl);
+       sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
 
        if (err_flag)
                write(err_fd, buf1, (LONG)strlen(buf1));
@@ -161,6 +166,7 @@ int warns(char * s, char * s1)
        return OK;
 }
 
+
 int warni(char * s, unsigned i)
 {
        char buf[EBUFSIZ];
@@ -172,7 +178,7 @@ int warni(char * s, unsigned i)
        if (listing > 0)
                ship_ln(buf);
 
-       sprintf(buf1, "%s%d: Warning: %s%s", curfname, curlineno, buf, nl);
+       sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
 
        if (err_flag)
                write(err_fd, buf1, (LONG)strlen(buf1));
@@ -184,6 +190,7 @@ int warni(char * s, unsigned i)
        return OK;
 }
 
+
 int fatal(char * s)
 {
        char buf[EBUFSIZ];
@@ -193,7 +200,7 @@ int fatal(char * s)
        if (listing > 0)
                ship_ln(s);
 
-       sprintf(buf, "%s%d: Fatal: %s%s", curfname, curlineno, s, nl);
+       sprintf(buf, "%s %d: Fatal: %s%s", curfname, curlineno, s, nl);
 
        if (err_flag)
                write(err_fd, buf, (LONG)strlen(buf));
@@ -203,12 +210,13 @@ int fatal(char * s)
        exit(1);
 }
 
+
 int interror(int n)
 {
        char buf[EBUFSIZ];
 
        err_setup();
-       sprintf(buf, "%s%d: Internal Error Number %d%s", curfname, curlineno, n, nl);
+       sprintf(buf, "%s %d: Internal Error Number %d%s", curfname, curlineno, n, nl);
 
        if (listing > 0)
                ship_ln(buf);
diff --git a/sect.c b/sect.c
index d50d9f3ffc997aebae45dbf8e7fae2148cdf5fb6..66219b6833bac65d9fd489b640076bb3900df352 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -454,6 +454,7 @@ int ResolveFixups(int sno)
                        loc = *fup.lp++;
                        cfileno = *fup.wp++;
                        curlineno = (int)*fup.wp++;
+DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
 
                        esym = NULL;
 
diff --git a/token.c b/token.c
index f30db090dc2d217907ee2a7b09a70413bf02e728..2877b481172bb209c3deae622e100629fa126e6a 100644 (file)
--- a/token.c
+++ b/token.c
@@ -116,20 +116,61 @@ static char * riscregname[] = {
 };
 
 
+// Removing this, provided it doesn't cause unwanted side-effects :-P
+#if 0
 //
 // Make `fnum' the Current `curfname'
+// NOTE: This is currently only called from error() in error.c
 //
 void setfnum(WORD fnum)
 {
-       FILEREC * fr;
+#if 0
+       // NOTE: fnum is ZERO based, this can cause problems if you're not careful!
+       FILEREC * fr = filerec;
 
-       for(fr=filerec; fr!=NULL && fnum--; fr=fr->frec_next);
+       DEBUG printf("[setfnum: fnum=%u]\n", fnum);
+
+       // Advance to the correct record...
+       while (fr != NULL && fnum != 0)
+       {
+               fr = fr->frec_next;
+               fnum--;
+       }
 
        if (fr == NULL)
                curfname = "(*top*)";
        else
                curfname = fr->frec_name;
+
+       DEBUG printf("[setfnum: curfname=%s]\n", curfname);
+#else
+       // 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
 }
+#endif
 
 
 //
@@ -634,7 +675,7 @@ int include(int handle, char * fname)
 
        // Verbose mode
        if (verb_flag)
-               printf("[Including: %s]\n", fname);
+               printf("[include: %s, cfileno=%u]\n", fname, cfileno);
 
        // Alloc and initialize include-descriptors
        inobj = a_inobj(SRC_IFILE);
@@ -645,7 +686,8 @@ 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
+       cfileno = ++filecount;                                  // Compute new file number
        curfname = strdup(fname);                               // Set current filename (alloc storage)
        curlineno = 0;                                                  // Start on line zero
 
@@ -662,6 +704,9 @@ int include(int handle, char * fname)
 
        last_fr = fr;
 
+       if (verb_flag)
+               printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno);
+
        return OK;
 }
 
@@ -747,9 +792,12 @@ int fpop(void)
                        ifile->if_link = f_ifile;
                        f_ifile = ifile;
                        close(ifile->ifhandle);                 // Close source file
+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);
                        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
                        break;
                case SRC_IMACRO:                                        // Pop and release an IMACRO
diff --git a/token.h b/token.h
index eaa7edbf25d5b1a5748f1f34bed8e8ea14d854d4..2daf6445c1426113d5ec60de3807ea8e969c457c 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 setfnum(WORD);
 int tokln(void);
 int fpop(void);
 int d_goto(WORD);