source: branches/libc-0.6/src/gcc/libf2c/libI77/dfe.c

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#include "config.h"
2#include "f2c.h"
3#include "fio.h"
4#include "fmt.h"
5
6int
7y_rsk (void)
8{
9 if (f__curunit->uend || f__curunit->url <= f__recpos
10 || f__curunit->url == 1)
11 return 0;
12 do
13 {
14 getc (f__cf);
15 }
16 while (++f__recpos < f__curunit->url);
17 return 0;
18}
19
20int
21y_getc (void)
22{
23 int ch;
24 if (f__curunit->uend)
25 return (-1);
26 if ((ch = getc (f__cf)) != EOF)
27 {
28 f__recpos++;
29 if (f__curunit->url >= f__recpos || f__curunit->url == 1)
30 return (ch);
31 else
32 return (' ');
33 }
34 if (feof (f__cf))
35 {
36 f__curunit->uend = 1;
37 errno = 0;
38 return (-1);
39 }
40 err (f__elist->cierr, errno, "readingd");
41}
42
43static int
44y_rev (void)
45{
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);
55}
56
57static int
58y_err (void)
59{
60 err (f__elist->cierr, 110, "dfe");
61}
62
63static int
64y_newrec (void)
65{
66 y_rev ();
67 f__hiwater = f__cursor = 0;
68 return (1);
69}
70
71int
72c_dfe (cilist * a)
73{
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);
94}
95
96integer
97s_rdfe (cilist * a)
98{
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);
117}
118
119integer
120s_wdfe (cilist * a)
121{
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);
141}
142
143integer
144e_rdfe (void)
145{
146 f__init = 1;
147 en_fio ();
148 return (0);
149}
150
151integer
152e_wdfe (void)
153{
154 f__init = 1;
155 return en_fio ();
156}
Note: See TracBrowser for help on using the repository browser.