]> Shamusworld >> Repos - rmac/blobdiff - error.c
Fix for "*" getting bad section attributes, reported by A. Seed.
[rmac] / error.c
diff --git a/error.c b/error.c
index c73cec52b0869af16b2c350c5e393727ea3c0434..83a6f372f73e869e6e3a9abc2ec9c12ffe0c16a9 100644 (file)
--- a/error.c
+++ b/error.c
@@ -3,17 +3,18 @@
 // ERROR.C - Error Handling
 // Copyright (C) 199x Landon Dyer, 2011 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
-// Source Utilised with the Kind Permission of Landon Dyer
+// Source utilised with the kind permission of Landon Dyer
 //
 
 #include "error.h"
 #include "token.h"
 #include "listing.h"
 
-int errcnt;                                                                    // Error count
-char * err_fname;                                                      // Name of error message file
+int errcnt;                                            // Error count
+char * err_fname;                              // Name of error message file
 
-static char nl[] = "\n";
+static const char nl[] = "\n";
+static long unused;                            // For supressing 'write' warnings
 
 
 //
@@ -21,25 +22,30 @@ static char nl[] = "\n";
 //
 int at_eol(void)
 {
-   if (*tok != EOL)
-      error("syntax error");
+       char msg[256];
 
-   return 0;
+       if (*tok != EOL)
+       {
+               sprintf(msg, "syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
+               error(msg);
+       }
+
+       return 0;
 }
 
 
 //
-// Cannot Create a File
+// Cannot create a file
 //
-void cantcreat(char * fn)
+void cantcreat(const char * fn)
 {
-   printf("cannot create: '%s'\n", fn);
-   exit(1);
+       printf("cannot create: '%s'\n", fn);
+       exit(1);
 }
 
 
 //
-// Setup for Error Message
+// Setup for error message
 // o  Create error listing file (if necessary)
 // o  Set current filename
 //
@@ -47,7 +53,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)
        {
@@ -67,9 +75,9 @@ void err_setup(void)
 
 
 //
-// Display Error Message
+// Display error message
 //
-int error(char * s)
+int error(const char * s)
 {
        char buf[EBUFSIZ];
        unsigned int length;
@@ -79,21 +87,22 @@ int error(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)
-               write(err_fd, buf, length);
+               unused = write(err_fd, buf, length);
        else
                printf("%s", buf);
 
        taglist('E');
-       ++errcnt;
+       errcnt++;
 
        return ERROR;
 }
 
-int errors(char * s, char * s1)
+
+int errors(const char * s, char * s1)
 {
        char buf[EBUFSIZ];
        char buf1[EBUFSIZ];
@@ -104,10 +113,10 @@ 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));
+               unused = write(err_fd, buf1, (LONG)strlen(buf1));
        else
                printf("%s", buf1);
 
@@ -117,7 +126,8 @@ int errors(char * s, char * s1)
        return ERROR;
 }
 
-int warn(char * s)
+
+int warn(const char * s)
 {
        char buf[EBUFSIZ];
 
@@ -126,10 +136,10 @@ 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));
+               unused = write(err_fd, buf, (LONG)strlen(buf));
        else
                printf("%s", buf);
 
@@ -138,7 +148,8 @@ int warn(char * s)
        return OK;
 }
 
-int warns(char * s, char * s1)
+
+int warns(const char * s, char * s1)
 {
        char buf[EBUFSIZ];
        char buf1[EBUFSIZ];
@@ -149,10 +160,10 @@ 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));
+               unused = write(err_fd, buf1, (LONG)strlen(buf1));
        else
                printf("%s", buf1);
 
@@ -161,7 +172,8 @@ int warns(char * s, char * s1)
        return OK;
 }
 
-int warni(char * s, unsigned i)
+
+int warni(const char * s, unsigned i)
 {
        char buf[EBUFSIZ];
        char buf1[EBUFSIZ];
@@ -172,10 +184,10 @@ 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));
+               unused = write(err_fd, buf1, (LONG)strlen(buf1));
        else
                printf("%s", buf1);
 
@@ -184,7 +196,8 @@ int warni(char * s, unsigned i)
        return OK;
 }
 
-int fatal(char * s)
+
+int fatal(const char * s)
 {
        char buf[EBUFSIZ];
 
@@ -193,30 +206,32 @@ 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));
+               unused = write(err_fd, buf, (LONG)strlen(buf));
        else
                printf("%s", buf);
 
        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);
 
        if (err_flag)
-               write(err_fd, buf, (LONG)strlen(buf));
+               unused = write(err_fd, buf, (LONG)strlen(buf));
        else
                printf("%s", buf);
 
        exit(1);
 }
+