version 1.1, 2003/11/21 02:10:37 |
version 1.5, 2003/12/05 13:51:32 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/Kclass/tree.c,v 1.4 2003/11/24 08:16:13 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "../datatype.h" |
#include "../datatype.h" |
#include "../stackm.h" |
#include "../stackm.h" |
Line 19 struct object KpoTree(struct object ob) { |
|
Line 19 struct object KpoTree(struct object ob) { |
|
newobp = (struct object *) sGC_malloc(sizeof(struct object)); |
newobp = (struct object *) sGC_malloc(sizeof(struct object)); |
if (newobp == NULL) errorKan1("%s\n","Kclass/indeterminate.c, no more memory."); |
if (newobp == NULL) errorKan1("%s\n","Kclass/indeterminate.c, no more memory."); |
if (ob.tag != Sarray) { |
if (ob.tag != Sarray) { |
errorKan1("%s\n","Kclass/indeterminate.c, only properly formatted list object can be transformed into tree. [name, cdname, arglist]."); |
errorKan1("%s\n","Kclass/indeterminate.c, only properly formatted list object can be transformed into tree. [name, attr-list, arglist]."); |
} |
} |
if (getoaSize(ob) < 3) { |
if (getoaSize(ob) < 3) { |
errorKan1("%s\n","Kclass/indeterminate.c, the length must 3 or more than 3. [name, cdname, arglist]."); |
errorKan1("%s\n","Kclass/indeterminate.c, the length must 3 or more than 3. [name, attr-list, arglist]."); |
} |
} |
ob1 = getoa(ob,0); ob2 = getoa(ob,1); ob3 = getoa(ob,2); |
ob1 = getoa(ob,0); ob2 = getoa(ob,1); ob3 = getoa(ob,2); |
if (ob1.tag != Sdollar || ob2.tag != Sarray || ob3.tag != Sarray) { |
if (ob1.tag != Sdollar || ob2.tag != Sarray || ob3.tag != Sarray) { |
errorKan1("%s\n","Kclass/indeterminate.c, [string name, list attributes, list arglist]."); |
errorKan1("%s\n","Kclass/indeterminate.c, [string name, list attributes, list arglist]."); |
} |
} |
*newobp = ob; |
*newobp = ob; /* Add class-tag to the array */ |
rob.rc.voidp = newobp; |
rob.rc.voidp = newobp; |
return(rob); |
return(rob); |
} |
} |
Line 67 struct object addTree(struct object ob1, struct object |
|
Line 67 struct object addTree(struct object ob1, struct object |
|
{ |
{ |
struct object rob,aob; |
struct object rob,aob; |
struct object ob3,ob4; |
struct object ob3,ob4; |
|
struct object attr; |
|
struct object keyValue; |
int i; |
int i; |
if (isTreeAdd(ob1) && !isTreeAdd(ob2)) { |
if (isTreeAdd(ob1) && !isTreeAdd(ob2)) { |
ob1 = KopTree(ob1); |
ob1 = KopTree(ob1); |
Line 101 struct object addTree(struct object ob1, struct object |
|
Line 103 struct object addTree(struct object ob1, struct object |
|
putoa(aob,0,ob1); |
putoa(aob,0,ob1); |
putoa(aob,1,ob2); |
putoa(aob,1,ob2); |
} |
} |
|
attr = newObjectArray(1); |
|
keyValue = newObjectArray(2); |
|
putoa(keyValue,0,KpoString("arith1")); |
|
putoa(keyValue,1,KpoString("plus")); |
|
putoa(attr,0,keyValue); |
rob = newObjectArray(3); |
rob = newObjectArray(3); |
putoa(rob,0,KpoString("add")); |
putoa(rob,0,KpoString("add")); |
putoa(rob,1,KpoString("basic")); |
putoa(rob,1,attr); |
putoa(rob,2,aob); |
putoa(rob,2,aob); |
return(KpoTree(rob)); |
return(KpoTree(rob)); |
} |
} |
|
|
|
/* XML DOM-like interfaces */ |
|
struct object KtreeGetDocumentElement(struct object to) { |
|
struct object rob; |
|
struct object ob; |
|
if (to.tag != Sclass) errorKan1("%s\n","KtreeGetDocumentElement"); |
|
if (ectag(to) != CLASSNAME_tree) errorKan1("%s\n","KtreeGetDocumentElement"); |
|
ob = KopTree(to); |
|
if (ob.tag != Sarray) errorKan1("%s\n","KtreeGetDocumentElement: not an array."); |
|
if (getoaSize(ob) != 3) errorKan1("%s\n","KtreeGetDocumentElement: array is broken."); |
|
ob=getoa(ob,0); |
|
if (ob.tag != Sdollar) errorKan1("%s\n","KtreeGetDocumentElement: element must be a string"); |
|
return ob; |
|
} |
|
|
/*------------------------------------------*/ |
struct object KtreeGetAttributes(struct object to) { |
|
struct object rob; |
|
struct object ob; |
|
if (to.tag != Sclass) errorKan1("%s\n","KtreeGetAttributes:"); |
|
if (ectag(to) != CLASSNAME_tree) errorKan1("%s\n","KtreeGetAttributes:"); |
|
ob = KopTree(to); |
|
if (ob.tag != Sarray) errorKan1("%s\n","KtreeGetAttributes: not an array."); |
|
if (getoaSize(ob) != 3) errorKan1("%s\n","KtreeGetAttributes: array is broken."); |
|
return getoa(ob,1); |
|
} |
|
|
|
struct object KtreeGetChildNodes(struct object to) { |
|
struct object rob; |
|
struct object ob; |
|
if (to.tag != Sclass) errorKan1("%s\n","KtreeGetChildNodes:"); |
|
if (ectag(to) != CLASSNAME_tree) errorKan1("%s\n","KtreeGetChildNodes:"); |
|
ob = KopTree(to); |
|
if (ob.tag != Sarray) errorKan1("%s\n","KtreeGetChildNodes: not an array."); |
|
if (getoaSize(ob) != 3) errorKan1("%s\n","KtreeGetChildNodes: array is broken."); |
|
return getoa(ob,2); |
|
} |
|
|
|
struct object KtreeCreateElement(struct object ostr) { |
|
struct object ob; |
|
if (ostr.tag != Sdollar) errorKan1("%s\n","KtreeCreateElement: not a string."); |
|
ob = newObjectArray(3); |
|
getoa(ob,0)=ostr; |
|
getoa(ob,1) = newObjectArray(0); |
|
getoa(ob,2) = newObjectArray(0); |
|
return KpoTree(ob); |
|
} |
|
|