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
23 "The RISC expression evaluator blew up, sorry" // Error #9
27 int errcnt; // Error count
28 char * err_fname; // Name of error message file
31 static long unused; // For supressing 'write' warnings
34 // Report error if not at EOL
36 // N.B.: Since this should *never* happen, we can feel free to add whatever
37 // diagnostics that will help in tracking down a problem to this function.
39 int ErrorIfNotAtEOL(void)
43 error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
54 // Cannot create a file
56 void CantCreateFile(const char * fn)
58 printf("Cannot create file: '%s'\n", fn);
63 // Setup for error message
64 // o Create error listing file (if necessary)
65 // o Set current filename
71 if (err_fname != NULL)
73 strcpy(fnbuf, err_fname);
76 strcpy(fnbuf, firstfname);
80 if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
81 CantCreateFile(fnbuf);
88 // Display error message (uses printf() style variable arguments)
90 int error(const char * text, ...)
99 vsprintf(buf, text, arg);
107 switch (cur_inobj->in_type)
110 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
114 // This is basically SetFilenameForErrorReporting() but we don't
115 // call it here as it will clobber curfname. That function is used
116 // during fixups only so it really doesn't matter at that point...
119 uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
121 // Check for absolute top filename (this should never happen)
128 // Advance to the correct record...
129 while (fr != NULL && fnum != 0)
135 // Check for file # record not found (this should never happen either)
139 filename = fr->frec_name;
141 sprintf(buf1, "%s %d: Error: %s\nCalled from: %s %d\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf,
142 curfname, curlineno);
146 sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
151 // No current file so cur_inobj is NULL
152 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
155 unused = write(err_fd, buf1, (LONG)strlen(buf1));
166 // Display warning message (uses printf() style variable arguments)
168 int warn(const char * text, ...)
176 vsprintf(buf, text, arg);
182 sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
185 unused = write(err_fd, buf1, (LONG)strlen(buf1));
194 int fatal(const char * s)
203 sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
206 unused = write(err_fd, buf, (LONG)strlen(buf));
218 sprintf(buf, "%s %d: Internal error #%d: %s\n", curfname, curlineno, n, interror_msg[n]);
224 unused = write(err_fd, buf, (LONG)strlen(buf));