X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=error.c;h=6da93e2079a279a2c03f5b3a0e6a945c139cbea6;hp=196e4a900aa987009d5182fc63acf1dd7e6c7c89;hb=05d0350b35a6a6b255cb2a3fab7796f5d4ee4d02;hpb=60f204cb9e3905100da0d89f14bb40db764acd9e diff --git a/error.c b/error.c index 196e4a9..6da93e2 100644 --- a/error.c +++ b/error.c @@ -1,19 +1,19 @@ // -// RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System +// RMAC - Reboot's Macro Assembler for all Atari computers // ERROR.C - Error Handling -// Copyright (C) 199x Landon Dyer, 2017 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // #include "error.h" -#include "token.h" +#include #include "listing.h" +#include "token.h" int errcnt; // Error count char * err_fname; // Name of error message file -static const char nl[] = "\n"; static long unused; // For supressing 'write' warnings @@ -22,13 +22,8 @@ static long unused; // For supressing 'write' warnings // int at_eol(void) { - char msg[256]; - if (*tok != EOL) - { - sprintf(msg, "syntax error. expected EOL, found $%X ('%c')", *tok, *tok); - error(msg); - } + error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok); return 0; } @@ -46,17 +41,13 @@ void cantcreat(const char * fn) // // Setup for error message -// o Create error listing file (if necessary) -// o Set current filename +// o Create error listing file (if necessary) +// o Set current filename // void err_setup(void) { char fnbuf[FNSIZ]; -// 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) { strcpy(fnbuf, err_fname); @@ -75,45 +66,24 @@ void err_setup(void) // -// Display error message +// Display error message (uses printf() style variable arguments) // -int error(const char * s) -{ - char buf[EBUFSIZ]; - unsigned int length; - - err_setup(); - - if (listing > 0) - ship_ln(s); - - sprintf(buf, "%s %d: Error: %s%s", curfname, curlineno, s, nl); - length = strlen(buf); - - if (err_flag) - unused = write(err_fd, buf, length); - else - printf("%s", buf); - - taglist('E'); - errcnt++; - - return ERROR; -} - - -int errors(const char * s, char * s1) +int error(const char * text, ...) { char buf[EBUFSIZ]; char buf1[EBUFSIZ]; err_setup(); - sprintf(buf, s, s1); + + va_list arg; + va_start(arg, text); + vsprintf(buf, text, arg); + va_end(arg); if (listing > 0) ship_ln(buf); - sprintf(buf1, "%s %d: Error: %s%s", curfname, curlineno, buf, nl); + sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf); if (err_flag) unused = write(err_fd, buf1, (LONG)strlen(buf1)); @@ -121,70 +91,30 @@ int errors(const char * s, char * s1) printf("%s", buf1); taglist('E'); - ++errcnt; + errcnt++; return ERROR; } -int warn(const char * s) -{ - char buf[EBUFSIZ]; - - err_setup(); - - if (listing > 0) - ship_ln(s); - - sprintf(buf, "%s %d: Warning: %s%s", curfname, curlineno, s, nl); - - if (err_flag) - unused = write(err_fd, buf, (LONG)strlen(buf)); - else - printf("%s", buf); - - taglist('W'); - - return OK; -} - - -int warns(const char * s, char * s1) -{ - char buf[EBUFSIZ]; - char buf1[EBUFSIZ]; - - err_setup(); - sprintf(buf, s, s1); - - if (listing > 0) - ship_ln(s); - - sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl); - - if (err_flag) - unused = write(err_fd, buf1, (LONG)strlen(buf1)); - else - printf("%s", buf1); - - taglist('W'); - - return OK; -} - - -int warni(const char * s, unsigned i) +// +// Display warning message (uses printf() style variable arguments) +// +int warn(const char * text, ...) { char buf[EBUFSIZ]; char buf1[EBUFSIZ]; err_setup(); - sprintf(buf, s, i); + va_list arg; + va_start(arg, text); + vsprintf(buf, text, arg); + va_end(arg); if (listing > 0) ship_ln(buf); - sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl); + sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf); if (err_flag) unused = write(err_fd, buf1, (LONG)strlen(buf1)); @@ -206,7 +136,7 @@ int fatal(const 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\n", curfname, curlineno, s); if (err_flag) unused = write(err_fd, buf, (LONG)strlen(buf)); @@ -222,7 +152,7 @@ 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 #%d\n", curfname, curlineno, n); if (listing > 0) ship_ln(buf);