verify xml loading, fix remaining files for e2.

This commit is contained in:
Enno Rehling 2018-02-06 18:46:28 +01:00
parent 434b7ae29e
commit df255b886a
25 changed files with 397 additions and 364 deletions

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<!-- <!--
_d: dativ (wir erklären allen /Schlümpfen/ den Krieg) _d: dativ (wir erklären allen /Schlümpfen/ den Krieg)
@ -7483,3 +7484,4 @@
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<eressea>
<strings> <strings>
<!-- <!--
Due to extreme lazyness on Enno's part, this file doesn't contain everything. Due to extreme lazyness on Enno's part, this file doesn't contain everything.
@ -1661,3 +1662,4 @@
<text locale="en">mistletoes</text> <text locale="en">mistletoes</text>
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<messages> <messages>
<message name="nr_insectwinter" section="nr"> <message name="nr_insectwinter" section="nr">
<text locale="de">Es ist Winter, und Insekten können nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren.</text> <text locale="de">Es ist Winter, und Insekten können nur in Wüsten oder mit Hilfe des Nestwärme-Tranks Personen rekrutieren.</text>
@ -1654,35 +1655,6 @@
<text locale="de">"Der Eisberg $region($region) treibt nach $direction($dir)."</text> <text locale="de">"Der Eisberg $region($region) treibt nach $direction($dir)."</text>
<text locale="en">"The iceberg $region($region) drifts $direction($dir)."</text> <text locale="en">"The iceberg $region($region) drifts $direction($dir)."</text>
</message> </message>
<message name="setjihad" section="events">
<type>
<arg name="race" type="race"/>
</type>
<text locale="de">"Wir erklären allen $race($race,2) den heiligen Krieg."</text>
<text locale="en">"We declare jihad on all $race($race,2)."</text>
</message>
<message name="pray_success" section="events">
<type>
<arg name="unit" type="unit"/>
</type>
<text locale="de">"Die Götter erhören $unit($unit)."</text>
<text locale="en">"The Gods have listened to $unit($unit)."</text>
</message>
<message name="new_fspecial_level" section="events">
<type>
<arg name="special" type="string"/>
<arg name="level" type="int"/>
</type>
<text locale="de">"Die Götter gewähren uns die Kraft eines $special($int($level))."</text>
<text locale="en">"The Gods grant us the powers of $special ($int($level))."</text>
</message>
<message name="new_fspecial" section="events">
<type>
<arg name="special" type="string"/>
</type>
<text locale="de">"Die Götter gewähren uns die Kraft eines ${special}."</text>
<text locale="en">"The Gods grant us the powers of ${special}."</text>
</message>
<message name="casualties" section="battle"> <message name="casualties" section="battle">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>
@ -8295,3 +8267,4 @@
</message> </message>
</messages> </messages>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<eressea>
<spellbook name="cerddor"> <spellbook name="cerddor">
<entry spell="song_of_healing" level="2" /> <entry spell="song_of_healing" level="2" />
<entry spell="song_of_confusion" level="4" /> <entry spell="song_of_confusion" level="4" />
@ -36,3 +37,4 @@
<entry spell="create_roqf" level="11" /> <entry spell="create_roqf" level="11" />
<entry spell="blabbermouth" level="4" /> <entry spell="blabbermouth" level="4" />
</spellbook> </spellbook>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1" ?> <?xml version="1.0" encoding="iso-8859-1" ?>
<eressea>
<spellbook name="draig"> <spellbook name="draig">
<entry spell="fireball" level="2" /> <entry spell="fireball" level="2" />
<entry spell="combatrust" level="6" /> <entry spell="combatrust" level="6" />
@ -30,3 +31,4 @@
<entry spell="create_firesword" level="12" /> <entry spell="create_firesword" level="12" />
<entry spell="create_trollbelt" level="9" /> <entry spell="create_trollbelt" level="9" />
</spellbook> </spellbook>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<eressea>
<spellbook name="gray"> <spellbook name="gray">
<entry spell="acidrain" level="8" /> <entry spell="acidrain" level="8" />
<entry spell="airship" level="6" /> <entry spell="airship" level="6" />
@ -165,3 +166,4 @@
<entry spell="wolfhowl" level="7" /> <entry spell="wolfhowl" level="7" />
<entry spell="wyrm_transformation" level="1" /> <entry spell="wyrm_transformation" level="1" />
</spellbook> </spellbook>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<eressea>
<spellbook name="gwyrrd"> <spellbook name="gwyrrd">
<entry spell="hail" level="3" /> <entry spell="hail" level="3" />
<entry spell="rustweapon" level="3" /> <entry spell="rustweapon" level="3" />
@ -39,3 +40,4 @@
<entry spell="create_aots" level="6" /> <entry spell="create_aots" level="6" />
<entry spell="create_magicherbbag" level="5" /> <entry spell="create_magicherbbag" level="5" />
</spellbook> </spellbook>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<eressea>
<spellbook name="illaun"> <spellbook name="illaun">
<entry spell="bad_dreams" level="10" /> <entry spell="bad_dreams" level="10" />
<entry spell="gooddreams" level="8" /> <entry spell="gooddreams" level="8" />
@ -27,4 +28,4 @@
<entry spell="create_invisibility_sphere" level="13" /> <entry spell="create_invisibility_sphere" level="13" />
<entry spell="readmind" level="7" /> <entry spell="readmind" level="7" />
</spellbook> </spellbook>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" ?> <?xml version="1.0" ?>
<eressea>
<spellbook name="tybied"> <spellbook name="tybied">
<entry spell="auratransfer" level="5" /> <entry spell="auratransfer" level="5" />
<entry spell="antimagiczone" level="5" /> <entry spell="antimagiczone" level="5" />
@ -34,3 +35,4 @@
<entry spell="create_rop" level="9" /> <entry spell="create_rop" level="9" />
<entry spell="create_bagofholding" level="10" /> <entry spell="create_bagofholding" level="10" />
</spellbook> </spellbook>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<namespace name="spellinfo"> <namespace name="spellinfo">
<string name="concealing_aura"> <string name="concealing_aura">
@ -117,3 +118,4 @@
</string> </string>
</namespace> </namespace>
</strings> </strings>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<namespace name="spellinfo"> <namespace name="spellinfo">
<string name="headache"> <string name="headache">
@ -403,3 +404,4 @@
<text locale="fr">amulettes du chaton</text> <text locale="fr">amulettes du chaton</text>
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<string name="dragon_postfix_0"> <string name="dragon_postfix_0">
<text locale="de">der Weise</text> <text locale="de">der Weise</text>
</string> </string>
@ -91,5 +91,5 @@
<string name="dragon_postfix_29"> <string name="dragon_postfix_29">
<text locale="de">die Schöne</text> <text locale="de">die Schöne</text>
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<string name="ghoul_prefix_0"> <string name="ghoul_prefix_0">
<text locale="de">Faulende</text> <text locale="de">Faulende</text>
</string> </string>
@ -113,3 +113,4 @@
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<string name="skeleton_prefix_0"> <string name="skeleton_prefix_0">
<text locale="de">Klapperige</text> <text locale="de">Klapperige</text>
</string> </string>
@ -117,5 +117,5 @@
<string name="skeleton_postfix_13"> <string name="skeleton_postfix_13">
<text locale="de">aus der Unterwelt</text> <text locale="de">aus der Unterwelt</text>
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<string name="undead_prefix_0"> <string name="undead_prefix_0">
<text locale="de">Grausige</text> <text locale="de">Grausige</text>
@ -154,3 +155,4 @@
</string> </string>
</strings> </strings>
</eressea>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<eressea>
<strings> <strings>
<string name="zombie_prefix_0"> <string name="zombie_prefix_0">
<text locale="de">Faulende</text> <text locale="de">Faulende</text>
@ -106,3 +107,4 @@
</string> </string>
</strings> </strings>
</eressea>

