[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.8 and 1.18

version 1.8, 2001/05/04 01:06:29 version 1.18, 2020/10/06 11:33:47
Line 1 
Line 1 
 /*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.7 2001/04/15 07:55:07 takayama Exp $*/  /*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.17 2020/10/04 06:10:36 noro 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 <arpa/inet.h>
 #include "datatype.h"  #include "datatype.h"
 #include "stackm.h"  #include "stackm.h"
 #include "extern.h"  #include "extern.h"
Line 18 
Line 19 
 #include "cmotag.htmp"   /* static char *cmotagToName(int tag) is defined  #include "cmotag.htmp"   /* static char *cmotagToName(int tag) is defined
                             here. */                              here. */
   
   void warningCmo(char *s);
   void errorCmo(char *s);
   size_t cmoOutGMPCoeff(mpz_srcptr x); // defined in cmo-gmp.c
   size_t cmoGetGMPCoeff(MP_INT *x, struct cmoBuffer *cb);
   int cmoCheckMathCap(struct object ob, struct object *mathcapObjp); // in oxmisc2.h
   
   
 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
Line 47  extern struct ring *CurrentRingp;
Line 55  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 156  struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat
Line 164  struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat
   }    }
 }  }
   
 dumpCmoBuf(struct cmoBuffer *cb)  int dumpCmoBuf(struct cmoBuffer *cb)
 {  {
   int i,size, tag;    int i,size, tag;
   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);
   tag = htonl(*((int *) s));    tag = htonl(*((int *) s));
   printf("CMO StandardEncoding: size = %d, size/sizeof(int) = %d, tag=%s \n",size,size/sizeof(int),cmotagToName(tag));    printf("CMO StandardEncoding: size = %d, size/sizeof(int) = %d, tag=%s \n",size,size/((int)sizeof(int)),cmotagToName(tag));
   for (i=0; i<size; i++) {    for (i=0; i<size; i++) {
     if (i % 20 == 0) putchar('\n');      if (i % 20 == 0) putchar('\n');
     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
    in cmoBuffer (cmo object in kan)     in cmoBuffer (cmo object in kan)
    to a stream */     to a stream */
 cmoToStream(struct object cmoObj,struct object of)  int cmoToStream(struct object cmoObj,struct object of)
 {  {
   int i,size;    int i,size;
   struct cmoBuffer *cb;    struct cmoBuffer *cb;
Line 213  struct object streamToCmo(struct object of)
Line 222  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 244  struct object streamToCmo(struct object of)
Line 253  struct object streamToCmo(struct object of)
 }  }
   
   
 cmoOutCmoNull() {  void cmoOutCmoNull() {
   cmoint tmp[1];    cmoint tmp[1];
   tmp[0] = htonl((cmoint) CMO_NULL);    tmp[0] = htonl((cmoint) CMO_NULL);
   cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));    cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
Line 254  cmoOutCmoNull() {
Line 263  cmoOutCmoNull() {
   
   
 /* unsigned short int must be 32 bits */  /* unsigned short int must be 32 bits */
 cmoOutInt32(int k)  void cmoOutInt32(int k)
 {  {
   cmoint tmp[2];    cmoint tmp[2];
   tmp[0] = htonl((cmoint) CMO_INT32);    tmp[0] = htonl((cmoint) CMO_INT32);
Line 262  cmoOutInt32(int k)
Line 271  cmoOutInt32(int k)
   cmoOutputToBuf(CMOPUT,tmp,2*sizeof(cmoint));    cmoOutputToBuf(CMOPUT,tmp,2*sizeof(cmoint));
 }  }
   
 cmoOutString(char *d,int size) {  int cmoOutString(char *d,int size) {
   cmoint tmp[2];    cmoint tmp[2];
   tmp[0] = htonl((cmoint) CMO_STRING);    tmp[0] = htonl((cmoint) CMO_STRING);
   tmp[1] = htonl((cmoint ) size);    tmp[1] = htonl((cmoint ) size);
   cmoOutputToBuf(CMOPUT,tmp,2*sizeof(cmoint));    cmoOutputToBuf(CMOPUT,tmp,2*sizeof(cmoint));
   cmoOutputToBuf(CMOPUT,d,size);    cmoOutputToBuf(CMOPUT,d,size);
     return 0;
 }  }
   
   
Line 361  int cmoOutPolynomial2(POLY f) 
Line 371  int cmoOutPolynomial2(POLY f) 
   return(0);    return(0);
 }  }
   
 int cmoOutRingDefinition(struct ring *rp,int option)  void cmoOutRingDefinition(struct ring *rp,int option)
 {  {
   cmoint tmp[3];    cmoint tmp[3];
   /* minimal information */    /* minimal information */
Line 387  int cmoOutRingDefinition(struct ring *rp,int option)
Line 397  int cmoOutRingDefinition(struct ring *rp,int option)
   
 }  }
   
 int cmoOutRingDefinition2(struct ring *rp,int option)  void cmoOutRingDefinition2(struct ring *rp,int option)
 {  {
   cmoint tmp[3];    cmoint tmp[3];
   /* minimal information */    /* minimal information */
Line 625  POLY cmoGetMonomial32(struct cmoBuffer *cb)
Line 635  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 671  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 771  void cmoObjectToCmo00(struct object ob)
Line 788  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 799  int Lisplike = 0;  
Line 816  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 1011  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 1029  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 1058  struct object cmoCmoToObject00(struct cmoBuffer *cb)
Line 1076  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 1083  struct object cmoCmoToObject(struct object ob)
Line 1101  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);
Line 1110  struct object cmoListToPoly(struct object ob) {
Line 1128  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);
Line 1151  main() {
Line 1170  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);
Line 1190  POLY cmoListToPOLY(struct object ob) 
Line 1210  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 1203  int Kan_PushBinary(int size,void *data)
Line 1223  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 1222  void *Kan_PopBinary(int *sizep)
Line 1242  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 int 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 1240  struct object cmoObjectFromStream(struct object obStre
Line 1260  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 1255  struct object cmoObjectFromStream2(FILE2 *fp2)
Line 1275  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 1272  struct object cmoObjectToStream(struct object ob, stru
Line 1292  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 1286  struct object cmoObjectToStream2(struct object ob, FIL
Line 1306  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 1296  int Kan_pushCMOFromStream(FILE2 *fp)
Line 1316  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 1320  int Kan_setMathCapToStream(FILE2 *fp,struct object ob)
Line 1340  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 1373  void *KSmathCapByStruct(void) 
Line 1393  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 1430  void *KSmathCapByStruct(void) 
Line 1450  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;
Line 1450  void *KSmathCapByStruct(void) 
Line 1471  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->sm[13] = SM_nop;
     mathcap->smSize = 14;
   
   return((void *)mathcap);    return((void *)mathcap);
 }  }
Line 1462  int cmoOutRawInt(int k)
Line 1485  int cmoOutRawInt(int k)
   cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));    cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint));
 }  }
   
 warningCmo(char *s) {  void warningCmo(char *s) {
   fprintf(stderr,"Warning: plugin/cmo.c : %s\n",s);    fprintf(stderr,"Warning: plugin/cmo.c : %s\n",s);
 }  }
   
 errorCmo(char *s) {  void errorCmo(char *s) {
   fprintf(stderr,"plugin/cmo.c : %s\n",s);    fprintf(stderr,"plugin/cmo.c : %s\n",s);
   errorKan1("%s\n","cmo fatal error. ox servers need SM_control_reset_connection.");    errorKan1("%s\n","cmo fatal error. ox servers need SM_control_reset_connection.");
   /* ErrorPacket is automatically push on the ErrorStack.    /* ErrorPacket is automatically push on the ErrorStack.

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.18

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