[BACK]Return to cmo.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / plugin

Diff for /OpenXM/src/kan96xx/plugin/cmo.c between version 1.1.1.1 and 1.14

version 1.1.1.1, 1999/10/08 02:12:05 version 1.14, 2013/11/06 06:23:24
Line 1 
Line 1 
   /*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.13 2005/06/16 05:07:24 takayama Exp $*/
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
 #include <netinet/in.h>  /* #include <netinet/in.h> */
 #include <stdlib.h>  #include <stdlib.h>
 #include "datatype.h"  #include "datatype.h"
 #include "stackm.h"  #include "stackm.h"
Line 15 
Line 16 
 #include "cmo.h"  #include "cmo.h"
   
 #include "cmotag.htmp"   /* static char *cmotagToName(int tag) is defined  #include "cmotag.htmp"   /* static char *cmotagToName(int tag) is defined
                             here. */                              here. */
   
 extern int OxVersion;  extern int OxVersion;
   
 int CmoClientMode = 1;  /* This flag is used to translate names for  int CmoClientMode = 1;  /* This flag is used to translate names for
                            indeterminates.                 indeterminates.
                            It does not work well if ox_sm1 have a server, i.e.,                 It does not work well if ox_sm1 have a server, i.e.,
                            sm1 --> ox_sm1 --> ox_sm1                 sm1 --> ox_sm1 --> ox_sm1
                            */                 */
   
 /* void *malloc(int s);  /* void *malloc(int s);
   #define GC_malloc(x) malloc(x) */    #define GC_malloc(x) malloc(x) */
Line 36  int CmoClientMode = 1;  /* This flag is used to transl
Line 37  int CmoClientMode = 1;  /* This flag is used to transl
 **************************************************************************/  **************************************************************************/
 /*  If you change the format of mathcap, do the follows.  /*  If you change the format of mathcap, do the follows.
     Mofify  cmoCheckMathCap in oxmisc2.c,      Mofify  cmoCheckMathCap in oxmisc2.c,
     oxReq, SM_setMathCap:, and              oxSendMathCap  in oxmisc.c,
           newMathCap in cmo.c,
       oxReq, SM_setMathCap: in oxmisc2.c, and
     grep mathCap and make all modifications.      grep mathCap and make all modifications.
 */  */
   
Line 44  extern struct ring *CurrentRingp;
Line 47  extern struct ring *CurrentRingp;
 extern struct ring *SmallRingp;  extern struct ring *SmallRingp;
 extern int CmoDMSOutputOption;  extern int CmoDMSOutputOption;
   
 struct object NullObjectInCmo;  struct object NullObjectInCmo = OINIT;
   
 extern int SerialCurrent;  extern int SerialCurrent;
 extern int DebugCMO;  extern int DebugCMO;
Line 86  struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat
Line 89  struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat
       break;        break;
     case CMOPUT:      case CMOPUT:
       for (i=0; i<size; i++) {        for (i=0; i<size; i++) {
         fp2fputc(((char *)data)[i], b.fp);          fp2fputc((int) ((char *)data)[i], b.fp);
       }        }
       break;        break;
     case CMOFLUSH:      case CMOFLUSH:
       if (fp2fflush(b.fp)<0) {        if (fp2fflush(b.fp)<0) {
         errorCmo("cmoOutputToBuf: CMOFLUSH failed in stream mode.");          errorCmo("cmoOutputToBuf: CMOFLUSH failed in stream mode.");
       }        }
       cb = (struct cmoBuffer *)sGC_malloc(sizeof(struct cmoBuffer));        cb = (struct cmoBuffer *)sGC_malloc(sizeof(struct cmoBuffer));
       cb->isStream = b.isStream;        cb->isStream = b.isStream;
Line 125  struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat
Line 128  struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat
       break;        break;
     case CMOPUT:      case CMOPUT:
       if (b.pos + size >= b.size) {        if (b.pos + size >= b.size) {
         tmp = sGC_malloc((b.size)*2+size);          tmp = sGC_malloc((b.size)*2+size);
         memcpy(tmp,b.buf,b.pos);          memcpy(tmp,b.buf,b.pos);
         b.buf = tmp;          b.buf = tmp;
         b.size = (b.size)*2+size;          b.size = (b.size)*2+size;
       }        }
       memcpy((void *) &(((char *)(b.buf))[b.pos]),data,size);        memcpy((void *) &(((char *)(b.buf))[b.pos]),data,size);
       b.pos += size;        b.pos += size;
Line 159  dumpCmoBuf(struct cmoBuffer *cb)
Line 162  dumpCmoBuf(struct cmoBuffer *cb)
   char *s;    char *s;
   if (cb->isStream) {    if (cb->isStream) {
     printf("cmoBuffer is directed to a stream.\n");      printf("cmoBuffer is directed to a stream.\n");
     return;      return 0;
   }    }
   size = cb->pos;    size = cb->pos;
   s = (char *)(cb->buf);    s = (char *)(cb->buf);
