X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=error.c;h=81983b14afecc912d844c54385619cf0758f2153;hp=6da93e2079a279a2c03f5b3a0e6a945c139cbea6;hb=c59f7a33730dacf753e066a4002e2f749051a137;hpb=96a5cd69571096f11a3a2a40f6133374f0adc9bb diff --git a/error.c b/error.c index 6da93e2..81983b1 100644 --- a/error.c +++ b/error.c @@ -1,7 +1,7 @@ // // RMAC - Reboot's Macro Assembler for all Atari computers // ERROR.C - Error Handling -// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2019 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -11,19 +11,30 @@ #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 // -int at_eol(void) +// 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 ErrorIfNotAtEOL(void) { if (*tok != EOL) + { error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok); + printf("Token = "); + DumpToken(*tok); + printf("\n"); + DumpTokenBuffer(); + } return 0; } @@ -32,9 +43,9 @@ int at_eol(void) // // 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); } @@ -58,7 +69,7 @@ void err_setup(void) err_fname = NULL; if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0) - cantcreat(fnbuf); + CantCreateFile(fnbuf); err_flag = 1; } @@ -83,7 +94,24 @@ int error(const char * text, ...) if (listing > 0) ship_ln(buf); - sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf); + if (cur_inobj) + { + switch (cur_inobj->in_type) + { + case SRC_IFILE: + 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); + break; + case SRC_IREPT: + sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf); + break; + } + } + else + // No current file so cur_inobj is NULL + sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf); if (err_flag) unused = write(err_fd, buf1, (LONG)strlen(buf1));