[Change] Major rewrite of xml parser, increased sanity checks.

This commit is contained in:
Allanis 2014-04-08 21:28:52 +01:00
parent 8f96995c8f
commit e9d216446d
12 changed files with 178 additions and 76 deletions

View File

@ -8,6 +8,7 @@
<shield w="98" h="8" x="52" y="201" /> <shield w="98" h="8" x="52" y="201" />
<armour w="98" h="8" x="52" y="212" /> <armour w="98" h="8" x="52" y="212" />
<energy w="98" h="8" x="52" y="223" /> <energy w="98" h="8" x="52" y="223" />
<fuel w="0" h="0" x="0" y="0" />
</health> </health>
<weapon x="40" y="239" w="112" h="42" /> <weapon x="40" y="239" w="112" h="42" />
<target> <target>

View File

@ -47,4 +47,5 @@ glColour cRadar_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. }; /**< Weapon
glColour cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. }; /**< Shield bar colour. */ glColour cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. }; /**< Shield bar colour. */
glColour cArmour = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. }; /**< Armour bar colour. */ glColour cArmour = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. }; /**< Armour bar colour. */
glColour cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. }; /**< Energy bar colour. */ glColour cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. }; /**< Energy bar colour. */
glColour cFuel = { .r = 0.8, .g = 0.2, .b = 0.8, .a = 1. }; /**< Fuel bar colour. */

View File

@ -56,4 +56,5 @@ extern glColour cRadar_weap;
extern glColour cShield; extern glColour cShield;
extern glColour cArmour; extern glColour cArmour;
extern glColour cEnergy; extern glColour cEnergy;
extern glColour cFuel;

View File

