diff --git a/conf/e2/config.json b/conf/e2/config.json index 5d29cd1f5..863a64c0a 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -3,7 +3,9 @@ "keywords.json", "calendar.json", "prefixes.json", - "e2/terrains.json" + "e2/terrains.json", + "e2/rules.xml", + "e2/locales.xml" ], "disabled": [ "jsreport" diff --git a/scripts/eressea/xmlconf.lua b/scripts/eressea/xmlconf.lua index 84f29eceb..1b70b0ccd 100644 --- a/scripts/eressea/xmlconf.lua +++ b/scripts/eressea/xmlconf.lua @@ -5,7 +5,7 @@ end if config.rules then local rules = config.rules .. '/' assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data") - assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") - assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") +-- assert(0 == read_xml(confdir .. rules .. 'rules.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") +-- assert(0 == read_xml(confdir .. rules .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?") end eressea.game.reset() diff --git a/src/jsonconf.c b/src/jsonconf.c index 3c5411b9d..15cc563b6 100644 --- a/src/jsonconf.c +++ b/src/jsonconf.c @@ -887,6 +887,53 @@ static void json_races(cJSON *json) { const char * json_relpath; +static void include_json(const char *filename) { + FILE *F; + if (json_relpath) { + char name[PATH_MAX]; + path_join(json_relpath, filename, name, sizeof(name)); + F = fopen(name, "r"); + } + else { + F = fopen(filename, "r"); + } + if (F) { + long pos; + fseek(F, 0, SEEK_END); + pos = ftell(F); + rewind(F); + if (pos > 0) { + cJSON *config; + char *data; + size_t sz; + + data = malloc(pos + 1); + sz = fread(data, 1, (size_t)pos, F); + data[sz] = 0; + config = cJSON_Parse(data); + free(data); + if (config) { + json_config(config); + cJSON_Delete(config); + } + else { + log_error("invalid JSON, could not parse %s", filename); + } + } + fclose(F); + } +} + +static void include_xml(const char *filename) { + char name[PATH_MAX]; + + if (json_relpath) { + path_join(json_relpath, filename, name, sizeof(name)); + filename = name; + } + read_xml(filename, NULL); +} + static void json_include(cJSON *json) { cJSON *child; if (json->type != cJSON_Array) { @@ -894,39 +941,12 @@ static void json_include(cJSON *json) { return; } for (child = json->child; child; child = child->next) { - FILE *F; - if (json_relpath) { - char name[PATH_MAX]; - path_join(json_relpath, child->valuestring, name, sizeof(name)); - F = fopen(name, "r"); + const char * filename = child->valuestring; + if (strstr(filename, ".xml") != NULL) { + include_xml(filename); } else { - F = fopen(child->valuestring, "r"); - } - if (F) { - long pos; - fseek(F, 0, SEEK_END); - pos = ftell(F); - rewind(F); - if (pos > 0) { - cJSON *config; - char *data; - size_t sz; - - data = malloc(pos + 1); - sz = fread(data, 1, (size_t)pos, F); - data[sz] = 0; - config = cJSON_Parse(data); - free(data); - if (config) { - json_config(config); - cJSON_Delete(config); - } - else { - log_error("invalid JSON, could not parse %s", child->valuestring); - } - } - fclose(F); + include_json(filename); } } } diff --git a/src/util/xml.c b/src/util/xml.c index ec72179c3..21480aece 100644 --- a/src/util/xml.c +++ b/src/util/xml.c @@ -112,7 +112,7 @@ int read_xml(const char *filename, const char *catalog) { xml_reader *reader = xmlReaders; xmlDocPtr doc; - int result; + int result = 0; if (catalog) { xmlLoadCatalog(catalog); @@ -122,8 +122,9 @@ int read_xml(const char *filename, const char *catalog) log_error("could not open '%s'\n", filename); return -1; } - - result = xmlXIncludeProcessFlags(doc, XML_PARSE_XINCLUDE | XML_PARSE_NONET | XML_PARSE_PEDANTIC | XML_PARSE_COMPACT); + if (catalog) { + result = xmlXIncludeProcessFlags(doc, XML_PARSE_XINCLUDE | XML_PARSE_NONET | XML_PARSE_PEDANTIC | XML_PARSE_COMPACT); + } if (result >= 0) { while (reader != NULL) { int i = reader->callback(doc);