Line 170  dumpCmoBuf(struct cmoBuffer *cb)
Line 173  dumpCmoBuf(struct cmoBuffer *cb)
     printf("%3x",(int)(unsigned char)s[i]);      printf("%3x",(int)(unsigned char)s[i]);
   }    }
   putchar('\n');    putchar('\n');
     return 0;
 }  }
   
 /* This obsolete function is used to write data  /* This obsolete function is used to write data
Line 195  cmoToStream(struct object cmoObj,struct object of)
Line 199  cmoToStream(struct object cmoObj,struct object of)
   s = (char *)(cb->buf);    s = (char *)(cb->buf);
   for (i=0; i<size; i++) {    for (i=0; i<size; i++) {
     if (file2) {      if (file2) {
       fp2fputc(s[i],(FILE2 *)(of.rc.voidp));        fp2fputc((int) s[i],(FILE2 *)(of.rc.voidp));
     }else{      }else{
       fputc(s[i],of.rc.file);        fputc((int) s[i],of.rc.file);
     }      }
   }    }
 }  }
Line 210  struct object streamToCmo(struct object of)
Line 214  struct object streamToCmo(struct object of)
 {  {
   int c;    int c;
   unsigned char s[1];    unsigned char s[1];
   struct object ob;    struct object ob = OINIT;
   int file2 = 0;    int file2 = 0;
   if (of.tag == Sfile) {    if (of.tag == Sfile) {
   
Line 374  int cmoOutRingDefinition(struct ring *rp,int option)
Line 378  int cmoOutRingDefinition(struct ring *rp,int option)
     cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)*3);      cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)*3);
     cmoOutInt32((rp->n)*2); /* number of variables */      cmoOutInt32((rp->n)*2); /* number of variables */
     cmoOutInt32(rp->p);     /* coefficient field.      cmoOutInt32(rp->p);     /* coefficient field.
                                CMO_INT32 or CMO_DMS_OF_N_VARIABLES */                                 CMO_INT32 or CMO_DMS_OF_N_VARIABLES */
     /* Optional arguments are  name of variables, weight_vector, output_order */      /* Optional arguments are  name of variables, weight_vector, output_order */
     break;      break;
   default:   /* including 0. */    default:   /* including 0. */
Line 400  int cmoOutRingDefinition2(struct ring *rp,int option)
Line 404  int cmoOutRingDefinition2(struct ring *rp,int option)
     cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)*3);      cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)*3);
     cmoOutInt32((rp->n)*2); /* number of variables */      cmoOutInt32((rp->n)*2); /* number of variables */
     cmoOutInt32(rp->p);     /* coefficient field.      cmoOutInt32(rp->p);     /* coefficient field.
                                CMO_INT32 or CMO_DMS_OF_N_VARIABLES */                                 CMO_INT32 or CMO_DMS_OF_N_VARIABLES */
     /* Optional arguments are  list of indeterminates (name of variables),      /* Optional arguments are  list of indeterminates (name of variables),
        weight_vector by list , output_order by list. */         weight_vector by list , output_order by list. */
     break;      break;
