home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / as / src / c / error < prev    next >
Encoding:
Text File  |  1993-02-10  |  3.0 KB  |  148 lines

  1. /* 
  2.  * error.c
  3.  * Copyright © 1992 Niklas Röjemo
  4.  */
  5.  
  6. #include <setjmp.h>
  7. #include <stdarg.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "error.h"
  13. #include "input.h"
  14. #include "output.h"
  15. #include "riscos.h"
  16.  
  17. #define MAXERR 100
  18.  
  19. extern int pedantic;
  20.  
  21. static int no_errors;
  22. static int no_warnings;
  23.  
  24. static int ThrowbackStarted;
  25. static char *Filename;
  26.  
  27. static char errbuf[1024];
  28.  
  29. void errorInit(int throwback,char *filename)
  30. {
  31.   if(throwback)
  32.     Filename = CanonicalisePath(filename);
  33.   else
  34.     Filename = 0;
  35. }
  36.  
  37. void errorFinish(void)
  38. {
  39. #ifndef UNIX
  40.   if(ThrowbackStarted>0)
  41.     ThrowbackEnd();
  42. #endif
  43. }
  44.  
  45. #ifndef UNIX
  46. char *LF(char *buf)
  47. {
  48.   char *p = buf;
  49.   p--;
  50.   while(*++p)
  51.     if(*p == '\n' || *p == '\r') *p = ' ';
  52.   while(*--p == ' ' && p > buf)
  53.     *p = 0;
  54.   *++p = '\n';
  55.   *++p = 0;
  56.   return buf;
  57. }
  58.  
  59. static void TB(int level, int lineno,char *error)
  60. {
  61.   os_error *err;
  62.   if(!Filename)
  63.     return;
  64.   if(!ThrowbackStarted) {
  65.     err = ThrowbackStart();
  66.     if(err) {
  67.       fprintf(stderr,"ThrowbackStart %s\n",err->errmess);
  68.       exit(-1);
  69.     }
  70.     err = ThrowbackSendStart(Filename);
  71.     if(err) {
  72.         if(pedantic)
  73.            fprintf(stderr,"ThrowbackSendStart %s",err->errmess);
  74.         ThrowbackStarted = -1;
  75.     } else 
  76.         ThrowbackStarted = 1;
  77.   }
  78.   if(ThrowbackStarted>0)
  79.     ThrowbackSendError(level,lineno,error);
  80. }
  81. #endif
  82.  
  83. int noerrors(void)
  84. {
  85.    if(no_errors)
  86.      outputRemove();
  87.    return no_errors;
  88. }
  89.  
  90. int nowarnings(void)
  91. {
  92.   return no_warnings;
  93. }
  94.  
  95. extern jmp_buf asmContinue;
  96. extern jmp_buf asmAbort;
  97.  
  98. static void fixup(ErrorTag t)
  99. {
  100.   skiprest();
  101.   if(t == ErrorAbort || no_errors>MAXERR)
  102.     longjmp(asmAbort,1);
  103.   else
  104.     longjmp(asmContinue,1);
  105. }
  106.  
  107. void error(ErrorTag e, BOOL c, const char *format, ...)
  108. {
  109.   char *str;
  110.   int t;
  111.   va_list ap;
  112.   switch(e) {
  113.     case ErrorInfo:    str = "INFO";        t = ThrowbackInfo;         break;
  114.     case ErrorWarning: str = "WARNING";     t = ThrowbackWarning;      no_warnings++; break;
  115.     case ErrorError:   str = "ERROR";       t = ThrowbackError;        no_errors++;   break;
  116.     default:           str = "FATAL ERROR"; t = ThrowbackSeriousError; no_errors++;   break;
  117.   }
  118.   va_start(ap,format);
  119.   vsprintf(errbuf,format,ap);
  120.   fprintf(stderr,"%s %5d: %s\n",str,inputLineNo,errbuf);
  121.   va_end(ap);
  122. #ifndef UNIX
  123.   TB(t,inputLineNo,errbuf);
  124. #endif
  125.   if(!c || no_errors > MAXERR) fixup(e);
  126. }
  127.  
  128. void errorLine(int lineno,ErrorTag e, BOOL c, const char *format, ...)
  129. {
  130.   char *str;
  131.   int t;
  132.   va_list ap;
  133.   switch(e) {
  134.     case ErrorInfo:    str = "INFO";        t = ThrowbackInfo;         break;
  135.     case ErrorWarning: str = "WARNING";     t = ThrowbackWarning;      no_warnings++; break;
  136.     case ErrorError:   str = "ERROR";       t = ThrowbackError;        no_errors++;   break;
  137.     default:           str = "FATAL ERROR"; t = ThrowbackSeriousError; no_errors++;   break;
  138.   }
  139.   va_start(ap,format);
  140.   vsprintf(errbuf,format,ap);
  141.   fprintf(stderr,"%s %5d: %s\n",str,lineno,errbuf);
  142.   va_end(ap);
  143. #ifndef UNIX
  144.   TB(t,lineno,errbuf);
  145. #endif
  146.   if(!c || no_errors > MAXERR) fixup(e);
  147. }
  148.