version 1.34, 2004/09/13 11:24:11 |
version 1.49, 2015/10/08 11:49:37 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/kanExport0.c,v 1.33 2004/09/11 01:00:42 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/kanExport0.c,v 1.48 2012/09/16 01:53:08 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "stackm.h" |
#include "stackm.h" |
#include "extern.h" |
#include "extern.h" |
Line 30 struct object KooAdd(ob1,ob2) |
|
Line 32 struct object KooAdd(ob1,ob2) |
|
POLY r; |
POLY r; |
int s,i; |
int s,i; |
objectp f1,f2,g1,g2; |
objectp f1,f2,g1,g2; |
struct object nn,dd; |
struct object nn = OINIT; |
|
struct object dd = OINIT; |
|
|
switch (Lookup[ob1.tag][ob2.tag]) { |
switch (Lookup[ob1.tag][ob2.tag]) { |
case SintegerSinteger: |
case SintegerSinteger: |
Line 161 struct object KooSub(ob1,ob2) |
|
Line 164 struct object KooSub(ob1,ob2) |
|
int s,i; |
int s,i; |
objectp f1,f2,g1,g2; |
objectp f1,f2,g1,g2; |
extern struct coeff *UniversalZero; |
extern struct coeff *UniversalZero; |
struct object nn,dd; |
struct object nn = OINIT; |
|
struct object dd = OINIT; |
|
|
switch (Lookup[ob1.tag][ob2.tag]) { |
switch (Lookup[ob1.tag][ob2.tag]) { |
case SintegerSinteger: |
case SintegerSinteger: |
Line 292 struct object KooMult(ob1,ob2) |
|
Line 296 struct object KooMult(ob1,ob2) |
|
POLY r; |
POLY r; |
int i,s; |
int i,s; |
objectp f1,f2,g1,g2; |
objectp f1,f2,g1,g2; |
struct object dd,nn; |
struct object dd = OINIT; |
|
struct object nn = OINIT; |
|
|
|
|
switch (Lookup[ob1.tag][ob2.tag]) { |
switch (Lookup[ob1.tag][ob2.tag]) { |
Line 438 struct object KoNegate(obj) |
|
Line 443 struct object KoNegate(obj) |
|
{ |
{ |
struct object rob = NullObject; |
struct object rob = NullObject; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
struct object tob; |
struct object tob = OINIT; |
switch(obj.tag) { |
switch(obj.tag) { |
case Sinteger: |
case Sinteger: |
rob = obj; |
rob = obj; |
Line 480 struct object KoInverse(obj) |
|
Line 485 struct object KoInverse(obj) |
|
struct object rob = NullObject; |
struct object rob = NullObject; |
extern struct coeff *UniversalOne; |
extern struct coeff *UniversalOne; |
objectp onep; |
objectp onep; |
struct object tob; |
struct object tob = OINIT; |
switch(obj.tag) { |
switch(obj.tag) { |
case Spoly: |
case Spoly: |
tob.tag = SuniversalNumber; |
tob.tag = SuniversalNumber; |
Line 546 struct object KaoMult(aa,bb) |
|
Line 551 struct object KaoMult(aa,bb) |
|
POLY tmp; |
POLY tmp; |
POLY fik; |
POLY fik; |
POLY gkj; |
POLY gkj; |
struct object rob; |
struct object rob = OINIT; |
int r1,r2; |
int r1,r2; |
int rsize; |
int rsize; |
struct object tob; |
struct object tob = OINIT; |
struct object ob1; |
struct object ob1 = OINIT; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
|
|
m = getoaSize(aa); m2 = getoaSize(bb); |
m = getoaSize(aa); m2 = getoaSize(bb); |
Line 610 struct object KaoMult(aa,bb) |
|
Line 615 struct object KaoMult(aa,bb) |
|
r1 = isMatrix(aa,m,n); r2 = isMatrix(bb,m2,n2); |
r1 = isMatrix(aa,m,n); r2 = isMatrix(bb,m2,n2); |
if (r1 == -1 || r2 == -1) { |
if (r1 == -1 || r2 == -1) { |
/* Object multiplication. Elements are not polynomials. */ |
/* Object multiplication. Elements are not polynomials. */ |
struct object ofik,ogkj,otmp; |
struct object ofik = OINIT; |
|
struct object ogkj = OINIT; |
|
struct object otmp = OINIT; |
rob = newObjectArray(m); |
rob = newObjectArray(m); |
for (i=0; i<m; i++) { |
for (i=0; i<m; i++) { |
getoa(rob,i) = newObjectArray(n2); |
getoa(rob,i) = newObjectArray(n2); |
Line 685 KooEqualQ(obj1,obj2) |
|
Line 692 KooEqualQ(obj1,obj2) |
|
struct object obj1; |
struct object obj1; |
struct object obj2; |
struct object obj2; |
{ |
{ |
struct object ob; |
struct object ob = OINIT; |
int i; |
int i; |
|
extern int Verbose; |
if (obj1.tag != obj2.tag) { |
if (obj1.tag != obj2.tag) { |
warningKan("KooEqualQ(ob1,ob2): the datatypes of ob1 and ob2 are not same. Returns false (0).\n"); |
warningKan("KooEqualQ(ob1,ob2): the datatypes of ob1 and ob2 are not same. Returns false (0).\n"); |
|
if (Verbose & 0x10) { |
|
fprintf(stderr,"obj1(tag:%d)=",obj1.tag); |
|
printObject(obj1,0,stderr); |
|
fprintf(stderr,", obj2(tag:%d)=",obj2.tag); |
|
printObject(obj2,0,stderr); |
|
fprintf(stderr,"\n"); fflush(stderr); |
|
} |
return(0); |
return(0); |
} |
} |
switch(obj1.tag) { |
switch(obj1.tag) { |
Line 766 struct object KooGreater(obj1,obj2) |
|
Line 781 struct object KooGreater(obj1,obj2) |
|
struct object obj1; |
struct object obj1; |
struct object obj2; |
struct object obj2; |
{ |
{ |
struct object ob; |
struct object ob = OINIT; |
int tt; |
int tt; |
if (obj1.tag != obj2.tag) { |
if (obj1.tag != obj2.tag) { |
errorKan1("%s\n","You cannot compare different kinds of objects."); |
errorKan1("%s\n","You cannot compare different kinds of objects."); |
Line 800 struct object KooGreater(obj1,obj2) |
|
Line 815 struct object KooGreater(obj1,obj2) |
|
case Sarray: |
case Sarray: |
{ |
{ |
int i,m1,m2; |
int i,m1,m2; |
struct object rr; |
struct object rr = OINIT; |
m1 = getoaSize(obj1); m2 = getoaSize(obj2); |
m1 = getoaSize(obj1); m2 = getoaSize(obj2); |
for (i=0; i< (m1>m2?m2:m1); i++) { |
for (i=0; i< (m1>m2?m2:m1); i++) { |
rr=KooGreater(getoa(obj1,i),getoa(obj2,i)); |
rr=KooGreater(getoa(obj1,i),getoa(obj2,i)); |
Line 856 struct object KooLess(obj1,obj2) |
|
Line 871 struct object KooLess(obj1,obj2) |
|
case Sarray: |
case Sarray: |
{ |
{ |
int i,m1,m2; |
int i,m1,m2; |
struct object rr; |
struct object rr = OINIT; |
m1 = getoaSize(obj1); m2 = getoaSize(obj2); |
m1 = getoaSize(obj1); m2 = getoaSize(obj2); |
for (i=0; i< (m1>m2?m2:m1); i++) { |
for (i=0; i< (m1>m2?m2:m1); i++) { |
rr=KooLess(getoa(obj1,i),getoa(obj2,i)); |
rr=KooLess(getoa(obj1,i),getoa(obj2,i)); |
Line 882 struct object KdataConversion(obj,key) |
|
Line 897 struct object KdataConversion(obj,key) |
|
{ |
{ |
char tmps[128]; /* Assume that double is not more than 128 digits */ |
char tmps[128]; /* Assume that double is not more than 128 digits */ |
char intstr[100]; /* Assume that int is not more than 100 digits */ |
char intstr[100]; /* Assume that int is not more than 100 digits */ |
struct object rob; |
struct object rob = OINIT; |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
int flag; |
int flag; |
struct object rob1,rob2; |
struct object rob1 = OINIT; |
|
struct object rob2 = OINIT; |
char *s; |
char *s; |
int i; |
int i; |
double f; |
double f; |
Line 924 struct object KdataConversion(obj,key) |
|
Line 940 struct object KdataConversion(obj,key) |
|
rob = newObjectArray(0); |
rob = newObjectArray(0); |
return rob; |
return rob; |
}else{ |
}else{ |
|
/* fprintf(stderr,"key=%s\n",key); */ |
warningKan("Sorry. The data conversion from null to this data type has not supported yet.\n"); |
warningKan("Sorry. The data conversion from null to this data type has not supported yet.\n"); |
} |
} |
break; |
break; |
Line 1033 struct object KdataConversion(obj,key) |
|
Line 1050 struct object KdataConversion(obj,key) |
|
}else if (strcmp(key,"null") == 0) { |
}else if (strcmp(key,"null") == 0) { |
rob = NullObject; |
rob = NullObject; |
return(rob); |
return(rob); |
|
}else if (strcmp(key,"byteArray") == 0) { |
|
rob = newByteArray(getoaSize(obj),obj); |
|
return(rob); |
}else { |
}else { |
{ /* Automatically maps the elements. */ |
{ /* Automatically maps the elements. */ |
int n,i; |
int n,i; |
Line 1210 struct object KdataConversion(obj,key) |
|
Line 1230 struct object KdataConversion(obj,key) |
|
warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n"); |
warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n"); |
} |
} |
break; |
break; |
|
case SbyteArray: |
|
if (strcmp(key,"array") == 0) { |
|
rob = byteArrayToArray(obj); |
|
return(rob); |
|
} else { |
|
warningKan("Sorryl This type of data conversion of ringp has not supported yet.\n"); |
|
} |
|
break; |
default: |
default: |
warningKan("Sorry. This type of data conversion has not supported yet.\n"); |
warningKan("Sorry. This type of data conversion has not supported yet.\n"); |
} |
} |
Line 1219 struct object KdataConversion(obj,key) |
|
Line 1247 struct object KdataConversion(obj,key) |
|
/* cf. macro to_int32 */ |
/* cf. macro to_int32 */ |
struct object Kto_int32(struct object ob) { |
struct object Kto_int32(struct object ob) { |
int n,i; |
int n,i; |
struct object otmp; |
struct object otmp = OINIT; |
struct object rob; |
struct object rob = OINIT; |
if (ob.tag == SuniversalNumber) return KdataConversion(ob,"integer"); |
if (ob.tag == SuniversalNumber) return KdataConversion(ob,"integer"); |
if (ob.tag == Sarray) { |
if (ob.tag == Sarray) { |
n = getoaSize(ob); |
n = getoaSize(ob); |
Line 1238 struct object Kto_int32(struct object ob) { |
|
Line 1266 struct object Kto_int32(struct object ob) { |
|
struct object KpoInteger(k) |
struct object KpoInteger(k) |
int k; |
int k; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Sinteger; |
obj.tag = Sinteger; |
obj.lc.ival = k; obj.rc.ival = 0; |
obj.lc.ival = k; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1246 struct object KpoInteger(k) |
|
Line 1274 struct object KpoInteger(k) |
|
struct object KpoString(s) |
struct object KpoString(s) |
char *s; |
char *s; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Sdollar; |
obj.tag = Sdollar; |
obj.lc.str = s; obj.rc.ival = 0; |
obj.lc.str = s; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1254 struct object KpoString(s) |
|
Line 1282 struct object KpoString(s) |
|
struct object KpoPOLY(f) |
struct object KpoPOLY(f) |
POLY f; |
POLY f; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Spoly; |
obj.tag = Spoly; |
obj.lc.poly = f; obj.rc.ival = 0; |
obj.lc.poly = f; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1262 struct object KpoPOLY(f) |
|
Line 1290 struct object KpoPOLY(f) |
|
struct object KpoArrayOfPOLY(ap) |
struct object KpoArrayOfPOLY(ap) |
struct arrayOfPOLY *ap ; |
struct arrayOfPOLY *ap ; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = SarrayOfPOLY; |
obj.tag = SarrayOfPOLY; |
obj.lc.arrayp = ap; obj.rc.ival = 0; |
obj.lc.arrayp = ap; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1271 struct object KpoArrayOfPOLY(ap) |
|
Line 1299 struct object KpoArrayOfPOLY(ap) |
|
struct object KpoMatrixOfPOLY(mp) |
struct object KpoMatrixOfPOLY(mp) |
struct matrixOfPOLY *mp ; |
struct matrixOfPOLY *mp ; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = SmatrixOfPOLY; |
obj.tag = SmatrixOfPOLY; |
obj.lc.matrixp = mp; obj.rc.ival = 0; |
obj.lc.matrixp = mp; obj.rc.ival = 0; |
return(obj); |
return(obj); |
Line 1280 struct object KpoMatrixOfPOLY(mp) |
|
Line 1308 struct object KpoMatrixOfPOLY(mp) |
|
struct object KpoRingp(ringp) |
struct object KpoRingp(ringp) |
struct ring *ringp; |
struct ring *ringp; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = Sring; |
obj.tag = Sring; |
obj.lc.ringp = ringp; |
obj.lc.ringp = ringp; |
return(obj); |
return(obj); |
Line 1289 struct object KpoRingp(ringp) |
|
Line 1317 struct object KpoRingp(ringp) |
|
struct object KpoUniversalNumber(u) |
struct object KpoUniversalNumber(u) |
struct coeff *u; |
struct coeff *u; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
obj.tag = SuniversalNumber; |
obj.tag = SuniversalNumber; |
obj.lc.universalNumber = u; |
obj.lc.universalNumber = u; |
return(obj); |
return(obj); |
Line 1297 struct object KpoUniversalNumber(u) |
|
Line 1325 struct object KpoUniversalNumber(u) |
|
struct object KintToUniversalNumber(n) |
struct object KintToUniversalNumber(n) |
int n; |
int n; |
{ |
{ |
struct object rob; |
struct object rob = OINIT; |
extern struct ring SmallRing; |
extern struct ring SmallRing; |
rob.tag = SuniversalNumber; |
rob.tag = SuniversalNumber; |
rob.lc.universalNumber = intToCoeff(n,&SmallRing); |
rob.lc.universalNumber = intToCoeff(n,&SmallRing); |
Line 1310 struct object arrayOfPOLYToArray(aa) |
|
Line 1338 struct object arrayOfPOLYToArray(aa) |
|
{ |
{ |
POLY *a; |
POLY *a; |
int size; |
int size; |
struct object r; |
struct object r = OINIT; |
int j; |
int j; |
struct object tmp; |
struct object tmp = OINIT; |
|
|
size = aa->n; a = aa->array; |
size = aa->n; a = aa->array; |
r = newObjectArray(size); |
r = newObjectArray(size); |
Line 1327 struct object arrayOfPOLYToArray(aa) |
|
Line 1355 struct object arrayOfPOLYToArray(aa) |
|
struct object matrixOfPOLYToArray(pmat) |
struct object matrixOfPOLYToArray(pmat) |
struct matrixOfPOLY *pmat; |
struct matrixOfPOLY *pmat; |
{ |
{ |
struct object r; |
struct object r = OINIT; |
struct object tmp; |
struct object tmp = OINIT; |
int i,j; |
int i,j; |
int m,n; |
int m,n; |
POLY *mat; |
POLY *mat; |
Line 1351 struct arrayOfPOLY *arrayToArrayOfPOLY(oa) |
|
Line 1379 struct arrayOfPOLY *arrayToArrayOfPOLY(oa) |
|
POLY *a; |
POLY *a; |
int size; |
int size; |
int i; |
int i; |
struct object tmp; |
struct object tmp = OINIT; |
struct arrayOfPOLY *ap; |
struct arrayOfPOLY *ap; |
|
|
if (oa.tag != Sarray) errorKan1("KarrayToArrayOfPOLY(): %s", |
if (oa.tag != Sarray) errorKan1("KarrayToArrayOfPOLY(): %s", |
Line 1379 struct matrixOfPOLY *arrayToMatrixOfPOLY(oa) |
|
Line 1407 struct matrixOfPOLY *arrayToMatrixOfPOLY(oa) |
|
int i,j; |
int i,j; |
struct matrixOfPOLY *ma; |
struct matrixOfPOLY *ma; |
|
|
struct object tmp,tmp2; |
struct object tmp = OINIT; |
|
struct object tmp2 = OINIT; |
if (oa.tag != Sarray) errorKan1("KarrayToMatrixOfPOLY(): %s", |
if (oa.tag != Sarray) errorKan1("KarrayToMatrixOfPOLY(): %s", |
"Argument is not array\n"); |
"Argument is not array\n"); |
m = getoaSize(oa); |
m = getoaSize(oa); |
Line 1417 int objArrayToOrderMatrix(oA,order,n,oasize) |
|
Line 1446 int objArrayToOrderMatrix(oA,order,n,oasize) |
|
{ |
{ |
int size; |
int size; |
int k,j; |
int k,j; |
struct object tmpOa; |
struct object tmpOa = OINIT; |
struct object obj; |
struct object obj = OINIT; |
if (oA.tag != Sarray) { |
if (oA.tag != Sarray) { |
warningKan("The argument should be of the form [ [...] [...] ... [...]]."); |
warningKan("The argument should be of the form [ [...] [...] ... [...]]."); |
return(-1); |
return(-1); |
Line 1503 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1532 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
ob4 = Order matrix |
ob4 = Order matrix |
ob5 = [(keyword) value (keyword) value ....] |
ob5 = [(keyword) value (keyword) value ....] |
*/ |
*/ |
#define RP_LIMIT 500 |
#define RP_LIMIT 5000 |
{ |
{ |
int i; |
int i; |
struct object ob; |
struct object ob = OINIT; |
int c,l,m,n; |
int c,l,m,n; |
int cc,ll,mm,nn; |
int cc,ll,mm,nn; |
int p; |
int p; |
Line 1529 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1558 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
extern char *F_mpMult; |
extern char *F_mpMult; |
char *fmp_mult_saved; |
char *fmp_mult_saved; |
char *mpMultName = NULL; |
char *mpMultName = NULL; |
struct object rob; |
struct object rob = OINIT; |
struct ring *savedCurrentRingp; |
struct ring *savedCurrentRingp; |
|
|
/* To get the ring structure. */ |
/* To get the ring structure. */ |
Line 1631 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1660 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
newRingp->cc = cc; |
newRingp->cc = cc; |
newRingp->x = xvars; |
newRingp->x = xvars; |
newRingp->D = dvars; |
newRingp->D = dvars; |
|
newRingp->Dsmall = makeDsmall(dvars,n); |
/* You don't need to set order and orderMatrixSize here. |
/* You don't need to set order and orderMatrixSize here. |
It was set by setOrder(). */ |
It was set by setOrder(). */ |
setFromTo(newRingp); |
setFromTo(newRingp); |
Line 1704 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1734 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
errorKan1("%s\n","An array of array should be given. (degreeShift)"); |
errorKan1("%s\n","An array of array should be given. (degreeShift)"); |
} |
} |
{ |
{ |
struct object ods; |
struct object ods = OINIT; |
struct object ods2; |
struct object ods2 = OINIT; |
int dssize,k,j,nn; |
int dssize,k,j,nn; |
ods=getoa(ob5,i+1); |
ods=getoa(ob5,i+1); |
if ((getoaSize(ods) < 1) || (getoa(ods,0).tag != Sarray)) { |
if ((getoaSize(ods) < 1) || (getoa(ods,0).tag != Sarray)) { |
Line 1733 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1763 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
errorKan1("%s\n","An array of array should be given. (partialEcart)"); |
errorKan1("%s\n","An array of array should be given. (partialEcart)"); |
} |
} |
{ |
{ |
struct object odv; |
struct object odv = OINIT; |
struct object ovv; |
struct object ovv = OINIT; |
int k,j,nn; |
int k,j,nn; |
char *vname; |
char *vname; |
odv=getoa(ob5,i+1); |
odv=getoa(ob5,i+1); |
Line 1812 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
Line 1842 int KsetUpRing(ob1,ob2,ob3,ob4,ob5) |
|
struct object KsetVariableNames(struct object ob,struct ring *rp) |
struct object KsetVariableNames(struct object ob,struct ring *rp) |
{ |
{ |
int n,i; |
int n,i; |
struct object ox; |
struct object ox = OINIT; |
struct object otmp; |
struct object otmp = OINIT; |
char **xvars; |
char **xvars; |
char **dvars; |
char **dvars; |
if (ob.tag != Sarray) { |
if (ob.tag != Sarray) { |
Line 1858 struct object KswitchFunction(ob1,ob2) |
|
Line 1888 struct object KswitchFunction(ob1,ob2) |
|
struct object ob1,ob2; |
struct object ob1,ob2; |
{ |
{ |
char *ans ; |
char *ans ; |
struct object rob; |
struct object rob = OINIT; |
int needWarningForAvoidTheSameRing = 0; |
int needWarningForAvoidTheSameRing = 0; |
extern int AvoidTheSameRing; |
extern int AvoidTheSameRing; |
if ((ob1.tag != Sdollar) || (ob2.tag != Sdollar)) { |
if ((ob1.tag != Sdollar) || (ob2.tag != Sdollar)) { |
Line 1900 struct object KoReplace(of,rule) |
|
Line 1930 struct object KoReplace(of,rule) |
|
struct object of; |
struct object of; |
struct object rule; |
struct object rule; |
{ |
{ |
struct object rob; |
struct object rob = OINIT; |
POLY f; |
POLY f; |
POLY lRule[N0*2]; |
POLY lRule[N0*2]; |
POLY rRule[N0*2]; |
POLY rRule[N0*2]; |
POLY r; |
POLY r; |
int i; |
int i; |
int n; |
int n; |
struct object trule; |
struct object trule = OINIT; |
|
|
|
|
if (rule.tag != Sarray) { |
if (rule.tag != Sarray) { |
Line 1963 struct object Kparts(f,v) |
|
Line 1993 struct object Kparts(f,v) |
|
{ |
{ |
POLY ff; |
POLY ff; |
POLY vv; |
POLY vv; |
struct object obj; |
struct object obj = OINIT; |
struct matrixOfPOLY *co; |
struct matrixOfPOLY *co; |
/* check the data type */ |
/* check the data type */ |
if (f.tag != Spoly || v.tag != Spoly) |
if (f.tag != Spoly || v.tag != Spoly) |
Line 1980 struct object Kparts2(f,v) |
|
Line 2010 struct object Kparts2(f,v) |
|
{ |
{ |
POLY ff; |
POLY ff; |
POLY vv; |
POLY vv; |
struct object obj; |
struct object obj = OINIT; |
struct matrixOfPOLY *co; |
struct matrixOfPOLY *co; |
/* check the data type */ |
/* check the data type */ |
if (f.tag != Spoly || v.tag != Spoly) |
if (f.tag != Spoly || v.tag != Spoly) |
Line 2028 struct object Ksp(ob1,ob2) |
|
Line 2058 struct object Ksp(ob1,ob2) |
|
struct object ob1,ob2; |
struct object ob1,ob2; |
{ |
{ |
struct spValue sv; |
struct spValue sv; |
struct object rob,cob; |
struct object rob = OINIT; |
|
struct object cob = OINIT; |
POLY f; |
POLY f; |
if (ob1.tag != Spoly || ob2.tag != Spoly) |
if (ob1.tag != Spoly || ob2.tag != Spoly) |
errorKan1("%s\n","Ksp(): The arguments must be polynomials."); |
errorKan1("%s\n","Ksp(): The arguments must be polynomials."); |
Line 2058 struct object Keval(obj) |
|
Line 2089 struct object Keval(obj) |
|
{ |
{ |
char *key; |
char *key; |
int size; |
int size; |
struct object rob; |
struct object rob = OINIT; |
rob = NullObject; |
rob = NullObject; |
|
|
if (obj.tag != Sarray) |
if (obj.tag != Sarray) |
Line 2103 char *KremoveSpace(str) |
|
Line 2134 char *KremoveSpace(str) |
|
struct object KtoRecords(ob) |
struct object KtoRecords(ob) |
struct object ob; |
struct object ob; |
{ |
{ |
struct object obj; |
struct object obj = OINIT; |
struct object tmp; |
struct object tmp = OINIT; |
int i; |
int i; |
int size; |
int size; |
char **argv; |
char **argv; |
Line 2200 int KtoArgvbyCurryBrace(str,argv,limit) |
|
Line 2231 int KtoArgvbyCurryBrace(str,argv,limit) |
|
} |
} |
|
|
struct object KstringToArgv(struct object ob) { |
struct object KstringToArgv(struct object ob) { |
struct object rob; |
struct object rob = OINIT; |
char *s; |
char *s; |
int n,wc,i,inblank; |
int n,wc,i,inblank; |
char **argv; |
char **argv; |
Line 2240 struct object KstringToArgv(struct object ob) { |
|
Line 2271 struct object KstringToArgv(struct object ob) { |
|
return(rob); |
return(rob); |
} |
} |
|
|
|
struct object KstringToArgv2(struct object ob,struct object oseparator) { |
|
struct object rob = OINIT; |
|
char *s; |
|
int n,wc,i,inblank; |
|
char **argv; |
|
int separator; |
|
if (ob.tag != Sdollar) |
|
errorKan1("%s\n","KstringToArgv2(): the argument must be a string."); |
|
if (oseparator.tag == Sinteger) { |
|
separator = KopInteger(oseparator); |
|
}else if (oseparator.tag == Sdollar) { |
|
s = KopString(oseparator); |
|
separator=s[0]; |
|
}else { |
|
errorKan1("%s\n","KstringToArgv2(ob,separator):the argument must be strings."); |
|
} |
|
n = strlen(KopString(ob)); |
|
s = (char *) sGC_malloc(sizeof(char)*(n+2)); |
|
if (s == NULL) errorKan1("%s\n","KstringToArgv(): No memory."); |
|
strcpy(s,KopString(ob)); |
|
inblank = 1; wc = 0; |
|
for (i=0; i<n; i++) { |
|
if (inblank && (s[i] != separator)) { |
|
wc++; inblank = 0; |
|
}else if ((!inblank) && (s[i] == separator)) { |
|
inblank = 1; |
|
} |
|
} |
|
argv = (char **) sGC_malloc(sizeof(char *)*(wc+2)); |
|
argv[0] = NULL; |
|
inblank = 1; wc = 0; |
|
for (i=0; i<n; i++) { |
|
if (inblank && (s[i] != separator)) { |
|
argv[wc] = &(s[i]); argv[wc+1]=NULL; |
|
wc++; inblank = 0; |
|
}else if ((inblank == 0) && (s[i] == separator)) { |
|
inblank = 1; s[i] = 0; |
|
}else if (inblank && (s[i] == separator)) { |
|
s[i] = 0; |
|
} |
|
} |
|
|
|
rob = newObjectArray(wc); |
|
for (i=0; i<wc; i++) { |
|
putoa(rob,i,KpoString(argv[i])); |
|
/* printf("%s\n",argv[i]); */ |
|
} |
|
return(rob); |
|
} |
|
|
static void checkDuplicateName(xvars,dvars,n) |
static void checkDuplicateName(xvars,dvars,n) |
char *xvars[]; |
char *xvars[]; |
char *dvars[]; |
char *dvars[]; |
Line 2262 static void checkDuplicateName(xvars,dvars,n) |
|
Line 2343 static void checkDuplicateName(xvars,dvars,n) |
|
} |
} |
|
|
struct object KooPower(struct object ob1,struct object ob2) { |
struct object KooPower(struct object ob1,struct object ob2) { |
struct object rob; |
struct object rob = OINIT; |
/* Bug. It has not yet been implemented. */ |
/* Bug. It has not yet been implemented. */ |
if (QuoteMode) { |
if (QuoteMode) { |
rob = powerTree(ob1,ob2); |
rob = powerTree(ob1,ob2); |
Line 2384 struct object KgbExtension(struct object obj) |
|
Line 2465 struct object KgbExtension(struct object obj) |
|
{ |
{ |
char *key; |
char *key; |
int size; |
int size; |
struct object keyo; |
struct object keyo = OINIT; |
struct object rob = NullObject; |
struct object rob = NullObject; |
struct object obj1,obj2,obj3; |
struct object obj1 = OINIT; |
|
struct object obj2 = OINIT; |
|
struct object obj3 = OINIT; |
POLY f1; |
POLY f1; |
POLY f2; |
POLY f2; |
POLY f3; |
POLY f3; |
Line 2555 struct object KmpzExtension(struct object obj) |
|
Line 2638 struct object KmpzExtension(struct object obj) |
|
{ |
{ |
char *key; |
char *key; |
int size; |
int size; |
struct object keyo; |
struct object keyo = OINIT; |
struct object rob = NullObject; |
struct object rob = NullObject; |
struct object obj0,obj1,obj2,obj3; |
struct object obj0 = OINIT; |
|
struct object obj1 = OINIT; |
|
struct object obj2 = OINIT; |
|
struct object obj3 = OINIT; |
MP_INT *f; |
MP_INT *f; |
MP_INT *g; |
MP_INT *g; |
MP_INT *h; |
MP_INT *h; |
Line 2786 struct object KmpzExtension(struct object obj) |
|
Line 2872 struct object KmpzExtension(struct object obj) |
|
/** : context */ |
/** : context */ |
struct object KnewContext(struct object superObj,char *name) { |
struct object KnewContext(struct object superObj,char *name) { |
struct context *cp; |
struct context *cp; |
struct object ob; |
struct object ob = OINIT; |
if (superObj.tag != Sclass) { |
if (superObj.tag != Sclass) { |
errorKan1("%s\n","The argument of KnewContext must be a Class.Context"); |
errorKan1("%s\n","The argument of KnewContext must be a Class.Context"); |
} |
} |
Line 2805 struct object KcreateClassIncetance(struct object ob1, |
|
Line 2891 struct object KcreateClassIncetance(struct object ob1, |
|
struct object ob3) |
struct object ob3) |
{ |
{ |
/* [class-tag super-obj] size [class-tag] cclass */ |
/* [class-tag super-obj] size [class-tag] cclass */ |
struct object ob4; |
struct object ob4 = OINIT; |
int size,size2,i; |
int size,size2,i; |
struct object ob5; |
struct object ob5 = OINIT; |
struct object rob; |
struct object rob = OINIT; |
|
|
if (ob1.tag != Sarray) |
if (ob1.tag != Sarray) |
errorKan1("%s\n","cclass: The first argument must be an array."); |
errorKan1("%s\n","cclass: The first argument must be an array."); |
Line 2861 struct object KpoDouble(double a) { |
|
Line 2947 struct object KpoDouble(double a) { |
|
double toDouble0(struct object ob) { |
double toDouble0(struct object ob) { |
double r; |
double r; |
int r3; |
int r3; |
struct object ob2; |
struct object ob2 = OINIT; |
struct object ob3; |
struct object ob3 = OINIT; |
switch(ob.tag) { |
switch(ob.tag) { |
case Sinteger: |
case Sinteger: |
return( (double) (KopInteger(ob)) ); |
return( (double) (KopInteger(ob)) ); |
Line 2891 double toDouble0(struct object ob) { |
|
Line 2977 double toDouble0(struct object ob) { |
|
} |
} |
|
|
struct object KpoGradedPolySet(struct gradedPolySet *grD) { |
struct object KpoGradedPolySet(struct gradedPolySet *grD) { |
struct object rob; |
struct object rob = OINIT; |
rob.tag = Sclass; |
rob.tag = Sclass; |
rob.lc.ival = CLASSNAME_GradedPolySet; |
rob.lc.ival = CLASSNAME_GradedPolySet; |
rob.rc.voidp = (void *) grD; |
rob.rc.voidp = (void *) grD; |
Line 2908 static char *getspace0(int a) { |
|
Line 2994 static char *getspace0(int a) { |
|
return(s); |
return(s); |
} |
} |
struct object KdefaultPolyRing(struct object ob) { |
struct object KdefaultPolyRing(struct object ob) { |
struct object rob; |
struct object rob = OINIT; |
int i,j,k,n; |
int i,j,k,n; |
struct object ob1,ob2,ob3,ob4,ob5; |
struct object ob1 = OINIT; |
struct object t1; |
struct object ob2 = OINIT; |
|
struct object ob3 = OINIT; |
|
struct object ob4 = OINIT; |
|
struct object ob5 = OINIT; |
|
struct object t1 = OINIT; |
char *s1; |
char *s1; |
extern struct ring *CurrentRingp; |
extern struct ring *CurrentRingp; |
static struct ring *a[N0]; |
static struct ring *a[N0]; |
Line 3001 struct object Krest(struct object ob) { |
|
Line 3091 struct object Krest(struct object ob) { |
|
} |
} |
} |
} |
struct object Kjoin(struct object ob1, struct object ob2) { |
struct object Kjoin(struct object ob1, struct object ob2) { |
struct object rob; |
struct object rob = OINIT; |
int n1,n2,i; |
int n1,n2,i; |
if ((ob1.tag == Sarray) && (ob2.tag == Sarray)) { |
if ((ob1.tag == Sarray) && (ob2.tag == Sarray)) { |
n1 = getoaSize(ob1); n2 = getoaSize(ob2); |
n1 = getoaSize(ob1); n2 = getoaSize(ob2); |
Line 3025 struct object Kjoin(struct object ob1, struct object o |
|
Line 3115 struct object Kjoin(struct object ob1, struct object o |
|
} |
} |
|
|
struct object Kget(struct object ob1, struct object ob2) { |
struct object Kget(struct object ob1, struct object ob2) { |
struct object rob; |
struct object rob = OINIT; |
struct object tob; |
struct object tob = OINIT; |
int i,j,size,n; |
int i,j,size,n; |
if (ob2.tag == Sinteger) { |
if (ob2.tag == Sinteger) { |
i =ob2.lc.ival; |
i =ob2.lc.ival; |
Line 3059 struct object Kget(struct object ob1, struct object ob |
|
Line 3149 struct object Kget(struct object ob1, struct object ob |
|
ob1 = rob; |
ob1 = rob; |
} |
} |
return Kcar(ob1); |
return Kcar(ob1); |
|
} else if (ob1.tag == SbyteArray) { |
|
size = getByteArraySize(ob1); |
|
if ((0 <= i) && (i<size)) { |
|
return(KpoInteger(KopByteArray(ob1)[i])); |
|
}else{ |
|
errorKan1("%s\n","Kget: Index is out of bound. (get)\n"); |
|
} |
|
} else if (ob1.tag == Sdollar) { |
|
unsigned char *sss; |
|
sss = (unsigned char *) KopString(ob1); |
|
size = strlen(sss); |
|
if ((0 <= i) && (i<size)) { |
|
return(KpoInteger(sss[i])); |
|
}else{ |
|
errorKan1("%s\n","Kget: Index is out of bound. (get)\n"); |
|
} |
|
|
}else errorKan1("%s\n","Kget: argument must be an array or a list."); |
}else errorKan1("%s\n","Kget: argument must be an array or a list."); |
} |
} |
|
|
|
/* Constructor of byteArray */ |
|
struct object newByteArray(int size,struct object obj) { |
|
unsigned char *ba; |
|
unsigned char *ba2; |
|
struct object rob = OINIT; |
|
struct object tob = OINIT; |
|
int i,n; |
|
ba = NULL; |
|
if (size > 0) { |
|
ba = (unsigned char *) sGC_malloc(size); |
|
if (ba == NULL) errorKan1("%s\n","No more memory."); |
|
} |
|
rob.tag = SbyteArray; rob.lc.bytes = ba; rob.rc.ival = size; |
|
if (obj.tag == SbyteArray) { |
|
n = getByteArraySize(obj); |
|
ba2 = KopByteArray(obj); |
|
for (i=0; i<(n<size?n:size); i++) { |
|
ba[i] = ba2[i]; |
|
} |
|
for (i=n; i<size; i++) ba[i] = 0; |
|
return rob; |
|
}else if (obj.tag == Sarray) { |
|
n = getoaSize(obj); |
|
for (i=0; i<n; i++) { |
|
tob = getoa(obj,i); |
|
tob = Kto_int32(tob); |
|
if (tob.tag != Sinteger) errorKan1("%s\n","newByteArray: array is not an array of integer or universalNumber."); |
|
ba[i] = (unsigned char) KopInteger(tob); |
|
} |
|
for (i=n; i<size; i++) ba[i] = 0; |
|
return rob; |
|
}else{ |
|
for (i=0; i<size; i++) ba[i] = 0; |
|
return rob; |
|
} |
|
} |
|
struct object newByteArrayFromStr(char *s,int size) { |
|
unsigned char *ba; |
|
struct object rob = OINIT; |
|
int i; |
|
ba = NULL; |
|
if (size > 0) { |
|
ba = (unsigned char *) sGC_malloc(size); |
|
if (ba == NULL) errorKan1("%s\n","No more memory."); |
|
} |
|
rob.tag = SbyteArray; rob.lc.bytes = ba; rob.rc.ival = size; |
|
for (i=0; i<size; i++) { |
|
ba[i] = (char) s[i]; |
|
} |
|
return(rob); |
|
} |
|
|
|
struct object byteArrayToArray(struct object obj) { |
|
int n,i; unsigned char *ba; |
|
struct object rob = OINIT; |
|
if (obj.tag != SbyteArray) errorKan1("%s\n","byteArrayToArray: argument is not an byteArray."); |
|
n = getByteArraySize(obj); |
|
rob = newObjectArray(n); |
|
ba = KopByteArray(obj); |
|
for (i=0; i<n; i++) putoa(rob,i,KpoInteger((int) ba[i])); |
|
return rob; |
|
} |
|
|
|
struct object KgetAttributeList(struct object ob){ |
|
struct object rob = OINIT; |
|
if (ob.attr != NULL) rob = *(ob.attr); |
|
else rob = NullObject; |
|
return rob; |
|
} |
|
struct object KsetAttributeList(struct object ob,struct object attr) { |
|
ob.attr = newObject(); |
|
*(ob.attr) = attr; |
|
return ob; |
|
} |
|
struct object KgetAttribute(struct object ob,struct object key) { |
|
struct object rob = OINIT; |
|
struct object alist = OINIT; |
|
int n,i; |
|
struct object tob = OINIT; |
|
char *s; |
|
rob = NullObject; |
|
if (ob.attr == NULL) return rob; |
|
alist = *(ob.attr); |
|
if (alist.tag != Sarray) return rob; |
|
if (key.tag != Sdollar) return rob; |
|
s = KopString(key); |
|
n = getoaSize(alist); |
|
for (i = 0; i < n; i += 2) { |
|
tob = getoa(alist,i); |
|
if (tob.tag == Sdollar) { |
|
if (strcmp(KopString(tob),s) == 0) { |
|
if (i+1 < n) rob = getoa(alist,i+1); |
|
return rob; |
|
} |
|
} |
|
} |
|
return rob; |
|
} |
|
/* ob (key) (value) setAttribute /ob set. They are not destructive. */ |
|
struct object KsetAttribute(struct object ob,struct object key,struct object value) { |
|
struct object rob = OINIT; |
|
struct object alist = OINIT; |
|
int n,i; |
|
char *s = ""; |
|
struct object tob = OINIT; |
|
rob = ob; |
|
if (ob.attr == NULL) { |
|
rob.attr = newObject(); |
|
*(rob.attr) = newObjectArray(2); |
|
putoa((*(rob.attr)),0,key); |
|
putoa((*(rob.attr)),1,value); |
|
return rob; |
|
} |
|
alist = *(ob.attr); |
|
if (alist.tag != Sarray) return rob; |
|
if (key.tag != Sdollar) { |
|
s = KopString(key); |
|
} |
|
n = getoaSize(alist); |
|
for (i = 0; i < n; i += 2) { |
|
tob = getoa(alist,i); |
|
if (tob.tag == Sdollar) { |
|
if (strcmp(KopString(tob),s) == 0) { |
|
if (i+1 < n) putoa(alist,i+1,value); |
|
return rob; |
|
} |
|
} |
|
} |
|
|
|
rob.attr = newObject(); |
|
*(rob.attr) = newObjectArray(n+2); |
|
for (i=0; i<n; i++) { |
|
putoa((*(rob.attr)),i,getoa((*(ob.attr)),i)); |
|
} |
|
putoa((*(rob.attr)),n,key); |
|
putoa((*(rob.attr)),n+1,value); |
|
return rob; |
|
} |
|
|
/****************************************************************** |
/****************************************************************** |
error handler |
Error handler |
******************************************************************/ |
******************************************************************/ |
|
|
errorKan1(str,message) |
errorKan1(str,message) |
Line 3073 errorKan1(str,message) |
|
Line 3319 errorKan1(str,message) |
|
extern char *GotoLabel; |
extern char *GotoLabel; |
extern int GotoP; |
extern int GotoP; |
extern int ErrorMessageMode; |
extern int ErrorMessageMode; |
|
extern int RestrictedMode, RestrictedMode_saved; |
char tmpc[1024]; |
char tmpc[1024]; |
|
RestrictedMode = RestrictedMode_saved; |
cancelAlarm(); |
cancelAlarm(); |
if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { |
if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { |
sprintf(tmpc,"\nERROR(kanExport[0|1].c): "); |
sprintf(tmpc,"\nERROR(kanExport[0|1].c): "); |
Line 3096 errorKan1(str,message) |
|
Line 3344 errorKan1(str,message) |
|
stdOperandStack(); contextControl(CCRESTORE); |
stdOperandStack(); contextControl(CCRESTORE); |
/* fprintf(stderr,"Now. Long jump!\n"); */ |
/* fprintf(stderr,"Now. Long jump!\n"); */ |
#if defined(__CYGWIN__) |
#if defined(__CYGWIN__) |
siglongjmp(EnvOfStackMachine,1); |
MYSIGLONGJMP(EnvOfStackMachine,1); |
#else |
#else |
longjmp(EnvOfStackMachine,1); |
MYLONGJMP(EnvOfStackMachine,1); |
#endif |
#endif |
} |
} |
|
|