Line 422  int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb)
Line 426  int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb)
     switch(a) {      switch(a) {
     case CMOGET:      case CMOGET:
       for (i=0; i<4; i++) {        for (i=0; i<4; i++) {
         cc = fp2fgetc(cb->fp);          cc = fp2fgetc(cb->fp);
         if (cc < 0) {          if (cc < 0) {
           return(-1);            return(-1);
           errorCmo("cmoGetIntFromBuf CMOGET: unexpected EOF.\n");            errorCmo("cmoGetIntFromBuf CMOGET: unexpected EOF.\n");
         }          }
         data[i] = cc;          data[i] = cc;
       }        }
       return( (int) ntohl( *((cmoint *) data) ));        return( (int) ntohl( *((cmoint *) data) ));
       break;        break;
     case CMOGETBYTE:      case CMOGETBYTE:
       cc = fp2fgetc(cb->fp);        cc = fp2fgetc(cb->fp);
       if (cc < 0) {        if (cc < 0) {
         return(-1);          return(-1);
         errorCmo("cmoGetIntFromBuf CMOGETBYTE: unexpected EOF.\n");          errorCmo("cmoGetIntFromBuf CMOGETBYTE: unexpected EOF.\n");
       }        }
       return(cc);        return(cc);
       break;        break;
Line 459  int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb)
Line 463  int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb)
     switch(a) {      switch(a) {
     case CMOGET:      case CMOGET:
       if (cb->rpos + sizeof(cmoint) > cb->pos) {        if (cb->rpos + sizeof(cmoint) > cb->pos) {
         fprintf(stderr,"No more data in the buffer. Returns -1.\n");          fprintf(stderr,"No more data in the buffer. Returns -1.\n");
         return(-1);          return(-1);
       }        }
       memcpy(tmp,(void *) &(((char *)(cb->buf))[cb->rpos]),        memcpy(tmp,(void *) &(((char *)(cb->buf))[cb->rpos]),
              sizeof(cmoint));               sizeof(cmoint));
       cb->rpos += sizeof(cmoint);        cb->rpos += sizeof(cmoint);
       return( (int) ntohl(tmp[0]));        return( (int) ntohl(tmp[0]));
       break;        break;
     case CMOGETBYTE:      case CMOGETBYTE:
       if (cb->rpos + 1 > cb->pos) {        if (cb->rpos + 1 > cb->pos) {
         fprintf(stderr,"No more data in the buffer. Returns -1.\n");          fprintf(stderr,"No more data in the buffer. Returns -1.\n");
         return(-1);          return(-1);
       }        }
       tmp[0] = ((unsigned char *)(cb->buf))[cb->rpos];        tmp[0] = ((unsigned char *)(cb->buf))[cb->rpos];
       cb->rpos += 1;        cb->rpos += 1;
Line 541  POLY cmoGetMonomial32(struct cmoBuffer *cb)
Line 545  POLY cmoGetMonomial32(struct cmoBuffer *cb)
     warningCmo("cmoGetMonomials32(): Changed the current ring, because your peer sent a DMS that does not fit to the current ring.");      warningCmo("cmoGetMonomials32(): Changed the current ring, because your peer sent a DMS that does not fit to the current ring.");
   
     /* original code.      /* original code.
     skip = nn - (CurrentRingp->n)*2;         skip = nn - (CurrentRingp->n)*2;
     nn1 = nn0 = CurrentRingp->n;         nn1 = nn0 = CurrentRingp->n;
     if (! (cb->errorno) ) {         if (! (cb->errorno) ) {
       warningCmo("cmoGetMonomial32(): serialized polynomial \\not\\in CurrentRing.");         warningCmo("cmoGetMonomial32(): serialized polynomial \\not\\in CurrentRing.");
     }         }
     cmoGetIntFromBuf(CMOERROR,cb);         cmoGetIntFromBuf(CMOERROR,cb);
     */      */
   }    }
   if (nn == (CurrentRingp->n)*2 ) {    if (nn == (CurrentRingp->n)*2 ) {
Line 622  POLY cmoGetMonomial32(struct cmoBuffer *cb)
Line 626  POLY cmoGetMonomial32(struct cmoBuffer *cb)
 /* ------------------------------------- */  /* ------------------------------------- */
 void cmoObjectToCmo00(struct object ob)  void cmoObjectToCmo00(struct object ob)
 {  {
   struct object rob;    struct object rob = OINIT;
   cmoint tmp[16];    cmoint tmp[16];
   char tmpc[16];    char tmpc[16];
   int i,size;    int i,size;
   struct object vlist, vlist0;    struct object vlist = OINIT;
     struct object vlist0 = OINIT;
   int m;    int m;
   struct object ob2;    struct object ob2 = OINIT;
   
   /* NO initialization */    /* NO initialization */
   switch(ob.tag) {    switch(ob.tag) {
Line 657  void cmoObjectToCmo00(struct object ob)
Line 662  void cmoObjectToCmo00(struct object ob)
   case SuniversalNumber:    case SuniversalNumber:
     cmoOutGMPCoeff(ob.lc.universalNumber->val.bigp);      cmoOutGMPCoeff(ob.lc.universalNumber->val.bigp);
     break;      break;
     case SrationalFunction:
       tmp[0] = htonl(CMO_RATIONAL);
       cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
           cmoObjectToCmo00(*(Knumerator(ob)));
           cmoObjectToCmo00(*(Kdenominator(ob)));
       break;
   case Sdouble:    case Sdouble:
     if (sizeof(double) != 8) errorCmo("double is assumed to be 8 bytes.");      if (sizeof(double) != 8) errorCmo("double is assumed to be 8 bytes.");
     cmoOutRawInt(CMO_64BIT_MACHINE_DOUBLE);      cmoOutRawInt(CMO_64BIT_MACHINE_DOUBLE);
Line 668  void cmoObjectToCmo00(struct object ob)
Line 679  void cmoObjectToCmo00(struct object ob)
     case CLASSNAME_ERROR_PACKET:      case CLASSNAME_ERROR_PACKET:
       /* fprintf(stderr,"ectag=%d\n",ectag(*KopErrorPacket(ob)));  **kxx:CMO_ERROR*/        /* fprintf(stderr,"ectag=%d\n",ectag(*KopErrorPacket(ob)));  **kxx:CMO_ERROR*/
       if (ectag(*KopErrorPacket(ob)) == CLASSNAME_ERROR_PACKET) {        if (ectag(*KopErrorPacket(ob)) == CLASSNAME_ERROR_PACKET) {
         tmp[0] = htonl(CMO_ERROR);          tmp[0] = htonl(CMO_ERROR);
         cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));          cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
       }else{        }else{
         tmp[0] = htonl(CMO_ERROR2);          tmp[0] = htonl(CMO_ERROR2);
         cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));          cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
         /* Send without OX_DATA header !! */          /* Send without OX_DATA header !! */
         cmoObjectToCmo00(*(KopErrorPacket(ob)));          cmoObjectToCmo00(*(KopErrorPacket(ob)));
       }        }
       break;        break;
     case CLASSNAME_mathcap:      case CLASSNAME_mathcap:
Line 689  void cmoObjectToCmo00(struct object ob)
Line 700  void cmoObjectToCmo00(struct object ob)
       /* cmoObjectToCmo00(KopIndeterminate(ob)); Old code. */        /* cmoObjectToCmo00(KopIndeterminate(ob)); Old code. */
       /* If you need to translate the name, do it here. */        /* If you need to translate the name, do it here. */
       if (CmoClientMode) {        if (CmoClientMode) {
         ob = KopIndeterminate(ob);          ob = KopIndeterminate(ob);
       }else{        }else{
         ob = cmoTranslateVariable_outGoing(KopIndeterminate(ob));          ob = cmoTranslateVariable_outGoing(KopIndeterminate(ob));
       }        }
       cmoObjectToCmo00(ob);        cmoObjectToCmo00(ob);
       break;        break;
     case CLASSNAME_recursivePolynomial:      case CLASSNAME_recursivePolynomial:
       /* We assume that the format of the recursive polynomial        /* We assume that the format of the recursive polynomial
          is OK. */           is OK. */
       tmp[0] = htonl(CMO_RECURSIVE_POLYNOMIAL);        tmp[0] = htonl(CMO_RECURSIVE_POLYNOMIAL);
       cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));        cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
       ob = KopRecursivePolynomial(ob);        ob = KopRecursivePolynomial(ob);
       vlist = getoa(ob,0);        vlist = getoa(ob,0);
       vlist0 = newObjectArray(getoaSize(vlist));        vlist0 = newObjectArray(getoaSize(vlist));
       for (i=0; i<getoaSize(vlist); i++) {        for (i=0; i<getoaSize(vlist); i++) {
         if (CmoClientMode) {          if (getoa(vlist,i).tag == Sdollar) {
           putoa(vlist0,i,            if (CmoClientMode) {
                 KpoIndeterminate(getoa(vlist,i)));              putoa(vlist0,i,
         }else{                    KpoIndeterminate(getoa(vlist,i)));
           putoa(vlist0,i,            }else{
                 KpoIndeterminate(cmoTranslateVariable_outGoing(getoa(vlist,i))));              putoa(vlist0,i,
         }                    KpoIndeterminate(cmoTranslateVariable_outGoing(getoa(vlist,i))));
             }
           }else{
             putoa(vlist0,i,getoa(vlist,i));
           }
       }        }
       cmoObjectToCmo00(vlist0); /* output the list of variables. */        cmoObjectToCmo00(vlist0); /* output the list of variables. */
       cmoObjectToCmo00(getoa(ob,1)); /* output the body of the recursive poly        cmoObjectToCmo00(getoa(ob,1)); /* output the body of the recursive poly
                               polynomial in one variable or any object*/                                          polynomial in one variable or any object*/
       break;        break;
     case CLASSNAME_polynomialInOneVariable:      case CLASSNAME_polynomialInOneVariable:
       tmp[0] = htonl(CMO_POLYNOMIAL_IN_ONE_VARIABLE);        tmp[0] = htonl(CMO_POLYNOMIAL_IN_ONE_VARIABLE);
       cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));        cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
       ob = KopPolynomialInOneVariable(ob);        ob = KopPolynomialInOneVariable(ob);
       if (ob.tag != Sarray) {        if (ob.tag != Sarray) {
         cmoObjectToCmo00(ob);          cmoObjectToCmo00(ob);
       }else{        }else{
         /* We do not check the format. */          /* We do not check the format. */
         m = (getoaSize(ob)-1)/2; /* the number of monomials */          m = (getoaSize(ob)-1)/2; /* the number of monomials */
         cmoOutRawInt(m);          cmoOutRawInt(m);
         ob2 = getoa(ob,0);       /* the variable name by integer. */          ob2 = getoa(ob,0);       /* the variable name by integer. */
         if (ob2.tag != Sinteger) {          if (ob2.tag != Sinteger) {
           warningCmo("cmoObjectToCmo00(): polynomial in one variable: this field should be integer. Output 0");            warningCmo("cmoObjectToCmo00(): polynomial in one variable: this field should be integer. Output 0");
           /* cmoOutInt32(0); */            /* cmoOutInt32(0); */
           cmoOutRawInt(0);            cmoOutRawInt(0);
         }else{          }else{
           /* cmoObjectToCmo00(ob2); */            /* cmoObjectToCmo00(ob2); */
           cmoOutRawInt(KopInteger(ob2));            cmoOutRawInt(KopInteger(ob2));
         }          }
         for (i=1; i<getoaSize(ob); i = i+2) {          for (i=1; i<getoaSize(ob); i = i+2) {
           cmoOutRawInt(KopInteger(getoa(ob,i)));  /* exponent */            cmoOutRawInt(KopInteger(getoa(ob,i)));  /* exponent */
           cmoObjectToCmo00(getoa(ob,i+1));          /* coefficient */            cmoObjectToCmo00(getoa(ob,i+1));          /* coefficient */
         }          }
       }        }
       break;        break;
     case CLASSNAME_tree:      case CLASSNAME_tree:
