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