home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / toolboxsas.lha / Toolbox / lib / lalr / Errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  3.3 KB  |  124 lines

  1. /* $Id: Errors.c,v 2.8 1992/08/17 14:35:54 grosch rel $ */
  2.  
  3. #include "Errors.h"
  4. #include <stdio.h>
  5. #include "System.h"
  6. #include "Sets.h"
  7. #include "Idents.h"
  8.  
  9.  
  10. static void yyExit(void)
  11.  {
  12.   Exit(1);
  13.  }
  14.  
  15.  
  16. void (*Errors_Exit)(void) = yyExit;
  17.  
  18.  
  19. static void WriteHead(short yyErrorClass, tPosition yyPosition)
  20.  {
  21.   WritePosition(stderr,yyPosition);
  22.   fputs(": ",stderr);
  23.   switch (yyErrorClass)
  24.    {
  25.     case xxFatal       : fputs("Fatal       ",stderr);
  26.                          break;
  27.     case xxRestriction : fputs("Restriction ",stderr);
  28.                          break;
  29.     case xxError       : fputs("Error       ",stderr);
  30.                          break;
  31.     case xxWarning     : fputs("Warning     ",stderr);
  32.                          break;
  33.     case xxRepair      : fputs("Repair      ",stderr);
  34.                          break;
  35.     case xxNote        : fputs("Note        ",stderr);
  36.                          break;
  37.     case xxInformation : fputs("Information ",stderr);
  38.                          break;
  39.     default            : fprintf(stderr,"Error class: %d ",yyErrorClass);
  40.    }
  41.  }
  42.  
  43.  
  44. static void WriteTail(short yyErrorClass)
  45.  {
  46.   fputc('\n',stderr);
  47.   if (yyErrorClass == xxFatal)
  48.     (*Errors_Exit)();
  49.  }
  50.  
  51.  
  52. static void WriteCode(short yyErrorCode)
  53.  {
  54.   switch (yyErrorCode)
  55.    {
  56.     case xxNoText         : break;
  57.     case xxSyntaxError    : fputs("syntax error",stderr);
  58.                             break;
  59.     case xxExpectedTokens : fputs("expected tokens",stderr);
  60.                             break;
  61.     case xxRestartPoint   : fputs("restart point",stderr);
  62.                             break;
  63.     case xxTokenInserted  : fputs("token inserted ",stderr);
  64.                             break;
  65.     default               : fprintf(stderr," error code: %d",yyErrorCode);
  66.    }
  67.  }
  68.  
  69.  
  70. static void WriteInfo(short yyInfoClass, char *yyInfo)
  71.  {
  72.   fputs(": ",stderr);
  73.   switch (yyInfoClass)
  74.    {
  75.     case xxInteger   : fprintf(stderr,"%d",*(int *)yyInfo);
  76.                        break;
  77.     case xxShort     : fprintf(stderr,"%d",*(short *)yyInfo);
  78.                        break;
  79.     case xxCharacter : fprintf(stderr,"%c",*yyInfo);
  80.                        break;
  81.     case xxString    : fputs(yyInfo,stderr);
  82.                        break;
  83.     case xxSet       : WriteSet(stderr, (tSet *)yyInfo);
  84.                        break;
  85.     case xxIdent     : WriteIdent(stderr,*(tIdent *)yyInfo);
  86.                        break;
  87.     default          : fprintf(stderr,"info class: %d",yyInfoClass);
  88.    }
  89.  }
  90.  
  91.  
  92. void ErrorMessage(short yyErrorCode, short yyErrorClass, tPosition yyPosition)
  93.  {
  94.   WriteHead(yyErrorClass,yyPosition);
  95.   WriteCode(yyErrorCode);
  96.   WriteTail(yyErrorClass);
  97.  }
  98.  
  99.  
  100. void ErrorMessageI(short yyErrorCode, short yyErrorClass, tPosition yyPosition, short yyInfoClass, char *yyInfo)
  101.  {
  102.    WriteHead(yyErrorClass,yyPosition);
  103.    WriteCode(yyErrorCode);
  104.    WriteInfo(yyInfoClass,yyInfo);
  105.    WriteTail(yyErrorClass);
  106.  }
  107.  
  108.  
  109. void Message(char *yyErrorText, short yyErrorClass, tPosition yyPosition)
  110.  {
  111.   WriteHead(yyErrorClass,yyPosition);
  112.   fputs(yyErrorText,stderr);
  113.   WriteTail(yyErrorClass);
  114.  }
  115.  
  116.  
  117. void MessageI(char *yyErrorText, short yyErrorClass, tPosition yyPosition, short yyInfoClass, char *yyInfo)
  118.  {
  119.   WriteHead(yyErrorClass,yyPosition);
  120.   fputs(yyErrorText, stderr);
  121.   WriteInfo(yyInfoClass,yyInfo);
  122.   WriteTail(yyErrorClass);
  123.  }
  124.