6 extern icilist
*f__svic
;
10 mv_cur(Void
) /* shouldn't use fseek because it insists on calling fflush */
11 /* instead we know too much about stdio */
13 int cursor
= f__cursor
;
15 if(f__external
== 0) {
17 if(f__hiwater
< f__recpos
)
18 f__hiwater
= f__recpos
;
22 err(f__elist
->cierr
, 110, "left off");
25 if(f__recpos
+ cursor
>= f__svic
->icirlen
)
26 err(f__elist
->cierr
, 110, "recend");
27 if(f__hiwater
<= f__recpos
)
28 for(; cursor
> 0; cursor
--)
30 else if(f__hiwater
<= f__recpos
+ cursor
) {
31 cursor
-= f__hiwater
- f__recpos
;
32 f__icptr
+= f__hiwater
- f__recpos
;
33 f__recpos
= f__hiwater
;
34 for(; cursor
> 0; cursor
--)
45 if(f__hiwater
<= f__recpos
)
46 for(;cursor
>0;cursor
--) (*f__putn
)(' ');
47 else if(f__hiwater
<= f__recpos
+ cursor
) {
48 cursor
-= f__hiwater
- f__recpos
;
49 f__recpos
= f__hiwater
;
50 for(; cursor
> 0; cursor
--)
59 if(cursor
+ f__recpos
< 0)
60 err(f__elist
->cierr
,110,"left off");
61 if(f__hiwater
< f__recpos
)
62 f__hiwater
= f__recpos
;
70 wrt_Z(n
,w
,minlen
,len
) Uint
*n
; int w
, minlen
; ftnlen len
;
72 wrt_Z(Uint
*n
, int w
, int minlen
, ftnlen len
)
75 register char *s
, *se
;
78 static char hex
[] = "0123456789ABCDEF";
94 w1
= (i
*(se
-s
) << 1) + 1;
98 for(i
= 0; i
< w
; i
++)
101 if ((minlen
-= w1
) > 0)
108 (*f__putn
)(hex
[*s
& 0xf]);
114 (*f__putn
)(hex
[*s
>> 4 & 0xf]);
115 (*f__putn
)(hex
[*s
& 0xf]);
125 wrt_I(n
,w
,len
, base
) Uint
*n
; ftnlen len
; register int base
;
127 wrt_I(Uint
*n
, int w
, ftnlen len
, register int base
)
129 { int ndigit
,sign
,spare
,i
;
132 if(len
==sizeof(integer
)) x
=n
->il
;
133 else if(len
== sizeof(char)) x
= n
->ic
;
135 else if (len
== sizeof(longint
)) x
= n
->ili
;
138 ans
=f__icvt(x
,&ndigit
,&sign
, base
);
140 if(sign
|| f__cplus
) spare
--;
142 for(i
=0;i
<w
;i
++) (*f__putn
)('*');
144 { for(i
=0;i
<spare
;i
++) (*f__putn
)(' ');
145 if(sign
) (*f__putn
)('-');
146 else if(f__cplus
) (*f__putn
)('+');
147 for(i
=0;i
<ndigit
;i
++) (*f__putn
)(*ans
++);
153 wrt_IM(n
,w
,m
,len
,base
) Uint
*n
; ftnlen len
; int base
;
155 wrt_IM(Uint
*n
, int w
, int m
, ftnlen len
, int base
)
157 { int ndigit
,sign
,spare
,i
,xsign
;
160 if(sizeof(integer
)==len
) x
=n
->il
;
161 else if(len
== sizeof(char)) x
= n
->ic
;
163 else if (len
== sizeof(longint
)) x
= n
->ili
;
166 ans
=f__icvt(x
,&ndigit
,&sign
, base
);
167 if(sign
|| f__cplus
) xsign
=1;
169 if(ndigit
+xsign
>w
|| m
+xsign
>w
)
170 { for(i
=0;i
<w
;i
++) (*f__putn
)('*');
174 { for(i
=0;i
<w
;i
++) (*f__putn
)(' ');
178 spare
=w
-ndigit
-xsign
;
181 for(i
=0;i
<spare
;i
++) (*f__putn
)(' ');
182 if(sign
) (*f__putn
)('-');
183 else if(f__cplus
) (*f__putn
)('+');
184 for(i
=0;i
<m
-ndigit
;i
++) (*f__putn
)('0');
185 for(i
=0;i
<ndigit
;i
++) (*f__putn
)(*ans
++);
197 if(f__cursor
&& (i
= mv_cur()))
201 { if(*s
!=quote
) (*f__putn
)(*s
);
202 else if(*++s
==quote
) (*f__putn
)(*s
);
211 wrt_H(int a
, char *s
)
216 if(f__cursor
&& (i
= mv_cur()))
218 while(a
--) (*f__putn
)(*s
++);
222 wrt_L(n
,len
, sz
) Uint
*n
; ftnlen sz
;
224 wrt_L(Uint
*n
, int len
, ftnlen sz
)
228 if(sizeof(long)==sz
) x
=n
->il
;
229 else if(sz
== sizeof(char)) x
= n
->ic
;
233 if(x
) (*f__putn
)('T');
234 else (*f__putn
)('F');
239 wrt_A(p
,len
) char *p
; ftnlen len
;
241 wrt_A(char *p
, ftnlen len
)
244 while(len
-- > 0) (*f__putn
)(*p
++);
249 wrt_AW(p
,w
,len
) char * p
; ftnlen len
;
251 wrt_AW(char * p
, int w
, ftnlen len
)
265 wrt_G(p
,w
,d
,e
,len
) ufloat
*p
; ftnlen len
;
267 wrt_G(ufloat
*p
, int w
, int d
, int e
, ftnlen len
)
270 int i
=0,oldscale
,n
,j
;
271 x
= len
==sizeof(real
)?p
->pf
:p
->pd
;
275 return(wrt_E(p
,w
,d
,e
,len
));
279 for(;i
<=d
;i
++,up
*=10)
280 { if(x
>=up
) continue;
286 i
=wrt_F(p
,w
-n
,d
-i
,len
);
287 for(j
=0;j
<n
;j
++) (*f__putn
)(' ');
291 return(wrt_E(p
,w
,d
,e
,len
));
294 w_ed(p
,ptr
,len
) struct syl
*p
; char *ptr
; ftnlen len
;
296 w_ed(struct syl
*p
, char *ptr
, ftnlen len
)
301 if(f__cursor
&& (i
= mv_cur()))
306 fprintf(stderr
,"w_ed, unexpected code: %d\n", p
->op
);
307 sig_die(f__fmtbuf
, 1);
308 case I
: return(wrt_I((Uint
*)ptr
,p
->p1
,len
, 10));
310 return(wrt_IM((Uint
*)ptr
,p
->p1
,p
->p2
.i
[0],len
,10));
312 /* O and OM don't work right for character, double, complex, */
313 /* or doublecomplex, and they differ from Fortran 90 in */
314 /* showing a minus sign for negative values. */
316 case O
: return(wrt_I((Uint
*)ptr
, p
->p1
, len
, 8));
318 return(wrt_IM((Uint
*)ptr
,p
->p1
,p
->p2
.i
[0],len
,8));
319 case L
: return(wrt_L((Uint
*)ptr
,p
->p1
, len
));
320 case A
: return(wrt_A(ptr
,len
));
322 return(wrt_AW(ptr
,p
->p1
,len
));
326 return(wrt_E((ufloat
*)ptr
,p
->p1
,p
->p2
.i
[0],p
->p2
.i
[1],len
));
329 return(wrt_G((ufloat
*)ptr
,p
->p1
,p
->p2
.i
[0],p
->p2
.i
[1],len
));
330 case F
: return(wrt_F((ufloat
*)ptr
,p
->p1
,p
->p2
.i
[0],len
));
332 /* Z and ZM assume 8-bit bytes. */
334 case Z
: return(wrt_Z((Uint
*)ptr
,p
->p1
,0,len
));
336 return(wrt_Z((Uint
*)ptr
,p
->p1
,p
->p2
.i
[0],len
));
340 w_ned(p
) struct syl
*p
;
347 default: fprintf(stderr
,"w_ned, unexpected code: %d\n", p
->op
);
348 sig_die(f__fmtbuf
, 1);
350 return((*f__donewrec
)());
351 case T
: f__cursor
= p
->p1
-f__recpos
- 1;
353 case TL
: f__cursor
-= p
->p1
;
354 if(f__cursor
< -f__recpos
) /* TL1000, 1X */
355 f__cursor
= -f__recpos
;
362 return(wrt_AP(p
->p2
.s
));
364 return(wrt_H(p
->p1
,p
->p2
.s
));