Line 764  void cmoObjectToCmo00(struct object ob)
Line 779  void cmoObjectToCmo00(struct object ob)
   
 struct object cmoObjectToCmo(struct object ob)  struct object cmoObjectToCmo(struct object ob)
 {  {
   struct object rob;    struct object rob = OINIT;
   if (DebugCMO) {    if (DebugCMO) {
     fprintf(stderr,"cmoObjectToCmo: ");      fprintf(stderr,"cmoObjectToCmo: ");
     printObject(ob,1,stderr);      printObject(ob,1,stderr);
Line 792  int Lisplike = 0;  
Line 807  int Lisplike = 0;  
   
 struct object cmoCmoToObject00(struct cmoBuffer *cb)  struct object cmoCmoToObject00(struct cmoBuffer *cb)
 {  {
   struct object rob;    struct object rob = OINIT;
   struct object ob1;    struct object ob1 = OINIT;
   struct object ob2;    struct object ob2 = OINIT;
   int tt,ival;    int tt,ival;
   int i,size;    int i,size;
   MP_INT *mi;    MP_INT *mi;
   MP_INT *mi2;    MP_INT *mi2;
   struct ring *oldringp;    struct ring *oldringp;
   char tmpc[16];    char tmpc[16];
   struct object vlist, vlist0;    struct object vlist = OINIT;
     struct object vlist0 = OINIT;
   int k;    int k;
   int m;    int m;
   struct object ob;    struct object ob = OINIT;
   
   
   tt = cmoGetIntFromBuf(CMOGET,cb); /* read the tag */    tt = cmoGetIntFromBuf(CMOGET,cb); /* read the tag */
Line 854  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 870  struct object cmoCmoToObject00(struct cmoBuffer *cb)
       putoa(rob,i,cmoCmoToObject00(cb));        putoa(rob,i,cmoCmoToObject00(cb));
       /* printObject(getoa(rob,i),0,stdout); */        /* printObject(getoa(rob,i),0,stdout); */
       if (i==0) {        if (i==0) {
         ob1 = getoa(rob,0);          ob1 = getoa(rob,0);
         if (ob1.tag == CMO+CMO_DMS) {          if (ob1.tag == CMO+CMO_DMS) {
           goto dmscase ;            goto dmscase ;
         }          }
       }        }
     }      }
     break;      break;
Line 876  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 892  struct object cmoCmoToObject00(struct cmoBuffer *cb)
       /* Change the CurrentRingp by looking up the name. */        /* Change the CurrentRingp by looking up the name. */
       ob1 = KfindUserDictionary(KopString(ob1));        ob1 = KfindUserDictionary(KopString(ob1));
       if (ob1.tag != Sring) {        if (ob1.tag != Sring) {
         errorCmo("cmoCmoToObject00(): your ring is not defined in the name space.");          errorCmo("cmoCmoToObject00(): your ring is not defined in the name space.");
       }        }
       CurrentRingp = KopRingp(ob1);        CurrentRingp = KopRingp(ob1);
     }      }
Line 953  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 969  struct object cmoCmoToObject00(struct cmoBuffer *cb)
     for (i=0; i<getoaSize(vlist0); i++) {      for (i=0; i<getoaSize(vlist0); i++) {
       ob1 = getoa(vlist0,i);        ob1 = getoa(vlist0,i);
       if (ectag(ob1) == CLASSNAME_indeterminate) {        if (ectag(ob1) == CLASSNAME_indeterminate) {
         ob1 = KopIndeterminate(ob1);          ob1 = KopIndeterminate(ob1);
         }else if (ectag(ob1) == CLASSNAME_tree) {
           /* do nothing. */
       }        }
       putoa(vlist,i,ob1);        putoa(vlist,i,ob1);
     }      }
Line 1002  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 1020  struct object cmoCmoToObject00(struct cmoBuffer *cb)
     }else{      }else{
       ob1 = getoa(rob,0);        ob1 = getoa(rob,0);
       if (ob1.tag != Sdollar) warningCmo("CMO_TREE : the first arg must be the node name by a string.");        if (ob1.tag != Sdollar) warningCmo("CMO_TREE : the first arg must be the node name by a string.");
       ob2 = getoa(rob,1); /* content dictionary name. */        ob2 = getoa(rob,1); /* Attribute List */
       if (ob2.tag != Sdollar) warningCmo("CMO_TREE : the second arg must be the node name by a string.");        if (ob2.tag != Sarray) warningCmo("CMO_TREE : the second arg must be a list of attributes.");
       rob = KpoTree(rob);        rob = KpoTree(rob);
     }      }
     break;      break;
