1: #
2: /*
3: * pi - Pascal interpreter code translator
4: *
5: * Steven Schultz GTE
6: * Version 1.2.1 October 1996
7: *
8: * Charles Haley, Bill Joy UCB
9: * Version 1.2 January 1979
10: *
11: *
12: * pxp - Pascal execution profiler
13: *
14: * Bill Joy UCB
15: * Version 1.2 January 1979
16: */
17:
18: #include "0.h"
19: #include "yy.h"
20:
21: int line = 1;
22:
23: /*
24: * Yymain initializes each of the utility
25: * clusters and then starts the processing
26: * by calling yyparse.
27: */
28: yymain()
29: {
30:
31: /*
32: * Initialize the scanner
33: */
34: #ifdef PXP
35: if (bracket == 0) {
36: #endif
37: if (getline() == -1) {
38: Perror(filename, "No lines in file");
39: pexit(NOSTART);
40: }
41: #ifdef PXP
42: } else
43: yyline = 0;
44: #endif
45:
46: #ifdef PI
47: magic();
48:
49: #endif
50: /*
51: * Initialize the clusters
52: *
53: initstring();
54: */
55: inithash();
56: inittree();
57: #ifdef PI
58: initnl();
59: #endif
60:
61: /*
62: * Process the input
63: */
64: yyparse();
65: #ifdef PI
66: magic2();
67: #ifdef DEBUG
68: dumpnl(0);
69: #endif
70: #endif
71: #ifdef PXP
72: prttab();
73: if (onefile) {
74: extern int outcol;
75:
76: if (outcol)
77: putchar('\n');
78: flush();
79: if (eflg) {
80: writef(2, "File not rewritten because of errors\n");
81: pexit(ERRS);
82: }
83: signal(1, 1);
84: signal(2, 1);
85: copyfile();
86: }
87: #endif
88: pexit(eflg ? ERRS : AOK);
89: }
90:
91: #ifdef PXP
92: copyfile()
93: {
94: extern int fout[];
95: register int c;
96:
97: close(1);
98: if (creat(firstname, 0644) != 1) {
99: perror(firstname);
100: pexit(ERRS);
101: }
102: lseek(fout[0], (long)0, 0);
103: while ((c = read(fout[0], &fout[3], 512)) > 0) {
104: if (write(1, &fout[3], c) != c) {
105: perror(firstname);
106: pexit(ERRS);
107: }
108: }
109: }
110: #endif
111:
112: static
113: struct {
114: int magic;
115: int txt_size;
116: int data_size;
117: } header;
118:
119: #ifdef PI
120: magic()
121: {
122: int buf[512];
123: register int hf, i;
124:
125: hf = open("/usr/share/pascal/npx_header", 0);
126: if (hf >= 0 && read(hf, buf, 1024) > 16) {
127: header.magic = buf[0];
128: header.txt_size = buf[1];
129: header.data_size = buf[2];
130: for (i = 0; i < 512; i++)
131: word(buf[i]);
132: }
133: close(hf);
134: word(0404);
135: }
136:
137: magic2()
138: {
139: int i;
140:
141: if (header.magic != 0407)
142: return;
143: pflush();
144: lseek(ofil, (long)0, 0);
145: header.data_size = lc - header.txt_size;
146: header.data_size -= 16;
147: write(ofil, &header, sizeof header);
148: lseek(ofil, (long)1022, 0);
149: i = ((int) lc) - 1024;
150: write(ofil, &i, 2);
151: }
152: #endif
153:
154: #ifdef PXP
155: writef(i, cp)
156: {
157:
158: write(i, cp, strlen(cp));
159: }
160: #endif
Defined functions
Defined variables
line
defined in line
21;
never used