Commit | Line | Data |
---|---|---|
832026c6 C |
1 | #include "defs" |
2 | ||
3 | struct { char chars[ 10 ]; }; | |
4 | ||
5 | ||
6 | crii() /* create names for intermediate files */ | |
7 | { | |
8 | ||
9 | #ifdef unix | |
10 | sprintf(icfile->filename, "eflc.%d", getpid()); | |
11 | sprintf(idfile->filename, "efld.%d", getpid()); | |
12 | sprintf(iefile->filename, "efle.%d", getpid()); | |
13 | #endif | |
14 | ||
15 | #ifdef gcos | |
16 | sprintf(icfile->filename, "code.efl"); | |
17 | sprintf(idfile->filename, "data.efl"); | |
18 | sprintf(iefile->filename, "equv.efl"); | |
19 | #endif | |
20 | } | |
21 | ||
22 | ||
23 | ||
24 | rmiis() | |
25 | { | |
26 | rmii(icfile); | |
27 | rmii(idfile); | |
28 | rmii(iefile); | |
29 | } | |
30 | ||
31 | ||
32 | ||
33 | ||
34 | rmii(p) /* discard the intermediate file */ | |
35 | struct fileblock *p; | |
36 | { | |
37 | #ifdef unix | |
38 | if(p) | |
39 | { | |
40 | fclose(p->fileptr); | |
41 | unlink(p->filename); | |
42 | } | |
43 | #endif | |
44 | ||
45 | #ifdef gcos | |
46 | if(p) | |
47 | fclose(p->fileptr, "d"); | |
48 | #endif | |
49 | } | |
50 | ||
51 | ||
52 | opiis() | |
53 | { | |
54 | opii(icfile); | |
55 | opii(idfile); | |
56 | opii(iefile); | |
57 | } | |
58 | ||
59 | ||
60 | ||
61 | ||
62 | opii(p) /* open the intermediate file for writing */ | |
63 | struct fileblock *p; | |
64 | { | |
65 | ||
66 | #ifdef unix | |
67 | if( (p->fileptr = fopen(p->filename, "w")) == NULL) | |
68 | fatal("cannot open intermediate file"); | |
69 | #endif | |
70 | ||
71 | #ifdef gcos | |
72 | if( (p->fileptr = fopen(p->filename, "wi")) == NULL) | |
73 | fatal("cannot open intermediate file"); | |
74 | #endif | |
75 | ||
76 | } | |
77 | ||
78 | ||
79 | ||
80 | swii(p) | |
81 | struct fileblock *p; | |
82 | { | |
83 | iifilep = p; | |
84 | } | |
85 | ||
86 | ||
87 | ||
88 | putii(w,n) | |
89 | int *w, n; | |
90 | { | |
91 | if( fwrite(w,sizeof(int),n, iifilep->fileptr) != n) | |
92 | fatal("write error"); | |
93 | } | |
94 | ||
95 | ||
96 | ||
97 | getii(w, n) | |
98 | int *w, n; | |
99 | { | |
100 | if( fread(w,sizeof(int), n, iifilep->fileptr) != n) | |
101 | fatal("read error"); | |
102 | } | |
103 | ||
104 | ||
105 | ||
106 | ||
107 | cliis() | |
108 | { | |
109 | clii(icfile); | |
110 | clii(idfile); | |
111 | clii(iefile); | |
112 | } | |
113 | ||
114 | ||
115 | ||
116 | ||
117 | clii(p) /* close the intermediate file */ | |
118 | struct fileblock *p; | |
119 | { | |
120 | #ifdef unix | |
121 | fclose(p->fileptr); | |
122 | #endif | |
123 | ||
124 | #ifdef gcos | |
125 | fclose(p->fileptr, "rl"); | |
126 | #endif | |
127 | } | |
128 | ||
129 | ||
130 | ||
131 | rewii(p) /* close and rewind the intermediate file for reading */ | |
132 | struct fileblock *p; | |
133 | { | |
134 | swii(p); | |
135 | putic(ICEOF,0); | |
136 | clii(p); | |
137 | ||
138 | #ifdef unix | |
139 | if( (p->fileptr = fopen(p->filename, "r")) == NULL) | |
140 | fatal("cannot open intermediate file"); | |
141 | #endif | |
142 | ||
143 | #ifdef gcos | |
144 | if( (p->fileptr = fopen(p->filename, "ri")) == NULL) | |
145 | fatal("cannot open intermediate file"); | |
146 | #endif | |
147 | } | |
148 | ||
149 | ||
150 | ||
151 | putic(c,p) | |
152 | int c; | |
153 | int p; | |
154 | { | |
155 | int w[2]; | |
156 | prevbg = (c==ICINDENT); | |
157 | w[0] = c; | |
158 | w[1] = p; | |
159 | putii(w,2); | |
160 | } | |
161 | ||
162 | ||
163 | getic(p) | |
164 | int *p; | |
165 | { | |
166 | int w[2]; | |
167 | ||
168 | getii(w,2); | |
169 | *p = w[1]; | |
170 | return( w[0] ); | |
171 | } | |
172 | ||
173 | ||
174 | ||
175 | putsii(l, p) | |
176 | int l; | |
177 | char *p; | |
178 | { | |
179 | int word; | |
180 | register int i, m, n; | |
181 | ||
182 | n = strlen(p); | |
183 | putic(l, n); | |
184 | m = (n/sizeof(int)) ; | |
185 | while(m-- > 0) | |
186 | { | |
187 | for(i=0 ; i<sizeof(int); ++i) | |
188 | word.chars[i] = *p++; | |
189 | putii(&word, 1); | |
190 | } | |
191 | n -= (n/sizeof(int))*sizeof(int); | |
192 | if(n > 0) | |
193 | { | |
194 | for(i=0 ; i<n ; ++i) | |
195 | word.chars[i] = *p++; | |
196 | putii(&word,1); | |
197 | } | |
198 | } | |
199 | ||
200 | ||
201 | ||
202 | ||
203 | ptr getsii(n) | |
204 | int n; | |
205 | { | |
206 | static int incomm[100]; | |
207 | int m; | |
208 | register int *q, *qm; | |
209 | char *p; | |
210 | ||
211 | m = (n + sizeof(int)-1 ) / sizeof(int); | |
212 | q = incomm; | |
213 | qm = q + m; | |
214 | ||
215 | while(q < qm) | |
216 | getii(q++, 1); | |
217 | p = incomm; | |
218 | p[n] = '\0'; | |
219 | ||
220 | return(incomm); | |
221 | } |