FreeWRL / FreeX3D 4.3.0
EAI_C_CommonFunctions.c
1/*
2
3
4???
5
6*/
7
8
9/****************************************************************************
10 This file is part of the FreeWRL/FreeX3D Distribution.
11
12 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
13
14 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Lesser Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
26****************************************************************************/
27
28
29
30// JAS - OLDCODE #ifndef REWIRE
31#include <config.h>
32#include <system.h>
33#include <libFreeWRL.h>
34// JAS - OLDCODE #endif
35#include <display.h>
36#include <internal.h>
37
38
39#include "../vrml_parser/Structs.h"
40#include "../main/headers.h"
41#include "../vrml_parser/CParseGeneral.h"
42#include "../scenegraph/Vector.h"
43#include "../vrml_parser/CFieldDecls.h"
44#include "../world_script/JScript.h"
45#include "../world_script/CScripts.h"
46#include "../vrml_parser/CParseParser.h"
47#include "../vrml_parser/CParseLexer.h"
48#include "EAIHeaders.h"
49#include "EAIHelpers.h"
50
51/* assume eaiverbose is false, unless told otherwise */
52//int eaiverbose = FALSE;
54 struct VRMLParser *parser; // = NULL;
55}* ppEAI_C_CommonFunctions;
56void *EAI_C_CommonFunctions_constructor()
57{
58 void *v = MALLOCV(sizeof(struct pEAI_C_CommonFunctions));
59 memset(v,0,sizeof(struct pEAI_C_CommonFunctions));
60 return v;
61}
62
63void EAI_C_CommonFunctions_init(struct tEAI_C_CommonFunctions* t){
64 //public
65 t->eaiverbose = FALSE;
66 //private
67 t->prv = EAI_C_CommonFunctions_constructor();
68 //just a pointer - null init ok
69}
70
71#define PST_MF_STRUCT_ELEMENT(type1,type2) \
72 case FIELDTYPE_MF##type1: { \
73 struct Multi_##type1 *myv; \
74 myv = (struct Multi_##type1 *) nst; \
75 /* printf ("old val p= %u, n = %d\n",myv->p, myv->n); */\
76 myv->p = myVal.mf##type2.p; \
77 myv->n = myVal.mf##type2.n; \
78 /* printf ("PST_MF_STRUCT_ELEMENT, now, element count %d\n",myv->n); */ \
79 break; }
80
81
82#define PST_SF_SIMPLE_ELEMENT(type1,type2,size3) \
83 case FIELDTYPE_SF##type1: { \
84 memcpy(nst, &myVal.sf##type2, size3); \
85 break; }
86
87
88/* create a structure to hold a string; it has a length, and a string pointer */
89struct Uni_String *newASCIIString(const char *str) {
90 struct Uni_String *retval;
91 int len;
92 int eaiverbose = gglobal()->EAI_C_CommonFunctions.eaiverbose;
93
94 if (eaiverbose) {
95 printf ("newASCIIString for :%s:\n",str);
96 }
97
98 /* the returning Uni_String is here. Make blank struct */
99 retval = MALLOC (struct Uni_String *, sizeof (struct Uni_String));
100 len = (int) strlen(str);
101
102 retval->strptr = MALLOC (char *, sizeof(char) * len+1);
103 memcpy(retval->strptr,str,len+1);
104 retval->len = len+1;
105 retval->touched = 1; /* make it 1, to signal that this is a NEW string. */
106
107 /* printf ("newASCIIString, returning UniString %x, strptr %u for string :%s:\n",retval, retval->strptr,str); */
108
109 return retval;
110}
111
112
113
114void clearASCIIString(struct Uni_String *us);
115void freeASCIIString(struct Uni_String *us);
116void clearMFString(struct Multi_String *ms);
117void freeMFString(struct Multi_String **ms);
118
119void clearASCIIString(struct Uni_String *us){
120 if(us){
121 FREE_IF_NZ(us->strptr);
122 us->strptr = NULL;
123 us->len = 0;
124 }
125}
126void freeASCIIString(struct Uni_String *us){
127 clearASCIIString(us);
128 FREE_IF_NZ(us);
129}
130void clearMFString(struct Multi_String *ms){
131 if(ms){
132 int i;
133 //printf("ms.n=%d\n",ms->n);
134 for(i=0;i<ms->n;i++){
135 struct Uni_String *us = ms->p[i];
136 //printf("us[%d]='%s'\n",i,us->strptr);
137 freeASCIIString(ms->p[i]);
138 }
139 ms->n = 0;
140 FREE_IF_NZ(ms->p);
141 }
142}
143void freeMFString(struct Multi_String **ms){
144 clearMFString(*ms);
145 FREE_IF_NZ(*ms);
146}
147
148/* do these strings differ?? If so, copy the new string over the old, and
149touch the touched flag */
150void verify_Uni_String(struct Uni_String *unis, const char *str) {
151 char *ns;
152 char *os;
153 size_t len;
154 // JASint eaiverbose = gglobal()->EAI_C_CommonFunctions.eaiverbose;
155
156 /* bounds checking */
157 if (unis == NULL) {
158 printf ("Warning, verify_Uni_String, comparing to NULL Uni_String, %s\n",str);
159 return;
160 }
161
162 /* are they different? */
163 if(!unis->strptr)
164 unis->strptr = strdup(str);
165 else
166 if (strcmp(str,unis->strptr)!= 0) {
167 os = unis->strptr;
168 len = strlen(str);
169 ns = MALLOC (char *,len+1);
170 memcpy(ns,str,len+1);
171 unis->strptr = ns;
172 FREE_IF_NZ (os);
173 unis->touched++;
174 }
175}
176
177
178
179
180/* get how many bytes in the type */
181int returnElementLength(int type) {
182 switch (type) {
183 case FIELDTYPE_SFVec2d:
184 case FIELDTYPE_MFVec2d:
185 case FIELDTYPE_MFVec3d:
186 case FIELDTYPE_SFVec3d:
187 case FIELDTYPE_MFDouble:
188 case FIELDTYPE_SFDouble:
189 case FIELDTYPE_SFVec4d:
190 case FIELDTYPE_MFVec4d:
191 case FIELDTYPE_SFMatrix3d:
192 case FIELDTYPE_MFMatrix3d:
193 case FIELDTYPE_SFMatrix4d:
194 case FIELDTYPE_MFMatrix4d:
195 case FIELDTYPE_SFTime :
196 case FIELDTYPE_MFTime : return (int) sizeof(double); break;
197 case FIELDTYPE_SFImage:
198 case FIELDTYPE_MFInt32: return (int) sizeof(int) ; break;
199 case FIELDTYPE_FreeWRLPTR:
200 case FIELDTYPE_MFString:
201 case FIELDTYPE_SFString:
202 case FIELDTYPE_SFNode :
203 case FIELDTYPE_MFNode : return (int) sizeof(void *); break;
204 default : {}
205 }
206 return (int) sizeof(float) ; /* turn into byte count */
207}
208
209/* for passing into CRoutes/CRoutes_Register */
210/* lengths are either positive numbers, or, if there is a complex type, a negative number. If positive,
211 in routing a memcpy is performed; if negative, then some inquiry is required to get correct length
212 of both source/dest during routing. */
213
214int returnRoutingElementLength(int type) {
215 switch (type) {
216 case FIELDTYPE_SFFloat: return (int)sizeof(float); break;
217 case FIELDTYPE_SFBool:
218 case FIELDTYPE_SFInt32: return (int) sizeof(int); break;
219 case FIELDTYPE_SFTime: return (int)sizeof(double); break;
220 case FIELDTYPE_SFDouble: return (int)sizeof(double); break;
221 case FIELDTYPE_SFNode: return (int)ROUTING_SFNODE; break;
222 case FIELDTYPE_SFColor: return (int)sizeof(struct SFColor); break;
223 case FIELDTYPE_SFColorRGBA: return (int)sizeof(struct SFColorRGBA); break;
224 case FIELDTYPE_SFRotation:return (int)sizeof(struct SFRotation); break;
225 case FIELDTYPE_SFVec2f: return (int) sizeof (struct SFVec2f); break;
226 case FIELDTYPE_SFVec3f: return (int)sizeof(struct SFVec3f); break;
227 case FIELDTYPE_SFVec4f: return (int)sizeof(struct SFVec4f); break;
228 case FIELDTYPE_SFVec2d: return (int)sizeof(struct SFVec2d); break;
229 case FIELDTYPE_SFVec3d: return (int) sizeof (struct SFVec3d); break;
230 case FIELDTYPE_SFVec4d: return (int)sizeof(struct SFVec4d); break;
231 case FIELDTYPE_SFString: return (int)ROUTING_SFSTRING; break;
232 case FIELDTYPE_SFImage: return (int)ROUTING_SFIMAGE; break;
233
234 case FIELDTYPE_SFMatrix3f: return (int) sizeof (struct SFMatrix3f); break;
235 case FIELDTYPE_SFMatrix4f: return (int)sizeof(struct SFMatrix4f); break;
236 case FIELDTYPE_SFMatrix3d: return (int) sizeof (struct SFMatrix3d); break;
237 case FIELDTYPE_SFMatrix4d: return (int)sizeof(struct SFMatrix4d); break;
238
239 case FIELDTYPE_MFFloat: return (int)ROUTING_MFFLOAT; break;
240 case FIELDTYPE_MFBool:
241 case FIELDTYPE_MFInt32: return (int)ROUTING_MFINT32; break;
242 case FIELDTYPE_MFTime: return (int)ROUTING_MFDOUBLE; break;
243 case FIELDTYPE_MFDouble: return (int)ROUTING_MFDOUBLE; break;
244 case FIELDTYPE_MFNode: return (int) ROUTING_MFNODE; break;
245 case FIELDTYPE_MFColor: return (int)ROUTING_MFCOLOR; break;
246 case FIELDTYPE_MFColorRGBA: return (int)ROUTING_MFROTATION; break;
247 case FIELDTYPE_MFRotation: return (int)ROUTING_MFROTATION; break;
248 case FIELDTYPE_MFVec2f: return (int) ROUTING_MFVEC2F; break;
249 case FIELDTYPE_MFVec3f: return (int) ROUTING_MFVEC3F; break;
250 case FIELDTYPE_MFVec4f: return (int) ROUTING_MFVEC4F; break;
251 case FIELDTYPE_MFVec2d: return (int)ROUTING_MFVEC2D; break;
252 case FIELDTYPE_MFVec3d: return (int)ROUTING_MFVEC3D; break;
253 case FIELDTYPE_MFVec4d: return (int) ROUTING_MFVEC4D; break;
254 case FIELDTYPE_MFString: return (int)ROUTING_MFSTRING; break;
255 case FIELDTYPE_MFMatrix3f: return (int) ROUTING_MFMATRIX3F; break;
256 case FIELDTYPE_MFMatrix3d: return (int) ROUTING_MFMATRIX3D; break;
257 case FIELDTYPE_MFMatrix4f: return (int)ROUTING_MFMATRIX4F; break;
258 case FIELDTYPE_MFMatrix4d: return (int)ROUTING_MFMATRIX4D; break;
259
260 default:{
261 printf ("warning - returnRoutingElementLength not a handled type, %d\n",type);
262 }
263 }
264 return (int) sizeof(int);
265}
266
267
268
269/* how many numbers/etc in an array entry? eg, SFVec3f = 3 - 3 floats */
270/* "" "" eg, MFVec3f = 3 - 3 floats, too! */
271int returnElementRowSize (int type) {
272 switch (type) {
273 case FIELDTYPE_SFVec2f:
274 case FIELDTYPE_MFVec2f:
275 case FIELDTYPE_SFVec2d:
276 case FIELDTYPE_MFVec2d:
277 return 2;
278 case FIELDTYPE_SFColor:
279 case FIELDTYPE_MFColor:
280 case FIELDTYPE_SFVec3f:
281 case FIELDTYPE_SFVec3d:
282 case FIELDTYPE_MFVec3f:
283 case FIELDTYPE_MFVec3d:
284 case FIELDTYPE_SFImage: /* initialization - we can have a "0,0,0" for no texture */
285 return 3;
286 case FIELDTYPE_SFRotation:
287 case FIELDTYPE_MFRotation:
288 case FIELDTYPE_SFVec4d:
289 case FIELDTYPE_SFVec4f:
290 case FIELDTYPE_MFVec4d:
291 case FIELDTYPE_MFVec4f:
292 case FIELDTYPE_SFColorRGBA:
293 case FIELDTYPE_MFColorRGBA:
294 return 4;
295 case FIELDTYPE_MFMatrix3f:
296 case FIELDTYPE_SFMatrix3f:
297 case FIELDTYPE_MFMatrix3d:
298 case FIELDTYPE_SFMatrix3d:
299 return 9;
300 case FIELDTYPE_MFMatrix4f:
301 case FIELDTYPE_SFMatrix4f:
302 case FIELDTYPE_MFMatrix4d:
303 case FIELDTYPE_SFMatrix4d:
304 return 16;
305 }
306 return 1;
307
308}
309
310
311
312int mf2sf(int itype){
313 //luckily the fieldtype defines are consistently mf = sf+1
314 //return convertToSFType(itype); //this is more reliable -converts and sf to itself- but bulky
315 //if(itype == FIELDTYPE_SFImage)
316 // return FIELDTYPE_SFInt32;
317 return itype -1;
318}
319int sf2mf(int itype){
320 //luckily the fieldtype defines are consistently mf = sf+1
321 return itype +1;
322}
323
324/*we seem to be missing something in generated code/structs that would allow me to
325 look up how big something is. I suspect it's ##MACRO-ized elsewhere.
326*/
327
328
329int isSForMFType(int itype){
330 //sadly the fieldtype defines aren't reliably even or odd for sf or mf, so we'll do a switch case
331 //-1 unknown /not a fieldtype
332 //0 SF
333 //1 MF
334 int iret;
335 switch(itype){
336 case FIELDTYPE_SFFloat:
337 case FIELDTYPE_SFRotation:
338 case FIELDTYPE_SFVec3f:
339 case FIELDTYPE_SFBool:
340 case FIELDTYPE_SFInt32:
341 case FIELDTYPE_SFNode:
342 case FIELDTYPE_SFColor:
343 case FIELDTYPE_SFColorRGBA:
344 case FIELDTYPE_SFTime:
345 case FIELDTYPE_SFString:
346 case FIELDTYPE_SFVec2f:
347 case FIELDTYPE_SFImage:
348 case FIELDTYPE_SFVec3d:
349 case FIELDTYPE_SFDouble:
350 case FIELDTYPE_SFMatrix3f:
351 case FIELDTYPE_SFMatrix3d:
352 case FIELDTYPE_SFMatrix4f:
353 case FIELDTYPE_SFMatrix4d:
354 case FIELDTYPE_SFVec2d:
355 case FIELDTYPE_SFVec4f:
356 case FIELDTYPE_SFVec4d:
357 iret = 0;
358 break;
359
360 case FIELDTYPE_MFFloat:
361 case FIELDTYPE_MFRotation:
362 case FIELDTYPE_MFVec3f:
363 case FIELDTYPE_MFBool:
364 case FIELDTYPE_MFInt32:
365 case FIELDTYPE_MFNode:
366 case FIELDTYPE_MFColor:
367 case FIELDTYPE_MFColorRGBA:
368 case FIELDTYPE_MFTime:
369 case FIELDTYPE_MFString:
370 case FIELDTYPE_MFVec2f:
371 case FIELDTYPE_MFImage:
372 case FIELDTYPE_MFVec3d:
373 case FIELDTYPE_MFDouble:
374 case FIELDTYPE_MFMatrix3f:
375 case FIELDTYPE_MFMatrix3d:
376 case FIELDTYPE_MFMatrix4f:
377 case FIELDTYPE_MFMatrix4d:
378 case FIELDTYPE_MFVec2d:
379 case FIELDTYPE_MFVec4f:
380 case FIELDTYPE_MFVec4d:
381 iret = 1; break;
382 default:
383 iret = -1; break;
384 }
385 return iret;
386}
387int type2SF(int itype){
388 //unconditionally returns sf type
389 int jtype, sformf = isSForMFType(itype);
390 if(sformf < 0) return -1;
391 jtype = itype;
392 if(sformf == 1) jtype = mf2sf(itype);
393 return jtype;
394}
395int isSFType(int itype){
396 return (isSForMFType(itype) == 0) ? 1 : 0;
397}
398
399int sizeofSForMF(int itype){
400 //goal get the offset for MF.p[i] in bytes
401 //or also this is the 'shallow size' for field copying
402 int iz;
403 switch(itype){
404 case FIELDTYPE_SFFloat: iz = sizeof(float); break;
405 case FIELDTYPE_SFRotation: iz = sizeof(struct SFRotation); break;
406 case FIELDTYPE_SFVec3f: iz = sizeof(struct SFVec3f);break;
407 case FIELDTYPE_SFBool: iz = sizeof(int); break;
408 case FIELDTYPE_SFInt32: iz = sizeof(int); break;
409 case FIELDTYPE_SFNode: iz = sizeof(void*); break;
410 case FIELDTYPE_SFColor: iz = sizeof(struct SFColor); break;
411 case FIELDTYPE_SFColorRGBA: iz = sizeof(struct SFColorRGBA); break;
412 case FIELDTYPE_SFTime: iz = sizeof(double); break;
413 case FIELDTYPE_SFString: iz = sizeof(struct Uni_String *); break; //sizeof(void *) because nodes that have a string field declare it struct Uni_String *, so when copying to a node, you copy sizeof(void*). H: if the char *string is const, then uni_string is const (they may hang out as pals for life, or char *string may outlive its uni_string pal
414 case FIELDTYPE_SFVec2f: iz = sizeof(struct SFVec2f); break;
415 case FIELDTYPE_SFImage: iz = sizeof(struct SFImage); break;
416 case FIELDTYPE_SFVec3d: iz = sizeof(struct SFVec3d); break;
417 case FIELDTYPE_SFDouble: iz = sizeof(double); break;
418 case FIELDTYPE_SFMatrix3f: iz = sizeof(struct SFMatrix3f); break;
419 case FIELDTYPE_SFMatrix3d: iz = sizeof(struct SFMatrix3d); break;
420 case FIELDTYPE_SFMatrix4f: iz = sizeof(struct SFMatrix4f); break;
421 case FIELDTYPE_SFMatrix4d: iz = sizeof(struct SFMatrix4d); break;
422 case FIELDTYPE_SFVec2d: iz = sizeof(struct SFVec2d); break;
423 case FIELDTYPE_SFVec4f: iz = sizeof(struct SFVec4f); break;
424 case FIELDTYPE_SFVec4d: iz = sizeof(struct SFVec4d); break;
425
426 case FIELDTYPE_MFImage:
427 case FIELDTYPE_MFFloat:
428 case FIELDTYPE_MFRotation:
429 case FIELDTYPE_MFVec3f:
430 case FIELDTYPE_MFBool:
431 case FIELDTYPE_MFInt32:
432 case FIELDTYPE_MFNode:
433 case FIELDTYPE_MFColor:
434 case FIELDTYPE_MFColorRGBA:
435 case FIELDTYPE_MFTime:
436 case FIELDTYPE_MFString:
437 case FIELDTYPE_MFVec2f:
438 case FIELDTYPE_MFVec3d:
439 case FIELDTYPE_MFDouble:
440 case FIELDTYPE_MFMatrix3f:
441 case FIELDTYPE_MFMatrix3d:
442 case FIELDTYPE_MFMatrix4f:
443 case FIELDTYPE_MFMatrix4d:
444 case FIELDTYPE_MFVec2d:
445 case FIELDTYPE_MFVec4f:
446 case FIELDTYPE_MFVec4d:
447 iz = sizeof(struct Multi_Node);
448 break;
449 default:
450 //unknown
451 iz = sizeof(void*);
452 break;
453 }
454 return iz;
455}
456int sizeofSF(int itype){
457 int jtype;
458 int sformf = isSForMFType(itype);
459 if( sformf < 0) return 0;
460 jtype = itype;
461 if( sformf == 1 ) jtype = mf2sf(itype);
462 return sizeofSForMF(jtype);
463}
464
465
466//static struct VRMLParser *parser = NULL;
467
468/* from the XML parser, for instance, we can call this on close to delete memory and memory tables */
469void Parser_deleteParserForScanStringValueToMem(void) {
470 ppEAI_C_CommonFunctions p = (ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv;
471 if (p==NULL) return;
472 if (p->parser != NULL) {
473 lexer_destroyData(p->parser->lexer);
474 deleteParser(p->parser);
475 p->parser = NULL;
476 }
477}
478
479
480void Parser_scanStringValueToMem(struct X3D_Node *node, size_t coffset, indexT ctype, char *value, int isXML) {
481 void *nst; /* used for pointer maths */
482 union anyVrml myVal;
483 char *mfstringtmp = NULL;
484 int oldXMLflag;
485 struct X3D_Node *np;
486 struct VRMLParser *parser = ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser;
487 #ifdef SETFIELDVERBOSE
488 printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
489 #endif
490 np = NULL;
491 /* if this is the first time through, create a new parser, and tell it:
492 - that we are using X3D formatted field strings, NOT "VRML" ones;
493 - that the destination node is not important (the NULL, offset 0) */
494
495 if (parser == NULL) {
496 parser=newParser(NULL,NULL, 0, TRUE);
497 //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
498 // save it
499 ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser = parser;
500 }
501
502 lexer_forceStringCleanup(parser->lexer);
503
504 /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
505 have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
506
507 if (isXML) {
508 /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
509 if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
510 /* printf ("returning\n"); */
511 lexer_forceStringCleanup(parser->lexer);
512 return;
513 }
514
515 }
516
517 /* there is a difference sometimes, in the XML format and VRML classic format. The XML
518 parser will use xml format, scripts and EAI will use the classic format */
519 oldXMLflag = parser->parsingX3DfromXML;
520 parser->parsingX3DfromXML = isXML;
521
522 /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
523 if (ctype == FIELDTYPE_MFString) {
524 #ifdef SETFIELDVERBOSE
525 printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
526 #endif
527
528 /* go to the first non-space character, and see if this is required;
529 sometimes people will encode mfstrings as:
530 url=' "images/earth.gif" "http://ww
531 note the space in the value */
532 while ((*value == ' ') && (*value != '\0')) value ++;
533
534 /* now, does the value string need quoting? */
535 if ((*value != '"') && (*value != '\'') && (*value != '[')) {
536 size_t len;
537 /* printf ("have to quote this string\n"); */
538 len = strlen(value);
539 mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
540 memcpy (&mfstringtmp[1],value,len);
541 mfstringtmp[0] = '"';
542 mfstringtmp[len+1] = '"';
543 mfstringtmp[len+2] = '\0';
544 /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
545
546 } else {
547 mfstringtmp = STRDUP(value);
548 }
549 parser_fromString(parser,mfstringtmp);
550 /* FREE_IF_NZ(mfstringtmp); */
551 } else if (ctype == FIELDTYPE_SFNode) {
552 /* Need to change index to proper node ptr */
553 np = getEAINodeFromTable(atoi(value), -1);
554 } else if (ctype == FIELDTYPE_SFString) {
555 if(isXML){
556 /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
557 int nq = 0;
558 char *mv, *pv, *v = value;
559 while (*v && *v != '\0')
560 {
561 if(*v == '"') nq++;
562 v++;
563 }
564 mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
565 v = value;
566 pv = NULL;
567 mv = mfstringtmp;
568 while(*v && *v != '\0')
569 {
570 if(*v == '"'){
571 if(!(pv && *pv == '\\')){
572 *mv = '\\';
573 mv++;
574 }
575 }
576 *mv = *v;
577 mv++;
578 pv = v;
579 v++;
580 }
581 *mv = '\0';
582 }else{
583 mfstringtmp = STRDUP(value);
584 }
585 parser_fromString(parser,mfstringtmp);
586 } else {
587 mfstringtmp = STRDUP(value);
588 parser_fromString(parser,mfstringtmp);
589 /* FREE_IF_NZ(mfstringtmp); */
590 }
591
592 ASSERT(parser->lexer);
593 FREE_IF_NZ(parser->lexer->curID);
594
595 if (ctype == FIELDTYPE_SFNode) {
596 struct X3D_Node* oldvalue;
597 nst = offsetPointer_deref(void *,node,coffset);
598 memcpy (&oldvalue, nst, sizeof(struct X3D_Node*));
599 if (oldvalue) {
600 remove_parent(oldvalue, node);
601 }
602 if(np){
603 memcpy(nst, (void*)&np, sizeof(struct X3D_Node*));
604 add_parent(np, node, "sarah's add", 0);
605 }
606 } else if (parseType(parser, ctype, &myVal)) {
607 /* printf ("parsed successfully\n"); */
608 nst = offsetPointer_deref(void *,node,coffset);
609
610
611/*
612MF_TYPE(MFNode, mfnode, Node)
613*/
614 switch (ctype) {
615
616 PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
617 PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
618 PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
619 PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
620 PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
621 PST_MF_STRUCT_ELEMENT(Color,color)
622 PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
623 PST_MF_STRUCT_ELEMENT(Int32,int32)
624 PST_MF_STRUCT_ELEMENT(Float,float)
625 PST_MF_STRUCT_ELEMENT(Double,double)
626 PST_MF_STRUCT_ELEMENT(Bool,bool)
627 PST_MF_STRUCT_ELEMENT(Time,time)
628 PST_MF_STRUCT_ELEMENT(Rotation,rotation)
629 PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
630 PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
631 PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
632 PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
633 PST_MF_STRUCT_ELEMENT(String,string)
634
635 PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
636 PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
637 PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
638 PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
639 PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
640 PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
641 PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
642 PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
643 PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
644 PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
645 PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
646 PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
647 PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
648 PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
649 PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
650 PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
651 PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
652 PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
653 PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
654 PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
655
656 case FIELDTYPE_SFString: {
657 //struct Uni_String *mptr;
658 memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
659 //mptr = * (struct Uni_String **)nst;
660 //if (!mptr) {
661 // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
662 //} else {
663 // FREE_IF_NZ(mptr->strptr);
664 // mptr->strptr = myVal.sfstring->strptr;
665 // mptr->len = myVal.sfstring->len;
666 // mptr->touched = myVal.sfstring->touched;
667 //}
668 break; }
669
670 default: {
671 printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
672 lexer_forceStringCleanup(parser->lexer);
673 return;
674 }
675 }
676
677 } else {
678 if (strlen (value) > 50) {
679 value[45] = '.';
680 value[46] = '.';
681 value[47] = '.';
682 value[48] = '\0';
683 }
684 ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
685 }
686
687 /* tell the parser that we have done with the input - it will FREE the data */
688 lexer_forceStringCleanup(parser->lexer);
689
690 /* and, reset the XML flag */
691 parser->parsingX3DfromXML = oldXMLflag;
692}
693
694
695void Parser_scanStringValueToMem_B(union anyVrml* any, indexT ctype, char *value, int isXML)
696{
697 //dug9 Feb 2013: same as Parser_scanStringValueToMem except:
698 // - puts it into *anyVrml instead of (node,offset)
699 // - doesn't update parents for SFNode, MFNode fields (just zeros it) - that's done outside
700 void *nst; /* used for pointer maths */
701 union anyVrml myVal;
702 char *mfstringtmp = NULL;
703 int oldXMLflag;
704 struct X3D_Node *np = NULL;
705 struct VRMLParser *parser = ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser;
706 #ifdef SETFIELDVERBOSE
707 printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
708 #endif
709
710 /* if this is the first time through, create a new parser, and tell it:
711 - that we are using X3D formatted field strings, NOT "VRML" ones;
712 - that the destination node is not important (the NULL, offset 0) */
713
714 if (parser == NULL) {
715 parser=newParser(NULL,NULL, 0, TRUE);
716 //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
717 // save it
718 ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser = parser;
719 }
720
721 lexer_forceStringCleanup(parser->lexer);
722
723 /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
724 have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
725
726 if (isXML) {
727 /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
728 if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
729 /* printf ("returning\n"); */
730 lexer_forceStringCleanup(parser->lexer);
731 return;
732 }
733
734 }
735
736 /* there is a difference sometimes, in the XML format and VRML classic format. The XML
737 parser will use xml format, scripts and EAI will use the classic format */
738 oldXMLflag = parser->parsingX3DfromXML;
739 parser->parsingX3DfromXML = isXML;
740
741 /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
742 if (ctype == FIELDTYPE_MFString) {
743 #ifdef SETFIELDVERBOSE
744 printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
745 #endif
746
747 /* go to the first non-space character, and see if this is required;
748 sometimes people will encode mfstrings as:
749 url=' "images/earth.gif" "http://ww
750 note the space in the value */
751 while ((*value == ' ') && (*value != '\0')) value ++;
752
753 /* now, does the value string need quoting? */
754 if ((*value != '"') && (*value != '\'') && (*value != '[')) {
755 static int MFS_warning_given = 0;
756 size_t len;
757 /* printf ("have to quote this string\n"); */
758 len = strlen(value);
759 mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
760 memcpy (&mfstringtmp[1],value,len);
761 mfstringtmp[0] = '"';
762 mfstringtmp[len+1] = '"';
763 mfstringtmp[len+2] = '\0';
764 if(0) if(!MFS_warning_given){
765 ConsoleMessage("Warning - an MFString needs internal quotes ie '%s' should be '%s'\n",value,mfstringtmp);
766 MFS_warning_given = 1;
767 }
768 /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
769
770 } else {
771 mfstringtmp = STRDUP(value);
772 }
773 parser_fromString(parser,mfstringtmp);
774 /* FREE_IF_NZ(mfstringtmp); */
775 } else if (ctype == FIELDTYPE_SFNode) {
776 /* Need to change index to proper node ptr */
777 np = getEAINodeFromTable(atoi(value), -1);
778 } else if (ctype == FIELDTYPE_SFString) {
779 if(isXML){
780 /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
781 int nq = 0;
782 char *mv, *pv, *v = value;
783 while (*v && *v != '\0')
784 {
785 if(*v == '"') nq++;
786 v++;
787 }
788 mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
789 v = value;
790 pv = NULL;
791 mv = mfstringtmp;
792 while(*v && *v != '\0')
793 {
794 if(*v == '"'){
795 if(!(pv && *pv == '\\')){
796 *mv = '\\';
797 mv++;
798 }
799 }
800 *mv = *v;
801 mv++;
802 pv = v;
803 v++;
804 }
805 *mv = '\0';
806 }else{
807 mfstringtmp = STRDUP(value);
808 }
809 parser_fromString(parser,mfstringtmp);
810 } else {
811 mfstringtmp = STRDUP(value);
812 parser_fromString(parser,mfstringtmp);
813 /* FREE_IF_NZ(mfstringtmp); */
814 }
815
816 ASSERT(parser->lexer);
817 FREE_IF_NZ(parser->lexer->curID);
818
819 if (ctype == FIELDTYPE_SFNode) {
820 //struct X3D_Node* oldvalue;
821 //nst = offsetPointer_deref(void *,node,coffset);
822 //memcpy (&oldvalue, any, sizeof(struct X3D_Node*));
823 //if (oldvalue) {
824 // remove_parent(oldvalue, node);
825 //}
826 memcpy(any, (void*)&np, sizeof(struct X3D_Node*));
827 any->sfnode->_parentVector = NULL;
828 //add_parent(np, node, "sarah's add", 0);
829 } else if (parseType(parser, ctype, &myVal)) {
830 /* printf ("parsed successfully\n"); */
831 //nst = offsetPointer_deref(void *,node,coffset);
832 nst = any;
833
834/*
835MF_TYPE(MFNode, mfnode, Node)
836*/
837 switch (ctype) {
838
839 PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
840 PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
841 PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
842 PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
843 PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
844 PST_MF_STRUCT_ELEMENT(Color,color)
845 PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
846 PST_MF_STRUCT_ELEMENT(Int32,int32)
847 PST_MF_STRUCT_ELEMENT(Float,float)
848 PST_MF_STRUCT_ELEMENT(Double,double)
849 PST_MF_STRUCT_ELEMENT(Bool,bool)
850 PST_MF_STRUCT_ELEMENT(Time,time)
851 PST_MF_STRUCT_ELEMENT(Rotation,rotation)
852 PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
853 PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
854 PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
855 PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
856 PST_MF_STRUCT_ELEMENT(String,string)
857 PST_MF_STRUCT_ELEMENT(Image, image)
858
859 PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
860 PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
861 PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
862 PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
863 PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
864 PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
865 PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
866 PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
867 PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
868 PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
869 PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
870 PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
871 PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
872 PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
873 PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
874 PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
875 PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
876 PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
877 PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
878 case FIELDTYPE_SFImage:
879 printf("in case FIELDTYPE_SFImage\n");
880 //PST_SF_SIMPLE_ELEMENT(Image, image, sizeof(struct Multi_Int32))
881 memcpy(nst, &myVal.sfimage, sizeof(struct SFImage));
882 break;
883 case FIELDTYPE_SFString: {
884 //struct Uni_String *mptr;
885 memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
886 //mptr = * (struct Uni_String **)nst;
887 //if (!mptr) {
888 // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
889 //} else {
890 // FREE_IF_NZ(mptr->strptr);
891 // mptr->strptr = myVal.sfstring->strptr;
892 // mptr->len = myVal.sfstring->len;
893 // mptr->touched = myVal.sfstring->touched;
894 //}
895 break; }
896
897 default: {
898 printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
899 lexer_forceStringCleanup(parser->lexer);
900 return;
901 }
902 }
903
904 } else {
905 if (strlen (value) > 50) {
906 value[45] = '.';
907 value[46] = '.';
908 value[47] = '.';
909 value[48] = '\0';
910 }
911 ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
912 }
913
914 /* tell the parser that we have done with the input - it will FREE the data */
915 lexer_forceStringCleanup(parser->lexer);
916
917 FREE_IF_NZ(mfstringtmp);
918
919 /* and, reset the XML flag */
920 parser->parsingX3DfromXML = oldXMLflag;
921}
922
923void Parser_scanStringValueToMem_C0(struct VRMLParser *parser, union anyVrml* any, indexT ctype, char *value, int isXML)
924{
925 //dug9 Apr 2013: same as Parser_scanStringValueToMemB except:
926 // - you create or remember your parser* outside, so no static or gglobal in here, so can be called from libeai.
927 // - puts it into *anyVrml instead of (node,offset)
928 // - doesn't update parents for SFNode, MFNode fields (just zeros it) - that's done outside
929 void *nst; /* used for pointer maths */
930 union anyVrml myVal;
931 char *mfstringtmp = NULL;
932 int oldXMLflag;
933 struct X3D_Node *np;
934 #ifdef SETFIELDVERBOSE
935 printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
936 #endif
937
938 /* if this is the first time through, create a new parser, and tell it:
939 - that we are using X3D formatted field strings, NOT "VRML" ones;
940 - that the destination node is not important (the NULL, offset 0) */
941
942 if (parser == NULL) {
943 parser=newParser(NULL,NULL, 0, TRUE);
944 //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
945 }
946
947 lexer_forceStringCleanup(parser->lexer);
948
949 /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
950 have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
951
952 if (isXML) {
953 /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
954 if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
955 /* printf ("returning\n"); */
956 lexer_forceStringCleanup(parser->lexer);
957 return;
958 }
959
960 }
961
962 /* there is a difference sometimes, in the XML format and VRML classic format. The XML
963 parser will use xml format, scripts and EAI will use the classic format */
964 oldXMLflag = parser->parsingX3DfromXML;
965 parser->parsingX3DfromXML = isXML;
966
967 /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
968 if (ctype == FIELDTYPE_MFString) {
969 #ifdef SETFIELDVERBOSE
970 printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
971 #endif
972
973 /* go to the first non-space character, and see if this is required;
974 sometimes people will encode mfstrings as:
975 url=' "images/earth.gif" "http://ww
976 note the space in the value */
977 while ((*value == ' ') && (*value != '\0')) value ++;
978
979 /* now, does the value string need quoting? */
980 if ((*value != '"') && (*value != '\'') && (*value != '[')) {
981 size_t len;
982 /* printf ("have to quote this string\n"); */
983 len = strlen(value);
984 mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
985 memcpy (&mfstringtmp[1],value,len);
986 mfstringtmp[0] = '"';
987 mfstringtmp[len+1] = '"';
988 mfstringtmp[len+2] = '\0';
989 /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
990
991 } else {
992 mfstringtmp = STRDUP(value);
993 }
994 parser_fromString(parser,mfstringtmp);
995 /* FREE_IF_NZ(mfstringtmp); */
996 } else if (ctype == FIELDTYPE_SFNode) {
997 /* Need to change index to proper node ptr */
998 np = getEAINodeFromTable(atoi(value), -1);
999 } else if (ctype == FIELDTYPE_SFString) {
1000 if(isXML){
1001 /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
1002 int nq = 0;
1003 char *mv, *pv, *v = value;
1004 while (*v && *v != '\0')
1005 {
1006 if(*v == '"') nq++;
1007 v++;
1008 }
1009 mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
1010 v = value;
1011 pv = NULL;
1012 mv = mfstringtmp;
1013 while(*v && *v != '\0')
1014 {
1015 if(*v == '"'){
1016 if(!(pv && *pv == '\\')){
1017 *mv = '\\';
1018 mv++;
1019 }
1020 }
1021 *mv = *v;
1022 mv++;
1023 pv = v;
1024 v++;
1025 }
1026 *mv = '\0';
1027 }else{
1028 mfstringtmp = STRDUP(value);
1029 }
1030 parser_fromString(parser,mfstringtmp);
1031 } else {
1032 mfstringtmp = STRDUP(value);
1033 parser_fromString(parser,mfstringtmp);
1034 /* FREE_IF_NZ(mfstringtmp); */
1035 }
1036
1037 ASSERT(parser->lexer);
1038 FREE_IF_NZ(parser->lexer->curID);
1039
1040 if (ctype == FIELDTYPE_SFNode) {
1041 //struct X3D_Node* oldvalue;
1042 //nst = offsetPointer_deref(void *,node,coffset);
1043 //memcpy (&oldvalue, any, sizeof(struct X3D_Node*));
1044 //if (oldvalue) {
1045 // remove_parent(oldvalue, node);
1046 //}
1047 memcpy(any, (void*)&np, sizeof(struct X3D_Node*));
1048 any->sfnode->_parentVector = NULL;
1049 //add_parent(np, node, "sarah's add", 0);
1050 } else if (parseType(parser, ctype, &myVal)) {
1051 /* printf ("parsed successfully\n"); */
1052 //nst = offsetPointer_deref(void *,node,coffset);
1053 nst = any;
1054
1055/*
1056MF_TYPE(MFNode, mfnode, Node)
1057*/
1058 switch (ctype) {
1059
1060 PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
1061 PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
1062 PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
1063 PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
1064 PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
1065 PST_MF_STRUCT_ELEMENT(Color,color)
1066 PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
1067 PST_MF_STRUCT_ELEMENT(Int32,int32)
1068 PST_MF_STRUCT_ELEMENT(Float,float)
1069 PST_MF_STRUCT_ELEMENT(Double,double)
1070 PST_MF_STRUCT_ELEMENT(Bool,bool)
1071 PST_MF_STRUCT_ELEMENT(Time,time)
1072 PST_MF_STRUCT_ELEMENT(Rotation,rotation)
1073 PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
1074 PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
1075 PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
1076 PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
1077 PST_MF_STRUCT_ELEMENT(String,string)
1078
1079 PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
1080 PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
1081 PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
1082 PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
1083 PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
1084 PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
1085 PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
1086 PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
1087 PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
1088 PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
1089 PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
1090 PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
1091 PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
1092 PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
1093 PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
1094 PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
1095 PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
1096 PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
1097 PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
1098 PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
1099
1100 case FIELDTYPE_SFString: {
1101 //struct Uni_String *mptr;
1102 memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
1103 //mptr = * (struct Uni_String **)nst;
1104 //if (!mptr) {
1105 // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
1106 //} else {
1107 // FREE_IF_NZ(mptr->strptr);
1108 // mptr->strptr = myVal.sfstring->strptr;
1109 // mptr->len = myVal.sfstring->len;
1110 // mptr->touched = myVal.sfstring->touched;
1111 //}
1112 break; }
1113
1114 default: {
1115 printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
1116 lexer_forceStringCleanup(parser->lexer);
1117 return;
1118 }
1119 }
1120
1121 } else {
1122 if (strlen (value) > 50) {
1123 value[45] = '.';
1124 value[46] = '.';
1125 value[47] = '.';
1126 value[48] = '\0';
1127 }
1128 ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
1129 }
1130
1131 /* tell the parser that we have done with the input - it will FREE the data */
1132 lexer_forceStringCleanup(parser->lexer);
1133
1134 /* and, reset the XML flag */
1135 parser->parsingX3DfromXML = oldXMLflag;
1136}
1137void Parser_scanStringValueToMem_C(void *any0, int ctype0, char *value, int isXML)
1138//void Parser_scanStringValueToMem_C(union anyVrml* any, indexT ctype, char *value, int isXML)
1139{
1140 struct VRMLParser *parser;
1141 union anyVrml* any;
1142 indexT ctype;
1143 any = (union anyVrml*)any0;
1144 ctype = (indexT)ctype0;
1145 parser=newParser(NULL,NULL, 0, TRUE);
1146 Parser_scanStringValueToMem_C0(parser, any, ctype, value, isXML);
1147 if (parser != NULL) {
1148 lexer_destroyData(parser->lexer);
1149 deleteParser(parser);
1150 parser = NULL;
1151 }
1152 return;
1153}