1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: *
6: * @(#)c_iio.c 5.2 7/30/85
7: */
8:
9: /*
10: * internal (character array) i/o: common portions
11: */
12:
13: #include "fio.h"
14: #include "lio.h"
15:
16: LOCAL icilist *svic; /* active internal io list */
17: LOCAL lio_nl;
18:
19: int z_wnew();
20:
21: z_getc()
22: {
23: if(formatted == LISTDIRECTED )
24: {
25: if( lio_nl == YES )
26: {
27: recnum++;
28: recpos = 0;
29: }
30: else if (recpos == svic->icirlen)
31: {
32: lio_nl = YES;
33: return('\n');
34: }
35: lio_nl = NO;
36: }
37:
38: if(icptr >= icend && !recpos) /* new rec beyond eof */
39: { leof = EOF;
40: return(EOF);
41: }
42: if(recpos++ < svic->icirlen) return(*icptr++);
43: return(' ');
44: }
45:
46: z_putc(c) char c;
47: {
48: if(icptr < icend)
49: { if(c=='\n') return(z_wnew());
50: if(recpos++ < svic->icirlen)
51: { *icptr++ = c;
52: return(OK);
53: }
54: else err(errflag,F_EREREC,"iio")
55: }
56: leof = EOF;
57: #ifndef KOSHER
58: err(endflag,EOF,"iio") /* NOT STANDARD, end-of-file on writes */
59: #endif
60: #ifdef KOSHER
61: err(errflag,F_EREREC,"iio")
62: #endif
63: }
64:
65: z_ungetc(ch,cf) char ch;
66: {
67: if( lio_nl == YES )
68: {
69: lio_nl = NO;
70: return(OK);
71: }
72: if(ch==EOF || --recpos >= svic->icirlen) return(OK);
73: if(--icptr < svic->iciunit || recpos < 0) err(errflag,F_ERBREC,"ilio")
74: *icptr = ch;
75: return(OK);
76: }
77:
78: LOCAL
79: c_fi(a) icilist *a;
80: {
81: fmtbuf=a->icifmt;
82: formatted = FORMATTED;
83: external = NO;
84: cblank=cplus=NO;
85: scale=cursor=0;
86: radix = 10;
87: signit = YES;
88: elist = YES;
89: svic = a;
90: recpos=reclen=0;
91: icend = a->iciunit + a->icirnum*a->icirlen;
92: errflag = a->icierr;
93: endflag = a->iciend;
94: return(OK);
95: }
96:
97: c_si(a) icilist *a;
98: {
99: sequential = YES;
100: recnum = 0;
101: icptr = a->iciunit;
102: return(c_fi(a));
103: }
104:
105: c_di(a) icilist *a;
106: {
107: sequential = NO;
108: recnum = a->icirec - 1;
109: icptr = a->iciunit + recnum*a->icirlen;
110: return(c_fi(a));
111: }
112:
113: z_rnew()
114: {
115: icptr = svic->iciunit + (++recnum)*svic->icirlen;
116: recpos = reclen = cursor = 0;
117: return(OK);
118: }
119:
120: z_wnew()
121: {
122: if(reclen > recpos)
123: { icptr += (reclen - recpos);
124: recpos = reclen;
125: }
126: while(recpos < svic->icirlen) (*putn)(' ');
127: recpos = reclen = cursor = 0;
128: recnum++;
129: return(OK);
130: }
131:
132: z_tab()
133: { int n;
134: if(reclen < recpos) reclen = recpos;
135: if((recpos + cursor) < 0) cursor = -recpos; /* to BOR */
136: n = reclen - recpos;
137: if(!reading && (cursor-n) > 0)
138: { icptr += n;
139: recpos = reclen;
140: cursor -= n;
141: while(cursor--) if(n=(*putn)(' ')) return(n);
142: }
143: else
144: { icptr += cursor;
145: recpos += cursor;
146: }
147: return(cursor=0);
148: }
149:
150: c_li(a) icilist *a;
151: {
152: fmtbuf="int list io";
153: sequential = YES;
154: formatted = LISTDIRECTED;
155: external = NO;
156: elist = YES;
157: svic = a;
158: recnum = recpos = 0;
159: cplus = cblank = NO;
160: lio_nl = NO;
161: icptr = a->iciunit;
162: icend = icptr + a->icirlen * a->icirnum;
163: errflag = a->icierr;
164: endflag = a->iciend;
165: leof = NO;
166: return(OK);
167: }
Defined functions
c_di
defined in line
105; used 2 times
c_fi
defined in line
78; used 2 times
c_li
defined in line
150; used 2 times
c_si
defined in line
97; used 2 times