-
-void err_setup(void) {
- char fnbuf[FNSIZ];
-
- setfnum(cfileno);
- if(err_fname != NULL) {
- strcpy(fnbuf, err_fname);
- if(*fnbuf == EOS) {
- strcpy(fnbuf, firstfname);
- }
- err_fname = NULL;
-
- if((err_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
- cantcreat(fnbuf);
- err_flag = 1;
- }
+int error(const char * text, ...)
+{
+ char buf[EBUFSIZ];
+ char buf1[EBUFSIZ];
+
+ err_setup();
+
+ va_list arg;
+ va_start(arg, text);
+ vsprintf(buf, text, arg);
+ va_end(arg);
+
+ if (listing > 0)
+ ship_ln(buf);
+
+ if (cur_inobj)
+ {
+ switch (cur_inobj->in_type)
+ {
+ case SRC_IFILE:
+ sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
+ break;
+ case SRC_IMACRO:
+ {
+ // This is basically SetFilenameForErrorReporting() but we don't
+ // call it here as it will clobber curfname. That function is used
+ // during fixups only so it really doesn't matter at that point...
+ char * filename;
+ FILEREC * fr;
+ uint16_t fnum = cur_inobj->inobj.imacro->im_macro->cfileno;
+
+ // Check for absolute top filename (this should never happen)
+ if (fnum == -1)
+ interror(8);
+ else
+ {
+ fr = filerec;
+
+ // Advance to the correct record...
+ while (fr != NULL && fnum != 0)
+ {
+ fr = fr->frec_next;
+ fnum--;
+ }
+ }
+ // Check for file # record not found (this should never happen either)
+ if (fr == NULL)
+ interror(8);
+
+ filename = fr->frec_name;
+
+ sprintf(buf1, "%s %d: Error: %s\nCalled from: %s %d\n", filename, cur_inobj->inobj.imacro->im_macro->lineList->lineno, buf,
+ curfname, curlineno);
+ }
+ break;
+ case SRC_IREPT:
+ sprintf(buf1, "%s %d: Error: %s\n", curfname, cur_inobj->inobj.irept->lineno, buf);
+ break;
+ }
+ }
+ else
+ // No current file so cur_inobj is NULL
+ sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
+
+ if (err_flag)
+ unused = write(err_fd, buf1, (LONG)strlen(buf1));
+ else
+ printf("%s", buf1);
+
+ taglist('E');
+ errcnt++;
+
+ return ERROR;