[Add] Added more complicated xml parse functions.
[Change] Renamed xml.h to lxml.h
This commit is contained in:
parent
54ca7b38af
commit
08ec271629
@ -15,7 +15,7 @@
|
||||
#include "cs.h"
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "pack.h"
|
||||
#include "log.h"
|
||||
#include "spfx.h"
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "pack.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "rng.h"
|
||||
#include "faction.h"
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "lephisto.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "hook.h"
|
||||
|
||||
#define HOOK_CHUNK 32 /* Size to grow by when out of space. */
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include "pack.h"
|
||||
#include "weapon.h"
|
||||
#include "faction.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "pause.h"
|
||||
#include "toolkit.h"
|
||||
#include "pilot.h"
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "pilot.h"
|
||||
#include "player.h"
|
||||
#include "ltime.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "music.h"
|
||||
#include "unidiff.h"
|
||||
#include "llua_misn.h"
|
||||
|
61
src/lxml.c
Normal file
61
src/lxml.c
Normal file
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @file lxml.c
|
||||
*
|
||||
* Handles some complex xml parsing.
|
||||
*/
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "lxml.h"
|
||||
|
||||
/**
|
||||
* @brief Parses a texture handling the sx and sy elements.
|
||||
* @param node Node to parse.
|
||||
* @param path Path to get file from, should be in the format of
|
||||
* "PREFIX%sSUFFIX".
|
||||
* @param defsx Default X sprites.
|
||||
* @param defsy Default Y sprites.
|
||||
* @return The texture from the node or NULL if an error occurred.
|
||||
*/
|
||||
glTexture* xml_parseTexture(xmlNodePtr node,
|
||||
const char* path, int defsx, int defsy) {
|
||||
|
||||
int sx, sy;
|
||||
char* buf, filename[PATH_MAX];
|
||||
glTexture* tex;
|
||||
|
||||
/* Sane defaults. */
|
||||
sx = defsx;
|
||||
sy = defsy;
|
||||
|
||||
/* Read x sprites. */
|
||||
xmlr_attr(node, "sx", buf);
|
||||
if(buf != NULL) {
|
||||
sx = atoi(buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/* Read y sprites. */
|
||||
xmlr_attr(node, "sy", buf);
|
||||
if(buf != NULL) {
|
||||
sy = atoi(buf);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/* Get graphic to load. */
|
||||
buf = xml_get(node);
|
||||
if(buf == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Convert name. */
|
||||
snprintf(filename, PATH_MAX, (path != NULL) ? path : "%s", buf);
|
||||
|
||||
/* Load the graphic. */
|
||||
if((sx == 1) && (sy == 1))
|
||||
tex = gl_newImage(filename);
|
||||
else
|
||||
tex = gl_newSprite(filename, sx, sy);
|
||||
|
||||
/* Return result. */
|
||||
return tex;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "libxml/xmlwriter.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "opengl.h"
|
||||
|
||||
#define XML_NODE_START 1
|
||||
#define XML_NODE_TEXT 3
|
||||
@ -79,3 +80,9 @@
|
||||
if(xmlTextWriterEndDocument(w) < 0) { \
|
||||
ERR("xmlw: Unable to end document"); return -1; }
|
||||
|
||||
/*
|
||||
* Functions for generic complex reading.
|
||||
*/
|
||||
glTexture* xml_parseTexture(xmlNodePtr node,
|
||||
const char* path, int defsx, int defsy);
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "log.h"
|
||||
#include "hook.h"
|
||||
#include "pack.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "faction.h"
|
||||
#include "player.h"
|
||||
#include "base64.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "pack.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "spfx.h"
|
||||
#include "outfit.h"
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "log.h"
|
||||
#include "weapon.h"
|
||||
#include "pack.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "spfx.h"
|
||||
#include "rng.h"
|
||||
#include "hook.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "opengl.h"
|
||||
#include "font.h"
|
||||
#include "pack.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "space.h"
|
||||
#include "rng.h"
|
||||
#include "land.h"
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <stdio.h> /* remove() */
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "player.h"
|
||||
#include "toolkit.h"
|
||||
#include "dialogue.h"
|
||||
|
20
src/ship.c
20
src/ship.c
@ -4,7 +4,7 @@
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "pack.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "toolkit.h"
|
||||
#include "ship.h"
|
||||
|
||||
@ -246,28 +246,22 @@ static int ship_parse(Ship* tmp, xmlNodePtr parent) {
|
||||
if(xml_isNode(node,"GFX")) {
|
||||
|
||||
/* Load the base graphic. */
|
||||
snprintf(str, strlen(xml_raw(node)) +
|
||||
sizeof(SHIP_GFX) + sizeof(SHIP_EXT),
|
||||
SHIP_GFX"%s"SHIP_EXT, xml_get(node));
|
||||
tmp->gfx_space = gl_newSprite(str, 6, 6);
|
||||
tmp->gfx_space = xml_parseTexture(node,
|
||||
SHIP_GFX"%s"SHIP_EXT, 6, 6);
|
||||
|
||||
/* Load the comm graphic. */
|
||||
snprintf(str, strlen(xml_raw(node))+
|
||||
sizeof(SHIP_GFX)+sizeof(SHIP_COMM)+sizeof(SHIP_EXT),
|
||||
SHIP_GFX"%s"SHIP_COMM SHIP_EXT, xml_get(node));
|
||||
tmp->gfx_comm = gl_newImage(str);
|
||||
tmp->gfx_comm = xml_parseTexture(node,
|
||||
SHIP_GFX"%s"SHIP_COMM SHIP_EXT, 1, 1);
|
||||
|
||||
/* Load the target graphic. */
|
||||
xmlr_attr(node, "target", stmp);
|
||||
if(stmp != NULL) {
|
||||
snprintf(str, strlen(stmp) +
|
||||
sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT),
|
||||
snprintf(str, PATH_MAX,
|
||||
SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, stmp);
|
||||
tmp->gfx_target = gl_newImage(str);
|
||||
free(stmp);
|
||||
} else { /* Load standard target graphic. */
|
||||
snprintf(str, strlen(xml_raw(node)) +
|
||||
sizeof(SHIP_GFX)+sizeof(SHIP_TARGET)+sizeof(SHIP_EXT),
|
||||
snprintf(str, PATH_MAX,
|
||||
SHIP_GFX"%s"SHIP_TARGET SHIP_EXT, xml_get(node));
|
||||
tmp->gfx_target = gl_newImage(str);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "lephisto.h"
|
||||
#include "opengl.h"
|
||||
#include "log.h"
|
||||
@ -686,8 +686,8 @@ static int planet_parse(Planet* planet, const xmlNodePtr parent) {
|
||||
cur = node->children;
|
||||
do {
|
||||
if(xml_isNode(cur, "space")) { /* Load space gfx. */
|
||||
snprintf(str, PATH_MAX, PLANET_GFX_SPACE"%s", xml_get(cur));
|
||||
planet->gfx_space = gl_newImage(str);
|
||||
planet->gfx_space = xml_parseTexture(cur,
|
||||
PLANET_GFX_SPACE"%s", 1, 1);
|
||||
}
|
||||
else if(xml_isNode(cur, "exterior")) { /* Load land gfx. */
|
||||
len = strlen(xml_raw(cur)) + sizeof(PLANET_GFX_EXTERIOR);
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "xml.h"
|
||||
#include "lxml.h"
|
||||
#include "space.h"
|
||||
#include "pack.h"
|
||||
#include "unidiff.h"
|
||||
|
Loading…
Reference in New Issue
Block a user