|
|
1.1 root 1: /* @(#)dfe.c 1.2 */
2: /* 3.0 SID # 1.2 */
3: #include "fio.h"
4: #include "fmt.h"
5: extern int rd_ed(),rd_ned(),y_getc(),y_putc(),y_err();
6: extern int y_rev(), y_rsk(), y_newrec();
7: extern int w_ed(),w_ned();
8: s_rdfe(a) cilist *a;
9: {
10: int n;
11: if(!init) f_init();
12: if(n=c_dfe(a))return(n);
13: reading=1;
14: if(curunit->uwrt) (void) nowreading(curunit);
15: getn = y_getc;
16: doed = rd_ed;
17: doned = rd_ned;
18: dorevert = donewrec = y_err;
19: doend = y_rsk;
20: if(pars_f(fmtbuf)<0)
21: err(a->cierr,100,"startio");
22: fmt_bg();
23: return(0);
24: }
25: s_wdfe(a) cilist *a;
26: {
27: int n;
28: if(!init) f_init();
29: if(n=c_dfe(a)) return(n);
30: reading=0;
31: if(!curunit->uwrt) (void) nowwriting(curunit);
32: putn = y_putc;
33: doed = w_ed;
34: doned= w_ned;
35: dorevert = y_err;
36: donewrec = y_newrec;
37: doend = y_rev;
38: if(pars_f(fmtbuf)<0)
39: err(a->cierr,100,"startwrt");
40: fmt_bg();
41: return(0);
42: }
43: e_rdfe()
44: {
45: (void) en_fio();
46: return(0);
47: }
48: e_wdfe()
49: {
50: (void) en_fio();
51: return(0);
52: }
53: c_dfe(a) cilist *a;
54: {
55: sequential=0;
56: formatted=external=1;
57: elist=a;
58: cursor=scale=recpos=0;
59: if(a->ciunit>MXUNIT || a->ciunit<0)
60: err(a->cierr,101,"startchk");
61: curunit = &units[a->ciunit];
62: if(curunit->ufd==NULL && fk_open(DIR,FMT,a->ciunit))
63: err(a->cierr,104,"dfe");
64: cf=curunit->ufd;
65: if(!curunit->ufmt) err(a->cierr,102,"dfe")
66: if(!curunit->useek) err(a->cierr,104,"dfe")
67: fmtbuf=a->cifmt;
68: (void) fseek(cf,(long)curunit->url * (a->cirec-1),0);
69: curunit->uend = 0;
70: return(0);
71: }
72: y_rsk()
73: {
74: if(curunit->uend || curunit->url <= recpos
75: || curunit->url == 1) return;
76: do {
77: getc(cf);
78: } while(++recpos < curunit->url);
79: }
80: y_getc()
81: {
82: int ch;
83: if(curunit->uend) return(-1);
84: if((ch=getc(cf))!=EOF)
85: {
86: recpos++;
87: if(curunit->url>=recpos ||
88: curunit->url==1)
89: return(ch);
90: else return(' ');
91: }
92: if(feof(cf))
93: {
94: curunit->uend=1;
95: errno=0;
96: return(-1);
97: }
98: err(elist->cierr,errno,"readingd");
99: }
100: y_putc(c)
101: {
102: recpos++;
103: if(recpos <= curunit->url || curunit->url==1)
104: putc(c,cf);
105: else
106: err(elist->cierr,110,"dout");
107: return(0);
108: }
109: y_rev()
110: { /*what about work done?*/
111: if(curunit->url==1 || recpos==curunit->url)
112: return(0);
113: while(recpos<curunit->url)
114: (*putn)(' ');
115: recpos=0;
116: return(0);
117: }
118: y_err()
119: {
120: err(elist->cierr, 110, "dfe");
121: }
122:
123: y_newrec()
124: {
125: if(curunit->url == 1 || recpos == curunit->url) {
126: hiwater = recpos = cursor = 0;
127: return(1);
128: }
129: if(hiwater > recpos)
130: recpos = hiwater;
131: y_rev();
132: hiwater = cursor = 0;
133: return(1);
134: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.