=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/cmo.c,v retrieving revision 1.1.1.1 retrieving revision 1.17 diff -u -p -r1.1.1.1 -r1.17 --- OpenXM/src/kan96xx/plugin/cmo.c 1999/10/08 02:12:05 1.1.1.1 +++ OpenXM/src/kan96xx/plugin/cmo.c 2020/10/04 06:10:36 1.17 @@ -1,6 +1,7 @@ +/*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.16 2020/10/04 03:14:07 noro Exp $*/ #include #include -#include +/* #include */ #include #include "datatype.h" #include "stackm.h" @@ -15,15 +16,15 @@ #include "cmo.h" #include "cmotag.htmp" /* static char *cmotagToName(int tag) is defined - here. */ + here. */ extern int OxVersion; int CmoClientMode = 1; /* This flag is used to translate names for - indeterminates. - It does not work well if ox_sm1 have a server, i.e., - sm1 --> ox_sm1 --> ox_sm1 - */ + indeterminates. + It does not work well if ox_sm1 have a server, i.e., + sm1 --> ox_sm1 --> ox_sm1 + */ /* void *malloc(int s); #define GC_malloc(x) malloc(x) */ @@ -36,7 +37,9 @@ int CmoClientMode = 1; /* This flag is used to transl **************************************************************************/ /* If you change the format of mathcap, do the follows. 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. */ @@ -44,7 +47,7 @@ extern struct ring *CurrentRingp; extern struct ring *SmallRingp; extern int CmoDMSOutputOption; -struct object NullObjectInCmo; +struct object NullObjectInCmo = OINIT; extern int SerialCurrent; extern int DebugCMO; @@ -86,12 +89,12 @@ struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat break; case CMOPUT: for (i=0; iisStream = b.isStream; @@ -125,10 +128,10 @@ struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat break; case CMOPUT: if (b.pos + size >= b.size) { - tmp = sGC_malloc((b.size)*2+size); - memcpy(tmp,b.buf,b.pos); - b.buf = tmp; - b.size = (b.size)*2+size; + tmp = sGC_malloc((b.size)*2+size); + memcpy(tmp,b.buf,b.pos); + b.buf = tmp; + b.size = (b.size)*2+size; } memcpy((void *) &(((char *)(b.buf))[b.pos]),data,size); b.pos += size; @@ -159,7 +162,7 @@ dumpCmoBuf(struct cmoBuffer *cb) char *s; if (cb->isStream) { printf("cmoBuffer is directed to a stream.\n"); - return; + return 0; } size = cb->pos; s = (char *)(cb->buf); @@ -170,6 +173,7 @@ dumpCmoBuf(struct cmoBuffer *cb) printf("%3x",(int)(unsigned char)s[i]); } putchar('\n'); + return 0; } /* This obsolete function is used to write data @@ -195,9 +199,9 @@ cmoToStream(struct object cmoObj,struct object of) s = (char *)(cb->buf); for (i=0; in)*2); /* number of variables */ 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 */ break; default: /* including 0. */ @@ -400,7 +404,7 @@ int cmoOutRingDefinition2(struct ring *rp,int option) cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)*3); cmoOutInt32((rp->n)*2); /* number of variables */ 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), weight_vector by list , output_order by list. */ break; @@ -422,20 +426,20 @@ int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb) switch(a) { case CMOGET: for (i=0; i<4; i++) { - cc = fp2fgetc(cb->fp); - if (cc < 0) { - return(-1); - errorCmo("cmoGetIntFromBuf CMOGET: unexpected EOF.\n"); - } - data[i] = cc; + cc = fp2fgetc(cb->fp); + if (cc < 0) { + return(-1); + errorCmo("cmoGetIntFromBuf CMOGET: unexpected EOF.\n"); + } + data[i] = cc; } return( (int) ntohl( *((cmoint *) data) )); break; case CMOGETBYTE: cc = fp2fgetc(cb->fp); if (cc < 0) { - return(-1); - errorCmo("cmoGetIntFromBuf CMOGETBYTE: unexpected EOF.\n"); + return(-1); + errorCmo("cmoGetIntFromBuf CMOGETBYTE: unexpected EOF.\n"); } return(cc); break; @@ -459,18 +463,18 @@ int cmoGetIntFromBuf(cmoAction a,struct cmoBuffer *cb) switch(a) { case CMOGET: if (cb->rpos + sizeof(cmoint) > cb->pos) { - fprintf(stderr,"No more data in the buffer. Returns -1.\n"); - return(-1); + fprintf(stderr,"No more data in the buffer. Returns -1.\n"); + return(-1); } memcpy(tmp,(void *) &(((char *)(cb->buf))[cb->rpos]), - sizeof(cmoint)); + sizeof(cmoint)); cb->rpos += sizeof(cmoint); return( (int) ntohl(tmp[0])); break; case CMOGETBYTE: if (cb->rpos + 1 > cb->pos) { - fprintf(stderr,"No more data in the buffer. Returns -1.\n"); - return(-1); + fprintf(stderr,"No more data in the buffer. Returns -1.\n"); + return(-1); } tmp[0] = ((unsigned char *)(cb->buf))[cb->rpos]; cb->rpos += 1; @@ -541,12 +545,12 @@ 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."); /* original code. - skip = nn - (CurrentRingp->n)*2; - nn1 = nn0 = CurrentRingp->n; - if (! (cb->errorno) ) { - warningCmo("cmoGetMonomial32(): serialized polynomial \\not\\in CurrentRing."); - } - cmoGetIntFromBuf(CMOERROR,cb); + skip = nn - (CurrentRingp->n)*2; + nn1 = nn0 = CurrentRingp->n; + if (! (cb->errorno) ) { + warningCmo("cmoGetMonomial32(): serialized polynomial \\not\\in CurrentRing."); + } + cmoGetIntFromBuf(CMOERROR,cb); */ } if (nn == (CurrentRingp->n)*2 ) { @@ -622,13 +626,14 @@ POLY cmoGetMonomial32(struct cmoBuffer *cb) /* ------------------------------------- */ void cmoObjectToCmo00(struct object ob) { - struct object rob; + struct object rob = OINIT; cmoint tmp[16]; char tmpc[16]; int i,size; - struct object vlist, vlist0; + struct object vlist = OINIT; + struct object vlist0 = OINIT; int m; - struct object ob2; + struct object ob2 = OINIT; /* NO initialization */ switch(ob.tag) { @@ -657,6 +662,12 @@ void cmoObjectToCmo00(struct object ob) case SuniversalNumber: cmoOutGMPCoeff(ob.lc.universalNumber->val.bigp); break; + case SrationalFunction: + tmp[0] = htonl(CMO_RATIONAL); + cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); + cmoObjectToCmo00(*(Knumerator(ob))); + cmoObjectToCmo00(*(Kdenominator(ob))); + break; case Sdouble: if (sizeof(double) != 8) errorCmo("double is assumed to be 8 bytes."); cmoOutRawInt(CMO_64BIT_MACHINE_DOUBLE); @@ -668,13 +679,13 @@ void cmoObjectToCmo00(struct object ob) case CLASSNAME_ERROR_PACKET: /* fprintf(stderr,"ectag=%d\n",ectag(*KopErrorPacket(ob))); **kxx:CMO_ERROR*/ if (ectag(*KopErrorPacket(ob)) == CLASSNAME_ERROR_PACKET) { - tmp[0] = htonl(CMO_ERROR); - cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); + tmp[0] = htonl(CMO_ERROR); + cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); }else{ - tmp[0] = htonl(CMO_ERROR2); - cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); - /* Send without OX_DATA header !! */ - cmoObjectToCmo00(*(KopErrorPacket(ob))); + tmp[0] = htonl(CMO_ERROR2); + cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); + /* Send without OX_DATA header !! */ + cmoObjectToCmo00(*(KopErrorPacket(ob))); } break; case CLASSNAME_mathcap: @@ -689,56 +700,60 @@ void cmoObjectToCmo00(struct object ob) /* cmoObjectToCmo00(KopIndeterminate(ob)); Old code. */ /* If you need to translate the name, do it here. */ if (CmoClientMode) { - ob = KopIndeterminate(ob); + ob = KopIndeterminate(ob); }else{ - ob = cmoTranslateVariable_outGoing(KopIndeterminate(ob)); + ob = cmoTranslateVariable_outGoing(KopIndeterminate(ob)); } cmoObjectToCmo00(ob); break; case CLASSNAME_recursivePolynomial: /* We assume that the format of the recursive polynomial - is OK. */ + is OK. */ tmp[0] = htonl(CMO_RECURSIVE_POLYNOMIAL); cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); ob = KopRecursivePolynomial(ob); vlist = getoa(ob,0); vlist0 = newObjectArray(getoaSize(vlist)); for (i=0; i= 1) { ob0 = getoa(ob,0); if (ob0.tag == CMO+CMO_DMS) { - rob = KpoPOLY(cmoListToPOLY(ob)); /* not ToPoly, ToPOLY */ + rob = KpoPOLY(cmoListToPOLY(ob)); /* not ToPoly, ToPOLY */ }else{ - rob = newObjectArray(n); - for (i=0; i>\n"); fflush(stdout); - */ + printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout); + */ if (ob.tag != Sarray) { errorCmo("cmoListToPoly2(): the argument must be array."); } @@ -1142,11 +1161,12 @@ main() { POLY cmoListToPOLY(struct object ob) { int size,i; - struct object ob0,ob1; + struct object ob0 = OINIT; + struct object ob1 = OINIT; POLY f; /* - printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout); - */ + printf("<<");printObject(ob,0,stdout); printf(">>\n"); fflush(stdout); + */ if (ob.tag != Sarray) { errorCmo("cmoListToPOLY(): the argument must be array."); } @@ -1164,9 +1184,9 @@ POLY cmoListToPOLY(struct object ob) for (i=size-1; i>=2; i--) { ob1 = getoa(ob,i); if (ob1.tag == Spoly) { - f = ppAdd(f,KopPOLY(ob1)); + f = ppAdd(f,KopPOLY(ob1)); }else{ - f = ppAdd(f,cmoListToPOLY(ob1)); + f = ppAdd(f,cmoListToPOLY(ob1)); } } return(f); @@ -1181,7 +1201,7 @@ POLY cmoListToPOLY(struct object ob) int Kan_PushBinary(int size,void *data) { struct cmoBuffer cb; - struct object ob; + struct object ob = OINIT; cb.pos = size; cb.rpos = 0; cb.buf = data; @@ -1194,7 +1214,7 @@ int Kan_PushBinary(int size,void *data) void *Kan_PopBinary(int *sizep) { - struct object ob; + struct object ob = OINIT; struct cmoBuffer *cb; ob = KSpop(); ob = cmoObjectToCmo(ob); @@ -1213,7 +1233,7 @@ void *Kan_PopBinary(int *sizep) struct object cmoObjectFromStream(struct object obStream) { struct cmoBuffer cb; - struct object rob; + struct object rob = OINIT; extern DebugCMO; if (obStream.tag != Sfile) { errorCmo("cmoObjectFromStream: Argument must be of type file."); @@ -1231,7 +1251,7 @@ struct object cmoObjectFromStream(struct object obStre struct object cmoObjectFromStream2(FILE2 *fp2) { struct cmoBuffer cb; - struct object rob; + struct object rob = OINIT; cb.isStream=1; cb.fp = fp2; cmoGetIntFromBuf(CMOINITSTREAM,&cb); rob = cmoCmoToObject00(&cb); @@ -1246,7 +1266,7 @@ struct object cmoObjectFromStream2(FILE2 *fp2) struct object cmoObjectToStream(struct object ob, struct object obStream) { - struct object rob; + struct object rob = OINIT; extern int DebugCMO; if (obStream.tag != Sfile) { errorCmo("cmoObjectToStream: Argument must be of type file."); @@ -1263,7 +1283,7 @@ struct object cmoObjectToStream(struct object ob, stru struct object cmoObjectToStream2(struct object ob, FILE2 *fp2) { - struct object rob; + struct object rob = OINIT; cmoOutputToBuf(CMOINITSTREAM,(void *)fp2,0); if (DebugCMO) { fprintf(stderr,"cmoObjectToStream2: "); @@ -1277,8 +1297,8 @@ struct object cmoObjectToStream2(struct object ob, FIL int Kan_pushCMOFromStream(FILE2 *fp) { - struct object ob; - struct object rob; + struct object ob = OINIT; + struct object rob = OINIT; ob.tag = Sfile; ob.rc.voidp = (void *)fp; ob.lc.str = MAGIC2; rob = cmoObjectFromStream(ob); KSpush(rob); @@ -1287,8 +1307,8 @@ int Kan_pushCMOFromStream(FILE2 *fp) int Kan_popCMOToStream(FILE2 *fp,int serial) { - struct object ob; - struct object sob; + struct object ob = OINIT; + struct object sob = OINIT; sob.tag = Sfile; sob.rc.file = (void *)fp; sob.lc.str = MAGIC2; ob = Kpop(); /*outfp2(fp);*/ /* outfp2 is for debugging. see develop/97feb.. 1999, 1/19*/ @@ -1311,15 +1331,16 @@ int Kan_setMathCapToStream(FILE2 *fp,struct object ob) /* It is declared in oxmisc2.h, too. */ struct object newMathCap(struct mathCap *mathcap){ - struct object rob; - struct object ob1; - struct object ob2; - struct object ob3; - struct object obOx; - struct object obSm; + struct object rob = OINIT; + struct object ob1 = OINIT; + struct object ob2 = OINIT; + struct object ob3 = OINIT; + struct object obOx = OINIT; + struct object obSm = OINIT; + struct object ob3tmp = OINIT; struct object *obp; - int i; - struct object mathinfo; + int i,j; + struct object mathinfo = OINIT; rob = newObjectArray(3); @@ -1328,17 +1349,17 @@ struct object newMathCap(struct mathCap *mathcap){ for (i=0; in); - for (i=0; in; i++) { - putoa(ob2,i,KpoInteger((mathcap->cmo)[i])); - } - obOx = newObjectArray(mathcap->oxSize); + ob3 = newObjectArray(mathcap->oxSize); for (i=0; ioxSize; 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; jn; 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); for (i=0; ismSize; i++) { @@ -1360,10 +1381,10 @@ struct object KSmathCap(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 object ob; + struct object ob = OINIT; char *s1,*s2; struct object *mathinfo; char *sys; @@ -1385,6 +1406,7 @@ void *KSmathCapByStruct(void) putoa(ob,1,KpoString(sys)); putoa(ob,2,KpoString(sysVersion)); s1 = getenv("HOSTTYPE"); + if (s1 == NULL) s1="unknown"; s2 = (char *)sGC_malloc(strlen(s1)+2+strlen("HOSTTYPE=")); strcpy(s2,"HOSTTYPE="); strcat(s2,s1); @@ -1419,13 +1441,14 @@ void *KSmathCapByStruct(void) mathcap->cmo[19]= CMO_64BIT_MACHINE_DOUBLE; mathcap->cmo[20]= CMO_ARRAY; mathcap->cmo[21]= CMO_RATIONAL; + mathcap->cmo[22]= CMO_QQ; - mathcap->n = 22 ; /* This is the number of cmo object. You can use - cmo upto 1023. see mathcap.h */ + mathcap->n = 23 ; /* This is the number of cmo object. You can use + cmo upto 1023. see mathcap.h */ mathcap->ox[0] = OX_DATA; 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[1] = SM_popString; @@ -1438,7 +1461,10 @@ void *KSmathCapByStruct(void) mathcap->sm[8] = SM_setMathCap; mathcap->sm[9] = SM_getsp; mathcap->sm[10] = SM_dupErrors; - mathcap->smSize = 11; + mathcap->sm[11] = SM_pushCMOtag; + mathcap->sm[12] = SM_executeFunctionWithOptionalArgument; + mathcap->sm[13] = SM_nop; + mathcap->smSize = 14; return((void *)mathcap); } @@ -1450,11 +1476,11 @@ int cmoOutRawInt(int k) cmoOutputToBuf(CMOPUT,tmp,sizeof(cmoint)); } -warningCmo(char *s) { +int warningCmo(char *s) { fprintf(stderr,"Warning: plugin/cmo.c : %s\n",s); } -errorCmo(char *s) { +int errorCmo(char *s) { fprintf(stderr,"plugin/cmo.c : %s\n",s); errorKan1("%s\n","cmo fatal error. ox servers need SM_control_reset_connection."); /* ErrorPacket is automatically push on the ErrorStack. @@ -1466,9 +1492,9 @@ errorCmo(char *s) { int outfp2(FILE2 *fp2) { int i; printf("--------- outfp2 ---------\n"); fflush(stdout); -/* if (checkfp2(fp2," f2pdumpBuf ") == -1) { - return(-1); - }*/ + /* if (checkfp2(fp2," f2pdumpBuf ") == -1) { + return(-1); + }*/ printf("fd=%d\n",fp2->fd); printf("initialied=%d\n",fp2->initialized); printf("readpos=%d\n",fp2->readpos); @@ -1501,7 +1527,7 @@ static char *translateReservedName(char *s) { return(NULL); } } - + struct object cmoTranslateVariable_inComming(struct object ob) { /* ob must be Sdollar, return value must be Sdollar. */ /* Read a variable name from an other system, @@ -1529,11 +1555,11 @@ struct object cmoTranslateVariable_inComming(struct ob if (t == NULL) errorCmo("No more memory."); for (i=count=0; i