OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / gcc / f / runtime / libI77 / wsfe.c
1 /*write sequential formatted external*/
2 #include "f2c.h"
3 #include "fio.h"
4 #include "fmt.h"
5 extern int f__hiwater;
6
7 #ifdef KR_headers
8 x_putc(c)
9 #else
10 x_putc(int c)
11 #endif
12 {
13         /* this uses \n as an indicator of record-end */
14         if(c == '\n' && f__recpos < f__hiwater) {       /* fseek calls fflush, a loss */
15 #if ! defined (NON_UNIX_STDIO) && ! defined (MISSING_FILE_ELEMS)
16                 if(f__cf->_ptr + f__hiwater - f__recpos < buf_end(f__cf))
17                         f__cf->_ptr += f__hiwater - f__recpos;
18                 else
19 #endif
20                         (void) fseek(f__cf, (long)(f__hiwater - f__recpos), SEEK_CUR);
21         }
22 #ifdef OMIT_BLANK_CC
23         if (!f__recpos++ && c == ' ')
24                 return c;
25 #else
26         f__recpos++;
27 #endif
28         return putc(c,f__cf);
29 }
30 x_wSL(Void)
31 {
32         (*f__putn)('\n');
33         f__recpos=0;
34         f__cursor = 0;
35         f__hiwater = 0;
36         return(1);
37 }
38 xw_end(Void)
39 {
40         if(f__nonl == 0)
41                 (*f__putn)('\n');
42         f__hiwater = f__recpos = f__cursor = 0;
43         return(0);
44 }
45 xw_rev(Void)
46 {
47         if(f__workdone) (*f__putn)('\n');
48         f__hiwater = f__recpos = f__cursor = 0;
49         return(f__workdone=0);
50 }
51
52 #ifdef KR_headers
53 integer s_wsfe(a) cilist *a;    /*start*/
54 #else
55 integer s_wsfe(cilist *a)       /*start*/
56 #endif
57 {       int n;
58         if(f__init != 1) f_init();
59         f__init = 3;
60         if(n=c_sfe(a)) return(n);
61         f__reading=0;
62         f__sequential=1;
63         f__formatted=1;
64         f__external=1;
65         f__elist=a;
66         f__hiwater = f__cursor=f__recpos=0;
67         f__nonl = 0;
68         f__scale=0;
69         f__fmtbuf=a->cifmt;
70         f__curunit = &f__units[a->ciunit];
71         f__cf=f__curunit->ufd;
72         if(pars_f(f__fmtbuf)<0) err(a->cierr,100,"startio");
73         f__putn= x_putc;
74         f__doed= w_ed;
75         f__doned= w_ned;
76         f__doend=xw_end;
77         f__dorevert=xw_rev;
78         f__donewrec=x_wSL;
79         fmt_bg();
80         f__cplus=0;
81         f__cblank=f__curunit->ublnk;
82         if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
83                 err(a->cierr,errno,"write start");
84         return(0);
85 }