home *** CD-ROM | disk | FTP | other *** search
- /*
- * error.c
- * Copyright © 1992 Niklas Röjemo
- */
-
- #include <setjmp.h>
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include "error.h"
- #include "input.h"
- #include "output.h"
- #include "riscos.h"
-
- #define MAXERR 100
-
- extern int pedantic;
-
- static int no_errors;
- static int no_warnings;
-
- static int ThrowbackStarted;
- static char *Filename;
-
- static char errbuf[1024];
-
- void errorInit(int throwback,char *filename)
- {
- if(throwback)
- Filename = CanonicalisePath(filename);
- else
- Filename = 0;
- }
-
- void errorFinish(void)
- {
- #ifndef UNIX
- if(ThrowbackStarted>0)
- ThrowbackEnd();
- #endif
- }
-
- #ifndef UNIX
- char *LF(char *buf)
- {
- char *p = buf;
- p--;
- while(*++p)
- if(*p == '\n' || *p == '\r') *p = ' ';
- while(*--p == ' ' && p > buf)
- *p = 0;
- *++p = '\n';
- *++p = 0;
- return buf;
- }
-
- static void TB(int level, int lineno,char *error)
- {
- os_error *err;
- if(!Filename)
- return;
- if(!ThrowbackStarted) {
- err = ThrowbackStart();
- if(err) {
- fprintf(stderr,"ThrowbackStart %s\n",err->errmess);
- exit(-1);
- }
- err = ThrowbackSendStart(Filename);
- if(err) {
- if(pedantic)
- fprintf(stderr,"ThrowbackSendStart %s",err->errmess);
- ThrowbackStarted = -1;
- } else
- ThrowbackStarted = 1;
- }
- if(ThrowbackStarted>0)
- ThrowbackSendError(level,lineno,error);
- }
- #endif
-
- int noerrors(void)
- {
- if(no_errors)
- outputRemove();
- return no_errors;
- }
-
- int nowarnings(void)
- {
- return no_warnings;
- }
-
- extern jmp_buf asmContinue;
- extern jmp_buf asmAbort;
-
- static void fixup(ErrorTag t)
- {
- skiprest();
- if(t == ErrorAbort || no_errors>MAXERR)
- longjmp(asmAbort,1);
- else
- longjmp(asmContinue,1);
- }
-
- void error(ErrorTag e, BOOL c, const char *format, ...)
- {
- char *str;
- int t;
- va_list ap;
- switch(e) {
- case ErrorInfo: str = "INFO"; t = ThrowbackInfo; break;
- case ErrorWarning: str = "WARNING"; t = ThrowbackWarning; no_warnings++; break;
- case ErrorError: str = "ERROR"; t = ThrowbackError; no_errors++; break;
- default: str = "FATAL ERROR"; t = ThrowbackSeriousError; no_errors++; break;
- }
- va_start(ap,format);
- vsprintf(errbuf,format,ap);
- fprintf(stderr,"%s %5d: %s\n",str,inputLineNo,errbuf);
- va_end(ap);
- #ifndef UNIX
- TB(t,inputLineNo,errbuf);
- #endif
- if(!c || no_errors > MAXERR) fixup(e);
- }
-
- void errorLine(int lineno,ErrorTag e, BOOL c, const char *format, ...)
- {
- char *str;
- int t;
- va_list ap;
- switch(e) {
- case ErrorInfo: str = "INFO"; t = ThrowbackInfo; break;
- case ErrorWarning: str = "WARNING"; t = ThrowbackWarning; no_warnings++; break;
- case ErrorError: str = "ERROR"; t = ThrowbackError; no_errors++; break;
- default: str = "FATAL ERROR"; t = ThrowbackSeriousError; no_errors++; break;
- }
- va_start(ap,format);
- vsprintf(errbuf,format,ap);
- fprintf(stderr,"%s %5d: %s\n",str,lineno,errbuf);
- va_end(ap);
- #ifndef UNIX
- TB(t,lineno,errbuf);
- #endif
- if(!c || no_errors > MAXERR) fixup(e);
- }
-