@ -64,14 +64,10 @@ static Commodity* commodity_parse(xmlNodePtr parent) {
node = parent->xmlChildrenNode; node = parent->xmlChildrenNode;
do { do {
if(xml_isNode(node, "description")) xmlr_strd(node, "description", tmp->description);
tmp->description = strdup(xml_get(node)); xmlr_strd(node, "high", tmp->high);
else if(xml_isNode(node, "high")) xmlr_strd(node, "medium", tmp->medium);
tmp->high = xml_getInt(node); xmlr_strd(node, "low", tmp->low);
else if(xml_isNode(node, "medium"))
tmp->medium = xml_getInt(node);
else if(xml_isNode(node, "low"))
tmp->low = xml_getInt(node);
} while((node = node->next)); } while((node = node->next));
#if 0 /* Let's kill this for now. */ #if 0 /* Let's kill this for now. */
#define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name) #define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name)

View File

@ -71,9 +71,9 @@ static unsigned int time = 0; /**< Used to calculate FPS and movement, in pa
static char version[VERSION_LEN]; /**< Contains version. */ static char version[VERSION_LEN]; /**< Contains version. */
static glTexture* loading; /**< Loading screen. */ static glTexture* loading; /**< Loading screen. */
/* Just some default crap. */ /* Some defaults. */
char* data = NULL; /**< Path to datafile. */ char* data = NULL; /**< Path to datafile. */
char dataname[DATA_NAME_LEN] = ""; /**< Name of data file. */ char* dataname = NULL; /**< Name of data file. */
int nosound = 0; /**< Disable sound when loaded. */ int nosound = 0; /**< Disable sound when loaded. */
int show_fps = 1; /**< Shows fps - default true. */ int show_fps = 1; /**< Shows fps - default true. */
int max_fps = 0; /**< Default FPS limit, 0 is no limit. */ int max_fps = 0; /**< Default FPS limit, 0 is no limit. */
@ -640,10 +640,7 @@ static void data_name(void) {
return; return;
} }
do { do {
if(xml_isNode(node, "name")) { xmlr_strd(node, "name", dataname);
strncpy(dataname, xml_get(node), DATA_NAME_LEN);
dataname[DATA_NAME_LEN-1] = '\0';
}
} while(xml_nextNode(node)); } while(xml_nextNode(node));
xmlFreeDoc(doc); xmlFreeDoc(doc);
@ -656,10 +653,14 @@ static void data_name(void) {
* @brief Set the window caption. * @brief Set the window caption.
*/ */
static void window_caption(void) { static void window_caption(void) {
char tmp[DATA_NAME_LEN+10]; size_t len;
char* tmp;
snprintf(tmp, DATA_NAME_LEN+10, APPNAME" - %s", dataname); len = strlen(dataname) + strlen(APPNAME);
tmp = malloc(sizeof(char)*len);
snprintf(tmp, len, APPNAME" - %s", dataname);
SDL_WM_SetCaption(tmp, NULL); SDL_WM_SetCaption(tmp, NULL);
free(tmp);
} }
static char human_version[50]; /**< Stores human readable version string. */ static char human_version[50]; /**< Stores human readable version string. */

View File

@ -26,8 +26,7 @@
#endif #endif
extern char* data; /**< Modifiable datafile. */ extern char* data; /**< Modifiable datafile. */
#define DATA data /**< Standard data file to use. */ #define DATA data /**< Standard data file to use. */
#define DATA_NAME_LEN 32 /**< Max length of data name. */ extern char *dataname; /**< Datafile name. */
extern char dataname[DATA_NAME_LEN]; /**< Datafile name. */
/* Max filename path. */ /* Max filename path. */
#ifndef PATH_MAX #ifndef PATH_MAX

View File

@ -362,15 +362,15 @@ int var_load(xmlNodePtr parent) {
var.type = MISN_VAR_NIL; var.type = MISN_VAR_NIL;
else if(strcmp(str, "num")==0) { else if(strcmp(str, "num")==0) {
var.type = MISN_VAR_NUM; var.type = MISN_VAR_NUM;
var.d.num = atoi(xml_get(cur)); var.d.num = xml_getFloat(cur);
} }
else if(strcmp(str, "bool")==0) { else if(strcmp(str, "bool")==0) {
var.type = MISN_VAR_BOOL; var.type = MISN_VAR_BOOL;
var.d.b = atoi(xml_get(cur)); var.d.b = xml_getInt(cur);
} }
else if(strcmp(str, "str")==0) { else if(strcmp(str, "str")==0) {
var.type = MISN_VAR_STR; var.type = MISN_VAR_STR;
var.d.str = atoi(xml_get(cur)); var.d.str = xml_getStrd(cur);
} else { } else {
/* Supeh error checking. */ /* Supeh error checking. */
WARN("Unknown var type '%s'", str); WARN("Unknown var type '%s'", str);

View File

@ -1691,7 +1691,7 @@ static Fleet* fleet_parse(const xmlNodePtr parent) {
if(xml_isNode(node, "faction")) if(xml_isNode(node, "faction"))
tmp->faction = faction_get(xml_get(node)); tmp->faction = faction_get(xml_get(node));
else if(xml_isNode(node, "ai")) else if(xml_isNode(node, "ai"))
tmp->ai = strdup(xml_get(node)); tmp->ai = xml_getStrd(node);
else if(xml_isNode(node, "pilots")) { else if(xml_isNode(node, "pilots")) {
cur = node->children; cur = node->children;
do { do {

View File

@ -143,17 +143,31 @@ typedef struct GUI_ {
glTexture* gfx_frame; /**< Frame of the GUI. */ glTexture* gfx_frame; /**< Frame of the GUI. */
glTexture* gfx_targetPilot, *gfx_targetPlanet; /**< Graphics used to target planets. */ glTexture* gfx_targetPilot, *gfx_targetPlanet; /**< Graphics used to target planets. */
Radar radar; /**< The radar. */ /* Rects. */
Rect nav; /**< Navigation computer. */
Rect shield; /**< Shield bar. */ /* Radar. */
Rect armour; /**< Armour bar. */ Radar radar; /**< The radar. */
Rect energy; /**< Energy bar. */ /* Navigation. */
Rect weapon; /**< Weapon targeting system. */ Rect nav; /**< Navigation computer. */
Rect target_health; /**< Target health. */ /* Health. */
Rect target_name; /**< Name of the target. */ Rect shield; /**< Shield bar. */
Rect target_faction; /**< Faction of the target. */ glTexture* gfx_shield; /**< Shield bar texture if applicable. */
Rect misc; /**< Misc stuff: credits, cargo.. */ Rect armour; /**< Armour bar. */
Rect msg; /**< Where messages go. */ glTexture* gfx_armour; /**M Armour bar texture if applicable. */
Rect energy; /**< Energy bar. */
glTexture* gfx_energy; /**< Energy bar texture if applicable. */
Rect fuel; /**< Fuel bar. */
glTexture* gfx_fuel; /**< Fuel bar texture if applicable. */
/* Weapon. */
Rect weapon; /**< Weapon targeting system. */
/* Targetting. */
Rect target_health; /**< Target health. */
Rect target_name; /**< Name of the target. */
Rect target_faction; /**< Faction of the target. */
/* Misc. */
Rect misc; /**< Misc stuff: credits, cargo.. */
/* Messages. */
Rect msg; /**< Where messages go. */
/* Positions. */ /* Positions. */
Vec2 frame; /**< Global frame position. */ Vec2 frame; /**< Global frame position. */
@ -200,11 +214,14 @@ static void player_newShipMake(char* name);
/* Sound. */ /* Sound. */
static void player_initSound(void); static void player_initSound(void);
/* Gui. */ /* Gui. */
static void rect_parseParam(const xmlNodePtr parent, char* name, double* param);
static void rect_parse(const xmlNodePtr parent, static void rect_parse(const xmlNodePtr parent,
double* x, double* y, double* w, double* h); double* x, double* y, double* w, double* h);
static int gui_parse(const xmlNodePtr parent, const char* name); static int gui_parse(const xmlNodePtr parent, const char* name);
static void gui_renderPilot(const Pilot* p); static void gui_renderPilot(const Pilot* p);
static void gui_renderBar(const glColour* c, const Rect* r, const double w); static void gui_renderHealth(const glColour* c, const Rect* r,
const glTexture* tex, const double w);
static void gui_cleanup(void);
/* Save/Load. */ /* Save/Load. */
static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc); static int player_saveShip(xmlTextWriterPtr writer, Pilot* ship, char* loc);
static int player_parse(xmlNodePtr parent); static int player_parse(xmlNodePtr parent);
@ -337,8 +354,7 @@ static int player_newMake(void) {
tmp = cur->children; tmp = cur->children;
do { do {
/* System name. @todo Chance based on percentage. */ /* System name. @todo Chance based on percentage. */
if(xml_isNode(tmp, "name")) xmlr_strd(tmp, "name", sysname);
sysname = strdup(xml_get(tmp));
/* Position. */ /* Position. */
xmlr_float(tmp, "x", x); xmlr_float(tmp, "x", x);
xmlr_float(tmp, "y", y); xmlr_float(tmp, "y", y);
@ -358,7 +374,7 @@ static int player_newMake(void) {
WARN("start.xml already contains a mission node!"); WARN("start.xml already contains a mission node!");
continue; continue;
} }
player_mission = strdup(xml_get(cur)); player_mission = xml_getStrd(cur);
} }
} while((cur = cur->next)); } while((cur = cur->next));
} }
@ -983,9 +999,10 @@ void player_renderGUI(void) {
} }
/* Health */ /* Health */
gui_renderBar(&cShield, &gui.shield, player->shield / player->shield_max); gui_renderHealth(&cShield, &gui.shield, &gui.gfx_shield, player->shield / player->shield_max);
gui_renderBar(&cArmour, &gui.armour, player->armour / player->armour_max); gui_renderHealth(&cArmour, &gui.armour, &gui.gfx_armour, player->armour / player->armour_max);
gui_renderBar(&cEnergy, &gui.energy, player->energy / player->energy_max); gui_renderHealth(&cEnergy, &gui.energy, &gui.gfx_energy, player->energy / player->energy_max);
gui_renderHealth(&cFuel, &gui.fuel, &gui.gfx_fuel, player->fuel / player->fuel_max);
/* Weapon. */ /* Weapon. */
if(player->secondary == NULL) { if(player->secondary == NULL) {
@ -1222,21 +1239,59 @@ static void gui_renderPilot(const Pilot* p) {
glEnd(); glEnd();
} }
/* Render a bar. */ /**
static void gui_renderBar(const glColour* c, const Rect* r, const double w) { * @brief Render a health bar.
int x, y, sx, sy; */
static void gui_renderHealth(const glColour* c, const Rect* r, const glTexture* tex,
const double w) {
glBegin(GL_QUADS); double x, y, sx, sy, tx, ty;
/* Set colour. */
COLOUR(*c); COLOUR(*c);
x = r->x - SCREEN_W/2.;
y = r->y - SCREEN_H/2.; /* Just create a bar. */
sx = w * r->w; if(tex == NULL) {
sy = r->h; /* Set the position values. */
glVertex2d(x, y); x = r->x - SCREEN_W/2.;
glVertex2d(x+sx, y); y = r->y - SCREEN_H/2.;
glVertex2d(x+sx, y-sy); sx = w * r->w;
glVertex2d(x, y-sy); sy = r->h;
glEnd();
glBegin(GL_QUADS);
glVertex2d(x, y);
glVertex2d(x+sx, y);
glVertex2d(x+sx, y-sy);
glVertex2d(x, y-sy);
glEnd();
} else { /* Render the texture. */
/* Set the position values. */
x = r->x - SCREEN_W/2.;
y = r->y - SCREEN_H/2. + tex->sh;
sx = w * tex->sw;
sy = tex->sh;
tx = tex->sw / tex->rw;
ty = tex->sh / tex->rh;
/* Draw the image. */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex->texture);
glBegin(GL_QUADS);
COLOUR(*c);
glTexCoord2d(0., ty);
glVertex2d(x, y);
glTexCoord2d(w*tx, ty);
glVertex2d(x + sx, y);
glTexCoord2d(w*tx, 0.);
glVertex2d(x+sx, y - sy);
glTexCoord2d(0., 0.);
glVertex2d(x, y - sy);
glEnd();
glDisable(GL_TEXTURE_2D);
}
} }
/** /**
@ -1247,9 +1302,7 @@ static void gui_renderBar(const glColour* c, const Rect* r, const double w) {
*/ */
int gui_init(void) { int gui_init(void) {
/* Set graphics to NULL. */ /* Set graphics to NULL. */
gui.gfx_frame = NULL; memset(&gui, 0, sizeof(GUI));
gui.gfx_targetPilot = NULL;
gui.gfx_targetPlanet = NULL;
/* -- Radar. */ /* -- Radar. */
gui.radar.res = RADAR_RES_DEFAULT; gui.radar.res = RADAR_RES_DEFAULT;
@ -1364,6 +1417,9 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
xmlNodePtr cur, node; xmlNodePtr cur, node;
char* tmp, buf[PATH_MAX]; char* tmp, buf[PATH_MAX];
/* Clean up. */
gui_cleanup();
/* Gfx. */ /* Gfx. */
/* Set a property and not a node because it must be loaded first. */ /* Set a property and not a node because it must be loaded first. */
tmp = xml_nodeProp(parent, "gfx"); tmp = xml_nodeProp(parent, "gfx");
@ -1375,15 +1431,12 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
/* Frame. */ /* Frame. */
snprintf(buf, PATH_MAX, GUI_GFX"%s.png", tmp); snprintf(buf, PATH_MAX, GUI_GFX"%s.png", tmp);
if(gui.gfx_frame) gl_freeTexture(gui.gfx_frame); /* Free if needed. */
gui.gfx_frame = gl_newImage(buf); gui.gfx_frame = gl_newImage(buf);
/* Pilot. */ /* Pilot. */
snprintf(buf, PATH_MAX, GUI_GFX"%s_pilot.png", tmp); snprintf(buf, PATH_MAX, GUI_GFX"%s_pilot.png", tmp);
if(gui.gfx_targetPilot) gl_freeTexture(gui.gfx_targetPilot); /* Free if needed. */
gui.gfx_targetPilot = gl_newSprite(buf, 2, 2); gui.gfx_targetPilot = gl_newSprite(buf, 2, 2);
/* Planet. */ /* Planet. */
snprintf(buf, PATH_MAX, GUI_GFX"%s_planet.png", tmp); snprintf(buf, PATH_MAX, GUI_GFX"%s_planet.png", tmp);
if(gui.gfx_targetPlanet) gl_freeTexture(gui.gfx_targetPlanet); /* Free if needed. */
gui.gfx_targetPlanet = gl_newSprite(buf, 2, 2); gui.gfx_targetPlanet = gl_newSprite(buf, 2, 2);
free(tmp); free(tmp);
@ -1430,20 +1483,34 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
if(xml_isNode(cur, "shield")) { if(xml_isNode(cur, "shield")) {
rect_parse(cur, &gui.shield.x, &gui.shield.y, rect_parse(cur, &gui.shield.x, &gui.shield.y,
&gui.shield.w, &gui.shield.h); &gui.shield.w, &gui.shield.h);
tmp = xml_get(cur);
if(tmp != NULL)
gui.gfx_shield = gl_newImage(tmp);
RELATIVIZE(gui.shield); RELATIVIZE(gui.shield);
} }
if(xml_isNode(cur, "armour")) { if(xml_isNode(cur, "armour")) {
rect_parse(cur, &gui.armour.x, &gui.armour.y, rect_parse(cur, &gui.armour.x, &gui.armour.y,
&gui.armour.w, &gui.armour.h); &gui.armour.w, &gui.armour.h);
if(tmp != NULL)
gui.gfx_armour = gl_newImage(tmp);
RELATIVIZE(gui.armour); RELATIVIZE(gui.armour);
} }
if(xml_isNode(cur, "energy")) { if(xml_isNode(cur, "energy")) {
rect_parse(cur, &gui.energy.x, &gui.energy.y, rect_parse(cur, &gui.energy.x, &gui.energy.y,
&gui.energy.w, &gui.energy.h); &gui.energy.w, &gui.energy.h);
if(tmp != NULL)
gui.gfx_energy = gl_newImage(tmp);
RELATIVIZE(gui.energy); RELATIVIZE(gui.energy);
} }
if(xml_isNode(cur, "fuel")) {
rect_parse(cur, &gui.fuel.x, &gui.fuel.y,
&gui.fuel.w, &gui.fuel.h);
if(tmp != NULL)
gui.gfx_fuel = gl_newImage(tmp);
RELATIVIZE(gui.fuel);
}
} while((cur = cur->next)); } while((cur = cur->next));
} }
/* Secondary weapon. */ /* Secondary weapon. */
@ -1494,15 +1561,49 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
#undef RELATIVIZE #undef RELATIVIZE
/** /**
* @fn void gui_free(void) * @brief Clean up the GUI.
* */
static void gui_cleanup(void) {
/* Free textures. */
if(gui.gfx_frame != NULL) {
gl_freeTexture(gui.gfx_frame);
gui.gfx_frame = NULL;
}
if(gui.gfx_targetPilot != NULL) {
gl_freeTexture(gui.gfx_targetPilot);
gui.gfx_targetPilot = NULL;
}
if(gui.gfx_targetPlanet != NULL) {
gl_freeTexture(gui.gfx_targetPlanet);
gui.gfx_targetPlanet = NULL;
}
/* Health textures. */
if(gui.gfx_shield != NULL) {
gl_freeTexture(gui.gfx_shield);
gui.gfx_shield = NULL;
}
if(gui.gfx_armour != NULL) {
gl_freeTexture(gui.gfx_armour);
gui.gfx_armour = NULL;
}
if(gui.gfx_energy != NULL) {
gl_freeTexture(gui.gfx_energy);
gui.gfx_energy = NULL;
}
if(gui.gfx_fuel != NULL) {
gl_freeTexture(gui.gfx_fuel);
gui.gfx_fuel = NULL;
}
}
/**
* @brief Free the GUI. * @brief Free the GUI.
*/ */
void gui_free(void) { void gui_free(void) {
if(gui.gfx_frame) gl_freeTexture(gui.gfx_frame); /* Clean up gui. */
if(gui.gfx_targetPilot) gl_freeTexture(gui.gfx_targetPilot); gui_cleanup();
if(gui.gfx_targetPlanet) gl_freeTexture(gui.gfx_targetPlanet);
/* Free messages. */
free(msg_stack); free(msg_stack);
} }

View File

@ -239,13 +239,13 @@ static Ship* ship_parse(xmlNodePtr parent) {
if(xml_isNode(node,"GFX")) { if(xml_isNode(node,"GFX")) {
/* Load the base graphic. */ /* Load the base graphic. */
snprintf(str, strlen(xml_get(node)) + snprintf(str, strlen(xml_raw(node)) +
sizeof(SHIP_GFX) + sizeof(SHIP_EXT), sizeof(SHIP_GFX) + sizeof(SHIP_EXT),
SHIP_GFX"%s"SHIP_EXT, xml_get(node)); SHIP_GFX"%s"SHIP_EXT, xml_get(node));
tmp->gfx_space = gl_newSprite(str, 6, 6); tmp->gfx_space = gl_newSprite(str, 6, 6);
/* Load the comm graphic. */ /* Load the comm graphic. */
snprintf(str, strlen(xml_get(node))+ snprintf(str, strlen(xml_raw(node))+
sizeof(SHIP_GFX)+sizeof(SHIP_COMM)+sizeof(SHIP_EXT), sizeof(SHIP_GFX)+sizeof(SHIP_COMM)+sizeof(SHIP_EXT),
SHIP_GFX"%s"SHIP_COMM SHIP_EXT, xml_get(node)); SHIP_GFX"%s"SHIP_COMM SHIP_EXT, xml_get(node));
tmp->gfx_comm = gl_newImage(str); tmp->gfx_comm = gl_newImage(str);
@ -259,7 +259,7 @@ static Ship* ship_parse(xmlNodePtr parent) {
tmp->gfx_target = gl_newImage(str); tmp->gfx_target = gl_newImage(str);
free(stmp); free(stmp);
} else { /* Load standard target graphic. */ } else { /* Load standard target graphic. */
snprintf(str, strlen(xml_get(node)) + snprintf(str, strlen(xml_raw(node)) +
sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT), sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT),
SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, xml_get(node)); SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, xml_get(node));
tmp->gfx_target = gl_newImage(str); tmp->gfx_target = gl_newImage(str);

View File

@ -686,7 +686,7 @@ static int planet_parse(Planet* planet, const xmlNodePtr parent) {
planet->gfx_space = gl_newImage(str); planet->gfx_space = gl_newImage(str);
} }
else if(xml_isNode(cur, "exterior")) { /* Load land gfx. */ else if(xml_isNode(cur, "exterior")) { /* Load land gfx. */
len = strlen(xml_get(cur)) + sizeof(PLANET_GFX_EXTERIOR); len = strlen(xml_raw(cur)) + sizeof(PLANET_GFX_EXTERIOR);
planet->gfx_exterior = malloc(len); planet->gfx_exterior = malloc(len);
snprintf(planet->gfx_exterior, len, PLANET_GFX_EXTERIOR"%s", xml_get(cur)); snprintf(planet->gfx_exterior, len, PLANET_GFX_EXTERIOR"%s", xml_get(cur));
} }
@ -715,9 +715,9 @@ static int planet_parse(Planet* planet, const xmlNodePtr parent) {
planet->faction = faction_get(xml_get(cur)); planet->faction = faction_get(xml_get(cur));
} }
else if(xml_isNode(cur, "description")) else if(xml_isNode(cur, "description"))
planet->description = strdup(xml_get(cur)); planet->description = xml_getStrd(cur);
else if(xml_isNode(cur, "bar")) else if(xml_isNode(cur, "bar"))
planet->bar_description = strdup(xml_get(cur)); planet->bar_description = xml_getStrd(cur);
else if(xml_isNode(cur, "services")) { else if(xml_isNode(cur, "services")) {
flags |= FLAG_SERVICESET; flags |= FLAG_SERVICESET;
planet->services = xml_getInt(cur); /* Flags gotten by data. */ planet->services = xml_getInt(cur); /* Flags gotten by data. */
@ -1072,7 +1072,7 @@ static void system_parseJumps(const xmlNodePtr parent) {
do { do {
if(xml_isNode(cur, "jump")) { if(xml_isNode(cur, "jump")) {
for(i = 0; i < systems_nstack; i++) for(i = 0; i < systems_nstack; i++)
if(strcmp(systems_stack[i].name, xml_get(cur))==0) { if(strcmp(systems_stack[i].name, xml_raw(cur))==0) {
sys->njumps++; sys->njumps++;
sys->jumps = realloc(sys->jumps, sys->njumps*sizeof(int)); sys->jumps = realloc(sys->jumps, sys->njumps*sizeof(int));
sys->jumps[sys->njumps-1] = i; sys->jumps[sys->njumps-1] = i;

View File

@ -21,10 +21,12 @@
#define xml_nodeProp(n,s) (char*)xmlGetProp(n, (xmlChar*)s) #define xml_nodeProp(n,s) (char*)xmlGetProp(n, (xmlChar*)s)
/* Get data different ways. */ /* Get data different ways. */
#define xml_get(n) ((char*)(n)->children->content) #define xml_raw(n) ((char*)(n)->children->content)
#define xml_getInt(n) (atoi((char*)(n)->children->content)) #define xml_get(n) (((n)->children == NULL) ? NULL : (char*)(n)->children->content)
#define xml_getLong(n) (atoi((char*)(n)->children->content)) #define xml_getInt(n) ((xml_get(n) == NULL) ? 0 : atoi(xml_raw(n)))
#define xml_getFloat(n) (atof((char*)(n)->children->content)) #define xml_getLong(n) ((xml_get(n) == NULL) ? 0 : atol(xml_raw(n)))
#define xml_getFloat(n) ((xml_get(n) == NULL) ? 0. : atof(xml_raw(n)))
#define xml_getStrd(n) ((xml_get(n) == NULL) ? NULL : strdup(xml_raw(n)))
/* Reader crap. */ /* Reader crap. */
#define xmlr_int(n,s,i) \ #define xmlr_int(n,s,i) \
@ -36,7 +38,7 @@
#define xmlr_str(n,s,str) \ #define xmlr_str(n,s,str) \
if(xml_isNode(n,s)) { str = xml_get(n); continue; } if(xml_isNode(n,s)) { str = xml_get(n); continue; }
#define xmlr_strd(n,s,str) \ #define xmlr_strd(n,s,str) \
if(xml_isNode(n,s)) { str = strdup(xml_get(n)); continue; } if(xml_isNode(n,s)) { str = ((xml_get(n) == NULL) ? NULL : strdup(xml_raw(n))); continue; }
#define xmlr_attr(n,s,a) \ #define xmlr_attr(n,s,a) \
a = xml_nodeProp(n,s) a = xml_nodeProp(n,s)