home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / pascal / src / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  3.9 KB  |  171 lines

  1. /*-
  2.  * Copyright (c) 1980 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)error.c    5.3 (Berkeley) 4/16/91";
  36. #endif /* not lint */
  37.  
  38. #include "whoami.h"
  39. #include "0.h"
  40. #ifndef PI1
  41. #include "tree_ty.h"        /* must be included for yy.h */
  42. #include "yy.h"
  43. #endif
  44.  
  45. char    errpfx    = 'E';
  46. extern    int yyline;
  47. /*
  48.  * Panic is called when impossible
  49.  * (supposedly, anyways) situations
  50.  * are encountered.
  51.  * Panic messages should be short
  52.  * as they do not go to the message
  53.  * file.
  54.  */
  55. panic(s)
  56.     char *s;
  57. {
  58.  
  59. #ifdef DEBUG
  60. #ifdef PI1
  61.     printf("Snark (%s) line=%d\n", s, line);
  62.     abort();
  63. #else
  64.     printf("Snark (%s) line=%d, yyline=%d\n", s, line, yyline);
  65.     abort () ;    /* die horribly */
  66. #endif
  67. #endif
  68. #ifdef PI1
  69.     Perror( "Snark in pi1", s);
  70. #else
  71.     Perror( "Snark in pi", s);
  72. #endif
  73.     pexit(DIED);
  74. }
  75.  
  76. /*
  77.  * Error is called for
  78.  * semantic errors and
  79.  * prints the error and
  80.  * a line number.
  81.  */
  82.  
  83. /*VARARGS1*/
  84.  
  85. error(a1, a2, a3, a4, a5)
  86.     register char *a1;
  87. {
  88.     char errbuf[256];         /* was extern. why? ...pbk */
  89.     register int i;
  90.  
  91.     if (errpfx == 'w' && opt('w') != 0) {
  92.         errpfx = 'E';
  93.         return;
  94.     }
  95.     Enocascade = FALSE;
  96.     geterr((int) a1, errbuf);
  97.     a1 = errbuf;
  98.     if (line < 0)
  99.         line = -line;
  100. #ifndef PI1
  101.     if (opt('l'))
  102.         yyoutline();
  103. #endif
  104.     yysetfile(filename);
  105.     if (errpfx == ' ') {
  106.         printf("  ");
  107.         for (i = line; i >= 10; i /= 10)
  108.             pchr( ' ' );
  109.         printf("... ");
  110.     } else if (Enoline)
  111.         printf("  %c - ", errpfx);
  112.     else
  113.         printf("%c %d - ", errpfx, line);
  114.     printf(a1, a2, a3, a4, a5);
  115.     if (errpfx == 'E')
  116. #ifndef PI0
  117.         eflg = TRUE, codeoff();
  118. #else
  119.         eflg = TRUE;
  120. #endif
  121.     errpfx = 'E';
  122.     if (Eholdnl)
  123.         Eholdnl = FALSE;
  124.     else
  125.         pchr( '\n' );
  126. }
  127.  
  128. /*VARARGS1*/
  129.  
  130. cerror(a1, a2, a3, a4, a5)
  131.     char *a1;
  132. {
  133.  
  134.     if (Enocascade)
  135.         return;
  136.     setpfx(' ');
  137.     error(a1, a2, a3, a4, a5);
  138. }
  139.  
  140. #ifdef PI1
  141.  
  142. /*VARARGS*/
  143.  
  144. derror(a1, a2, a3, a4, a5)
  145.     char *a1, *a2, *a3, *a4, *a5;
  146. {
  147.  
  148.     if (!holdderr)
  149.         error(a1, a2, a3, a4, a5);
  150.     errpfx = 'E';
  151. }
  152.  
  153. char    *lastname, printed, hadsome;
  154.  
  155.     /*
  156.      *    this yysetfile for PI1 only.
  157.      *    the real yysetfile is in yyput.c
  158.      */
  159. yysetfile(name)
  160.     char *name;
  161. {
  162.  
  163.     if (lastname == name)
  164.         return;
  165.     printed |= 1;
  166.     gettime( name );
  167.     printf("%s  %s:\n" , myctime( &tvec ) , name );
  168.     lastname = name;
  169. }
  170. #endif
  171.