2011-12-27 00:50:27 +02:00
|
|
|
//
|
2021-03-08 00:43:25 +02:00
|
|
|
// RMAC - Renamed Macro Assembler for all Atari computers
|
2011-12-27 00:50:27 +02:00
|
|
|
// ERROR.C - Error Handling
|
2021-03-08 00:43:25 +02:00
|
|
|
// Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends
|
2011-12-27 00:50:27 +02:00
|
|
|
// RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
|
2015-02-19 16:56:14 +02:00
|
|
|
// Source utilised with the kind permission of Landon Dyer
|
2011-12-27 00:50:27 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "error.h"
|
2017-06-24 03:03:24 +03:00
|
|
|
#include <stdarg.h>
|
2023-06-18 16:05:01 +03:00
|
|
|
#include "token.h"
|
2011-12-27 00:50:27 +02:00
|
|
|
#include "listing.h"
|
2021-10-17 12:10:32 +03:00
|
|
|
char * interror_msg[] = {
|
|
|
|
"Unknown internal error", // Error not referenced, should not be displayed
|
|
|
|
"Unknown internal error", // Error not referenced, should not be displayed
|
|
|
|
"Bad MULTX entry in chrtab", // Error #2
|
|
|
|
"Unknown internal error", // Error not referenced, should not be displayed
|
|
|
|
"Bad fixup type", // Error #4
|
|
|
|
"Bad operator in expression stream", // Error #5
|
|
|
|
"Can't find generated code in section", // Error #6
|
2022-05-30 22:30:11 +03:00
|
|
|
"Fixup (loc) out of range", // Error #7
|
|
|
|
"Absolute top filename found", // Error #8
|
|
|
|
"The RISC expression evaluator blew up, sorry" // Error #9
|
2021-10-17 12:10:32 +03:00
|
|
|
};
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2019-08-08 02:24:52 +03:00
|
|
|
// Exported variables
|
2013-03-05 19:47:22 +02:00
|
|
|
int errcnt; // Error count
|
|
|
|
char * err_fname; // Name of error message file
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2019-08-08 02:24:52 +03:00
|
|
|
// Internal variables
|
2013-03-05 19:47:22 +02:00
|
|
|
static long unused; // For supressing 'write' warnings
|
2011-12-27 00:50:27 +02:00
|
|
|
|
|
|
|
//
|
2012-01-11 19:31:31 +02:00
|
|
|
// Report error if not at EOL
|
2019-08-08 02:24:52 +03:00
|
|
|
//
|
2017-11-21 15:54:55 +02:00
|
|
|
// 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.
|
2011-12-27 00:50:27 +02:00
|
|
|
//
|
2019-08-08 02:24:52 +03:00
|
|
|
int ErrorIfNotAtEOL(void)
|
2012-01-11 19:31:31 +02:00
|
|
|
{
|
2017-11-29 15:57:58 +02:00
|
|
|
if (*tok != EOL)
|
2017-11-21 15:54:55 +02:00
|
|
|
{
|
2017-11-29 15:57:58 +02:00
|
|
|
error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
|
2017-11-21 15:54:55 +02:00
|
|
|
printf("Token = ");
|
2017-11-29 15:57:58 +02:00
|
|
|
DumpToken(*tok);
|
2017-11-21 15:54:55 +02:00
|
|
|
printf("\n");
|
|
|
|
DumpTokenBuffer();
|
|
|
|
}
|
2012-01-11 19:31:31 +02:00
|
|
|
|
2013-03-05 19:47:22 +02:00
|
|
|
return 0;
|
2011-12-27 00:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-01-16 19:16:33 +02:00
|
|
|
// Cannot create a file
|
2011-12-27 00:50:27 +02:00
|
|
|
//
|
2019-08-08 02:24:52 +03:00
|
|
|
void CantCreateFile(const char * fn)
|
2012-01-11 19:31:31 +02:00
|
|
|
{
|
2019-08-08 02:24:52 +03:00
|
|
|
printf("Cannot create file: '%s'\n", fn);
|
2013-03-05 19:47:22 +02:00
|
|
|
exit(1);
|
2011-12-27 00:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2015-01-16 19:16:33 +02:00
|
|
|
// Setup for error message
|
2017-06-24 03:03:24 +03:00
|
|
|
// o Create error listing file (if necessary)
|
|
|
|
// o Set current filename
|
2011-12-27 00:50:27 +02:00
|
|
|
//
|
2012-01-11 19:31:31 +02:00
|
|
|
void err_setup(void)
|
|
|
|
{
|
|
|
|
char fnbuf[FNSIZ];
|
|
|
|
|
|
|
|
if (err_fname != NULL)
|
|
|
|
{
|
|
|
|
strcpy(fnbuf, err_fname);
|
|
|
|
|
|
|
|
if (*fnbuf == EOS)
|
|
|
|
strcpy(fnbuf, firstfname);
|
|
|
|
|
|
|
|
err_fname = NULL;
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
|
2019-08-08 02:24:52 +03:00
|
|
|
CantCreateFile(fnbuf);
|
2012-01-11 19:31:31 +02:00
|
|
|
|
|
|
|
err_flag = 1;
|
|
|
|
}
|
2011-12-27 00:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2017-06-24 03:03:24 +03:00
|
|
|
// Display error message (uses printf() style variable arguments)
|
2011-12-27 00:50:27 +02:00
|
|
|
//
|
2017-06-24 03:03:24 +03:00
|
|
|
int error(const char * text, ...)
|
2012-01-11 19:31:31 +02:00
|
|
|
{
|
|
|
|
char buf[EBUFSIZ];
|
|
|
|
char buf1[EBUFSIZ];
|
|
|
|
|
|
|
|
err_setup();
|
2017-06-24 03:03:24 +03:00
|
|
|
|
|
|
|
va_list arg;
|
|
|
|
va_start(arg, text);
|
|
|
|
vsprintf(buf, text, arg);
|
|
|
|
va_end(arg);
|
2012-01-11 19:31:31 +02:00
|
|
|
|
|
|
|
if (listing > 0)
|
|
|
|
ship_ln(buf);
|
|
|
|
|
2018-01-23 14:46:00 +02:00
|
|
|
if (cur_inobj)
|
2017-11-29 20:47:38 +02:00
|
|
|
{
|
2018-01-23 14:46:00 +02:00
|
|
|
switch (cur_inobj->in_type)
|
|
|
|
{
|
|
|
|
case SRC_IFILE:
|
|
|
|
sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
|
|
|
|
break;
|
|
|
|
case SRC_IMACRO:
|
2020-09-02 22:49:42 +03:00
|
|
|
{
|
2021-06-09 04:45:29 +03:00
|
|
|
// 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...
|
2020-09-02 22:49:42 +03:00
|
|
|
char * filename;
|
|
|
|
FILEREC * fr;
|
|
|
|
uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
|
2021-06-09 04:45:29 +03:00
|
|
|
|
2020-09-02 22:49:42 +03:00
|
|
|
// 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;
|
|
|
|
|
2021-06-09 04:48:19 +03:00
|
|
|
sprintf(buf1, "%s %d: Error: %s\nCalled from: %s %d\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf,
|
|
|
|
curfname, curlineno);
|
2020-09-02 22:49:42 +03:00
|
|
|
}
|
2018-01-23 14:46:00 +02:00
|
|
|
break;
|
|
|
|
case SRC_IREPT:
|
|
|
|
sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
|
|
|
|
break;
|
|
|
|
}
|
2017-11-29 20:47:38 +02:00
|
|
|
}
|
2018-01-23 14:46:00 +02:00
|
|
|
else
|
|
|
|
// No current file so cur_inobj is NULL
|
|
|
|
sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
|
2012-01-11 19:31:31 +02:00
|
|
|
|
|
|
|
if (err_flag)
|
2013-03-05 19:47:22 +02:00
|
|
|
unused = write(err_fd, buf1, (LONG)strlen(buf1));
|
2012-01-11 19:31:31 +02:00
|
|
|
else
|
|
|
|
printf("%s", buf1);
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
taglist('E');
|
2017-06-24 03:03:24 +03:00
|
|
|
errcnt++;
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-18 04:06:46 +02:00
|
|
|
return ERROR;
|
2011-12-27 00:50:27 +02:00
|
|
|
}
|
|
|
|
|
2017-06-24 03:03:24 +03:00
|
|
|
//
|
|
|
|
// Display warning message (uses printf() style variable arguments)
|
|
|
|
//
|
|
|
|
int warn(const char * text, ...)
|
2012-01-11 19:31:31 +02:00
|
|
|
{
|
|
|
|
char buf[EBUFSIZ];
|
|
|
|
char buf1[EBUFSIZ];
|
|
|
|
|
|
|
|
err_setup();
|
2017-06-24 03:03:24 +03:00
|
|
|
va_list arg;
|
|
|
|
va_start(arg, text);
|
|
|
|
vsprintf(buf, text, arg);
|
|
|
|
va_end(arg);
|
2012-01-11 19:31:31 +02:00
|
|
|
|
|
|
|
if (listing > 0)
|
|
|
|
ship_ln(buf);
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2017-06-24 03:03:24 +03:00
|
|
|
sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
if (err_flag)
|
2013-03-05 19:47:22 +02:00
|
|
|
unused = write(err_fd, buf1, (LONG)strlen(buf1));
|
2012-01-11 19:31:31 +02:00
|
|
|
else
|
|
|
|
printf("%s", buf1);
|
|
|
|
|
|
|
|
taglist('W');
|
|
|
|
|
2012-01-18 04:06:46 +02:00
|
|
|
return OK;
|
2011-12-27 00:50:27 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 19:47:22 +02:00
|
|
|
int fatal(const char * s)
|
2012-01-11 19:31:31 +02:00
|
|
|
{
|
|
|
|
char buf[EBUFSIZ];
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
err_setup();
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
if (listing > 0)
|
|
|
|
ship_ln(s);
|
|
|
|
|
2017-06-24 03:03:24 +03:00
|
|
|
sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
|
2012-01-11 19:31:31 +02:00
|
|
|
|
|
|
|
if (err_flag)
|
2013-03-05 19:47:22 +02:00
|
|
|
unused = write(err_fd, buf, (LONG)strlen(buf));
|
2012-01-11 19:31:31 +02:00
|
|
|
else
|
|
|
|
printf("%s", buf);
|
|
|
|
|
|
|
|
exit(1);
|
2011-12-27 00:50:27 +02:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
int interror(int n)
|
|
|
|
{
|
|
|
|
char buf[EBUFSIZ];
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
err_setup();
|
2021-10-17 12:10:32 +03:00
|
|
|
sprintf(buf, "%s %d: Internal error #%d: %s\n", curfname, curlineno, n, interror_msg[n]);
|
2011-12-27 00:50:27 +02:00
|
|
|
|
2012-01-11 19:31:31 +02:00
|
|
|
if (listing > 0)
|
|
|
|
ship_ln(buf);
|
|
|
|
|
|
|
|
if (err_flag)
|
2013-03-05 19:47:22 +02:00
|
|
|
unused = write(err_fd, buf, (LONG)strlen(buf));
|
2012-01-11 19:31:31 +02:00
|
|
|
else
|
|
|
|
printf("%s", buf);
|
|
|
|
|
|
|
|
exit(1);
|
2011-12-27 01:54:45 +02:00
|
|
|
}
|