1 #include "f2c.h"
2 #include "fio.h"
3 #include "fmt.h"
4
y_rsk(Void)5 y_rsk(Void)
6 {
7 if(f__curunit->uend || f__curunit->url <= f__recpos
8 || f__curunit->url == 1) return 0;
9 do {
10 getc(f__cf);
11 } while(++f__recpos < f__curunit->url);
12 return 0;
13 }
y_getc(Void)14 y_getc(Void)
15 {
16 int ch;
17 if(f__curunit->uend) return(-1);
18 if((ch=getc(f__cf))!=EOF)
19 {
20 f__recpos++;
21 if(f__curunit->url>=f__recpos ||
22 f__curunit->url==1)
23 return(ch);
24 else return(' ');
25 }
26 if(feof(f__cf))
27 {
28 f__curunit->uend=1;
29 errno=0;
30 return(-1);
31 }
32 err(f__elist->cierr,errno,"readingd");
33 }
34
35 static int
y_rev(Void)36 y_rev(Void)
37 {
38 if (f__recpos < f__hiwater)
39 f__recpos = f__hiwater;
40 if (f__curunit->url > 1)
41 while(f__recpos < f__curunit->url)
42 (*f__putn)(' ');
43 if (f__recpos)
44 f__putbuf(0);
45 f__recpos = 0;
46 return(0);
47 }
48
49 static int
y_err(Void)50 y_err(Void)
51 {
52 err(f__elist->cierr, 110, "dfe");
53 }
54
55 static int
y_newrec(Void)56 y_newrec(Void)
57 {
58 y_rev();
59 f__hiwater = f__cursor = 0;
60 return(1);
61 }
62
63 #ifdef KR_headers
c_dfe(a)64 c_dfe(a) cilist *a;
65 #else
66 c_dfe(cilist *a)
67 #endif
68 {
69 f__sequential=0;
70 f__formatted=f__external=1;
71 f__elist=a;
72 f__cursor=f__scale=f__recpos=0;
73 f__curunit = &f__units[a->ciunit];
74 if(a->ciunit>MXUNIT || a->ciunit<0)
75 err(a->cierr,101,"startchk");
76 if(f__curunit->ufd==NULL && fk_open(DIR,FMT,a->ciunit))
77 err(a->cierr,104,"dfe");
78 f__cf=f__curunit->ufd;
79 if(!f__curunit->ufmt) err(a->cierr,102,"dfe")
80 if(!f__curunit->useek) err(a->cierr,104,"dfe")
81 f__fmtbuf=a->cifmt;
82 if(a->cirec <= 0)
83 err(a->cierr,130,"dfe")
84 fseek(f__cf,(long)f__curunit->url * (a->cirec-1),SEEK_SET);
85 f__curunit->uend = 0;
86 return(0);
87 }
88 #ifdef KR_headers
s_rdfe(a)89 integer s_rdfe(a) cilist *a;
90 #else
91 integer s_rdfe(cilist *a)
92 #endif
93 {
94 int n;
95 if(!f__init) f_init();
96 f__reading=1;
97 if(n=c_dfe(a))return(n);
98 if(f__curunit->uwrt && f__nowreading(f__curunit))
99 err(a->cierr,errno,"read start");
100 f__getn = y_getc;
101 f__doed = rd_ed;
102 f__doned = rd_ned;
103 f__dorevert = f__donewrec = y_err;
104 f__doend = y_rsk;
105 if(pars_f(f__fmtbuf)<0)
106 err(a->cierr,100,"read start");
107 fmt_bg();
108 return(0);
109 }
110 #ifdef KR_headers
s_wdfe(a)111 integer s_wdfe(a) cilist *a;
112 #else
113 integer s_wdfe(cilist *a)
114 #endif
115 {
116 int n;
117 if(!f__init) f_init();
118 f__reading=0;
119 if(n=c_dfe(a)) return(n);
120 if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
121 err(a->cierr,errno,"startwrt");
122 f__putn = x_putc;
123 f__doed = w_ed;
124 f__doned= w_ned;
125 f__dorevert = y_err;
126 f__donewrec = y_newrec;
127 f__doend = y_rev;
128 if(pars_f(f__fmtbuf)<0)
129 err(a->cierr,100,"startwrt");
130 fmt_bg();
131 return(0);
132 }
e_rdfe(Void)133 integer e_rdfe(Void)
134 {
135 en_fio();
136 return 0;
137 }
e_wdfe(Void)138 integer e_wdfe(Void)
139 {
140 return en_fio();
141 }
142