X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=error.c;h=1452e98f8a3ac8339f84a38bbcf43b4ad93942fe;hb=8cc58000c33d121dee192a5d21156c245fb7ab02;hp=9b5460b850e8f35846b6997e8f0a8f5bc82ebca6;hpb=9153334781cd2e23750f4dc002e847606c07a1f0;p=rmac diff --git a/error.c b/error.c index 9b5460b..1452e98 100644 --- a/error.c +++ b/error.c @@ -1,28 +1,31 @@ // -// RMAC - Reboot's Macro Assembler for all Atari computers +// RMAC - Renamed Macro Assembler for all Atari computers // ERROR.C - Error Handling -// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2021 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 +#include #include "listing.h" #include "token.h" +// Exported variables int errcnt; // Error count char * err_fname; // Name of error message file +// Internal variables static long unused; // For supressing 'write' warnings - // // Report error if not at EOL +// // N.B.: Since this should *never* happen, we can feel free to add whatever // diagnostics that will help in tracking down a problem to this function. // -int at_eol(void) +int ErrorIfNotAtEOL(void) { if (*tok != EOL) { @@ -36,17 +39,15 @@ int at_eol(void) return 0; } - // // Cannot create a file // -void cantcreat(const char * fn) +void CantCreateFile(const char * fn) { - printf("cannot create: '%s'\n", fn); + printf("Cannot create file: '%s'\n", fn); exit(1); } - // // Setup for error message // o Create error listing file (if necessary) @@ -66,13 +67,12 @@ void err_setup(void) err_fname = NULL; if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0) - cantcreat(fnbuf); + CantCreateFile(fnbuf); err_flag = 1; } } - // // Display error message (uses printf() style variable arguments) // @@ -99,7 +99,36 @@ 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\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf); + } break; case SRC_IREPT: sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf); @@ -121,7 +150,6 @@ int error(const char * text, ...) return ERROR; } - // // Display warning message (uses printf() style variable arguments) // @@ -151,7 +179,6 @@ int warn(const char * text, ...) return OK; } - int fatal(const char * s) { char buf[EBUFSIZ]; @@ -171,7 +198,6 @@ int fatal(const char * s) exit(1); } - int interror(int n) { char buf[EBUFSIZ]; @@ -189,4 +215,3 @@ int interror(int n) exit(1); } -