summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <lpouzenc@gmail.com>2013-07-11 22:22:34 +0200
committerLudovic Pouzenc <lpouzenc@gmail.com>2013-07-11 22:22:34 +0200
commit22ef62efac76adb97bd14be2d897823a108a154d (patch)
tree8cca6496080cedc6e5f7a82fde2fb4411cb5bb23
parent4a11294dd17f3e087477057a85add7b9b6b4ea5d (diff)
downloadmplemmings-22ef62efac76adb97bd14be2d897823a108a154d.tar.gz
mplemmings-22ef62efac76adb97bd14be2d897823a108a154d.tar.bz2
mplemmings-22ef62efac76adb97bd14be2d897823a108a154d.zip
Debut de parser pour les fichiers styles/*.ini. Part en segfault, surement boucle infinie.
-rw-r--r--Makefile.am6
-rw-r--r--src/include/parser.h2
-rw-r--r--src/parser.c153
3 files changed, 158 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 4b613ea..09c4d66 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,10 +4,10 @@ ACLOCAL_AMFLAGS = -I m4 --install
bin_PROGRAMS = mplemmings mplemmings_ds
# Target list of programs that will not installed anywhere (dev helping tiny programs)
-noinst_PROGRAMS = sbmoose sbsprite initest
+noinst_PROGRAMS = sbmoose sbsprite initest inistyle
# Use configure detected necessary cflags and ldflags
-AM_CFLAGS = $(DEPS_CFLAGS)
+AM_CFLAGS = -I src/include/ $(DEPS_CFLAGS)
LIBS = $(DEPS_LIBS)
# Per target specs
@@ -16,6 +16,8 @@ mplemmings_ds_SOURCES = src/mplemmings_ds.c
sbmoose_SOURCES = src/sandbox/moose.c
sbsprite_SOURCES = src/sandbox/sprite.c
initest_SOURCES = src/minini/dev/minIni.c src/minini/dev/my_SDL_stdinc.c src/minini/dev/test.c
+inistyle_SOURCES = src/minini/dev/minIni.c src/minini/dev/my_SDL_stdinc.c src/parser.c
+inistyle_CPPFLAGS = -I src/minini/dev/
#sbmoose_CPPFLAGS = -DDEBUG
# Extra files to be shipped in the tarball (make dist)
diff --git a/src/include/parser.h b/src/include/parser.h
index 5be656d..0a1d2d4 100644
--- a/src/include/parser.h
+++ b/src/include/parser.h
@@ -18,6 +18,6 @@
#define STEEL_MAX_WIDTH 256
#define STEEL_MAX_HEIGHT 256
-int mpl_ini_parse(gameIni_t *gIni);
+int loadIni(gameIni_t *gIni, const char *filepath);
#endif /*PARSER_H*/
diff --git a/src/parser.c b/src/parser.c
new file mode 100644
index 0000000..44ab4ed
--- /dev/null
+++ b/src/parser.c
@@ -0,0 +1,153 @@
+#include "parser.h"
+
+#include "minIni.h"
+
+/*
+long ini_getl(const mTCHAR *Section, const mTCHAR *Key, long DefValue, const mTCHAR *Filename);
+int ini_gets(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *DefValue, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
+
+int ini_getsection(int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
+int ini_getkey(const mTCHAR *Section, int idx, mTCHAR *Buffer, int BufferSize, const mTCHAR *Filename);
+
+typedef int (*INI_CALLBACK)(const mTCHAR *Section, const mTCHAR *Key, const mTCHAR *Value, const void *UserData);
+int ini_browse(INI_CALLBACK Callback, const void *UserData, const mTCHAR *Filename);
+*/
+
+typedef struct {
+ int need_2pass;
+ gameIni_t *gIni;
+} parserState_t;
+
+int callback_pass1(const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData);
+int callback_pass2(const mTCHAR *Section, const mTCHAR *key, const mTCHAR *value, const void *userData);
+
+
+int main() {
+ gameIni_t gIni;
+ return loadIni(&gIni,"/home/lpouzenc/Bureau/USB/lem/2010-netlemmings/trunk/styles/brick/brick.ini");
+}
+
+int loadIni(gameIni_t *gIni, const char *filepath) {
+ int res;
+ parserState_t state;
+ const void *UserData=(void *)&state;
+ state.gIni=gIni;
+
+ (void) SDL_memset(&state,0,sizeof(parserState_t));
+ (void) SDL_memset(gIni,0,sizeof(gameIni_t));
+
+ res=ini_browse(callback_pass1, UserData, filepath);
+ if (res!=0) return res;
+ if (state.need_2pass) {
+ res=ini_browse(callback_pass2, UserData, filepath);
+ }
+}
+
+uint32_t hextext2rgb(const char str[]) {
+ return 42; //FIXME
+}
+
+/*#define IS(str) if (SDL_strcasecmp(Key,str)==0)
+#define PREFIX(str) if (SDL_strncasecmp(Key,str)==0)
+*/
+int callback_pass1(const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData) {
+ gameIni_t *gIni = ((parserState_t*) userData)->gIni;
+
+ if (SDL_strcasecmp(key,"bgcolor")==0)
+ {gIni->style.bgColor = hextext2rgb(value); return 0;}
+ if (SDL_strcasecmp(key,"debrisColor")==0)
+ {gIni->style.debrisColor = hextext2rgb(value); return 0;}
+ if (SDL_strcasecmp(key,"particleColor")==0)
+ {
+ char *wordBoundary;
+ int i=0;
+ ((parserState_t*) userData)->need_2pass=1;
+
+ while ( strlen(value)>0 && (wordBoundary=strchr(value,',')) != NULL ) {
+ *wordBoundary='\0';
+ //gIni->style.particleColor[i++]=hextext2rgb(value); // 2nd pass
+ value = wordBoundary+1;
+ }
+ // Parse the last one
+ //gIni->style.particleColor[i++]=hextext2rgb(value); //2nd pass
+
+ if (gIni->style.particleColor != NULL ) {
+ return 1;
+ }
+
+ gIni->style.particleColor=SDL_calloc(i,sizeof(uint32_t));
+ if ( ! gIni->style.particleColor ) {
+ return 2;
+ }
+ gIni->style.particleColorCount=i;
+
+ return 0;
+ }
+ if (SDL_strcasecmp(key,"tiles")==0) {
+ int v = atoi(value);
+ if ( v<0 || v>MAX_OBJECT_TYPES) return 3;
+ gIni->style.tiles = v;
+ return 0;
+ }
+
+ if (SDL_strncasecmp(key,"frames_", 7) == 0) {
+ int i = atoi(value+7);
+ if ( i<0 || i>=gIni->style.tiles) return 4;
+
+ int v = atoi(value);
+ if ( v<0 || v>MAX_OBJECT_FRAMES) return 5;
+
+ gIni->style.objects[i].frames = v;
+ return 0;
+ }
+
+ if (SDL_strncasecmp(key,"anim_", 5) == 0) {
+ int i = atoi(value+5);
+ if ( i<0 || i>=gIni->style.tiles) return 6;
+
+ int v = atoi(value);
+ if ( v<0 || v>3) return 7;
+
+ gIni->style.objects[i].anim = v;
+ return 0;
+ }
+
+ if (SDL_strncasecmp(key,"type_", 5) == 0) {
+ int i = atoi(value+5);
+ if ( i<0 || i>=gIni->style.tiles) return 8;
+
+ int v = atoi(value);
+ if (! (v==0 || v==32 || (v>=3 && v<=8))) return 9;
+
+ gIni->style.objects[i].type = v;
+ return 0;
+ }
+
+ if (SDL_strncasecmp(key,"sound_", 6) == 0) {
+ int i = atoi(value+6);
+ if ( i<0 || i>=gIni->style.tiles) return 10;
+
+ int v = atoi(value);
+ if ( v<0 || v>MAX_SOUNDS_COUNT) return 11;
+
+ gIni->style.objects[i].frames = v;
+ return 0;
+ }
+
+ if (SDL_strncasecmp(key,"frames_", 7) == 0) {
+ int i = atoi(value+7);
+ if ( i<0 || i>=gIni->style.tiles) return 4;
+
+ int v = atoi(value);
+ if ( v<0 || v>MAX_OBJECT_FRAMES) return 5;
+
+ gIni->style.objects[i].frames = v;
+ return 0;
+ }
+
+ return -1;
+}
+
+int callback_pass2(const mTCHAR *section, const mTCHAR *key, const mTCHAR *value, const void *userData) {
+
+}