2 // RMAC - Renamed Macro Assembler for all Atari computers
3 // ERROR.C - Error Handling
4 // Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
13 char * interror_msg[] = {
14 "Unknown internal error", // Error not referenced, should not be displayed
15 "Unknown internal error", // Error not referenced, should not be displayed
16 "Bad MULTX entry in chrtab", // Error #2
17 "Unknown internal error", // Error not referenced, should not be displayed
18 "Bad fixup type", // Error #4
19 "Bad operator in expression stream", // Error #5
20 "Can't find generated code in section", // Error #6
21 "Fixup (loc) out of range" // Error #7
22 "Absolute top filename found" // Error #8
26 int errcnt; // Error count
27 char * err_fname; // Name of error message file
30 static long unused; // For supressing 'write' warnings
33 // Report error if not at EOL
35 // N.B.: Since this should *never* happen, we can feel free to add whatever
36 // diagnostics that will help in tracking down a problem to this function.
38 int ErrorIfNotAtEOL(void)
42 error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
53 // Cannot create a file
55 void CantCreateFile(const char * fn)
57 printf("Cannot create file: '%s'\n", fn);
62 // Setup for error message
63 // o Create error listing file (if necessary)
64 // o Set current filename
70 if (err_fname != NULL)
72 strcpy(fnbuf, err_fname);
75 strcpy(fnbuf, firstfname);
79 if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
80 CantCreateFile(fnbuf);
87 // Display error message (uses printf() style variable arguments)
89 int error(const char * text, ...)
98 vsprintf(buf, text, arg);
106 switch (cur_inobj->in_type)
109 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
113 // This is basically SetFilenameForErrorReporting() but we don't
114 // call it here as it will clobber curfname. That function is used
115 // during fixups only so it really doesn't matter at that point...
118 uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
120 // Check for absolute top filename (this should never happen)
127 // Advance to the correct record...
128 while (fr != NULL && fnum != 0)
134 // Check for file # record not found (this should never happen either)
138 filename = fr->frec_name;
140 sprintf(buf1, "%s %d: Error: %s\nCalled from: %s %d\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf,
141 curfname, curlineno);
145 sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
150 // No current file so cur_inobj is NULL
151 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
154 unused = write(err_fd, buf1, (LONG)strlen(buf1));
165 // Display warning message (uses printf() style variable arguments)
167 int warn(const char * text, ...)
175 vsprintf(buf, text, arg);
181 sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
184 unused = write(err_fd, buf1, (LONG)strlen(buf1));
193 int fatal(const char * s)
202 sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
205 unused = write(err_fd, buf, (LONG)strlen(buf));
217 sprintf(buf, "%s %d: Internal error #%d: %s\n", curfname, curlineno, n, interror_msg[n]);
223 unused = write(err_fd, buf, (LONG)strlen(buf));