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;
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_SFTime: return (int) sizeof(double); break;
217 case FIELDTYPE_SFBool:
218 case FIELDTYPE_SFInt32: return (int) sizeof(int); break;
219 case FIELDTYPE_SFFloat: return (int) sizeof (float); break;
220 case FIELDTYPE_SFVec2f: return (int) sizeof (struct SFVec2f); break;
221 case FIELDTYPE_SFVec3f:
222 case FIELDTYPE_SFColor: return (int) sizeof (struct SFColor); break;
223 case FIELDTYPE_SFVec3d: return (int) sizeof (struct SFVec3d); break;
224 case FIELDTYPE_SFColorRGBA:
225 case FIELDTYPE_SFRotation:return (int) sizeof (struct SFRotation); break;
226 case FIELDTYPE_SFNode: return (int) ROUTING_SFNODE; break;
227 case FIELDTYPE_SFMatrix3f: return (int) sizeof (struct SFMatrix3f); break;
228 case FIELDTYPE_SFMatrix3d: return (int) sizeof (struct SFMatrix3d); break;
229/* FIXME FIND DEF FOR SFVEC4F */
230// JAS - OLDCODE #ifndef REWIRE
231 case FIELDTYPE_SFVec4f: return (int) sizeof (struct SFVec4f) ; break;
232// JAS - OLDCODE #endif
233 case FIELDTYPE_SFMatrix4f: return (int) sizeof (struct SFMatrix4f); break;
234 case FIELDTYPE_SFVec2d: return (int) sizeof (struct SFVec2d); break;
235 case FIELDTYPE_SFDouble: return (int) sizeof (double); break;
236 case FIELDTYPE_SFVec4d: return (int) sizeof (struct SFVec4d); break;
237
238 case FIELDTYPE_SFString: return (int) ROUTING_SFSTRING; break;
239 case FIELDTYPE_SFImage: return (int) ROUTING_SFIMAGE; break;
240
241 case FIELDTYPE_MFNode: return (int) ROUTING_MFNODE; break;
242 case FIELDTYPE_MFString: return (int) ROUTING_MFSTRING; break;
243 case FIELDTYPE_MFFloat: return (int) ROUTING_MFFLOAT; break;
244 case FIELDTYPE_MFColorRGBA:
245 case FIELDTYPE_MFRotation: return (int) ROUTING_MFROTATION; break;
246 case FIELDTYPE_MFBool:
247 case FIELDTYPE_MFInt32: return (int) ROUTING_MFINT32; break;
248 case FIELDTYPE_MFColor: return (int) ROUTING_MFCOLOR; break;
249 case FIELDTYPE_MFVec2f: return (int) ROUTING_MFVEC2F; break;
250 case FIELDTYPE_MFVec3f: return (int) ROUTING_MFVEC3F; break;
251 case FIELDTYPE_MFVec3d: return (int) ROUTING_MFVEC3D; break;
252 case FIELDTYPE_MFDouble: return (int) ROUTING_MFDOUBLE; break;
253 case FIELDTYPE_MFTime: return (int) ROUTING_MFDOUBLE; break;
254 case FIELDTYPE_MFMatrix4f: return (int) ROUTING_MFMATRIX4F; break;
255 case FIELDTYPE_MFMatrix4d: return (int) ROUTING_MFMATRIX4D; break;
256 case FIELDTYPE_MFVec2d: return (int) ROUTING_MFVEC2D; break;
257 case FIELDTYPE_MFVec4f: return (int) ROUTING_MFVEC4F; break;
258 case FIELDTYPE_MFVec4d: return (int) ROUTING_MFVEC4D; break;
259 case FIELDTYPE_MFMatrix3f: return (int) ROUTING_MFMATRIX3F; break;
260 case FIELDTYPE_MFMatrix3d: return (int) ROUTING_MFMATRIX3D; break;
261
262 default:{
263 printf ("warning - returnRoutingElementLength not a handled type, %d\n",type);
264 }
265 }
266 return (int) sizeof(int);
267}
268
269
270
271/* how many numbers/etc in an array entry? eg, SFVec3f = 3 - 3 floats */
272/* "" "" eg, MFVec3f = 3 - 3 floats, too! */
273int returnElementRowSize (int type) {
274 switch (type) {
275 case FIELDTYPE_SFVec2f:
276 case FIELDTYPE_MFVec2f:
277 case FIELDTYPE_SFVec2d:
278 case FIELDTYPE_MFVec2d:
279 return 2;
280 case FIELDTYPE_SFColor:
281 case FIELDTYPE_MFColor:
282 case FIELDTYPE_SFVec3f:
283 case FIELDTYPE_SFVec3d:
284 case FIELDTYPE_MFVec3f:
285 case FIELDTYPE_MFVec3d:
286 case FIELDTYPE_SFImage: /* initialization - we can have a "0,0,0" for no texture */
287 return 3;
288 case FIELDTYPE_SFRotation:
289 case FIELDTYPE_MFRotation:
290 case FIELDTYPE_SFVec4d:
291 case FIELDTYPE_SFVec4f:
292 case FIELDTYPE_MFVec4d:
293 case FIELDTYPE_MFVec4f:
294 case FIELDTYPE_SFColorRGBA:
295 case FIELDTYPE_MFColorRGBA:
296 return 4;
297 case FIELDTYPE_MFMatrix3f:
298 case FIELDTYPE_SFMatrix3f:
299 case FIELDTYPE_MFMatrix3d:
300 case FIELDTYPE_SFMatrix3d:
301 return 9;
302 case FIELDTYPE_MFMatrix4f:
303 case FIELDTYPE_SFMatrix4f:
304 case FIELDTYPE_MFMatrix4d:
305 case FIELDTYPE_SFMatrix4d:
306 return 16;
307 }
308 return 1;
309
310}
311
312
313
314int mf2sf(int itype){
315 //luckily the fieldtype defines are consistently mf = sf+1
316 //return convertToSFType(itype); //this is more reliable -converts and sf to itself- but bulky
317 if(itype == FIELDTYPE_SFImage)
318 return FIELDTYPE_SFInt32;
319 return itype -1;
320}
321int sf2mf(int itype){
322 //luckily the fieldtype defines are consistently mf = sf+1
323 return itype +1;
324}
325
326/*we seem to be missing something in generated code/structs that would allow me to
327 look up how big something is. I suspect it's ##MACRO-ized elsewhere.
328*/
329
330
331int isSForMFType(int itype){
332 //sadly the fieldtype defines aren't reliably even or odd for sf or mf, so we'll do a switch case
333 //-1 unknown /not a fieldtype
334 //0 SF
335 //1 MF
336 int iret;
337 switch(itype){
338 case FIELDTYPE_SFFloat:
339 case FIELDTYPE_SFRotation:
340 case FIELDTYPE_SFVec3f:
341 case FIELDTYPE_SFBool:
342 case FIELDTYPE_SFInt32:
343 case FIELDTYPE_SFNode:
344 case FIELDTYPE_SFColor:
345 case FIELDTYPE_SFColorRGBA:
346 case FIELDTYPE_SFTime:
347 case FIELDTYPE_SFString:
348 case FIELDTYPE_SFVec2f:
349 //case FIELDTYPE_SFImage:
350 case FIELDTYPE_SFVec3d:
351 case FIELDTYPE_SFDouble:
352 case FIELDTYPE_SFMatrix3f:
353 case FIELDTYPE_SFMatrix3d:
354 case FIELDTYPE_SFMatrix4f:
355 case FIELDTYPE_SFMatrix4d:
356 case FIELDTYPE_SFVec2d:
357 case FIELDTYPE_SFVec4f:
358 case FIELDTYPE_SFVec4d:
359 iret = 0;
360 break;
361
362 case FIELDTYPE_MFFloat:
363 case FIELDTYPE_MFRotation:
364 case FIELDTYPE_MFVec3f:
365 case FIELDTYPE_MFBool:
366 case FIELDTYPE_MFInt32:
367 case FIELDTYPE_MFNode:
368 case FIELDTYPE_MFColor:
369 case FIELDTYPE_MFColorRGBA:
370 case FIELDTYPE_MFTime:
371 case FIELDTYPE_MFString:
372 case FIELDTYPE_MFVec2f:
373 case FIELDTYPE_SFImage: //
374 case FIELDTYPE_MFVec3d:
375 case FIELDTYPE_MFDouble:
376 case FIELDTYPE_MFMatrix3f:
377 case FIELDTYPE_MFMatrix3d:
378 case FIELDTYPE_MFMatrix4f:
379 case FIELDTYPE_MFMatrix4d:
380 case FIELDTYPE_MFVec2d:
381 case FIELDTYPE_MFVec4f:
382 case FIELDTYPE_MFVec4d:
383 iret = 1; break;
384 default:
385 iret = -1; break;
386 }
387 return iret;
388}
389int type2SF(int itype){
390 //unconditionally returns sf type
391 int jtype, sformf = isSForMFType(itype);
392 if(sformf < 0) return -1;
393 jtype = itype;
394 if(sformf == 1) jtype = mf2sf(itype);
395 return jtype;
396}
397int isSFType(int itype){
398 return (isSForMFType(itype) == 0) ? 1 : 0;
399}
400#define FIELDTYPE_MFImage 43
401int sizeofSForMF(int itype){
402 //goal get the offset for MF.p[i] in bytes
403 //or also this is the 'shallow size' for field copying
404 int iz;
405 switch(itype){
406 case FIELDTYPE_SFFloat: iz = sizeof(float); break;
407 case FIELDTYPE_SFRotation: iz = sizeof(struct SFRotation); break;
408 case FIELDTYPE_SFVec3f: iz = sizeof(struct SFVec3f);break;
409 case FIELDTYPE_SFBool: iz = sizeof(int); break;
410 case FIELDTYPE_SFInt32: iz = sizeof(int); break;
411 case FIELDTYPE_SFNode: iz = sizeof(void*); break;
412 case FIELDTYPE_SFColor: iz = sizeof(struct SFColor); break;
413 case FIELDTYPE_SFColorRGBA: iz = sizeof(struct SFColorRGBA); break;
414 case FIELDTYPE_SFTime: iz = sizeof(double); break;
415 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
416 case FIELDTYPE_SFVec2f: iz = sizeof(struct SFVec2f); break;
417 //case FIELDTYPE_SFImage: iz = sizeof(void*); break;
418 case FIELDTYPE_SFVec3d: iz = sizeof(struct SFVec3d); break;
419 case FIELDTYPE_SFDouble: iz = sizeof(double); break;
420 case FIELDTYPE_SFMatrix3f: iz = sizeof(struct SFMatrix3f); break;
421 case FIELDTYPE_SFMatrix3d: iz = sizeof(struct SFMatrix3d); break;
422 case FIELDTYPE_SFMatrix4f: iz = sizeof(struct SFMatrix4f); break;
423 case FIELDTYPE_SFMatrix4d: iz = sizeof(struct SFMatrix4d); break;
424 case FIELDTYPE_SFVec2d: iz = sizeof(struct SFVec2d); break;
425 case FIELDTYPE_SFVec4f: iz = sizeof(struct SFVec4f); break;
426 case FIELDTYPE_SFVec4d: iz = sizeof(struct SFVec4d); break;
427
428 case FIELDTYPE_SFImage: //same as MFInt32
429 case FIELDTYPE_MFFloat:
430 case FIELDTYPE_MFRotation:
431 case FIELDTYPE_MFVec3f:
432 case FIELDTYPE_MFBool:
433 case FIELDTYPE_MFInt32:
434 case FIELDTYPE_MFNode:
435 case FIELDTYPE_MFColor:
436 case FIELDTYPE_MFColorRGBA:
437 case FIELDTYPE_MFTime:
438 case FIELDTYPE_MFString:
439 case FIELDTYPE_MFVec2f:
440 case FIELDTYPE_MFImage:
441 case FIELDTYPE_MFVec3d:
442 case FIELDTYPE_MFDouble:
443 case FIELDTYPE_MFMatrix3f:
444 case FIELDTYPE_MFMatrix3d:
445 case FIELDTYPE_MFMatrix4f:
446 case FIELDTYPE_MFMatrix4d:
447 case FIELDTYPE_MFVec2d:
448 case FIELDTYPE_MFVec4f:
449 case FIELDTYPE_MFVec4d:
450 iz = sizeof(struct Multi_Node);
451 break;
452 default:
453 //unknown
454 iz = sizeof(void*);
455 break;
456 }
457 return iz;
458}
459int sizeofSF(int itype){
460 int jtype;
461 int sformf = isSForMFType(itype);
462 if( sformf < 0) return 0;
463 jtype = itype;
464 if( sformf == 1 ) jtype = mf2sf(itype);
465 return sizeofSForMF(jtype);
466}
467
468
469//static struct VRMLParser *parser = NULL;
470
471/* from the XML parser, for instance, we can call this on close to delete memory and memory tables */
472void Parser_deleteParserForScanStringValueToMem(void) {
473 ppEAI_C_CommonFunctions p = (ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv;
474 if (p==NULL) return;
475 if (p->parser != NULL) {
476 lexer_destroyData(p->parser->lexer);
477 deleteParser(p->parser);
478 p->parser = NULL;
479 }
480}
481
482
483void Parser_scanStringValueToMem(struct X3D_Node *node, size_t coffset, indexT ctype, char *value, int isXML) {
484 void *nst; /* used for pointer maths */
485 union anyVrml myVal;
486 char *mfstringtmp = NULL;
487 int oldXMLflag;
488 struct X3D_Node *np;
489 struct VRMLParser *parser = ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser;
490 #ifdef SETFIELDVERBOSE
491 printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
492 #endif
493 np = NULL;
494 /* if this is the first time through, create a new parser, and tell it:
495 - that we are using X3D formatted field strings, NOT "VRML" ones;
496 - that the destination node is not important (the NULL, offset 0) */
497
498 if (parser == NULL) {
499 parser=newParser(NULL,NULL, 0, TRUE);
500 //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
501 // save it
502 ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser = parser;
503 }
504
505 lexer_forceStringCleanup(parser->lexer);
506
507 /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
508 have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
509
510 if (isXML) {
511 /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
512 if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
513 /* printf ("returning\n"); */
514 lexer_forceStringCleanup(parser->lexer);
515 return;
516 }
517
518 }
519
520 /* there is a difference sometimes, in the XML format and VRML classic format. The XML
521 parser will use xml format, scripts and EAI will use the classic format */
522 oldXMLflag = parser->parsingX3DfromXML;
523 parser->parsingX3DfromXML = isXML;
524
525 /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
526 if (ctype == FIELDTYPE_MFString) {
527 #ifdef SETFIELDVERBOSE
528 printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
529 #endif
530
531 /* go to the first non-space character, and see if this is required;
532 sometimes people will encode mfstrings as:
533 url=' "images/earth.gif" "http://ww
534 note the space in the value */
535 while ((*value == ' ') && (*value != '\0')) value ++;
536
537 /* now, does the value string need quoting? */
538 if ((*value != '"') && (*value != '\'') && (*value != '[')) {
539 size_t len;
540 /* printf ("have to quote this string\n"); */
541 len = strlen(value);
542 mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
543 memcpy (&mfstringtmp[1],value,len);
544 mfstringtmp[0] = '"';
545 mfstringtmp[len+1] = '"';
546 mfstringtmp[len+2] = '\0';
547 /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
548
549 } else {
550 mfstringtmp = STRDUP(value);
551 }
552 parser_fromString(parser,mfstringtmp);
553 /* FREE_IF_NZ(mfstringtmp); */
554 } else if (ctype == FIELDTYPE_SFNode) {
555 /* Need to change index to proper node ptr */
556 np = getEAINodeFromTable(atoi(value), -1);
557 } else if (ctype == FIELDTYPE_SFString) {
558 if(isXML){
559 /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
560 int nq = 0;
561 char *mv, *pv, *v = value;
562 while (*v && *v != '\0')
563 {
564 if(*v == '"') nq++;
565 v++;
566 }
567 mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
568 v = value;
569 pv = NULL;
570 mv = mfstringtmp;
571 while(*v && *v != '\0')
572 {
573 if(*v == '"'){
574 if(!(pv && *pv == '\\')){
575 *mv = '\\';
576 mv++;
577 }
578 }
579 *mv = *v;
580 mv++;
581 pv = v;
582 v++;
583 }
584 *mv = '\0';
585 }else{
586 mfstringtmp = STRDUP(value);
587 }
588 parser_fromString(parser,mfstringtmp);
589 } else {
590 mfstringtmp = STRDUP(value);
591 parser_fromString(parser,mfstringtmp);
592 /* FREE_IF_NZ(mfstringtmp); */
593 }
594
595 ASSERT(parser->lexer);
596 FREE_IF_NZ(parser->lexer->curID);
597
598 if (ctype == FIELDTYPE_SFNode) {
599 struct X3D_Node* oldvalue;
600 nst = offsetPointer_deref(void *,node,coffset);
601 memcpy (&oldvalue, nst, sizeof(struct X3D_Node*));
602 if (oldvalue) {
603 remove_parent(oldvalue, node);
604 }
605 if(np){
606 memcpy(nst, (void*)&np, sizeof(struct X3D_Node*));
607 add_parent(np, node, "sarah's add", 0);
608 }
609 } else if (parseType(parser, ctype, &myVal)) {
610 /* printf ("parsed successfully\n"); */
611 nst = offsetPointer_deref(void *,node,coffset);
612
613
614/*
615MF_TYPE(MFNode, mfnode, Node)
616*/
617 switch (ctype) {
618
619 PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
620 PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
621 PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
622 PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
623 PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
624 PST_MF_STRUCT_ELEMENT(Color,color)
625 PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
626 PST_MF_STRUCT_ELEMENT(Int32,int32)
627 PST_MF_STRUCT_ELEMENT(Float,float)
628 PST_MF_STRUCT_ELEMENT(Double,double)
629 PST_MF_STRUCT_ELEMENT(Bool,bool)
630 PST_MF_STRUCT_ELEMENT(Time,time)
631 PST_MF_STRUCT_ELEMENT(Rotation,rotation)
632 PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
633 PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
634 PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
635 PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
636 PST_MF_STRUCT_ELEMENT(String,string)
637
638 PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
639 PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
640 PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
641 PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
642 PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
643 PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
644 PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
645 PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
646 PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
647 PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
648 PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
649 PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
650 PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
651 PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
652 PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
653 PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
654 PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
655 PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
656 PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
657 PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
658
659 case FIELDTYPE_SFString: {
660 //struct Uni_String *mptr;
661 memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
662 //mptr = * (struct Uni_String **)nst;
663 //if (!mptr) {
664 // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
665 //} else {
666 // FREE_IF_NZ(mptr->strptr);
667 // mptr->strptr = myVal.sfstring->strptr;
668 // mptr->len = myVal.sfstring->len;
669 // mptr->touched = myVal.sfstring->touched;
670 //}
671 break; }
672
673 default: {
674 printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
675 lexer_forceStringCleanup(parser->lexer);
676 return;
677 }
678 }
679
680 } else {
681 if (strlen (value) > 50) {
682 value[45] = '.';
683 value[46] = '.';
684 value[47] = '.';
685 value[48] = '\0';
686 }
687 ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
688 }
689
690 /* tell the parser that we have done with the input - it will FREE the data */
691 lexer_forceStringCleanup(parser->lexer);
692
693 /* and, reset the XML flag */
694 parser->parsingX3DfromXML = oldXMLflag;
695}
696
697
698void Parser_scanStringValueToMem_B(union anyVrml* any, indexT ctype, char *value, int isXML)
699{
700 //dug9 Feb 2013: same as Parser_scanStringValueToMem except:
701 // - puts it into *anyVrml instead of (node,offset)
702 // - doesn't update parents for SFNode, MFNode fields (just zeros it) - that's done outside
703 void *nst; /* used for pointer maths */
704 union anyVrml myVal;
705 char *mfstringtmp = NULL;
706 int oldXMLflag;
707 struct X3D_Node *np = NULL;
708 struct VRMLParser *parser = ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser;
709 #ifdef SETFIELDVERBOSE
710 printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
711 #endif
712
713 /* if this is the first time through, create a new parser, and tell it:
714 - that we are using X3D formatted field strings, NOT "VRML" ones;
715 - that the destination node is not important (the NULL, offset 0) */
716
717 if (parser == NULL) {
718 parser=newParser(NULL,NULL, 0, TRUE);
719 //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
720 // save it
721 ((ppEAI_C_CommonFunctions)gglobal()->EAI_C_CommonFunctions.prv)->parser = parser;
722 }
723
724 lexer_forceStringCleanup(parser->lexer);
725
726 /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
727 have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
728
729 if (isXML) {
730 /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
731 if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
732 /* printf ("returning\n"); */
733 lexer_forceStringCleanup(parser->lexer);
734 return;
735 }
736
737 }
738
739 /* there is a difference sometimes, in the XML format and VRML classic format. The XML
740 parser will use xml format, scripts and EAI will use the classic format */
741 oldXMLflag = parser->parsingX3DfromXML;
742 parser->parsingX3DfromXML = isXML;
743
744 /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
745 if (ctype == FIELDTYPE_MFString) {
746 #ifdef SETFIELDVERBOSE
747 printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
748 #endif
749
750 /* go to the first non-space character, and see if this is required;
751 sometimes people will encode mfstrings as:
752 url=' "images/earth.gif" "http://ww
753 note the space in the value */
754 while ((*value == ' ') && (*value != '\0')) value ++;
755
756 /* now, does the value string need quoting? */
757 if ((*value != '"') && (*value != '\'') && (*value != '[')) {
758 static int MFS_warning_given = 0;
759 size_t len;
760 /* printf ("have to quote this string\n"); */
761 len = strlen(value);
762 mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
763 memcpy (&mfstringtmp[1],value,len);
764 mfstringtmp[0] = '"';
765 mfstringtmp[len+1] = '"';
766 mfstringtmp[len+2] = '\0';
767 if(0) if(!MFS_warning_given){
768 ConsoleMessage("Warning - an MFString needs internal quotes ie '%s' should be '%s'\n",value,mfstringtmp);
769 MFS_warning_given = 1;
770 }
771 /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
772
773 } else {
774 mfstringtmp = STRDUP(value);
775 }
776 parser_fromString(parser,mfstringtmp);
777 /* FREE_IF_NZ(mfstringtmp); */
778 } else if (ctype == FIELDTYPE_SFNode) {
779 /* Need to change index to proper node ptr */
780 np = getEAINodeFromTable(atoi(value), -1);
781 } else if (ctype == FIELDTYPE_SFString) {
782 if(isXML){
783 /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
784 int nq = 0;
785 char *mv, *pv, *v = value;
786 while (*v && *v != '\0')
787 {
788 if(*v == '"') nq++;
789 v++;
790 }
791 mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
792 v = value;
793 pv = NULL;
794 mv = mfstringtmp;
795 while(*v && *v != '\0')
796 {
797 if(*v == '"'){
798 if(!(pv && *pv == '\\')){
799 *mv = '\\';
800 mv++;
801 }
802 }
803 *mv = *v;
804 mv++;
805 pv = v;
806 v++;
807 }
808 *mv = '\0';
809 }else{
810 mfstringtmp = STRDUP(value);
811 }
812 parser_fromString(parser,mfstringtmp);
813 } else {
814 mfstringtmp = STRDUP(value);
815 parser_fromString(parser,mfstringtmp);
816 /* FREE_IF_NZ(mfstringtmp); */
817 }
818
819 ASSERT(parser->lexer);
820 FREE_IF_NZ(parser->lexer->curID);
821
822 if (ctype == FIELDTYPE_SFNode) {
823 //struct X3D_Node* oldvalue;
824 //nst = offsetPointer_deref(void *,node,coffset);
825 //memcpy (&oldvalue, any, sizeof(struct X3D_Node*));
826 //if (oldvalue) {
827 // remove_parent(oldvalue, node);
828 //}
829 memcpy(any, (void*)&np, sizeof(struct X3D_Node*));
830 any->sfnode->_parentVector = NULL;
831 //add_parent(np, node, "sarah's add", 0);
832 } else if (parseType(parser, ctype, &myVal)) {
833 /* printf ("parsed successfully\n"); */
834 //nst = offsetPointer_deref(void *,node,coffset);
835 nst = any;
836
837/*
838MF_TYPE(MFNode, mfnode, Node)
839*/
840 switch (ctype) {
841
842 PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
843 PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
844 PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
845 PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
846 PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
847 PST_MF_STRUCT_ELEMENT(Color,color)
848 PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
849 PST_MF_STRUCT_ELEMENT(Int32,int32)
850 PST_MF_STRUCT_ELEMENT(Float,float)
851 PST_MF_STRUCT_ELEMENT(Double,double)
852 PST_MF_STRUCT_ELEMENT(Bool,bool)
853 PST_MF_STRUCT_ELEMENT(Time,time)
854 PST_MF_STRUCT_ELEMENT(Rotation,rotation)
855 PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
856 PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
857 PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
858 PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
859 PST_MF_STRUCT_ELEMENT(String,string)
860
861 PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
862 PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
863 PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
864 PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
865 PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
866 PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
867 PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
868 PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
869 PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
870 PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
871 PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
872 PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
873 PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
874 PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
875 PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
876 PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
877 PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
878 PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
879 PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
880 PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
881
882 case FIELDTYPE_SFString: {
883 //struct Uni_String *mptr;
884 memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
885 //mptr = * (struct Uni_String **)nst;
886 //if (!mptr) {
887 // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
888 //} else {
889 // FREE_IF_NZ(mptr->strptr);
890 // mptr->strptr = myVal.sfstring->strptr;
891 // mptr->len = myVal.sfstring->len;
892 // mptr->touched = myVal.sfstring->touched;
893 //}
894 break; }
895
896 default: {
897 printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
898 lexer_forceStringCleanup(parser->lexer);
899 return;
900 }
901 }
902
903 } else {
904 if (strlen (value) > 50) {
905 value[45] = '.';
906 value[46] = '.';
907 value[47] = '.';
908 value[48] = '\0';
909 }
910 ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
911 }
912
913 /* tell the parser that we have done with the input - it will FREE the data */
914 lexer_forceStringCleanup(parser->lexer);
915
916 FREE_IF_NZ(mfstringtmp);
917
918 /* and, reset the XML flag */
919 parser->parsingX3DfromXML = oldXMLflag;
920}
921
922void Parser_scanStringValueToMem_C0(struct VRMLParser *parser, union anyVrml* any, indexT ctype, char *value, int isXML)
923{
924 //dug9 Apr 2013: same as Parser_scanStringValueToMemB except:
925 // - you create or remember your parser* outside, so no static or gglobal in here, so can be called from libeai.
926 // - puts it into *anyVrml instead of (node,offset)
927 // - doesn't update parents for SFNode, MFNode fields (just zeros it) - that's done outside
928 void *nst; /* used for pointer maths */
929 union anyVrml myVal;
930 char *mfstringtmp = NULL;
931 int oldXMLflag;
932 struct X3D_Node *np;
933 #ifdef SETFIELDVERBOSE
934 printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
935 #endif
936
937 /* if this is the first time through, create a new parser, and tell it:
938 - that we are using X3D formatted field strings, NOT "VRML" ones;
939 - that the destination node is not important (the NULL, offset 0) */
940
941 if (parser == NULL) {
942 parser=newParser(NULL,NULL, 0, TRUE);
943 //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
944 }
945
946 lexer_forceStringCleanup(parser->lexer);
947
948 /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
949 have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
950
951 if (isXML) {
952 /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
953 if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
954 /* printf ("returning\n"); */
955 lexer_forceStringCleanup(parser->lexer);
956 return;
957 }
958
959 }
960
961 /* there is a difference sometimes, in the XML format and VRML classic format. The XML
962 parser will use xml format, scripts and EAI will use the classic format */
963 oldXMLflag = parser->parsingX3DfromXML;
964 parser->parsingX3DfromXML = isXML;
965
966 /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
967 if (ctype == FIELDTYPE_MFString) {
968 #ifdef SETFIELDVERBOSE
969 printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
970 #endif
971
972 /* go to the first non-space character, and see if this is required;
973 sometimes people will encode mfstrings as:
974 url=' "images/earth.gif" "http://ww
975 note the space in the value */
976 while ((*value == ' ') && (*value != '\0')) value ++;
977
978 /* now, does the value string need quoting? */
979 if ((*value != '"') && (*value != '\'') && (*value != '[')) {
980 size_t len;
981 /* printf ("have to quote this string\n"); */
982 len = strlen(value);
983 mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
984 memcpy (&mfstringtmp[1],value,len);
985 mfstringtmp[0] = '"';
986 mfstringtmp[len+1] = '"';
987 mfstringtmp[len+2] = '\0';
988 /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
989
990 } else {
991 mfstringtmp = STRDUP(value);
992 }
993 parser_fromString(parser,mfstringtmp);
994 /* FREE_IF_NZ(mfstringtmp); */
995 } else if (ctype == FIELDTYPE_SFNode) {
996 /* Need to change index to proper node ptr */
997 np = getEAINodeFromTable(atoi(value), -1);
998 } else if (ctype == FIELDTYPE_SFString) {
999 if(isXML){
1000 /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
1001 int nq = 0;
1002 char *mv, *pv, *v = value;
1003 while (*v && *v != '\0')
1004 {
1005 if(*v == '"') nq++;
1006 v++;
1007 }
1008 mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
1009 v = value;
1010 pv = NULL;
1011 mv = mfstringtmp;
1012 while(*v && *v != '\0')
1013 {
1014 if(*v == '"'){
1015 if(!(pv && *pv == '\\')){
1016 *mv = '\\';
1017 mv++;
1018 }
1019 }
1020 *mv = *v;
1021 mv++;
1022 pv = v;
1023 v++;
1024 }
1025 *mv = '\0';
1026 }else{
1027 mfstringtmp = STRDUP(value);
1028 }
1029 parser_fromString(parser,mfstringtmp);
1030 } else {
1031 mfstringtmp = STRDUP(value);
1032 parser_fromString(parser,mfstringtmp);
1033 /* FREE_IF_NZ(mfstringtmp); */
1034 }
1035
1036 ASSERT(parser->lexer);
1037 FREE_IF_NZ(parser->lexer->curID);
1038
1039 if (ctype == FIELDTYPE_SFNode) {
1040 //struct X3D_Node* oldvalue;
1041 //nst = offsetPointer_deref(void *,node,coffset);
1042 //memcpy (&oldvalue, any, sizeof(struct X3D_Node*));
1043 //if (oldvalue) {
1044 // remove_parent(oldvalue, node);
1045 //}
1046 memcpy(any, (void*)&np, sizeof(struct X3D_Node*));
1047 any->sfnode->_parentVector = NULL;
1048 //add_parent(np, node, "sarah's add", 0);
1049 } else if (parseType(parser, ctype, &myVal)) {
1050 /* printf ("parsed successfully\n"); */
1051 //nst = offsetPointer_deref(void *,node,coffset);
1052 nst = any;
1053
1054/*
1055MF_TYPE(MFNode, mfnode, Node)
1056*/
1057 switch (ctype) {
1058
1059 PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
1060 PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
1061 PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
1062 PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
1063 PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
1064 PST_MF_STRUCT_ELEMENT(Color,color)
1065 PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
1066 PST_MF_STRUCT_ELEMENT(Int32,int32)
1067 PST_MF_STRUCT_ELEMENT(Float,float)
1068 PST_MF_STRUCT_ELEMENT(Double,double)
1069 PST_MF_STRUCT_ELEMENT(Bool,bool)
1070 PST_MF_STRUCT_ELEMENT(Time,time)
1071 PST_MF_STRUCT_ELEMENT(Rotation,rotation)
1072 PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
1073 PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
1074 PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
1075 PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
1076 PST_MF_STRUCT_ELEMENT(String,string)
1077
1078 PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
1079 PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
1080 PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
1081 PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
1082 PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
1083 PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
1084 PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
1085 PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
1086 PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
1087 PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
1088 PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
1089 PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
1090 PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
1091 PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
1092 PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
1093 PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
1094 PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
1095 PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
1096 PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
1097 PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
1098
1099 case FIELDTYPE_SFString: {
1100 //struct Uni_String *mptr;
1101 memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
1102 //mptr = * (struct Uni_String **)nst;
1103 //if (!mptr) {
1104 // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
1105 //} else {
1106 // FREE_IF_NZ(mptr->strptr);
1107 // mptr->strptr = myVal.sfstring->strptr;
1108 // mptr->len = myVal.sfstring->len;
1109 // mptr->touched = myVal.sfstring->touched;
1110 //}
1111 break; }
1112
1113 default: {
1114 printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
1115 lexer_forceStringCleanup(parser->lexer);
1116 return;
1117 }
1118 }
1119
1120 } else {
1121 if (strlen (value) > 50) {
1122 value[45] = '.';
1123 value[46] = '.';
1124 value[47] = '.';
1125 value[48] = '\0';
1126 }
1127 ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
1128 }
1129
1130 /* tell the parser that we have done with the input - it will FREE the data */
1131 lexer_forceStringCleanup(parser->lexer);
1132
1133 /* and, reset the XML flag */
1134 parser->parsingX3DfromXML = oldXMLflag;
1135}
1136void Parser_scanStringValueToMem_C(void *any0, int ctype0, char *value, int isXML)
1137//void Parser_scanStringValueToMem_C(union anyVrml* any, indexT ctype, char *value, int isXML)
1138{
1139 struct VRMLParser *parser;
1140 union anyVrml* any;
1141 indexT ctype;
1142 any = (union anyVrml*)any0;
1143 ctype = (indexT)ctype0;
1144 parser=newParser(NULL,NULL, 0, TRUE);
1145 Parser_scanStringValueToMem_C0(parser, any, ctype, value, isXML);
1146 if (parser != NULL) {
1147 lexer_destroyData(parser->lexer);
1148 deleteParser(parser);
1149 parser = NULL;
1150 }
1151 return;
1152}