1 /*- 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)error.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 #include "whoami.h" 13 #include "0.h" 14 #ifndef PI1 15 #include "tree_ty.h" /* must be included for yy.h */ 16 #include "yy.h" 17 #endif 18 19 char errpfx = 'E'; 20 extern int yyline; 21 /* 22 * Panic is called when impossible 23 * (supposedly, anyways) situations 24 * are encountered. 25 * Panic messages should be short 26 * as they do not go to the message 27 * file. 28 */ 29 panic(s) 30 char *s; 31 { 32 33 #ifdef DEBUG 34 #ifdef PI1 35 printf("Snark (%s) line=%d\n", s, line); 36 abort(); 37 #else 38 printf("Snark (%s) line=%d, yyline=%d\n", s, line, yyline); 39 abort () ; /* die horribly */ 40 #endif 41 #endif 42 #ifdef PI1 43 Perror( "Snark in pi1", s); 44 #else 45 Perror( "Snark in pi", s); 46 #endif 47 pexit(DIED); 48 } 49 50 /* 51 * Error is called for 52 * semantic errors and 53 * prints the error and 54 * a line number. 55 */ 56 57 /*VARARGS1*/ 58 59 error(a1, a2, a3, a4, a5) 60 register char *a1; 61 { 62 char errbuf[256]; /* was extern. why? ...pbk */ 63 register int i; 64 65 if (errpfx == 'w' && opt('w') != 0) { 66 errpfx = 'E'; 67 return; 68 } 69 Enocascade = FALSE; 70 geterr((int) a1, errbuf); 71 a1 = errbuf; 72 if (line < 0) 73 line = -line; 74 #ifndef PI1 75 if (opt('l')) 76 yyoutline(); 77 #endif 78 yysetfile(filename); 79 if (errpfx == ' ') { 80 printf(" "); 81 for (i = line; i >= 10; i /= 10) 82 pchr( ' ' ); 83 printf("... "); 84 } else if (Enoline) 85 printf(" %c - ", errpfx); 86 else 87 printf("%c %d - ", errpfx, line); 88 printf(a1, a2, a3, a4, a5); 89 if (errpfx == 'E') 90 #ifndef PI0 91 eflg = TRUE, codeoff(); 92 #else 93 eflg = TRUE; 94 #endif 95 errpfx = 'E'; 96 if (Eholdnl) 97 Eholdnl = FALSE; 98 else 99 pchr( '\n' ); 100 } 101 102 /*VARARGS1*/ 103 104 cerror(a1, a2, a3, a4, a5) 105 char *a1; 106 { 107 108 if (Enocascade) 109 return; 110 setpfx(' '); 111 error(a1, a2, a3, a4, a5); 112 } 113 114 #ifdef PI1 115 116 /*VARARGS*/ 117 118 derror(a1, a2, a3, a4, a5) 119 char *a1, *a2, *a3, *a4, *a5; 120 { 121 122 if (!holdderr) 123 error(a1, a2, a3, a4, a5); 124 errpfx = 'E'; 125 } 126 127 char *lastname, printed, hadsome; 128 129 /* 130 * this yysetfile for PI1 only. 131 * the real yysetfile is in yyput.c 132 */ 133 yysetfile(name) 134 char *name; 135 { 136 137 if (lastname == name) 138 return; 139 printed |= 1; 140 gettime( name ); 141 printf("%s %s:\n" , myctime( &tvec ) , name ); 142 lastname = name; 143 } 144 #endif 145