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