From ec28a1aed6faf7585db53034e93d66ccc9d62456 Mon Sep 17 00:00:00 2001 From: Vitaly Driedfruit Date: Thu, 18 Apr 2013 15:36:56 +0400 Subject: [PATCH] Switch to RWops-based file reader for css. --- src/runeconf.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/runeconf.c b/src/runeconf.c index 9254bfb..86f2c01 100644 --- a/src/runeconf.c +++ b/src/runeconf.c @@ -533,17 +533,36 @@ dom_iter rcfg_house_iterator = { int cfg_load(const char *filename) { - css_ruleset *mainCSS; + css_ruleset *sheet; - mainCSS = css_load_file(filename); - if (mainCSS == NULL) return -1; + SDL_RWops *file; + + file = SDL_RWFromFile(filename, "rb"); + if (file == NULL) return -1; + + css_parser *state = css_parser_create(); + + char buf[1024]; + int n, err; + while (1) { + n = SDL_RWread(file, buf, sizeof(char), sizeof(buf)); + if (n <= 0) break; + + err = css_parse(state, buf, n); + if (err) break; + } + + SDL_RWclose(file); + + sheet = css_parser_done(state); + if (sheet == NULL) return -1; num_bunits = MAX_BUNITS; num_bhouses = MAX_BHOUSES; //css_fprintf(stdout, mainCSS); - css_cascade(&rcfg_units_iterator, &bunits, mainCSS); - css_cascade(&rcfg_house_iterator, &bhouses, mainCSS); + css_cascade(&rcfg_units_iterator, &bunits, sheet); + css_cascade(&rcfg_house_iterator, &bhouses, sheet); return 0; } \ No newline at end of file -- 2.11.4.GIT