FSF GCC merge 02/23/03
[official-gcc.git] / libf2c / libI77 / dfe.c
blob5ce0b4cd661541853f794ba4eb86f6d3749b70ee
1 #include "config.h"
2 #include "f2c.h"
3 #include "fio.h"
4 #include "fmt.h"
6 int
7 y_rsk (void)
9 if (f__curunit->uend || f__curunit->url <= f__recpos
10 || f__curunit->url == 1)
11 return 0;
14 getc (f__cf);
16 while (++f__recpos < f__curunit->url);
17 return 0;
20 int
21 y_getc (void)
23 int ch;
24 if (f__curunit->uend)
25 return (-1);
26 if ((ch = getc (f__cf)) != EOF)
28 f__recpos++;
29 if (f__curunit->url >= f__recpos || f__curunit->url == 1)
30 return (ch);
31 else
32 return (' ');
34 if (feof (f__cf))
36 f__curunit->uend = 1;
37 errno = 0;
38 return (-1);
40 err (f__elist->cierr, errno, "readingd");
43 static int
44 y_rev (void)
46 if (f__recpos < f__hiwater)
47 f__recpos = f__hiwater;
48 if (f__curunit->url > 1)
49 while (f__recpos < f__curunit->url)
50 (*f__putn) (' ');
51 if (f__recpos)
52 f__putbuf (0);
53 f__recpos = 0;
54 return (0);
57 static int
58 y_err (void)
60 err (f__elist->cierr, 110, "dfe");
63 static int
64 y_newrec (void)
66 y_rev ();
67 f__hiwater = f__cursor = 0;
68 return (1);
71 int
72 c_dfe (cilist * a)
74 f__sequential = 0;
75 f__formatted = f__external = 1;
76 f__elist = a;
77 f__cursor = f__scale = f__recpos = 0;
78 f__curunit = &f__units[a->ciunit];
79 if (a->ciunit > MXUNIT || a->ciunit < 0)
80 err (a->cierr, 101, "startchk");
81 if (f__curunit->ufd == NULL && fk_open (DIR, FMT, a->ciunit))
82 err (a->cierr, 104, "dfe");
83 f__cf = f__curunit->ufd;
84 if (!f__curunit->ufmt)
85 err (a->cierr, 102, "dfe");
86 if (!f__curunit->useek)
87 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);
96 integer
97 s_rdfe (cilist * a)
99 int n;
100 if (f__init != 1)
101 f_init ();
102 f__init = 3;
103 f__reading = 1;
104 if ((n = c_dfe (a)))
105 return (n);
106 if (f__curunit->uwrt && f__nowreading (f__curunit))
107 err (a->cierr, errno, "read start");
108 f__getn = y_getc;
109 f__doed = rd_ed;
110 f__doned = rd_ned;
111 f__dorevert = f__donewrec = y_err;
112 f__doend = y_rsk;
113 if (pars_f (f__fmtbuf) < 0)
114 err (a->cierr, 100, "read start");
115 fmt_bg ();
116 return (0);
119 integer
120 s_wdfe (cilist * a)
122 int n;
123 if (f__init != 1)
124 f_init ();
125 f__init = 3;
126 f__reading = 0;
127 if ((n = c_dfe (a)))
128 return (n);
129 if (f__curunit->uwrt != 1 && f__nowwriting (f__curunit))
130 err (a->cierr, errno, "startwrt");
131 f__putn = x_putc;
132 f__doed = w_ed;
133 f__doned = w_ned;
134 f__dorevert = y_err;
135 f__donewrec = y_newrec;
136 f__doend = y_rev;
137 if (pars_f (f__fmtbuf) < 0)
138 err (a->cierr, 100, "startwrt");
139 fmt_bg ();
140 return (0);
143 integer
144 e_rdfe (void)
146 f__init = 1;
147 en_fio ();
148 return (0);
151 integer
152 e_wdfe (void)
154 f__init = 1;
155 return en_fio ();