plan to eliminate xinclude use, move to single config file with includes.

This commit is contained in:
Enno Rehling 2018-02-04 18:25:38 +01:00
parent 2d7d46d3ac
commit a316283a6d
4 changed files with 60 additions and 37 deletions

View File

@ -3,7 +3,9 @@
"keywords.json",
"calendar.json",
"prefixes.json",
"e2/terrains.json"
"e2/terrains.json",
"e2/rules.xml",
"e2/locales.xml"
],
"disabled": [
"jsreport"

View File

@ -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()

View File

@ -887,21 +887,15 @@ static void json_races(cJSON *json) {
const char * json_relpath;
static void json_include(cJSON *json) {
cJSON *child;
if (json->type != cJSON_Array) {
log_error("config is not a json array: %d", json->type);
return;
}
for (child = json->child; child; child = child->next) {
static void include_json(const char *filename) {
FILE *F;
if (json_relpath) {
char name[PATH_MAX];
path_join(json_relpath, child->valuestring, name, sizeof(name));
path_join(json_relpath, filename, name, sizeof(name));
F = fopen(name, "r");
}
else {
F = fopen(child->valuestring, "r");
F = fopen(filename, "r");
}
if (F) {
long pos;
@ -923,12 +917,38 @@ static void json_include(cJSON *json) {
cJSON_Delete(config);
}
else {
log_error("invalid JSON, could not parse %s", child->valuestring);
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) {
log_error("config is not a json array: %d", json->type);
return;
}
for (child = json->child; child; child = child->next) {
const char * filename = child->valuestring;
if (strstr(filename, ".xml") != NULL) {
include_xml(filename);
}
else {
include_json(filename);
}
}
}
void json_config(cJSON *json) {

View File

@ -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;
}
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);