Go to the documentation of this file.
12 #include "readworld.tab.h"
15 YY_BUFFER_STATE buffer;
24 unsigned int currentIncludeLevel=0;
26 unsigned int firstLink;
27 unsigned int firstObject;
29 int ReadWorldlex( void);
31 extern unsigned int RWline;
33 void Switch2File( char *ln, unsigned int nl, unsigned int no, char *path, char *file);
43 R_NUMBER (({DIGIT}+(\.{DIGIT}+)?)|(\.{DIGIT}+))((E|e)[+-]?{DIGIT}+)?
46 IDENTIFIER {LETTER}({DIGIT}|{LETTER}|"_ ")*
47 EXT_IDENTIFIER {IDENTIFIER}(":: "{IDENTIFIER})+
62 [^*\n]+ // eat comment in chunks
63 "* " // eat the lone star
69 {RETURN} { RWline++; }
104 return(_GRANULARITY);
180 return(_SPH_PRS_SPH);
281 return(_SELFCOLLISIONS);
297 char string_tmp[100];
299 memcpy(string_tmp,ReadWorldtext,(unsigned int)ReadWorldleng);
300 string_tmp[ReadWorldleng]=0;
301 ReadWorldlval.int_number=atoi(string_tmp);
306 char string_tmp[100];
308 memcpy(string_tmp,ReadWorldtext,(unsigned int)ReadWorldleng);
309 string_tmp[ReadWorldleng]=0;
310 ReadWorldlval.real_number=atof(string_tmp);
316 NEW(ReadWorldlval.string,ReadWorldleng,char);
318 memcpy(ReadWorldlval.string,&(ReadWorldtext[1]),(unsigned int)ReadWorldleng-2);
319 ReadWorldlval.string[ReadWorldleng-2]=0;
325 if (currentIncludeLevel==0)
327 NEW(ReadWorldlval.id,ReadWorldleng+1,char);
328 memcpy(ReadWorldlval.id,ReadWorldtext,(unsigned int)ReadWorldleng);
330 ReadWorldlval.id[ReadWorldleng]=0;
334 NEW(ReadWorldlval.id,includeInfo[currentIncludeLevel-1].pl+2+ReadWorldleng+1,char);
335 sprintf(ReadWorldlval.id,"%s__%s ",includeInfo[currentIncludeLevel-1].prefix,ReadWorldtext);
336 ReadWorldlval.id[includeInfo[currentIncludeLevel-1].pl+ReadWorldleng+2]=0;
345 if (currentIncludeLevel==0)
347 NEW(ReadWorldlval.id,ReadWorldleng+1,char);
348 memcpy(ReadWorldlval.id,ReadWorldtext,(unsigned int)ReadWorldleng);
350 ReadWorldlval.id[ReadWorldleng]=0;
352 for(i=0;i<ReadWorldleng;i++)
354 if (ReadWorldlval.id[i]==':')
355 ReadWorldlval.id[i]='_';
362 NEW(ReadWorldlval.id,includeInfo[currentIncludeLevel-1].pl+2+ReadWorldleng+1,char);
363 sprintf(ReadWorldlval.id,"%s__%s ",includeInfo[currentIncludeLevel-1].prefix,ReadWorldtext);
364 ReadWorldlval.id[includeInfo[currentIncludeLevel-1].pl+ReadWorldleng+2]=0;
366 for(i=0,k=includeInfo[currentIncludeLevel-1].pl+2;i<ReadWorldleng;i++,k++)
368 if (ReadWorldlval.id[k]==':')
369 ReadWorldlval.id[k]='_';
373 return(_EXT_IDENTIFIER);
377 if (currentIncludeLevel>0)
379 currentIncludeLevel--;
381 /* Recover the line number */
382 RWline=includeInfo[currentIncludeLevel].line;
384 /* Deletes the prefix */
385 free(includeInfo[currentIncludeLevel].prefix);
387 /* Recover the first link/object in the upper file */
388 firstLink=includeInfo[currentIncludeLevel].fl;
389 firstObject=includeInfo[currentIncludeLevel].fo;
391 /* Deletes the lex buffer and switch */
392 yy_delete_buffer(YY_CURRENT_BUFFER);
393 yy_switch_to_buffer(includeInfo[currentIncludeLevel].buffer);
399 . { return(ReadWorldtext[0]); }
404 * This function is automatically called by the parser at the end of a file.
405 * If 1 is returned the lexical analysis is stopped.
413 void Switch2File(char *ln,unsigned int nl,unsigned int no,char *path,char *file)
419 if (currentIncludeLevel>=MAX_INCLUDES)
420 ReadWorlderror("Includes nested too deeply. A loop of includes? " );
422 /* in the new file, lines are numbered from 1 again :) */
423 includeInfo[currentIncludeLevel].line=RWline;
426 /* Store the first link/object in the current file and reset them */
427 includeInfo[currentIncludeLevel].fl=firstLink;
428 includeInfo[currentIncludeLevel].fo=firstObject;
432 /* identifiers in the new file will need the prefix defined next */
434 if (currentIncludeLevel>0)
436 /* If we have a previous prefix, add it to the current prefix */
437 l1=includeInfo[currentIncludeLevel-1].pl;
438 NEW(includeInfo[currentIncludeLevel].prefix,l1+l2+2,char);
439 memcpy(includeInfo[currentIncludeLevel].prefix,includeInfo[currentIncludeLevel-1].prefix,l1*sizeof(char));
440 includeInfo[currentIncludeLevel].prefix[l1]='_';
446 NEW(includeInfo[currentIncludeLevel].prefix,l2+1,char);
448 /* add the link name to the prefix */
449 memcpy(&(includeInfo[currentIncludeLevel].prefix[l1]),ln,l2*sizeof(char));
450 includeInfo[currentIncludeLevel].prefix[l1+l2]=0;
452 includeInfo[currentIncludeLevel].pl=l1+l2; /* cache of the prefix lenght */
454 /* stack the yybuffer */
455 includeInfo[currentIncludeLevel].buffer=YY_CURRENT_BUFFER;
456 currentIncludeLevel++;
458 /* Now try to open the file to be included */
461 NEW(name,l1+l2+1,char);
462 memcpy(name,path,l1*sizeof(char));
463 memcpy(&(name[l1]),file,l2*sizeof(char));
471 NEW(m,l1+l1+100,char);
472 sprintf(m,"Can not open included file: %s ",name);
478 yy_switch_to_buffer(yy_create_buffer(f,YY_BUF_SIZE));
unsigned int RWline Number of the line currently parsed when reading a .world file.
#define CYLINDER One of the possible type of polyhedrons.
#define SEGMENTS One of the possible type of polyhedrons.
#define LINE One of the possible type of polyhedrons.
Definitions of constants and macros used in several parts of the cuik library.
#define MAX_INCLUDES Maximum number of nested included files.
#define SPHERE One of the possible type of polyhedrons.
Error function specific of world.
|
Follow us!