OSDN Git Service

* Previous contents of gcc/f/runtime moved into toplevel
[pf3gnuchains/gcc-fork.git] / libf2c / libI77 / dfe.c
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 }
34 #ifdef KR_headers
35 y_putc(c)
36 #else
37 y_putc(int c)
38 #endif
39 {
40         f__recpos++;
41         if(f__recpos <= f__curunit->url || f__curunit->url==1)
42                 putc(c,f__cf);
43         else
44                 err(f__elist->cierr,110,"dout");
45         return(0);
46 }
47 y_rev(Void)
48 {       /*what about work done?*/
49         if(f__curunit->url==1 || f__recpos==f__curunit->url)
50                 return(0);
51         while(f__recpos<f__curunit->url)
52                 (*f__putn)(' ');
53         f__recpos=0;
54         return(0);
55 }
56 y_err(Void)
57 {
58         err(f__elist->cierr, 110, "dfe");
59 }
60
61 y_newrec(Void)
62 {
63         if(f__curunit->url == 1 || f__recpos == f__curunit->url) {
64                 f__hiwater = f__recpos = f__cursor = 0;
65                 return(1);
66         }
67         if(f__hiwater > f__recpos)
68                 f__recpos = f__hiwater;
69         y_rev();
70         f__hiwater = f__cursor = 0;
71         return(1);
72 }
73
74 #ifdef KR_headers
75 c_dfe(a) cilist *a;
76 #else
77 c_dfe(cilist *a)
78 #endif
79 {
80         f__sequential=0;
81         f__formatted=f__external=1;
82         f__elist=a;
83         f__cursor=f__scale=f__recpos=0;
84         if(a->ciunit>MXUNIT || a->ciunit<0)
85                 err(a->cierr,101,"startchk");
86         f__curunit = &f__units[a->ciunit];
87         if(f__curunit->ufd==NULL && fk_open(DIR,FMT,a->ciunit))
88                 err(a->cierr,104,"dfe");
89         f__cf=f__curunit->ufd;
90         if(!f__curunit->ufmt) err(a->cierr,102,"dfe");
91         if(!f__curunit->useek) err(a->cierr,104,"dfe");
92         f__fmtbuf=a->cifmt;
93         if(a->cirec <= 0)
94                 err(a->cierr,130,"dfe");
95         (void) fseek(f__cf,(long)f__curunit->url * (a->cirec-1),SEEK_SET);
96         f__curunit->uend = 0;
97         return(0);
98 }
99 #ifdef KR_headers
100 integer s_rdfe(a) cilist *a;
101 #else
102 integer s_rdfe(cilist *a)
103 #endif
104 {
105         int n;
106         if(f__init != 1) f_init();
107         f__init = 3;
108         f__reading=1;
109         if(n=c_dfe(a))return(n);
110         if(f__curunit->uwrt && f__nowreading(f__curunit))
111                 err(a->cierr,errno,"read start");
112         f__getn = y_getc;
113         f__doed = rd_ed;
114         f__doned = rd_ned;
115         f__dorevert = f__donewrec = y_err;
116         f__doend = y_rsk;
117         if(pars_f(f__fmtbuf)<0)
118                 err(a->cierr,100,"read start");
119         fmt_bg();
120         return(0);
121 }
122 #ifdef KR_headers
123 integer s_wdfe(a) cilist *a;
124 #else
125 integer s_wdfe(cilist *a)
126 #endif
127 {
128         int n;
129         if(f__init != 1) f_init();
130         f__init = 3;
131         f__reading=0;
132         if(n=c_dfe(a)) return(n);
133         if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
134                 err(a->cierr,errno,"startwrt");
135         f__putn = y_putc;
136         f__doed = w_ed;
137         f__doned= w_ned;
138         f__dorevert = y_err;
139         f__donewrec = y_newrec;
140         f__doend = y_rev;
141         if(pars_f(f__fmtbuf)<0)
142                 err(a->cierr,100,"startwrt");
143         fmt_bg();
144         return(0);
145 }
146 integer e_rdfe(Void)
147 {
148         f__init = 1;
149         (void) en_fio();
150         return(0);
151 }
152 integer e_wdfe(Void)
153 {
154         f__init = 1;
155         return en_fio();
156 }