| 1 |
#include "f2c.h" |
| 2 |
#include "fio.h" |
| 3 |
#include "fmt.h" |
| 4 |
#ifdef __cplusplus |
| 5 |
extern "C" { |
| 6 |
#endif |
| 7 |
extern char *f__icptr; |
| 8 |
char *f__icend; |
| 9 |
extern icilist *f__svic; |
| 10 |
int f__icnum; |
| 11 |
|
| 12 |
int |
| 13 |
z_getc(Void) |
| 14 |
{ |
| 15 |
if(f__recpos++ < f__svic->icirlen) { |
| 16 |
if(f__icptr >= f__icend) err(f__svic->iciend,(EOF),"endfile"); |
| 17 |
return(*(unsigned char *)f__icptr++); |
| 18 |
} |
| 19 |
return '\n'; |
| 20 |
} |
| 21 |
|
| 22 |
void |
| 23 |
#ifdef KR_headers |
| 24 |
z_putc(c) |
| 25 |
#else |
| 26 |
z_putc(int c) |
| 27 |
#endif |
| 28 |
{ |
| 29 |
if (f__icptr < f__icend && f__recpos++ < f__svic->icirlen) |
| 30 |
*f__icptr++ = c; |
| 31 |
} |
| 32 |
|
| 33 |
int |
| 34 |
z_rnew(Void) |
| 35 |
{ |
| 36 |
f__icptr = f__svic->iciunit + (++f__icnum)*f__svic->icirlen; |
| 37 |
f__recpos = 0; |
| 38 |
f__cursor = 0; |
| 39 |
f__hiwater = 0; |
| 40 |
return 1; |
| 41 |
} |
| 42 |
|
| 43 |
static int |
| 44 |
z_endp(Void) |
| 45 |
{ |
| 46 |
(*f__donewrec)(); |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
int |
| 51 |
#ifdef KR_headers |
| 52 |
c_si(a) icilist *a; |
| 53 |
#else |
| 54 |
c_si(icilist *a) |
| 55 |
#endif |
| 56 |
{ |
| 57 |
f__elist = (cilist *)a; |
| 58 |
f__fmtbuf=a->icifmt; |
| 59 |
f__curunit = 0; |
| 60 |
f__sequential=f__formatted=1; |
| 61 |
f__external=0; |
| 62 |
if(pars_f(f__fmtbuf)<0) |
| 63 |
err(a->icierr,100,"startint"); |
| 64 |
fmt_bg(); |
| 65 |
f__cblank=f__cplus=f__scale=0; |
| 66 |
f__svic=a; |
| 67 |
f__icnum=f__recpos=0; |
| 68 |
f__cursor = 0; |
| 69 |
f__hiwater = 0; |
| 70 |
f__icptr = a->iciunit; |
| 71 |
f__icend = f__icptr + a->icirlen*a->icirnum; |
| 72 |
f__cf = 0; |
| 73 |
return(0); |
| 74 |
} |
| 75 |
|
| 76 |
int |
| 77 |
iw_rev(Void) |
| 78 |
{ |
| 79 |
if(f__workdone) |
| 80 |
z_endp(); |
| 81 |
f__hiwater = f__recpos = f__cursor = 0; |
| 82 |
return(f__workdone=0); |
| 83 |
} |
| 84 |
|
| 85 |
#ifdef KR_headers |
| 86 |
integer s_rsfi(a) icilist *a; |
| 87 |
#else |
| 88 |
integer s_rsfi(icilist *a) |
| 89 |
#endif |
| 90 |
{ int n; |
| 91 |
if(n=c_si(a)) return(n); |
| 92 |
f__reading=1; |
| 93 |
f__doed=rd_ed; |
| 94 |
f__doned=rd_ned; |
| 95 |
f__getn=z_getc; |
| 96 |
f__dorevert = z_endp; |
| 97 |
f__donewrec = z_rnew; |
| 98 |
f__doend = z_endp; |
| 99 |
return(0); |
| 100 |
} |
| 101 |
|
| 102 |
int |
| 103 |
z_wnew(Void) |
| 104 |
{ |
| 105 |
if (f__recpos < f__hiwater) { |
| 106 |
f__icptr += f__hiwater - f__recpos; |
| 107 |
f__recpos = f__hiwater; |
| 108 |
} |
| 109 |
while(f__recpos++ < f__svic->icirlen) |
| 110 |
*f__icptr++ = ' '; |
| 111 |
f__recpos = 0; |
| 112 |
f__cursor = 0; |
| 113 |
f__hiwater = 0; |
| 114 |
f__icnum++; |
| 115 |
return 1; |
| 116 |
} |
| 117 |
#ifdef KR_headers |
| 118 |
integer s_wsfi(a) icilist *a; |
| 119 |
#else |
| 120 |
integer s_wsfi(icilist *a) |
| 121 |
#endif |
| 122 |
{ int n; |
| 123 |
if(n=c_si(a)) return(n); |
| 124 |
f__reading=0; |
| 125 |
f__doed=w_ed; |
| 126 |
f__doned=w_ned; |
| 127 |
f__putn=z_putc; |
| 128 |
f__dorevert = iw_rev; |
| 129 |
f__donewrec = z_wnew; |
| 130 |
f__doend = z_endp; |
| 131 |
return(0); |
| 132 |
} |
| 133 |
integer e_rsfi(Void) |
| 134 |
{ int n = en_fio(); |
| 135 |
f__fmtbuf = NULL; |
| 136 |
return(n); |
| 137 |
} |
| 138 |
integer e_wsfi(Void) |
| 139 |
{ |
| 140 |
int n; |
| 141 |
n = en_fio(); |
| 142 |
f__fmtbuf = NULL; |
| 143 |
if(f__svic->icirnum != 1 |
| 144 |
&& (f__icnum > f__svic->icirnum |
| 145 |
|| (f__icnum == f__svic->icirnum && (f__recpos | f__hiwater)))) |
| 146 |
err(f__svic->icierr,110,"inwrite"); |
| 147 |
if (f__recpos < f__hiwater) |
| 148 |
f__recpos = f__hiwater; |
| 149 |
if (f__recpos >= f__svic->icirlen) |
| 150 |
err(f__svic->icierr,110,"recend"); |
| 151 |
if (!f__recpos && f__icnum) |
| 152 |
return n; |
| 153 |
while(f__recpos++ < f__svic->icirlen) |
| 154 |
*f__icptr++ = ' '; |
| 155 |
return n; |
| 156 |
} |
| 157 |
#ifdef __cplusplus |
| 158 |
} |
| 159 |
#endif |