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

Diff for /OpenXM_contrib2/asir2000/io/bsave.c between version 1.17 and 1.21

version 1.17, 2015/08/04 06:20:45 version 1.21, 2020/10/04 03:14:08
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/bsave.c,v 1.16 2009/03/16 16:43:03 ohara Exp $   * $OpenXM: OpenXM_contrib2/asir2000/io/bsave.c,v 1.20 2018/03/29 01:32:53 noro Exp $
 */  */
 /* saveXXX must not use GC_malloc(), GC_malloc_atomic(). */  /* saveXXX must not use GC_malloc(), GC_malloc_atomic(). */
   
 #include "ca.h"  #include "ca.h"
 #include "parse.h"  #include "parse.h"
 #include "com.h"  #include "com.h"
   #include "ox.h"
   
 void savenbp(FILE *s,NBP p);  void savenbp(FILE *s,NBP p);
   
 void (*savef[])() = { 0, savenum, savep, saver, savelist, savevect,  void (*savef[])() = { 0, savenum, savep, saver, savelist, savevect,
         savemat, savestring, 0, savedp, saveui, saveerror,0,0,0,savegfmmat,    savemat, savestring, 0, savedp, saveui, saveerror,0,0,0,savegfmmat,
         savebytearray, 0, 0, 0, 0, 0, 0, 0, 0,  savenbp };    savebytearray, 0, 0, 0, 0, 0, 0, 0, 0,  savenbp };
 #if defined(INTERVAL)  #if defined(INTERVAL)
 void saveitv();  void saveitv();
 void saveitvd();  void saveitvd();
Line 69  static short zeroval = 0;
Line 70  static short zeroval = 0;
   
 void saveobj(FILE *s,Obj p)  void saveobj(FILE *s,Obj p)
 {  {
         if ( !p )    if ( !p )
                 write_short(s,&zeroval);      write_short(s,&zeroval);
         else if ( !savef[OID(p)] )    else if ( !savef[OID(p)] )
                 error("saveobj : not implemented");      error("saveobj : not implemented");
         else    else
                 (*savef[OID(p)])(s,p);      (*savef[OID(p)])(s,p);
 }  }
   
 void savenum(FILE *s,Num p)  void savenum(FILE *s,Num p)
 {  {
         if ( !nsavef[NID(p)] )    if ( !nsavef[NID(p)] )
                 error("savenum : not implemented");      error("savenum : not implemented");
         else {    else {
                 write_short(s,&OID(p)); write_char(s,&NID(p));      write_short(s,&OID(p)); write_char(s,&NID(p));
                 write_char(s,&(p->pad));      write_char(s,&(p->pad));
                 (*nsavef[NID(p)])(s,p);      (*nsavef[NID(p)])(s,p);
         }    }
 }  }
   
 void saveq(FILE *s,Q p)  void saveq(FILE *s,Q p)
 {  {
         int size[2];    int size[2];
         int len = 2;    int len = 2;
   
         size[0] = PL(NM(p)); size[1] = DN(p) ? PL(DN(p)) : 0;    size[0] = PL(NM(p)); size[1] = DN(p) ? PL(DN(p)) : 0;
         write_intarray(s,size,len);    write_intarray(s,size,len);
         write_intarray(s,BD(NM(p)),size[0]);    write_intarray(s,BD(NM(p)),size[0]);
         if ( size[1] )    if ( size[1] )
                 write_intarray(s,BD(DN(p)),size[1]);      write_intarray(s,BD(DN(p)),size[1]);
 }  }
   
 void savereal(FILE *s,Real p)  void savereal(FILE *s,Real p)
