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