1 /* Copyright (C) by GFD-Dennou Club, 1999-2000. All rights reserved. */
2 #include "libtinyf2c.h"
3 #include "fio.h"
4 #include "fmt.h"
5
6 extern char *f__fmtbuf;
7
8 extern x_getc(Void);
9 extern x_endp(Void);
10 extern x_rev(Void);
11 extern int xw_end(Void);
12 extern int xw_rev(Void);
13
14 /* check sequential formatted external I/O reading
15 */
c_sfe(cilist * a)16 c_sfe(cilist *a)
17 {
18 unit *p;
19 f__curunit = p = &f__units[a->ciunit];
20 if(a->ciunit >= MXUNIT || a->ciunit<0)
21 err(a->cierr,101,"startio");
22 if(p->ufd==NULL && fk_open(SEQ,FMT,a->ciunit))
23 err(a->cierr,114,"sfe");
24 if(!p->ufmt)
25 err(a->cierr,102,"sfe");
26 return(0);
27 }
28
29 /* start sequential formatted external I/O reading
30 */
s_rsfe(cilist * a)31 integer s_rsfe(cilist *a)
32 {
33 int n;
34
35 if(!f__init)
36 f_init();
37 f__reading=1;
38 f__sequential=1;
39 f__formatted=1;
40 f__external=1;
41 if(n=c_sfe(a))
42 return(n);
43 f__elist=a;
44 f__cursor=f__recpos=0;
45 f__scale=0;
46 f__fmtbuf=a->cifmt;
47 f__cf=f__curunit->ufd;
48 if(pars_f(f__fmtbuf)<0)
49 err(a->cierr,100,"startio");
50 f__getn= x_getc;
51 f__doed= rd_ed;
52 f__doned= rd_ned;
53 fmt_bg();
54 f__doend=x_endp;
55 f__donewrec=xrd_SL;
56 f__dorevert=x_rev;
57 f__cblank=f__curunit->ublnk;
58 f__cplus=0;
59 if(f__curunit->uwrt && f__nowreading(f__curunit))
60 err(a->cierr,errno,"read start");
61 if(f__curunit->uend)
62 err(f__elist->ciend,(EOF),"read start");
63 return(0);
64 }
65
66 /* end sequential formatted external I/O reading
67 */
e_rsfe(Void)68 integer e_rsfe(Void)
69 {
70 int n;
71
72 n=en_fio();
73 f__fmtbuf=NULL;
74 return(n);
75 }
76
77 /* start sequential formatted external I/O writing
78 */
s_wsfe(cilist * a)79 integer s_wsfe(cilist *a)
80 {
81 int n;
82
83 if(!f__init)
84 f_init();
85 f__reading=0;
86 f__sequential=1;
87 f__formatted=1;
88 f__external=1;
89 if(n=c_sfe(a))
90 return(n);
91 f__elist=a;
92 f__hiwater = f__cursor=f__recpos=0;
93 f__nonl = 0;
94 f__scale=0;
95 f__fmtbuf=a->cifmt;
96 f__cf=f__curunit->ufd;
97 if(pars_f(f__fmtbuf)<0)
98 err(a->cierr,100,"startio");
99 f__putn= x_putc;
100 f__doed= w_ed;
101 f__doned= w_ned;
102 f__doend=xw_end;
103 f__dorevert=xw_rev;
104 f__donewrec=x_wSL;
105 fmt_bg();
106 f__cplus=0;
107 f__cblank=f__curunit->ublnk;
108 if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
109 err(a->cierr,errno,"write start");
110 return(0);
111 }
112
113 /* start sequential formatted external I/O writing
114 */
e_wsfe(Void)115 integer e_wsfe(Void)
116 {
117 int n = en_fio();
118 f__fmtbuf = NULL;
119 return n;
120 }
121