[BACK]Return to cpexpr.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / io

Diff for /OpenXM_contrib2/asir2000/io/cpexpr.c between version 1.28 and 1.29

version 1.28, 2017/08/31 02:36:21 version 1.29, 2018/03/29 01:32:53
Line 44 
Line 44 
  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY   * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,   * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.   * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
  * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.27 2015/08/04 06:20:45 noro Exp $   * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.28 2017/08/31 02:36:21 noro Exp $
 */  */
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
Line 110  static int total_length;
Line 110  static int total_length;
   
 int estimate_length(VL vl,pointer p)  int estimate_length(VL vl,pointer p)
 {  {
         total_length = 0;    total_length = 0;
         PRINTEXPR(vl,p);    PRINTEXPR(vl,p);
         return total_length;    return total_length;
 }  }
   
 void PRINTBF(BF a)  void PRINTBF(BF a)
 {  {
         char *str;    char *str;
         int dprec;    int dprec;
         char fbuf[BUFSIZ];    char fbuf[BUFSIZ];
   
         dprec = a->body->_mpfr_prec*0.30103;    dprec = a->body->_mpfr_prec*0.30103;
         sprintf(fbuf,"%%.%dR%c",dprec,double_output?'f':'g');    sprintf(fbuf,"%%.%dR%c",dprec,double_output?'f':'g');
         mpfr_asprintf(&str,fbuf,a->body);    mpfr_asprintf(&str,fbuf,a->body);
         total_length += strlen(str);    total_length += strlen(str);
         mpfr_free_str(str);    mpfr_free_str(str);
 }  }
   
 void PRINTNUM(Num q)  void PRINTNUM(Num q)
 {  {
         DAlg d;    DAlg d;
         DP nm;    DP nm;
         Q dn;    Q dn;
   
         if ( !q ) {    if ( !q ) {
                 PUTS("0");      PUTS("0");
                 return;      return;
         }    }
         switch ( NID(q) ) {    switch ( NID(q) ) {
                 case N_Q:      case N_Q:
                         if ( SGN((Q)q) == -1 )        if ( SGN((Q)q) == -1 )
                                 PUTS("-");          PUTS("-");
                         PRINTN(NM((Q)q));        PRINTN(NM((Q)q));
                         if ( !INT((Q)q) ) {        if ( !INT((Q)q) ) {
                                 PUTS("/"); PRINTN(DN((Q)q));          PUTS("/"); PRINTN(DN((Q)q));
                         }        }
                         break;        break;
                 case N_R:      case N_R:
                         if ( double_output )        if ( double_output )
                                 total_length += 400+real_digit; /* XXX */          total_length += 400+real_digit; /* XXX */
                         else        else
                                 total_length += 20+real_digit; /* XXX */          total_length += 20+real_digit; /* XXX */
                         break;        break;
                 case N_A:      case N_A:
                         PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");        PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
                         break;        break;
                 case N_B:      case N_B:
                         PRINTBF((BF)q); break;        PRINTBF((BF)q); break;
                 case N_C:      case N_C:
                         PRINTCPLX((C)q); break;        PRINTCPLX((C)q); break;
                 case N_M:      case N_M:
                         total_length += 11; /* XXX */        total_length += 11; /* XXX */
                         break;        break;
                 case N_LM:      case N_LM:
                         PRINTN(((LM)q)->body); break;        PRINTN(((LM)q)->body); break;
                 case N_GF2N:      case N_GF2N:
                         if ( hex_output )        if ( hex_output )
                                 PRINTN((N)(((GF2N)q)->body));          PRINTN((N)(((GF2N)q)->body));
                         else        else
                                 PRINTUP2(((GF2N)q)->body);          PRINTUP2(((GF2N)q)->body);
                         break;        break;
                 case N_GFPN:      case N_GFPN:
                         PRINTUP((UP)(((GFPN)q)->body));        PRINTUP((UP)(((GFPN)q)->body));
                         break;        break;
                 case N_GFS:      case N_GFS:
                         total_length += 13; /* XXX */        total_length += 13; /* XXX */
                         break;        break;
                 case N_GFSN:      case N_GFSN:
                         PRINTUM(BDY((GFSN)q));        PRINTUM(BDY((GFSN)q));
                         break;        break;
                 case N_DA:      case N_DA:
                         d = (DAlg)q;        d = (DAlg)q;
                         nm = d->nm;        nm = d->nm;
                         dn = d->dn;        dn = d->dn;
                         if ( SGN((Q)dn) == -1 ) PUTS("-");        if ( SGN((Q)dn) == -1 ) PUTS("-");
                         PUTS("(");        PUTS("(");
                         PRINTDP(CO,((DAlg)q)->nm);        PRINTDP(CO,((DAlg)q)->nm);
                         PUTS(")");        PUTS(")");
                         if ( !UNIN(NM(dn)) ) {        if ( !UNIN(NM(dn)) ) {
                                 PUTS("/");          PUTS("/");
                                 PRINTN(NM(dn));          PRINTN(NM(dn));
                         }        }
                         break;        break;
                 default:      default:
                         break;        break;
         }    }
 }  }
   
 void PRINTV(VL vl,V v)  void PRINTV(VL vl,V v)
 {  {
         PF pf;    PF pf;
         PFAD ad;    PFAD ad;
         int i;    int i;
   
         if ( NAME(v) )    if ( NAME(v) )
                 PUTS(NAME(v));      PUTS(NAME(v));
         else if ( (vid)v->attr == V_PF ) {    else if ( (vid)v->attr == V_PF ) {
                 pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;      pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;
                 if ( !strcmp(NAME(pf),"pow") ) {      if ( !strcmp(NAME(pf),"pow") ) {
                         PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");        PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");
                         PRINTR(vl,(R)ad[1].arg); PUTS("))");        PRINTR(vl,(R)ad[1].arg); PUTS("))");
                 } else if ( !pf->argc )      } else if ( !pf->argc )
                         PUTS(NAME(pf));        PUTS(NAME(pf));
                 else {      else {
                         if ( hideargs ) {        if ( hideargs ) {
                                 for ( i = 0; i < pf->argc; i++ )          for ( i = 0; i < pf->argc; i++ )
                                         if ( ad[i].d )            if ( ad[i].d )
                                                 break;              break;
                                 if ( i < pf->argc ) {          if ( i < pf->argc ) {
                                         PUTS(NAME(pf));            PUTS(NAME(pf));
                                         total_length += 11; /* XXX */            total_length += 11; /* XXX */
                                         for ( i = 1; i < pf->argc; i++ ) {            for ( i = 1; i < pf->argc; i++ ) {
                                                 total_length += 11; /* XXX */              total_length += 11; /* XXX */
                                         }            }
                                         PUTS("}");            PUTS("}");
                                 } else {          } else {
                                         PUTS(NAME(pf));            PUTS(NAME(pf));
                                         total_length += 1; /* XXX */            total_length += 1; /* XXX */
                                 }          }
                         } else {        } else {
                                 for ( i = 0; i < pf->argc; i++ )          for ( i = 0; i < pf->argc; i++ )
                                         if ( ad[i].d )            if ( ad[i].d )
                                                 break;              break;
                                 if ( i < pf->argc ) {          if ( i < pf->argc ) {
                                         PUTS(NAME(pf));            PUTS(NAME(pf));
                                         total_length += 11; /* XXX */            total_length += 11; /* XXX */
                                         for ( i = 1; i < pf->argc; i++ ) {            for ( i = 1; i < pf->argc; i++ ) {
                                                 total_length += 11; /* XXX */              total_length += 11; /* XXX */
                                         }            }
                                         PUTS(")(");            PUTS(")(");
                                 } else {          } else {
                                         PUTS(NAME(pf));            PUTS(NAME(pf));
                                         total_length += 1; /* XXX */            total_length += 1; /* XXX */
                                 }          }
                                 PRINTR(vl,(R)ad[0].arg);          PRINTR(vl,(R)ad[0].arg);
                                 for ( i = 1; i < pf->argc; i++ ) {          for ( i = 1; i < pf->argc; i++ ) {
                                         PUTS(","); PRINTR(vl,(R)ad[i].arg);            PUTS(","); PRINTR(vl,(R)ad[i].arg);
                                 }          }
                                 PUTS(")");          PUTS(")");
                         }        }
                 }      }
         }    }
 }  }
   
 void PRINTN(N n)  void PRINTN(N n)
 {  {
         double ceil();    double ceil();
   
         if ( !n )    if ( !n )
                 PUTS("0");      PUTS("0");
         else if ( hex_output )    else if ( hex_output )
                 total_length += 2+(int)(PL(n)*8);      total_length += 2+(int)(PL(n)*8);
         else    else
                 total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1);      total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1);
 }  }
   
 void PRINTSTR(STRING str)  void PRINTSTR(STRING str)
 {  {
         char *p;    char *p;
   
         for ( p = BDY(str); *p; p++ )    for ( p = BDY(str); *p; p++ )
                 if ( *p == '"' )      if ( *p == '"' )
                         PUTS("\"");        PUTS("\"");
                 else {      else {
                         total_length += 1;        total_length += 1;
                 }      }
 }  }
   
 void PRINTDP(VL vl,DP d)  void PRINTDP(VL vl,DP d)
 {  {
         int n,i;    int n,i;
         MP m;    MP m;
         DL dl;    DL dl;
   
         for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {    for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
                 PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");      PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
                 for ( i = 0, dl = m->dl; i < n-1; i++ ) {      for ( i = 0, dl = m->dl; i < n-1; i++ ) {
                         total_length += 11;        total_length += 11;
                 }      }
                 total_length += 10;      total_length += 10;
                 PUTS(">>");      PUTS(">>");
                 if ( NEXT(m) )      if ( NEXT(m) )
                         PUTS("+");        PUTS("+");
         }    }
 }  }
   
 void PRINTDPM(VL vl,DPM d)  void PRINTDPM(VL vl,DPM d)
 {  {
         int n,i;    int n,i;
         DMM m;    DMM m;
         DL dl;    DL dl;
   
         for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {    for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
                 PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");      PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
                 for ( i = 0, dl = m->dl; i < n-1; i++ ) {      for ( i = 0, dl = m->dl; i < n-1; i++ ) {
                         total_length += 11;        total_length += 11;
                 }      }
                 total_length += 10;      total_length += 10;
                 total_length += 11; /* for ':pos' */      total_length += 11; /* for ':pos' */
                 PUTS(">>");      PUTS(">>");
                 if ( NEXT(m) )      if ( NEXT(m) )
                         PUTS("+");        PUTS("+");
         }    }
 }  }
   
   
 void PRINTUI(VL vl,USINT u)  void PRINTUI(VL vl,USINT u)
 {  {
         total_length += 10;    total_length += 10;
 }  }
   
 void PRINTGFMMAT(VL vl,GFMMAT mat)  void PRINTGFMMAT(VL vl,GFMMAT mat)
 {  {
         int row,col,i,j;    int row,col,i,j;
         unsigned int **b;    unsigned int **b;
   
         row = mat->row;    row = mat->row;
         col = mat->col;    col = mat->col;
         b = mat->body;    b = mat->body;
         for ( i = 0; i < row; i++ ) {    for ( i = 0; i < row; i++ ) {
                 PUTS("[");      PUTS("[");
                 for ( j = 0; j < col; j++ ) {      for ( j = 0; j < col; j++ ) {
                         total_length += 10; /* XXX */        total_length += 10; /* XXX */
                 }      }
                 PUTS("]\n");      PUTS("]\n");
         }    }
 }  }
   
 void PRINTBYTEARRAY(VL vl,BYTEARRAY array)  void PRINTBYTEARRAY(VL vl,BYTEARRAY array)
 {  {
         /* |xx xx ... xx| */    /* |xx xx ... xx| */
         total_length += 1+3*array->len;    total_length += 1+3*array->len;
 }  }
   
 extern int print_quote;  extern int print_quote;
   
 void PRINTQUOTE(VL vl,QUOTE quote)  void PRINTQUOTE(VL vl,QUOTE quote)
 {  {
         LIST list;    LIST list;
   
         if ( print_quote == 2 ) {    if ( print_quote == 2 ) {
                 PRINTFNODE(BDY(quote),0);      PRINTFNODE(BDY(quote),0);
         } else if ( print_quote == 1 ) {    } else if ( print_quote == 1 ) {
                 /* XXX */      /* XXX */
                 fnodetotree(BDY(quote),&list);      fnodetotree(BDY(quote),&list);
                 PRINTEXPR(vl,(Obj)list);      PRINTEXPR(vl,(Obj)list);
         } else {    } else {
                 /* <...quoted...> */      /* <...quoted...> */
                 total_length += 20;      total_length += 20;
         }    }
 }  }
   
 void PRINTQUOTEARG(VL vl,QUOTEARG quote)  void PRINTQUOTEARG(VL vl,QUOTEARG quote)
 {  {
         /* XXX */    /* XXX */
         /* <...quoted...> */    /* <...quoted...> */
         total_length += 20;    total_length += 20;
 }  }
   
 void PRINTSYMBOL(SYMBOL sym)  void PRINTSYMBOL(SYMBOL sym)
 {  {
         total_length += strlen(sym->name);    total_length += strlen(sym->name);
 }  }
   
 void PRINTTB(VL vl,TB p)  void PRINTTB(VL vl,TB p)
 {  {
         int i;    int i;
   
         for ( i = 0; i < p->next; i++ ) {    for ( i = 0; i < p->next; i++ ) {
                 total_length += strlen(p->body[i]);      total_length += strlen(p->body[i]);
         }    }
 }  }
   
 void PRINTUP2(UP2 p)  void PRINTUP2(UP2 p)
 {  {
         int d,i;    int d,i;
   
         if ( !p ) {    if ( !p ) {
                 PUTS("0");      PUTS("0");
         } else {    } else {
                 d = degup2(p);      d = degup2(p);
                 PUTS("(");      PUTS("(");
                 if ( !d ) {      if ( !d ) {
                         PUTS("1");        PUTS("1");
                 } else if ( d == 1 ) {      } else if ( d == 1 ) {
                         PUTS("@");        PUTS("@");
                 } else {      } else {
                         PRINTHAT;        PRINTHAT;
                         total_length += 11;        total_length += 11;
                 }      }
                 for ( i = d-1; i >= 0; i-- ) {      for ( i = d-1; i >= 0; i-- ) {
                         if ( p->b[i/BSH] & (1<<(i%BSH)) )        if ( p->b[i/BSH] & (1<<(i%BSH)) )
                                 if ( !i ) {          if ( !i ) {
                                         PUTS("+1");            PUTS("+1");
                                 } else if ( i == 1 ) {          } else if ( i == 1 ) {
                                         PUTS("+@");            PUTS("+@");
                                 } else {          } else {
                                         PRINTHAT;            PRINTHAT;
                                         total_length += 12;            total_length += 12;
                                 }          }
                 }      }
                 PUTS(")");      PUTS(")");
         }    }
 }  }
   
 void PRINTQOP(VL vl,F f)  void PRINTQOP(VL vl,F f)
 {  {
         char *op;    char *op;
   
         op = FOP(f)==AL_EX?"ex":"all";    op = FOP(f)==AL_EX?"ex":"all";
         PUTS(op); PUTS(NAME(FQVR(f)));    PUTS(op); PUTS(NAME(FQVR(f)));
         total_length += 2;    total_length += 2;
         PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");    PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");
 }  }
   
 void PRINTUP(UP n)  void PRINTUP(UP n)
 {  {
         int i,d;    int i,d;
   
         if ( !n )    if ( !n )
                 PUTS("0");      PUTS("0");
         else if ( !n->d )    else if ( !n->d )
                 PRINTNUM(n->c[0]);      PRINTNUM(n->c[0]);
         else {    else {
                 d = n->d;      d = n->d;
                 PUTS("(");      PUTS("(");
                 if ( !d ) {      if ( !d ) {
                         PRINTNUM(n->c[d]);        PRINTNUM(n->c[d]);
                 } else if ( d == 1 ) {      } else if ( d == 1 ) {
                         PRINTNUM(n->c[d]);        PRINTNUM(n->c[d]);
                         PUTS("*@p");        PUTS("*@p");
                 } else {      } else {
                         PRINTNUM(n->c[d]);        PRINTNUM(n->c[d]);
                         PRINTHAT;        PRINTHAT;
                         total_length += 13;        total_length += 13;
                 }      }
                 for ( i = d-1; i >= 0; i-- ) {      for ( i = d-1; i >= 0; i-- ) {
                         if ( n->c[i] ) {        if ( n->c[i] ) {
                                 PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");          PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");
                                 if ( i >= 2 ) {          if ( i >= 2 ) {
                                         PRINTHAT;            PRINTHAT;
                                         total_length += 13;            total_length += 13;
                                 } else if ( i == 1 )          } else if ( i == 1 )
                                         PUTS("*@p");            PUTS("*@p");
                         }        }
                 }      }
                 PUTS(")");      PUTS(")");
         }    }
 }  }
   
 void PRINTUM(UM n)  void PRINTUM(UM n)
 {  {
         int i,d;    int i,d;
   
         if ( !n )    if ( !n )
                 PUTS("0");      PUTS("0");
         else if ( !n->d )    else if ( !n->d )
                 PRINTSF(n->c[0]);      PRINTSF(n->c[0]);
         else {    else {
                 d = n->d;      d = n->d;
                 PUTS("(");      PUTS("(");
                 if ( !d ) {      if ( !d ) {
                         PRINTSF(n->c[d]);        PRINTSF(n->c[d]);
                 } else if ( d == 1 ) {      } else if ( d == 1 ) {
                         PRINTSF(n->c[d]);        PRINTSF(n->c[d]);
                         PUTS("*@s");        PUTS("*@s");
                 } else {      } else {
                         PRINTSF(n->c[d]);        PRINTSF(n->c[d]);
                         PUTS("*@s"); PRINTHAT; total_length += 13;        PUTS("*@s"); PRINTHAT; total_length += 13;
                 }      }
                 for ( i = d-1; i >= 0; i-- ) {      for ( i = d-1; i >= 0; i-- ) {
                         if ( n->c[i] ) {        if ( n->c[i] ) {
                                 PUTS("+("); PRINTSF(n->c[i]); PUTS(")");          PUTS("+("); PRINTSF(n->c[i]); PUTS(")");
                                 if ( i >= 2 ) {          if ( i >= 2 ) {
                                         PUTS("*@s"); PRINTHAT; total_length += 13;            PUTS("*@s"); PRINTHAT; total_length += 13;
                                 } else if ( i == 1 )          } else if ( i == 1 )
                                         PUTS("*@s");            PUTS("*@s");
                         }        }
                 }      }
                 PUTS(")");      PUTS(")");
         }    }
 }  }
   
 void PRINTNBP(VL vl,NBP p)  void PRINTNBP(VL vl,NBP p)
 {  {
         NODE t;    NODE t;
         NBM m;    NBM m;
         int d,i;    int d,i;
         unsigned int *b;    unsigned int *b;
         if ( !p ) PUTS("0");    if ( !p ) PUTS("0");
         else {    else {
                 for ( t = BDY(p); t; t = NEXT(t) ) {      for ( t = BDY(p); t; t = NEXT(t) ) {
                         m = (NBM)BDY(t);        m = (NBM)BDY(t);
                         PRINTEXPR(vl,(Obj)m->c);        PRINTEXPR(vl,(Obj)m->c);
                         d = m->d;        d = m->d;
                         b = m->b;        b = m->b;
                         if ( d )        if ( d )
                                 for ( i = 0; i < d; i++ ) {          for ( i = 0; i < d; i++ ) {
                                         if ( NBM_GET(b,i) ) PUTS("x");            if ( NBM_GET(b,i) ) PUTS("x");
                                         else PUTS("y");            else PUTS("y");
                                 }          }
                         else PUTS("1");        else PUTS("1");
                         if ( NEXT(t) ) PUTS("+");        if ( NEXT(t) ) PUTS("+");
                 }      }
         }    }
 }  }
   
 void PRINTSF(unsigned int i)  void PRINTSF(unsigned int i)
 {  {
         if ( !i ) {    if ( !i ) {
                 PUTS("0");      PUTS("0");
         } else    } else
                 total_length += 15;      total_length += 15;
   
 #ifndef CPRINT  #ifndef CPRINT
 #define CPRINT  #define CPRINT

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>