Line 1049  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 1067  struct object cmoCmoToObject00(struct cmoBuffer *cb)
   
 struct object cmoCmoToObject(struct object ob)  struct object cmoCmoToObject(struct object ob)
 {  {
   struct object rob;    struct object rob = OINIT;
   struct object ob0;    struct object ob0 = OINIT;
   struct cmoBuffer *cb;    struct cmoBuffer *cb;
   if (!(ob.tag == Sclass && ob.lc.ival == CMO)) {    if (!(ob.tag == Sclass && ob.lc.ival == CMO)) {
     rob.tag = Snull;      rob.tag = Snull;
Line 1074  struct object cmoCmoToObject(struct object ob)
Line 1092  struct object cmoCmoToObject(struct object ob)
 }  }
   
 struct object cmoListToPoly(struct object ob) {  struct object cmoListToPoly(struct object ob) {
   struct object ob0;    struct object ob0 = OINIT;
   struct object rob;    struct object rob = OINIT;
   int i,n;    int i,n;
   if (ob.tag == Sarray) {    if (ob.tag == Sarray) {
     n = getoaSize(ob);      n = getoaSize(ob);
     if (n >= 1) {      if (n >= 1) {
       ob0 = getoa(ob,0);        ob0 = getoa(ob,0);
       if (ob0.tag == CMO+CMO_DMS) {        if (ob0.tag == CMO+CMO_DMS) {
         rob = KpoPOLY(cmoListToPOLY(ob)); /* not ToPoly, ToPOLY */          rob = KpoPOLY(cmoListToPOLY(ob)); /* not ToPoly, ToPOLY */
       }else{        }else{
         rob = newObjectArray(n);          rob = newObjectArray(n);
         for (i=0; i<n; i++) {          for (i=0; i<n; i++) {
           putoa(rob,i,cmoListToPoly(getoa(ob,i)));            putoa(rob,i,cmoListToPoly(getoa(ob,i)));
         }          }
       }        }
     }else{      }else{
       rob = ob;        rob = ob;
Line 1101  struct object cmoListToPoly(struct object ob) {
Line 1119  struct object cmoListToPoly(struct object ob) {
 struct object cmoListToPoly2(struct object ob)  struct object cmoListToPoly2(struct object ob)
 {  {
   int size,i;    int size,i;
   struct object ob0,ob1;    struct object ob0 = OINIT;
     struct object ob1 = OINIT;
   POLY f;    POLY f;
   /*    /*
      printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout);      printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout);
      */    */
   if (ob.tag != Sarray) {    if (ob.tag != Sarray) {
     errorCmo("cmoListToPoly2(): the argument must be array.");      errorCmo("cmoListToPoly2(): the argument must be array.");
   }    }
Line 1142  main() {
Line 1161  main() {
 POLY cmoListToPOLY(struct object ob)  POLY cmoListToPOLY(struct object ob)
 {  {
   int size,i;    int size,i;
   struct object ob0,ob1;    struct object ob0 = OINIT;
     struct object ob1 = OINIT;
   POLY f;    POLY f;
   /*    /*
      printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout);      printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout);
      */    */
   if (ob.tag != Sarray) {    if (ob.tag != Sarray) {
     errorCmo("cmoListToPOLY(): the argument must be array.");      errorCmo("cmoListToPOLY(): the argument must be array.");
   }    }
Line 1164  POLY cmoListToPOLY(struct object ob) 
Line 1184  POLY cmoListToPOLY(struct object ob) 
     for (i=size-1; i>=2; i--) {      for (i=size-1; i>=2; i--) {
       ob1 = getoa(ob,i);        ob1 = getoa(ob,i);
       if (ob1.tag == Spoly) {        if (ob1.tag == Spoly) {
         f = ppAdd(f,KopPOLY(ob1));          f = ppAdd(f,KopPOLY(ob1));
       }else{        }else{
         f = ppAdd(f,cmoListToPOLY(ob1));          f = ppAdd(f,cmoListToPOLY(ob1));
       }        }
     }      }
     return(f);      return(f);
Line 1181  POLY cmoListToPOLY(struct object ob) 
Line 1201  POLY cmoListToPOLY(struct object ob) 
 int Kan_PushBinary(int size,void *data)  int Kan_PushBinary(int size,void *data)
 {  {
   struct cmoBuffer cb;    struct cmoBuffer cb;
   struct object ob;    struct object ob = OINIT;
   cb.pos = size;    cb.pos = size;
   cb.rpos = 0;    cb.rpos = 0;
   cb.buf = data;    cb.buf = data;
Line 1194  int Kan_PushBinary(int size,void *data)
Line 1214  int Kan_PushBinary(int size,void *data)
   
 void *Kan_PopBinary(int *sizep)  void *Kan_PopBinary(int *sizep)
 {  {
   struct object ob;    struct object ob = OINIT;
   struct cmoBuffer *cb;    struct cmoBuffer *cb;
   ob = KSpop();    ob = KSpop();
   ob = cmoObjectToCmo(ob);    ob = cmoObjectToCmo(ob);
Line 1213  void *Kan_PopBinary(int *sizep)
Line 1233  void *Kan_PopBinary(int *sizep)
 struct object cmoObjectFromStream(struct object obStream)  struct object cmoObjectFromStream(struct object obStream)
 {  {
   struct cmoBuffer cb;    struct cmoBuffer cb;
   struct object rob;    struct object rob = OINIT;
   extern DebugCMO;    extern DebugCMO;
   if (obStream.tag != Sfile) {    if (obStream.tag != Sfile) {
     errorCmo("cmoObjectFromStream: Argument must be of type file.");      errorCmo("cmoObjectFromStream: Argument must be of type file.");
Line 1231  struct object cmoObjectFromStream(struct object obStre
Line 1251  struct object cmoObjectFromStream(struct object obStre
 struct object cmoObjectFromStream2(FILE2 *fp2)  struct object cmoObjectFromStream2(FILE2 *fp2)
 {  {
   struct cmoBuffer cb;    struct cmoBuffer cb;
   struct object rob;    struct object rob = OINIT;
   cb.isStream=1; cb.fp = fp2;    cb.isStream=1; cb.fp = fp2;
   cmoGetIntFromBuf(CMOINITSTREAM,&cb);    cmoGetIntFromBuf(CMOINITSTREAM,&cb);
   rob = cmoCmoToObject00(&cb);    rob = cmoCmoToObject00(&cb);
Line 1246  struct object cmoObjectFromStream2(FILE2 *fp2)
Line 1266  struct object cmoObjectFromStream2(FILE2 *fp2)
   
 struct object cmoObjectToStream(struct object ob, struct object obStream)  struct object cmoObjectToStream(struct object ob, struct object obStream)
 {  {
   struct object rob;    struct object rob = OINIT;
   extern int DebugCMO;    extern int DebugCMO;
   if (obStream.tag != Sfile) {    if (obStream.tag != Sfile) {
     errorCmo("cmoObjectToStream: Argument must be of type file.");      errorCmo("cmoObjectToStream: Argument must be of type file.");
Line 1263  struct object cmoObjectToStream(struct object ob, stru
Line 1283  struct object cmoObjectToStream(struct object ob, stru
   
 struct object cmoObjectToStream2(struct object ob, FILE2 *fp2)  struct object cmoObjectToStream2(struct object ob, FILE2 *fp2)
 {  {
   struct object rob;    struct object rob = OINIT;
   cmoOutputToBuf(CMOINITSTREAM,(void *)fp2,0);    cmoOutputToBuf(CMOINITSTREAM,(void *)fp2,0);
   if (DebugCMO) {    if (DebugCMO) {
     fprintf(stderr,"cmoObjectToStream2: ");      fprintf(stderr,"cmoObjectToStream2: ");
Line 1277  struct object cmoObjectToStream2(struct object ob, FIL
Line 1297  struct object cmoObjectToStream2(struct object ob, FIL
   
 int Kan_pushCMOFromStream(FILE2 *fp)  int Kan_pushCMOFromStream(FILE2 *fp)
 {  {
   struct object ob;    struct object ob = OINIT;
   struct object rob;    struct object rob = OINIT;
   ob.tag = Sfile; ob.rc.voidp = (void *)fp; ob.lc.str = MAGIC2;    ob.tag = Sfile; ob.rc.voidp = (void *)fp; ob.lc.str = MAGIC2;
   rob = cmoObjectFromStream(ob);    rob = cmoObjectFromStream(ob);
   KSpush(rob);    KSpush(rob);
Line 1287  int Kan_pushCMOFromStream(FILE2 *fp)
Line 1307  int Kan_pushCMOFromStream(FILE2 *fp)
   
 int Kan_popCMOToStream(FILE2 *fp,int serial)  int Kan_popCMOToStream(FILE2 *fp,int serial)
 {  {
   struct object ob;    struct object ob = OINIT;
   struct object sob;    struct object sob = OINIT;
   sob.tag = Sfile; sob.rc.file = (void *)fp; sob.lc.str = MAGIC2;    sob.tag = Sfile; sob.rc.file = (void *)fp; sob.lc.str = MAGIC2;
   ob = Kpop();    ob = Kpop();
   /*outfp2(fp);*/ /* outfp2 is for debugging. see develop/97feb.. 1999, 1/19*/    /*outfp2(fp);*/ /* outfp2 is for debugging. see develop/97feb.. 1999, 1/19*/
Line 1311  int Kan_setMathCapToStream(FILE2 *fp,struct object ob)
Line 1331  int Kan_setMathCapToStream(FILE2 *fp,struct object ob)
   
 /* It is declared in oxmisc2.h, too. */  /* It is declared in oxmisc2.h, too. */
 struct object newMathCap(struct mathCap *mathcap){  struct object newMathCap(struct mathCap *mathcap){
   struct object rob;    struct object rob = OINIT;
   struct object ob1;    struct object ob1 = OINIT;
   struct object ob2;    struct object ob2 = OINIT;
   struct object ob3;    struct object ob3 = OINIT;
   struct object obOx;    struct object obOx = OINIT;
   struct object obSm;    struct object obSm = OINIT;
     struct object ob3tmp = OINIT;
   struct object *obp;    struct object *obp;
   int i;    int i,j;
   struct object mathinfo;    struct object mathinfo = OINIT;
   
   rob = newObjectArray(3);    rob = newObjectArray(3);
   
Line 1328  struct object newMathCap(struct mathCap *mathcap){
Line 1349  struct object newMathCap(struct mathCap *mathcap){
   for (i=0; i<getoaSize(mathinfo); i++) {    for (i=0; i<getoaSize(mathinfo); i++) {
     putoa(ob1,i,getoa(mathinfo,i));      putoa(ob1,i,getoa(mathinfo,i));
   }    }
   ob2 = newObjectArray(mathcap->n);    ob3 = newObjectArray(mathcap->oxSize);
   for (i=0; i<mathcap->n; i++) {  
     putoa(ob2,i,KpoInteger((mathcap->cmo)[i]));  
   }  
   obOx = newObjectArray(mathcap->oxSize);  
   for (i=0; i<mathcap->oxSize; i++) {    for (i=0; i<mathcap->oxSize; i++) {
     putoa(obOx,i,KpoInteger((mathcap->ox)[i]));      ob3tmp = newObjectArray(2);
       putoa(ob3tmp,0,KpoInteger((mathcap->ox)[i]));
       ob2 = newObjectArray(mathcap->n);
       for (j=0; j<mathcap->n; j++) {
         putoa(ob2,j,KpoInteger((mathcap->cmo)[j]));
       }
       putoa(ob3tmp,1,ob2);
       putoa(ob3,i,ob3tmp);
   }    }
   ob3 = newObjectArray(2);  
   putoa(ob3,0,obOx);  
   putoa(ob3,1,ob2);  
   
   obSm = newObjectArray(mathcap->smSize);    obSm = newObjectArray(mathcap->smSize);
   for (i=0; i<mathcap->smSize; i++) {    for (i=0; i<mathcap->smSize; i++) {
Line 1360  struct object KSmathCap(void)
Line 1381  struct object KSmathCap(void)
 }  }
   
 void *KSmathCapByStruct(void)  void *KSmathCapByStruct(void)
 /* Return the math cap of kan/sm1 with cmo.c as a mathcap classObject*/       /* Return the math cap of kan/sm1 with cmo.c as a mathcap classObject*/
 {  {
   struct mathCap *mathcap;    struct mathCap *mathcap;
   struct object ob;    struct object ob = OINIT;
   char *s1,*s2;    char *s1,*s2;
   struct object *mathinfo;    struct object *mathinfo;
   char *sys;    char *sys;
Line 1385  void *KSmathCapByStruct(void) 
Line 1406  void *KSmathCapByStruct(void) 
   putoa(ob,1,KpoString(sys));    putoa(ob,1,KpoString(sys));
   putoa(ob,2,KpoString(sysVersion));    putoa(ob,2,KpoString(sysVersion));
   s1 = getenv("HOSTTYPE");    s1 = getenv("HOSTTYPE");
     if (s1 == NULL) s1="unknown";
   s2 = (char *)sGC_malloc(strlen(s1)+2+strlen("HOSTTYPE="));    s2 = (char *)sGC_malloc(strlen(s1)+2+strlen("HOSTTYPE="));
   strcpy(s2,"HOSTTYPE=");    strcpy(s2,"HOSTTYPE=");
   strcat(s2,s1);    strcat(s2,s1);
Line 1419  void *KSmathCapByStruct(void) 
Line 1441  void *KSmathCapByStruct(void) 
   mathcap->cmo[19]= CMO_64BIT_MACHINE_DOUBLE;    mathcap->cmo[19]= CMO_64BIT_MACHINE_DOUBLE;
   mathcap->cmo[20]= CMO_ARRAY;    mathcap->cmo[20]= CMO_ARRAY;
   mathcap->cmo[21]= CMO_RATIONAL;    mathcap->cmo[21]= CMO_RATIONAL;
     mathcap->cmo[22]= CMO_QQ;
   
   mathcap->n = 22 ;   /* This is the number of cmo object. You can use    mathcap->n = 23 ;   /* This is the number of cmo object. You can use
                        cmo upto 1023. see mathcap.h */                           cmo upto 1023. see mathcap.h */
   
   mathcap->ox[0] = OX_DATA;    mathcap->ox[0] = OX_DATA;
   mathcap->oxSize = 1 ;   /* This is the number of OX object. You can use    mathcap->oxSize = 1 ;   /* This is the number of OX object. You can use
                              OX upto 1023. see mathcap.h */                               OX upto 1023. see mathcap.h */
   
   mathcap->sm[0] = SM_popCMO;    mathcap->sm[0] = SM_popCMO;
   mathcap->sm[1] = SM_popString;    mathcap->sm[1] = SM_popString;
Line 1438  void *KSmathCapByStruct(void) 
Line 1461  void *KSmathCapByStruct(void) 
   mathcap->sm[8] = SM_setMathCap;    mathcap->sm[8] = SM_setMathCap;
   mathcap->sm[9] = SM_getsp;    mathcap->sm[9] = SM_getsp;
   mathcap->sm[10] = SM_dupErrors;    mathcap->sm[10] = SM_dupErrors;
   mathcap->smSize = 11;    mathcap->sm[11] = SM_pushCMOtag;
     mathcap->sm[12] = SM_executeFunctionWithOptionalArgument;
     mathcap->smSize = 13;
   
   return((void *)mathcap);    return((void *)mathcap);
 }  }
Line 1466  errorCmo(char *s) {
Line 1491  errorCmo(char *s) {
 int outfp2(FILE2 *fp2) {  int outfp2(FILE2 *fp2) {
   int i;    int i;
   printf("---------  outfp2 ---------\n"); fflush(stdout);    printf("---------  outfp2 ---------\n"); fflush(stdout);
 /*  if (checkfp2(fp2," f2pdumpBuf ") == -1) {    /*  if (checkfp2(fp2," f2pdumpBuf ") == -1) {
     return(-1);        return(-1);
   }*/        }*/
   printf("fd=%d\n",fp2->fd);    printf("fd=%d\n",fp2->fd);
   printf("initialied=%d\n",fp2->initialized);    printf("initialied=%d\n",fp2->initialized);
   printf("readpos=%d\n",fp2->readpos);    printf("readpos=%d\n",fp2->readpos);
Line 1501  static char *translateReservedName(char *s) {
Line 1526  static char *translateReservedName(char *s) {
     return(NULL);      return(NULL);
   }    }
 }  }
   
 struct object cmoTranslateVariable_inComming(struct object ob) {  struct object cmoTranslateVariable_inComming(struct object ob) {
   /* ob must be Sdollar, return value must be Sdollar. */    /* ob must be Sdollar, return value must be Sdollar. */
   /* Read a variable name from an other system,    /* Read a variable name from an other system,
Line 1529  struct object cmoTranslateVariable_inComming(struct ob
Line 1554  struct object cmoTranslateVariable_inComming(struct ob
     if (t == NULL) errorCmo("No more memory.");      if (t == NULL) errorCmo("No more memory.");
     for (i=count=0; i<n; i++) {      for (i=count=0; i<n; i++) {
       if (s[i] <= ' ' || s[i] == '#') {        if (s[i] <= ' ' || s[i] == '#') {
         t[count++] = '#';          t[count++] = '#';
         t[count++] = (s[i]/16 < 10? s[i]/16+'0': (s[i]/16-10)+'A');          t[count++] = (s[i]/16 < 10? s[i]/16+'0': (s[i]/16-10)+'A');
         t[count++] = (s[i]%16 < 10? s[i]%16+'0': (s[i]%16-10)+'A');          t[count++] = (s[i]%16 < 10? s[i]%16+'0': (s[i]%16-10)+'A');
       }else{        }else{
         t[count++] = s[i];          t[count++] = s[i];
       }        }
     }      }
     t[count] = '\0';      t[count] = '\0';

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.14

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