Line 112  void savebf(FILE *s,BF p)
Line 113  void savebf(FILE *s,BF p)
 {  {
   unsigned int zero = 0;    unsigned int zero = 0;
   unsigned int prec;    unsigned int prec;
         L exp;    L exp;
   int sgn,len,t;    int sgn,len,t;
   
   prec = MPFR_PREC(p->body);    prec = MPFR_PREC(p->body);
   exp = MPFR_EXP(p->body);    exp = MPFR_EXP(p->body);
   sgn = MPFR_SIGN(p->body);    sgn = MPFR_SIGN(p->body);
         len = MPFR_LIMB_SIZE(p->body);    len = MPFR_LIMB_SIZE(p->body);
   
         write_int(s,&sgn);    write_int(s,&sgn);
         write_int(s,(int *)&prec);    write_int(s,(int *)&prec);
         write_int64(s,(UL *)&exp);    write_int64(s,(UL *)&exp);
   #if defined(VISUAL)
   #if !defined(_WIN64)
     write_int(s,&len);
     write_intarray(s,p->body->_mpfr_d,len);
   #else
     t = (prec+31)/32;
     write_int(s,&t);
     write_longarray(s,(long long *)p->body->_mpfr_d,t);
   #endif
   #else
 #if SIZEOF_LONG == 4  #if SIZEOF_LONG == 4
         write_int(s,&len);    write_int(s,&len);
         write_intarray(s,p->body->_mpfr_d,len);    write_intarray(s,p->body->_mpfr_d,len);
 #else /* SIZEOF_LONG == 8 */  #else /* SIZEOF_LONG == 8 */
         t = 2*len;    t = (prec+31)/32;
         write_int(s,&t);    write_int(s,&t);
         write_longarray(s,p->body->_mpfr_d,len);    write_longarray(s,p->body->_mpfr_d,t);
 #endif  #endif
   #endif
 }  }
   
 #if defined(INTERVAL)  #if defined(INTERVAL)
 void saveitv(FILE *s,Itv p)  void saveitv(FILE *s,Itv p)
 {  {
         saveobj(s,(Obj)INF(p));    saveobj(s,(Obj)INF(p));
         saveobj(s,(Obj)SUP(p));    saveobj(s,(Obj)SUP(p));
 }  }
   
 void saveitvd(FILE *s,IntervalDouble p)  void saveitvd(FILE *s,IntervalDouble p)
 {  {
         write_double(s,&INF(p));    write_double(s,&INF(p));
         write_double(s,&SUP(p));    write_double(s,&SUP(p));
 }  }
 #endif  #endif
   
Line 155  void savemi(FILE *s,MQ p)
Line 167  void savemi(FILE *s,MQ p)
   
 void savelm(FILE *s,LM p)  void savelm(FILE *s,LM p)
 {  {
         int size;    int size;
   
         size = PL(BDY(p));    size = PL(BDY(p));
         write_int(s,&size);    write_int(s,&size);
         write_intarray(s,BD(BDY(p)),size);    write_intarray(s,BD(BDY(p)),size);
 }  }
   
 void savegf2n(FILE *s,GF2N p)  void savegf2n(FILE *s,GF2N p)
 {  {
         int len;    int len;
   
         len = p->body->w;    len = p->body->w;
         write_int(s,&len);    write_int(s,&len);
         write_intarray(s,p->body->b,len);    write_intarray(s,p->body->b,len);
 }  }
   
 void savegfpn(FILE *s,GFPN p)  void savegfpn(FILE *s,GFPN p)
 {  {
         int d,i;    int d,i;
   
         d = p->body->d;    d = p->body->d;
         write_int(s,&d);    write_int(s,&d);
         for ( i = 0; i <= d; i++ )    for ( i = 0; i <= d; i++ )
                 saveobj(s,(Obj)p->body->c[i]);      saveobj(s,(Obj)p->body->c[i]);
 }  }
   
 void savegfs(FILE *s,GFS p)  void savegfs(FILE *s,GFS p)
Line 186  void savegfs(FILE *s,GFS p)
Line 198  void savegfs(FILE *s,GFS p)
   
 void savegfsn(FILE *s,GFSN p)  void savegfsn(FILE *s,GFSN p)
 {  {
         int d;    int d;
   
         d = DEG(BDY(p));    d = DEG(BDY(p));
         write_int(s,&d);    write_int(s,&d);
         write_intarray(s,COEF(BDY(p)),d+1);    write_intarray(s,COEF(BDY(p)),d+1);
 }  }
   
 void savedalg(FILE *s,DAlg p)  void savedalg(FILE *s,DAlg p)
 {  {
         saveobj(s,(Obj)p->nm);    saveobj(s,(Obj)p->nm);
         saveobj(s,(Obj)p->dn);    saveobj(s,(Obj)p->dn);
 }  }
   
 void savep(FILE *s,P p)  void savep(FILE *s,P p)
 {  {
         DCP dc;    DCP dc;
         int n;    int n;
         int vindex;    int vindex;
   
         if ( NUM(p) )    if ( NUM(p) )
                 savenum(s,(Num)p);      savenum(s,(Num)p);
         else {    else {
                 vindex = save_convv(VR(p));      vindex = save_convv(VR(p));
                 for ( dc = DC(p), n = 0; dc; dc = NEXT(dc), n++ );      for ( dc = DC(p), n = 0; dc; dc = NEXT(dc), n++ );
                 write_short(s,&OID(p));      write_short(s,&OID(p));
                 write_int(s,&vindex);      write_int(s,&vindex);
                 if ( vindex < 0 )      if ( vindex < 0 )
                         savepfins(s,VR(p));        savepfins(s,VR(p));
                 write_int(s,&n);      write_int(s,&n);
                 for ( dc = DC(p); dc; dc = NEXT(dc) ) {      for ( dc = DC(p); dc; dc = NEXT(dc) ) {
                         saveobj(s,(Obj)DEG(dc)); saveobj(s,(Obj)COEF(dc));        saveobj(s,(Obj)DEG(dc)); saveobj(s,(Obj)COEF(dc));
                 }      }
         }    }
 }  }
   
 /* save a pure function (v->attr = V_PF) */  /* save a pure function (v->attr = V_PF) */
