Go to the documentation of this file.
13 #include "readworld.tab.h"
16 YY_BUFFER_STATE buffer;
25 unsigned int currentIncludeLevel=0;
27 unsigned int firstLink;
28 unsigned int firstObject;
30 int ReadWorldlex( void);
32 extern unsigned int RWline;
34 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++; }
92 return(_GREATER_EQUAL);
168 return(_GRANULARITY);
244 return(_SPH_PRS_SPH);
353 return(_SELFCOLLISIONS);
369 char string_tmp[100];
371 memcpy(string_tmp,ReadWorldtext,(unsigned int)ReadWorldleng);
372 string_tmp[ReadWorldleng]=0;
373 ReadWorldlval.int_number=atoi(string_tmp);
378 char string_tmp[100];
380 memcpy(string_tmp,ReadWorldtext,(unsigned int)ReadWorldleng);
381 string_tmp[ReadWorldleng]=0;
382 ReadWorldlval.real_number=atof(string_tmp);
388 NEW(ReadWorldlval.string,ReadWorldleng,char);
390 memcpy(ReadWorldlval.string,&(ReadWorldtext[1]),(unsigned int)ReadWorldleng-2);
391 ReadWorldlval.string[ReadWorldleng-2]=0;
397 if (currentIncludeLevel==0)
399 NEW(ReadWorldlval.id,ReadWorldleng+1,char);
400 memcpy(ReadWorldlval.id,ReadWorldtext,(unsigned int)ReadWorldleng);
402 ReadWorldlval.id[ReadWorldleng]=0;
406 NEW(ReadWorldlval.id,includeInfo[currentIncludeLevel-1].pl+2+ReadWorldleng+1,char);
407 sprintf(ReadWorldlval.id,"%s__%s ",includeInfo[currentIncludeLevel-1].prefix,ReadWorldtext);
408 ReadWorldlval.id[includeInfo[currentIncludeLevel-1].pl+ReadWorldleng+2]=0;
417 if (currentIncludeLevel==0)
419 NEW(ReadWorldlval.id,ReadWorldleng+1,char);
420 memcpy(ReadWorldlval.id,ReadWorldtext,(unsigned int)ReadWorldleng);
422 ReadWorldlval.id[ReadWorldleng]=0;
424 for(i=0;i<ReadWorldleng;i++)
426 if (ReadWorldlval.id[i]==':')
427 ReadWorldlval.id[i]='_';
434 NEW(ReadWorldlval.id,includeInfo[currentIncludeLevel-1].pl+2+ReadWorldleng+1,char);
435 sprintf(ReadWorldlval.id,"%s__%s ",includeInfo[currentIncludeLevel-1].prefix,ReadWorldtext);
436 ReadWorldlval.id[includeInfo[currentIncludeLevel-1].pl+ReadWorldleng+2]=0;
438 for(i=0,k=includeInfo[currentIncludeLevel-1].pl+2;i<ReadWorldleng;i++,k++)
440 if (ReadWorldlval.id[k]==':')
441 ReadWorldlval.id[k]='_';
445 return(_EXT_IDENTIFIER);
449 if (currentIncludeLevel>0)
451 currentIncludeLevel--;
453 /* Recover the line number */
454 RWline=includeInfo[currentIncludeLevel].line;
456 /* Deletes the prefix */
457 free(includeInfo[currentIncludeLevel].prefix);
459 /* Recover the first link/object in the upper file */
460 firstLink=includeInfo[currentIncludeLevel].fl;
461 firstObject=includeInfo[currentIncludeLevel].fo;
463 /* Deletes the lex buffer and switch */
464 yy_delete_buffer(YY_CURRENT_BUFFER);
465 yy_switch_to_buffer(includeInfo[currentIncludeLevel].buffer);
471 . { return(ReadWorldtext[0]); }
476 * This function is automatically called by the parser at the end of a file.
477 * If 1 is returned the lexical analysis is stopped.
487 void Switch2File(char *ln,unsigned int nl,unsigned int no,char *path,char *file)
493 if (currentIncludeLevel>=MAX_INCLUDES)
494 ReadWorlderror("Includes nested too deeply. A loop of includes? " );
496 /* in the new file, lines are numbered from 1 again :) */
497 includeInfo[currentIncludeLevel].line=RWline;
500 /* Store the first link/object in the current file and reset them */
501 includeInfo[currentIncludeLevel].fl=firstLink;
502 includeInfo[currentIncludeLevel].fo=firstObject;
506 /* identifiers in the new file will need the prefix defined next */
508 if (currentIncludeLevel>0)
510 /* If we have a previous prefix, add it to the current prefix */
511 l1=includeInfo[currentIncludeLevel-1].pl;
512 NEW(includeInfo[currentIncludeLevel].prefix,l1+l2+2,char);
513 memcpy(includeInfo[currentIncludeLevel].prefix,includeInfo[currentIncludeLevel-1].prefix,l1*sizeof(char));
514 includeInfo[currentIncludeLevel].prefix[l1]='_';
520 NEW(includeInfo[currentIncludeLevel].prefix,l2+1,char);
522 /* add the link name to the prefix */
523 memcpy(&(includeInfo[currentIncludeLevel].prefix[l1]),ln,l2*sizeof(char));
524 includeInfo[currentIncludeLevel].prefix[l1+l2]=0;
526 includeInfo[currentIncludeLevel].pl=l1+l2; /* cache of the prefix lenght */
528 /* stack the yybuffer */
529 includeInfo[currentIncludeLevel].buffer=YY_CURRENT_BUFFER;
530 currentIncludeLevel++;
532 /* Now try to open the file to be included */
535 NEW(name,l1+l2+1,char);
536 memcpy(name,path,l1*sizeof(char));
537 memcpy(&(name[l1]),file,l2*sizeof(char));
545 NEW(m,l1+l1+100,char);
546 sprintf(m,"Can not open included file: %s ",name);
552 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.
Definition of the Tcolor type and the associated functions.
Error function specific of world.
|
Follow us!