[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.6 and 1.13

version 1.6, 2000/02/02 03:30:48 version 1.13, 2005/06/16 05:07:24
Line 1 
Line 1 
 /*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.5 2000/01/25 05:07:11 takayama Exp $*/  /*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.12 2004/08/28 12:50:06 takayama Exp $*/
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
 /* #include <netinet/in.h> */  /* #include <netinet/in.h> */
Line 16 
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 38  int CmoClientMode = 1;  /* This flag is used to transl
Line 38  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,
             oxSendMathCap  in oxmisc.c,              oxSendMathCap  in oxmisc.c,
             newMathCap in cmo.c,          newMathCap in cmo.c,
     oxReq, SM_setMathCap: in oxmisc2.c, and      oxReq, SM_setMathCap: in oxmisc2.c, and
     grep mathCap and make all modifications.      grep mathCap and make all modifications.
 */  */
Line 47  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 89  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((int) ((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 128  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 213  struct object streamToCmo(struct object of)
Line 213  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 377  int cmoOutRingDefinition(struct ring *rp,int option)
Line 377  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 403  int cmoOutRingDefinition2(struct ring *rp,int option)
Line 403  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 425  int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb)
Line 425  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 462  int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb)
Line 462  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 544  POLY cmoGetMonomial32(struct cmoBuffer *cb)
Line 544  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 625  POLY cmoGetMonomial32(struct cmoBuffer *cb)
Line 625  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 660  void cmoObjectToCmo00(struct object ob)
Line 661  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 671  void cmoObjectToCmo00(struct object ob)
Line 678  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 692  void cmoObjectToCmo00(struct object ob)
Line 699  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 767  void cmoObjectToCmo00(struct object ob)
Line 778  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 795  int Lisplike = 0;  
Line 806  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 857  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 869  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 879  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 891  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 956  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 968  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 1005  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 1019  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 1052  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 1066  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 1077  struct object cmoCmoToObject(struct object ob)
Line 1091  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 1104  struct object cmoListToPoly(struct object ob) {
Line 1118  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 1145  main() {
Line 1160  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 1167  POLY cmoListToPOLY(struct object ob) 
Line 1183  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 1184  POLY cmoListToPOLY(struct object ob) 
Line 1200  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 1197  int Kan_PushBinary(int size,void *data)
Line 1213  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 1216  void *Kan_PopBinary(int *sizep)
Line 1232  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 1234  struct object cmoObjectFromStream(struct object obStre
Line 1250  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 1249  struct object cmoObjectFromStream2(FILE2 *fp2)
Line 1265  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 1266  struct object cmoObjectToStream(struct object ob, stru
Line 1282  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 1280  struct object cmoObjectToStream2(struct object ob, FIL
Line 1296  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 1290  int Kan_pushCMOFromStream(FILE2 *fp)
Line 1306  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 1314  int Kan_setMathCapToStream(FILE2 *fp,struct object ob)
Line 1330  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;    struct object ob3tmp = OINIT;
   struct object *obp;    struct object *obp;
   int i,j;    int i,j;
   struct object mathinfo;    struct object mathinfo = OINIT;
   
   rob = newObjectArray(3);    rob = newObjectArray(3);
   
Line 1364  struct object KSmathCap(void)
Line 1380  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 1424  void *KSmathCapByStruct(void) 
Line 1440  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 1444  void *KSmathCapByStruct(void) 
Line 1461  void *KSmathCapByStruct(void) 
   mathcap->sm[9] = SM_getsp;    mathcap->sm[9] = SM_getsp;
   mathcap->sm[10] = SM_dupErrors;    mathcap->sm[10] = SM_dupErrors;
   mathcap->sm[11] = SM_pushCMOtag;    mathcap->sm[11] = SM_pushCMOtag;
   mathcap->smSize = 12;    mathcap->sm[12] = SM_executeFunctionWithOptionalArgument;
     mathcap->smSize = 13;
   
   return((void *)mathcap);    return((void *)mathcap);
 }  }
Line 1472  errorCmo(char *s) {
Line 1490  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 1507  static char *translateReservedName(char *s) {
Line 1525  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 1535  struct object cmoTranslateVariable_inComming(struct ob
Line 1553  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.6  
changed lines
  Added in v.1.13

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