Line 226  void savep(FILE *s,P p)
Line 238  void savep(FILE *s,P p)
   
 void savepfins(FILE *s,V v)  void savepfins(FILE *s,V v)
 {  {
         PFINS ins;    PFINS ins;
         PF pf;    PF pf;
         int argc,i;    int argc,i;
         int *darray;    int *darray;
   
         ins = (PFINS)v->priv;    ins = (PFINS)v->priv;
         pf = ins->pf;    pf = ins->pf;
         savestr(s,NAME(pf));    savestr(s,NAME(pf));
         argc = pf->argc;    argc = pf->argc;
         write_int(s,&argc);    write_int(s,&argc);
         darray = (int *)ALLOCA(argc*sizeof(int));    darray = (int *)ALLOCA(argc*sizeof(int));
         for ( i = 0; i < argc; i++ )    for ( i = 0; i < argc; i++ )
                 darray[i] = ins->ad[i].d;      darray[i] = ins->ad[i].d;
         write_intarray(s,darray,argc);    write_intarray(s,darray,argc);
         for ( i = 0; i < argc; i++ )    for ( i = 0; i < argc; i++ )
                 saveobj(s,ins->ad[i].arg);      saveobj(s,ins->ad[i].arg);
 }  }
   
 void saver(FILE *s,R p)  void saver(FILE *s,R p)
 {  {
         if ( !RAT(p) )    if ( !RAT(p) )
                 savep(s,(P)p);      savep(s,(P)p);
         else {    else {
                 write_short(s,&OID(p)); write_short(s,&p->reduced);      write_short(s,&OID(p)); write_short(s,&p->reduced);
                 savep(s,NM(p)); savep(s,DN(p));      savep(s,NM(p)); savep(s,DN(p));
         }    }
 }  }
   
 void savelist(FILE *s,LIST p)  void savelist(FILE *s,LIST p)
 {  {
         int n;    int n;
         NODE tn;    NODE tn;
   
         for ( tn = BDY(p), n = 0; tn; tn = NEXT(tn), n++ );    for ( tn = BDY(p), n = 0; tn; tn = NEXT(tn), n++ );
         write_short(s,&OID(p)); write_int(s,&n);    write_short(s,&OID(p)); write_int(s,&n);
         for ( tn = BDY(p); tn; tn = NEXT(tn) )    for ( tn = BDY(p); tn; tn = NEXT(tn) )
                 saveobj(s,(Obj)BDY(tn));      saveobj(s,(Obj)BDY(tn));
 }  }
   
 void savevect(FILE *s,VECT p)  void savevect(FILE *s,VECT p)
 {  {
         int i,len = 2;    int i,len = 2;
   
         write_short(s,&OID(p)); write_int(s,&p->len);    write_short(s,&OID(p)); write_int(s,&p->len);
         for ( i = 0, len = p->len; i < len; i++ )    for ( i = 0, len = p->len; i < len; i++ )
                 saveobj(s,(Obj)BDY(p)[i]);      saveobj(s,(Obj)BDY(p)[i]);
 }  }
   
 void savemat(FILE *s,MAT p)  void savemat(FILE *s,MAT p)
 {  {
         int i,j,row,col;    int i,j,row,col;
         int len = 3;    int len = 3;
   
         write_short(s,&OID(p)); write_int(s,&p->row); write_int(s,&p->col);    write_short(s,&OID(p)); write_int(s,&p->row); write_int(s,&p->col);
         for ( i = 0, row = p->row, col = p->col; i < row; i++ )    for ( i = 0, row = p->row, col = p->col; i < row; i++ )
                 for ( j = 0; j < col; j++ )      for ( j = 0; j < col; j++ )
                         saveobj(s,(Obj)BDY(p)[i][j]);        saveobj(s,(Obj)BDY(p)[i][j]);
 }  }
   
 void savestring(FILE *s,STRING p)  void savestring(FILE *s,STRING p)
 {  {
         write_short(s,&OID(p)); savestr(s,BDY(p));    write_short(s,&OID(p)); savestr(s,BDY(p));
 }  }
   
 void savestr(FILE *s,char *p)  void savestr(FILE *s,char *p)
 {  {
         int size;    int size;
   
         size = p ? strlen(p) : 0; write_int(s,&size);    size = p ? strlen(p) : 0; write_int(s,&size);
         if ( size )    if ( size )
                 write_string(s,p,size);      write_string(s,p,size);
 }  }
   
 void savedp(FILE *s,DP p)  void savedp(FILE *s,DP p)
 {  {
         int nv,n,i,sugar;    int nv,n,i,sugar;
         MP m,t;    MP m,t;
   
         nv = p->nv; m = p->body; sugar = p->sugar;    nv = p->nv; m = p->body; sugar = p->sugar;
         for ( n = 0, t = m; t; t = NEXT(t), n++ );    for ( n = 0, t = m; t; t = NEXT(t), n++ );
         write_short(s,&OID(p)); write_int(s,&nv); write_int(s,&sugar); write_int(s,&n);    write_short(s,&OID(p)); write_int(s,&nv); write_int(s,&sugar); write_int(s,&n);
         for ( i = 0, t = m; i < n; i++, t = NEXT(t) ) {    for ( i = 0, t = m; i < n; i++, t = NEXT(t) ) {
                 saveobj(s,(Obj)t->c);      saveobj(s,(Obj)t->c);
                 write_int(s,&t->dl->td); write_intarray(s,&(t->dl->d[0]),nv);      write_int(s,&t->dl->td); write_intarray(s,&(t->dl->d[0]),nv);
         }    }
 }  }
   
 void saveui(FILE *s,USINT u)  void saveui(FILE *s,USINT u)
 {  {
         write_short(s,&OID(u)); write_int(s,&BDY(u));    write_short(s,&OID(u)); write_int(s,&BDY(u));
 }  }
   
 void saveerror(FILE *s,ERR e)  void saveerror(FILE *s,ERR e)
 {  {
         write_short(s,&OID(e)); saveobj(s,(Obj)BDY(e));    write_short(s,&OID(e)); saveobj(s,(Obj)BDY(e));
 }  }
   
 void savegfmmat(FILE *s,GFMMAT p)  void savegfmmat(FILE *s,GFMMAT p)
 {  {
         int i,row,col;    int i,row,col;
   
         write_short(s,&OID(p)); write_int(s,&p->row); write_int(s,&p->col);    write_short(s,&OID(p)); write_int(s,&p->row); write_int(s,&p->col);
         for ( i = 0, row = p->row, col = p->col; i < row; i++ )    for ( i = 0, row = p->row, col = p->col; i < row; i++ )
                 write_intarray(s,p->body[i],col);      write_intarray(s,p->body[i],col);
 }  }
   
 void savebytearray(FILE *s,BYTEARRAY p)  void savebytearray(FILE *s,BYTEARRAY p)
 {  {
         write_short(s,&OID(p)); write_int(s,&p->len);    write_short(s,&OID(p)); write_int(s,&p->len);
         write_string(s,p->body,p->len);    write_string(s,p->body,p->len);
 }  }
   
 void savenbp(FILE *s,NBP p)  void savenbp(FILE *s,NBP p)
 {  {
         int i,n;    int i,n;
         NODE t;    NODE t;
         NBM m;    NBM m;
   
         write_short(s,&OID(p));    write_short(s,&OID(p));
         for ( n = 0, t = BDY(p); t; t = NEXT(t), n++ );    for ( n = 0, t = BDY(p); t; t = NEXT(t), n++ );
         write_int(s,&n);    write_int(s,&n);
         for ( i = 0, t = BDY(p); i < n; t = NEXT(t), i++ ) {    for ( i = 0, t = BDY(p); i < n; t = NEXT(t), i++ ) {
                 m = (NBM)BDY(t);      m = (NBM)BDY(t);
                 saveobj(s,(Obj)m->c);      saveobj(s,(Obj)m->c);
                 write_int(s,&m->d);      write_int(s,&m->d);
                 write_intarray(s,m->b,(m->d+31)/32);      write_intarray(s,m->b,(m->d+31)/32);
         }    }
 }  }

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.21

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