BSD 4_3 release
[unix-history] / usr / src / usr.lib / libI77 / wrtfmt.c
index 4dbaa5d..9607e62 100644 (file)
@@ -1,6 +1,12 @@
 /*
 /*
-char id_wrtfmt[] = "@(#)wrtfmt.c       1.7";
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
  *
  *
+ *     @(#)wrtfmt.c    5.1     6/7/85
+ */
+
+/*
  * formatted write routines
  */
 
  * formatted write routines
  */
 
@@ -8,6 +14,7 @@ char id_wrtfmt[] = "@(#)wrtfmt.c       1.7";
 #include "format.h"
 
 extern char *icvt();
 #include "format.h"
 
 extern char *icvt();
+extern char *s_init;
 
 #define abs(x) (x<0?-x:x)
 
 
 #define abs(x) (x<0?-x:x)
 
@@ -20,20 +27,23 @@ w_ed(p,ptr,len) char *ptr; struct syl *p; ftnlen len;
        case IM:
                return(wrt_IM(ptr,p->p1,p->p2,len));
        case L:
        case IM:
                return(wrt_IM(ptr,p->p1,p->p2,len));
        case L:
-               return(wrt_L(ptr,p->p1));
+               return(wrt_L(ptr,p->p1,len));
        case A:
        case A:
-               p->p1 = len;    /* cheap trick */
+               return(wrt_AW(ptr,len,len));
        case AW:
                return(wrt_AW(ptr,p->p1,len));
        case D:
        case AW:
                return(wrt_AW(ptr,p->p1,len));
        case D:
+               return(wrt_E(ptr,p->p1,p->p2,2,len,'d'));
        case DE:
        case DE:
-               return(wrt_E(ptr,p->p1,p->p2,p->p3,len,'d'));
+               return(wrt_E(ptr,p->p1,(p->p2)&0xff,((p->p2)>>8)&0xff,len,'d'));
        case E:
        case E:
+               return(wrt_E(ptr,p->p1,p->p2,2,len,'e'));
        case EE:
        case EE:
-               return(wrt_E(ptr,p->p1,p->p2,p->p3,len,'e'));
+               return(wrt_E(ptr,p->p1,(p->p2)&0xff,((p->p2)>>8)&0xff,len,'e'));
        case G:
        case G:
+               return(wrt_G(ptr,p->p1,p->p2,2,len));
        case GE:
        case GE:
-               return(wrt_G(ptr,p->p1,p->p2,p->p3,len));
+               return(wrt_G(ptr,p->p1,(p->p2)&0xff,((p->p2)>>8)&0xff,len));
        case F:
                return(wrt_F(ptr,p->p1,p->p2,len));
        default:
        case F:
                return(wrt_F(ptr,p->p1,p->p2,len));
        default:
@@ -66,14 +76,15 @@ w_ned(p,ptr) char *ptr; struct syl *p;
                tab = YES;
                return(OK);
        case APOS:
                tab = YES;
                return(OK);
        case APOS:
-               return(wrt_AP(p->p1));
+               return(wrt_AP(&s_init[p->p1]));
        case H:
        case H:
-               return(wrt_H(p->p1,p->p2));
+               return(wrt_H(p->p1,&s_init[p->p2]));
        default:
                return(errno=F_ERFMT);
        }
 }
 
        default:
                return(errno=F_ERFMT);
        }
 }
 
+LOCAL
 wr_mvcur()
 {      int n;
        if(tab) return((*dotab)());
 wr_mvcur()
 {      int n;
        if(tab) return((*dotab)());
@@ -82,6 +93,7 @@ wr_mvcur()
        return(cursor=0);
 }
 
        return(cursor=0);
 }
 
+LOCAL
 wrt_IM(ui,w,m,len) uint *ui; ftnlen len;
 {      int ndigit,sign,spare,i,xsign,n;
        long x;
 wrt_IM(ui,w,m,len) uint *ui; ftnlen len;
 {      int ndigit,sign,spare,i,xsign,n;
        long x;
@@ -112,6 +124,7 @@ wrt_IM(ui,w,m,len) uint *ui; ftnlen len;
        return(OK);
 }
 
        return(OK);
 }
 
+LOCAL
 wrt_AP(p)
 {      char *s,quote;
        int n;
 wrt_AP(p)
 {      char *s,quote;
        int n;
@@ -126,6 +139,7 @@ wrt_AP(p)
        return(OK);
 }
 
        return(OK);
 }
 
+LOCAL
 wrt_H(a,b)
 {      char *s=(char *)b;
        int n;
 wrt_H(a,b)
 {      char *s=(char *)b;
        int n;
@@ -134,14 +148,19 @@ wrt_H(a,b)
        return(OK);
 }
 
        return(OK);
 }
 
-wrt_L(l,len) ftnint *l;
+wrt_L(l,width,len) uint *l; ftnlen len;
 {      int i,n;
 {      int i,n;
-       for(i=0;i<len-1;i++) PUT(' ')
-       if(*l) PUT('t')
+       for(i=0;i<width-1;i++) PUT(' ')
+       if(len == sizeof (short))
+               i = l->is;
+       else
+               i = l->il;
+       if(i) PUT('t')
        else PUT('f')
        return(OK);
 }
 
        else PUT('f')
        return(OK);
 }
 
+LOCAL
 wrt_AW(p,w,len) char * p; ftnlen len;
 {      int n;
        while(w>len)
 wrt_AW(p,w,len) char * p; ftnlen len;
 {      int n;
        while(w>len)
@@ -160,7 +179,10 @@ wrt_E(p,w,d,e,len,expch) ufloat *p; ftnlen len; char expch;
 
        if((len==sizeof(float)?p->pf:p->pd)==0.0)
        {
 
        if((len==sizeof(float)?p->pf:p->pd)==0.0)
        {
+               n = cblank;
+               cblank = 1;     /* force '0' fill */
                wrt_F(p,w-(e+2),d,len);
                wrt_F(p,w-(e+2),d,len);
+               cblank = n;
                PUT(expch)
                PUT('+')
 /*             for(i=0;i<(e-1);i++)PUT(' ')
                PUT(expch)
                PUT('+')
 /*             for(i=0;i<(e-1);i++)PUT(' ')
@@ -222,6 +244,7 @@ E_badfield:
        return(OK);
 }
 
        return(OK);
 }
 
+LOCAL
 wrt_G(p,w,d,e,len) ufloat *p; ftnlen len;
 {      double uplim = 1.0, x;
        int i,oldscale,n,j,ne;
 wrt_G(p,w,d,e,len) ufloat *p; ftnlen len;
 {      double uplim = 1.0, x;
        int i,oldscale,n,j,ne;