|
|
1.1 root 1: #
2: /*
3: * input library
4: *
5: * S. R. Bourne
6: * Bell Telephone Laboratories
7: *
8: */
9:
10: #include "input.h"
11:
12: INT peekc;
13: INT eof;
14: FILEBLK _stdfile;
15: FILE standin = &_stdfile;
16:
17:
18: readc()
19: {
20: REG INT c;
21: REG INT len;
22: REG FILE f;
23:
24: retry:
25: IF peekc
26: THEN c=peekc&LOBYTE; peekc=0;
27: ELIF (f=standin, f->fnxt!=f->fend)
28: THEN c = *f->fnxt++;
29: IF c==NL THEN f->flin++; FI
30: ELIF eof ORF f->fdes<0
31: THEN c=EOF; eof++;
32: ELIF (len=read(f->fdes,f->fbuf,f->fsiz))<=0
33: THEN close(f->fdes); f->fdes = -1; c=EOF; eof++;
34: ELSE f->fend = (f->fnxt = f->fbuf)+len;
35: goto retry;
36: FI
37: return(c);
38: }
39:
40: initf(fd)
41: FILE fd;
42: {
43: REG FILE f=standin;
44:
45: f->fdes=fd; f->fsiz=BUFSIZ;
46: f->fnxt=f->fend=f->fbuf; f->flin=1;
47: eof=FALSE;
48: }
49:
50: estabf(s)
51: REG STRING s;
52: {
53: REG FILE f;
54:
55: (f=standin)->fdes = -1;
56: f->fend=length(s)+(f->fnxt=s);
57: f->flin=1;
58: return(eof=(s==0));
59: }
60:
61: push(af)
62: FILE af;
63: {
64: REG FILE f;
65:
66: (f=af)->fstak=standin;
67: f->feof=eof;
68: standin=f;
69: }
70:
71: pop()
72: {
73: REG FILE f;
74:
75: IF (f=standin)->fstak
76: THEN IF f->fdes>=0 THEN close(f->fdes); FI
77: standin=f->fstak; eof=f->feof;
78: return(TRUE);
79: ELSE return(FALSE);
80: FI
81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.