1 /*
2 * See Licensing and Copyright notice in naev.h
3 */
4
5 /**
6 * @file nxml.c
7 *
8 * Handles some complex xml parsing.
9 */
10
11
12 #include "nxml.h"
13
14 #include "naev.h"
15
16 #include "nstring.h"
17
18
19 /**
20 * @brief Parses a texture handling the sx and sy elements.
21 *
22 * @param node Node to parse.
23 * @param path Path to get file from, should be in the format of
24 * "PREFIX%sSUFFIX".
25 * @param defsx Default X sprites.
26 * @param defsy Default Y sprites.
27 * @param flags Image parameter control flags.
28 * @return The texture from the node or NULL if an error occurred.
29 */
xml_parseTexture(xmlNodePtr node,const char * path,int defsx,int defsy,const unsigned int flags)30 glTexture* xml_parseTexture( xmlNodePtr node,
31 const char *path, int defsx, int defsy,
32 const unsigned int flags )
33 {
34 int sx, sy;
35 char *buf, filename[PATH_MAX];
36 glTexture *tex;
37
38 /*
39 * Sane defaults.
40 */
41 sx = defsx;
42 sy = defsy;
43
44 /* Read x sprites. */
45 xmlr_attr(node, "sx", buf );
46 if (buf != NULL) {
47 sx = atoi(buf);
48 free(buf);
49 }
50
51 /* Read y sprites. */
52 xmlr_attr(node, "sy", buf );
53 if (buf != NULL) {
54 sy = atoi(buf);
55 free(buf);
56 }
57
58 /* Get graphic to load. */
59 buf = xml_get( node );
60 if (buf == NULL)
61 return NULL;
62
63 /* Convert name. */
64 nsnprintf( filename, PATH_MAX, (path != NULL) ? path : "%s", buf );
65
66 /* Load the graphic. */
67 if ((sx == 1) && (sy == 1))
68 tex = gl_newImage( filename, flags );
69 else
70 tex = gl_newSprite( filename, sx, sy, flags );
71
72 /* Return result. */
73 return tex;
74 }
75
76
77 /**
78 * @brief Sets up the standard xml write parameters.
79 */
xmlw_setParams(xmlTextWriterPtr writer)80 void xmlw_setParams( xmlTextWriterPtr writer )
81 {
82 xmlTextWriterSetIndentString(writer, (const xmlChar*)" ");
83 xmlTextWriterSetIndent(writer, 1);
84 }
85
86
87