home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pi1 / error.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  124 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. /*
  4.  * pi - Pascal interpreter code translator
  5.  *
  6.  * Charles Haley, Bill Joy UCB
  7.  * Version 1.2 January 1979
  8.  */
  9.  
  10. #include "0.h"
  11. #ifndef PI1
  12. #include "yy.h"
  13. #endif
  14.  
  15. char    errpfx    'E';
  16. extern    int yyline;
  17. /*
  18.  * Panic is called when impossible
  19.  * (supposedly, anyways) situations
  20.  * are encountered.
  21.  * Panic messages should be short
  22.  * as they do not go to the message
  23.  * file.
  24.  */
  25. panic(s)
  26.     char *s;
  27. {
  28.  
  29. #ifdef DEBUG
  30. #ifdef PI1
  31.     printf("Snark (%s) line=%d\n", s, line);
  32.     abort();
  33. #else
  34.     printf("Snark (%s) line=%d, yyline=%d\n", s, line, yyline);
  35. #endif
  36. #endif
  37. #ifdef PI1
  38.     Perror( "Snark in pi1", s);
  39. #else
  40.     Perror( "Snark in pi", s);
  41. #endif
  42.     pexit(DIED);
  43. }
  44.  
  45. extern    char *errfile;
  46. /*
  47.  * Error is called for
  48.  * semantic errors and
  49.  * prints the error and
  50.  * a line number.
  51.  */
  52. error(a1, a2, a3, a4)
  53.     register char *a1;
  54. {
  55.     char buf[256];
  56.     register int i;
  57.  
  58.     if (errpfx == 'w' && opt('w') != 0)
  59.         return;
  60.     Enocascade = 0;
  61.     geterr(a1, buf);
  62.     a1 = buf;
  63.     if (line < 0)
  64.         line = -line;
  65. #ifndef PI1
  66.     if (opt('l'))
  67.         yyoutline();
  68. #endif
  69.     yysetfile(filename);
  70.     if (errpfx == ' ') {
  71.         printf("  ");
  72.         for (i = line; i >= 10; i =/ 10)
  73.             putchar(' ');
  74.         printf("... ");
  75.     } else if (Enoline)
  76.         printf("  %c - ", errpfx);
  77.     else
  78.         printf("%c %d - ", errpfx, line);
  79.     printf(a1, a2, a3, a4);
  80.     if (errpfx == 'E')
  81. #ifndef PI0
  82.         eflg++, cgenflg++;
  83. #else
  84.         eflg++;
  85. #endif
  86.     errpfx = 'E';
  87.     if (Eholdnl)
  88.         Eholdnl = 0;
  89.     else
  90.         putchar('\n');
  91. }
  92.  
  93. cerror(a1, a2, a3, a4)
  94. {
  95.  
  96.     if (Enocascade)
  97.         return;
  98.     setpfx(' ');
  99.     error(a1, a2, a3, a4);
  100. }
  101.  
  102. #ifdef PI1
  103. derror(a1, a2, a3, a4)
  104. {
  105.  
  106.     if (!holdderr)
  107.         error(a1, a2, a3, a4);
  108.     errpfx = 'E';
  109. }
  110.  
  111. char    *lastname, printed, hadsome;
  112.  
  113. yysetfile(name)
  114.     char *name;
  115. {
  116.  
  117.     if (lastname == name)
  118.         return;
  119.     printed =| 1;
  120.     printf("%s:\n", name);
  121.     lastname = name;
  122. }
  123. #endif
  124.