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 79b54060f9
commit 92f82c3608
4 changed files with 60 additions and 37 deletions

View File

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

View File

@ -5,7 +5,7 @@ end
if config.rules then if config.rules then
local rules = config.rules .. '/' local rules = config.rules .. '/'
assert(0 == eressea.config.read(rules .. 'config.json', confdir), "could not read JSON data") 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 .. '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 .. 'locales.xml', confdir .. rules .. 'catalog.xml'), "could not load XML data, did you compile with LIBXML2 ?")
end end
eressea.game.reset() eressea.game.reset()

View File

@ -887,21 +887,15 @@ static void json_races(cJSON *json) {
const char * json_relpath; const char * json_relpath;
static void json_include(cJSON *json) { static void include_json(const char *filename) {
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) {
FILE *F; FILE *F;
if (json_relpath) { if (json_relpath) {
char name[PATH_MAX]; 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"); F = fopen(name, "r");
} }
else { else {
F = fopen(child->valuestring, "r"); F = fopen(filename, "r");
} }
if (F) { if (F) {
long pos; long pos;
@ -923,12 +917,38 @@ static void json_include(cJSON *json) {
cJSON_Delete(config); cJSON_Delete(config);
} }
else { else {
log_error("invalid JSON, could not parse %s", child->valuestring); log_error("invalid JSON, could not parse %s", filename);
} }
} }
fclose(F); 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) { void json_config(cJSON *json) {

View File

@ -112,7 +112,7 @@ int read_xml(const char *filename, const char *catalog)
{ {
xml_reader *reader = xmlReaders; xml_reader *reader = xmlReaders;
xmlDocPtr doc; xmlDocPtr doc;
int result; int result = 0;
if (catalog) { if (catalog) {
xmlLoadCatalog(catalog); xmlLoadCatalog(catalog);
@ -122,8 +122,9 @@ int read_xml(const char *filename, const char *catalog)
log_error("could not open '%s'\n", filename); log_error("could not open '%s'\n", filename);
return -1; return -1;
} }
if (catalog) {
result = xmlXIncludeProcessFlags(doc, XML_PARSE_XINCLUDE | XML_PARSE_NONET | XML_PARSE_PEDANTIC | XML_PARSE_COMPACT); result = xmlXIncludeProcessFlags(doc, XML_PARSE_XINCLUDE | XML_PARSE_NONET | XML_PARSE_PEDANTIC | XML_PARSE_COMPACT);
}
if (result >= 0) { if (result >= 0) {
while (reader != NULL) { while (reader != NULL) {
int i = reader->callback(doc); int i = reader->callback(doc);