=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/cmo.c,v retrieving revision 1.1.1.1 retrieving revision 1.8 diff -u -p -r1.1.1.1 -r1.8 --- OpenXM/src/kan96xx/plugin/cmo.c 1999/10/08 02:12:05 1.1.1.1 +++ OpenXM/src/kan96xx/plugin/cmo.c 2001/05/04 01:06:29 1.8 @@ -1,6 +1,7 @@ +/*$OpenXM: OpenXM/src/kan96xx/plugin/cmo.c,v 1.7 2001/04/15 07:55:07 takayama 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. */ @@ -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; @@ -195,9 +198,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 +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; @@ -422,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; @@ -459,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; @@ -541,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 ) { @@ -668,13 +671,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 +692,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,8 +1154,8 @@ POLY cmoListToPOLY(struct object ob) struct object ob0,ob1; 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 +1173,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); @@ -1317,8 +1326,9 @@ struct object newMathCap(struct mathCap *mathcap){ struct object ob3; struct object obOx; struct object obSm; + struct object ob3tmp; struct object *obp; - int i; + int i,j; struct object mathinfo; rob = newObjectArray(3); @@ -1328,17 +1338,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,7 +1370,7 @@ 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; @@ -1385,6 +1395,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); @@ -1421,11 +1432,11 @@ void *KSmathCapByStruct(void) mathcap->cmo[21]= CMO_RATIONAL; mathcap->n = 22 ; /* 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->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 +1449,8 @@ 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->smSize = 12; return((void *)mathcap); } @@ -1466,9 +1478,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 +1513,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 +1541,11 @@ struct object cmoTranslateVariable_inComming(struct ob if (t == NULL) errorCmo("No more memory."); for (i=count=0; i