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