33 #include <libFreeWRL.h>
35 #include "../vrml_parser/Structs.h"
36 #include "../main/headers.h"
37 #include "../vrml_parser/CParseGeneral.h"
38 #include "../scenegraph/Vector.h"
39 #include "../vrml_parser/CFieldDecls.h"
40 #include "../world_script/JScript.h"
41 #include "../world_script/CScripts.h"
42 #include "../world_script/fieldSet.h"
43 #include "../vrml_parser/CParseParser.h"
44 #include "../vrml_parser/CParseLexer.h"
45 #include "../vrml_parser/CParse.h"
46 #include "../vrml_parser/CRoutes.h"
47 #include "../input/EAIHeaders.h"
48 #include "../input/EAIHelpers.h"
50 #include "X3DParser.h"
53 #include <libxml/parser.h>
55 typedef xmlSAXHandler* XML_Parser;
58 #define XML_GetCurrentLineNumber(aaa) (int)999
61 #define XML_ParserFree(aaa) FREE_IF_NZ(aaa)
62 #define XML_SetUserData(aaa,bbb)
63 #define XML_STATUS_ERROR -1
68 #define PARSING_NODES 1
69 #define PARSING_SCRIPT 2
70 #define PARSING_PROTODECLARE 3
71 #define PARSING_PROTOINTERFACE 4
72 #define PARSING_PROTOBODY 5
73 #define PARSING_PROTOINSTANCE 6
75 #define PARSING_CONNECT 8
76 #define PARSING_EXTERNPROTODECLARE 9
77 #define PARSING_FIELD 10
78 #define PARSING_PROTOINSTANCE_USE 11
81 #define PROTOINSTANCE_MAX_LEVELS 50
83 #define LINE freewrl_XML_GetCurrentLineNumber()
86 struct X3D_Node *broto_search_DEFname(
struct X3D_Proto *context,
const char *name);
87 static struct X3D_Node *DEFNameIndex (
const char *name,
struct X3D_Node* node,
int force);
99 ud->context = ud->nodes = ud->atts = ud->modes = ud->fields = NULL;
100 ud->context = newVector(
struct X3D_Node*,256);
102 ud->nodes = newVector(
struct X3D_Node*,256);
104 ud->atts = newVector(
void*,256);
106 ud->modes = newVector(
int,256);
108 ud->fields = newVector(
char *,256);
114 deleteVector(
struct X3D_Node*,ud->context);
115 deleteVector(
struct X3D_Node*,ud->nodes);
116 deleteVector(
void*,ud->atts);
117 deleteVector(
void*,ud->modes);
118 deleteVector(
void*,ud->fields);
131 static void pushContext(
void *userData,
struct X3D_Node* context){
133 if(context->_nodeType != NODE_Proto && context->_nodeType != NODE_Inline)
134 printf(
"attempt to cast a node of type %d to Proto\n",context->_nodeType);
135 stack_push(
struct X3D_Proto*,ud->context,X3D_PROTO(context));
137 static struct X3D_Proto* getContext(
void *userData,
int index){
141 return vector_get(
struct X3D_Proto*,ud->context, vectorSize(ud->context)+index);
143 return vector_get(
struct X3D_Proto*,ud->context, index);
145 static void popContext(
void *userData){
147 stack_pop(
struct X3D_Proto*,ud->context);
150 static void pushNode(
void *userData,
struct X3D_Node* node){
152 stack_push(
struct X3D_Node*,ud->nodes,node);
153 stack_push(
void* ,ud->atts,NULL);
155 static struct X3D_Node* getNode(
void *userData,
int index){
158 return vector_get(
struct X3D_Node*,ud->nodes, vectorSize(ud->nodes)+index);
160 return vector_get(
struct X3D_Node*,ud->nodes, index);
163 static void popNode(
void *userData){
165 stack_pop(
struct X3D_Node*,ud->nodes);
166 stack_pop(
void* ,ud->atts);
174 {PARSING_NODES,
"PARSING_NODES"},
175 {PARSING_SCRIPT,
"PARSING_SCRIPT"},
176 {PARSING_PROTODECLARE,
"PARSING_PROTODECLARE"},
177 {PARSING_PROTOINTERFACE,
"PARSING_PROTOINTERFACE"},
178 {PARSING_PROTOBODY,
"PARSING_PROTOBODY"},
179 {PARSING_PROTOINSTANCE,
"PARSING_PROTOINSTANCE"},
180 {PARSING_IS,
"PARSING_IS"},
181 {PARSING_CONNECT,
"PARSING_CONNECT"},
182 {PARSING_EXTERNPROTODECLARE,
"PARSING_EXTERNPROTODECLARE"},
183 {PARSING_FIELD,
"PARSING_FIELD"},
184 {PARSING_PROTOINSTANCE_USE,
"PARSING_PROTOINSTANCE_USE"},
188 static void pushMode(
void *userData,
int parsingmode){
190 stack_push(
int,ud->modes,parsingmode);
192 static int getMode(
void *userData,
int index){
196 return vector_get(
int,ud->modes, vectorSize(ud->modes)+index);
198 return vector_get(
int,ud->modes, index);
200 static void popMode(
void *userData){
202 stack_pop(
int,ud->modes);
205 static void pushField(
void *userData,
const char *fname){
207 stack_push(
char *,ud->fields,(
char *)fname);
208 if(0) printf(
"push n=%d\n",ud->fields->n);
210 static char * getField(
void *userData,
int index){
212 if(0) printf(
"get n=%d\n",ud->fields->n);
214 return vector_get(
char *,ud->fields, vectorSize(ud->fields)+index);
216 return vector_get(
char *,ud->fields, index);
219 static void popField(
void *userData){
221 stack_pop(
char *,ud->fields);
222 if(0) printf(
"pop n=%d\n",ud->fields->n);
225 static int XML_ParseFile(xmlSAXHandler *me,
void *user_data,
const char *myinput,
int myinputlen,
int recovery) {
227 if (xmlSAXUserParseMemory(me, user_data, myinput,myinputlen) == 0)
return 0;
228 return XML_STATUS_ERROR;
233 #define XML_CreateParserLevel(aaa) \
234 aaa = MALLOC(xmlSAXHandler *, sizeof (xmlSAXHandler)); \
235 bzero (aaa,sizeof(xmlSAXHandler));
237 #define XML_SetElementHandler(aaa,bbb,ccc) \
238 aaa->startElement = bbb; \
239 aaa->endElement = ccc;
242 #define XML_SetDefaultHandler(aaa,bbb)
243 #define XML_SetCdataSectionHandler(aaa,bbb,ccc) \
244 aaa->cdataBlock = endCDATA;
262 int CDATA_TextMallocSize;
264 int in3_3_fieldValue;
265 int in3_3_fieldIndex;
267 int X3DParserRecurseLevel;
268 XML_Parser x3dparser[PROTOINSTANCE_MAX_LEVELS];
269 XML_Parser currentX3DParser;
271 int currentParserMode[PROTOINSTANCE_MAX_LEVELS];
272 int currentParserModeIndex;
277 static void *X3DParser_constructor(){
283 void X3DParser_init(
struct tX3DParser *t){
286 t->CDATA_Text = NULL;
287 t->CDATA_Text_curlen = 0;
289 t->prv = X3DParser_constructor();
293 p->DEFedNodes = NULL;
295 p->CDATA_TextMallocSize = 0;
297 p->in3_3_fieldValue = FALSE;
298 p->in3_3_fieldIndex = INT_ID_UNDEFINED;
300 p->X3DParserRecurseLevel = INT_ID_UNDEFINED;
301 p->currentX3DParser = NULL;
303 p->currentParserModeIndex = 0;
309 void X3DParser_clear(
struct tX3DParser *t){
313 free_xml_user_data(p->user_data);
315 lexer_destroyData(p->myLexer);
316 FREE_IF_NZ(p->myLexer);
326 #ifdef X3DPARSERVERBOSE
327 static const char *parserModeStrings[] = {
331 "PARSING_PROTODECLARE ",
332 "PARSING_PROTOINTERFACE ",
334 "PARSING_PROTOINSTANCE",
337 "PARSING_EXTERNPROTODECLARE",
340 #undef X3DPARSERVERBOSE
344 int freewrl_XML_GetCurrentLineNumber(
void) {
346 if (p->X3DParserRecurseLevel > INT_ID_UNDEFINED)
348 p->currentX3DParser = p->x3dparser[p->X3DParserRecurseLevel];
349 return (
int) XML_GetCurrentLineNumber(p->currentX3DParser);
351 return INT_ID_UNDEFINED;
406 char *X3DParser_getNameFromNode(
struct X3D_Node* myNode) {
412 if (!p->DEFedNodes)
return NULL;
416 for (ind=0; ind<vectorSize(stack_top(
struct Vector*, p->DEFedNodes)); ind++) {
417 node=vector_get(
struct X3D_Node*, stack_top(
struct Vector*, p->DEFedNodes),ind);
421 if (myNode == node) {
424 ns = stack_top(
struct Vector*, p->myLexer->userNodeNames);
425 return ((
char *)vector_get (
const char*, ns,ind));
434 struct X3D_Node *X3DParser_getNodeFromName(
const char *name) {
435 return DEFNameIndex(name,NULL,FALSE);
443 void kill_X3DDefs(
void) {
450 printf (
"kill_X3DDefs... DEFedNodes %p\n",p->DEFedNodes);
451 printf (
"kill_X3DDefs... myLexer %p\n",p->myLexer);
453 if (p->DEFedNodes != NULL) {
454 for (i=0; i<vectorSize(p->DEFedNodes); i++) {
455 struct Vector * myele = vector_get (
struct Vector*, p->DEFedNodes, i);
460 deleteVector (
struct Vector *,myele);
462 deleteVector(
struct Vector*, p->DEFedNodes);
463 p->DEFedNodes = NULL;
467 if (p->myLexer != NULL) {
468 lexer_destroyData(p->myLexer);
469 deleteLexer(p->myLexer);
474 Parser_deleteParserForScanStringValueToMem();
481 static struct X3D_Node *DEFNameIndex (
const char *name,
struct X3D_Node* node,
int force) {
486 #ifdef X3DPARSERVERBOSE
487 printf (
"DEFNameIndex, p is %p\n",p);
488 printf (
"DEFNameIndex, looking for :%s:, force %d nodePointer %u\n",name,force,node);
489 printf (
"DEFNameIndex, p->myLexer %p\n",p->myLexer);
490 printf (
"DEFNameIndex, stack %p\n",p->DEFedNodes);
491 printf (
"DEFNameIndex, p->user_data %p\n",p->user_data);
494 if (p->user_data != NULL) {
497 struct X3D_Proto *context2 = getContext(ud,TOP);
499 if (ud->context != NULL) {
503 node = broto_search_DEFname(context2,name);
511 #ifdef X3DPARSERVERBOSE
512 if (node != NULL) printf (
"DEFNameIndex for %s, returning %u, nt %s\n",
513 name, node,stringNodeType(node->_nodeType));
514 else printf (
"DEFNameIndex, node is NULL\n");
520 #undef X3DPARSERVERBOSE
524 int getFieldFromNodeAndName(
struct X3D_Node* node,
const char *fieldname,
int *type,
int *kind,
int *iifield,
union anyVrml **value);
525 void broto_store_route(
struct X3D_Proto* proto,
struct X3D_Node* fromNode,
int fromOfs,
struct X3D_Node* toNode,
int toOfs,
int ft);
527 void broto_store_ImportRoute(
struct X3D_Proto* proto,
char *fromNode,
char *fromField,
char *toNode,
char* toField);
531 static int QA_routeEnd(
struct X3D_Proto *context,
char* cnode,
char* cfield,
struct brouteEnd* brend,
int isFrom){
537 brend->cfield = STRDUP(cfield);
538 brend->cnode = STRDUP(cnode);
540 node = broto_search_DEFname(context,cnode);
543 imp = broto_search_IMPORTname(context, cnode);
550 int type,kind,ifield,source;
553 if(isFrom) idir = PKW_outputOnly;
554 else idir = PKW_inputOnly;
555 found = find_anyfield_by_nameAndRouteDir(node,&value,&kind,&type,cfield,&source,&decl,&ifield,idir);
560 brend->ifield = ifield;
567 void QAandRegister_parsedRoute_B(
struct X3D_Proto *context,
char* fnode,
char* ffield,
char* tnode,
char* tfield){
572 int haveFrom, haveTo, ok;
575 int allowingVeryWeakRoutes = 1;
578 route = createNewBrotoRoute();
579 haveFrom = QA_routeEnd(context, fnode, ffield, &route->from, 1);
580 haveTo = QA_routeEnd(context, tnode, tfield, &route->to, 0);
581 if((haveFrom && haveTo) || allowingVeryWeakRoutes){
584 if( !route->from.weak) ftf = route->from.ftype;
585 if( !route->to.weak) ftt = route->to.ftype;
586 route->ft = ftf > -1 ? ftf : ftt > -1? ftt : -1;
587 route->lastCommand = 0;
588 if(ftf == ftt && ftf > -1){
590 int pflags = context->__protoFlags;
591 char oldwayflag = ciflag_get(pflags,1);
592 char instancingflag = ciflag_get(pflags,0);
593 if(oldwayflag || instancingflag){
594 CRoutes_RegisterSimpleB(route->from.node, route->from.ifield, route->to.node, route->to.ifield, route->ft);
595 route->lastCommand = 1;
600 }
else if(route->to.weak || route->from.weak){
605 if(ok || allowingVeryWeakRoutes)
606 broto_store_broute(context,route);
607 if(!ok || !(haveFrom && haveTo)){
608 ConsoleMessage(
"Routing problem: ");
610 if (haveFrom && haveTo && route->from.ftype != route->to.ftype) {
611 ConsoleMessage (
"type mismatch %s != %s, ",stringFieldtypeType(route->from.ftype), stringFieldtypeType(route->to.ftype));
613 if(!haveFrom) ConsoleMessage(
" _From_ ");
614 if(!haveTo) ConsoleMessage(
" _To_ ");
615 ConsoleMessage (
"from %s %s, ",fnode,ffield);
616 ConsoleMessage (
"to %s %s\n",tnode,tfield);
623 static void parseRoutes_B (
void *ud,
char **atts) {
634 char *ffield, *tfield, *fnode, *tnode;
636 context = getContext(ud,TOP);
638 ffield = tfield = fnode = tnode = NULL;
639 for (i = 0; atts[i]; i += 2) {
640 if (strcmp(
"fromNode",atts[i]) == 0) {
642 }
else if (strcmp(
"toNode",atts[i]) == 0) {
644 }
else if (strcmp(
"fromField",atts[i])==0) {
646 }
else if (strcmp(
"toField",atts[i]) ==0) {
650 QAandRegister_parsedRoute_B(context, fnode, ffield, tnode, tfield);
696 int getFieldFromNodeAndName(
struct X3D_Node* node,
const char *fieldname,
int *type,
int *kind,
int *iifield,
union anyVrml **value);
697 int indexChildrenName(
struct X3D_Node *node);
699 #define PPX(A) getTypeNode(X3D_NODE(A)) //possible proto expansion
703 static void linkNodeIn_B(
void *ud) {
722 struct X3D_Node *node, *typenode, *parent;
723 char *parentsSuggestion;
724 int type, kind, iifield, ok, isRootNode, mode;
728 mode = getMode(ud,TOP);
729 node = getNode(ud,TOP);
730 typenode = PPX(node);
731 parent = getNode(ud,TOP-1);
732 if(!node || !parent)
return;
733 if(node && !typenode)
736 if(parent->_nodeType == NODE_Proto){
737 if(mode == PARSING_PROTOBODY) isRootNode = TRUE;
745 union anyVrml *valueadd = NULL;
746 ok = getFieldFromNodeAndName(parent,
"__children",&type,&kind,&iifield,&valueadd);
747 AddRemoveChildren(parent,&valueadd->mfnode,&node,1,1,__FILE__,__LINE__);
750 unsigned int iContainer, jContainer, defaultContainer[3];
752 parentsSuggestion = getField(ud,TOP-1);
755 jContainer = typenode->_defaultContainer;
758 defaultContainer[0] = (jContainer << 22) >> 22;
759 defaultContainer[1] = (jContainer << 12) >> 22;
760 defaultContainer[2] = (jContainer << 2) >> 22;
762 if(defaultContainer[1])
764 if(defaultContainer[2])
766 for(i=0;i<ncontainer;i++){
767 iContainer = defaultContainer[i];
768 if(iContainer == FIELDNAMES_children) iContainer = 0;
773 fname = FIELDNAMES[iContainer];
774 ok = getFieldFromNodeAndName(parent,fname,&type,&kind,&iifield,&value);
775 ok = ok && (kind == PKW_initializeOnly || kind == PKW_inputOutput);
777 if(!value && iContainer == FIELDNAMES_children){
780 ok = getFieldFromNodeAndName(parent,
"children",&type,&kind,&iifield,&value);
781 ok = ok && (kind == PKW_initializeOnly || kind == PKW_inputOutput);
783 int kids = indexChildrenName(parent);
785 value = (
union anyVrml*)childrenField(parent);
786 type = FIELDTYPE_MFNode;
795 if(!ok && parentsSuggestion) {
802 ok =getFieldFromNodeAndName(parent,parentsSuggestion,&type,&kind,&iifield,&value);
805 if(!value && parent){
806 ok = getFieldFromNodeAndName(parent,
"children",&type,&kind,&iifield,&value);
808 int kids = indexChildrenName(parent);
810 value = (
union anyVrml*)childrenField(parent);
811 type = FIELDTYPE_MFNode;
817 if(type == FIELDTYPE_SFNode){
818 value->sfnode = node;
819 ADD_PARENT(node,parent);
820 }
else if(type == FIELDTYPE_MFNode){
821 union anyVrml *valueadd = NULL;
823 if(parent->_nodeType == NODE_Proto){
824 struct X3D_Proto *pparent = X3D_PROTO(parent);
825 char cflag = ciflag_get(pparent->__protoFlags,2);
827 ok = getFieldFromNodeAndName(parent,
"addChildren",&type,&kind,&iifield,&valueadd);
830 AddRemoveChildren(parent,&valueadd->mfnode,&node,1,1,__FILE__,__LINE__);
832 AddRemoveChildren(parent,&value->mfnode,&node,1,1,__FILE__,__LINE__);
835 printf(
"no where to put node in parent\n");
836 printf(
"nodetype=%s parenttype=%s\n",stringNodeType(node->_nodeType),stringNodeType(parent->_nodeType));
844 void Parser_scanStringValueToMem_B(
union anyVrml* any, indexT ctype,
const char *value,
int isXML);
846 static void endCDATA_B (
void *ud,
const xmlChar *
string,
int len) {
847 char *fieldname = getField(ud,TOP);
848 struct X3D_Node *node = getNode(ud,TOP);
849 int type, kind, iifield, ok, handled;
851 ok = getFieldFromNodeAndName(node,fieldname,&type,&kind,&iifield,&value);
854 if(!strcmp(fieldname,
"url")){
856 if(strstr((
char*)
string,
"script")){
858 value->mfstring.n = 1;
859 value->mfstring.p = MALLOCV(
sizeof(
void *));
860 value->mfstring.p[0] = newASCIIString((
char *)
string);
865 Parser_scanStringValueToMem_B(value, type, (
const char*)
string, TRUE);
869 void endCDATA (
void *ud,
const xmlChar *
string,
int len) {
870 endCDATA_B(ud,
string,len);
876 void handleImport_B (
struct X3D_Node *nodeptr,
char *nodeName,
char *nodeImport,
char *as);
877 static void parseImport_B(
void *ud,
char **atts) {
879 char *inlinedef, *exporteddef, *as;
881 context = getContext(ud,TOP);
883 inlinedef = exporteddef = as = NULL;
884 for (i = 0; atts[i]; i += 2) {
885 printf(
"import field:%s=%s\n", atts[i], atts[i + 1]);
886 if(!strcmp(atts[i],
"inlineDEF")) inlinedef = atts[i+1];
887 if(!strcmp(atts[i],
"exportedDEF")) exporteddef = atts[i+1];
888 if(!strcmp(atts[i],
"AS")) as = atts[i+1];
891 handleImport_B (X3D_NODE(context), inlinedef, exporteddef, as);
895 void handleExport_B (
void *nodeptr,
char *node,
char *as);
896 static void parseExport_B(
void *ud,
char **atts) {
901 context = getContext(ud,TOP);
903 localdef = as = NULL;
904 for (i = 0; atts[i]; i += 2) {
905 printf(
"export field:%s=%s\n", atts[i], atts[i + 1]);
906 if(!strcmp(atts[i],
"localDEF")) localdef = atts[i+1];
907 if(!strcmp(atts[i],
"AS")) as = atts[i+1];
909 handleExport_B(context,localdef, as);
914 static void parseComponent(
char **atts) {
916 int myComponent = INT_ID_UNDEFINED;
917 int myLevel = INT_ID_UNDEFINED;
920 for (i = 0; atts[i]; i += 2) {
922 if (strcmp(
"level",atts[i]) == 0) {
923 if (sscanf(atts[i+1],
"%d",&myLevel) != 1) {
924 ConsoleMessage (
"Line %d: Expected Component level for component %s, got %s",LINE, atts[i], atts[i+1]);
927 }
else if (strcmp(
"name",atts[i]) == 0) {
928 myComponent = findFieldInCOMPONENTS(atts[i+1]);
929 if (myComponent == INT_ID_UNDEFINED) {
930 ConsoleMessage(
"Line %d: Component statement, but component name not valid :%s:",LINE,atts[i+1]);
935 ConsoleMessage (
"Line %d: Unknown fields in Component statement :%s: :%s:",LINE,atts[i], atts[i+1]);
939 if (myComponent == INT_ID_UNDEFINED) {
940 ConsoleMessage(
"Line %d: Component statement, but component name not stated",LINE);
941 }
else if (myLevel == INT_ID_UNDEFINED) {
942 ConsoleMessage(
"Line %d: Component statement, but component level not stated",LINE);
944 handleComponent(myComponent,myLevel);
949 static void parseX3Dhead(
char **atts) {
951 int myProfile = -10000;
952 int versionIndex = INT_ID_UNDEFINED;
954 for (i = 0; atts[i]; i += 2) {
956 if (strcmp(
"profile",atts[i]) == 0) {
957 myProfile = findFieldInPROFILES(atts[i+1]);
958 }
else if (strcmp(
"version",atts[i]) == 0) {
966 if (myProfile == INT_ID_UNDEFINED) {
967 ConsoleMessage (
"expected valid profile in X3D header");
970 if (myProfile >= 0) handleProfile (myProfile);
973 if (versionIndex != INT_ID_UNDEFINED) {
974 handleVersion (atts[versionIndex]);
978 static void parseHeader(
char **atts) {
980 for (i = 0; atts[i]; i += 2) {
984 static void parseScene(
char **atts) {
986 for (i = 0; atts[i]; i += 2) {
990 static void parseMeta(
char **atts) {
992 for (i = 0; atts[i]; i += 2) {
996 void deleteMallocedFieldValue(
int type,
union anyVrml *fieldPtr);
997 static void parseFieldValue_B(
void *ud,
char **atts) {
998 int i, type, kind, iifield, ok;
999 const char *fname, *svalue, *cname;
1001 struct X3D_Node *node = getNode(ud,TOP);
1003 if(0) printf(
"parseFieldValue\n");
1004 fname = svalue = NULL;
1005 for(i=0;atts[i];i+=2){
1006 if(!strcmp(atts[i],
"name")) fname = atts[i+1];
1007 if(!strcmp(atts[i],
"value")) svalue = atts[i+1];
1013 ok = getFieldFromNodeAndName(node,fname,&type,&kind,&iifield,&value);
1016 ok = getFieldFromNodeAndIndex(node, iifield, &cname, &type, &kind, &value);
1019 if(cname && value && svalue){
1020 deleteMallocedFieldValue(type,value);
1021 Parser_scanStringValueToMem_B(value,type,svalue,TRUE);
1023 if(cname && (node->_nodeType == NODE_Proto)){
1033 pnode = X3D_PROTO(node);
1035 pfield = vector_get(
struct ProtoFieldDecl*,pstruct->iface,iifield);
1039 if(pfield->type == FIELDTYPE_MFNode){
1040 struct Multi_Node* mfn = &pfield->defaultVal.mfnode;
1042 AddRemoveChildren(node,mfn,mfn->p,mfn->n,2,__FILE__,__LINE__);
1043 pfield->defaultVal.mfnode.n = 0;
1044 pfield->defaultVal.mfnode.p = NULL;
1046 if(pfield->type == FIELDTYPE_SFNode){
1047 struct X3D_Node **sfn = &pfield->defaultVal.sfnode;
1049 AddRemoveSFNodeFieldChild(node,sfn,*sfn,2,__FILE__,__LINE__);
1050 pfield->defaultVal.sfnode = NULL;
1052 pfield->alreadySet = TRUE;
1055 pushField(ud,cname);
1057 static void endFieldValue_B(
void *ud){
1058 if(0) printf(
"endFieldValue\n");
1065 static void parseIS(
void *ud) {
1066 #ifdef X3DPARSERVERBOSE
1067 printf (
"parseIS mode is %s\n",parserModeStrings[getMode(ud,TOP)]);
1069 pushMode(ud,PARSING_IS);
1075 static void endIS(
void *ud) {
1076 #ifdef X3DPARSERVERBOSE
1077 printf (
"endIS mode is %s\n",parserModeStrings[getMode(ud,TOP)]);
1084 static void endProtoInterfaceTag(
void *ud) {
1085 if (getMode(ud,TOP) != PARSING_PROTOINTERFACE) {
1086 ConsoleMessage (
"endProtoInterfaceTag: got a </ProtoInterface> but not parsing one at line %d",LINE);
1092 static void endProtoBodyTag_B(
void *ud,
const char *name) {
1094 if (getMode(ud,TOP) != PARSING_PROTOBODY) {
1095 ConsoleMessage (
"endProtoBodyTag: got a </ProtoBody> but not parsing one at line %d",LINE);
1101 static void endExternProtoDeclareTag_B(
void *ud) {
1107 static void endProtoDeclareTag_B(
void *ud) {
1112 if (getMode(ud,TOP) != PARSING_PROTODECLARE) {
1113 ConsoleMessage (
"endProtoDeclareTag: got a </ProtoDeclare> but not parsing one at line %d",LINE);
1114 pushMode(ud,PARSING_PROTODECLARE);
1116 if(0) printf(
"end protoDeclare\n");
1118 proto = X3D_PROTO(getNode(ud,TOP));
1120 if(proto->__children.n)
1121 cptr = &proto->__children;
1122 else if(proto->addChildren.n)
1123 cptr = &proto->addChildren;
1126 if(c1->_defaultContainer > INT_ID_UNDEFINED)
1127 proto->_defaultContainer = c1->_defaultContainer;
1136 static void endProtoInstance_B(
void *ud,
const char *name) {
1140 if(0) printf(
"endProtoInstance_B\n");
1142 node = getNode(ud,TOP);
1143 mode = getMode(ud,TOP);
1145 if(node->_nodeType == NODE_Proto || node->_nodeType == NODE_Inline ){
1146 if(mode != PARSING_PROTOINSTANCE_USE){
1148 struct X3D_Proto *pnode = X3D_PROTO(node);
1149 pflagdepth = ciflag_get(pnode->__protoFlags,0);
1155 pdeclare = X3D_PROTO(pnode->__prototype);
1160 deep_copy_broto_body2(&pdeclare,&pnode);
1188 void **shaderFields(
struct X3D_Node* node){
1190 switch(node->_nodeType){
1192 shaderfield = &X3D_SCRIPT(node)->__scriptObj;
break;
1193 case NODE_ComposedShader:
1194 shaderfield = (
void**)&X3D_COMPOSEDSHADER(node)->_shaderUserDefinedFields;
break;
1196 shaderfield = (
void**)&X3D_EFFECT(node)->_shaderUserDefinedFields;
break;
1197 case NODE_ShaderProgram:
1198 shaderfield = (
void**)&X3D_SHADERPROGRAM(node)->_shaderUserDefinedFields;
break;
1199 case NODE_PackagedShader:
1200 shaderfield = (
void**)&X3D_PACKAGEDSHADER(node)->_shaderUserDefinedFields;
break;
1207 void broto_store_DEF(
struct X3D_Proto* proto,
struct X3D_Node* node,
const char *name);
1208 static void parseAttributes_B(
void *ud,
char **atts);
1209 void add_node_to_broto_context(
struct X3D_Proto *context,
struct X3D_Node *node);
1210 void push_binding_stack_set(
struct X3D_Node* layersetnode);
1211 void push_next_layerId_from_binding_stack_set(
struct X3D_Node* layer);
1212 void pop_binding_stack_set();
1214 static void startBuiltin_B(
void *ud,
int myNodeType,
const xmlChar *name,
char** atts) {
1215 struct X3D_Node *node, *fromDEFtable;
1220 const char *defname, *suggestedChildField, *containerfield;
1222 suggestedChildField = containerfield = NULL;
1223 context = getContext(ud,TOP);
1224 pflagdepth = ciflag_get(context->__protoFlags,0);
1225 if(0) printf(
"start builtin %s\n",name);
1230 for (i = 0; atts[i]; i += 2) {
1232 if (strcmp (
"DEF",atts[i]) == 0) {
1233 defname = atts[i+1];
1234 fromDEFtable = broto_search_DEFname(context,defname);
1236 #ifdef X3DPARSERVERBOSE
1237 printf (
"Warning - line %d duplicate DEF name: \'%s\'\n",LINE,atts[i+1]);
1240 }
else if (strcmp (
"USE",atts[i]) == 0) {
1241 #ifdef X3DPARSERVERBOSE
1242 printf (
"this is a USE, name %s\n",atts[i+1]);
1246 fromDEFtable = broto_search_DEFname(context,atts[i+1]);
1247 if (!fromDEFtable) {
1248 ConsoleMessage (
"Warning - line %d DEF name: \'%s\' not found",LINE,atts[i+1]);
1249 ConsoleMessage(
"\n");
1251 #ifdef X3DPARSERVERBOSE
1252 printf (
"copying for field %s defName %s\n",atts[i], atts[i+1]);
1256 if (myNodeType != fromDEFtable->_nodeType) {
1257 ConsoleMessage (
"Warning, line %d DEF/USE mismatch, '%s', %s != %s", LINE,
1258 atts[i+1],stringNodeType(fromDEFtable->_nodeType), stringNodeType (myNodeType));
1261 node = fromDEFtable;
1262 node->referenceCount++;
1264 #ifdef X3DPARSERVERBOSE
1265 printf (
"successful copying for field %s defName %s\n",atts[i], atts[i+1]);
1270 }
else if(!strcmp(atts[i],
"containerField")) containerfield = atts[i+1];
1275 node = createNewX3DNode(myNodeType);
1277 node = createNewX3DNode0(myNodeType);
1279 broto_store_DEF(context,node,defname);
1283 if(containerfield) {
1285 int builtinField = findFieldInFIELDNAMES(containerfield);
1286 if(builtinField > INT_ID_UNDEFINED){
1291 node->_defaultContainer = (node->_defaultContainer << 10) + builtinField;
1299 shaderfield = shaderFields(node);
1301 (*shaderfield) = (
void *)new_Shader_ScriptB(node);
1304 if(node->_nodeType == NODE_LayerSet)
1305 push_binding_stack_set(node);
1306 if(node->_nodeType == NODE_Layer || node->_nodeType == NODE_LayoutLayer)
1307 push_next_layerId_from_binding_stack_set(node);
1308 if(node->_nodeType == NODE_Inline)
1309 X3D_INLINE(node)->__parentProto = X3D_NODE(context);
1310 node->_executionContext = X3D_NODE(context);
1311 add_node_to_broto_context(context,node);
1313 kids = indexChildrenName(node);
1315 suggestedChildField = FIELDNAMES[kids];
1316 if(node->_nodeType == NODE_Script || node->_nodeType == NODE_ShaderPart
1317 || node->_nodeType == NODE_ShaderProgram || node->_nodeType == NODE_EffectPart)
1318 suggestedChildField = FIELDNAMES[FIELDNAMES_url];
1320 pushField(ud,suggestedChildField);
1322 parseAttributes_B(ud,atts);
1330 static void endBuiltin_B(
void *ud,
const xmlChar *name){
1334 node = getNode(ud,TOP);
1335 context = getContext(ud,TOP);
1336 if(0)printf(
"end builtin %s\n",name);
1337 pflagdepth = ciflag_get(context->__protoFlags,0);
1338 if(node->_nodeType == NODE_Script && pflagdepth){
1341 initialize_one_script(sn->__scriptObj,&sn->url);
1344 if(node->_nodeType == NODE_LayerSet)
1345 pop_binding_stack_set();
1354 static xmlChar* fixAmp(
const unsigned char *InFieldValue)
1356 char *fieldValue = (
char *)InFieldValue;
1365 char *pp = strstr((
char *)fieldValue,
"&");
1367 memmove(pp+1,pp+5,strlen(fieldValue) - (pp+1 - fieldValue));
1368 pp = strstr(pp,
"&");
1381 return (xmlChar *)fieldValue;
1383 static void parseAttributes_B(
void *ud,
char **atts) {
1384 int i, type, kind, iifield;
1386 char *name, *svalue;
1387 const char *ignore [] = {
"containerField",
"USE",
"DEF"};
1390 node = getNode(ud,TOP);
1391 for (i=0; atts[i]; i+=2) {
1395 if(findFieldInARR(name,ignore,3) == INT_ID_UNDEFINED){
1396 if(getFieldFromNodeAndName(node,name,&type,&kind,&iifield,&value)){
1397 deleteMallocedFieldValue(type,value);
1398 Parser_scanStringValueToMem_B(value, type,svalue, TRUE);
1401 if(!strcmp(name,
"side")){
1403 if(!strcmp(svalue,
"left"))
1404 node->_renderFlags |= VF_HideRight;
1405 else if(!strcmp(svalue,
"right"))
1406 node->_renderFlags |= VF_HideLeft;
1413 int findFieldInARR(
const char* field,
const char** arr,
size_t cnt);
1414 static void parseScriptProtoField_B(
void *ud,
char **atts) {
1423 int mp_name, mp_accesstype, mp_type, mp_value, i;
1426 char *fname, *cname;
1429 mp_name = mp_accesstype = mp_type = mp_value = ID_UNDEFINED;
1430 if(0) printf(
"start scriptProtoField\n");
1432 for (i = 0; atts[i]; i += 2) {
1434 if ((strcmp(
"appinfo", atts[i]) != 0) &&
1435 (strcmp(
"documentation",atts[i]) != 0)) {
1436 if (strcmp(atts[i],
"name") == 0) { mp_name = i+1;
1437 }
else if (strcmp(atts[i],
"accessType") == 0) { mp_accesstype = i+1;
1438 }
else if (strcmp(atts[i],
"type") == 0) { mp_type = i+1;
1439 }
else if (strcmp(atts[i],
"value") == 0) { mp_value = i+1;
1441 ConsoleMessage (
"X3D Proto/Script parsing line %d: unknown field type %s",LINE,atts[i]);
1446 if(mp_accesstype > -1 && mp_type > -1 && mp_name > -1){
1448 pkwmode = findFieldInARR(atts[mp_accesstype], PROTOKEYWORDS, PROTOKEYWORDS_COUNT);
1449 pkwmode = pkwmode > -1? X3DMODE(pkwmode) : pkwmode;
1450 type = findFieldInARR(atts[mp_type],FIELDTYPES,FIELDTYPES_COUNT);
1451 fname = atts[mp_name];
1454 bzero(&defaultValue,
sizeof (
union anyVrml));
1455 if(type == FIELDTYPE_SFString)
1456 defaultValue.sfstring = newASCIIString(
"");
1459 Parser_scanStringValueToMem_B(&defaultValue, type, atts[mp_value], TRUE);
1462 if(pkwmode > -1 && type > -1){
1463 struct X3D_Node * node = getNode(ud,TOP);
1464 if(node->_nodeType == NODE_Proto){
1468 pnode = X3D_PROTO(node);
1470 pfield = newProtoFieldDecl(pkwmode,type,0);
1471 pfield->cname = STRDUP(fname);
1472 cname = pfield->cname;
1473 memcpy(&pfield->defaultVal,&defaultValue,
sizeof(
union anyVrml));
1480 switch(node->_nodeType)
1482 case NODE_Script: shader =(
struct Shader_Script *)(X3D_SCRIPT(node)->__scriptObj);
break;
1483 case NODE_ComposedShader: shader =(
struct Shader_Script *)(X3D_COMPOSEDSHADER(node)->_shaderUserDefinedFields);
break;
1484 case NODE_Effect: shader =(
struct Shader_Script *)(X3D_EFFECT(node)->_shaderUserDefinedFields);
break;
1485 case NODE_ShaderProgram: shader =(
struct Shader_Script *)(X3D_SHADERPROGRAM(node)->_shaderUserDefinedFields);
break;
1486 case NODE_PackagedShader: shader =(
struct Shader_Script *)(X3D_PACKAGEDSHADER(node)->_shaderUserDefinedFields);
break;
1488 jsname = JSparamIndex (fname, atts[mp_type]);
1489 cname = getJSparamnames()[jsname].name;
1493 sfield->fieldDecl = newFieldDecl(pkwmode,type,0,jsname,0);
1494 memcpy(&sfield->value,&defaultValue,
sizeof(
union anyVrml));
1495 sfield->valueSet = valueSet;
1496 sfield->eventInSet = FALSE;
1502 pushField(ud,cname);
1503 pushMode(ud,PARSING_FIELD);
1507 static void parseProtoInterface (
void *ud,
char **atts) {
1508 if (getMode(ud,TOP) != PARSING_PROTODECLARE && getMode(ud,TOP) != PARSING_EXTERNPROTODECLARE) {
1509 ConsoleMessage (
"got a <ProtoInterface>, but not within a <ProtoDeclare>\n");
1512 pushMode(ud,PARSING_PROTOINTERFACE);
1514 void Parser_scanStringValueToMem_B(
union anyVrml* any, indexT ctype,
const char *value,
int isXML);
1516 static void parseExternProtoDeclare_B (
void *ud,
char **atts) {
1524 char *type_name, *appinfo, *documentation, *containerfield, *url;
1528 type_name = appinfo = documentation = containerfield = url = NULL;
1529 if(0) printf(
"in parseExternProtoDeclare_B\n");
1531 proto = createNewX3DNode0(NODE_Proto);
1532 for (i = 0; atts[i]; i += 2) {
1533 #ifdef X3DPARSERVERBOSE
1535 printf (
"parseProtoDeclare: field:%s=%s\n", atts[i], atts[i+1]);
1538 if (!strcmp(
"name",atts[i]) ) type_name = atts[i+1];
1539 else if(!strcmp(
"containerField",atts[i])) containerfield = atts[i+1];
1540 else if(!strcmp(
"appInfo",atts[i])) appinfo = atts[i+1];
1541 else if(!strcmp(
"documentation",atts[i])) documentation = atts[i+1];
1542 else if(!strcmp(
"url",atts[i])) url = atts[i+1];
1545 parent = (
struct X3D_Proto*)getContext(ud,TOP);
1546 obj=newProtoDefinition();
1550 obj->protoName = STRDUP(type_name);
1552 printf (
"warning - have proto but no name, so just copying a default string in\n");
1553 obj->protoName = STRDUP(
"noProtoNameDefined");
1555 type_name = obj->protoName;
1557 if(parent->__externProtoDeclares == NULL)
1558 parent->__externProtoDeclares = newVector(
struct X3D_Proto*,4);
1559 vector_pushBack(
struct X3D_Proto*,parent->__externProtoDeclares,proto);
1560 proto->__parentProto = X3D_NODE(parent);
1561 proto->__protoFlags = parent->__protoFlags;
1562 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,0);
1564 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,2);
1565 proto->__protoFlags = ciflag_set(proto->__protoFlags,1,3);
1567 proto->__protoDef = obj;
1568 proto->__prototype = X3D_NODE(proto);
1569 proto->__typename = STRDUP(obj->protoName);
1571 int builtinField = findFieldInFIELDNAMES(containerfield);
1572 if(builtinField > -1){
1573 proto->_defaultContainer = builtinField;
1577 Parser_scanStringValueToMem_B((
union anyVrml*)&proto->url, FIELDTYPE_MFString,url, TRUE);
1579 proto->__loadstatus = 0;
1580 pushMode(ud,PARSING_EXTERNPROTODECLARE);
1581 pushNode(ud,X3D_NODE(proto));
1582 pushField(ud,
"__children");
1586 static void parseProtoDeclare_B (
void *ud,
char **atts) {
1595 char *type_name, *appinfo, *documentation, *containerfield;
1599 type_name = appinfo = documentation = containerfield = NULL;
1600 if(0) printf(
"in start protoDeclare\n");
1602 proto = createNewX3DNode0(NODE_Proto);
1603 for (i = 0; atts[i]; i += 2) {
1604 #ifdef X3DPARSERVERBOSE
1606 printf (
"parseProtoDeclare: field:%s=%s\n", atts[i], atts[i+1]);
1609 if (!strcmp(
"name",atts[i]) ) type_name = atts[i+1];
1610 else if(!strcmp(
"containerField",atts[i])) containerfield = atts[i+1];
1611 else if(!strcmp(
"appInfo",atts[i])) appinfo = atts[i+1];
1612 else if(!strcmp(
"documentation",atts[i])) documentation = atts[i+1];
1615 parent = (
struct X3D_Proto*)getContext(ud,TOP);
1616 obj=newProtoDefinition();
1620 obj->protoName = STRDUP(type_name);
1622 printf (
"warning - have proto but no name, so just copying a default string in\n");
1623 obj->protoName = STRDUP(
"noProtoNameDefined");
1625 type_name = obj->protoName;
1627 if(parent->__protoDeclares == NULL)
1628 parent->__protoDeclares = newVector(
struct X3D_Proto*,4);
1629 vector_pushBack(
struct X3D_Proto*,parent->__protoDeclares,proto);
1630 proto->__parentProto = X3D_NODE(parent);
1631 proto->__protoFlags = parent->__protoFlags;
1632 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,0);
1634 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,2);
1635 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,3);
1637 proto->__protoDef = obj;
1638 proto->__prototype = X3D_NODE(proto);
1639 proto->__typename = STRDUP(obj->protoName);
1641 int builtinField = findFieldInFIELDNAMES(containerfield);
1642 if(builtinField > -1){
1643 proto->_defaultContainer = builtinField;
1647 pushMode(ud,PARSING_PROTODECLARE);
1648 pushNode(ud,X3D_NODE(proto));
1649 pushField(ud,
"__children");
1652 static void parseProtoBody_B (
void *ud,
char **atts) {
1654 pushContext(ud,getNode(ud,TOP));
1655 pushMode(ud,PARSING_PROTOBODY);
1659 void add_node_to_broto_context(
struct X3D_Proto *context,
struct X3D_Node *node);
1660 void linkNodeIn_B(
void *ud);
1661 struct X3D_Node *broto_search_DEFname(
struct X3D_Proto *context,
const char *name);
1663 static void parseProtoInstance_B(
void *ud,
char **atts) {
1684 nameIndex = INT_ID_UNDEFINED;
1687 defNameIndex = INT_ID_UNDEFINED;
1689 if(0) printf(
"parseProtoInstance\n");
1691 for (i = 0; atts[i]; i += 2) {
1692 if (strcmp(
"name",atts[i]) == 0) {
1694 }
else if (strcmp(
"containerField",atts[i]) == 0) {
1696 }
else if (strcmp(
"DEF",atts[i]) == 0) {
1698 }
else if (strcmp(
"class",atts[i]) == 0) {
1699 ConsoleMessage (
"field \"class\" not currently used in a ProtoInstance parse... sorry");
1700 }
else if (strcmp(
"USE",atts[i]) == 0) {
1707 currentContext = getContext(ud,TOP);
1709 pflagdepth = ciflag_get(currentContext->__protoFlags,0);
1713 if (nameIndex != INT_ID_UNDEFINED) {
1714 protoname = atts[nameIndex];
1716 ConsoleMessage (
"\"ProtoInstance\" found, but field \"name\" not found!\n");
1723 char * defname = atts[defNameIndex];
1725 fromDEFtable = broto_search_DEFname(currentContext,defname);
1726 if (!fromDEFtable) {
1727 ConsoleMessage (
"Warning - line %d DEF name: \'%s\' not found",LINE,atts[i+1]);
1728 ConsoleMessage(
"\n");
1730 #ifdef X3DPARSERVERBOSE
1731 printf (
"copying for field %s defName %s\n",atts[i], atts[i+1]);
1735 if (NODE_Proto != fromDEFtable->_nodeType) {
1736 ConsoleMessage (
"Warning, line %d DEF/USE mismatch, '%s', %s != %s", LINE,
1737 atts[i+1],stringNodeType(fromDEFtable->_nodeType), stringNodeType (NODE_Proto));
1740 char* containerfield;
1741 node = fromDEFtable;
1742 node->referenceCount++;
1744 #ifdef X3DPARSERVERBOSE
1745 printf (
"successful copying for field %s defName %s\n",atts[i], atts[i+1]);
1748 containerfield = NULL;
1749 for (i = 0; atts[i]; i += 2) {
1750 if(!strcmp(atts[i],
"containerField")) containerfield = atts[i+1];
1752 if(containerfield) {
1753 int builtinField = findFieldInFIELDNAMES(containerfield);
1754 if(builtinField > INT_ID_UNDEFINED){
1755 node->_defaultContainer = builtinField;
1759 pushMode(ud,PARSING_PROTOINSTANCE_USE);
1765 if( isAvailableBroto(protoname, currentContext , &proto))
1768 char* containerfield;
1771 idepth = pflagdepth == 1;
1772 node=X3D_NODE(brotoInstance(proto,idepth));
1773 node->_executionContext = X3D_NODE(proto);
1774 if (defNameIndex != INT_ID_UNDEFINED){
1775 char * defname = atts[defNameIndex];
1776 broto_store_DEF(currentContext,node, defname);
1778 add_node_to_broto_context(currentContext,node);
1781 containerfield = NULL;
1782 for (i = 0; atts[i]; i += 2) {
1783 if(!strcmp(atts[i],
"containerField")) containerfield = atts[i+1];
1785 if(containerfield) {
1786 int builtinField = findFieldInFIELDNAMES(containerfield);
1787 if(builtinField > INT_ID_UNDEFINED){
1788 node->_defaultContainer = builtinField;
1795 ConsoleMessage (
"Attempt to instance undefined prototype typename %s\n",protoname);
1800 pushMode(ud,PARSING_PROTOINSTANCE);
1804 BOOL nodeTypeSupportsUserFields(
struct X3D_Node *node);
1805 int getFieldFromNodeAndName(
struct X3D_Node* node,
const char *fieldname,
int *type,
int *kind,
int *iifield,
union anyVrml **value);
1806 void broto_store_IS(
struct X3D_Proto *proto,
char *protofieldname,
int pmode,
int iprotofield,
int type,
1807 struct X3D_Node *node,
char* nodefieldname,
int mode,
int ifield,
int source);
1809 static void parseConnect_B(
void *ud,
char **atts) {
1813 char *nodefield, *protofield;
1814 node = getNode(ud,TOP);
1815 proto = context = getContext(ud,TOP);
1817 nodefield = protofield = NULL;
1818 for(i=0;atts[i];i+=2){
1819 if(!strcmp(atts[i],
"nodeField")) nodefield = atts[i+1];
1820 if(!strcmp(atts[i],
"protoField")) protofield = atts[i+1];
1823 if(nodefield && protofield){
1824 int ptype, pkind, pifield, ntype, nkind, nifield;
1825 union anyVrml *pvalue, *nvalue;
1826 okp = getFieldFromNodeAndName(X3D_NODE(proto),protofield,&ptype, &pkind, &pifield, &pvalue);
1827 okn = getFieldFromNodeAndName(node, nodefield,&ntype, &nkind, &nifield, &nvalue);
1842 ConsoleMessage(
"Parser error: IS - we have a name match: %s IS %s found protofield %s\n",
1843 nodefield,protofield,protofield);
1844 ConsoleMessage(
"...But the types don't match: nodefield %s protofield %s\n",
1845 FIELDTYPES[ntype],FIELDTYPES[ptype]);
1849 if(nkind != PKW_inputOutput && nkind != pkind){
1850 if(pkind != PKW_inputOutput){
1851 ConsoleMessage(
"Parser Error: IS - we have a name match: %s IS %s found protofield %s\n",
1852 nodefield,protofield,protofield);
1853 ConsoleMessage(
"...But the modes don't jive: nodefield %s protofield %s\n",
1854 PROTOKEYWORDS[nkind],PROTOKEYWORDS[pkind]);
1857 ConsoleMessage(
"Parser Warning: IS - we have a name match: %s IS %s found protofield %s\n",
1858 nodefield,protofield,protofield);
1859 ConsoleMessage(
"...But the modes don't jive: nodefield %s protofield %s\n",
1860 PROTOKEYWORDS[nkind],PROTOKEYWORDS[pkind]);
1861 ConsoleMessage(
"...will thunk\n");
1868 if(pkind == PKW_initializeOnly || pkind == PKW_inputOutput)
1870 shallow_copy_field(ntype, pvalue , nvalue);
1873 source = node->_nodeType == NODE_Proto ? 3 : node->_nodeType == NODE_Script ? 1 : nodeTypeSupportsUserFields(node) ? 2 : 0;
1875 broto_store_IS(context,protofield,pkind,pifield,ptype,
1876 node,nodefield,nkind,nifield,source);
1881 static void XMLCALL X3DstartElement(
void *ud,
const xmlChar *iname,
const xmlChar **atts) {
1885 char *blankAtts[] = {NULL,NULL};
1886 const char *name = (
const char*) iname;
1889 if (atts == NULL) myAtts = blankAtts;
1890 else myAtts = (
char **) atts;
1892 #ifdef X3DPARSERVERBOSE
1894 printf (
"X3DstartElement: %s: atts %p\n",name,atts);
1897 for (i = 0; myAtts[i]; i += 2) {
1898 printf(
" X3DStartElement field:%s=%s\n", myAtts[i], atts[i + 1]);
1905 for (i = 0; atts[i]; i += 2) {
1906 atts[i+1] = fixAmp(atts[i+1]);
1910 myNodeIndex = findFieldInNODES(name);
1913 if (myNodeIndex != INT_ID_UNDEFINED) {
1914 startBuiltin_B(ud,myNodeIndex,(
const xmlChar *)name,myAtts);
1923 myNodeIndex = findFieldInX3DSPECIAL(name);
1924 if (myNodeIndex != INT_ID_UNDEFINED) {
1925 switch (myNodeIndex) {
1926 case X3DSP_ProtoDeclare:
1927 parseProtoDeclare_B(ud,myAtts);
1929 case X3DSP_ExternProtoDeclare:
1930 parseExternProtoDeclare_B(ud,myAtts);
1932 case X3DSP_ProtoBody:
1933 parseProtoBody_B(ud,myAtts);
1935 case X3DSP_ProtoInterface:
1936 parseProtoInterface(ud,myAtts);
1938 case X3DSP_ProtoInstance:
1939 parseProtoInstance_B(ud,myAtts);
1942 parseRoutes_B(ud,myAtts);
1944 case X3DSP_meta: parseMeta(myAtts);
break;
1945 case X3DSP_Scene: parseScene(myAtts);
break;
1947 case X3DSP_Header: parseHeader(myAtts);
break;
1948 case X3DSP_X3D: parseX3Dhead(myAtts);
break;
1949 case X3DSP_fieldValue:
1950 parseFieldValue_B(ud,myAtts);
1953 parseScriptProtoField_B (ud, myAtts);
1955 case X3DSP_IS: parseIS(ud);
break;
1956 case X3DSP_component: parseComponent(myAtts);
break;
1958 parseExport_B(ud,myAtts);
1961 parseImport_B(ud,myAtts);
1964 parseConnect_B(ud,myAtts);
1967 default: printf (
" huh? startElement, X3DSPECIAL, but not handled?? %d, :%s:\n",myNodeIndex,X3DSPECIAL[myNodeIndex]);
1972 printf (
"startElement name do not currently handle this one :%s: index %d\n",name,myNodeIndex);
1975 static void endScriptProtoField_B(
void *ud) {
1976 if(0) printf(
"end scriptprotofield\n");
1982 static void XMLCALL X3DendElement(
void *ud,
const xmlChar *iname) {
1984 const char*name = (
const char*) iname;
1990 #ifdef X3DPARSERVERBOSE
1991 printf (
"endElement: %s : parentIndex %d mode %s\n",name,parentIndex,parserModeStrings[getMode(ud,TOP)]);
1996 myNodeIndex = findFieldInNODES(name);
1997 if (myNodeIndex != INT_ID_UNDEFINED) {
1998 endBuiltin_B(ud,iname);
2006 myNodeIndex = findFieldInX3DSPECIAL(name);
2007 if (myNodeIndex != INT_ID_UNDEFINED) {
2008 switch (myNodeIndex) {
2009 case X3DSP_ProtoInstance:
2010 endProtoInstance_B(ud,name);
2012 case X3DSP_ProtoInterface:
2013 endProtoInterfaceTag(ud);
2015 case X3DSP_ProtoBody:
2016 endProtoBodyTag_B(ud,name);
2018 case X3DSP_ProtoDeclare:
2019 endProtoDeclareTag_B(ud);
2021 case X3DSP_ExternProtoDeclare:
2022 endExternProtoDeclareTag_B(ud);
2033 case X3DSP_component:
2036 case X3DSP_X3D:
break;
2038 endScriptProtoField_B(ud);
2040 case X3DSP_fieldValue:
2041 endFieldValue_B(ud);
2046 printf (
"endElement: huh? X3DSPECIAL, but not handled?? %s\n",X3DSPECIAL[myNodeIndex]);
2051 printf (
"unhandled endElement name %s index %d\n",name,myNodeIndex);
2052 #ifdef X3DPARSERVERBOSE
2053 printf (
"endElement %s\n",name);
2057 static XML_Parser initializeX3DParser () {
2059 p->X3DParserRecurseLevel++;
2061 if (p->X3DParserRecurseLevel >= PROTOINSTANCE_MAX_LEVELS) {
2062 ConsoleMessage (
"XML_PARSER init: XML file PROTO nested too deep\n");
2063 p->X3DParserRecurseLevel--;
2065 XML_CreateParserLevel(p->x3dparser[p->X3DParserRecurseLevel]);
2066 XML_SetElementHandler(p->x3dparser[p->X3DParserRecurseLevel], X3DstartElement, X3DendElement);
2067 XML_SetCdataSectionHandler (p->x3dparser[p->X3DParserRecurseLevel], startCDATA, endCDATA);
2068 XML_SetDefaultHandler (p->x3dparser[p->X3DParserRecurseLevel],handleCDATA);
2069 XML_SetUserData(p->x3dparser[p->X3DParserRecurseLevel], &parentIndex);
2072 return p->x3dparser[p->X3DParserRecurseLevel];
2075 static void shutdownX3DParser (
void *ud) {
2080 XML_ParserFree(p->x3dparser[p->X3DParserRecurseLevel]);
2081 p->X3DParserRecurseLevel--;
2084 if (p->X3DParserRecurseLevel == INT_ID_UNDEFINED) {
2086 gglobal()->X3DParser.parentIndex = 0;
2090 if (p->X3DParserRecurseLevel < INT_ID_UNDEFINED) {
2091 ConsoleMessage (
"XML_PARSER close underflow");
2092 p->X3DParserRecurseLevel = INT_ID_UNDEFINED;
2096 FREE_IF_NZ(tg->X3DParser.CDATA_Text);
2097 p->CDATA_TextMallocSize = 0;
2098 if (p->X3DParserRecurseLevel > INT_ID_UNDEFINED)
2099 p->currentX3DParser = p->x3dparser[p->X3DParserRecurseLevel];
2105 for(i=0;i<vectorSize(p->DEFedNodes);i++){
2106 struct Vector* vd = vector_get(
struct Vector*,p->DEFedNodes,i);
2109 deleteVector(
struct Vector*, p->DEFedNodes);
2122 int X3DParse (
struct X3D_Node* ectx,
struct X3D_Node* myParent,
const char *inputstring) {
2125 p->currentX3DParser = initializeX3DParser();
2130 DEBUG_X3DPARSER (
"X3DPARSE on :\n%s:\n",inputstring);
2131 if(p->user_data == NULL){
2134 p->user_data = new_xml_user_data();
2136 pushContext(p->user_data,ectx);
2137 if(myParent->_nodeType == NODE_Proto )
2138 pushField(p->user_data,
"__children");
2140 pushField(p->user_data,
"children");
2141 pushNode(p->user_data,myParent);
2142 pushMode(p->user_data,PARSING_NODES);
2144 if (XML_ParseFile(p->currentX3DParser, p->user_data, inputstring, (
int) strlen(inputstring), TRUE) == XML_STATUS_ERROR) {
2146 xmlErrorPtr xe = xmlGetLastError();
2147 ConsoleMessage(
"Xml Error %s \n",xe->message);
2148 ConsoleMessage(
"Line %d\n",xe->line);
2155 popField(p->user_data);
2156 shutdownX3DParser(p->user_data);
2157 Parser_deleteParserForScanStringValueToMem();
2160 popField(p->user_data);
2161 shutdownX3DParser(p->user_data);
2162 Parser_deleteParserForScanStringValueToMem();