View File

@ -18,6 +18,13 @@ require 'tests.e2'
require 'lunit' require 'lunit'
rng.inject(0) rng.inject(0)
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.ship.damage.nocrew", "0")
eressea.settings.set("rules.ship.drifting", "0")
eressea.settings.set("rules.ship.storms", "0")
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
rules = require('eressea.' .. config.rules) rules = require('eressea.' .. config.rules)
result = lunit.main() result = lunit.main()
return result.errors + result.failed return result.errors + result.failed

View File

@ -19,6 +19,13 @@ require 'lunit'
rng.inject(0) rng.inject(0)
eressea.settings.set("rules.alliances", "0") eressea.settings.set("rules.alliances", "0")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.ship.damage.nocrew", "0")
eressea.settings.set("rules.ship.drifting", "0")
eressea.settings.set("rules.ship.storms", "0")
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
rules = require('eressea.' .. config.rules) rules = require('eressea.' .. config.rules)
result = lunit.main() result = lunit.main()
return result.errors + result.failed return result.errors + result.failed

View File

@ -897,10 +897,10 @@ static int tolua_get_spells(lua_State * L)
return tolua_selist_push(L, "spell_list", "spell", spells); return tolua_selist_push(L, "spell_list", "spell", spells);
} }
static int init_data(const char *filename, const char *catalog) static int init_data(const char *filename)
{ {
int l; int l;
l = read_xml(filename, catalog); l = read_xml(filename);
reset_locales(); reset_locales();
if (l) { if (l) {
return l; return l;
@ -915,8 +915,7 @@ static int init_data(const char *filename, const char *catalog)
int tolua_read_xml(lua_State * L) int tolua_read_xml(lua_State * L)
{ {
const char *filename = tolua_tostring(L, 1, "config.xml"); const char *filename = tolua_tostring(L, 1, "config.xml");
const char *catalog = tolua_tostring(L, 2, "catalog.xml"); lua_pushinteger(L, init_data(filename));
lua_pushinteger(L, init_data(filename, catalog));
return 1; return 1;
} }

View File

@ -27,7 +27,7 @@ int main(int argc, char **argv) {
if (argc < 4) return usage(); if (argc < 4) return usage();
xmlfile = argv[2]; xmlfile = argv[2];
catalog = argv[3]; catalog = argv[3];
read_xml(xmlfile, catalog); read_xml(xmlfile);
write_rules("rules.dat"); write_rules("rules.dat");
return 0; return 0;
} }

View File

@ -928,7 +928,7 @@ static const char * uri_to_file(const char * uri, char *name, size_t size) {
return path; return path;
} }
static void include_json(const char *uri) { static int include_json(const char *uri) {
FILE *F; FILE *F;
char name[PATH_MAX]; char name[PATH_MAX];
const char *filename = uri_to_file(uri, name, sizeof(name)); const char *filename = uri_to_file(uri, name, sizeof(name));
@ -955,19 +955,22 @@ static void include_json(const char *uri) {
} }
else { else {
log_error("could not parse JSON from %s", uri); log_error("could not parse JSON from %s", uri);
return -1;
} }
} }
fclose(F); fclose(F);
} }
return 0;
} }
static void include_xml(const char *uri) { static int include_xml(const char *uri) {
char name[PATH_MAX]; char name[PATH_MAX];
const char *filename = uri_to_file(uri, name, sizeof(name)); const char *filename = uri_to_file(uri, name, sizeof(name));
int err = read_xml(filename, NULL); int err = read_xml(filename);
if (err != 0) { if (err < 0) {
log_error("could not parse XML from %s", uri); log_error("could not parse XML from %s", uri);
} }
return err;
} }
static void json_include(cJSON *json) { static void json_include(cJSON *json) {
@ -978,12 +981,16 @@ static void json_include(cJSON *json) {
} }
for (child = json->child; child; child = child->next) { for (child = json->child; child; child = child->next) {
const char *uri = child->valuestring; const char *uri = child->valuestring;
int err;
if (strstr(uri, ".xml") != NULL) { if (strstr(uri, ".xml") != NULL) {
include_xml(uri); err = include_xml(uri);
} }
else { else {
include_json(uri); err = include_json(uri);
}
if (err != 0) {
log_error("no data found in %s", uri);
} }
} }
} }

