1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)yymain.c 5.4 (Berkeley) 04/16/91"; 10 #endif /* not lint */ 11 12 /* 13 * pi - Pascal interpreter code translator 14 * 15 * Charles Haley, Bill Joy UCB 16 * Version 1.2 November 1978 17 * 18 * 19 * pxp - Pascal execution profiler 20 * 21 * Bill Joy UCB 22 * Version 1.2 November 1978 23 */ 24 25 #include "whoami.h" 26 #include "0.h" 27 #include "yy.h" 28 29 int line = 1; 30 31 /* 32 * Yymain initializes each of the utility 33 * clusters and then starts the processing 34 * by calling yyparse. 35 */ 36 yymain() 37 { 38 39 /* 40 * Initialize the scanner 41 */ 42 #ifdef PXP 43 if (bracket == 0) { 44 #endif 45 if (getline() == -1) { 46 Perror(filename, "No lines in file"); 47 pexit(NOSTART); 48 } 49 #ifdef PXP 50 } else 51 yyline = 0; 52 #endif 53 54 #ifdef PI 55 magic(); 56 57 #endif 58 /* 59 * Initialize the clusters 60 * 61 initstring(); 62 */ 63 inithash(); 64 inittree(); 65 #ifdef PI 66 initnl(); 67 #endif 68 69 /* 70 * Process the input 71 */ 72 yyparse(); 73 #ifdef PI 74 magic2(); 75 #ifdef DEBUG 76 dumpnl(0); 77 #endif 78 #endif 79 #ifdef PXP 80 prttab(); 81 if (onefile) { 82 extern int outcol; 83 84 if (outcol) 85 putchar('\n'); 86 flush(); 87 if (eflg) { 88 writef(2, "File not rewritten because of errors\n"); 89 pexit(ERRS); 90 } 91 signal(1, 1); 92 signal(2, 1); 93 copyfile(); 94 } 95 #endif 96 pexit(eflg ? ERRS : AOK); 97 } 98 99 #ifdef PXP 100 copyfile() 101 { 102 register int c; 103 char buf[BUFSIZ]; 104 105 if (freopen(stdoutn, "r", stdin) == NULL) { 106 perror(stdoutn); 107 pexit(ERRS); 108 } 109 if (freopen(firstname, "w", stdout) == NULL) { 110 perror(firstname); 111 pexit(ERRS); 112 } 113 while ((c = getchar()) > 0) 114 putchar(c); 115 if (ferror(stdout)) 116 perror(stdout); 117 } 118 #endif 119 120 static 121 struct { 122 int magic; 123 unsigned txt_size; 124 unsigned data_size; 125 unsigned bss_size; 126 unsigned syms_size; 127 unsigned entry_point; 128 unsigned tr_size; 129 unsigned dr_size; 130 } header; 131 132 #ifdef PI 133 magic() 134 { 135 136 /* 137 * this is the size of /usr/lib/npxheader 138 */ 139 #define HEAD_BYTES 1024 140 short buf[HEAD_BYTES / sizeof ( short )]; 141 unsigned *ubuf = buf; 142 register int hf, i; 143 144 hf = open("/usr/lib/npx_header", 0); 145 if (hf >= 0 && read(hf, buf, HEAD_BYTES) > sizeof header) { 146 header.magic = ubuf[0]; 147 header.txt_size = ubuf[1]; 148 header.data_size = ubuf[2]; 149 header.bss_size = ubuf[3]; 150 header.syms_size = ubuf[4]; 151 header.entry_point = ubuf[5]; 152 header.tr_size = ubuf[6]; 153 header.dr_size = ubuf[7]; 154 for (i = 0; i < HEAD_BYTES / sizeof ( short ); i++) 155 word(buf[i]); 156 } 157 close(hf); 158 word(0404); 159 } 160 161 magic2() 162 { 163 short i; 164 165 if (header.magic != 0407) 166 panic ( "magic2" ); 167 pflush(); 168 lseek(ofil, 0l, 0); 169 header.data_size = ( unsigned ) lc - header.txt_size; 170 header.data_size -= sizeof header; 171 write(ofil, &header, sizeof header); 172 lseek(ofil, ( long ) ( HEAD_BYTES - sizeof ( short ) ) , 0); 173 i = ( ( unsigned ) lc) - HEAD_BYTES; 174 write(ofil, &i, 2); 175 } 176 #endif 177 178 #ifdef PXP 179 writef(i, cp) 180 { 181 182 write(i, cp, strlen(cp)); 183 } 184 #endif 185