OSDN Git Service

2004-02-13 Frank Ch. Eigler <fche@redhat.com>
[pf3gnuchains/gcc-fork.git] / libf2c / libI77 / rsfe.c
1 /* read sequential formatted external */
2 #include "config.h"
3 #include "f2c.h"
4 #include "fio.h"
5 #include "fmt.h"
6
7 int
8 xrd_SL (void)
9 {
10   int ch;
11   if (!f__curunit->uend)
12     while ((ch = getc (f__cf)) != '\n')
13       if (ch == EOF)
14         {
15           f__curunit->uend = 1;
16           break;
17         }
18   f__cursor = f__recpos = 0;
19   return (1);
20 }
21
22 int
23 x_getc (void)
24 {
25   int ch;
26   if (f__curunit->uend)
27     return (EOF);
28   ch = getc (f__cf);
29   if (ch != EOF && ch != '\n')
30     {
31       f__recpos++;
32       return (ch);
33     }
34   if (ch == '\n')
35     {
36       (void) ungetc (ch, f__cf);
37       return (ch);
38     }
39   if (f__curunit->uend || feof (f__cf))
40     {
41       errno = 0;
42       f__curunit->uend = 1;
43       return (-1);
44     }
45   return (-1);
46 }
47
48 int
49 x_endp (void)
50 {
51   xrd_SL ();
52   return f__curunit->uend == 1 ? EOF : 0;
53 }
54
55 int
56 x_rev (void)
57 {
58   (void) xrd_SL ();
59   return (0);
60 }
61
62 integer
63 s_rsfe (cilist * a)             /* start */
64 {
65   int n;
66   if (f__init != 1)
67     f_init ();
68   f__init = 3;
69   f__reading = 1;
70   f__sequential = 1;
71   f__formatted = 1;
72   f__external = 1;
73   if ((n = c_sfe (a)))
74     return (n);
75   f__elist = a;
76   f__cursor = f__recpos = 0;
77   f__scale = 0;
78   f__fmtbuf = a->cifmt;
79   f__curunit = &f__units[a->ciunit];
80   f__cf = f__curunit->ufd;
81   if (pars_f (f__fmtbuf) < 0)
82     err (a->cierr, 100, "startio");
83   f__getn = x_getc;
84   f__doed = rd_ed;
85   f__doned = rd_ned;
86   fmt_bg ();
87   f__doend = x_endp;
88   f__donewrec = xrd_SL;
89   f__dorevert = x_rev;
90   f__cblank = f__curunit->ublnk;
91   f__cplus = 0;
92   if (f__curunit->uwrt && f__nowreading (f__curunit))
93     err (a->cierr, errno, "read start");
94   if (f__curunit->uend)
95     err (f__elist->ciend, (EOF), "read start");
96   return (0);
97 }