summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2010-11-14 14:24:57 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2010-11-14 14:24:57 +0000
commitcaf2d729421aaa7baffef76c5d24ffecc28fb6c2 (patch)
tree5bbc3f506f7bba70e295eafb3e7d447d810d605c
parentea2178f9dba92197ec0b57ce6a633b5607259611 (diff)
download2010-netlemmings-caf2d729421aaa7baffef76c5d24ffecc28fb6c2.tar.gz
2010-netlemmings-caf2d729421aaa7baffef76c5d24ffecc28fb6c2.tar.bz2
2010-netlemmings-caf2d729421aaa7baffef76c5d24ffecc28fb6c2.zip
Début d'intégration du parser. Création d'un test_parce.c pour lancer direct le parsing. Ça segfaulte vilain aaprès une syntax error. Ya du taff :D
git-svn-id: file:///var/svn/2010-netlemmings/trunk@149 077b3477-7977-48bd-8428-443f22f7bfda
-rw-r--r--src/parser/ginit.h20
-rw-r--r--src/parser/parse_ini.lex133
-rw-r--r--src/parser/parse_ini.yy716
-rw-r--r--src/test/test_parse.c31
-rwxr-xr-xsrc/test/test_parse.sh1
5 files changed, 114 insertions, 787 deletions
diff --git a/src/parser/ginit.h b/src/parser/ginit.h
index ccdd6b9..7cec1fe 100644
--- a/src/parser/ginit.h
+++ b/src/parser/ginit.h
@@ -1,14 +1,19 @@
+#ifndef GINIT_H
+#define GINIT_H
+
+#include "SDL/SDL.h"
enum eMapStyle {
brick , bubble , crystal , dirt , fire , marble ,
pillar , rock , snow , special, undefined
};
- char tabString_eMapStyle[NBR_STYLE_MAP][10] = {
+/*
+ char tabString_eMapStyle[][10] = {
"brick" , "bubble" , "crystal" , "dirt" , "fire" , "marble" ,
"pillar" , "rock" , "snow" , "special", "undefined"
};
-
+*/
struct colorMap {
Uint32 bgColor;// background color present in "style".ini
Uint32 debrisColor;// debris color present in "style".ini
@@ -118,14 +123,14 @@
builder , builder_end , digger , basher , miner , jumper ,
died , enter , safe , nuke , bomber_stopper , floater_start
};
-
+/*
char tabString_eLemmingJob[TOTAL_LEM_JOB][20] = {
"walker" , "faller" , "climber" , "climber_to_walker" , "floater" ,
"splat" , "stopper" , "drowning" , "trap_death" , "exIt" , "bomber",
"builder" , "builder_end , digger" , "basher" , "miner" , "jumper",
"died" , "enter" , "safe" , "nuke", "bomber_stopper", "floater_start"
};
-
+*/
struct lemmingMask {
// ID == lemming.ID;
int stateM; // number of state in mask_XX.gif;
@@ -165,13 +170,13 @@
numClimbers,numFloaters,numBombers,numBlockers,numBuilders,
numBashers,numMiners,numDiggers
};
-
+/*
char tabString_eParaMap[IDENT_COUNT][32] = {
"releaseRate","numLemmings","numToRescue","timeLimit",
"numClimbers","numFloaters","numBombers","numBlockers",
"numBuilders","numBashers","numMiners","numDiggers"
};
-
+*/
struct infoMap {
char* name; // map name; default=NULL;
int paraMap[IDENT_COUNT]; // some parameter of this map
@@ -262,6 +267,7 @@
struct objet o; // all DATA of objet on this map;
struct steel s; // all DATA of steel on this map;
struct lemming l; // all DATA of lemming on this map;
+ int parseError;
/*
// 0-13 : BUTTON_LEMMING state button 0: off; 1: on;
// 14 : CURSOR STATE
@@ -272,4 +278,4 @@
int cptGame[NBR_CPT]; // default=0;
*/
};
- // FIN: GAMEINIT
+#endif /*GINIT_H*/
diff --git a/src/parser/parse_ini.lex b/src/parser/parse_ini.lex
index 9298543..8d68a0a 100644
--- a/src/parser/parse_ini.lex
+++ b/src/parser/parse_ini.lex
@@ -6,17 +6,16 @@
#define MAX_STR_LEN 255
-
- int string(int tok) {
- int lg = strlen(yytext);
- if ( lg > MAX_STR_LEN ) {
- return LEXERROR;
- } else {
- yylval.str = malloc(sizeof(char)*(lg+1));
- strcpy(yylval.str, yytext);
- return tok;
- }
+int string(int tok) {
+ int lg = strlen(yytext);
+ if ( lg > MAX_STR_LEN ) {
+ return LEXERROR;
+ } else {
+ yylval.str = malloc(sizeof(char)*(lg+1));
+ strcpy(yylval.str, yytext);
+ return tok;
}
+}
%}
%option noinput
@@ -26,98 +25,50 @@
BLANK [ \t]
NOT_BLANK [^ \t]
IDENT [a-zA-Z][a-zA-Z0-9_-]*
-NUMBER "-"?[0-9]+
+INTEGER "-"?[0-9]+
+INTHEX "0x"[0-9a-f]+
COMMENT "#"[^\n]*
/*
- %s : inclusive start condition (inclus aussi les règles sans <cond>)
- %x : exclusive start condition (règles sans <cond> inactives)
+ %s : inclusive start condition (includes also rules starting without <sc>)
+ %x : exclusive start condition
*/
-%x INI_VALUE
-%x STR_M
-%x STR_MM
+%x TYPE_STR
+%x TYPE_OTHER
+%x VAL_STR
+%x VAL_OTHER
%%
-"=" {
- BEGIN(INI_VALUE);
- return AFF;
- }
-
-<INI_VALUE>\n {
- yylineno++;
- BEGIN(INITIAL);
- return EOL;
- }
-
-<INI_VALUE>{NUMBER}{BLANK}*{COMMENT}? {
- yylval.num = atoi(yytext);
- return INT;
- }
-
-<INI_VALUE>"," {
- return VIR;
- }
-
-"style" {
- BEGIN(STR_M);
- return STYLE;
- }
-
-"name" {
- BEGIN(STR_M);
- return NAME;
- }
-
-"superlemming" {
- BEGIN(STR_M);
- return SLEM;
- }
-
-"bgColor" {
- BEGIN(STR_M);
- return BGCOLOR;
- }
-
-"debrisColor" {
- BEGIN(STR_M);
- return DEBRISCOLOR;
- }
-
-"particleColor" {
- BEGIN(STR_M);
- return PARTICLECOLOR;
- }
+ /* Wilcard state. Following rules are common to all states */
+<*>\n { yylineno++; BEGIN(INITIAL); return EOL; }
+<*>\r /* Ignore - http://fr.wikipedia.org/wiki/Fin_de_ligne : CRLF*/
-<STR_M>{BLANK}*"="{BLANK}* {
- BEGIN(STR_MM);
- return AFF;
- }
+ /* Other rules for almost states (but VAL_STR) to ignore blanks and comments */
+<TYPE_STR,TYPE_OTHER,VAL_OTHER>"#"[^\n]*\n { yylineno++; } /* Single line Comment*/
+<TYPE_STR,TYPE_OTHER,VAL_OTHER>{BLANK}* /* Ignore */
-<STR_M>{BLANK}*
-<STR_MM>{BLANK}*
-<STR_MM>{BLANK}*[^\n]* {
- BEGIN(INITIAL);
- return string(STR);
- }
+ /* Initial state, start condition is 'INITIAL' (implicit), we catch only identifiers here */
+"style" { BEGIN(TYPE_STR); return STYLE; }
+"name" { BEGIN(TYPE_STR); return NAME; }
-<STR_MM>\n {
- yylineno++;
- BEGIN(INITIAL);
- return EOL;
- }
+"superlemming" { BEGIN(TYPE_OTHER); return SLEM; }
-{IDENT} {
- return string(IDENT);
- }
+"bgColor" { BEGIN(TYPE_OTHER); return BGCOLOR; }
+"debriscolor" { BEGIN(TYPE_OTHER); return DEBRISCOLOR; }
+"particlecolor" { BEGIN(TYPE_OTHER); return PARTICLECOLOR; }
-"#"[^\n]*\n { yylineno++; } /* Single line Comment*/
-\r /* http://fr.wikipedia.org/wiki/Fin_de_ligne : CRLF*/
-\n { yylineno++; return EOL; }
-{BLANK}* /* Ignore */
+ /* TYPE_* states for catching the '=' token and go in the right state machine for catching values */
+<TYPE_STR>"="{BLANK}* { BEGIN(VAL_STR); return AFF; }
+<TYPE_OTHER>"=" { BEGIN(VAL_OTHER); return AFF; }
-{NOT_BLANK} { /* Pour tout ce qu'on a pas encore chopé */
- fprintf(stderr, "LEX : ERROR : unknown char '%c'", yytext[0]);
- return LEXERROR;
- }
+<VAL_STR>[^\r\n]+ { return string(STR); }
+<VAL_OTHER>{INTEGER} { yylval.num = atoi(yytext); return INT; }
+<VAL_OTHER>{INTHEX} { int res=sscanf(yytext, "0x%x", &yylval.uint32); if(res) return INT; else return LEXERROR; }
+<VAL_OTHER>{IDENT} { return string(IDENT); }
+<VAL_OTHER>"," { return VIR; }
+<*>.+ { /* Everything else is catched here */
+ fprintf(stderr, "LEX : ERROR : unknown sequence '%s'", yytext);
+ return LEXERROR;
+ }
diff --git a/src/parser/parse_ini.yy b/src/parser/parse_ini.yy
index 9e01c27..dc9ca28 100644
--- a/src/parser/parse_ini.yy
+++ b/src/parser/parse_ini.yy
@@ -1,728 +1,66 @@
%{
-#include "y.tab.h"
-
-#include "SDL/SDL.h"
-#include "SDL/SDL_image.h"
-
-#include <sys/types.h>
-#include <dirent.h>
-
-#include <stdio.h>
+//#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
- /** time per frame in microseconds - this is the timing everything else is based on */
-#define FPS 150
- /** redraw animated level obejcts every 3rd frame (about 100ms) */
-#define ANIM_STEP_FPS 3
-
- // the original formula is: release lemming every 4+(99-speed)/2 time steps
- // where one step is 60ms (3s/50) or 66ms (4s/60).
- // Lemmini runs at 30ms/33ms, so the term has to be multiplied by 2
- // 8+(99-releaseRate) should be correct
- //releaseBase = 8 + (99 - releaseRate);
-
-
-#define TIME_WAIT_TRAP_START 15000 // milliseconde
-
-#define INTERFACE_HEIGHT 150
-
-#define MINIMAP_X0 420
-#define MINIMAP_Y0 325
-#define MINIMAP_MX 350
-#define MINIMAP_MY 175
-
-#define INTER_BUTTON_X 0
-#define INTER_BUTTON_Y 50
-
- //Les dimensions du niveau
-#define LEVEL_WIDTH (1664*2)
-#define LEVEL_HEIGHT (160*2)
-
- // Decale le tableau d'objet
- //0: lemmfont.gif
- //1: numfont.gif
- //2: countdown.gif
- //3: cursor.gif
- //4: explode.gif
- //5: border.gif
- //6: replay.gif
- //7: select.gif
- //8: font7x10.bmp
- //9: alphabet.gif
-
- //10: mask_10.gif
- //11: mask_11.gif
- //12: mask_6.gif
- //13: mask_13.gif
- //14: mask_14.gif
- //15: mask_15.gif
- //16: imask_13.gif
- //17: imask_14.gif
- //18: imask_15.gif
-#define NBR_ADD_OBJ 19
- //9-21 : icone_XX.gif
-#define NBR_BUTTON_LEMMING 13
-#define ADD_OBJ (NBR_ADD_OBJ+NBR_BUTTON_LEMMING)
-
-//FIXME : pas de variables pour les couleurs
-/*
- //cyan pixel color
- Uint32 ccc_cyan= 0x00ffff;
- //yellow pixel color
- Uint32 ccc_yellow = 0xffff00;
- //Red pixel color
- Uint32 ccc_red= 0xff0000;
- //green pixel color
- Uint32 ccc_green= 0x00ff00;
- // erase surface;
- Uint32 ccc_black= 0x000000;
-
- // gimp
- Uint32 ccc_gimp = 0xffffff;
-
- //Blanc cursor
- Uint32 ccc_cursor = 0x000000;
- //Noir colorKeyGif
- Uint32 ccc_keyGif = 0x000000;
- // lemming color
- Uint32 ccc_lemming = 0x001a82;
-
- // object color
- // terrain
- Uint32 ccc_tRemove = 0x007f00ff; // Violet
- Uint32 ccc_tRemoveNoOverwrite = 0x009932cd; // Lilas
- Uint32 ccc_tFull = 0xff38b0de; // Ciel d'été
- Uint32 ccc_tNoOverwrite = 0xff0000ff; // bleu
- Uint32 ccc_tHidden = 0xff236b8e; // Bleu Acier
-
- // after conversion
- // destructible => brick
- Uint32 ccc_tBrick = 0x00edaa;//0x00ed4f; // vert
- // empty => bgStencil
- Uint32 ccc_bgStencil = 0x000000;
- // steel
- // indestructible => steel
- Uint32 ccc_s = 0xff00aa;//0xff00ff;//rose bonbon
-
- // object
- Uint32 ccc_oPassive = 0x6b8ebb;//0x6b8e23; // Vert olive clair
-
- Uint32 ccc_oNoDigLeft = 0xff7fbb;//0xff7f00; // Thé
- Uint32 ccc_oNoDigRight = 0xd987bb;//0xd98719; // Ocre
-
- Uint32 ccc_oTrapDrown = 0x7fffbb;//0x7fff00;// Vert de Hooker
- Uint32 ccc_oTrapAndNoLem = 0x8c17bb;//0x8c1717; // Ecarlate
- Uint32 ccc_oTrapAndLem = 0xa62abb;//0xa62a2a; // Brun
-
- Uint32 ccc_oExit = 0xd9d9bb;//0xd9d919; // Blond
- Uint32 ccc_oEntry = 0x855ebb;//0x855e42; // Bronze
-
- Uint32 ccc_oUnknow = 0xffffbb;//0xffffff; // Blanc
-
-
- // error
- Uint32 ccc_error = 0x666669;
-
- // lemming
- Uint32 ccc_lWalk_on = 0xffddcc;
-
- Uint32 ccc_lStopper = 0xffffcb;
-
- Uint32 ccc_lStopperLeft = 0xffbbcb;
- Uint32 ccc_lStopperRight = 0xffcccb;
-
-*/
-
-
- // Config Cam
-#define CAM_VITESSE 8
-#define BOUND_SENSIBILITE 50
-
- struct list_int {
- int val;
- struct list_int *next;
- };
-
- struct val {
- int type;
- union ptr_u { char * str; struct list_int *ints;} ptr;
- };
-
- //DEBUT NEW CONCEPTION
-
- // DEBUT: MAP_STRUCTURE
-#define NBR_STYLE_MAP 11
-#define PARTICULE_COUNT 16
-
+//#include <sys/types.h>
+//#include <dirent.h>
#include "ginit.h"
- //FIN NEW CONCEPTION
-
- enum sens { UD , LR };
-
- extern FILE *yyin;
- extern int yylineno; // Bidouille pour avoir le numero de ligne du lexer ^^
- int yylex();
- void yyerror(struct gameInit *gInit, char *s);
-
-/*
- SDL_Surface *load_image( char* filename, Uint32 cbg );
-
- // void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip );
-
- int init();
-
- SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c);
-
- int load_fields(char *folder, struct gameInit *gInit, int tabnum[255] );
-
- int afficher(struct gameInit *gInit);
-
- int load_files(struct gameInit *gInit);
-
- int clean_up();
-
- int anim_objet(int typeS, int typeO, int cptFps, int frames, int *cpt, struct gameInit *gInit);// returne le state de l'oblet a afficher
-
- Uint32 get_pixel32( int x, int y, SDL_Surface *surface );
-
- int putPixel(SDL_Surface *surface,Uint16 x,Uint16 y,Uint32 color);
-
- int checkPixelDOWN(int nbr, int x, int y );
-
- int checkPixelUP(int nbr, int x, int y, int size );
-
- int outOfLowerMap(int y);
-
- int aboveGround(int x, int y);
-
- int midY(int y, int size);
-
- int reachedPlateau(int x, int y, int size, int dir);
-
- int stencilMid(int x, int y);
-
- int turnedByStopper(int x, int y, int dir);
-
- int explode(int x, int y, int size);
-
- int stateLemming(struct gameInit *gInit);
-
- int ereasePx(int x,int y,SDL_Surface *s,Uint32 bgColor);
-
- struct listeSimplementChainee* rev_listeO (struct listeSimplementChainee* liste);
-
- int initGame(struct gameInit *gInit);
-
- int creationLemming(struct gameInit *gInit);
-
- int paint_terrain (struct gameInit *gInit, int choix);
-
- int paint_manip(SDL_Surface *spr,SDL_Rect from,SDL_Surface *t,SDL_Rect to,Uint32 ccc_t, Uint32 ccc_spr, int mode, SDL_Surface *stencil);
-
- int paint_objet (struct gameInit *gInit, int cptFps);
-
- int paint_objet_stencil (struct gameInit *gInit, int cptFps);
-
- int supprLem (struct gameInit *gInit, int cptFps);
-
- int paint_lemming (struct gameInit *gInit, int cptFps);
-
- int test_O_UD(int UD);
-
- Uint32 string_to_Uint32 (char* c, int taille);
-
- Uint32* tab_of_string_to_Uint32 (char* c, int taille);
+extern FILE *yyin;
+extern int yylineno;
- int paint_letters (char* text);
-
- int findTerrain( struct gameInit *gInit,int x, int y, int x0);
-
- int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit);
-
- int print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, int value);
-
- int print_alpha(SDL_Surface *dst, SDL_Surface *src, int x, int y, char* msg);
-
- int paint_bomber(int x,int y,int xMax,SDL_Surface *cooldown,SDL_Surface *dst,int cpt);
-
- int testAlpha(SDL_Surface *dst, SDL_Surface *src,SDL_Surface *src2, int x, int y);
-
- int legende (struct gameInit *gInit);
-
- int paint_interface(struct gameInit *gInit);
-
- int giveSkill (struct gameInit *gInit, struct listeSimplementChainee* k, int skill );
-
- int mouse_action (struct gameInit *gInit, int x, int y, int camX , int camY);
-
- int lancement();
-
- int test_blit(SDL_Surface *spr,SDL_Rect* from,SDL_Surface *t,SDL_Rect* to);
-
- int test_FillRect( SDL_Surface *t, SDL_Rect *to, Uint32 ccc);
-
- int miniMap (SDL_Surface *s, int x0, int y0, float coefX, float coefY);
-
- int paint_stencil=0;
-*/
+int yylex();
+void yyerror(struct gameInit *gInit, char *s);
%}
%parse-param { struct gameInit *gInit }
-%union {char* str; int num; struct list_int *ints; struct val *val;}
+%union {char* str; int num; uint32_t uint32; uint32_t *p_uint32;}
%token LEXERROR
+%token EOL
+
%token STYLE
%token NAME
%token SLEM
%token BGCOLOR
%token DEBRISCOLOR
%token PARTICLECOLOR
+
%token AFF
-%token XC
-%token EOL
%token VIR
+
%token <str> IDENT
%token <str> STR
%token <num> INT
+%token <uint32> INTHEX
-%type <ints> extra_vals
-%type <val> val
+%type <p_uint32> particles
%start ini
-
%%
ini:
| ini decl
| ini EOL
-decl: STYLE AFF val {
- int ok=0;
- enum eMapStyle s; // STYLE
- ////-DEBUG-printf("Le style\n");
- if ( $3->type != 0 ) {
- //-DEBUG-printf("ERREUR: Fichier .ini corrompu (style n'est pas de style int)\n");
- } else {
- s=0;
- while(s<NBR_STYLE_MAP){
-
- if ( (strcmp($3->ptr.str,"undefined")!=0)&&
- (strcmp($3->ptr.str,tabString_eMapStyle[s]) == 0 ) ){
-
- ok=2;
- gInit->mapI.map.style=s;
- break;
- }
- ++s;
- }
- if (ok!=2) {
- // BUG ...
- //-DEBUG-printf("Style [%s] invalide (undefined) !!\n",$3->ptr.str);
- exit(2);
- }
- }
-}
-| NAME AFF val {
- ////-DEBUG-printf("Le name \n");
- gInit->mapI.name=$3->ptr.str; //FIXME
-}
-| SLEM AFF val {
- int res=99;
- ////-DEBUG-printf("Le superlemming \n");
- if(strcmp($3->ptr.str,"true")==0){
- res = 1;
- }
- if(strcmp($3->ptr.str,"false")==0){
- res = 0;
- }
- if(res!=99){
- gInit->mapI.map.superLemming=res;
- } else {
- //-DEBUG-printf("superlemming value invalid: %d %s\n",res,$3->ptr.str);
- exit(1);
- }
-}
-| BGCOLOR AFF val {
- //-DEBUG-printf("BGCOLOR XC\n");
- gInit->mapI.map.cmap.bgColor = string_to_Uint32($3->ptr.str,6);
-}
-| DEBRISCOLOR AFF val {
- //-DEBUG-printf("DEBRISCOLOR XC\n");
- gInit->mapI.map.cmap.debrisColor = string_to_Uint32($3->ptr.str,6);
-}
-| PARTICLECOLOR AFF val {
- gInit->mapI.map.cmap.particleColor=tab_of_string_to_Uint32($3->ptr.str,6);
-}
-| IDENT AFF val EOL {
- enum eParaMap t; // parameter of this map
- int i=0,state=0;
- // cette variable sert a derteminer dans quel cas on se trouve
-
- // lvl*.ini => fichier de conf des d'une map de lemming
- // state==0: aucun token detecter
- // state==1: token para de la map detecter
- // state==2: token xPos detecter
- // state==3: token terrain_ detecter
- // state==4: token object_ detecter
- // state==5: token steel_ detecter
-
- // style.ini => fichire de conf des objets animes
- // state==6: token frames_ detecter
- // state==7: token anim_ detecter
- // state==8: token type_ detecter
- // state==9: token sound_ detecter
-
- // state==10: token title detecter FIXME
-
- // lemming.ini => fichier de conf des lemmings
- // state==11: token lemm_ detecter
- // state==12: token pos_ detecter
- // state==13: token mask_ detecter
- // state==14: token imask_ detecter
-
- // liste terrain || objet || steel
- struct listeSimplementChainee **listeItem=NULL;
-
- ////-DEBUG-printf("'%s' ^\n ", $1);
- // donne les parametres de la map
- t=0;
- while(t<IDENT_COUNT){
- if (strcmp($1,tabString_eParaMap[t]) == 0 ){
- state=1;
- gInit->mapI.paraMap[t]=$3->ptr.ints->val;
- break;
- }
- ++t;
- }
- if (state!=1){
-
- if (strcmp($1,"xPos") == 0){
- state=2;
- gInit->mapI.xPos=$3->ptr.ints->val;
- }
-
- if(strncmp($1,"terrain_",8) == 0){
- state=3;
- // init terrain
- if(gInit->t.lt==NULL){
- gInit->t.nbr=0;
-
- } else {
- gInit->t.nbr+=1;
- }
- listeItem=&gInit->t.lt;
- }
-
- if(strncmp($1,"object_",7) == 0){
- state=4;
- // init objet
- if(gInit->o.lo==NULL){
- gInit->o.nbr=0;
- } else {
- gInit->o.nbr+=1;
- }
- listeItem=&gInit->o.lo;
- }
-
- if(strncmp($1,"steel_",6) == 0){
- state=5;
- // init steel
- if(gInit->s.ls==NULL){
- gInit->s.nbr=0;
- } else {
- gInit->o.nbr+=1;
- }
- listeItem=&gInit->s.ls;
- }
-
-
- // Sprite Objet
- if(strncmp($1,"frames_",7) == 0){
- state=6;
- // 1ER CAS
- if(gInit->mapI.map.tilesObjet == 0){//-DEBUG-printf("ERREUR: tilesObjet == 0 => exit to prevent a segFault\n");
- exit(4);
- }
- if(gInit->mapI.map.tabDataSprO == NULL){
- gInit->mapI.map.tabDataSprO= malloc((sizeof(struct spriteObjet))*(gInit->mapI.map.tilesObjet));
- gInit->cptGame[15] = -1;
- }
- gInit->cptGame[15] +=1;
- gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].state=$3->ptr.ints->val;
- }
-
- if(strncmp($1,"anim_",5) == 0){
- state=7;
- gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].anim=$3->ptr.ints->val;
- }
-
- if(strncmp($1,"type_",5) == 0){
- state=8;
- gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].type=$3->ptr.ints->val;
- }
-
- if(strncmp($1,"sound_",6) == 0){
- state=9;
- gInit->mapI.map.tabDataSprO[gInit->cptGame[15]].sound=$3->ptr.ints->val;
- }
- // "style".ini
- if(strncmp($1,"tiles",5) == 0){
- state=10;
- if($3->ptr.ints->val!=gInit->mapI.map.tiles){
- //-DEBUG-printf("BUG: variable parse && nbrFichier are different %d waiting and %d found\n",$3->ptr.ints->val,gInit->mapI.map.tiles);
- exit(2);
- }
- //gInit->mapI.map.tiles=$3->ptr.ints->val;
- }
-
- // lemming .ini
- if(strncmp($1,"lemm_",5)==0){
- state=11;
- // PREMIER CAS
- if(gInit->mapI.lemmingDATA == NULL){
- // 1ER CAS
- gInit->mapI.lemmingDATA=malloc((sizeof(struct lemmingJobAndSprite))*LEM_JOB);
- gInit->cptGame[15] = -1;
- }
- gInit->cptGame[15] +=1;
- gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask=NULL;
- gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask=NULL;
- }
-
- if(strncmp($1,"pos_",4)==0){
- state=12;
- }
-
- if(strncmp($1,"mask_",5)==0){
- state=13;
- gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask=malloc(sizeof(struct lemmingMask));
- }
-
- if(strncmp($1,"imask_",6)==0){
- state=14;
- gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask=malloc(sizeof(struct lemmingImask));
- }
-
- if((state>2 && state<6)||(state>10 && state<15)){
- struct list_int *curr=$3->ptr.ints;
-
- struct listeSimplementChainee *k = malloc(sizeof(struct listeSimplementChainee));
-
- //k->data.pt=NULL;
-
-
- //i=0;
- switch(state){
- // 3: terrain
- case 3 : {i=0;k->data.pt=malloc(sizeof(struct paraTerrain));break;}
- // 4: objet
- case 4 : {
- i=4;
- k->data.po=malloc(sizeof(struct paraObjet));
- k->data.po->cptState=0;
- break;
- }
- // 5 : steel
- case 5 : {i=9;k->ID=0;k->data.ps=malloc(sizeof(struct paraSteel));break;}
-
- case 11 : {i=13;break;}
- case 12 : {i=16;break;}
- case 13 : {i=19;break;}
- case 14 : {i=22;break;}
- // en cas de BUG
- default: //-DEBUG-printf("BUG parser: state = %d\n",state);
- exit(6);
- }
-
- while (curr!=NULL) {
- // //-DEBUG-printf("%i ", curr->val);
- switch(i) {
- // pour les terrains
- case 0: k->ID=curr->val; break;
- case 3: k->x=curr->val; break;
- case 2: k->y=curr->val; break;
- case 1: {
- k->data.pt->modif=curr->val;
- switch(k->data.pt->modif){
- case 0:
- case 2:
- case 4:
- case 6:
- case 8:
- case 10:
- case 12:
- case 14:
- case 15:
- break;
- default: printf("Erreur valeur interdite pour modif Terrain %d\n",k->data.pt->modif);exit (9);
- }
- break;
- }
- // pour les objets
- case 4: k->ID=curr->val; if(k->ID==1){++gInit->mapI.nbrEntry;} break;
- case 8: k->x=curr->val; break;
- case 7: k->y=curr->val; break;
- case 6: {
- k->data.po->paintMode=curr->val;
- switch(k->data.po->paintMode){
- case 0:
- case 2:
- case 4:
- case 8:
- break;
- default: printf("Erreur valeur interdite pour paint Objet %d\n",k->data.po->paintMode);exit (19);
- }
- break;
- }
- case 5: {
- k->data.po->UD = curr->val;
- if((k->data.po->UD!=0)&&(k->data.po->UD!=1)){
- printf("Erreur valeur interdite pour UD Objet %d\n",k->data.po->UD);
- exit (29);
- }
- break;
- }
- // pour les steels
- case 9: k->x=curr->val; break;
- case 12: k->y=curr->val; break;
- case 11: k->data.ps->w = curr->val; break;
- case 10: k->data.ps->h = curr->val; break;
- // pour les lemmings
- // lemm_
- case 13: gInit->mapI.lemmingDATA[gInit->cptGame[15]].state=curr->val;break;
- case 15: gInit->mapI.lemmingDATA[gInit->cptGame[15]].dir=curr->val;break;
- case 14: gInit->mapI.lemmingDATA[gInit->cptGame[15]].anim=curr->val;break;
- // pos_
- case 16: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footX=curr->val;break;
- case 18: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footY=curr->val;break;
- case 17: gInit->mapI.lemmingDATA[gInit->cptGame[15]].footSize=curr->val;break;
- // mask_
- case 19: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->stateM=curr->val;break;
- case 21: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->dirM=curr->val;break;
- case 20: gInit->mapI.lemmingDATA[gInit->cptGame[15]].mask->cooldown=curr->val;break;
- // imask_
- case 22: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->stateI=curr->val;break;
- case 23: gInit->mapI.lemmingDATA[gInit->cptGame[15]].imask->dirI=curr->val;break;
- // en cas de BUG
- default: //-DEBUG-printf("BUG parser i = %d\n",i);
- exit(7);
+decl: STYLE AFF STR {}
+| NAME AFF STR { gInit->mapI.name = $3; }
+| SLEM AFF INT {}
+| BGCOLOR AFF INTHEX { gInit->mapI.map.cmap.bgColor = $3; }
+| DEBRISCOLOR AFF INTHEX { gInit->mapI.map.cmap.debrisColor = $3; }
+| PARTICLECOLOR AFF particles { gInit->mapI.map.cmap.particleColor = $3; }
+| IDENT AFF STR {}
+
+particles: INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX {
+ $$=malloc(16*sizeof(uint32_t));
+ $$[0]=$1; $$[1]=$3; $$[2]=$5; $$[3]=$7; $$[4]=$9; $$[5]=$11; $$[6]=$13; $$[7]=$15 ;$$[8]=$17; $$[9]=$19; $$[10]=$21; $$[11]=$23; $$[12]=$25; $$[13]=$27; $$[14]=$29; $$[15]=$31;
}
- curr=curr->next;
- ++i;
- }
- // fichier lvl*.ini
- if(state>2 && state<6){
- k->next=*listeItem;
- *listeItem=k;
- }
- //free(curr);
- } else {
-
- if(state == 0) {
- //-DEBUG-printf("BUG: no parse for this token : %s \n",$1);
- exit(8);
- }
- }
- } // FIN ok==0
-}
-
-val: INT extra_vals {
- // //-DEBUG-printf("creation de liste int ... \n");
- $$=malloc(sizeof(struct val));
- $$->type=1;
- $$->ptr.ints=malloc(sizeof(struct list_int));
- $$->ptr.ints->val=$1;
- $$->ptr.ints->next=$2;
- // //-DEBUG-printf("liste int %d\n",$1);
- }
-| STR {
- // //-DEBUG-printf("creation de liste STR ...\n");
- $$=malloc(sizeof(struct val));
- $$->type=0;
-
- $$->ptr.str=malloc(sizeof(char)*strlen($1)+1);
- strcpy($$->ptr.str, $1);
- // //-DEBUG-printf("liste STR %s\n",$1);
-}
-extra_vals: { $$=NULL; }
-| extra_vals VIR INT { //FIXME : => VIR INT extra_vals
- $$=malloc(sizeof(struct list_int));
- $$->val=$3;
- $$->next=$1;
-}
-
%%
void yyerror(struct gameInit *gInit, char *s) {
fprintf(stderr, "(stdin):%i: error: %s\n", yylineno, s);
- exit(9);
-}
-/*
-#include "fonctions_integrees.c"
-#include "fonctions_non_integrees.c"
-
-
-int main (int argc, char **argv)
-{
- int res,i,num,lt;
- char *temp,*temp0;
- //Uint32 ctest;
- //int j,k;
- //argc=3;
- //argv[1]="1";
- //argv[2]="72";
- if (argc<2 || argc>3) {
- fprintf(stderr, "Usage %s [Option] <Filename>\n",argv[0]);
- fprintf(stderr,"\nOption:\n\t- 1: on se place dans le dossier 1_orig\n");
- fprintf(stderr,"\t- 2: on se place dans le dossier 2_ohno\n");
- fprintf(stderr,"\t- 3: on se place dans le dossier 3_test\n");
- fprintf(stderr,"Filename:\n\t- numero du lvl (ex: 1, 4, 13, 65b )\n");
- return(44);
- }
- if (argc==3) {
- i=1;
- num=atoi(argv[2]);
- if (num >= 10) ++i;
- if (num >= 100) ++i;
- if (num >= 1000){
- fprintf(stderr,"Too many lvl (%d > 999)\n",num);
- return(45);
- }
- temp0=malloc(sizeof(char)*(3-i));// => [00] [0] []
- switch(i){
- case 1 : temp0 = "00";break;
- case 2 : temp0 = "0";break;
- case 3 : temp0 = "";break;
- default:fprintf(stderr,"BUG: i[=%d] > 3 ERREUR\n",i);return(46);
- }
-
- lt = (strlen("../../../../trunk/level/1_orig/lvl.ini")+5);// + 4 : 4 chiffres lvl.ini, +1 : string
- temp=malloc(sizeof(char)*lt);
- switch(atoi(argv[1])){
- case 1 : sprintf(temp,"../../../../trunk/level/1_orig/lvl0%s%d.ini",temp0,num);break;
- case 2 : sprintf(temp,"../../../../trunk/level/2_ohno/lvl1%s%d.ini",temp0,num);break;
- case 3 : sprintf(temp,"../../../../trunk/level/3_test/lvl2%s%d.ini",temp0,num);break;
- default:fprintf(stderr,"ERREUR: dossier [%d] inconnu\n",atoi(argv[1]));return(47);
- }
- } else {
- temp=malloc(sizeof(char)*(strlen(argv[1])+1));
- sprintf(temp,"%s",argv[1]);
- }
- yyin=fopen(temp, "r");
- //yyin=fopen("./lvlTest01.ini", "r");
- if (yyin==NULL) {
- fprintf(stderr,"Filename INVALIDE: %s\n",temp);
- perror("Impossible d'ouvrir le niveau"); return(48); }
-
-
- res=lancement();
- printf("code retour %d\n",res);
- //fclose(yyin); fait dans lancement
-
- return res;
-
+ gInit->parseError=1;
}
-*/
diff --git a/src/test/test_parse.c b/src/test/test_parse.c
new file mode 100644
index 0000000..ed7987d
--- /dev/null
+++ b/src/test/test_parse.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include "SDL/SDL.h"
+#include "../parser/y.tab.h"
+#include "../parser/ginit.h"
+
+extern FILE *yyin;
+extern int yyparse(struct gameInit *gInit);
+
+int main(int argc, char **argv) {
+ char *filepath=NULL;
+ struct gameInit *gInit=NULL;
+
+ if (argc<2) {
+ fprintf(stderr, "Usage %s <ini_file>\n", argv[0]);
+ return 1;
+ }
+ filepath=argv[1];
+
+ yyin=fopen(filepath, "r");
+ if (yyin == NULL ) {
+ fprintf(stderr, "main(), Could not open '%s'\n", filepath);
+ return 2;
+ }
+
+ printf("Parsing '%s'\n", filepath);
+ yyparse(gInit);
+ printf("End of parse ('%s')\n", filepath);
+
+ fclose(yyin);
+ return 0;
+}
diff --git a/src/test/test_parse.sh b/src/test/test_parse.sh
new file mode 100755
index 0000000..4cc8323
--- /dev/null
+++ b/src/test/test_parse.sh
@@ -0,0 +1 @@
+gcc -Wall --std=c99 -D_POSIX_SOURCE -g test_parse.c ../parser/y.tab.c ../parser/lex.yy.c