=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/cmo.c,v retrieving revision 1.5 retrieving revision 1.13 diff -u -p -r1.5 -r1.13 --- OpenXM/src/kan96xx/plugin/cmo.c 2000/01/25 05:07:11 1.5 +++ OpenXM/src/kan96xx/plugin/cmo.c 2005/06/16 05:07:24 1.13 @@ -1,4 +1,4 @@ -/*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.4 1999/11/27 01:41:11 takayama Exp $*/ +/*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.12 2004/08/28 12:50:06 takayama Exp $*/ #include #include /* #include */ @@ -16,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) */ @@ -38,7 +38,7 @@ int CmoClientMode = 1; /* This flag is used to transl /* If you change the format of mathcap, do the follows. Mofify cmoCheckMathCap in oxmisc2.c, oxSendMathCap in oxmisc.c, - newMathCap in cmo.c, + newMathCap in cmo.c, oxReq, SM_setMathCap: in oxmisc2.c, and grep mathCap and make all modifications. */ @@ -47,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; @@ -89,12 +89,12 @@ struct cmoBuffer *cmoOutputToBuf(cmoAction a,void *dat break; case CMOPUT: for (i=0; iisStream = b.isStream; @@ -128,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; @@ -213,7 +213,7 @@ struct object streamToCmo(struct object of) { int c; unsigned char s[1]; - struct object ob; + struct object ob = OINIT; int file2 = 0; if (of.tag == Sfile) { @@ -377,7 +377,7 @@ int cmoOutRingDefinition(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 name of variables, weight_vector, output_order */ break; default: /* including 0. */ @@ -403,7 +403,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; @@ -425,20 +425,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; @@ -462,18 +462,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; @@ -544,12 +544,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 ) { @@ -625,13 +625,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) { @@ -660,6 +661,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); @@ -671,13 +678,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: @@ -692,56 +699,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."); } @@ -1145,11 +1160,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."); } @@ -1167,9 +1183,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); @@ -1184,7 +1200,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; @@ -1197,7 +1213,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); @@ -1216,7 +1232,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."); @@ -1234,7 +1250,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); @@ -1249,7 +1265,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."); @@ -1266,7 +1282,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: "); @@ -1280,8 +1296,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); @@ -1290,8 +1306,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*/ @@ -1314,16 +1330,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 ob3tmp; + 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,j; - struct object mathinfo; + struct object mathinfo = OINIT; rob = newObjectArray(3); @@ -1364,10 +1380,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; @@ -1424,13 +1440,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; @@ -1443,7 +1460,9 @@ 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->smSize = 13; return((void *)mathcap); } @@ -1471,9 +1490,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); @@ -1506,7 +1525,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, @@ -1534,11 +1553,11 @@ struct object cmoTranslateVariable_inComming(struct ob if (t == NULL) errorCmo("No more memory."); for (i=count=0; i