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
15 int errcnt; // Error count
16 char * err_fname; // Name of error message file
19 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);
44 // Cannot create a file
46 void CantCreateFile(const char * fn)
48 printf("Cannot create file: '%s'\n", fn);
54 // Setup for error message
55 // o Create error listing file (if necessary)
56 // o Set current filename
62 if (err_fname != NULL)
64 strcpy(fnbuf, err_fname);
67 strcpy(fnbuf, firstfname);
71 if ((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
72 CantCreateFile(fnbuf);
80 // Display error message (uses printf() style variable arguments)
82 int error(const char * text, ...)
91 vsprintf(buf, text, arg);
99 switch (cur_inobj->in_type)
102 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
106 // This is basically SetFilenameForErrorReporting() but we don't call it here
107 // as it will clobber curfname. That function is used during fixups only so
108 // it really doesn't matter at that point...
112 uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
113 // Check for absolute top filename (this should never happen)
120 // Advance to the correct record...
121 while (fr != NULL && fnum != 0)
127 // Check for file # record not found (this should never happen either)
131 filename = fr->frec_name;
133 sprintf(buf1, "%s %d: Error: %s\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf);
137 sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
142 // No current file so cur_inobj is NULL
143 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
146 unused = write(err_fd, buf1, (LONG)strlen(buf1));
158 // Display warning message (uses printf() style variable arguments)
160 int warn(const char * text, ...)
168 vsprintf(buf, text, arg);
174 sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
177 unused = write(err_fd, buf1, (LONG)strlen(buf1));
187 int fatal(const char * s)
196 sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
199 unused = write(err_fd, buf, (LONG)strlen(buf));
212 sprintf(buf, "%s %d: Internal error #%d\n", curfname, curlineno, n);
218 unused = write(err_fd, buf, (LONG)strlen(buf));