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
16 int errcnt; // Error count
17 char * err_fname; // Name of error message file
20 static long unused; // For supressing 'write' warnings
23 // Report error if not at EOL
25 // N.B.: Since this should *never* happen, we can feel free to add whatever
26 // diagnostics that will help in tracking down a problem to this function.
28 int ErrorIfNotAtEOL(void)
32 error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
43 // Cannot create a file
45 void CantCreateFile(const char * fn)
47 printf("Cannot create file: '%s'\n", fn);
52 // Setup for error message
53 // o Create error listing file (if necessary)
54 // o Set current filename
60 if (err_fname != NULL)
62 strcpy(fnbuf, err_fname);
65 strcpy(fnbuf, firstfname);
69 if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
70 CantCreateFile(fnbuf);
77 // Display error message (uses printf() style variable arguments)
79 int error(const char * text, ...)
88 vsprintf(buf, text, arg);
96 switch (cur_inobj->in_type)
99 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
103 // This is basically SetFilenameForErrorReporting() but we don't
104 // call it here as it will clobber curfname. That function is used
105 // during fixups only so it really doesn't matter at that point...
108 uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
110 // Check for absolute top filename (this should never happen)
117 // Advance to the correct record...
118 while (fr != NULL && fnum != 0)
124 // Check for file # record not found (this should never happen either)
128 filename = fr->frec_name;
130 sprintf(buf1, "%s %d: Error: %s\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf);
134 sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
139 // No current file so cur_inobj is NULL
140 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
143 unused = write(err_fd, buf1, (LONG)strlen(buf1));
154 // Display warning message (uses printf() style variable arguments)
156 int warn(const char * text, ...)
164 vsprintf(buf, text, arg);
170 sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
173 unused = write(err_fd, buf1, (LONG)strlen(buf1));
182 int fatal(const char * s)
191 sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
194 unused = write(err_fd, buf, (LONG)strlen(buf));
206 sprintf(buf, "%s %d: Internal error #%d\n", curfname, curlineno, n);
212 unused = write(err_fd, buf, (LONG)strlen(buf));