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);
105 sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf);
108 sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
113 // No current file so cur_inobj is NULL
114 sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
117 unused = write(err_fd, buf1, (LONG)strlen(buf1));
129 // Display warning message (uses printf() style variable arguments)
131 int warn(const char * text, ...)
139 vsprintf(buf, text, arg);
145 sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
148 unused = write(err_fd, buf1, (LONG)strlen(buf1));
158 int fatal(const char * s)
167 sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
170 unused = write(err_fd, buf, (LONG)strlen(buf));
183 sprintf(buf, "%s %d: Internal error #%d\n", curfname, curlineno, n);
189 unused = write(err_fd, buf, (LONG)strlen(buf));