1a8a1e94bSdlw /*
2*9e4573b6Slibs char id_iio[] = "@(#)iio.c 1.7";
3a8a1e94bSdlw *
4a8a1e94bSdlw * internal (character array) i/o
5a8a1e94bSdlw */
6a8a1e94bSdlw
7a8a1e94bSdlw #include "fio.h"
8a8a1e94bSdlw #include "lio.h"
9a8a1e94bSdlw
10*9e4573b6Slibs LOCAL icilist *svic; /* active internal io list */
11*9e4573b6Slibs
12a8a1e94bSdlw extern int rd_ed(),rd_ned(),w_ed(),w_ned();
13a8a1e94bSdlw extern int l_read(),l_write();
14a8a1e94bSdlw int z_wnew(),z_rnew(),z_tab();
15a8a1e94bSdlw
16*9e4573b6Slibs LOCAL
z_getc()17a8a1e94bSdlw z_getc()
18a8a1e94bSdlw {
19a8a1e94bSdlw if(icptr >= icend && !recpos) /* new rec beyond eof */
20a8a1e94bSdlw { leof = EOF;
21a8a1e94bSdlw return(EOF);
22a8a1e94bSdlw }
23e718b566Sdlw if(formatted == LISTDIRECTED) return(EOF);
24*9e4573b6Slibs if(recpos++ < svic->icirlen) return(*icptr++);
25a8a1e94bSdlw return(' ');
26a8a1e94bSdlw }
27a8a1e94bSdlw
28*9e4573b6Slibs LOCAL
z_putc(c)29a8a1e94bSdlw z_putc(c) char c;
30a8a1e94bSdlw {
31a8a1e94bSdlw if(icptr < icend)
32a8a1e94bSdlw { if(c=='\n') return(z_wnew());
33a8a1e94bSdlw if(recpos++ < svic->icirlen)
34a8a1e94bSdlw { *icptr++ = c;
35a8a1e94bSdlw return(OK);
36a8a1e94bSdlw }
3781947dbeSdlw else err(errflag,F_EREREC,"iio")
38a8a1e94bSdlw }
39a8a1e94bSdlw leof = EOF;
40a8a1e94bSdlw #ifndef KOSHER
41a8a1e94bSdlw err(endflag,EOF,"iio") /* NOT STANDARD, end-of-file on writes */
42a8a1e94bSdlw #endif
43a8a1e94bSdlw #ifdef KOSHER
4481947dbeSdlw err(errflag,F_EREREC,"iio")
45a8a1e94bSdlw #endif
46a8a1e94bSdlw }
47a8a1e94bSdlw
48*9e4573b6Slibs LOCAL
z_ungetc(ch,cf)49a8a1e94bSdlw z_ungetc(ch,cf) char ch;
50a8a1e94bSdlw { if(ch==EOF || --recpos >= svic->icirlen) return(OK);
5181947dbeSdlw if(--icptr < svic->iciunit || recpos < 0) err(errflag,F_ERBREC,"ilio")
52a8a1e94bSdlw *icptr = ch;
53a8a1e94bSdlw return(OK);
54a8a1e94bSdlw }
55a8a1e94bSdlw
s_rsfi(a)56a8a1e94bSdlw s_rsfi(a) icilist *a;
57a8a1e94bSdlw {
58a8a1e94bSdlw reading = YES;
59a8a1e94bSdlw doed=rd_ed;
60a8a1e94bSdlw doned=rd_ned;
61a8a1e94bSdlw getn=z_getc;
62a8a1e94bSdlw doend = donewrec = z_rnew;
63a8a1e94bSdlw dorevert = z_rnew;
64a8a1e94bSdlw dotab = z_tab;
65a8a1e94bSdlw return(c_si(a));
66a8a1e94bSdlw }
67a8a1e94bSdlw
s_wsfi(a)68a8a1e94bSdlw s_wsfi(a) icilist *a;
69a8a1e94bSdlw {
70a8a1e94bSdlw reading = NO;
71a8a1e94bSdlw doed=w_ed;
72a8a1e94bSdlw doned=w_ned;
73a8a1e94bSdlw putn=z_putc;
74a8a1e94bSdlw doend = donewrec = z_wnew;
75a8a1e94bSdlw dorevert = z_wnew;
76a8a1e94bSdlw dotab = z_tab;
77a8a1e94bSdlw return(c_si(a));
78a8a1e94bSdlw }
79a8a1e94bSdlw
s_rdfi(a)80a8a1e94bSdlw s_rdfi(a) icilist *a;
81a8a1e94bSdlw {
82a8a1e94bSdlw reading = YES;
83a8a1e94bSdlw doed = rd_ed;
84a8a1e94bSdlw doned = rd_ned;
85a8a1e94bSdlw getn = z_getc;
86a8a1e94bSdlw donewrec = z_rnew;
87a8a1e94bSdlw dorevert = doend = z_rnew;
88a8a1e94bSdlw dotab = z_tab;
89a8a1e94bSdlw return(c_di(a));
90a8a1e94bSdlw }
91a8a1e94bSdlw
s_wdfi(a)92a8a1e94bSdlw s_wdfi(a) icilist *a;
93a8a1e94bSdlw {
94a8a1e94bSdlw reading = NO;
95a8a1e94bSdlw doed = w_ed;
96a8a1e94bSdlw doned = w_ned;
97a8a1e94bSdlw putn = z_putc;
98a8a1e94bSdlw donewrec = z_wnew;
99a8a1e94bSdlw dorevert = doend = z_wnew;
100a8a1e94bSdlw dotab = z_tab;
101a8a1e94bSdlw return(c_di(a));
102a8a1e94bSdlw }
103a8a1e94bSdlw
104*9e4573b6Slibs LOCAL
c_fi(a)105a8a1e94bSdlw c_fi(a) icilist *a;
106a8a1e94bSdlw {
107a8a1e94bSdlw fmtbuf=a->icifmt;
108a8a1e94bSdlw formatted = FORMATTED;
109a8a1e94bSdlw external = NO;
110a8a1e94bSdlw cblank=cplus=NO;
111a8a1e94bSdlw scale=cursor=0;
112a8a1e94bSdlw radix = 10;
113a8a1e94bSdlw signit = YES;
114a8a1e94bSdlw elist = YES;
115a8a1e94bSdlw svic = a;
116a8a1e94bSdlw recpos=reclen=0;
117a8a1e94bSdlw icend = a->iciunit + a->icirnum*a->icirlen;
118a8a1e94bSdlw errflag = a->icierr;
119a8a1e94bSdlw endflag = a->iciend;
120eb11917eSlibs if(pars_f()) err(errflag,F_ERFMT,"ifio")
121a8a1e94bSdlw fmt_bg();
122a8a1e94bSdlw return(OK);
123a8a1e94bSdlw }
124a8a1e94bSdlw
125*9e4573b6Slibs LOCAL
c_si(a)126a8a1e94bSdlw c_si(a) icilist *a;
127a8a1e94bSdlw {
128a8a1e94bSdlw sequential = YES;
129a8a1e94bSdlw recnum = 0;
130a8a1e94bSdlw icptr = a->iciunit;
131a8a1e94bSdlw return(c_fi(a));
132a8a1e94bSdlw }
133a8a1e94bSdlw
134*9e4573b6Slibs LOCAL
c_di(a)135a8a1e94bSdlw c_di(a) icilist *a;
136a8a1e94bSdlw {
137a8a1e94bSdlw sequential = NO;
138a8a1e94bSdlw recnum = a->icirec - 1;
139a8a1e94bSdlw icptr = a->iciunit + recnum*a->icirlen;
140a8a1e94bSdlw return(c_fi(a));
141a8a1e94bSdlw }
142a8a1e94bSdlw
143*9e4573b6Slibs LOCAL
z_rnew()144a8a1e94bSdlw z_rnew()
145a8a1e94bSdlw {
146a8a1e94bSdlw icptr = svic->iciunit + (++recnum)*svic->icirlen;
147a8a1e94bSdlw recpos = reclen = cursor = 0;
148a8a1e94bSdlw return(OK);
149a8a1e94bSdlw }
150a8a1e94bSdlw
151*9e4573b6Slibs LOCAL
z_wnew()152a8a1e94bSdlw z_wnew()
153a8a1e94bSdlw {
154a8a1e94bSdlw if(reclen > recpos)
155a8a1e94bSdlw { icptr += (reclen - recpos);
156a8a1e94bSdlw recpos = reclen;
157a8a1e94bSdlw }
158a8a1e94bSdlw while(recpos < svic->icirlen) (*putn)(' ');
159a8a1e94bSdlw recpos = reclen = cursor = 0;
160a8a1e94bSdlw recnum++;
161a8a1e94bSdlw return(OK);
162a8a1e94bSdlw }
163a8a1e94bSdlw
164*9e4573b6Slibs LOCAL
z_tab()165a8a1e94bSdlw z_tab()
166a8a1e94bSdlw { int n;
167a8a1e94bSdlw if(reclen < recpos) reclen = recpos;
168b5715174Sdlw if((recpos + cursor) < 0) cursor = -recpos; /* to BOR */
169a8a1e94bSdlw n = reclen - recpos;
170a8a1e94bSdlw if(!reading && (cursor-n) > 0)
171a8a1e94bSdlw { icptr += n;
172a8a1e94bSdlw recpos = reclen;
173a8a1e94bSdlw cursor -= n;
174a8a1e94bSdlw while(cursor--) if(n=(*putn)(' ')) return(n);
175a8a1e94bSdlw }
176a8a1e94bSdlw else
177a8a1e94bSdlw { icptr += cursor;
178a8a1e94bSdlw recpos += cursor;
179a8a1e94bSdlw }
180a8a1e94bSdlw return(cursor=0);
181a8a1e94bSdlw }
182a8a1e94bSdlw
e_rsfi()183a8a1e94bSdlw e_rsfi()
184a8a1e94bSdlw { int n;
185a8a1e94bSdlw n = en_fio();
186a8a1e94bSdlw fmtbuf = NULL;
187a8a1e94bSdlw return(n);
188a8a1e94bSdlw }
189a8a1e94bSdlw
e_wsfi()190a8a1e94bSdlw e_wsfi()
191a8a1e94bSdlw {
192a8a1e94bSdlw return(e_rsfi());
193a8a1e94bSdlw }
194a8a1e94bSdlw
e_rdfi()195a8a1e94bSdlw e_rdfi()
196a8a1e94bSdlw {
197a8a1e94bSdlw return(e_rsfi());
198a8a1e94bSdlw }
199a8a1e94bSdlw
e_wdfi()200a8a1e94bSdlw e_wdfi()
201a8a1e94bSdlw {
202a8a1e94bSdlw return(e_wsfi());
203a8a1e94bSdlw }
204a8a1e94bSdlw
205*9e4573b6Slibs LOCAL
c_li(a)206a8a1e94bSdlw c_li(a) icilist *a;
207a8a1e94bSdlw {
208a8a1e94bSdlw fmtbuf="int list io";
209a8a1e94bSdlw sequential = formatted = LISTDIRECTED;
210a8a1e94bSdlw external = NO;
211a8a1e94bSdlw elist = YES;
212a8a1e94bSdlw svic = a;
213a8a1e94bSdlw recnum = recpos = 0;
214a8a1e94bSdlw cplus = cblank = NO;
215a8a1e94bSdlw icptr = a->iciunit;
216a8a1e94bSdlw icend = icptr + a->icirlen * a->icirnum;
217a8a1e94bSdlw errflag = a->icierr;
218a8a1e94bSdlw endflag = a->iciend;
219a8a1e94bSdlw leof = NO;
220a8a1e94bSdlw return(OK);
221a8a1e94bSdlw }
222a8a1e94bSdlw
s_rsli(a)223a8a1e94bSdlw s_rsli(a) icilist *a;
224a8a1e94bSdlw {
225a8a1e94bSdlw reading = YES;
226a8a1e94bSdlw lioproc = l_read;
227a8a1e94bSdlw getn = z_getc;
228a8a1e94bSdlw ungetn = z_ungetc;
229a8a1e94bSdlw l_first = YES;
230a8a1e94bSdlw lcount = 0;
231a8a1e94bSdlw lquit = NO;
232a8a1e94bSdlw return(c_li(a));
233a8a1e94bSdlw }
234a8a1e94bSdlw
s_wsli(a)235a8a1e94bSdlw s_wsli(a) icilist *a;
236a8a1e94bSdlw {
237a8a1e94bSdlw reading = NO;
238a8a1e94bSdlw putn = z_putc;
239a8a1e94bSdlw lioproc = l_write;
240a8a1e94bSdlw line_len = a->icirlen;
241a8a1e94bSdlw return(c_li(a));
242a8a1e94bSdlw }
243a8a1e94bSdlw
e_rsli()244a8a1e94bSdlw e_rsli()
245a8a1e94bSdlw { fmtbuf = NULL;
246a8a1e94bSdlw return(OK);
247a8a1e94bSdlw }
248a8a1e94bSdlw
e_wsli()249a8a1e94bSdlw e_wsli()
250a8a1e94bSdlw { fmtbuf = NULL;
251a8a1e94bSdlw reclen = recpos;
252a8a1e94bSdlw return(z_wnew());
253a8a1e94bSdlw }
254a8a1e94bSdlw
255a8a1e94bSdlw ftnint
iiorec_()256a8a1e94bSdlw iiorec_()
257a8a1e94bSdlw { return(recnum); }
258a8a1e94bSdlw
259a8a1e94bSdlw ftnint
iiopos_()260a8a1e94bSdlw iiopos_()
261a8a1e94bSdlw { return(recpos); }
262