View File

@ -4085,7 +4085,12 @@ static void reset_game(void)
void turn_begin(void) void turn_begin(void)
{ {
int start = first_turn();
assert(turn >= 0); assert(turn >= 0);
if (turn < start) {
/* this should only happen during tests */
turn = start;
}
++turn; ++turn;
reset_game(); reset_game();
} }

View File

@ -77,7 +77,6 @@ double xml_fvalue(xmlNodePtr node, const char *name, double dflt)
/* libxml includes */ /* libxml includes */
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/xinclude.h>
typedef struct xml_reader { typedef struct xml_reader {
struct xml_reader *next; struct xml_reader *next;
@ -108,33 +107,25 @@ void xml_register_callback(xml_callback callback)
*insert = reader; *insert = reader;
} }
int read_xml(const char *filename, const char *catalog) int read_xml(const char *filename)
{ {
xml_reader *reader = xmlReaders; xml_reader *reader = xmlReaders;
xmlDocPtr doc; xmlDocPtr doc;
int result = 0; int results = 0;
if (catalog) { doc = xmlReadFile(filename, NULL, XML_PARSE_NONET | XML_PARSE_PEDANTIC | XML_PARSE_COMPACT);
xmlLoadCatalog(catalog);
}
doc = xmlReadFile(filename, NULL, XML_PARSE_XINCLUDE | XML_PARSE_NONET | XML_PARSE_PEDANTIC | XML_PARSE_COMPACT);
if (doc == NULL) { if (doc == NULL) {
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);
}
if (result >= 0) {
while (reader != NULL) { while (reader != NULL) {
int i = reader->callback(doc); int i = reader->callback(doc);
if (i != 0) { if (i < 0) {
return i; return i;
} }
results += i;
reader = reader->next; reader = reader->next;
} }
result = 0;
}
xmlFreeDoc(doc); xmlFreeDoc(doc);
return result; return (results > 0) ? 0 : -1;
} }

