FreeWRL/FreeX3D  3.0.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;
53 typedef struct pEAI_C_CommonFunctions{
54  struct VRMLParser *parser; // = NULL;
56 void *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 
63 void 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 */
89 struct Uni_String *newASCIIString(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  strncpy(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 
114 void clearASCIIString(struct Uni_String *us);
115 void freeASCIIString(struct Uni_String *us);
116 void clearMFString(struct Multi_String *ms);
117 void freeMFString(struct Multi_String **ms);
118 
119 void clearASCIIString(struct Uni_String *us){
120  if(us){
121  FREE_IF_NZ(us->strptr);
122  us->strptr = NULL;
123  us->len = 0;
124  }
125 }
126 void freeASCIIString(struct Uni_String *us){
127  clearASCIIString(us);
128  FREE_IF_NZ(us);
129 }
130 void 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 }
143 void 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
149 touch the touched flag */
150 void verify_Uni_String(struct Uni_String *unis, 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 (strcmp(str,unis->strptr)!= 0) {
164  os = unis->strptr;
165  len = strlen(str);
166  ns = MALLOC (char *,len+1);
167  strncpy(ns,str,len+1);
168  unis->strptr = ns;
169  FREE_IF_NZ (os);
170  unis->touched++;
171  }
172 }
173 
174 
175 
176 
177 /* get how many bytes in the type */
178 int returnElementLength(int type) {
179  switch (type) {
180  case FIELDTYPE_SFVec2d:
181  case FIELDTYPE_MFVec2d:
182  case FIELDTYPE_MFVec3d:
183  case FIELDTYPE_SFVec3d:
184  case FIELDTYPE_MFDouble:
185  case FIELDTYPE_SFDouble:
186  case FIELDTYPE_SFVec4d:
187  case FIELDTYPE_MFVec4d:
188  case FIELDTYPE_SFMatrix3d:
189  case FIELDTYPE_MFMatrix3d:
190  case FIELDTYPE_SFMatrix4d:
191  case FIELDTYPE_MFMatrix4d:
192  case FIELDTYPE_SFTime :
193  case FIELDTYPE_MFTime : return (int) sizeof(double); break;
194  case FIELDTYPE_SFImage:
195  case FIELDTYPE_MFInt32: return (int) sizeof(int) ; break;
196  case FIELDTYPE_FreeWRLPTR:
197  case FIELDTYPE_MFString:
198  case FIELDTYPE_SFString:
199  case FIELDTYPE_SFNode :
200  case FIELDTYPE_MFNode : return (int) sizeof(void *); break;
201  default : {}
202  }
203  return (int) sizeof(float) ; /* turn into byte count */
204 }
205 
206 /* for passing into CRoutes/CRoutes_Register */
207 /* lengths are either positive numbers, or, if there is a complex type, a negative number. If positive,
208  in routing a memcpy is performed; if negative, then some inquiry is required to get correct length
209  of both source/dest during routing. */
210 
211 int returnRoutingElementLength(int type) {
212  switch (type) {
213  case FIELDTYPE_SFTime: return (int) sizeof(double); break;
214  case FIELDTYPE_SFBool:
215  case FIELDTYPE_SFInt32: return (int) sizeof(int); break;
216  case FIELDTYPE_SFFloat: return (int) sizeof (float); break;
217  case FIELDTYPE_SFVec2f: return (int) sizeof (struct SFVec2f); break;
218  case FIELDTYPE_SFVec3f:
219  case FIELDTYPE_SFColor: return (int) sizeof (struct SFColor); break;
220  case FIELDTYPE_SFVec3d: return (int) sizeof (struct SFVec3d); break;
221  case FIELDTYPE_SFColorRGBA:
222  case FIELDTYPE_SFRotation:return (int) sizeof (struct SFRotation); break;
223  case FIELDTYPE_SFNode: return (int) ROUTING_SFNODE; break;
224  case FIELDTYPE_SFMatrix3f: return (int) sizeof (struct SFMatrix3f); break;
225  case FIELDTYPE_SFMatrix3d: return (int) sizeof (struct SFMatrix3d); break;
226 /* FIXME FIND DEF FOR SFVEC4F */
227 // JAS - OLDCODE #ifndef REWIRE
228  case FIELDTYPE_SFVec4f: return (int) sizeof (struct SFVec4f) ; break;
229 // JAS - OLDCODE #endif
230  case FIELDTYPE_SFMatrix4f: return (int) sizeof (struct SFMatrix4f); break;
231  case FIELDTYPE_SFVec2d: return (int) sizeof (struct SFVec2d); break;
232  case FIELDTYPE_SFDouble: return (int) sizeof (double); break;
233  case FIELDTYPE_SFVec4d: return (int) sizeof (struct SFVec4d); break;
234 
235  case FIELDTYPE_SFString: return (int) ROUTING_SFSTRING; break;
236  case FIELDTYPE_SFImage: return (int) ROUTING_SFIMAGE; break;
237 
238  case FIELDTYPE_MFNode: return (int) ROUTING_MFNODE; break;
239  case FIELDTYPE_MFString: return (int) ROUTING_MFSTRING; break;
240  case FIELDTYPE_MFFloat: return (int) ROUTING_MFFLOAT; break;
241  case FIELDTYPE_MFColorRGBA:
242  case FIELDTYPE_MFRotation: return (int) ROUTING_MFROTATION; break;
243  case FIELDTYPE_MFBool:
244  case FIELDTYPE_MFInt32: return (int) ROUTING_MFINT32; break;
245  case FIELDTYPE_MFColor: return (int) ROUTING_MFCOLOR; break;
246  case FIELDTYPE_MFVec2f: return (int) ROUTING_MFVEC2F; break;
247  case FIELDTYPE_MFVec3f: return (int) ROUTING_MFVEC3F; break;
248  case FIELDTYPE_MFVec3d: return (int) ROUTING_MFVEC3D; break;
249  case FIELDTYPE_MFDouble: return (int) ROUTING_MFDOUBLE; break;
250  case FIELDTYPE_MFTime: return (int) ROUTING_MFDOUBLE; break;
251  case FIELDTYPE_MFMatrix4f: return (int) ROUTING_MFMATRIX4F; break;
252  case FIELDTYPE_MFMatrix4d: return (int) ROUTING_MFMATRIX4D; break;
253  case FIELDTYPE_MFVec2d: return (int) ROUTING_MFVEC2D; break;
254  case FIELDTYPE_MFVec4f: return (int) ROUTING_MFVEC4F; break;
255  case FIELDTYPE_MFVec4d: return (int) ROUTING_MFVEC4D; break;
256  case FIELDTYPE_MFMatrix3f: return (int) ROUTING_MFMATRIX3F; break;
257  case FIELDTYPE_MFMatrix3d: return (int) ROUTING_MFMATRIX3D; break;
258 
259  default:{
260  printf ("warning - returnRoutingElementLength not a handled type, %d\n",type);
261  }
262  }
263  return (int) sizeof(int);
264 }
265 
266 
267 
268 /* how many numbers/etc in an array entry? eg, SFVec3f = 3 - 3 floats */
269 /* "" "" eg, MFVec3f = 3 - 3 floats, too! */
270 int returnElementRowSize (int type) {
271  switch (type) {
272  case FIELDTYPE_SFVec2f:
273  case FIELDTYPE_MFVec2f:
274  case FIELDTYPE_SFVec2d:
275  case FIELDTYPE_MFVec2d:
276  return 2;
277  case FIELDTYPE_SFColor:
278  case FIELDTYPE_MFColor:
279  case FIELDTYPE_SFVec3f:
280  case FIELDTYPE_SFVec3d:
281  case FIELDTYPE_MFVec3f:
282  case FIELDTYPE_MFVec3d:
283  case FIELDTYPE_SFImage: /* initialization - we can have a "0,0,0" for no texture */
284  return 3;
285  case FIELDTYPE_SFRotation:
286  case FIELDTYPE_MFRotation:
287  case FIELDTYPE_SFVec4d:
288  case FIELDTYPE_SFVec4f:
289  case FIELDTYPE_MFVec4d:
290  case FIELDTYPE_MFVec4f:
291  case FIELDTYPE_SFColorRGBA:
292  case FIELDTYPE_MFColorRGBA:
293  return 4;
294  case FIELDTYPE_MFMatrix3f:
295  case FIELDTYPE_SFMatrix3f:
296  case FIELDTYPE_MFMatrix3d:
297  case FIELDTYPE_SFMatrix3d:
298  return 9;
299  case FIELDTYPE_MFMatrix4f:
300  case FIELDTYPE_SFMatrix4f:
301  case FIELDTYPE_MFMatrix4d:
302  case FIELDTYPE_SFMatrix4d:
303  return 16;
304  }
305  return 1;
306 
307 }
308 
309 
310 
311 int mf2sf(int itype){
312  //luckily the fieldtype defines are consistently mf = sf+1
313  //return convertToSFType(itype); //this is more reliable -converts and sf to itself- but bulky
314  if(itype == FIELDTYPE_SFImage)
315  return FIELDTYPE_SFInt32;
316  return itype -1;
317 }
318 int sf2mf(int itype){
319  //luckily the fieldtype defines are consistently mf = sf+1
320  return itype +1;
321 }
322 
323 /*we seem to be missing something in generated code/structs that would allow me to
324  look up how big something is. I suspect it's ##MACRO-ized elsewhere.
325 */
326 
327 
328 int isSForMFType(int itype){
329  //sadly the fieldtype defines aren't reliably even or odd for sf or mf, so we'll do a switch case
330  //-1 unknown /not a fieldtype
331  //0 SF
332  //1 MF
333  int iret;
334  switch(itype){
335  case FIELDTYPE_SFFloat:
336  case FIELDTYPE_SFRotation:
337  case FIELDTYPE_SFVec3f:
338  case FIELDTYPE_SFBool:
339  case FIELDTYPE_SFInt32:
340  case FIELDTYPE_SFNode:
341  case FIELDTYPE_SFColor:
342  case FIELDTYPE_SFColorRGBA:
343  case FIELDTYPE_SFTime:
344  case FIELDTYPE_SFString:
345  case FIELDTYPE_SFVec2f:
346  //case FIELDTYPE_SFImage:
347  case FIELDTYPE_SFVec3d:
348  case FIELDTYPE_SFDouble:
349  case FIELDTYPE_SFMatrix3f:
350  case FIELDTYPE_SFMatrix3d:
351  case FIELDTYPE_SFMatrix4f:
352  case FIELDTYPE_SFMatrix4d:
353  case FIELDTYPE_SFVec2d:
354  case FIELDTYPE_SFVec4f:
355  case FIELDTYPE_SFVec4d:
356  iret = 0;
357  break;
358 
359  case FIELDTYPE_MFFloat:
360  case FIELDTYPE_MFRotation:
361  case FIELDTYPE_MFVec3f:
362  case FIELDTYPE_MFBool:
363  case FIELDTYPE_MFInt32:
364  case FIELDTYPE_MFNode:
365  case FIELDTYPE_MFColor:
366  case FIELDTYPE_MFColorRGBA:
367  case FIELDTYPE_MFTime:
368  case FIELDTYPE_MFString:
369  case FIELDTYPE_MFVec2f:
370  case FIELDTYPE_SFImage: //
371  case FIELDTYPE_MFVec3d:
372  case FIELDTYPE_MFDouble:
373  case FIELDTYPE_MFMatrix3f:
374  case FIELDTYPE_MFMatrix3d:
375  case FIELDTYPE_MFMatrix4f:
376  case FIELDTYPE_MFMatrix4d:
377  case FIELDTYPE_MFVec2d:
378  case FIELDTYPE_MFVec4f:
379  case FIELDTYPE_MFVec4d:
380  iret = 1; break;
381  default:
382  iret = -1; break;
383  }
384  return iret;
385 }
386 int type2SF(int itype){
387  //unconditionally returns sf type
388  int jtype, sformf = isSForMFType(itype);
389  if(sformf < 0) return -1;
390  jtype = itype;
391  if(sformf == 1) jtype = mf2sf(itype);
392  return jtype;
393 }
394 int isSFType(int itype){
395  return (isSForMFType(itype) == 0) ? 1 : 0;
396 }
397 #define FIELDTYPE_MFImage 43
398 int sizeofSForMF(int itype){
399  //goal get the offset for MF.p[i] in bytes
400  //or also this is the 'shallow size' for field copying
401  int iz;
402  switch(itype){
403  case FIELDTYPE_SFFloat: iz = sizeof(float); break;
404  case FIELDTYPE_SFRotation: iz = sizeof(struct SFRotation); break;
405  case FIELDTYPE_SFVec3f: iz = sizeof(struct SFVec3f);break;
406  case FIELDTYPE_SFBool: iz = sizeof(int); break;
407  case FIELDTYPE_SFInt32: iz = sizeof(int); break;
408  case FIELDTYPE_SFNode: iz = sizeof(void*); break;
409  case FIELDTYPE_SFColor: iz = sizeof(struct SFColor); break;
410  case FIELDTYPE_SFColorRGBA: iz = sizeof(struct SFColorRGBA); break;
411  case FIELDTYPE_SFTime: iz = sizeof(double); break;
412  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
413  case FIELDTYPE_SFVec2f: iz = sizeof(struct SFVec2f); break;
414  //case FIELDTYPE_SFImage: iz = sizeof(void*); break;
415  case FIELDTYPE_SFVec3d: iz = sizeof(struct SFVec3d); break;
416  case FIELDTYPE_SFDouble: iz = sizeof(double); break;
417  case FIELDTYPE_SFMatrix3f: iz = sizeof(struct SFMatrix3f); break;
418  case FIELDTYPE_SFMatrix3d: iz = sizeof(struct SFMatrix3d); break;
419  case FIELDTYPE_SFMatrix4f: iz = sizeof(struct SFMatrix4f); break;
420  case FIELDTYPE_SFMatrix4d: iz = sizeof(struct SFMatrix4d); break;
421  case FIELDTYPE_SFVec2d: iz = sizeof(struct SFVec2d); break;
422  case FIELDTYPE_SFVec4f: iz = sizeof(struct SFVec4f); break;
423  case FIELDTYPE_SFVec4d: iz = sizeof(struct SFVec4d); break;
424 
425  case FIELDTYPE_SFImage: //same as MFInt32
426  case FIELDTYPE_MFFloat:
427  case FIELDTYPE_MFRotation:
428  case FIELDTYPE_MFVec3f:
429  case FIELDTYPE_MFBool:
430  case FIELDTYPE_MFInt32:
431  case FIELDTYPE_MFNode:
432  case FIELDTYPE_MFColor:
433  case FIELDTYPE_MFColorRGBA:
434  case FIELDTYPE_MFTime:
435  case FIELDTYPE_MFString:
436  case FIELDTYPE_MFVec2f:
437  case FIELDTYPE_MFImage:
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 }
456 int 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 */
469 void 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 
480 void 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 /*
612 MF_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 
695 void 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 /*
835 MF_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 
858  PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
859  PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
860  PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
861  PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
862  PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
863  PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
864  PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
865  PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
866  PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
867  PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
868  PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
869  PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
870  PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
871  PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
872  PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
873  PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
874  PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
875  PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
876  PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
877  PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
878 
879  case FIELDTYPE_SFString: {
880  //struct Uni_String *mptr;
881  memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
882  //mptr = * (struct Uni_String **)nst;
883  //if (!mptr) {
884  // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
885  //} else {
886  // FREE_IF_NZ(mptr->strptr);
887  // mptr->strptr = myVal.sfstring->strptr;
888  // mptr->len = myVal.sfstring->len;
889  // mptr->touched = myVal.sfstring->touched;
890  //}
891  break; }
892 
893  default: {
894  printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
895  lexer_forceStringCleanup(parser->lexer);
896  return;
897  }
898  }
899 
900  } else {
901  if (strlen (value) > 50) {
902  value[45] = '.';
903  value[46] = '.';
904  value[47] = '.';
905  value[48] = '\0';
906  }
907  ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
908  }
909 
910  /* tell the parser that we have done with the input - it will FREE the data */
911  lexer_forceStringCleanup(parser->lexer);
912 
913  FREE_IF_NZ(mfstringtmp);
914 
915  /* and, reset the XML flag */
916  parser->parsingX3DfromXML = oldXMLflag;
917 }
918 
919 void Parser_scanStringValueToMem_C0(struct VRMLParser *parser, union anyVrml* any, indexT ctype, char *value, int isXML)
920 {
921  //dug9 Apr 2013: same as Parser_scanStringValueToMemB except:
922  // - you create or remember your parser* outside, so no static or gglobal in here, so can be called from libeai.
923  // - puts it into *anyVrml instead of (node,offset)
924  // - doesn't update parents for SFNode, MFNode fields (just zeros it) - that's done outside
925  void *nst; /* used for pointer maths */
926  union anyVrml myVal;
927  char *mfstringtmp = NULL;
928  int oldXMLflag;
929  struct X3D_Node *np;
930  #ifdef SETFIELDVERBOSE
931  printf ("\nPST, for %s we have %s strlen %lu\n",stringFieldtypeType(ctype), value, strlen(value));
932  #endif
933 
934  /* if this is the first time through, create a new parser, and tell it:
935  - that we are using X3D formatted field strings, NOT "VRML" ones;
936  - that the destination node is not important (the NULL, offset 0) */
937 
938  if (parser == NULL) {
939  parser=newParser(NULL,NULL, 0, TRUE);
940  //ConsoleMessage ("Parser_ScanStringValueToMem, new parser created");
941  }
942 
943  lexer_forceStringCleanup(parser->lexer);
944 
945  /* October 20, 2009; XML parsing should not go through here; XML encoded X3D should not have a "value=" field, but
946  have the SFNode or MFNode as part of the syntax, eg <field ...> <Box/> </field> */
947 
948  if (isXML) {
949  /* printf ("we have XML parsing for type %s, string :%s:\n",stringFieldtypeType(ctype),value); */
950  if ((ctype==FIELDTYPE_SFNode) || (ctype==FIELDTYPE_MFNode)) {
951  /* printf ("returning\n"); */
952  lexer_forceStringCleanup(parser->lexer);
953  return;
954  }
955 
956  }
957 
958  /* there is a difference sometimes, in the XML format and VRML classic format. The XML
959  parser will use xml format, scripts and EAI will use the classic format */
960  oldXMLflag = parser->parsingX3DfromXML;
961  parser->parsingX3DfromXML = isXML;
962 
963  /* we NEED MFStrings to have quotes on; so if this is a MFString, ensure quotes are ok */
964  if (ctype == FIELDTYPE_MFString) {
965  #ifdef SETFIELDVERBOSE
966  printf ("parsing type %s, string :%s:\n",stringFieldtypeType(ctype),value);
967  #endif
968 
969  /* go to the first non-space character, and see if this is required;
970  sometimes people will encode mfstrings as:
971  url=' "images/earth.gif" "http://ww
972  note the space in the value */
973  while ((*value == ' ') && (*value != '\0')) value ++;
974 
975  /* now, does the value string need quoting? */
976  if ((*value != '"') && (*value != '\'') && (*value != '[')) {
977  size_t len;
978  /* printf ("have to quote this string\n"); */
979  len = strlen(value);
980  mfstringtmp = MALLOC (char *, sizeof (char *) * len + 10);
981  memcpy (&mfstringtmp[1],value,len);
982  mfstringtmp[0] = '"';
983  mfstringtmp[len+1] = '"';
984  mfstringtmp[len+2] = '\0';
985  /* printf ("so, mfstring is :%s:\n",mfstringtmp); */
986 
987  } else {
988  mfstringtmp = STRDUP(value);
989  }
990  parser_fromString(parser,mfstringtmp);
991  /* FREE_IF_NZ(mfstringtmp); */
992  } else if (ctype == FIELDTYPE_SFNode) {
993  /* Need to change index to proper node ptr */
994  np = getEAINodeFromTable(atoi(value), -1);
995  } else if (ctype == FIELDTYPE_SFString) {
996  if(isXML){
997  /* double quotes " are unique to x3d values and must be \" to pass javascript compiling */
998  int nq = 0;
999  char *mv, *pv, *v = value;
1000  while (*v && *v != '\0')
1001  {
1002  if(*v == '"') nq++;
1003  v++;
1004  }
1005  mfstringtmp = (char *)MALLOC(void *, strlen(value)+nq+1);
1006  v = value;
1007  pv = NULL;
1008  mv = mfstringtmp;
1009  while(*v && *v != '\0')
1010  {
1011  if(*v == '"'){
1012  if(!(pv && *pv == '\\')){
1013  *mv = '\\';
1014  mv++;
1015  }
1016  }
1017  *mv = *v;
1018  mv++;
1019  pv = v;
1020  v++;
1021  }
1022  *mv = '\0';
1023  }else{
1024  mfstringtmp = STRDUP(value);
1025  }
1026  parser_fromString(parser,mfstringtmp);
1027  } else {
1028  mfstringtmp = STRDUP(value);
1029  parser_fromString(parser,mfstringtmp);
1030  /* FREE_IF_NZ(mfstringtmp); */
1031  }
1032 
1033  ASSERT(parser->lexer);
1034  FREE_IF_NZ(parser->lexer->curID);
1035 
1036  if (ctype == FIELDTYPE_SFNode) {
1037  //struct X3D_Node* oldvalue;
1038  //nst = offsetPointer_deref(void *,node,coffset);
1039  //memcpy (&oldvalue, any, sizeof(struct X3D_Node*));
1040  //if (oldvalue) {
1041  // remove_parent(oldvalue, node);
1042  //}
1043  memcpy(any, (void*)&np, sizeof(struct X3D_Node*));
1044  any->sfnode->_parentVector = NULL;
1045  //add_parent(np, node, "sarah's add", 0);
1046  } else if (parseType(parser, ctype, &myVal)) {
1047  /* printf ("parsed successfully\n"); */
1048  //nst = offsetPointer_deref(void *,node,coffset);
1049  nst = any;
1050 
1051 /*
1052 MF_TYPE(MFNode, mfnode, Node)
1053 */
1054  switch (ctype) {
1055 
1056  PST_MF_STRUCT_ELEMENT(Vec2f,vec2f)
1057  PST_MF_STRUCT_ELEMENT(Vec3f,vec3f)
1058  PST_MF_STRUCT_ELEMENT(Vec3d,vec3d)
1059  PST_MF_STRUCT_ELEMENT(Vec4d,vec4d)
1060  PST_MF_STRUCT_ELEMENT(Vec2d,vec2d)
1061  PST_MF_STRUCT_ELEMENT(Color,color)
1062  PST_MF_STRUCT_ELEMENT(ColorRGBA,colorrgba)
1063  PST_MF_STRUCT_ELEMENT(Int32,int32)
1064  PST_MF_STRUCT_ELEMENT(Float,float)
1065  PST_MF_STRUCT_ELEMENT(Double,double)
1066  PST_MF_STRUCT_ELEMENT(Bool,bool)
1067  PST_MF_STRUCT_ELEMENT(Time,time)
1068  PST_MF_STRUCT_ELEMENT(Rotation,rotation)
1069  PST_MF_STRUCT_ELEMENT(Matrix3f,matrix3f)
1070  PST_MF_STRUCT_ELEMENT(Matrix3d,matrix3d)
1071  PST_MF_STRUCT_ELEMENT(Matrix4f,matrix4f)
1072  PST_MF_STRUCT_ELEMENT(Matrix4d,matrix4d)
1073  PST_MF_STRUCT_ELEMENT(String,string)
1074 
1075  PST_SF_SIMPLE_ELEMENT(Float,float,sizeof(float))
1076  PST_SF_SIMPLE_ELEMENT(Time,time,sizeof(double))
1077  PST_SF_SIMPLE_ELEMENT(Double,double,sizeof(double))
1078  PST_SF_SIMPLE_ELEMENT(Int32,int32,sizeof(int))
1079  PST_SF_SIMPLE_ELEMENT(Bool,bool,sizeof(int))
1080  PST_SF_SIMPLE_ELEMENT(Node,node,sizeof(void *))
1081  PST_SF_SIMPLE_ELEMENT(Vec2f,vec2f,sizeof(struct SFVec2f))
1082  PST_SF_SIMPLE_ELEMENT(Vec2d,vec2d,sizeof(struct SFVec2d))
1083  PST_SF_SIMPLE_ELEMENT(Vec3f,vec3f,sizeof(struct SFColor))
1084  PST_SF_SIMPLE_ELEMENT(Vec3d,vec3d,sizeof(struct SFVec3d))
1085  PST_SF_SIMPLE_ELEMENT(Vec4f,vec4f,sizeof(struct SFVec4f))
1086  PST_SF_SIMPLE_ELEMENT(Vec4d,vec4d,sizeof(struct SFVec4d))
1087  PST_SF_SIMPLE_ELEMENT(Rotation,rotation,sizeof(struct SFRotation))
1088  PST_SF_SIMPLE_ELEMENT(Color,color,sizeof(struct SFColor))
1089  PST_SF_SIMPLE_ELEMENT(ColorRGBA,colorrgba,sizeof(struct SFColorRGBA))
1090  PST_SF_SIMPLE_ELEMENT(Matrix3f,matrix3f,sizeof(struct SFMatrix3f))
1091  PST_SF_SIMPLE_ELEMENT(Matrix4f,matrix4f,sizeof(struct SFMatrix4f))
1092  PST_SF_SIMPLE_ELEMENT(Matrix3d,matrix3d,sizeof(struct SFMatrix3d))
1093  PST_SF_SIMPLE_ELEMENT(Matrix4d,matrix4d,sizeof(struct SFMatrix4d))
1094  PST_SF_SIMPLE_ELEMENT(Image,image,sizeof(struct Multi_Int32))
1095 
1096  case FIELDTYPE_SFString: {
1097  //struct Uni_String *mptr;
1098  memcpy(nst, &myVal.sfstring, sizeof(struct Uni_String*));
1099  //mptr = * (struct Uni_String **)nst;
1100  //if (!mptr) {
1101  // ERROR_MSG("Parser_scanStringValueToMem: is nst (Uni_String) supposed to hold a NULL value ?");
1102  //} else {
1103  // FREE_IF_NZ(mptr->strptr);
1104  // mptr->strptr = myVal.sfstring->strptr;
1105  // mptr->len = myVal.sfstring->len;
1106  // mptr->touched = myVal.sfstring->touched;
1107  //}
1108  break; }
1109 
1110  default: {
1111  printf ("unhandled type, in EAIParse %s\n",stringFieldtypeType(ctype));
1112  lexer_forceStringCleanup(parser->lexer);
1113  return;
1114  }
1115  }
1116 
1117  } else {
1118  if (strlen (value) > 50) {
1119  value[45] = '.';
1120  value[46] = '.';
1121  value[47] = '.';
1122  value[48] = '\0';
1123  }
1124  ConsoleMessage ("parser problem on parsing fieldType %s, string :%s:", stringFieldtypeType(ctype),value);
1125  }
1126 
1127  /* tell the parser that we have done with the input - it will FREE the data */
1128  lexer_forceStringCleanup(parser->lexer);
1129 
1130  /* and, reset the XML flag */
1131  parser->parsingX3DfromXML = oldXMLflag;
1132 }
1133 void Parser_scanStringValueToMem_C(void *any0, int ctype0, char *value, int isXML)
1134 //void Parser_scanStringValueToMem_C(union anyVrml* any, indexT ctype, char *value, int isXML)
1135 {
1136  struct VRMLParser *parser;
1137  union anyVrml* any;
1138  indexT ctype;
1139  any = (union anyVrml*)any0;
1140  ctype = (indexT)ctype0;
1141  parser=newParser(NULL,NULL, 0, TRUE);
1142  Parser_scanStringValueToMem_C0(parser, any, ctype, value, isXML);
1143  if (parser != NULL) {
1144  lexer_destroyData(parser->lexer);
1145  deleteParser(parser);
1146  parser = NULL;
1147  }
1148  return;
1149 }