34 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../main/headers.h"
39 #include "CParseGeneral.h"
40 #include "../scenegraph/Vector.h"
41 #include "../vrml_parser/CFieldDecls.h"
42 #include "../world_script/JScript.h"
43 #include "../world_script/CScripts.h"
44 #include "../world_script/fieldSet.h"
45 #include "../input/EAIHeaders.h"
46 #include "../input/EAIHelpers.h"
47 #include "CParseParser.h"
48 #include "CParseLexer.h"
51 #include "../opengl/OpenGL_Utils.h"
53 #define PARSE_ERROR(msg) \
55 CPARSE_ERROR_CURID(msg); \
56 FREE_IF_NZ(me->lexer->curID); \
59 #define PARSER_FINALLY
61 #define DEFMEM_INIT_SIZE 16
63 #define DJ_KEEP_COMPILER_WARNING 0
66 char fw_outline[2000];
68 int latest_protoDefNumber;
70 void *CParseParser_constructor(){
75 void CParseParser_init(
struct tCParseParser *t){
78 t->prv = CParseParser_constructor();
81 p->foundInputErrors = 0;
82 p->latest_protoDefNumber = 1;
88 void resetParseSuccessfullyFlag(
void) {
90 p->foundInputErrors = 0;
92 int parsedSuccessfully(
void) {
94 return p->foundInputErrors == 0;
147 static BOOL parser_routeStatement(
struct VRMLParser*);
148 static BOOL parser_componentStatement(
struct VRMLParser*);
149 static BOOL parser_exportStatement(
struct VRMLParser*);
150 static BOOL parser_importStatement(
struct VRMLParser*);
151 static BOOL parser_metaStatement(
struct VRMLParser*);
152 static BOOL parser_unitStatement(
struct VRMLParser*);
153 static BOOL parser_profileStatement(
struct VRMLParser*);
162 static BOOL parser_sffloatValue_ (
struct VRMLParser *,
void *);
163 static BOOL parser_sfint32Value_ (
struct VRMLParser *,
void *);
164 static BOOL parser_sftimeValue (
struct VRMLParser *,
void *);
165 static BOOL parser_sfboolValue (
struct VRMLParser *,
void *);
166 static BOOL parser_sfnodeValue (
struct VRMLParser *,
void *);
167 static BOOL parser_sfrotationValue (
struct VRMLParser *,
void *);
168 static BOOL parser_sfcolorValue (
struct VRMLParser *,
void *);
169 static BOOL parser_sfcolorrgbaValue (
struct VRMLParser *,
void *);
170 static BOOL parser_sfmatrix3fValue (
struct VRMLParser *,
void *);
171 static BOOL parser_sfmatrix4fValue (
struct VRMLParser *,
void *);
172 static BOOL parser_sfvec2fValue (
struct VRMLParser *,
void *);
173 static BOOL parser_sfvec4fValue (
struct VRMLParser *,
void *);
174 static BOOL parser_sfvec2dValue (
struct VRMLParser *,
void *);
175 static BOOL parser_sfvec3dValue (
struct VRMLParser *,
void *);
176 static BOOL parser_sfvec4dValue (
struct VRMLParser *,
void *);
177 static BOOL parser_sfmatrix3dValue (
struct VRMLParser *,
void *);
178 static BOOL parser_sfmatrix4dValue (
struct VRMLParser *,
void *);
179 static BOOL parser_mfboolValue(
struct VRMLParser*,
void*);
180 static BOOL parser_mfcolorValue(
struct VRMLParser*,
void*);
181 static BOOL parser_mfcolorrgbaValue(
struct VRMLParser*,
void*);
182 static BOOL parser_mffloatValue(
struct VRMLParser*,
void*);
183 static BOOL parser_mfint32Value(
struct VRMLParser*,
void*);
184 static BOOL parser_mfnodeValue(
struct VRMLParser*,
void*);
185 static BOOL parser_mfrotationValue(
struct VRMLParser*,
void*);
186 static BOOL parser_mfstringValue(
struct VRMLParser*,
void*);
187 static BOOL parser_mftimeValue(
struct VRMLParser*,
void*);
188 static BOOL parser_mfvec2fValue(
struct VRMLParser*,
void*);
189 static BOOL parser_mfvec3fValue(
struct VRMLParser*,
void*);
190 static BOOL parser_mfvec3dValue(
struct VRMLParser*,
void*);
191 static BOOL parser_sfstringValue_(
struct VRMLParser*,
void*);
192 static BOOL parser_sfimageValue(
struct VRMLParser*,
void*);
193 static BOOL parser_mfvec2dValue(
struct VRMLParser*,
void*);
194 static BOOL parser_mfvec4fValue(
struct VRMLParser*,
void*);
195 static BOOL parser_mfvec4dValue(
struct VRMLParser*,
void*);
200 #define parser_sfvec3fValue(me, ret) \
201 parser_sfcolorValue(me, ret)
205 static BOOL parser_fieldTypeNotParsedYet(
struct VRMLParser* me,
void* ret);
208 BOOL (*PARSE_TYPE[])(
struct VRMLParser*,
void*)={
209 &parser_sffloatValue_, &parser_mffloatValue,
210 &parser_sfrotationValue, &parser_mfrotationValue,
211 &parser_sfcolorValue, &parser_mfvec3fValue,
212 &parser_sfboolValue, &parser_mfboolValue,
213 &parser_sfint32Value_, &parser_mfint32Value,
214 &parser_sfnodeValue, &parser_mfnodeValue,
215 &parser_sfcolorValue, &parser_mfcolorValue,
216 &parser_sfcolorrgbaValue, &parser_mfcolorrgbaValue,
217 &parser_sftimeValue, &parser_mftimeValue,
218 &parser_sfstringValue_, &parser_mfstringValue,
219 &parser_sfvec2fValue, &parser_mfvec2fValue,
220 &parser_fieldTypeNotParsedYet,
221 &parser_sfimageValue,
222 &parser_sfvec3dValue, &parser_mfvec3dValue,
223 &parser_sftimeValue, &parser_mftimeValue,
224 &parser_sfmatrix3fValue, &parser_fieldTypeNotParsedYet,
225 &parser_sfmatrix3dValue, &parser_fieldTypeNotParsedYet,
226 &parser_sfmatrix4fValue, &parser_fieldTypeNotParsedYet,
227 &parser_sfmatrix4dValue, &parser_fieldTypeNotParsedYet,
228 &parser_sfvec2dValue, &parser_mfvec2dValue,
229 &parser_sfvec4fValue, &parser_mfvec4fValue,
230 &parser_sfvec4dValue, &parser_mfvec4dValue,
231 &parser_fieldTypeNotParsedYet,
238 ASSERT(PARSE_TYPE[type]);
241 if (type == ID_UNDEFINED)
return false;
243 return PARSE_TYPE[type](me, (
void*)defaultVal);
254 struct ProtoFieldDecl* newProtoFieldDecl(indexT mode, indexT type, indexT name)
262 ret->alreadySet=FALSE;
263 ret->fieldString = NULL;
265 ret->scriptDests = NULL;
266 ret->defaultVal.mfnode.p = NULL;
267 ret->defaultVal.mfnode.n = 0;
272 ddecl = newProtoFieldDecl(sdecl->mode,sdecl->type,sdecl->name);
274 ddecl->cname = STRDUP(sdecl->cname);
277 shallow_copy_field(sdecl->type,&(sdecl->defaultVal),&(ddecl->defaultVal));
285 void deleteMallocedFieldValue(
int type,
union anyVrml *fieldPtr)
291 if(type == FIELDTYPE_FreeWRLPTR){
292 if(0) FREE_IF_NZ(fieldPtr->sfstring);
293 }
else if(type == FIELDTYPE_SFString){
296 us = fieldPtr->sfstring;
297 clearASCIIString(us);
298 FREE_IF_NZ(fieldPtr->sfstring);
300 }
else if(type == FIELDTYPE_MFString){
301 clearMFString(&fieldPtr->mfstring);
302 fieldPtr->mfstring.n = 0;
305 FREE_IF_NZ(fieldPtr->mfnode.p);
306 fieldPtr->mfnode.n = 0;
315 FREE_IF_NZ(me->cname);
316 FREE_IF_NZ(me->fieldString);
317 fieldPtr = &(me->defaultVal);
319 deleteMallocedFieldValue(type,fieldPtr);
350 ret->deconstructedProtoBody = NULL;
354 ret->protoDefNumber = p->latest_protoDefNumber++;
355 ret->estimatedBodyLen = 0;
356 ret->protoName = NULL;
358 ret->isExtern = FALSE;
366 for(i=0;i<vectorSize(ret->iface);i++) {
369 deleteProtoFieldDecl(iface);
374 FREE_IF_NZ(ret->protoName);
383 indexT ind, indexT mode)
388 if (!me)
return NULL;
389 for(i=0; i!=vectorSize(me->iface); ++i)
392 if(f->name==ind && f->mode==mode) {
410 if(node->_nodeType == NODE_Proto){
422 struct VRMLParser* newParser(
void *ectx,
void* ptr,
unsigned ofs,
int parsingX3DfromXML) {
424 ret->lexer=newLexer();
430 ret->DEFedNodes = NULL;
432 ret->parsingX3DfromXML = parsingX3DfromXML;
433 ret->brotoDEFedNodes = NULL;
437 struct VRMLParser* reuseParser(
void *ectx,
void* ptr,
unsigned ofs) {
464 deleteLexer(me->lexer);
469 static void parser_scopeOut_DEFUSE();
470 static void parser_scopeOut_PROTO();
471 void parser_destroyData(
struct VRMLParser* me)
479 while(!stack_empty(me->DEFedNodes))
480 parser_scopeOut_DEFUSE(me);
481 deleteStack(
struct Vector*, me->DEFedNodes);
484 ASSERT(!me->DEFedNodes);
490 while(!stack_empty(me->PROTOs))
491 parser_scopeOut_PROTO(me);
492 deleteStack(
struct Vector*, me->PROTOs);
497 lexer_destroyData(me->lexer);
501 zeroScriptHandles ();
506 static void parser_scopeIn_DEFUSE(
struct VRMLParser* me)
509 me->DEFedNodes=newStack(
struct Vector*);
511 ASSERT(me->DEFedNodes);
512 stack_push(
struct Vector*, me->DEFedNodes,
513 newVector(
struct X3D_Node*, DEFMEM_INIT_SIZE));
514 ASSERT(!stack_empty(me->DEFedNodes));
525 static void parser_scopeIn_PROTO(
struct VRMLParser* me)
532 static void parser_scopeOut_DEFUSE(
struct VRMLParser* me)
534 ASSERT(!stack_empty(me->DEFedNodes));
536 deleteVector(
struct X3D_Node*, stack_top(
struct Vector*, me->DEFedNodes));
537 stack_pop(
struct Vector*, me->DEFedNodes);
544 static void parser_scopeOut_PROTO(
struct VRMLParser* me)
549 vector_popBackN(
struct ProtoDefinition*, me->PROTOs, lexer_getProtoPopCnt(me->lexer));
550 lexer_scopeOut_PROTO(me->lexer);
555 lexer_scopeIn(me->lexer);
556 parser_scopeIn_DEFUSE(me);
557 parser_scopeIn_PROTO(me);
561 parser_scopeOut_DEFUSE(me);
562 parser_scopeOut_PROTO(me);
563 lexer_scopeOut(me->lexer);
567 #define STRDUP_IF_NZ(_ptr) ((_ptr) ? STRDUP(_ptr) : NULL)
568 #define DECLAREUP char *saveNextIn, *saveCurID = NULL;
569 #define SAVEUP { FREE_IF_NZ(saveCurID); \
570 saveCurID = STRDUP_IF_NZ(me->lexer->curID); \
571 saveNextIn = me->lexer->nextIn;}
572 #define BACKUP {FREE_IF_NZ(me->lexer->curID); \
573 me->lexer->curID = saveCurID; \
574 me->lexer->nextIn = saveNextIn; }
575 #define FREEUP {FREE_IF_NZ(saveCurID);}
577 static BOOL parser_brotoStatement(
struct VRMLParser* me);
595 #ifdef CPARSERVERBOSE
596 printf(
"parser_vrmlScene: Try node\n");
598 if(parser_nodeStatement(me, &node))
602 AddRemoveChildren(me->ptr, offsetPointer_deref(
void *,me->ptr,me->ofs), &node, 1, 1,__FILE__,__LINE__);
603 #ifdef CPARSERVERBOSE
604 printf(
"parser_vrmlScene: node parsed\n");
615 #ifdef CPARSERVERBOSE
616 printf(
"parser_vrmlScene: Try route\n");
621 BLOCK_STATEMENT(parser_vrmlScene)
631 #ifdef CPARSERVERBOSE
632 printf(
"parser_vrmlScene: Try proto\n");
641 if(parser_brotoStatement(me)) {
642 #ifdef CPARSERVERBOSE
643 printf(
"parser_vrmlScene: BROTO parsed\n");
652 void broto_store_DEF(
struct X3D_Proto* proto,
struct X3D_Node* node,
const char *name);
657 return parser_node_B(me,node,ival);
666 BOOL parser_vrmlScene_B(
struct VRMLParser* me)
668 parse_proto_body(me);
673 return lexer_eof(me->lexer);
696 return parser_vrmlScene_B(me);
721 char *startOfField = NULL;
722 int startOfFieldLexerLevel = INT_ID_UNDEFINED;
725 #ifdef CPARSERVERBOSE
726 printf (
"start of parser_interfaceDeclaration\n");
729 bzero (&defaultVal,
sizeof (
union anyVrml));
732 ASSERT((proto || script) && !(proto && script));
739 if(!lexer_protoFieldMode(me->lexer, &mode)) {
740 #ifdef CPARSERVERBOSE
741 printf (
"parser_interfaceDeclaration, not lexer_protoFieldMode, returning\n");
749 if (script != NULL) {
750 if(script->ShaderScriptNode->_nodeType==NODE_Script && mode==PKW_inputOutput)
752 PARSE_ERROR(
"Scripts must not have inputOutputs!")
759 if(!lexer_fieldType(me->lexer, &type))
760 PARSE_ERROR(
"Expected fieldType after proto-field keyword!")
762 #ifdef CPARSERVERBOSE
763 printf (
"parser_interfaceDeclaration, switching on mode %s\n",PROTOKEYWORDS[mode]);
769 #define LEX_DEFINE_FIELDID(suff) \
771 if(!lexer_define_##suff(me->lexer, &name)) \
772 PARSE_ERROR("Expected fieldNameId after field type!") \
775 LEX_DEFINE_FIELDID(initializeOnly)
776 LEX_DEFINE_FIELDID(inputOnly)
777 LEX_DEFINE_FIELDID(outputOnly)
778 LEX_DEFINE_FIELDID(inputOutput)
792 #ifdef CPARSERVERBOSE
793 printf (
"parser_interfaceDeclaration, calling newProtoFieldDecl\n");
796 pdecl=newProtoFieldDecl(mode, type, name);
797 pdecl->cname = STRDUP(protoFieldDecl_getStringName(me->lexer, pdecl));
799 externproto = proto->isExtern;
800 #ifdef CPARSERVERBOSE
801 printf (
"parser_interfaceDeclaration, finished calling newProtoFieldDecl\n");
804 #ifdef CPARSERVERBOSE
805 printf (
"parser_interfaceDeclaration, calling newScriptFieldDecl\n");
808 sdecl=newScriptFieldDecl(me->lexer, mode, type, name);
816 if((mode==PKW_initializeOnly || mode==PKW_inputOutput) ) {
817 #ifdef CPARSERVERBOSE
818 printf (
"parser_interfaceDeclaration, mode==PKW_initializeOnly || mode==PKW_inputOutput\n");
824 if (script && lexer_keyword(me->lexer, KW_IS)) {
830 if(!lexer_field(me->lexer, NULL, NULL, &fieldO, &fieldE))
831 PARSE_ERROR(
"Expected fieldId after IS!")
833 if(fieldO!=ID_UNDEFINED)
836 pField=protoDefinition_getField(me->curPROTO, fieldO, PKW_initializeOnly);
838 PARSE_ERROR(
"IS source is no field of current PROTO!")
839 ASSERT(pField->mode==PKW_initializeOnly);
842 ASSERT(fieldE!=ID_UNDEFINED);
844 pField=protoDefinition_getField(me->curPROTO, fieldE, PKW_inputOutput);
846 PARSE_ERROR(
"IS source is no field of current PROTO!")
847 ASSERT(pField->mode==PKW_inputOutput);
852 sfield = newScriptFieldInstanceInfo(sdecl, script);
854 defaultVal = pField->defaultVal;
859 startOfField = (
char *)me->lexer->nextIn;
860 startOfFieldLexerLevel = me->lexer->lexerInputLevel;
864 bzero (&defaultVal,
sizeof (
union anyVrml));
866 if (!parseType(me, type, &defaultVal)) {
868 CPARSE_ERROR_CURID(
"Expected default value for field!");
869 if(pdecl) deleteProtoFieldDecl(pdecl);
870 if(sdecl) deleteScriptFieldDecl(sdecl);
878 pdecl->defaultVal=defaultVal;
883 scriptFieldDecl_setFieldValue(sdecl, defaultVal);
886 #ifdef CPARSERVERBOSE
887 printf (
"parser_interfaceDeclaration, NOT mode==PKW_initializeOnly || mode==PKW_inputOutput\n");
891 if (script && lexer_keyword(me->lexer, KW_IS)) {
894 BOOL isIn = FALSE, isOut = FALSE;
896 #ifdef CPARSERVERBOSE
897 printf (
"parser_interfaceDeclaration, got IS\n");
901 if (mode == PKW_inputOnly) {
902 if (lexer_inputOnly(me->lexer, NULL, NULL, NULL, &evO, &evE)) {
904 isOut = (evE != ID_UNDEFINED);
907 if (lexer_outputOnly(me->lexer, NULL, NULL, NULL, &evO, &evE)) {
913 if (!isIn && !isOut) {
914 #ifdef CPARSERVERBOSE
915 printf (
"parser_interfaceDeclaration, NOT isIn Nor isOut\n");
923 pField = protoDefinition_getField(me->curPROTO, evO, isIn ? PKW_inputOnly: PKW_outputOnly);
928 sfield = newScriptFieldInstanceInfo(sdecl, script);
941 if (startOfField != NULL) {
942 if (startOfFieldLexerLevel == me->lexer->lexerInputLevel) {
944 size_t sz = (size_t) ((me->lexer->nextIn)-startOfField);
947 FREE_IF_NZ(pdecl->fieldString);
948 pdecl->fieldString = MALLOC (
char *, sz + 2);
949 if (NULL != pdecl->fieldString)
951 strncpy(pdecl->fieldString,startOfField,sz);
952 pdecl->fieldString[sz]=
'\0';
980 for (i=startOfFieldLexerLevel+1; i<me->lexer->lexerInputLevel; i++) {
981 printf (
"CAUTION: unverified code in recursive PROTO invocations in classic VRML parser\n");
982 printf (
"level %d\n",i);
983 printf (
"size of this level, %d\n",(
int) (me->lexer->oldNextIn[i+1] - me->lexer->startOfStringPtr[i]));
984 sz += (size_t) (me->lexer->oldNextIn[i+1] - me->lexer->startOfStringPtr[i]);
988 sz += (size_t)(me->lexer->nextIn - me->lexer->startOfStringPtr[me->lexer->lexerInputLevel]);
995 FREE_IF_NZ(pdecl->fieldString);
996 pdecl->fieldString = MALLOC(
char *, sz);
997 curStrPtr = pdecl->fieldString;
1011 for (i=startOfFieldLexerLevel+1; i<me->lexer->lexerInputLevel; i++) {
1012 sz = (size_t) (me->lexer->oldNextIn[i+1] - me->lexer->startOfStringPtr[i]);
1013 strncpy(curStrPtr,me->lexer->startOfStringPtr[i],sz);
1018 sz = (size_t)(me->lexer->nextIn - me->lexer->startOfStringPtr[me->lexer->lexerInputLevel]);
1019 strncpy(curStrPtr,me->lexer->startOfStringPtr[me->lexer->lexerInputLevel],sz);
1027 #ifdef CPARSERVERBOSE
1028 printf (
"pdecl->fieldString is :%s:\n",pdecl->fieldString);
1031 protoDefinition_addIfaceField(proto, pdecl);
1035 script_addField(script, sdecl);
1038 #ifdef CPARSERVERBOSE
1039 printf (
"end of parser_interfaceDeclaration\n");
1058 static BOOL parser_componentStatement(
struct VRMLParser* me) {
1059 char *cname, *clevel;
1060 char cfullname[200];
1061 int myComponent = INT_ID_UNDEFINED;
1062 int myLevel = INT_ID_UNDEFINED;
1064 #if DJ_KEEP_COMPILER_WARNING
1065 #define COMPSTRINGSIZE 20
1069 lexer_skip(me->lexer);
1072 if(!lexer_keyword(me->lexer, KW_COMPONENT))
return FALSE;
1074 #ifdef CPARSERVERBOSE
1075 printf (
"parser_componentStatement...\n");
1078 if(!lexer_setCurID(me->lexer))
return TRUE;
1079 ASSERT(me->lexer->curID);
1085 strcpy(cfullname,me->lexer->curID);
1087 FREE_IF_NZ(me->lexer->curID);
1091 for(i=0;i<strlen(cfullname);i++)
1092 if(cfullname[i] ==
':'){
1093 cfullname[i] =
'\0';
1094 clevel = &cfullname[i+1];
1097 myComponent = findFieldInCOMPONENTS(cname);
1099 if(clevel) myLevel = atoi(clevel);
1101 handleComponent(myComponent,myLevel);
1114 switch(node->_nodeType){
1124 struct X3D_Node *broto_search_DEFname(
struct X3D_Proto *context,
const char *name);
1126 void handleExport_B (
void *ctxnodeptr,
char *nodename,
char *as) {
1128 struct X3D_Proto *context = hasContext(ctxnodeptr);
1132 if(!context->__EXPORTS) context->__EXPORTS = newVector(
struct IMEXPORT *,4);
1133 mxport->mxname = STRDUP(nodename);
1134 mxport->as = mxport->mxname;
1136 mxport->as = STRDUP(as);
1137 node = broto_search_DEFname(context,mxport->mxname);
1138 mxport->nodeptr = node;
1139 vector_pushBack(
struct IMEXPORT*,context->__EXPORTS,mxport);
1141 #ifdef CAPABILITIESVERBOSE
1142 printf (
"handleExport: node :%s: ",node);
1143 if (as != NULL) printf (
" AS :%s: ",node);
1149 void handleImport_B (
struct X3D_Node *nodeptr,
char *nodeName,
char *nodeImport,
char *as) {
1155 struct X3D_Proto *context = hasContext(nodeptr);
1158 if(!context->__IMPORTS) context->__IMPORTS = newVector(
struct IMEXPORT *,4);
1159 mxport->mxname = STRDUP(nodeImport);
1160 mxport->inlinename = STRDUP(nodeName);
1161 mxport->as = mxport->mxname;
1163 mxport->as = STRDUP(as);
1164 mxport->nodeptr = NULL;
1165 vector_pushBack(
struct IMEXPORT*,context->__IMPORTS,mxport);
1168 #ifdef CAPABILITIESVERBOSE
1169 printf (
"handleImport: inlineNodeName :%s: nodeToImport :%s:",nodeName, nodeImport);
1170 if (as != NULL) printf (
" AS :%s: ",as);
1175 static BOOL parser_exportStatement(
struct VRMLParser* me) {
1176 char *nodeToExport = NULL;
1180 lexer_skip(me->lexer);
1183 if(!lexer_keyword(me->lexer, KW_EXPORT))
return FALSE;
1185 #ifdef CPARSERVERBOSE
1186 printf (
"parser_exportStatement...\n");
1189 if(!lexer_setCurID(me->lexer))
return TRUE;
1190 ASSERT(me->lexer->curID);
1193 nodeToExport = me->lexer->curID;
1194 me->lexer->curID = NULL;
1196 if(!lexer_setCurID(me->lexer))
return TRUE;
1197 ASSERT(me->lexer->curID);
1200 if (strcmp(
"AS",me->lexer->curID) == 0) {
1201 FREE_IF_NZ(me->lexer->curID);
1202 if(!lexer_setCurID(me->lexer))
return TRUE;
1203 ASSERT(me->lexer->curID);
1204 alias = me->lexer->curID;
1208 handleExport_B(me->ectx,nodeToExport, alias);
1211 FREE_IF_NZ(nodeToExport);
1212 if (alias != NULL) {FREE_IF_NZ(me->lexer->curID);}
1216 static BOOL parser_importStatement(
struct VRMLParser* me) {
1217 char *inlineNodeName = NULL;
1219 char *nodeToImport = NULL;
1222 lexer_skip(me->lexer);
1225 if(!lexer_keyword(me->lexer, KW_IMPORT))
return FALSE;
1227 #ifdef CPARSERVERBOSE
1228 printf (
"parser_importStatement...\n");
1231 if(!lexer_setCurID(me->lexer))
return TRUE;
1232 ASSERT(me->lexer->curID);
1235 inlineNodeName = STRDUP(me->lexer->curID);
1236 FREE_IF_NZ(me->lexer->curID);
1239 if (!lexer_point(me->lexer)) {
1240 CPARSE_ERROR_CURID(
"expected period in IMPORT statement")
1244 if(!lexer_setCurID(me->lexer)) return TRUE;
1245 ASSERT(me->lexer->curID);
1248 nodeToImport = STRDUP(me->lexer->curID);
1249 FREE_IF_NZ(me->lexer->curID);
1252 if(!lexer_setCurID(me->lexer)) return TRUE;
1253 ASSERT(me->lexer->curID);
1256 if (strcmp("AS",me->lexer->curID) == 0) {
1257 FREE_IF_NZ(me->lexer->curID);
1258 if(!lexer_setCurID(me->lexer))
return TRUE;
1259 ASSERT(me->lexer->curID);
1260 alias = STRDUP(me->lexer->curID);
1261 FREE_IF_NZ(me->lexer->curID);
1265 handleImport_B(me->ectx,inlineNodeName, nodeToImport, alias);
1267 FREE_IF_NZ (inlineNodeName);
1268 FREE_IF_NZ (nodeToImport);
1272 static BOOL parser_metaStatement(
struct VRMLParser* me) {
1276 lexer_skip(me->lexer);
1279 if(!lexer_keyword(me->lexer, KW_META))
return FALSE;
1281 #ifdef CPARSERVERBOSE
1282 printf (
"parser_metaStatement...\n");
1288 val1=NULL; val2 = NULL;
1290 if(!parser_sfstringValue (me, &val1)) {
1291 CPARSE_ERROR_CURID(
"Expected a string after a META keyword")
1294 if(!parser_sfstringValue (me, &val2)) {
1295 CPARSE_ERROR_CURID(
"Expected a string after a META keyword")
1298 if ((val1 != NULL) && (val2 != NULL)) { handleMetaDataStringString(val1,val2); }
1301 if (val1 != NULL) {FREE_IF_NZ(val1->strptr); FREE_IF_NZ(val1);}
1302 if (val2 != NULL) {FREE_IF_NZ(val2->strptr); FREE_IF_NZ(val2);}
1305 static BOOL parser_unitStatement(
struct VRMLParser* me) {
1307 double conversionfactor;
1308 char *categoryname = NULL;
1309 char *unitname = NULL;
1313 lexer_skip(me->lexer);
1316 if(!lexer_keyword(me->lexer, KW_UNIT))
return FALSE;
1318 #ifdef CPARSERVERBOSE
1319 printf (
"parser_unitStatement...\n");
1325 categoryname=NULL; unitname = NULL; conversionfactor = 0.0;
1327 if(!lexer_setCurID(me->lexer))
return TRUE;
1328 ASSERT(me->lexer->curID);
1330 categoryname = STRDUP(me->lexer->curID);
1331 FREE_IF_NZ(me->lexer->curID);
1333 if(!lexer_setCurID(me->lexer))
return TRUE;
1334 ASSERT(me->lexer->curID);
1336 unitname = STRDUP(me->lexer->curID);
1337 FREE_IF_NZ(me->lexer->curID);
1339 if(!parser_sftimeValue(me,&conversionfactor)) {
1340 CPARSE_ERROR_CURID(
"Expected a numeric string after a UNIT keyword")
1343 if ((categoryname != NULL) && (unitname != NULL) && (conversionfactor != 0.0)) {
1344 handleUnitDataStringString(categoryname,unitname,conversionfactor);
1348 if (categoryname != NULL) FREE_IF_NZ(categoryname);
1349 if (unitname != NULL) FREE_IF_NZ(unitname);
1354 static BOOL parser_profileStatement(
struct VRMLParser* me) {
1355 int myProfile = INT_ID_UNDEFINED;
1358 lexer_skip(me->lexer);
1361 if(!lexer_keyword(me->lexer, KW_PROFILE))
return FALSE;
1363 #ifdef CPARSERVERBOSE
1364 printf (
"parser_profileStatement...\n");
1367 if(!lexer_setCurID(me->lexer))
return TRUE;
1368 ASSERT(me->lexer->curID);
1370 myProfile = findFieldInPROFILES(me->lexer->curID);
1372 if (myProfile != ID_UNDEFINED) {
1373 handleProfile(myProfile);
1375 CPARSE_ERROR_CURID(
"Expected a profile after a PROFILE keyword")
1380 #ifdef CPARSERVERBOSE
1381 printf (
"my profile is %d\n",myProfile);
1384 FREE_IF_NZ(me->lexer->curID);
1393 static BOOL parser_routeStatement_B(
struct VRMLParser* me);
1395 static BOOL parser_routeStatement(
struct VRMLParser* me)
1397 return parser_routeStatement_B(me);
1403 void parser_registerRoute(
struct VRMLParser* me,
1404 struct X3D_Node* fromNode,
int fromOfs,
1405 struct X3D_Node* toNode,
int toOfs,
1409 if ((fromOfs == ID_UNDEFINED) || (toOfs == ID_UNDEFINED)) {
1410 ConsoleMessage (
"problem registering route - either fromField or toField invalid");
1412 CRoutes_RegisterSimple(fromNode, fromOfs, toNode, toOfs, ft);
1419 int ind = ID_UNDEFINED;
1424 if(!lexer_defineNodeName(me->lexer, &ind))
1425 PARSE_ERROR(
"Expected nodeNameId after DEF!\n")
1426 ASSERT(ind!=ID_UNDEFINED);
1430 if(!me->DEFedNodes || stack_empty(me->DEFedNodes)) {
1432 parser_scopeIn_DEFUSE(me);
1434 ASSERT(me->DEFedNodes);
1435 ASSERT(!stack_empty(me->DEFedNodes));
1439 ASSERT(ind<=vectorSize(stack_top(
struct Vector*, me->DEFedNodes)));
1440 if(ind==vectorSize(stack_top(
struct Vector*, me->DEFedNodes))) {
1441 vector_pushBack(
struct X3D_Node*, stack_top(
struct Vector*, me->DEFedNodes), NULL);
1443 ASSERT(ind<vectorSize(stack_top(
struct Vector*, me->DEFedNodes)));
1449 #ifdef CPARSERVERBOSE
1450 printf(
"parser_KW_DEF: parsing DEFed node \n");
1452 if(!parser_node(me, &node,ind)) {
1455 CPARSE_ERROR_CURID(
"ERROR:Expected an X3D node in a DEF statement, got \"");
1459 #ifdef CPARSERVERBOSE
1460 printf(
"parser_KW_DEF: DEFed node successfully parsed\n");
1476 if(!lexer_nodeName(me->lexer, &ind)) {
1477 CPARSE_ERROR_CURID(
"ERROR:Expected valid DEF name after USE; found: ");
1478 FREE_IF_NZ(me->lexer->curID);
1481 #ifdef CPARSERVERBOSE
1482 printf(
"parser_KW_USE: parsing USE\n");
1486 ASSERT(ind!=ID_UNDEFINED);
1489 ASSERT(me->DEFedNodes && !stack_empty(me->DEFedNodes) &&
1490 ind<vectorSize(stack_top(
struct Vector*, me->DEFedNodes)));
1492 #ifdef CPARSERVERBOSE
1493 printf (
"parser_KW_USE, returning vector %u\n", vector_get(
struct X3D_Node*, stack_top(
struct Vector*, me->DEFedNodes), ind));
1517 void push_binding_stack_set(
struct X3D_Node* layersetnode);
1518 void push_next_layerId_from_binding_stack_set(
struct X3D_Node *layer);
1519 void pop_binding_stack_set();
1526 if(lexer_keyword(me->lexer, KW_DEF)) {
1529 *ret = parse_KW_DEF(me);
1534 if(lexer_keyword(me->lexer, KW_USE)) {
1535 *ret= parse_KW_USE(me);
1540 return parser_node(me, ret, ID_UNDEFINED);
1550 for(i=0; i!=node->n; ++i) {
1551 ADD_PARENT(node->p[i], parent);
1561 void deleteMallocedFieldValue(
int type,
union anyVrml *fieldPtr);
1562 static BOOL parser_fieldValue(
struct VRMLParser* me,
struct X3D_Node *node,
int offs,
1565 #undef PARSER_FINALLY
1566 #define PARSER_FINALLY
1568 #ifdef CPARSERVERBOSE
1569 printf (
"start of parser_fieldValue\n");
1570 printf (
"me->curPROTO = %u\n",me->curPROTO);
1574 #ifdef CPARSERVERBOSE
1575 printf (
"parser_fieldValue, not an IS\n");
1578 #define myOffsetPointer_deref(t, me) \
1579 ((t)(((char*)(node))+offs))
1581 void* directRet=myOffsetPointer_deref(
void*, ret);
1582 deleteMallocedFieldValue(type,directRet);
1597 #ifdef CPARSERVERBOSE
1598 printf (
"parser_fieldValue, me %u, directRet %u\n",me,directRet);
1602 return PARSE_TYPE[type](me, directRet);
1605 #undef PARSER_FINALLY
1606 #define PARSER_FINALLY
1613 #define NODE_SPECIFIC_INIT(type, code) \
1616 struct X3D_##type* node=(struct X3D_##type*)n; \
1621 switch(n->_nodeType)
1624 NODE_SPECIFIC_INIT(Script, node->__scriptObj=new_Shader_ScriptB(X3D_NODE(node));)
1625 NODE_SPECIFIC_INIT(ShaderProgram, node->_shaderUserDefinedFields=X3D_NODE(new_Shader_ScriptB(X3D_NODE(node)));)
1626 NODE_SPECIFIC_INIT(PackagedShader, node->_shaderUserDefinedFields=X3D_NODE(new_Shader_ScriptB(X3D_NODE(node)));)
1627 NODE_SPECIFIC_INIT(ComposedShader, node->_shaderUserDefinedFields=X3D_NODE(new_Shader_ScriptB(X3D_NODE(node)));)
1628 NODE_SPECIFIC_INIT(Effect, node->_shaderUserDefinedFields=X3D_NODE(new_Shader_ScriptB(X3D_NODE(node)));)
1638 #define INIT_CODE_sfnode(var) \
1639 ADD_PARENT(node2->var, X3D_NODE(node2));
1640 #define INIT_CODE_mfnode(var) \
1641 mfnode_add_parent(&node2->var, X3D_NODE(node2));
1642 #define INIT_CODE_sfbool(var)
1643 #define INIT_CODE_sfcolor(var)
1644 #define INIT_CODE_sfcolorrgba(var)
1645 #define INIT_CODE_sffloat(var)
1646 #define INIT_CODE_sfimage(var)
1647 #define INIT_CODE_sfint32(var)
1648 #define INIT_CODE_sfrotation(var)
1649 #define INIT_CODE_sfstring(var)
1650 #define INIT_CODE_sftime(var)
1651 #define INIT_CODE_sfvec2f(var)
1652 #define INIT_CODE_sfvec3f(var)
1653 #define INIT_CODE_sfvec3d(var)
1654 #define INIT_CODE_mfbool(var)
1655 #define INIT_CODE_mfcolor(var)
1656 #define INIT_CODE_mfcolorrgba(var)
1657 #define INIT_CODE_mffloat(var)
1658 #define INIT_CODE_mfint32(var)
1659 #define INIT_CODE_mfrotation(var)
1660 #define INIT_CODE_mfstring(var)
1661 #define INIT_CODE_mftime(var)
1662 #define INIT_CODE_mfvec2f(var)
1663 #define INIT_CODE_mfvec3f(var)
1664 #define INIT_CODE_mfvec3d(var)
1665 #define INIT_CODE_sfdouble(var)
1666 #define INIT_CODE_mfdouble(var)
1667 #define INIT_CODE_sfvec4d(var)
1668 #define INIT_CODE_mfmatrix3f(var)
1669 #define INIT_CODE_mfmatrix4f(var)
1671 #define INIT_CODE_mfmatrix3d(var)
1672 #define INIT_CODE_mfmatrix4d(var)
1673 #define INIT_CODE_mfvec2d(var)
1674 #define INIT_CODE_mfvec4d(var)
1675 #define INIT_CODE_mfvec4f(var)
1676 #define INIT_CODE_sfmatrix3d(var)
1677 #define INIT_CODE_sfmatrix3f(var)
1678 #define INIT_CODE_sfmatrix4d(var)
1679 #define INIT_CODE_sfmatrix4f(var)
1680 #define INIT_CODE_sfvec2d(var)
1681 #define INIT_CODE_sfvec4f(var)
1700 if(!lexer_field(me->lexer, &fieldO, &fieldE, NULL, NULL))
1718 #define EVENT_IN(n, f, t, v, realType)
1719 #define EVENT_OUT(n, f, t, v, realType)
1722 #define END_NODE(type) \
1728 #define FTIND_sfnode FIELDTYPE_SFNode
1729 #define FTIND_sfbool FIELDTYPE_SFBool
1730 #define FTIND_sfcolor FIELDTYPE_SFColor
1731 #define FTIND_sfcolorrgba FIELDTYPE_SFColorRGBA
1732 #define FTIND_sffloat FIELDTYPE_SFFloat
1733 #define FTIND_sfimage FIELDTYPE_SFImage
1734 #define FTIND_sfint32 FIELDTYPE_SFInt32
1735 #define FTIND_sfrotation FIELDTYPE_SFRotation
1736 #define FTIND_sfstring FIELDTYPE_SFString
1737 #define FTIND_sftime FIELDTYPE_SFTime
1738 #define FTIND_sfdouble FIELDTYPE_SFDouble
1739 #define FTIND_sfvec2f FIELDTYPE_SFVec2f
1740 #define FTIND_sfvec2d FIELDTYPE_SFVec2d
1741 #define FTIND_sfvec3f FIELDTYPE_SFVec3f
1742 #define FTIND_sfvec3d FIELDTYPE_SFVec3d
1743 #define FTIND_sfvec4f FIELDTYPE_SFVec4f
1744 #define FTIND_sfvec4d FIELDTYPE_SFVec4d
1745 #define FTIND_sfmatrix3f FIELDTYPE_SFMatrix3f
1746 #define FTIND_sfmatrix4f FIELDTYPE_SFMatrix4f
1747 #define FTIND_sfmatrix3d FIELDTYPE_SFMatrix3d
1748 #define FTIND_sfmatrix4d FIELDTYPE_SFMatrix4d
1750 #define FTIND_mfnode FIELDTYPE_MFNode
1751 #define FTIND_mfbool FIELDTYPE_MFBool
1752 #define FTIND_mfcolor FIELDTYPE_MFColor
1753 #define FTIND_mfcolorrgba FIELDTYPE_MFColorRGBA
1754 #define FTIND_mffloat FIELDTYPE_MFFloat
1755 #define FTIND_mfint32 FIELDTYPE_MFInt32
1756 #define FTIND_mfrotation FIELDTYPE_MFRotation
1757 #define FTIND_mfstring FIELDTYPE_MFString
1758 #define FTIND_mftime FIELDTYPE_MFTime
1759 #define FTIND_mfvec2f FIELDTYPE_MFVec2f
1760 #define FTIND_mfvec2d FIELDTYPE_MFVec2d
1761 #define FTIND_mfvec3f FIELDTYPE_MFVec3f
1762 #define FTIND_mfvec3d FIELDTYPE_MFVec3d
1763 #define FTIND_mfvec4d FIELDTYPE_MFVec4d
1764 #define FTIND_mfvec4f FIELDTYPE_MFVec4f
1765 #define FTIND_mfdouble FIELDTYPE_MFDouble
1766 #define FTIND_mfmatrix3f FIELDTYPE_MFMatrix3f
1767 #define FTIND_mfmatrix4f FIELDTYPE_MFMatrix4f
1768 #define FTIND_mfmatrix3d FIELDTYPE_MFMatrix3d
1769 #define FTIND_mfmatrix4d FIELDTYPE_MFMatrix4d
1775 #define PROCESS_FIELD_B(exposed, node, field, fieldType, var, fe) \
1776 case exposed##FIELD_##field: \
1777 if(!parser_fieldValue(me, \
1778 X3D_NODE(node2), (int) offsetof(struct X3D_##node, var), \
1779 FTIND_##fieldType, fe, FALSE, NULL, NULL)) {\
1780 PARSE_ERROR("Expected " #fieldType " Value for a fieldtype!") }\
1781 INIT_CODE_##fieldType(var) \
1788 #define NODE_DEFAULT_B \
1790 PARSE_ERROR("Parser PROCESS_FIELD_B, Unsupported node!")
1797 if(fieldE!=ID_UNDEFINED)
1798 switch(node->_nodeType)
1802 #define BEGIN_NODE(type) \
1805 struct X3D_##type* node2=(struct X3D_##type*)node; \
1812 #define EXPOSED_FIELD(node, field, fieldType, var, realType) \
1813 PROCESS_FIELD_B(EXPOSED_, node, field, fieldType, var, fieldE)
1816 #define FIELD(n, f, t, v, realType)
1819 #include "NodeFields.h"
1824 #undef EXPOSED_FIELD
1831 if(fieldO!=ID_UNDEFINED)
1832 switch(node->_nodeType)
1836 #define BEGIN_NODE(type) \
1839 struct X3D_##type* node2=(struct X3D_##type*)node; \
1845 #define FIELD(node, field, fieldType, var, realType) \
1846 PROCESS_FIELD_B(, node, field, fieldType, var, ID_UNDEFINED)
1849 #define EXPOSED_FIELD(n, f, t, v, realType)
1852 #include "NodeFields.h"
1857 #undef EXPOSED_FIELD
1869 PARSE_ERROR(
"Unsupported field for node!")
1876 return parser_field_B(me,node);
1892 case FIELDTYPE_MFNode:
1895 outMF->p=MALLOC(
void *,
sizeof(
struct X3D_Node*));
1899 case FIELDTYPE_MFFloat:
1900 case FIELDTYPE_MFRotation:
1901 case FIELDTYPE_MFVec3f:
1902 case FIELDTYPE_MFBool:
1903 case FIELDTYPE_MFInt32:
1904 case FIELDTYPE_MFColor:
1905 case FIELDTYPE_MFColorRGBA:
1906 case FIELDTYPE_MFTime:
1907 case FIELDTYPE_MFDouble:
1908 case FIELDTYPE_MFString:
1909 case FIELDTYPE_MFVec2f:
1911 localSize = returnRoutingElementLength(convertToSFType(type));
1915 outMF->p=MALLOC(
void *, localSize);
1916 memcpy (&outMF->p[0], &in, localSize);
1920 ConsoleMessage(
"VRML Parser; stuffDEFUSE, unhandled type");
1935 rsz = returnElementRowSize(type);
1936 elelen = returnElementLength(type);
1951 for (i=0; i<outMF->n; i++) {
1952 if (type == FIELDTYPE_MFString) {
1955 FREE_IF_NZ(m->strptr);
1960 if (outMF->n != 1) {
1962 FREE_IF_NZ(outMF->p);
1964 outMF->p=MALLOC(
void *, rsz * elelen);
1969 memcpy (outMF->p, inSF, rsz * elelen);
1973 #define PARSER_MFFIELD(name, type) \
1974 static BOOL parser_mf##name##Value(struct VRMLParser* me, void *ret) { \
1975 struct Vector* vec; \
1977 struct Multi_##type *rv; \
1985 if (!(me->parsingX3DfromXML)) { \
1987 if(lexer_keyword(me->lexer, KW_USE)) { \
1990 RCX=parse_KW_USE(me); \
1991 if (RCX == NULL) return FALSE; \
1993 stuffDEFUSE(ret, RCX, FIELDTYPE_MF##type); \
1997 else if (lexer_keyword(me->lexer, KW_DEF)) { \
2000 RCX=parse_KW_DEF(me); \
2001 if (RCX == NULL) return FALSE; \
2004 stuffDEFUSE(ret, RCX, FIELDTYPE_MF##type); \
2011 if (me->lexer->curID != NULL) { \
2013 if (!parser_node(me, &RCX, ID_UNDEFINED)) { \
2016 if (RCX == NULL) return FALSE; \
2018 stuffDEFUSE(ret, RCX, FIELDTYPE_MF##type); \
2023 if((!lexer_openSquare(me->lexer)) && (!(me->parsingX3DfromXML))) { \
2024 vrml##type##T RCXRet; \
2026 if(!parser_sf##name##Value(me, &RCXRet)) { \
2033 stuffSFintoMF(ret, (vrmlNodeT *)&RCXRet, FIELDTYPE_MF##type); \
2039 vec=newVector(vrml##type##T, 128); \
2040 if (!me->parsingX3DfromXML) { \
2041 while(!lexer_closeSquare(me->lexer)) { \
2042 vrml##type##T val; \
2043 if(!parser_sf##name##Value(me, &val)) { \
2044 CPARSE_ERROR_CURID("ERROR:Expected \"]\" before end of MF-Value") \
2047 vector_pushBack(vrml##type##T, vec, val); \
2050 lexer_skip(me->lexer); \
2051 while(*me->lexer->nextIn != '\0') { \
2052 vrml##type##T val; \
2053 if(!parser_sf##name##Value(me, &val)) { \
2054 CPARSE_ERROR_CURID("ERROR:Expected \"]\" before end of MF-Value") \
2057 vector_pushBack(vrml##type##T, vec, val); \
2058 lexer_skip(me->lexer); \
2061 rv = (struct Multi_##type*) ret; \
2062 rv->n=vectorSize(vec); \
2063 rv->p=vector_releaseData(vrml##type##T, vec); \
2065 deleteVector(vrml##type##T, vec); \
2069 PARSER_MFFIELD(
bool, Bool)
2070 PARSER_MFFIELD(color, Color)
2071 PARSER_MFFIELD(colorrgba, ColorRGBA)
2072 PARSER_MFFIELD(
float, Float)
2073 PARSER_MFFIELD(int32, Int32)
2074 PARSER_MFFIELD(node, Node)
2075 PARSER_MFFIELD(rotation, Rotation)
2076 PARSER_MFFIELD(
string, String)
2077 PARSER_MFFIELD(time, Time)
2078 PARSER_MFFIELD(vec2f, Vec2f)
2079 PARSER_MFFIELD(vec3f, Vec3f)
2080 PARSER_MFFIELD(vec3d, Vec3d)
2081 PARSER_MFFIELD(vec2d, Vec2d)
2082 PARSER_MFFIELD(vec4f, Vec4f)
2083 PARSER_MFFIELD(vec4d, Vec4d)
2089 #define PARSER_FIXED_VEC(name, type, cnt) \
2090 BOOL parser_sf##name##Value(struct VRMLParser* me, void* ret) \
2093 vrml##type##T *rv; \
2094 ASSERT(me->lexer); \
2095 rv = (vrml##type##T *) ret; \
2096 for(i=0; i!=cnt; ++i) {\
2097 if(!parser_sffloatValue(me, rv->c+i)) \
2104 #define PARSER_FIXED_DOUBLE_VEC(name, type, cnt) \
2105 BOOL parser_sf##name##Value(struct VRMLParser* me, void* ret) \
2108 vrml##type##T *rv; \
2109 ASSERT(me->lexer); \
2110 rv = (vrml##type##T *) ret; \
2111 for(i=0; i!=cnt; ++i) {\
2112 if(!parser_sfdoubleValue_(me, rv->c+i)) \
2118 BOOL parser_sfdoubleValue_(
struct VRMLParser* me, vrmlDoubleT* ret)
2120 return lexer_double(me->lexer, ret);
2122 static BOOL parser_sffloatValue_(
struct VRMLParser* me,
void* ret)
2125 rf = (vrmlFloatT*)ret;
2126 return lexer_float(me->lexer, rf);
2128 static BOOL parser_sfint32Value_(
struct VRMLParser* me,
void* ret)
2131 rf = (vrmlInt32T*)ret;
2132 return lexer_int32(me->lexer, rf);
2139 *ret=newASCIIString((
char *)me->startOfStringPtr[me->lexerInputLevel]);
2143 static BOOL parser_sfstringValue_(
struct VRMLParser* me,
void* ret) {
2150 if (!me->parsingX3DfromXML)
return lexer_string(me->lexer, rv);
2152 else return set_X3Dstring(me->lexer, rv);
2157 static BOOL parser_sfboolValue(
struct VRMLParser* me,
void* ret) {
2160 rv = (vrmlBoolT*)ret;
2163 if (!me->parsingX3DfromXML) {
2164 if(lexer_keyword(me->lexer, KW_TRUE)) {
2168 if(lexer_keyword(me->lexer, KW_FALSE)) {
2175 if (!strcmp(me->lexer->startOfStringPtr[me->lexer->lexerInputLevel],
"true")) {
2179 if (!strcmp(me->lexer->startOfStringPtr[me->lexer->lexerInputLevel],
"false")) {
2185 if (!gglobal()->internalc.global_strictParsing && (!strcmp(me->lexer->startOfStringPtr[me->lexer->lexerInputLevel],
"TRUE"))) {
2186 CPARSE_ERROR_CURID(
"found upper case TRUE in XML file - should be lower case");
2190 if (!gglobal()->internalc.global_strictParsing && (!strcmp(me->lexer->startOfStringPtr[me->lexer->lexerInputLevel],
"FALSE"))) {
2191 CPARSE_ERROR_CURID (
"found upper case FALSE in XML file - should be lower case");
2203 PARSER_FIXED_VEC(color, Color, 3)
2204 PARSER_FIXED_VEC(colorrgba, ColorRGBA, 4)
2205 PARSER_FIXED_VEC(matrix3f, Matrix3f, 9)
2206 PARSER_FIXED_VEC(matrix4f, Matrix4f, 16)
2207 PARSER_FIXED_VEC(vec2f, Vec2f, 2)
2208 PARSER_FIXED_VEC(vec4f, Vec4f, 4)
2209 PARSER_FIXED_VEC(rotation, Rotation, 4)
2210 PARSER_FIXED_DOUBLE_VEC(vec2d, Vec2d, 2)
2211 PARSER_FIXED_DOUBLE_VEC(vec3d, Vec3d, 3)
2212 PARSER_FIXED_DOUBLE_VEC(vec4d, Vec4d, 4)
2213 PARSER_FIXED_DOUBLE_VEC(matrix3d, Matrix3d, 9)
2214 PARSER_FIXED_DOUBLE_VEC(matrix4d, Matrix4d, 16)
2219 static BOOL parser_sfimageValue(struct
VRMLParser* me,
void* ret)
2222 vrmlInt32T width, height, depth;
2227 if(!lexer_int32(me->lexer, &width))
2229 if(!lexer_int32(me->lexer, &height))
2231 if(!lexer_int32(me->lexer, &depth))
2235 rv->n=3+width*height;
2236 rv->p=MALLOC(
int *,
sizeof(
int) * rv->n);
2241 for(ptr=rv->p+3; ptr!=rv->p+rv->n; ++ptr)
2242 if(!lexer_int32(me->lexer, ptr))
2253 static BOOL parser_sfnodeValue(
struct VRMLParser* me,
void* ret) {
2260 if(lexer_keyword(me->lexer, KW_NULL)) {
2266 if (!me->parsingX3DfromXML) {
2267 return parser_nodeStatement(me, rv);
2270 if (sscanf(me->lexer->startOfStringPtr[me->lexer->lexerInputLevel],
"%lu", &tmp) != 1) {
2271 CPARSE_ERROR_FIELDSTRING (
"error finding SFNode id on line :%s:",
2272 me->lexer->startOfStringPtr[me->lexer->lexerInputLevel]);
2282 static BOOL parser_sftimeValue(
struct VRMLParser* me,
void* ret)
2285 rv = (vrmlTimeT*)ret;
2286 return lexer_double(me->lexer, rv);
2290 static BOOL parser_fieldTypeNotParsedYet(
struct VRMLParser* me,
void* ret) {
2291 CPARSE_ERROR_CURID (
"received a request to parse a type not supported yet");
2297 #define OUTLINELEN 800
2299 void cParseErrorCurID(
struct VRMLParser *me,
char *str) {
2300 char fw_outline[OUTLINELEN];
2303 if (strlen(str) > FROMSRC) {
2304 strncpy(fw_outline,str,FROMSRC);
2305 fw_outline[FROMSRC-1] =
'\0';
2307 strcpy(fw_outline,str);
2309 if (me->lexer->curID != ((
void *)0)) {
2310 strcat (fw_outline,
"; current token :");
2311 strcat (fw_outline, me->lexer->curID);
2312 strcat (fw_outline,
": ");
2314 if (me->lexer->nextIn != NULL) {
2315 strcat (fw_outline,
" at: \"");
2316 strncat(fw_outline,me->lexer->nextIn,FROMSRC);
2317 if (strlen(me->lexer->nextIn) > FROMSRC)
2318 strcat (fw_outline,
"...");
2319 strcat (fw_outline,
"\"");
2322 p->foundInputErrors++;
2323 ConsoleMessage(fw_outline);
2326 void cParseErrorFieldString(
struct VRMLParser *me,
char *str,
const char *str2) {
2328 char fw_outline[OUTLINELEN];
2329 int str2len = (int) strlen(str2);
2332 if (strlen(str) > FROMSRC) str[FROMSRC] =
'\0';
2333 strcpy(fw_outline,str);
2334 strcat (fw_outline,
" (");
2335 strncat (fw_outline,str2,str2len);
2336 strcat (fw_outline,
") ");
2337 if (me->lexer->curID != ((
void *)0)) strcat (fw_outline, me->lexer->curID);
2338 if (me->lexer->nextIn != NULL) {
2339 strcat (fw_outline,
" at: \"");
2340 strncat(fw_outline,me->lexer->nextIn,FROMSRC);
2341 if (strlen(me->lexer->nextIn) > FROMSRC)
2342 strcat (fw_outline,
"...");
2343 strcat (fw_outline,
"\"");
2346 p->foundInputErrors++;
2347 ConsoleMessage(fw_outline);
2429 void add_node_to_broto_context(
struct X3D_Proto *currentContext,
struct X3D_Node *node);
2431 static BOOL parser_externbrotoStatement(
struct VRMLParser* me);
2433 int nodeTypeB, nodeTypeU, isBroto;
2441 currentContext = (
struct X3D_Proto*)me->ectx;
2442 pflagdepth = ciflag_get(currentContext->__protoFlags,0);
2453 #ifdef CPARSERVERBOSE
2454 printf (
"parser_node START, curID :%s: nextIn :%s:\n",me->lexer->curID, me->lexer->nextIn);
2459 if(parser_routeStatement(me)) {
2463 if (parser_componentStatement(me)) {
2467 if (parser_exportStatement(me)) {
2471 if (parser_importStatement(me)) {
2475 if (parser_metaStatement(me)) {
2479 if (parser_profileStatement(me)) {
2482 if(parser_brotoStatement(me)) {
2485 if(parser_externbrotoStatement(me)) {
2492 if(!lexer_node(me->lexer, &nodeTypeB, &nodeTypeU)) {
2493 #ifdef CPARSERVERBOSE
2494 printf (
"parser_node, not lexed - is this one of those special nodes?\n");
2503 if(!lexer_openCurly(me->lexer))
2504 PARSE_ERROR(
"Expected { after node-type id!")
2506 #ifdef CPARSERVERBOSE
2507 printf (
"parser_node: have nodeTypeB %d nodeTypeU %d\n",nodeTypeB, nodeTypeU);
2510 if (nodeTypeU != ID_UNDEFINED) {
2516 char *protoname = vector_get(
char*, me->lexer->userNodeTypesVec, nodeTypeU);
2520 if( isAvailableBroto(protoname, currentContext , &proto))
2524 idepth = pflagdepth == 1;
2525 node=X3D_NODE(brotoInstance(proto,idepth));
2526 node->_executionContext = X3D_NODE(currentContext);
2527 add_node_to_broto_context(currentContext,node);
2531 if (ind != ID_UNDEFINED) {
2534 vector_get(
struct X3D_Node*, stack_top(
struct Vector*, me->DEFedNodes), ind)=node;
2535 #ifdef CPARSERVERBOSE
2536 printf(
"parser_node: adding DEFed node (pointer %p) to DEFedNodes vector\n", node);
2538 name = vector_get(
char*, stack_top(
struct Vector*, me->lexer->userNodeNames), ind);
2539 broto_store_DEF((
struct X3D_Proto*)(me->ectx),node, name);
2546 if(nodeTypeB!=ID_UNDEFINED) {
2547 #ifdef CPARSERVERBOSE
2548 printf(
"parser_node: parsing builtin node\n");
2553 node=X3D_NODE(createNewX3DNode((
int)nodeTypeB));
2554 if(node->_nodeType == NODE_Inline){
2555 if(X3D_NODE(me->ectx)->_nodeType != NODE_Inline && X3D_NODE(me->ectx)->_nodeType != NODE_Proto)
2556 printf(
"ouch trying to caste a %d nodetype to inline or proto\n",X3D_NODE(me->ectx)->_nodeType);
2557 X3D_INLINE(node)->__parentProto = me->ectx;
2560 node=X3D_NODE(createNewX3DNode0((
int)nodeTypeB));
2562 node->_executionContext = X3D_NODE(currentContext);
2563 add_node_to_broto_context(currentContext,node);
2568 if (ind != ID_UNDEFINED) {
2571 vector_get(
struct X3D_Node*, stack_top(
struct Vector*, me->DEFedNodes), ind)=node;
2572 name = vector_get(
char*, stack_top(
struct Vector*, me->lexer->userNodeNames), ind);
2573 broto_store_DEF((
struct X3D_Proto*)(me->ectx),node, name);
2575 #ifdef CPARSERVERBOSE
2576 printf(
"parser_node: adding DEFed node (pointer %p) to DEFedNodes vector\n", node);
2583 parser_specificInitNode_B(node, me);
2586 switch (node->_nodeType) {
2587 case NODE_Script: script=X3D_SCRIPT(node)->__scriptObj;
break;
2588 case NODE_ShaderProgram: shader=(
struct Shader_Script *)(X3D_SHADERPROGRAM(node)->_shaderUserDefinedFields);
break;
2589 case NODE_PackagedShader: shader=(
struct Shader_Script *)(X3D_PACKAGEDSHADER(node)->_shaderUserDefinedFields);
break;
2590 case NODE_ComposedShader: shader=(
struct Shader_Script *)(X3D_COMPOSEDSHADER(node)->_shaderUserDefinedFields);
break;
2591 case NODE_Effect: shader=(
struct Shader_Script *)(X3D_EFFECT(node)->_shaderUserDefinedFields);
break;
2593 push_binding_stack_set(node);
break;
2594 case NODE_LayoutLayer:
2596 push_next_layerId_from_binding_stack_set(node);
break;
2608 if( (nodeTypeB!=ID_UNDEFINED) || isBroto)
2610 #define SPLIT_SCRIPTUSERFIELD_CREATION_FROM_VALUEPARSING 1
2619 #ifdef CPARSERVERBOSE
2620 printf(
"parser_node: try parsing field ... \n");
2623 if( found_IS_field(me,node) ){
2627 if(SPLIT_SCRIPTUSERFIELD_CREATION_FROM_VALUEPARSING)
2628 if(parser_field_user(me,node)) {
2633 if(parser_field(me, node)) {
2634 #ifdef CPARSERVERBOSE
2635 printf(
"parser_node: field parsed\n");
2644 #ifdef CPARSERVERBOSE
2645 printf(
"parser_node: try parsing ROUTE ... \n");
2650 BLOCK_STATEMENT(parser_node);
2660 #ifdef CPARSERVERBOSE
2661 printf(
"parser_node: try parsing PROTO ... \n");
2672 if(parser_brotoStatement(me)) {
2673 #ifdef CPARSERVERBOSE
2674 printf(
"parser_vrmlScene: BROTO parsed\n");
2679 #ifdef CPARSERVERBOSE
2680 printf(
"parser_node: try parsing Script or Shader field\n");
2690 if(SPLIT_SCRIPTUSERFIELD_CREATION_FROM_VALUEPARSING)
2691 if(script && parser_interfaceDeclarationB(me, NULL, script)){
2694 if(!SPLIT_SCRIPTUSERFIELD_CREATION_FROM_VALUEPARSING)
2695 if(script && parser_interfaceDeclaration(me, NULL, script)) {
2696 #ifdef CPARSERVERBOSE
2697 printf(
"parser_node: SCRIPT field parsed\n");
2702 if(shader && parser_interfaceDeclaration(me, NULL, shader)) {
2703 #ifdef CPARSERVERBOSE
2704 printf(
"parser_node: Shader field parsed\n");
2714 #ifdef CPARSERVERBOSE
2715 printf(
"parser_node: try parsing SCRIPT url\n");
2719 initialize_one_script(script,&X3D_SCRIPT(node)->url);
2720 #ifdef CPARSERVERBOSE
2721 printf(
"parser_node: SCRIPT url parsed\n");
2725 if(isBroto && pflagdepth){
2733 ptype = X3D_PROTO(X3D_PROTO(node)->__prototype);
2734 pdest = X3D_PROTO(node);
2735 deep_copy_broto_body2(&ptype,&pdest);
2745 #ifdef CPARSERVERBOSE
2746 printf (
"calling lexer_closeCurly at B\n");
2749 if(!lexer_closeCurly(me->lexer)) {
2750 CPARSE_ERROR_CURID(
"ERROR: Expected a closing brace after fields of a node;")
2754 if(node->_nodeType == NODE_LayerSet)
2755 pop_binding_stack_set();
2759 #ifdef CPARSERVERBOSE
2760 printf (
"returning at end of parser_node, ret %u\n",node);
2761 if (node != NULL) printf (
"and, node type is %s\n",stringNodeType(node->_nodeType));
2791 #ifdef CPARSERVERBOSE
2792 printf (
"start of parser_interfaceDeclaration\n");
2797 ASSERT((proto || script) && !(proto && script));
2804 if(!lexer_protoFieldMode(me->lexer, &mode)) {
2805 #ifdef CPARSERVERBOSE
2806 printf (
"parser_interfaceDeclaration, not lexer_protoFieldMode, returning\n");
2814 if (script != NULL) {
2815 if(script->ShaderScriptNode->_nodeType==NODE_Script && mode==PKW_inputOutput)
2817 PARSE_ERROR(
"Scripts must not have inputOutputs!")
2824 if(!lexer_fieldType(me->lexer, &type))
2825 PARSE_ERROR(
"Expected fieldType after proto-field keyword!")
2827 #ifdef CPARSERVERBOSE
2828 printf (
"parser_interfaceDeclaration, switching on mode %s\n",PROTOKEYWORDS[mode]);
2837 #define LEX_DEFINE_FIELDID(suff) \
2839 if(!lexer_define_##suff(me->lexer, &name)) \
2840 PARSE_ERROR("Expected fieldNameId after field type!") \
2843 LEX_DEFINE_FIELDID(initializeOnly)
2844 LEX_DEFINE_FIELDID(inputOnly)
2845 LEX_DEFINE_FIELDID(outputOnly)
2846 LEX_DEFINE_FIELDID(inputOutput)
2859 #ifdef CPARSERVERBOSE
2860 printf (
"parser_interfaceDeclaration, calling newProtoFieldDecl\n");
2863 pdecl=newProtoFieldDecl(mode, type, name);
2866 #ifdef CPARSERVERBOSE
2867 printf (
"parser_interfaceDeclaration, finished calling newProtoFieldDecl\n");
2870 #ifdef CPARSERVERBOSE
2871 printf (
"parser_interfaceDeclaration, calling newScriptFieldDecl\n");
2874 sdecl=newScriptFieldDecl(me->lexer, mode, type, name);
2882 if(mode==PKW_initializeOnly || mode==PKW_inputOutput) {
2883 #ifdef CPARSERVERBOSE
2884 printf (
"parser_interfaceDeclaration, mode==PKW_initializeOnly || mode==PKW_inputOutput\n");
2886 bzero (&defaultVal,
sizeof (
union anyVrml));
2890 pdecl->defaultVal=defaultVal;
2896 scriptFieldDecl_setFieldValue(sdecl, defaultVal);
2906 protoDefinition_addIfaceField(proto, pdecl);
2914 #ifdef CPARSERVERBOSE
2915 printf (
"end of parser_interfaceDeclaration\n");
2927 BOOL find_anyfield_by_name(
struct VRMLLexer* lexer,
struct X3D_Node* node,
union anyVrml **anyptr,
int *imode,
int *itype,
char* nodeFieldName,
int *isource,
void **fdecl,
int *ifield);
2928 void scriptFieldDecl_jsFieldInit(
struct ScriptFieldDecl* me,
int num);
2944 char *nodeFieldName;
2956 #ifdef CPARSERVERBOSE
2957 printf (
"start of parser_field_user\n");
2967 if(!lexer_setCurID(me->lexer))
return FALSE;
2968 ASSERT(me->lexer->curID);
2973 nodeFieldName = STRDUP(me->lexer->curID);
2980 FREE_IF_NZ(me->lexer->curID);
2984 if(!find_anyfield_by_name(me->lexer,node,&targetVal,&mode,&type,nodeFieldName,&source,&fdecl,&ifield)){
2987 FREE_IF_NZ(nodeFieldName);
2992 FREE_IF_NZ(nodeFieldName);
2997 if(mode==PKW_initializeOnly || mode==PKW_inputOutput) {
2998 #ifdef CPARSERVERBOSE
2999 printf (
"parser_field_user, mode==PKW_initializeOnly || mode==PKW_inputOutput\n");
3005 deleteMallocedFieldValue(type,targetVal);
3006 if (!parseType(me, type, targetVal)) {
3008 CPARSE_ERROR_CURID(
"Expected default value for field!");
3011 FREE_IF_NZ(nodeFieldName);
3020 struct X3D_Proto *pnode = X3D_PROTO(node);
3023 struct ProtoFieldDecl * pf = protoDefinition_getFieldByNum(pd, ifield);
3047 #ifdef CPARSERVERBOSE
3048 printf (
"end of parser_user_field\n");
3051 FREE_IF_NZ(nodeFieldName);
3061 static BOOL parser_brotoStatement(
struct VRMLParser* me)
3078 if(!lexer_keyword(me->lexer, KW_PROTO))
3087 if(!lexer_defineNodeType(me->lexer, &name))
3088 PARSE_ERROR(
"Expected nodeTypeId after PROTO!\n")
3089 ASSERT(name!=ID_UNDEFINED);
3092 obj=newProtoDefinition();
3095 if (vectorSize(me->lexer->userNodeTypesVec) != ID_UNDEFINED) {
3096 obj->protoName = STRDUP(vector_get(
const char*, me->lexer->userNodeTypesVec, vectorSize(me->lexer->userNodeTypesVec)-1));
3098 printf (
"warning - have proto but no name, so just copying a default string in\n");
3099 obj->protoName = STRDUP(
"noProtoNameDefined");
3102 #ifdef CPARSERVERBOSE
3103 printf (
"parser_protoStatement, working on proto :%s:\n",obj->protoName);
3108 parser_scopeIn_PROTO(me);
3122 if(!lexer_openSquare(me->lexer))
3123 PARSE_ERROR(
"Expected [ to start interface declaration!")
3129 while(parser_interfaceDeclaration(me, obj, NULL));
3132 if(!lexer_closeSquare(me->lexer))
3133 PARSE_ERROR("Expected ] after interface declaration!")
3143 proto = createNewX3DNode0(NODE_Proto);
3145 if(X3D_NODE(me->ectx)->_nodeType != NODE_Proto && X3D_NODE(me->ectx)->_nodeType != NODE_Inline )
3146 printf("ouch trying to caste node type %d to proto\n",X3D_NODE(me->ectx)->_nodeType);
3148 if(parent->__protoDeclares == NULL)
3149 parent->__protoDeclares = newVector(struct
X3D_Proto*,4);
3150 vector_pushBack(struct X3D_Proto*,parent->__protoDeclares,proto);
3153 proto->__parentProto = X3D_NODE(parent);
3154 proto->__protoFlags = parent->__protoFlags;
3155 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,0);
3157 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,2);
3158 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,3);
3160 proto->__protoDef = obj;
3161 proto->__prototype = X3D_NODE(proto);
3162 proto->__typename = STRDUP(obj->protoName);
3166 if(!lexer_openCurly(me->lexer))
3167 PARSE_ERROR("Expected { to start PROTO body!
")
3169 /* record the start of this proto body - keep the text around */
3170 //startOfBody = (char *) me->lexer->nextIn;
3171 //initCP = (char *) me->lexer->startOfStringPtr[me->lexer->lexerInputLevel];
3173 /* Create a new vector of nodes and push it onto the DEFedNodes stack */
3174 /* This is the list of nodes defined for this scope */
3175 /* Also checks that the PROTOs vector exists, and creates it if it does not */
3181 #ifdef CPARSERVERBOSE
3182 printf ("about to parse PROTO body;
new proto def %p\n
",obj);
3188 ofs = me->ofs; //Q. does this change? Or are we always ofs of children in Proto? H: parseFromString different
3191 me->ofs = offsetof(struct X3D_Proto, __children);
3192 parse_proto_body(me);
3197 /* We are done parsing this proto. Set the curPROTO to the last proto we were parsing. */
3198 // me->curPROTO=oldCurPROTO;
3200 if(!lexer_closeCurly(me->lexer))
3201 PARSE_ERROR("Expected } to end PROTO body!
")
3203 /* Takes the top DEFedNodes vector off of the stack. The local scope now refers to the next vector in the DEFedNodes stack */
3204 parser_scopeOut(me);
3206 /* Make sure that the next token is a '}'. Skip over it. */
3207 #ifdef CPARSERVERBOSE
3208 printf ("calling lexer_closeCurly at A\n
");
3209 printf ("parser_protoStatement, FINISHED proto :%s:\n
",obj->protoName);
3215 /* EXTERNPROTO keyword handling.
3216 Like PROTO above: parses ExternProtoDeclare Interface as a X3D_Proto
3217 - with __url and resource for fetching the definition
3219 #define LOAD_INITIAL_STATE 0
3220 static BOOL parser_externbrotoStatement(struct VRMLParser* me)
3223 struct ProtoDefinition* obj;
3224 //char *startOfBody;
3228 struct X3D_Proto *proto, *parent;
3234 /* Really a EXTERNPROTO? */
3236 if(!lexer_keyword(me->lexer, KW_EXTERNPROTO))
3243 /* lexer_defineNodeType is #defined as lexer_defineID(me, ret, userNodeTypesVec, FALSE) */
3244 /* Add the EXTERNPROTO name to the userNodeTypesVec list of names return the index of the name in the list in name */
3245 if(!lexer_defineNodeType(me->lexer, &name))
3246 PARSE_ERROR("Expected nodeTypeId after EXTERNPROTO!\n
")
3247 ASSERT(name!=ID_UNDEFINED);
3249 /* Create a new blank ProtoDefinition structure to contain the data for this EXTERNPROTO */
3250 obj=newProtoDefinition();
3251 obj->isExtern = TRUE;
3252 /* save the name, if we can get it - it will be the last name on the list, because we will have JUST parsed it. */
3253 if (vectorSize(me->lexer->userNodeTypesVec) != ID_UNDEFINED) {
3254 obj->protoName = STRDUP(vector_get(const char*, me->lexer->userNodeTypesVec, vectorSize(me->lexer->userNodeTypesVec)-1));
3256 printf ("warning - have proto but no name, so just copying a
default string in\n
");
3257 obj->protoName = STRDUP("noProtoNameDefined
");
3260 #ifdef CPARSERVERBOSE
3261 printf ("parser_protoStatement, working on proto :%s:\n
",obj->protoName);
3264 /* If the PROTOs stack has not yet been created, create it */
3266 parser_scopeIn_PROTO(me);
3270 /* ASSERT(name==vectorSize(me->PROTOs)); */
3272 /* Add the empty ProtoDefinition structure we just created onto the PROTOs stack */
3273 vector_pushBack(struct ProtoDefinition*, me->PROTOs, obj);
3275 /* Now we want to fill in the information in the ProtoDefinition */
3277 /* Interface declarations */
3279 /* Make sure that the next token is a '['. Skip over it. */
3280 if(!lexer_openSquare(me->lexer))
3281 PARSE_ERROR("Expected [ to start
interface declaration!")
3287 while(parser_interfaceDeclaration(me, obj, NULL));
3290 if(!lexer_closeSquare(me->lexer))
3291 PARSE_ERROR(
"Expected ] after interface declaration!")
3301 proto = createNewX3DNode0(NODE_Proto);
3304 if(parent->__externProtoDeclares == NULL)
3305 parent->__externProtoDeclares = newVector(struct
X3D_Proto*,4);
3306 vector_pushBack(struct X3D_Proto*,parent->__externProtoDeclares,proto);
3309 proto->__parentProto = X3D_NODE(parent);
3310 proto->__protoFlags = parent->__protoFlags;
3311 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,0);
3313 proto->__protoFlags = ciflag_set(proto->__protoFlags,0,2);
3314 proto->__protoFlags = ciflag_set(proto->__protoFlags,1,3);
3316 proto->__protoDef = obj;
3317 proto->__prototype = X3D_NODE(proto);
3318 proto->__typename = (
void *)STRDUP(obj->protoName);
3328 if (!parser_mfstringValue(me,&proto->url)) {
3329 PARSE_ERROR (
"EXTERNPROTO - problem reading URL string");
3331 proto->__loadstatus = LOAD_INITIAL_STATE;
3354 void broto_store_route(
struct X3D_Proto* proto,
3355 struct X3D_Node* fromNode,
int fromIndex,
3356 struct X3D_Node* toNode,
int toIndex,
3363 if ((fromIndex == ID_UNDEFINED) || (toIndex == ID_UNDEFINED)) {
3364 ConsoleMessage (
"problem registering route - either fromField or toField invalid");
3368 route = createNewBrotoRoute();
3369 route->from.node = fromNode;
3370 route->from.ifield = fromIndex;
3371 route->to.node = toNode;
3372 route->to.ifield = toIndex;
3373 route->lastCommand = 1;
3376 routes = proto->__ROUTES;
3377 if( routes == NULL){
3379 proto->__ROUTES = routes;
3381 stack_push(
struct brotoRoute *, routes, route);
3403 void broto_store_ImportRoute_obsolete(
struct X3D_Proto* proto,
char *fromNode,
char *fromField,
char *toNode,
char* toField)
3407 if( proto->__ROUTES == NULL)
3408 proto->__ROUTES= newStack(
struct brotoRoute *);
3409 route = createNewBrotoRoute();
3411 route->lastCommand = 0;
3412 route->from.weak = 2;
3413 route->from.cnode = STRDUP(fromNode);
3414 route->from.cfield = STRDUP(fromField);
3415 route->from.ftype = -1;
3417 route->to.cnode = STRDUP(toNode);
3418 route->to.cfield = STRDUP(toField);
3419 route->to.ftype = -1;
3420 stack_push(
struct brotoRoute *, proto->__ROUTES, route);
3428 void broto_store_broute(
struct X3D_Proto* context,
struct brotoRoute *route){
3429 if( context->__ROUTES == NULL)
3430 context->__ROUTES= newStack(
struct brotoRoute *);
3431 stack_push(
struct brotoRoute *, context->__ROUTES, route);
3433 void free_brouteEnd(
struct brouteEnd *bend){
3434 FREE_IF_NZ(bend->cnode);
3435 FREE_IF_NZ(bend->cfield);
3438 free_brouteEnd(&route->from);
3439 free_brouteEnd(&route->to);
3444 BOOL route_parse_nodefield(
struct VRMLParser* me,
int *NodeIndex,
struct X3D_Node** Node,
int KW_eventType,
3447 int PKW_eventType = PKW_outputOnly;
3454 char *nodeFieldName;
3465 if(KW_eventType == KW_outputOnly){
3466 PKW_eventType = PKW_outputOnly;
3467 cerror1 =
"Expected an event of type : outputOnly :";
3468 }
else if(KW_eventType == KW_inputOnly) {
3469 PKW_eventType = PKW_inputOnly;
3470 cerror1 =
"Expected an event of type : inputOnly :";
3476 if(!lexer_nodeName(me->lexer, NodeIndex)) {
3478 CPARSE_ERROR_CURID(
"ERROR:ROUTE: Expected a valid DEF name; found \"");
3485 ASSERT(me->DEFedNodes && !stack_empty(me->DEFedNodes) && *NodeIndex<vectorSize(stack_top(
struct Vector*, me->DEFedNodes)));
3488 stack_top(
struct Vector*, me->DEFedNodes),
3491 if (*Node == NULL) {
3493 CPARSE_ERROR_CURID(
"ERROR:ROUTE: no DEF name found - check scoping and \"}\"s");
3500 if(!lexer_point(me->lexer)) {
3501 CPARSE_ERROR_CURID(
"ERROR:ROUTE: Expected \".\" after the NODE name")
3507 if(!lexer_setCurID(me->lexer)) return FALSE;
3508 ASSERT(me->lexer->curID);
3509 nodeFieldName = STRDUP(me->lexer->curID);
3511 FREE_IF_NZ(me->lexer->curID);
3514 foundField = find_anyfield_by_nameAndRouteDir( *Node, &fieldPtr, &mode, &type,
3515 nodeFieldName, &source, &fdecl, &ifield, PKW_eventType);
3519 *Ofs = NODE_OFFSETS[(*Node)->_nodeType][ifield*5 + 1];
3522 *ScriptField = fdecl;
3526 if((*Node)->_nodeType==NODE_Script && !fdecl) {
3527 PARSE_ERROR(
"Event-field invalid for this PROTO/Script!")
3529 PARSE_ERROR(cerror1)
3531 FREE_IF_NZ(nodeFieldName);
3535 struct IMEXPORT *broto_search_IMPORTname(
struct X3D_Proto *context,
char *name);
3536 BOOL route_parse_nodefield_B(
struct VRMLParser* me,
char **ssnode,
char **ssfield)
3544 char *snode,*sfield;
3549 if(!lexer_setCurID(me->lexer))
3551 ASSERT(me->lexer->curID);
3552 snode = STRDUP(me->lexer->curID);
3553 FREE_IF_NZ(me->lexer->curID);
3557 if(!lexer_point(me->lexer)) {
3558 CPARSE_ERROR_CURID(
"ERROR:ROUTE: Expected \".\" after the NODE name")
3564 if(!lexer_setCurID(me->lexer))
3566 ASSERT(me->lexer->curID);
3567 sfield = STRDUP(me->lexer->curID);
3568 FREE_IF_NZ(me->lexer->curID);
3578 void QAandRegister_parsedRoute_B(struct X3D_Proto *context,
char* fnode,
char* ffield,
char* tnode,
char* tfield);
3582 static BOOL parser_routeStatement_B(struct
VRMLParser* me)
3584 char *sfnode, *sffield;
3585 char *stnode, *stfield;
3586 int foundfrom, foundto, gotTO;
3591 lexer_skip(me->lexer);
3594 if(!lexer_keyword(me->lexer, KW_ROUTE))
3602 foundfrom = route_parse_nodefield_B(me,&sfnode, &sffield);
3606 if(!lexer_keyword(me->lexer, KW_TO)) {
3608 char *buf = p->fw_outline;
3609 strcpy (buf,
"ERROR:ROUTE: Expected \"TO\" found \"");
3610 if (me->lexer->curID != NULL) strcat (buf, me->lexer->curID);
else strcat (buf,
"(EOF)");
3611 CPARSE_ERROR_CURID(buf);
3619 foundto = route_parse_nodefield_B(me,&stnode, &stfield);
3621 if(!(foundfrom && gotTO && foundto)){
3623 FREE_IF_NZ(sffield);
3625 FREE_IF_NZ(stfield);
3630 QAandRegister_parsedRoute_B(X3D_PROTO(me->ectx), sfnode, sffield, stnode, stfield);
3632 FREE_IF_NZ(sffield);
3634 FREE_IF_NZ(stfield);
3694 void broto_store_DEF(
struct X3D_Proto* proto,
struct X3D_Node* node,
const char *name)
3699 def.name = STRDUP(name);
3700 defs = proto->__DEFnames;
3704 proto->__DEFnames = defs;
3708 int broto_search_DEF_index_by_node(
struct X3D_Proto* proto,
struct X3D_Node *node){
3710 Stack *defs = proto->__DEFnames;
3714 for(i=0;i<vectorSize(defs);i++){
3716 if(def.node == node){
3725 void broto_clear_DEF_by_node(
struct X3D_Proto* proto,
struct X3D_Node* node)
3730 index = broto_search_DEF_index_by_node(proto,node);
3732 defs = proto->__DEFnames;
3734 FREE_IF_NZ(def.name);
3735 vector_removeElement(
sizeof(
struct brotoDefpair),defs,index);
3738 struct X3D_Node *broto_search_DEFname(
struct X3D_Proto *context,
const char *name){
3739 int i, istart, iend;
3744 if(context->__DEFnames){
3745 istart = vectorSize(context->__DEFnames) -1;
3747 for(i=istart;i>=iend; i--) {
3748 def = vector_get(
struct brotoDefpair, context->__DEFnames,i);
3749 if(!strcmp(def.name, name))
return def.node;
3754 struct IMEXPORT *broto_search_IMPORTname(
struct X3D_Proto *context,
char *name){
3757 if(context->__IMPORTS)
3758 for(i=0;i<vectorSize(context->__IMPORTS);i++){
3759 def = vector_get(
struct IMEXPORT *, context->__IMPORTS,i);
3760 if(!strcmp(def->as,name))
return def;
3764 struct IMEXPORT *broto_search_EXPORTname(
struct X3D_Proto *context,
char *name){
3767 if(context->__EXPORTS)
3768 for(i=0;i<vectorSize(context->__EXPORTS);i++){
3769 def = vector_get(
struct IMEXPORT *, context->__EXPORTS,i);
3770 if(!strcmp(def->as,name))
return def;
3776 BOOL isAvailableBroto(
char *pname,
struct X3D_Proto* currentContext,
struct X3D_Proto **proto)
3782 struct X3D_Proto *p;
3783 struct X3D_Proto* context;
3789 context = currentContext;
3795 BOOL bottomUp = TRUE;
3797 plist = (
struct Vector*) context->__protoDeclares;
3799 int n = vectorSize(plist);
3803 if(bottomUp) j = n - 1 - i;
3805 p = vector_get(
struct X3D_Proto*,plist,j);
3806 obj = p->__protoDef;
3807 if(!strcmp(obj->protoName,pname))
3814 plist = (
struct Vector*) context->__externProtoDeclares;
3816 int n = vectorSize(plist);
3820 if(bottomUp) j = n - 1 - i;
3822 p = vector_get(
struct X3D_Proto*,plist,j);
3823 obj = p->__protoDef;
3824 if(!strcmp(obj->protoName,pname))
3831 context = (
struct X3D_Proto*)context->__parentProto;
3833 printf(
"ouch no broto definition found\n");
3846 for(i=0;i<p2p->n;i++)
3849 if(pair.pp == source){
3857 void copy_routes2(
Stack *routes,
struct X3D_Proto* target,
struct Vector *p2p)
3862 struct X3D_Node *fromNode, *toNode;
3863 if(routes == NULL)
return;
3864 for(i=0;i<routes->n;i++)
3866 route = vector_get(
struct brotoRoute*, routes, i);
3869 fromNode = p2p_lookup(route->from.node,p2p);
3870 toNode = p2p_lookup(route->to.node,p2p);
3871 CRoutes_RegisterSimpleB(fromNode, route->from.ifield, toNode, route->to.ifield, route->ft);
3875 broto_store_route(target,fromNode,route->from.ifield, toNode, route->to.ifield, route->ft);
3882 void copy_defnames2(
Stack *defnames,
struct X3D_Proto* target,
struct Vector *p2p)
3893 if(target->__DEFnames == NULL)
3899 n = vectorSize(defnames);
3902 def2.name = STRDUP(def.name);
3903 def2.node = p2p_lookup(def.node, p2p);
3905 stack_push(
struct brotoDefpair, target->__DEFnames, def2);
3909 void copy_IS(
Stack *istable,
struct X3D_Proto* target,
struct Vector *p2p);
3910 void copy_IStable(
Stack **sourceIS,
Stack** destIS);
3912 Stack *instancedScripts,
struct X3D_Proto *ctx,
struct X3D_Node *parent);
3913 void initialize_scripts(
Stack *instancedScripts);
3914 void deep_copy_broto_body2(
struct X3D_Proto** proto,
struct X3D_Proto** dest)
3944 struct X3D_Proto *prototype, *p;
3946 Stack *instancedScripts;
3951 p->__children.n = 0;
3952 p->__children.p = NULL;
3953 parent = (
struct X3D_Node*) (*dest);
3954 prototype = (
struct X3D_Proto*)(*proto)->__prototype;
3956 p->__prototype = X3D_NODE(prototype);
3958 p->__protoFlags = ciflag_set(p->__protoFlags,1,2);
3965 copy_IStable((
Stack **) &(prototype->__IS), (
Stack **) &(p->__IS));
3967 instancedScripts = (*dest)->__scripts;
3968 if( instancedScripts == NULL)
3970 instancedScripts = newStack(
struct X3D_Node *);
3971 (*dest)->__scripts = instancedScripts;
3975 copy_field(FIELDTYPE_MFNode,(
union anyVrml*)&(prototype->__children),(
union anyVrml*)&(p->__children),
3976 p2p,instancedScripts,p,parent);
3978 copy_routes2(prototype->__ROUTES, p, p2p);
3980 copy_defnames2(prototype->__DEFnames, p, p2p);
3983 copy_IS(p->__IS, p, p2p);
3985 initialize_scripts(instancedScripts);
3991 struct X3D_Proto *brotoInstance(
struct X3D_Proto* proto, BOOL ideep)
4002 struct X3D_Proto *p;
4005 p = createNewX3DNode(NODE_Proto);
4007 p->__children.n = 0;
4008 p->__children.p = NULL;
4011 pflags = ciflag_set(pflags,1,0);
4013 pflags = ciflag_set(pflags,1,2);
4014 pflags = ciflag_set(pflags,0,3);
4015 if(ciflag_get(proto->__protoFlags,3)==1)
4016 pflags = ciflag_set(pflags,1,3);
4018 p->__protoFlags = pflags;
4021 p = createNewX3DNode0(NODE_Proto);
4023 p->__children.n = 0;
4024 p->__children.p = NULL;
4031 p->__protoFlags = 0;
4036 p->__prototype = proto->__prototype;
4037 p->_nodeType = proto->_nodeType;
4038 p->_defaultContainer = proto->_defaultContainer;
4039 p->_renderFlags = proto->_renderFlags;
4040 pobj = proto->__protoDef;
4044 nobj->iface = newVector(
struct ProtoFieldDecl *, pobj->iface->n);
4046 nobj->protoName = STRDUP(pobj->protoName);
4047 for(i=0;i<pobj->iface->n;i++)
4049 pdecl = protoDefinition_getFieldByNum(pobj, i);
4051 ndecl=newProtoFieldDecl(pdecl->mode, pdecl->type, pdecl->name);
4055 ndecl = copy_ProtoFieldDecl(pdecl);
4057 protoDefinition_addIfaceField(nobj, ndecl);
4059 p->__protoDef = nobj;
4069 for(i=0;i<p2p->n;i++)
4072 if(pnode == pair.pp)
return pair.pn;
4077 void copy_routes(
Stack *routes,
struct X3D_Proto* target,
struct Vector *p2p)
4081 struct X3D_Node *fromNode, *toNode;
4082 if(routes == NULL)
return;
4083 for(i=0;i<routes->n;i++)
4085 route = vector_get(
struct brotoRoute*, routes, i);
4088 fromNode = p2p_lookup(route->from.node,p2p);
4089 toNode = p2p_lookup(route->to.node,p2p);
4090 CRoutes_RegisterSimpleB(fromNode, route->from.ifield, toNode, route->to.ifield, route->ft);
4105 struct X3D_Proto *proto;
4106 char *protofieldname;
4111 char* nodefieldname;
4118 void copy_IS(
Stack *istable,
struct X3D_Proto* target,
struct Vector *p2p)
4123 if(istable == NULL)
return;
4124 for(i=0;i<istable->n;i++)
4126 int ifield, iprotofield;
4127 is = vector_get(
struct brotoIS*, istable, i);
4130 node = p2p_lookup(is->node,p2p);
4132 pnode = X3D_NODE(target);
4133 ifield = is->ifield;
4136 iprotofield = is->iprotofield;
4139 if(is->pmode == PKW_outputOnly){
4142 CRoutes_RegisterSimpleB(node, ifield, pnode, iprotofield, 0);
4144 }
else if(is->pmode == PKW_inputOnly){
4145 CRoutes_RegisterSimpleB(pnode, iprotofield, node, ifield, 0);
4146 }
else if(is->pmode == PKW_inputOutput){
4147 CRoutes_RegisterSimpleB(node, ifield, pnode, iprotofield, 0);
4148 CRoutes_RegisterSimpleB(pnode, iprotofield, node, ifield, 0);
4154 void unregister_IStableRoutes(
Stack* istable,
struct X3D_Proto* target){
4162 if(istable == NULL)
return;
4163 for(i=0;i<istable->n;i++)
4165 int ifield, iprotofield;
4166 is = vector_get(
struct brotoIS*, istable, i);
4171 pnode = X3D_NODE(target);
4172 ifield = is->ifield;
4175 iprotofield = is->iprotofield;
4178 if(is->pmode == PKW_outputOnly){
4181 CRoutes_RemoveSimpleB(node, ifield, pnode, iprotofield, 0);
4183 }
else if(is->pmode == PKW_inputOnly){
4184 CRoutes_RemoveSimpleB(pnode, iprotofield, node, ifield, 0);
4185 }
else if(is->pmode == PKW_inputOutput){
4186 CRoutes_RemoveSimpleB(node, ifield, pnode, iprotofield, 0);
4187 CRoutes_RemoveSimpleB(pnode, iprotofield, node, ifield, 0);
4194 void copy_IStable(
Stack **sourceIS,
Stack** destIS)
4199 *destIS = newStack(
struct brotoIS*);
4201 for(i=0;i<(*sourceIS)->n;i++)
4204 iss = vector_get(
struct brotoIS*,*sourceIS,i);
4205 memcpy(isd,iss,
sizeof(
struct brotoIS));
4207 stack_push(
struct brotoIS*, *destIS, isd);
4216 for(i=0;i<IStable->n;i++)
4219 if(target == record->node){
4220 if(ifield == record->ifield && source == record->source){
4232 void copy_defnames(
Stack *defnames,
struct X3D_Proto* target,
struct Vector *p2p)
4237 defs = globalParser->brotoDEFedNodes;
4241 globalParser->brotoDEFedNodes = defs;
4247 n = vectorSize(defnames);
4251 def2->name = def->name;
4252 def2->node = p2p_lookup(def->node, p2p);
4257 char *broto_getNameFromNode(
struct X3D_Node* node)
4264 defs = globalParser->brotoDEFedNodes;
4268 n = vectorSize(defs);
4271 if(def->node == node){
4281 Stack *instancedScripts,
struct X3D_Proto *ctx);
4285 Stack *instancedScripts,
struct X3D_Proto *ctx,
struct X3D_Node *parent)
4291 isMF = typeIndex % 2;
4292 sftype = typeIndex - isMF;
4295 isize = sizeofSForMF(sftype);
4302 deleteMallocedFieldValue(typeIndex,dest);
4305 if( sftype == FIELDTYPE_SFNode ) nele = (int) upper_power_of_two(nele);
4309 mfd->p = MALLOC (
struct X3D_Node **, isize*nele);
4310 bzero(mfd->p,isize*nele);
4312 ps = (
char *)mfs->p;
4313 pd = (
char *)mfd->p;
4314 for(i=0;i<mfs->n;i++)
4316 copy_field(sftype,(
union anyVrml*)ps,(
union anyVrml*)pd,p2p,instancedScripts,ctx,parent);
4326 case FIELDTYPE_SFNode:
4329 deep_copy_node(&source->sfnode,&dest->sfnode,p2p,instancedScripts,ctx);
4330 add_parent(dest->sfnode,parent,__FILE__,__LINE__);
4332 dest->sfnode = NULL;
4336 case FIELDTYPE_SFString:
4339 deleteMallocedFieldValue(typeIndex,dest);
4343 sd->strptr = STRDUP((*ss)->strptr);
4344 dest->sfstring = sd;
4349 memcpy(dest,source,isize);
4356 void deep_copy_broto_body(
struct X3D_Proto** proto,
struct X3D_Proto** dest,
Stack *instancedScripts)
4385 struct X3D_Proto *prototype, *p;
4391 p->__children.n = 0;
4392 p->__children.p = NULL;
4393 parent = (
struct X3D_Node*) (*dest);
4394 prototype = (
struct X3D_Proto*)(*proto)->__prototype;
4400 copy_IStable((
Stack **) &(prototype->__IS), (
Stack **) &(p->__IS));
4403 copy_field(FIELDTYPE_MFNode,(
union anyVrml*)&(prototype->__children),(
union anyVrml*)&(p->__children),
4404 p2p,instancedScripts,p,parent);
4406 copy_routes(prototype->__ROUTES, p, p2p);
4408 copy_defnames(prototype->__DEFnames, p, p2p);
4411 copy_IS(p->__IS, p, p2p);
4422 void shallow_copy_field(
int typeIndex,
union anyVrml* source,
union anyVrml* dest)
4428 isMF = typeIndex % 2;
4429 sftype = typeIndex - isMF;
4432 isize = sizeofSForMF(sftype);
4440 deleteMallocedFieldValue(typeIndex,dest);
4442 if( sftype == FIELDTYPE_SFNode ) nele = (int) upper_power_of_two(nele);
4447 mfd->p = MALLOC (
struct X3D_Node **, isize*nele);
4448 bzero(mfd->p,isize*nele);
4450 ps = (
char *)mfs->p;
4451 pd = (
char *)mfd->p;
4452 for(i=0;i<mfs->n;i++)
4454 shallow_copy_field(sftype,(
union anyVrml*)ps,(
union anyVrml*)pd);
4463 case FIELDTYPE_SFString:
4467 deleteMallocedFieldValue(typeIndex,dest);
4472 sd->strptr = STRDUP((*ss)->strptr);
4473 dest->sfstring = sd;
4479 memcpy(dest,source,isize);
4485 int PKW_from_KW(
int KW_index)
4492 case KW_initializeOnly:
4493 pkw = PKW_initializeOnly;
break;
4495 pkw = PKW_inputOnly;
break;
4497 pkw = PKW_outputOnly;
break;
4498 case KW_inputOutput:
4499 pkw = PKW_inputOutput;
break;
4501 pkw = PKW_field;
break;
4503 pkw = PKW_eventIn;
break;
4505 pkw = PKW_eventOut;
break;
4506 case KW_exposedField:
4507 pkw = PKW_exposedField;
break;
4513 BOOL isManagedField(
int mode,
int type, BOOL isPublic);
4514 void registerParentIfManagedField(
int type,
int mode, BOOL isPublic,
union anyVrml* any,
struct X3D_Node* parent)
4523 if(isManagedField(mode,type,isPublic))
4525 int n,k,haveSomething;
4527 haveSomething = (type==FIELDTYPE_SFNode && any->sfnode) || (type==FIELDTYPE_MFNode && any->mfnode.n);
4528 haveSomething = haveSomething && parent;
4530 if(type==FIELDTYPE_SFNode){
4531 plist = &any->sfnode;
4534 plist = any->mfnode.p;
4541 if( !sfn->_parentVector)
4542 sfn->_parentVector = newVector(
struct X3D_Node*,2);
4543 vector_pushBack(
struct X3D_Node*, sfn->_parentVector, parent);
4549 void freeMallocedNodeFields(
struct X3D_Node* node);
4551 void freePublicBuiltinNodeFields(
struct X3D_Node* node);
4552 void **shaderFields(
struct X3D_Node* node);
4554 struct X3D_Proto* ctx)
4558 void **shaderfield = NULL;
4559 if(*source == NULL){
4563 *dest = inPointerTable(*source,p2p);
4570 if((*source)->_nodeType == NODE_Proto){
4571 *dest = X3D_NODE(brotoInstance(X3D_PROTO(X3D_PROTO(*source)->__prototype),ciflag_get(ctx->__protoFlags,0)));
4573 *dest=X3D_NODE(createNewX3DNode( (*source)->_nodeType));
4575 add_node_to_broto_context(ctx,(*dest));
4578 if((*source)->_nodeType == NODE_Script)
4579 stack_push(
struct X3D_Node*,instancedScripts,*dest);
4585 shaderfield = shaderFields(*source);
4588 typedef struct field_info{
4599 offsets = (finfo)NODE_OFFSETS[(*source)->_nodeType];
4601 field = &offsets[ifield];
4603 while( field->nameIndex > -1)
4611 isrecord = in_IStable(*source,ifield,(
Stack *)ctx->__IS, is_source);
4612 if (isrecord != NULL)
4617 union anyVrml *source_field, *dest_field;
4620 sp = ctx->__protoDef;
4621 sdecl = protoDefinition_getFieldByNum(sp, isrecord->iprotofield);
4624 source_field = (
union anyVrml*)&(sdecl->defaultVal);
4625 dest_field = (
union anyVrml*)&((
char*)*dest )[field->offset];
4627 shallow_copy_field(field->typeIndex, source_field, dest_field);
4628 registerParentIfManagedField(field->typeIndex,PKW_from_KW(field->ioType),1, dest_field, *dest);
4639 else if((*source)->_nodeType == NODE_Proto && !strcmp(FIELDNAMES[field->nameIndex],
"__protoDef") )
4645 struct X3D_Proto *s, *d;
4647 s = (
struct X3D_Proto*)*source;
4648 d = (
struct X3D_Proto*)*dest;
4655 dp = newProtoDefinition();
4664 for(k=0;k<sp->iface->n;k++)
4666 sdecl = protoDefinition_getFieldByNum(sp, k);
4667 ddecl = protoDefinition_getFieldByNum(dp, k);
4674 isrecord = in_IStable(*source,k,(
Stack *)ctx->__IS, is_source);
4675 if (isrecord != NULL)
4680 union anyVrml *source_field, *dest_field;
4683 sp = ctx->__protoDef;
4684 sdecl = protoDefinition_getFieldByNum(sp, isrecord->iprotofield);
4687 source_field = (
union anyVrml*)&(sdecl->defaultVal);
4688 dest_field = (
union anyVrml*)&(ddecl->defaultVal);
4694 shallow_copy_field(sdecl->type, source_field, dest_field);
4695 registerParentIfManagedField(sdecl->type,sdecl->mode,1, dest_field, *dest);
4696 ddecl->alreadySet = sdecl->alreadySet;
4702 if(sdecl->mode == PKW_initializeOnly || sdecl->mode == PKW_inputOutput){
4704 union anyVrml *source_field, *dest_field;
4705 source_field = (
union anyVrml*)&(sdecl->defaultVal);
4706 dest_field = (
union anyVrml*)&(ddecl->defaultVal);
4707 copy_field(sdecl->type,source_field,dest_field,p2p,instancedScripts,ctx,parent);
4708 ddecl->alreadySet = sdecl->alreadySet;
4716 else if((*source)->_nodeType == NODE_Script && !strcmp(FIELDNAMES[field->nameIndex],
"__scriptObj") )
4727 sp = s->__scriptObj;
4728 dp = d->__scriptObj = new_Shader_ScriptB(*dest);
4729 dp->loaded = sp->loaded;
4731 sfields = sp->fields;
4732 for(k=0;k<sfields->n;k++)
4738 bzero(dfield->fieldDecl,
sizeof(
struct FieldDecl));
4742 isrecord = in_IStable(*source,k,(
Stack *)ctx->__IS, is_source);
4743 isInitialize = isrecord && (isrecord->mode == PKW_initializeOnly || isrecord->mode == PKW_inputOutput);
4749 union anyVrml *source_field, *dest_field;
4753 sp = ctx->__protoDef;
4754 sdecl = protoDefinition_getFieldByNum(sp, isrecord->iprotofield);
4755 if(sdecl->fieldString)
4756 dfield->ASCIIvalue = STRDUP(sdecl->fieldString);
4757 memcpy(dfield->fieldDecl,sfield->fieldDecl,
sizeof(
struct FieldDecl));
4765 source_field = (
union anyVrml*)&(sdecl->defaultVal);
4766 dest_field = (
union anyVrml*)&(dfield->value);
4768 shallow_copy_field(sdecl->type, source_field, dest_field);
4769 registerParentIfManagedField(sdecl->type, sdecl->mode, 1, dest_field, *dest);
4772 if(sfield->ASCIIvalue)
4773 dfield->ASCIIvalue = STRDUP(sfield->ASCIIvalue);
4775 memcpy(dfield->fieldDecl,sfield->fieldDecl,
sizeof(
struct FieldDecl));
4778 dfield->value = sfield->value;
4782 if(sfield->fieldDecl->PKWmode == PKW_initializeOnly || sfield->fieldDecl->PKWmode == PKW_inputOutput){
4783 union anyVrml *source_field, *dest_field;
4784 source_field = (
union anyVrml*)&(sfield->value);
4785 dest_field = (
union anyVrml*)&(dfield->value);
4786 copy_field(dfield->fieldDecl->fieldType,source_field,dest_field,p2p,instancedScripts,ctx,parent);
4788 dfield->valueSet = sfield->valueSet;
4793 else if(shaderfield && !strcmp(FIELDNAMES[field->nameIndex],
"_shaderUserDefinedFields") )
4810 void **dshaderfield;
4815 dshaderfield = shaderFields(*dest);
4817 dp = new_Shader_ScriptB(*dest);
4818 (*dshaderfield) = (
void*) dp;
4819 dp->loaded = sp->loaded;
4821 sfields = sp->fields;
4822 for(k=0;k<sfields->n;k++)
4828 bzero(dfield->fieldDecl,
sizeof(
struct FieldDecl));
4832 isrecord = in_IStable(*source,k,(
Stack *)ctx->__IS, is_source);
4833 isInitialize = isrecord && (isrecord->mode == PKW_initializeOnly || isrecord->mode == PKW_inputOutput);
4839 union anyVrml *source_field, *dest_field;
4843 sp = ctx->__protoDef;
4844 sdecl = protoDefinition_getFieldByNum(sp, isrecord->iprotofield);
4845 if(sdecl->fieldString)
4846 dfield->ASCIIvalue = STRDUP(sdecl->fieldString);
4847 memcpy(dfield->fieldDecl,sfield->fieldDecl,
sizeof(
struct FieldDecl));
4855 source_field = (
union anyVrml*)&(sdecl->defaultVal);
4856 dest_field = (
union anyVrml*)&(dfield->value);
4858 shallow_copy_field(sdecl->type, source_field, dest_field);
4859 registerParentIfManagedField(sdecl->type, sdecl->mode, 1, dest_field, *dest);
4862 if(sfield->ASCIIvalue)
4863 dfield->ASCIIvalue = STRDUP(sfield->ASCIIvalue);
4865 memcpy(dfield->fieldDecl,sfield->fieldDecl,
sizeof(
struct FieldDecl));
4868 dfield->value = sfield->value;
4872 if(sfield->fieldDecl->PKWmode == PKW_initializeOnly || sfield->fieldDecl->PKWmode == PKW_inputOutput){
4873 union anyVrml *source_field, *dest_field;
4874 source_field = (
union anyVrml*)&(sfield->value);
4875 dest_field = (
union anyVrml*)&(dfield->value);
4876 copy_field(dfield->fieldDecl->fieldType,source_field,dest_field,p2p,instancedScripts,ctx,parent);
4878 dfield->valueSet = sfield->valueSet;
4885 if( FIELDNAMES[field->nameIndex][0] !=
'_'){
4886 union anyVrml *source_field, *dest_field;
4887 source_field = (
union anyVrml*)&((
char*)*source)[field->offset];
4888 dest_field = (
union anyVrml*)&((
char*)*dest )[field->offset];
4896 copy_field(field->typeIndex,source_field,dest_field,p2p,instancedScripts,ctx,parent);
4900 field = &offsets[ifield];
4903 if((*source)->_nodeType == NODE_Proto)
4908 struct X3D_Proto *pdest;
4909 unsigned char pdepthflag;
4910 pdest = X3D_PROTO(*dest);
4913 pdepthflag = ciflag_get(ctx->__protoFlags,0);
4914 pdest->__protoFlags = ciflag_set(pdest->__protoFlags,pdepthflag,0);
4916 deep_copy_broto_body2((
struct X3D_Proto**)source,(
struct X3D_Proto**)dest);
4919 int nextScriptHandle (
void);
4926 ss->num = nextScriptHandle();
4930 for(j=0;j<ss->fields->n;j++)
4945 script_initCodeFromMFUri(ss, url);
4948 void initialize_scripts(
Stack *instancedScripts)
4977 if(instancedScripts)
4986 n = instancedScripts->n;
4989 p = vector_get(
struct X3D_Node*,instancedScripts,i);
4992 ss = sn->__scriptObj;
4994 initialize_one_script(ss,&sn->url);
4999 ss->num = nextScriptHandle();
5003 for(j=0;j<ss->fields->n;j++)
5009 scriptFieldDecl_jsFieldInit(field, ss->num);
5017 script_initCodeFromMFUri(ss, &sn->url);
5023 void sceneInstance(
struct X3D_Proto* sceneProto,
struct X3D_Node *sceneInstance)
5052 struct X3D_Proto *scenePlaceholderProto;
5057 children = childrenField(sceneInstance);
5060 parent = (
struct X3D_Node*)sceneInstance;
5061 scenePlaceholderProto = createNewX3DNode0(NODE_Proto);
5069 copy_field(FIELDTYPE_MFNode,(
union anyVrml*)&(sceneProto->__children),(
union anyVrml*)children,
5070 p2p,instancedScripts,scenePlaceholderProto,parent);
5073 copy_routes(sceneProto->__ROUTES, NULL, p2p);
5075 copy_IS(sceneProto->__IS, NULL, p2p);
5077 copy_defnames(sceneProto->__DEFnames, NULL, p2p);
5079 initialize_scripts(instancedScripts);
5127 BOOL nodeTypeSupportsUserFields(
struct X3D_Node *node)
5130 user = node->_nodeType == NODE_Proto || node->_nodeType == NODE_Script ||
5131 node->_nodeType == NODE_ComposedShader || node->_nodeType == NODE_ShaderProgram ||
5132 node->_nodeType == NODE_PackagedShader || node->_nodeType == NODE_Effect ? TRUE : FALSE;
5137 const char *rootFieldName(
const char* fieldname,
int* len,
int *has_changed,
int *has_set)
5144 static char* str_changed =
"_changed";
5146 static int len_changed = 8;
5147 static int len_set = 4;
5152 ln = (int) strlen(fieldname);
5154 *has_changed = ln > len_changed ? !strncmp(&fieldname[ln-len_changed],str_changed,len_changed) : FALSE;
5155 *has_set = ln > len_set ? !strncmp(fieldname,
"set_",len_set) : FALSE;
5156 s = *has_set ? &fieldname[len_set] : fieldname;
5157 *len = *has_changed? (int)(&fieldname[ln - len_changed] - s) : (int)(&fieldname[ln] - s);
5160 BOOL fieldSynonymCompare(
const char *routeFieldName,
const char* nodeFieldName)
5165 int lr,hsr,hcr,ln,hsn,hcn;
5166 const char *rf, *nf;
5168 if(!strcmp(routeFieldName,nodeFieldName) )
return FALSE;
5171 rf = rootFieldName(routeFieldName,&lr,&hsr,&hcr);
5172 nf = rootFieldName(nodeFieldName, &ln,&hsn,&hcn);
5174 if(lr != ln)
return TRUE;
5175 if(strncmp(rf,nf,lr))
return TRUE;
5193 int X3DMODE(
int val)
5198 case PKW_initializeOnly:
5199 iret = PKW_initializeOnly;
break;
5200 case PKW_exposedField:
5201 case PKW_inputOutput:
5202 iret = PKW_inputOutput;
break;
5205 iret = PKW_inputOnly;
break;
5207 case PKW_outputOnly:
5208 iret = PKW_outputOnly;
break;
5210 printf(
"ouch from X3DMODE\n");
5216 BOOL walk_fields(
struct X3D_Node* node,
int (*callbackFunc)(),
void* callbackData);
5218 BOOL walk_fields(
struct X3D_Node* node, BOOL (*callbackFunc)(
void *callbackData,
struct X3D_Node* node,
int jfield,
union anyVrml *fieldPtr,
5219 const char *fieldName, indexT mode, indexT type,
int isource,BOOL publicfield),
void* callbackData);
5231 BOOL cbExactName(
void *callbackData,
struct X3D_Node* node,
int jfield,
union anyVrml *fieldPtr,
char *fieldName,
int mode,
int type,
int source,BOOL publicfield)
5235 found = !strcmp(fieldName,cbd->fname);
5237 cbd->fieldValue = fieldPtr;
5238 cbd->fname = fieldName;
5239 cbd->jfield = jfield;
5242 cbd->publicfield = publicfield;
5243 cbd->source = source;
5248 int *imode,
int *itype,
char* nodeFieldName,
int *isource,
void** fdecl,
int *ifield)
5252 cbd.fname = nodeFieldName;
5253 found = walk_fields(node,cbExactName,&cbd);
5255 *anyptr = cbd.fieldValue;
5258 *isource = cbd.source;
5259 *ifield = cbd.jfield;
5275 BOOL cbRootNameAndRouteDir(
void *callbackData,
struct X3D_Node* node,
int jfield,
union anyVrml *fieldPtr,
char *fieldName,
int mode,
int type,
int source,BOOL publicfield)
5280 found = !fieldSynonymCompare(fieldName,cbd->fname) ? TRUE : FALSE;
5281 found = found && (mode == cbd->PKW_eventType || mode == PKW_inputOutput);
5283 cbd->fname = fieldName;
5284 cbd->jfield = jfield;
5287 cbd->publicfield = publicfield;
5288 cbd->source = source;
5292 BOOL find_anyfield_by_nameAndRouteDir(
struct X3D_Node* node,
union anyVrml **anyptr,
5293 int *imode,
int *itype,
char* nodeFieldName,
int *isource,
void** fdecl,
int *ifield,
int PKW_eventType)
5297 cbd.fname = nodeFieldName;
5298 cbd.PKW_eventType = PKW_eventType;
5299 found = walk_fields(node,cbRootNameAndRouteDir,&cbd);
5301 *anyptr = cbd.fieldValue;
5304 *isource = cbd.source;
5305 *ifield = cbd.jfield;
5311 BOOL cbCountFields(
void *callbackData,
struct X3D_Node* node,
int jfield,
union anyVrml *fieldPtr,
char *fieldName,
int mode,
int type,
int source,BOOL publicfield)
5314 int *count = (
int*)callbackData;
5318 int count_fields(
struct X3D_Node* node)
5323 walk_fields(node,cbCountFields,&count);
5327 void **shaderFields(
struct X3D_Node* node);
5329 int getFieldFromNodeAndName0(
struct X3D_Node* node,
const char *fieldname,
int *type,
int *kind,
int *iifield,
union anyVrml **value){
5335 shaderfield = shaderFields(node);
5337 if(node->_nodeType == NODE_Script)
5349 sfields = sp->fields;
5350 for(k=0;k<sfields->n;k++)
5355 fdecl = sfield->fieldDecl;
5356 fieldName = fieldDecl_getShaderScriptName(fdecl);
5357 if(!strcmp(fieldName,fieldname)){
5358 *type = fdecl->fieldType;
5359 *kind = fdecl->PKWmode;
5360 *value = &(sfield->value);
5366 else if(shaderfield)
5376 sfields = sp->fields;
5377 for(k=0;k<sfields->n;k++)
5382 fdecl = sfield->fieldDecl;
5383 fieldName = fieldDecl_getShaderScriptName(fdecl);
5384 if(!strcmp(fieldName,fieldname)){
5385 *type = fdecl->fieldType;
5386 *kind = fdecl->PKWmode;
5387 *value = &(sfield->value);
5392 }
else if(node->_nodeType == NODE_Proto) {
5395 struct X3D_Proto* pnode = (
struct X3D_Proto*)node;
5399 for(k=0; k!=vectorSize(pstruct->iface); ++k)
5401 const char *fieldName;
5404 fieldName = pfield->cname;
5405 if(!strcmp(fieldName,fieldname)){
5406 *type = pfield->type;
5407 *kind = pfield->mode;
5408 if(pfield->mode == PKW_initializeOnly || pfield->mode == PKW_inputOutput)
5409 *value = &(pfield->defaultVal);
5418 typedef struct field_info{
5429 offsets = (finfo)NODE_OFFSETS[node->_nodeType];
5431 field = &offsets[ifield];
5432 while( field->nameIndex > -1)
5434 if(!strcmp(FIELDNAMES[field->nameIndex],fieldname)){
5436 *type = field->typeIndex;
5438 switch(field->ioType){
5439 case KW_initializeOnly: kkind = PKW_initializeOnly;
break;
5440 case KW_inputOnly: kkind = PKW_inputOnly;
break;
5441 case KW_outputOnly: kkind = PKW_outputOnly;
break;
5442 case KW_inputOutput: kkind = PKW_inputOutput;
break;
5446 *value = (
union anyVrml*)&((
char*)node)[field->offset];
5450 field = &offsets[ifield];
5455 int getFieldFromNodeAndName(
struct X3D_Node* node,
const char *fieldname,
int *type,
int *kind,
int *iifield,
union anyVrml **value){
5457 ifound = getFieldFromNodeAndName0(node,fieldname,type,kind,iifield,value);
5461 nf = rootFieldName(fieldname, &ln,&hcn,&hsn);
5465 ifound = getFieldFromNodeAndName0(node,nf,type,kind,iifield,value);
5470 char rootname[MAXJSVARIABLELENGTH];
5471 strncpy(rootname,fieldname,ln);
5472 rootname[ln] =
'\0';
5473 ifound = getFieldFromNodeAndName0(node,rootname,type,kind,iifield,value);
5478 int getFieldFromNodeAndIndex(
struct X3D_Node* node,
int ifield,
const char **fieldname,
int *type,
int *kind,
union anyVrml **value){
5484 if(node->_nodeType == NODE_Script )
5498 sfields = sp->fields;
5501 if(k > -1 && k < sfields->n)
5505 fdecl = sfield->fieldDecl;
5506 *fieldname = fieldDecl_getShaderScriptName(fdecl);
5507 *type = fdecl->fieldType;
5508 *kind = fdecl->PKWmode;
5509 *value = &(sfield->value);
5513 }
else if(node->_nodeType == NODE_Proto ) {
5516 struct X3D_Proto* pnode = (
struct X3D_Proto*)node;
5521 if(k > -1 && k < vectorSize(pstruct->iface))
5525 *fieldname = pfield->cname;
5526 *type = pfield->type;
5527 *kind = pfield->mode;
5528 if(pfield->mode == PKW_initializeOnly || pfield->mode == PKW_inputOutput)
5529 *value = &(pfield->defaultVal);
5538 typedef struct field_info{
5551 offsets = (finfo)NODE_OFFSETS[node->_nodeType];
5554 if(kfield >= offsets[0].offset){
5556 while(offsets[k].nameIndex > -1){
5557 if(ifield == offsets[k].offset){
5564 for(k=0;k<=kfield;k++)
5565 if(offsets[k].nameIndex == -1)
return 0;
5566 *fieldname = FIELDNAMES[offsets[kfield].nameIndex];
5567 *type = offsets[kfield].typeIndex;
5569 switch(offsets[kfield].ioType){
5570 case KW_initializeOnly: kkind = PKW_initializeOnly;
break;
5571 case KW_inputOnly: kkind = PKW_inputOnly;
break;
5572 case KW_outputOnly: kkind = PKW_outputOnly;
break;
5573 case KW_inputOutput: kkind = PKW_inputOutput;
break;
5576 *value = (
union anyVrml*)&((
char*)node)[offsets[kfield].offset];
5583 void broto_store_IS(
struct X3D_Proto *proto,
char *protofieldname,
int pmode,
int iprotofield,
int type,
5584 struct X3D_Node *node,
char* nodefieldname,
int mode,
int ifield,
int source)
5591 is->protofieldname = strdup(protofieldname);
5593 is->iprotofield = iprotofield;
5596 is->nodefieldname = strdup(nodefieldname);
5598 is->ifield = ifield;
5599 is->source = source;
5603 ISs = newStack(
struct brotoIS *);
5606 stack_push(
struct brotoIS *, ISs, is);
5621 int ifield, iprotofield;
5623 struct X3D_Proto* proto;
5624 char *protoFieldName;
5625 char *nodeFieldName;
5628 BOOL foundProtoField;
5638 if(!lexer_setCurID(me->lexer))
return FALSE;
5639 ASSERT(me->lexer->curID);
5640 nodeFieldName = STRDUP(me->lexer->curID);
5642 FREE_IF_NZ(me->lexer->curID);
5657 foundField = find_anyfield_by_name(me->lexer, node, &fieldPtr, &mode, &type, nodeFieldName, &source, &fdecl, &ifield);
5662 FREE_IF_NZ(nodeFieldName);
5668 if(!lexer_keyword(me->lexer, KW_IS)) {
5670 FREE_IF_NZ(nodeFieldName);
5677 if(!lexer_setCurID(me->lexer))
return FALSE;
5678 ASSERT(me->lexer->curID);
5679 protoFieldName = STRDUP(me->lexer->curID);
5680 FREE_IF_NZ(me->lexer->curID);
5693 proto = (
struct X3D_Proto*)me->ectx;
5695 foundProtoField = FALSE;
5698 const char* pname = NULL;
5700 for(i=0; i!=vectorSize(pdef->iface); ++i)
5705 foundProtoField = !strcmp(pname,protoFieldName) ? TRUE : FALSE;
5706 if(foundProtoField ) {
5713 if( !foundProtoField ){
5714 ConsoleMessage(
"Parser error: no matching protoField for %s IS %s\n",
5715 nodeFieldName,protoFieldName);
5716 FREE_IF_NZ(me->lexer->curID);
5718 FREE_IF_NZ(nodeFieldName);
5719 FREE_IF_NZ(protoFieldName);
5723 if(f->type != type){
5724 if(!pname) pname =
"";
5725 ConsoleMessage(
"Parser error: IS - we have a name match: %s IS %s found protofield %s\n",
5726 nodeFieldName,protoFieldName,pname);
5727 ConsoleMessage(
"...But the types don't match: nodefield %s protofield %s\n",
5728 FIELDTYPES[type],FIELDTYPES[f->type]);
5729 FREE_IF_NZ(me->lexer->curID);
5731 FREE_IF_NZ(nodeFieldName);
5732 FREE_IF_NZ(protoFieldName);
5747 if(X3DMODE(mode) != PKW_inputOutput && X3DMODE(mode) != X3DMODE(f->mode)){
5748 if(X3DMODE(f->mode) != PKW_inputOutput){
5749 ConsoleMessage(
"Parser Error: IS - we have a name match: %s IS %s found protofield %s\n",
5750 nodeFieldName,protoFieldName,f->fieldString);
5751 ConsoleMessage(
"...But the modes don't jive: nodefield %s protofield %s\n",
5752 PROTOKEYWORDS[mode],PROTOKEYWORDS[f->mode]);
5753 FREE_IF_NZ(me->lexer->curID);
5755 FREE_IF_NZ(nodeFieldName);
5756 FREE_IF_NZ(protoFieldName);
5759 ConsoleMessage(
"Parser Warning: IS - we have a name match: %s IS %s found protofield %s\n",
5760 nodeFieldName,protoFieldName,f->fieldString);
5761 ConsoleMessage(
"...But the modes don't jive: nodefield %s protofield %s\n",
5762 PROTOKEYWORDS[mode],PROTOKEYWORDS[f->mode]);
5763 ConsoleMessage(
"...will thunk\n");
5770 if(X3DMODE(f->mode) == PKW_initializeOnly || X3DMODE(f->mode) == PKW_inputOutput)
5781 shallow_copy_field(type, &(f->defaultVal) , fieldPtr);
5794 broto_store_IS(proto,protoFieldName,X3DMODE(f->mode),iprotofield,type,
5795 node,nodeFieldName,X3DMODE(mode),ifield,source);
5804 FREE_IF_NZ(nodeFieldName);
5805 FREE_IF_NZ(protoFieldName);
5823 ulr = librarySearch(res->URLrequest);
5824 if(ulr)
return ulr->three;
5830 #define LOAD_INITIAL_STATE 0
5831 #define LOAD_REQUEST_RESOURCE 1
5832 #define LOAD_FETCHING_RESOURCE 2
5834 #define LOAD_STABLE 10
5863 void load_externProtoDeclare (
struct X3D_Proto *node) {
5868 char flagInstance, flagExtern;
5869 flagInstance = ciflag_get(node->__protoFlags,2);
5870 flagExtern = ciflag_get(node->__protoFlags,3);
5871 if(flagInstance == 0 && flagExtern == 1) {
5874 switch (node->__loadstatus) {
5875 case LOAD_INITIAL_STATE:
5877 if (node->url.n == 0) {
5878 node->__loadstatus = LOAD_STABLE;
5881 res = resource_create_multi(&(node->url));
5882 res->media_type = resm_unknown;
5883 node->__loadstatus = LOAD_REQUEST_RESOURCE;
5884 node->__loadResource = res;
5888 case LOAD_REQUEST_RESOURCE:
5889 res = node->__loadResource;
5890 resource_identify(node->_parentResource, res);
5891 node->__afterPound = (
void*)res->afterPoundCharacters;
5894 if(node->__afterPound)
5895 res2 = resLibraryAlreadyRequested(res);
5897 node->__loadResource = res2;
5899 struct X3D_Proto *libraryScene;
5902 res->actions = resa_download | resa_load;
5903 libraryScene = createNewX3DNode0(NODE_Proto);
5904 res->ectx = (
void*)libraryScene;
5905 res->whereToPlaceData = X3D_NODE(libraryScene);
5906 res->offsetFromWhereToPlaceData = offsetof (
struct X3D_Proto, __children);
5907 addLibrary(res->URLrequest,libraryScene,res);
5908 resitem_enqueue(ml_new(res));
5910 node->__loadstatus = LOAD_FETCHING_RESOURCE;
5913 case LOAD_FETCHING_RESOURCE:
5914 res = node->__loadResource;
5918 if (res->status == ress_loaded) {
5919 res->actions = resa_process;
5920 res->complete = FALSE;
5921 resitem_enqueue(ml_new(res));
5922 }
else if ((res->status == ress_failed) || (res->status == ress_invalid)) {
5924 printf (
"resource failed to load\n");
5925 node->__loadstatus = LOAD_STABLE;
5926 }
else if (res->status == ress_parsed) {
5929 struct X3D_Proto *libraryScene = res->whereToPlaceData;
5930 if(node->__externProtoDeclares == NULL)
5931 node->__externProtoDeclares = newVector(
struct X3D_Proto*,1);
5932 vector_pushBack(
struct X3D_Proto*,node->__externProtoDeclares,libraryScene);
5934 if(node->__externProtoDeclares){
5935 int n = vectorSize(node->__externProtoDeclares);
5937 struct X3D_Proto *libraryScene = vector_get(
struct X3D_Proto*,node->__externProtoDeclares,0);
5938 if(libraryScene->__protoDeclares){
5939 int m = vectorSize(libraryScene->__protoDeclares);
5942 struct X3D_Proto* pDefinition;
5946 if(node->__afterPound){
5948 char *
typename, *matchstring;
5950 matchstring = node->__afterPound;
5951 pDefinition = vector_get(
struct X3D_Proto*,libraryScene->__protoDeclares,k);
5952 typename = (
char *)pDefinition->__typename;
5954 if(!strcmp(matchstring,
typename)){
5957 node->__protoDeclares = newVector(
struct X3D_Proto*,1);
5958 vector_pushBack(
struct X3D_Proto*,node->__protoDeclares,pDefinition);
5964 pDefinition = vector_get(
struct X3D_Proto*,libraryScene->__protoDeclares,0);
5965 node->__protoDeclares = newVector(
struct X3D_Proto*,1);
5966 vector_pushBack(
struct X3D_Proto*,node->__protoDeclares,pDefinition);
5972 node->__loadstatus = LOAD_STABLE;
5984 void load_externProtoInstance (
struct X3D_Proto *node) {
5989 char flagInstance, flagExtern;
5990 flagInstance = ciflag_get(node->__protoFlags,2);
5991 flagExtern = ciflag_get(node->__protoFlags,3);
5992 if(flagInstance == 1 && flagExtern == 1) {
5993 struct X3D_Proto *pnode = NULL;
5994 if(node->__children.n)
return;
5995 pnode = (
struct X3D_Proto*)node->__prototype;
5997 if(pnode->__loadstatus != LOAD_STABLE){
5999 load_externProtoDeclare(pnode);
6001 if(pnode->__loadstatus == LOAD_STABLE){
6003 if(pnode->__protoDeclares){
6004 int n = vectorSize(pnode->__protoDeclares);
6006 struct X3D_Proto *pdeclare, *pinstance;
6008 pdeclare = vector_get(
struct X3D_Proto*,pnode->__protoDeclares,0);
6009 pinstance = brotoInstance(pdeclare,1);
6010 if (pinstance != NULL) {
6015 ed = node->__protoDef;
6017 pd = pinstance->__protoDef;
6019 add_node_to_broto_context(node,X3D_NODE(pinstance));
6024 char *ename, *pname;
6029 for(i=0;i<ei->n;i++){
6030 ef = protoDefinition_getFieldByNum(ed, i);
6032 for(j=0;j<pi->n;j++){
6033 pf = protoDefinition_getFieldByNum(pd, j);
6035 if(!strcmp(ename,pname)){
6038 if(ef->type == pf->type){
6042 broto_store_IS(node,ef->cname,ef->mode, i, ef->type, X3D_NODE(pinstance), pf->cname, pf->mode, j, 3);
6051 p2pentry.pp = X3D_NODE(pinstance);
6052 p2pentry.pn = X3D_NODE(pinstance);
6054 copy_IS(node->__IS, node, p2p);
6063 for(i=0;i<istable->n;i++)
6067 is = vector_get(
struct brotoIS*, istable, i);
6068 if(is->pmode == PKW_inputOutput || is->pmode == PKW_initializeOnly){
6069 if(is->mode == PKW_inputOutput || is->mode == PKW_initializeOnly){
6070 ef = protoDefinition_getFieldByNum(ed, is->iprotofield);
6071 pf = protoDefinition_getFieldByNum(pd, is->ifield);
6072 if(ef->alreadySet ){
6074 shallow_copy_field(is->type, &ef->defaultVal, &pf->defaultVal);
6075 pf->alreadySet = TRUE;
6082 deep_copy_broto_body2(&pdeclare,&pinstance);
6083 nnode = X3D_NODE(pinstance);
6084 AddRemoveChildren(X3D_NODE(node), &node->__children, &nnode, 1, 1,__FILE__,__LINE__);
6085 add_parent(X3D_NODE(pinstance),X3D_NODE(node),__FILE__,__LINE__);
6094 void add_node_to_broto_context(
struct X3D_Proto *context,
struct X3D_Node *node){
6104 if(context && hasContext(X3D_NODE(context))){
6106 if(!context->__nodes)
6107 context->__nodes = newVector(
struct X3D_Node*,4);
6108 __nodes = context->__nodes;
6109 node->_executionContext = (
struct X3D_Node*)context;
6110 stack_push(
struct X3D_Node*,__nodes,node);
6111 if(hasContext(node)){
6113 if(!context->__subcontexts)
6114 context->__subcontexts = newVector(
struct X3D_Node*,4);
6115 __subctxs = context->__subcontexts;
6116 stack_push(
struct X3D_Node*,__subctxs,node);
6120 void remove_node_from_broto_context(
struct X3D_Proto *context,
struct X3D_Node *node){
6130 if(context && hasContext(X3D_NODE(context))){
6131 if(context->__nodes){
6133 for(i=0;i<vectorSize(context->__nodes);i++){
6136 vector_remove_elem(
struct X3D_Node*,context->__nodes,i);
6141 if(context->__subcontexts && hasContext(node) ){
6143 for(i=0;i<vectorSize(context->__subcontexts);i++){
6144 struct X3D_Node *ns = vector_get(
struct X3D_Node*,context->__subcontexts,i);
6146 vector_remove_elem(
struct X3D_Node*,context->__subcontexts,i);
6153 void lock_and_do_routes_register();
6154 int unregister_broutes(
struct X3D_Proto * node){
6157 if(node && hasContext(X3D_NODE(node))){
6158 unsigned char depthflag = ciflag_get(node->__protoFlags,0);
6164 for(i=0;i<vectorSize(node->__ROUTES);i++){
6165 route = vector_get(
struct brotoRoute*,node->__ROUTES,i);
6166 if(route && route->lastCommand){
6167 CRoutes_RemoveSimpleB(route->from.node,route->from.ifield,route->to.node,route->to.ifield,route->ft);
6168 route->lastCommand = 0;
6175 lock_and_do_routes_register();
6184 void unRegisterTexture(
struct X3D_Node *tmp);
6185 void unRegisterBindable (
struct X3D_Node *node);
6186 void remove_OSCsensor(
struct X3D_Node * node);
6187 void remove_picksensor(
struct X3D_Node * node);
6188 void delete_first(
struct X3D_Node *node);
6189 void removeNodeFromKeySensorList(
struct X3D_Node* node);
6190 int unInitializeScript(
struct X3D_Node *node);
6191 void delete_polyrep(
struct X3D_Node *node);
6192 void unRegisterPolyRep(
struct X3D_Node *node);
6193 void delete_glbuffers(
struct X3D_Node *node);
6194 int unRegisterX3DAnyNode(
struct X3D_Node *node){
6222 unRegisterTexture(node);
6224 unRegisterX3DNode(node);
6226 unRegisterBindable(node);
6228 remove_OSCsensor(node);
6230 remove_picksensor(node);
6234 removeNodeFromKeySensorList(X3D_NODE(node));
6237 unInitializeScript(node);
6240 delete_polyrep(node);
6241 delete_glbuffers(node);
6244 int print_broto_stats(
int level,
struct X3D_Proto *node){
6247 for(i=0;i<level;i++)
6249 spaces[level] =
'\0';
6250 nr = node->__ROUTES ? vectorSize(node->__ROUTES) : 0;
6251 nn = node->__nodes ? vectorSize(node->__nodes) : 0;
6252 nc = node->__subcontexts ? vectorSize(node->__subcontexts) : 0;
6254 printf(
"%sctx=%p routes=%d nodes=%d subcontexts=%d\n",spaces,node,nr,nn,nc);
6256 int nextlevel = level + 1;
6258 struct X3D_Proto* sc = vector_get(
struct X3D_Proto*,node->__subcontexts,i);
6259 print_broto_stats(nextlevel,sc);
6265 int unregister_broto_instance(
struct X3D_Proto* node){
6282 if(node && hasContext(X3D_NODE(node))){
6283 unsigned char depthflag = ciflag_get(node->__protoFlags,0);
6287 if(node->__subcontexts){
6289 for(i=0;i<vectorSize(node->__subcontexts);i++){
6290 struct X3D_Proto* subcontext = vector_get(
struct X3D_Proto*,node->__subcontexts,i);
6291 unregister_broto_instance(subcontext);
6295 unregister_IStableRoutes((
Stack*)node->__IS, node);
6297 unregister_broutes(node);
6304 for(i=0;i<vectorSize(node->__nodes);i++){
6306 unRegisterX3DAnyNode(ns);
6307 broto_clear_DEF_by_node(node,ns);
6315 int gc_broto_instance(
struct X3D_Proto* node){
6326 if(node && hasContext(X3D_NODE(node))){
6327 node->__children.n = 0;
6328 node->_sortedChildren.n = 0;
6329 if(node->__subcontexts){
6330 struct X3D_Proto *subctx;
6331 for(i=0;i<vectorSize(node->__subcontexts);i++){
6332 subctx = vector_get(
struct X3D_Proto*,node->__subcontexts,i);
6333 gc_broto_instance(subctx);
6335 deleteVector(
struct X3D_Proto*,node->__subcontexts);
6339 for(i=0;i<vectorSize(node->__ROUTES);i++){
6344 deleteVector(
struct brotoRoute *, node->__ROUTES);
6348 deleteVector(
struct X3D_Node *,node->__scripts);
6351 for(i=0;i<vectorSize(node->__IS);i++) {
6355 deleteVector(
struct brotoIS *,node->__IS);
6358 if(node->__DEFnames) {
6359 for(i=0;i<vectorSize(node->__DEFnames);i++) {
6361 FREE_IF_NZ(def.name);
6367 deleteVector(
struct EXIMPORT *,node->__IMPORTS);
6370 deleteVector(
struct EXIMPORT *,node->__EXPORTS);
6380 int crash_challenge = 1;
6381 if(crash_challenge) {
6382 for(i=0;i<vectorSize(node->__nodes);i++){
6383 nx = vector_get(
struct X3D_Node*,node->__nodes,i);
6384 freeMallocedNodeFields(nx);
6388 deleteVector(
struct X3D_Node *,node->__nodes);
6390 if(node->__protoDeclares){
6392 struct X3D_Proto *subctx;
6393 char flagInstance, flagExtern;
6394 flagInstance = ciflag_get(node->__protoFlags,2);
6395 flagExtern = ciflag_get(node->__protoFlags,3);
6396 if(!(flagExtern && !flagInstance))
6397 for(i=0;i<vectorSize(node->__protoDeclares);i++){
6398 subctx = vector_get(
struct X3D_Proto*,node->__protoDeclares,i);
6400 gc_broto_instance(subctx);
6401 freeMallocedNodeFields(X3D_NODE(subctx));
6404 deleteVector(
void*,node->__protoDeclares);
6406 if(node->__externProtoDeclares){
6408 struct X3D_Proto *subctx;
6409 char flagInstance, flagExtern;
6410 flagInstance = ciflag_get(node->__protoFlags,2);
6411 flagExtern = ciflag_get(node->__protoFlags,3);
6412 if(!(flagExtern && !flagInstance))
6413 for(i=0;i<vectorSize(node->__externProtoDeclares);i++){
6417 subctx = vector_get(
struct X3D_Proto*,node->__externProtoDeclares,i);
6418 gc_broto_instance(subctx);
6419 freeMallocedNodeFields(X3D_NODE(subctx));
6422 deleteVector(
void*,node->__externProtoDeclares);
6428 int unload_broto(
struct X3D_Proto* node){
6451 if(node && hasContext(X3D_NODE(node))){
6453 unregister_broto_instance(node);
6454 gc_broto_instance(node);
6459 int unRegisterNodeRoutes(
struct X3D_Proto *context,
struct X3D_Node* node){
6462 if(context && hasContext(X3D_NODE(context))){
6463 if(context->__ROUTES){
6465 nr = vectorSize(context->__ROUTES);
6469 route = vector_get(
struct brotoRoute*,context->__ROUTES,ii);
6470 if(route->from.node == node || route->to.node == node){
6471 if( route->lastCommand){
6472 CRoutes_RemoveSimpleB(route->from.node,route->from.ifield,route->to.node,route->to.ifield,route->ft);
6473 route->lastCommand = 0;
6475 vector_remove_elem(
struct X3D_Node*,context->__ROUTES,ii);
6483 int remove_broto_node(
struct X3D_Proto *context,
struct X3D_Node* node){
6487 if(context && hasContext(X3D_NODE(context))){
6488 if(node && hasContext(node))
6489 unload_broto(X3D_PROTO(node));
6490 unRegisterX3DAnyNode(node);
6491 unRegisterNodeRoutes(context,node);
6492 remove_node_from_broto_context(context,node);