View File

@ -31,7 +31,7 @@ extern "C" {
bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt); bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt);
void xml_done(void); void xml_done(void);
int read_xml(const char *filename, const char *catalog); int read_xml(const char *filename);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -282,6 +282,7 @@ static int parse_buildings(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr buildings; xmlXPathObjectPtr buildings;
int result = 0;
/* reading eressea/buildings/building */ /* reading eressea/buildings/building */
buildings = buildings =
@ -289,6 +290,7 @@ static int parse_buildings(xmlDocPtr doc)
if (buildings->nodesetval != NULL) { if (buildings->nodesetval != NULL) {
xmlNodeSetPtr nodes = buildings->nodesetval; xmlNodeSetPtr nodes = buildings->nodesetval;
int i; int i;
result += nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
xmlChar *propValue; xmlChar *propValue;
@ -387,19 +389,21 @@ static int parse_buildings(xmlDocPtr doc)
xmlXPathFreeObject(buildings); xmlXPathFreeObject(buildings);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return result;
} }
static int parse_ships(xmlDocPtr doc) static int parse_ships(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr ships; xmlXPathObjectPtr ships;
int result = 0;
/* reading eressea/ships/ship */ /* reading eressea/ships/ship */
ships = xmlXPathEvalExpression(BAD_CAST "/eressea/ships/ship", xpath); ships = xmlXPathEvalExpression(BAD_CAST "/eressea/ships/ship", xpath);
if (ships->nodesetval != NULL) { if (ships->nodesetval != NULL) {
xmlNodeSetPtr nodes = ships->nodesetval; xmlNodeSetPtr nodes = ships->nodesetval;
int i; int i;
result += nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr child, node = nodes->nodeTab[i]; xmlNodePtr child, node = nodes->nodeTab[i];
xmlChar *propValue; xmlChar *propValue;
@ -481,7 +485,7 @@ static int parse_ships(xmlDocPtr doc)
xmlXPathFreeObject(ships); xmlXPathFreeObject(ships);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return result;
} }
static void xml_readpotion(xmlXPathContextPtr xpath, item_type * itype) static void xml_readpotion(xmlXPathContextPtr xpath, item_type * itype)
@ -794,13 +798,15 @@ static int parse_resources(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr resources; xmlXPathObjectPtr resources;
xmlNodeSetPtr nodes; int results = 0;
int i;
/* reading eressea/resources/resource */ /* reading eressea/resources/resource */
resources = resources =
xmlXPathEvalExpression(BAD_CAST "/eressea/resources/resource", xpath); xmlXPathEvalExpression(BAD_CAST "/eressea/resources/resource", xpath);
nodes = resources->nodesetval; if (resources->nodesetval) {
int i;
xmlNodeSetPtr nodes = resources->nodesetval;
results = nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
xmlChar *propValue, *name, *appearance; xmlChar *propValue, *name, *appearance;
@ -884,6 +890,7 @@ static int parse_resources(xmlDocPtr doc)
} }
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
} }
}
xmlXPathFreeObject(resources); xmlXPathFreeObject(resources);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
@ -891,7 +898,7 @@ static int parse_resources(xmlDocPtr doc)
/* make sure old items (used in requirements) are available */ /* make sure old items (used in requirements) are available */
init_resources(); init_resources();
return 0; return results;
} }
static void add_items(equipment * eq, xmlNodeSetPtr nsetItems) static void add_items(equipment * eq, xmlNodeSetPtr nsetItems)
@ -1055,6 +1062,7 @@ static int parse_equipment(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr xpathRaces; xmlXPathObjectPtr xpathRaces;
int result = 0;
/* reading eressea/equipment/set */ /* reading eressea/equipment/set */
xpathRaces = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/set", xpath); xpathRaces = xmlXPathEvalExpression(BAD_CAST "/eressea/equipment/set", xpath);
@ -1062,6 +1070,7 @@ static int parse_equipment(xmlDocPtr doc)
xmlNodeSetPtr nsetRaces = xpathRaces->nodesetval; xmlNodeSetPtr nsetRaces = xpathRaces->nodesetval;
int i; int i;
result += nsetRaces->nodeNr;
for (i = 0; i != nsetRaces->nodeNr; ++i) { for (i = 0; i != nsetRaces->nodeNr; ++i) {
xmlNodePtr node = nsetRaces->nodeTab[i]; xmlNodePtr node = nsetRaces->nodeTab[i];
xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); xmlChar *propName = xmlGetProp(node, BAD_CAST "name");
@ -1108,21 +1117,23 @@ static int parse_equipment(xmlDocPtr doc)
xmlXPathFreeObject(xpathRaces); xmlXPathFreeObject(xpathRaces);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return result;
} }
static int parse_spellbooks(xmlDocPtr doc) static int parse_spellbooks(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr spellbooks; xmlXPathObjectPtr spellbooks;
int results = 0;
/* reading eressea/spells/spell */ /* reading eressea/spells/spell */
spellbooks = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spellbook", xpath); spellbooks = xmlXPathEvalExpression(BAD_CAST "/eressea/spellbook", xpath);
if (spellbooks->nodesetval != NULL) { if (spellbooks->nodesetval != NULL) {
xmlNodeSetPtr nodes = spellbooks->nodesetval; xmlNodeSetPtr nodes = spellbooks->nodesetval;
int i, k; int i, k;
results += nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlXPathObjectPtr result; xmlXPathObjectPtr result;
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
@ -1166,13 +1177,14 @@ static int parse_spellbooks(xmlDocPtr doc)
} }
xmlXPathFreeObject(spellbooks); xmlXPathFreeObject(spellbooks);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return results;
} }
static int parse_spells(xmlDocPtr doc) static int parse_spells(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr spells; xmlXPathObjectPtr spells;
int result = 0;
/* reading eressea/spells/spell */ /* reading eressea/spells/spell */
spells = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spell", xpath); spells = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spell", xpath);
@ -1180,6 +1192,7 @@ static int parse_spells(xmlDocPtr doc)
xmlNodeSetPtr nodes = spells->nodesetval; xmlNodeSetPtr nodes = spells->nodesetval;
int i; int i;
result += nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlXPathObjectPtr result; xmlXPathObjectPtr result;
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
@ -1299,7 +1312,7 @@ static int parse_spells(xmlDocPtr doc)
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return result;
} }
static void parse_ai(race * rc, xmlNodePtr node) static void parse_ai(race * rc, xmlNodePtr node)
@ -1332,12 +1345,14 @@ static int parse_races(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr races; xmlXPathObjectPtr races;
xmlNodeSetPtr nodes; int results = 0;
int i;
/* reading eressea/races/race */ /* reading eressea/races/race */
races = xmlXPathEvalExpression(BAD_CAST "/eressea/races/race", xpath); races = xmlXPathEvalExpression(BAD_CAST "/eressea/races/race", xpath);
nodes = races->nodesetval; if (races->nodesetval) {
xmlNodeSetPtr nodes = races->nodesetval;
int i;
results += nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
xmlNodePtr child; xmlNodePtr child;
@ -1567,11 +1582,12 @@ static int parse_races(xmlDocPtr doc)
} }
xmlXPathFreeObject(result); xmlXPathFreeObject(result);
} }
}
xmlXPathFreeObject(races); xmlXPathFreeObject(races);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return results;
} }
static int parse_messages(xmlDocPtr doc) static int parse_messages(xmlDocPtr doc)
@ -1579,7 +1595,7 @@ static int parse_messages(xmlDocPtr doc)
xmlXPathContextPtr xpath; xmlXPathContextPtr xpath;
xmlXPathObjectPtr messages; xmlXPathObjectPtr messages;
xmlNodeSetPtr nodes; xmlNodeSetPtr nodes;
int i; int i, results;
xpath = xmlXPathNewContext(doc); xpath = xmlXPathNewContext(doc);
@ -1587,6 +1603,7 @@ static int parse_messages(xmlDocPtr doc)
messages = messages =
xmlXPathEvalExpression(BAD_CAST "/eressea/messages/message", xpath); xmlXPathEvalExpression(BAD_CAST "/eressea/messages/message", xpath);
nodes = messages->nodesetval; nodes = messages->nodesetval;
results = nodes->nodeNr;
for (i = 0; i != nodes->nodeNr; ++i) { for (i = 0; i != nodes->nodeNr; ++i) {
xmlNodePtr node = nodes->nodeTab[i]; xmlNodePtr node = nodes->nodeTab[i];
const char *default_section = "events"; const char *default_section = "events";
@ -1671,7 +1688,7 @@ static int parse_messages(xmlDocPtr doc)
xmlXPathFreeObject(messages); xmlXPathFreeObject(messages);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return results;
} }
static void static void
@ -1726,21 +1743,24 @@ static int parse_strings(xmlDocPtr doc)
{ {
xmlXPathContextPtr xpath = xmlXPathNewContext(doc); xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr strings; xmlXPathObjectPtr strings;
int results = 0;
/* reading eressea/strings/string */ /* reading eressea/strings/string */
strings = xmlXPathEvalExpression(BAD_CAST "/eressea/strings/string", xpath); strings = xmlXPathEvalExpression(BAD_CAST "/eressea/strings/string", xpath);
xml_readstrings(xpath, strings->nodesetval->nodeTab, xml_readstrings(xpath, strings->nodesetval->nodeTab,
strings->nodesetval->nodeNr, false); strings->nodesetval->nodeNr, false);
results += strings->nodesetval->nodeNr;
xmlXPathFreeObject(strings); xmlXPathFreeObject(strings);
strings = strings =
xmlXPathEvalExpression(BAD_CAST "/eressea/strings/namespace/string", xpath); xmlXPathEvalExpression(BAD_CAST "/eressea/strings/namespace/string", xpath);
xml_readstrings(xpath, strings->nodesetval->nodeTab, xml_readstrings(xpath, strings->nodesetval->nodeTab,
strings->nodesetval->nodeNr, true); strings->nodesetval->nodeNr, true);
results += strings->nodesetval->nodeNr;
xmlXPathFreeObject(strings); xmlXPathFreeObject(strings);
xmlXPathFreeContext(xpath); xmlXPathFreeContext(xpath);
return 0; return results;
} }
void register_xmlreader(void) void register_xmlreader(void)