]>
Commit | Line | Data |
---|---|---|
81fea2b1 JL |
1 | #include "f2c.h" |
2 | #include "fio.h" | |
3 | #include "fmt.h" | |
4 | ||
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 | } | |
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 | } | |
a843efa0 CB |
34 | |
35 | static int | |
81fea2b1 | 36 | y_rev(Void) |
a843efa0 CB |
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; | |
81fea2b1 JL |
46 | return(0); |
47 | } | |
a843efa0 CB |
48 | |
49 | static int | |
81fea2b1 JL |
50 | y_err(Void) |
51 | { | |
52 | err(f__elist->cierr, 110, "dfe"); | |
53 | } | |
54 | ||
a843efa0 | 55 | static int |
81fea2b1 JL |
56 | y_newrec(Void) |
57 | { | |
81fea2b1 JL |
58 | y_rev(); |
59 | f__hiwater = f__cursor = 0; | |
60 | return(1); | |
61 | } | |
62 | ||
63 | #ifdef KR_headers | |
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 | if(a->ciunit>MXUNIT || a->ciunit<0) | |
74 | err(a->cierr,101,"startchk"); | |
75 | f__curunit = &f__units[a->ciunit]; | |
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"); | |
6d3e8f62 | 84 | fseek(f__cf,(long)f__curunit->url * (a->cirec-1),SEEK_SET); |
81fea2b1 JL |
85 | f__curunit->uend = 0; |
86 | return(0); | |
87 | } | |
88 | #ifdef KR_headers | |
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 != 1) f_init(); | |
96 | f__init = 3; | |
97 | f__reading=1; | |
98 | if(n=c_dfe(a))return(n); | |
99 | if(f__curunit->uwrt && f__nowreading(f__curunit)) | |
100 | err(a->cierr,errno,"read start"); | |
101 | f__getn = y_getc; | |
102 | f__doed = rd_ed; | |
103 | f__doned = rd_ned; | |
104 | f__dorevert = f__donewrec = y_err; | |
105 | f__doend = y_rsk; | |
106 | if(pars_f(f__fmtbuf)<0) | |
107 | err(a->cierr,100,"read start"); | |
108 | fmt_bg(); | |
109 | return(0); | |
110 | } | |
111 | #ifdef KR_headers | |
112 | integer s_wdfe(a) cilist *a; | |
113 | #else | |
114 | integer s_wdfe(cilist *a) | |
115 | #endif | |
116 | { | |
117 | int n; | |
118 | if(f__init != 1) f_init(); | |
119 | f__init = 3; | |
120 | f__reading=0; | |
121 | if(n=c_dfe(a)) return(n); | |
122 | if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit)) | |
123 | err(a->cierr,errno,"startwrt"); | |
a843efa0 | 124 | f__putn = x_putc; |
81fea2b1 JL |
125 | f__doed = w_ed; |
126 | f__doned= w_ned; | |
127 | f__dorevert = y_err; | |
128 | f__donewrec = y_newrec; | |
129 | f__doend = y_rev; | |
130 | if(pars_f(f__fmtbuf)<0) | |
131 | err(a->cierr,100,"startwrt"); | |
132 | fmt_bg(); | |
133 | return(0); | |
134 | } | |
135 | integer e_rdfe(Void) | |
136 | { | |
137 | f__init = 1; | |
a843efa0 | 138 | en_fio(); |
81fea2b1 JL |
139 | return(0); |
140 | } |