[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.21 and 1.29

version 1.21, 2004/03/17 03:22:47 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.20 2004/03/17 02:23: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"
 #include "al.h"  #include "al.h"
 #include "base.h"  #include "base.h"
 #if PARI  
 #include "genpari.h"  
 #endif  
   
 #ifndef CPRINT  #ifndef CPRINT
 #define CPRINT  #define CPRINT
Line 80  static int total_length;
Line 77  static int total_length;
 #define PRINTSTR length_str  #define PRINTSTR length_str
 #define PRINTCOMP length_comp  #define PRINTCOMP length_comp
 #define PRINTDP length_dp  #define PRINTDP length_dp
   #define PRINTDPM length_dpm
 #define PRINTUI length_ui  #define PRINTUI length_ui
 #define PRINTGF2MAT length_gf2mat  #define PRINTGF2MAT length_gf2mat
 #define PRINTGFMMAT length_gfmmat  #define PRINTGFMMAT length_gfmmat
 #define PRINTBYTEARRAY length_bytearray  #define PRINTBYTEARRAY length_bytearray
 #define PRINTQUOTE length_QUOTE  #define PRINTQUOTE length_QUOTE
   #define PRINTQUOTEARG length_QUOTEARG
 #define PRINTSYMBOL length_SYMBOL  #define PRINTSYMBOL length_SYMBOL
 #define PRINTRANGE length_RANGE  #define PRINTRANGE length_RANGE
 #define PRINTTB length_TB  #define PRINTTB length_TB
   #define PRINTDPV length_DPV
   #define PRINTNBP length_nbp
 #define PRINTERR length_err  #define PRINTERR length_err
 #define PRINTLF length_lf  #define PRINTLF length_lf
 #define PRINTLOP length_lop  #define PRINTLOP length_lop
Line 109  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;
 }  }
   
 #if defined(PARI)  
 void PRINTBF(BF a)  void PRINTBF(BF a)
 {  {
         char *str;    char *str;
         char *GENtostr0();    int dprec;
         void myoutbrute();    char fbuf[BUFSIZ];
   
         if ( double_output ) {    dprec = a->body->_mpfr_prec*0.30103;
                 str = GENtostr0(a->body,myoutbrute);    sprintf(fbuf,"%%.%dR%c",dprec,double_output?'f':'g');
         } else {    mpfr_asprintf(&str,fbuf,a->body);
                 str = GENtostr(a->body);    total_length += strlen(str);
         }    mpfr_free_str(str);
         total_length += strlen(str);  
         free(str);  
 }  }
 #endif  
   
 void PRINTNUM(Num q)  void PRINTNUM(Num q)
 {  {
         if ( !q ) {    DAlg d;
                 PUTS("0");    DP nm;
                 return;    Q dn;
         }  
         switch ( NID(q) ) {    if ( !q ) {
                 case N_Q:      PUTS("0");
                         if ( SGN((Q)q) == -1 )      return;
                                 PUTS("-");    }
                         PRINTN(NM((Q)q));    switch ( NID(q) ) {
                         if ( !INT((Q)q) ) {      case N_Q:
                                 PUTS("/"); PRINTN(DN((Q)q));        if ( SGN((Q)q) == -1 )
                         }          PUTS("-");
                         break;        PRINTN(NM((Q)q));
                 case N_R:        if ( !INT((Q)q) ) {
                         if ( double_output )          PUTS("/"); PRINTN(DN((Q)q));
                                 total_length += 400+real_digit; /* XXX */        }
                         else        break;
                                 total_length += 20+real_digit; /* XXX */      case N_R:
                         break;        if ( double_output )
                 case N_A:          total_length += 400+real_digit; /* XXX */
                         PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");        else
                         break;          total_length += 20+real_digit; /* XXX */
 #if defined(PARI)        break;
                 case N_B:      case N_A:
                         PRINTBF((BF)q); break;        PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
 #endif        break;
                 case N_C:      case N_B:
                         PRINTCPLX((C)q); break;        PRINTBF((BF)q); break;
                 case N_M:      case N_C:
                         total_length += 11; /* XXX */        PRINTCPLX((C)q); break;
                         break;      case N_M:
                 case N_LM:        total_length += 11; /* XXX */
                         PRINTN(((LM)q)->body); break;        break;
                 case N_GF2N:      case N_LM:
                         if ( hex_output )        PRINTN(((LM)q)->body); break;
                                 PRINTN((N)(((GF2N)q)->body));      case N_GF2N:
                         else        if ( hex_output )
                                 PRINTUP2(((GF2N)q)->body);          PRINTN((N)(((GF2N)q)->body));
                         break;        else
                 case N_GFPN:          PRINTUP2(((GF2N)q)->body);
                         PRINTUP((UP)(((GFPN)q)->body));        break;
                         break;      case N_GFPN:
                 case N_GFS:        PRINTUP((UP)(((GFPN)q)->body));
                         total_length += 13; /* XXX */        break;
                         break;      case N_GFS:
                 case N_GFSN:        total_length += 13; /* XXX */
                         PRINTUM(BDY((GFSN)q));        break;
                         break;      case N_GFSN:
                 default:        PRINTUM(BDY((GFSN)q));
                         break;        break;
         }      case N_DA:
         d = (DAlg)q;
         nm = d->nm;
         dn = d->dn;
         if ( SGN((Q)dn) == -1 ) PUTS("-");
         PUTS("(");
         PRINTDP(CO,((DAlg)q)->nm);
         PUTS(")");
         if ( !UNIN(NM(dn)) ) {
           PUTS("/");
           PRINTN(NM(dn));
         }
         break;
       default:
         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)
   {
     int n,i;
     DMM m;
     DL dl;
   
     for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
       PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
       for ( i = 0, dl = m->dl; i < n-1; i++ ) {
         total_length += 11;
       }
       total_length += 10;
       total_length += 11; /* for ':pos' */
       PUTS(">>");
       if ( NEXT(m) )
         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)
   {
     /* XXX */
     /* <...quoted...> */
     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)
   {
     NODE t;
     NBM m;
     int d,i;
     unsigned int *b;
     if ( !p ) PUTS("0");
     else {
       for ( t = BDY(p); t; t = NEXT(t) ) {
         m = (NBM)BDY(t);
         PRINTEXPR(vl,(Obj)m->c);
         d = m->d;
         b = m->b;
         if ( d )
           for ( i = 0; i < d; i++ ) {
             if ( NBM_GET(b,i) ) PUTS("x");
             else PUTS("y");
           }
         else PUTS("1");
         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.21  
changed lines
  Added in v.1.29

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