00001 #include "f2c.h"
00002 #include "fio.h"
00003 #include "fmt.h"
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007
00008 extern icilist *f__svic;
00009 extern char *f__icptr;
00010
00011 static int
00012 mv_cur(Void)
00013
00014 {
00015 int cursor = f__cursor;
00016 f__cursor = 0;
00017 if(f__external == 0) {
00018 if(cursor < 0) {
00019 if(f__hiwater < f__recpos)
00020 f__hiwater = f__recpos;
00021 f__recpos += cursor;
00022 f__icptr += cursor;
00023 if(f__recpos < 0)
00024 err(f__elist->cierr, 110, "left off");
00025 }
00026 else if(cursor > 0) {
00027 if(f__recpos + cursor >= f__svic->icirlen)
00028 err(f__elist->cierr, 110, "recend");
00029 if(f__hiwater <= f__recpos)
00030 for(; cursor > 0; cursor--)
00031 (*f__putn)(' ');
00032 else if(f__hiwater <= f__recpos + cursor) {
00033 cursor -= f__hiwater - f__recpos;
00034 f__icptr += f__hiwater - f__recpos;
00035 f__recpos = f__hiwater;
00036 for(; cursor > 0; cursor--)
00037 (*f__putn)(' ');
00038 }
00039 else {
00040 f__icptr += cursor;
00041 f__recpos += cursor;
00042 }
00043 }
00044 return(0);
00045 }
00046 if (cursor > 0) {
00047 if(f__hiwater <= f__recpos)
00048 for(;cursor>0;cursor--) (*f__putn)(' ');
00049 else if(f__hiwater <= f__recpos + cursor) {
00050 cursor -= f__hiwater - f__recpos;
00051 f__recpos = f__hiwater;
00052 for(; cursor > 0; cursor--)
00053 (*f__putn)(' ');
00054 }
00055 else {
00056 f__recpos += cursor;
00057 }
00058 }
00059 else if (cursor < 0)
00060 {
00061 if(cursor + f__recpos < 0)
00062 err(f__elist->cierr,110,"left off");
00063 if(f__hiwater < f__recpos)
00064 f__hiwater = f__recpos;
00065 f__recpos += cursor;
00066 }
00067 return(0);
00068 }
00069
00070 static int
00071 #ifdef KR_headers
00072 wrt_Z(n,w,minlen,len) Uint *n; int w, minlen; ftnlen len;
00073 #else
00074 wrt_Z(Uint *n, int w, int minlen, ftnlen len)
00075 #endif
00076 {
00077 register char *s, *se;
00078 register int i, w1;
00079 static int one = 1;
00080 static char hex[] = "0123456789ABCDEF";
00081 s = (char *)n;
00082 --len;
00083 if (*(char *)&one) {
00084
00085 se = s;
00086 s += len;
00087 i = -1;
00088 }
00089 else {
00090 se = s + len;
00091 i = 1;
00092 }
00093 for(;; s += i)
00094 if (s == se || *s)
00095 break;
00096 w1 = (i*(se-s) << 1) + 1;
00097 if (*s & 0xf0)
00098 w1++;
00099 if (w1 > w)
00100 for(i = 0; i < w; i++)
00101 (*f__putn)('*');
00102 else {
00103 if ((minlen -= w1) > 0)
00104 w1 += minlen;
00105 while(--w >= w1)
00106 (*f__putn)(' ');
00107 while(--minlen >= 0)
00108 (*f__putn)('0');
00109 if (!(*s & 0xf0)) {
00110 (*f__putn)(hex[*s & 0xf]);
00111 if (s == se)
00112 return 0;
00113 s += i;
00114 }
00115 for(;; s += i) {
00116 (*f__putn)(hex[*s >> 4 & 0xf]);
00117 (*f__putn)(hex[*s & 0xf]);
00118 if (s == se)
00119 break;
00120 }
00121 }
00122 return 0;
00123 }
00124
00125 static int
00126 #ifdef KR_headers
00127 wrt_I(n,w,len, base) Uint *n; ftnlen len; register int base;
00128 #else
00129 wrt_I(Uint *n, int w, ftnlen len, register int base)
00130 #endif
00131 { int ndigit,sign,spare,i;
00132 longint x;
00133 char *ans;
00134 if(len==sizeof(integer)) x=n->il;
00135 else if(len == sizeof(char)) x = n->ic;
00136 #ifdef Allow_TYQUAD
00137 else if (len == sizeof(longint)) x = n->ili;
00138 #endif
00139 else x=n->is;
00140 ans=f__icvt(x,&ndigit,&sign, base);
00141 spare=w-ndigit;
00142 if(sign || f__cplus) spare--;
00143 if(spare<0)
00144 for(i=0;i<w;i++) (*f__putn)('*');
00145 else
00146 { for(i=0;i<spare;i++) (*f__putn)(' ');
00147 if(sign) (*f__putn)('-');
00148 else if(f__cplus) (*f__putn)('+');
00149 for(i=0;i<ndigit;i++) (*f__putn)(*ans++);
00150 }
00151 return(0);
00152 }
00153 static int
00154 #ifdef KR_headers
00155 wrt_IM(n,w,m,len,base) Uint *n; ftnlen len; int base;
00156 #else
00157 wrt_IM(Uint *n, int w, int m, ftnlen len, int base)
00158 #endif
00159 { int ndigit,sign,spare,i,xsign;
00160 longint x;
00161 char *ans;
00162 if(sizeof(integer)==len) x=n->il;
00163 else if(len == sizeof(char)) x = n->ic;
00164 #ifdef Allow_TYQUAD
00165 else if (len == sizeof(longint)) x = n->ili;
00166 #endif
00167 else x=n->is;
00168 ans=f__icvt(x,&ndigit,&sign, base);
00169 if(sign || f__cplus) xsign=1;
00170 else xsign=0;
00171 if(ndigit+xsign>w || m+xsign>w)
00172 { for(i=0;i<w;i++) (*f__putn)('*');
00173 return(0);
00174 }
00175 if(x==0 && m==0)
00176 { for(i=0;i<w;i++) (*f__putn)(' ');
00177 return(0);
00178 }
00179 if(ndigit>=m)
00180 spare=w-ndigit-xsign;
00181 else
00182 spare=w-m-xsign;
00183 for(i=0;i<spare;i++) (*f__putn)(' ');
00184 if(sign) (*f__putn)('-');
00185 else if(f__cplus) (*f__putn)('+');
00186 for(i=0;i<m-ndigit;i++) (*f__putn)('0');
00187 for(i=0;i<ndigit;i++) (*f__putn)(*ans++);
00188 return(0);
00189 }
00190 static int
00191 #ifdef KR_headers
00192 wrt_AP(s) char *s;
00193 #else
00194 wrt_AP(char *s)
00195 #endif
00196 { char quote;
00197 int i;
00198
00199 if(f__cursor && (i = mv_cur()))
00200 return i;
00201 quote = *s++;
00202 for(;*s;s++)
00203 { if(*s!=quote) (*f__putn)(*s);
00204 else if(*++s==quote) (*f__putn)(*s);
00205 else return(1);
00206 }
00207 return(1);
00208 }
00209 static int
00210 #ifdef KR_headers
00211 wrt_H(a,s) char *s;
00212 #else
00213 wrt_H(int a, char *s)
00214 #endif
00215 {
00216 int i;
00217
00218 if(f__cursor && (i = mv_cur()))
00219 return i;
00220 while(a--) (*f__putn)(*s++);
00221 return(1);
00222 }
00223
00224 int
00225 #ifdef KR_headers
00226 wrt_L(n,len, sz) Uint *n; ftnlen sz;
00227 #else
00228 wrt_L(Uint *n, int len, ftnlen sz)
00229 #endif
00230 { int i;
00231 long x;
00232 if(sizeof(long)==sz) x=n->il;
00233 else if(sz == sizeof(char)) x = n->ic;
00234 else x=n->is;
00235 for(i=0;i<len-1;i++)
00236 (*f__putn)(' ');
00237 if(x) (*f__putn)('T');
00238 else (*f__putn)('F');
00239 return(0);
00240 }
00241 static int
00242 #ifdef KR_headers
00243 wrt_A(p,len) char *p; ftnlen len;
00244 #else
00245 wrt_A(char *p, ftnlen len)
00246 #endif
00247 {
00248 while(len-- > 0) (*f__putn)(*p++);
00249 return(0);
00250 }
00251 static int
00252 #ifdef KR_headers
00253 wrt_AW(p,w,len) char * p; ftnlen len;
00254 #else
00255 wrt_AW(char * p, int w, ftnlen len)
00256 #endif
00257 {
00258 while(w>len)
00259 { w--;
00260 (*f__putn)(' ');
00261 }
00262 while(w-- > 0)
00263 (*f__putn)(*p++);
00264 return(0);
00265 }
00266
00267 static int
00268 #ifdef KR_headers
00269 wrt_G(p,w,d,e,len) ufloat *p; ftnlen len;
00270 #else
00271 wrt_G(ufloat *p, int w, int d, int e, ftnlen len)
00272 #endif
00273 { double up = 1,x;
00274 int i=0,oldscale,n,j;
00275 x = len==sizeof(real)?p->pf:p->pd;
00276 if(x < 0 ) x = -x;
00277 if(x<.1) {
00278 if (x != 0.)
00279 return(wrt_E(p,w,d,e,len));
00280 i = 1;
00281 goto have_i;
00282 }
00283 for(;i<=d;i++,up*=10)
00284 { if(x>=up) continue;
00285 have_i:
00286 oldscale = f__scale;
00287 f__scale = 0;
00288 if(e==0) n=4;
00289 else n=e+2;
00290 i=wrt_F(p,w-n,d-i,len);
00291 for(j=0;j<n;j++) (*f__putn)(' ');
00292 f__scale=oldscale;
00293 return(i);
00294 }
00295 return(wrt_E(p,w,d,e,len));
00296 }
00297
00298 int
00299 #ifdef KR_headers
00300 w_ed(p,ptr,len) struct syl *p; char *ptr; ftnlen len;
00301 #else
00302 w_ed(struct syl *p, char *ptr, ftnlen len)
00303 #endif
00304 {
00305 int i;
00306
00307 if(f__cursor && (i = mv_cur()))
00308 return i;
00309 switch(p->op)
00310 {
00311 default:
00312 fprintf(stderr,"w_ed, unexpected code: %d\n", p->op);
00313 sig_die(f__fmtbuf, 1);
00314 case I: return(wrt_I((Uint *)ptr,p->p1,len, 10));
00315 case IM:
00316 return(wrt_IM((Uint *)ptr,p->p1,p->p2.i[0],len,10));
00317
00318
00319
00320
00321
00322 case O: return(wrt_I((Uint *)ptr, p->p1, len, 8));
00323 case OM:
00324 return(wrt_IM((Uint *)ptr,p->p1,p->p2.i[0],len,8));
00325 case L: return(wrt_L((Uint *)ptr,p->p1, len));
00326 case A: return(wrt_A(ptr,len));
00327 case AW:
00328 return(wrt_AW(ptr,p->p1,len));
00329 case D:
00330 case E:
00331 case EE:
00332 return(wrt_E((ufloat *)ptr,p->p1,p->p2.i[0],p->p2.i[1],len));
00333 case G:
00334 case GE:
00335 return(wrt_G((ufloat *)ptr,p->p1,p->p2.i[0],p->p2.i[1],len));
00336 case F: return(wrt_F((ufloat *)ptr,p->p1,p->p2.i[0],len));
00337
00338
00339
00340 case Z: return(wrt_Z((Uint *)ptr,p->p1,0,len));
00341 case ZM:
00342 return(wrt_Z((Uint *)ptr,p->p1,p->p2.i[0],len));
00343 }
00344 }
00345
00346 int
00347 #ifdef KR_headers
00348 w_ned(p) struct syl *p;
00349 #else
00350 w_ned(struct syl *p)
00351 #endif
00352 {
00353 switch(p->op)
00354 {
00355 default: fprintf(stderr,"w_ned, unexpected code: %d\n", p->op);
00356 sig_die(f__fmtbuf, 1);
00357 case SLASH:
00358 return((*f__donewrec)());
00359 case T: f__cursor = p->p1-f__recpos - 1;
00360 return(1);
00361 case TL: f__cursor -= p->p1;
00362 if(f__cursor < -f__recpos)
00363 f__cursor = -f__recpos;
00364 return(1);
00365 case TR:
00366 case X:
00367 f__cursor += p->p1;
00368 return(1);
00369 case APOS:
00370 return(wrt_AP(p->p2.s));
00371 case H:
00372 return(wrt_H(p->p1,p->p2.s));
00373 }
00374 }
00375 #ifdef __cplusplus
00376 }
00377 #endif