|
|
1.1 root 1: /*
2: * direct formatted external i/o
3: */
4:
5: #include "fio.h"
6:
7: extern int rd_ed(),rd_ned(),w_ed(),w_ned();
8: int y_getc(),y_putc(),y_rnew(),y_wnew(),y_tab();
9:
10: char *dfe = "dfe";
11: char *rdfe = "read dfe";
12: char *wdfe = "write dfe";
13:
14: s_rdfe(a) cilist *a;
15: {
16: int n;
17: reading = YES;
18: if(n=c_dfe(a,READ)) return(n);
19: if(curunit->uwrt) nowreading(curunit);
20: getn = y_getc;
21: doed = rd_ed;
22: doned = rd_ned;
23: dotab = y_tab;
24: dorevert = doend = donewrec = y_rnew;
25: if(pars_f(fmtbuf)) err(errflag,100,rdfe)
26: fmt_bg();
27: return(OK);
28: }
29:
30: s_wdfe(a) cilist *a;
31: {
32: int n;
33: reading = NO;
34: if(n=c_dfe(a,WRITE)) return(n);
35: curunit->uend = NO;
36: if(!curunit->uwrt) nowwriting(curunit);
37: putn = y_putc;
38: doed = w_ed;
39: doned = w_ned;
40: dotab = y_tab;
41: dorevert = doend = donewrec = y_wnew;
42: if(pars_f(fmtbuf)) err(errflag,100,wdfe)
43: fmt_bg();
44: return(OK);
45: }
46:
47: e_rdfe()
48: {
49: en_fio();
50: return(OK);
51: }
52:
53: e_wdfe()
54: {
55: en_fio();
56: return(OK);
57: }
58:
59: c_dfe(a,flag) cilist *a;
60: { int n;
61: sequential = NO;
62: external = formatted = FORMATTED;
63: lfname = NULL;
64: elist = NO;
65: cursor=scale=recpos=reclen=0;
66: radix = 10;
67: signit = YES;
68: fmtbuf = a->cifmt;
69: errflag = a->cierr;
70: endflag = a->ciend;
71: lunit = a->ciunit;
72: if(not_legal(lunit)) err(errflag,101,dfe);
73: curunit = &units[lunit];
74: if(!curunit->ufd && (n=fk_open(flag,DIR,FMT,lunit))) err(errflag,n,dfe)
75: cf = curunit->ufd;
76: elist = YES;
77: lfname = curunit->ufnm;
78: if(!curunit->ufmt) err(errflag,102,dfe)
79: if(!curunit->useek || !curunit->url) err(errflag,104,dfe)
80: recnum = a->cirec - 1;
81: fseek(cf, (long)curunit->url * recnum, 0);
82: cblank = curunit->ublnk;
83: cplus = NO;
84: return(OK);
85: }
86:
87: y_getc()
88: {
89: int ch;
90: if(curunit->uend) return(EOF);
91: if(curunit->url==1 || recpos++ < curunit->url)
92: {
93: if((ch=getc(cf))!=EOF)
94: {
95: return(ch);
96: }
97: if(feof(cf))
98: {
99: curunit->uend = YES;
100: return(EOF);
101: }
102: err(errflag,errno,rdfe);
103: }
104: else return(' ');
105: }
106:
107: y_putc(c)
108: {
109: if(curunit->url!=1 && recpos++ >= curunit->url) err(errflag,110,wdfe)
110: putc(c,cf);
111: return(OK);
112: }
113:
114: y_tab()
115: { int n;
116: if(curunit->url==1)
117: {
118: if(cursor < 0 && -cursor > ftell(cf)) return(107);
119: }
120: else
121: { if(reclen < recpos) reclen = recpos;
122: if((recpos + cursor) < 0) return(107);
123: n = reclen - recpos; /* n >= 0 */
124: if(!reading && (cursor-n) > 0)
125: { recpos = reclen;
126: cursor -= n;
127: fseek(cf,(long)n,1);
128: while(cursor--) if(n=(*putn)(' ')) return(n);
129: return(cursor=0);
130: }
131: recpos += cursor;
132: if(recpos >= curunit->url) err(errflag,110,dfe)
133: }
134: fseek(cf,(long)cursor,1);
135: return(cursor=0);
136: }
137:
138: /*
139: /*y_rev()
140: /*{ /*what about work done?*/
141: /* if(curunit->url==1) return(0);
142: /* while(recpos<curunit->url) (*putn)(' ');
143: /* recpos=0;
144: /* return(0);
145: /*}
146: /*
147: /*y_err()
148: /*{
149: /* err(errflag, 110, dfe);
150: /*}
151: */
152:
153: y_rnew()
154: { if(curunit->url != 1)
155: { fseek(cf,(long)curunit->url*(++recnum),0);
156: recpos = reclen = cursor = 0;
157: }
158: return(OK);
159: }
160:
161: y_wnew()
162: { if(curunit->url != 1)
163: { if(reclen > recpos)
164: { fseek(cf,(long)(reclen-recpos),1);
165: recpos = reclen;
166: }
167: while(recpos < curunit->url) (*putn)(' ');
168: recnum++;
169: recpos = reclen = cursor = 0;
170: }
171: return(OK);
172: }
173:
174: y_rend()
175: {
176: return(OK);
177: }
178:
179: y_wend()
180: {
181: return(y_wnew());
182: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.