naev 0.11.5
nxml.c
Go to the documentation of this file.
1
10#include "naev.h"
13#include "nxml.h"
14
15#include "ndata.h"
16#include "nstring.h"
17
29glTexture* xml_parseTexture( xmlNodePtr node,
30 const char *path, int defsx, int defsy,
31 const unsigned int flags )
32{
33 int sx, sy;
34 char *buf, filename[PATH_MAX];
35 glTexture *tex;
36
37 xmlr_attr_int_def(node, "sx", sx, defsx );
38 xmlr_attr_int_def(node, "sy", sy, defsy );
39
40 /* Get graphic to load. */
41 buf = xml_get( node );
42 if (buf == NULL)
43 return NULL;
44
45 /* Check for absolute pathe. */
46 if ((buf[0]=='/') || (path==NULL))
47 snprintf( filename, sizeof(filename), "%s", buf );
48 else
49 snprintf( filename, sizeof(filename), path, buf );
50
51 /* Load the graphic. */
52 if ((sx == 1) && (sy == 1))
53 tex = gl_newImage( filename, flags );
54 else
55 tex = gl_newSprite( filename, sx, sy, flags );
56
57 /* Return result. */
58 return tex;
59}
60
64void xmlw_setParams( xmlTextWriterPtr writer )
65{
66 xmlTextWriterSetIndentString(writer, (const xmlChar*)" ");
67 xmlTextWriterSetIndent(writer, 1);
68}
69
75xmlDocPtr xml_parsePhysFS( const char* filename )
76{
77 char *buf;
78 size_t bufsize;
79 xmlDocPtr doc;
80
81 /* @TODO: Don't slurp?
82 * Can we directly create an InputStream backed by PHYSFS_*, or use SAX? */
83 buf = ndata_read( filename, &bufsize );
84 if (buf == NULL) {
85 WARN( _("Unable to read data from '%s'"), filename );
86 return NULL;
87 }
88 /* Empty file, we ignore these. */
89 if (bufsize==0) {
90 free(buf);
91 return NULL;
92 }
93 doc = xmlParseMemory( buf, bufsize );
94 if (doc == NULL)
95 WARN( _("Unable to parse document '%s'"), filename );
96 free( buf );
97 return doc;
98}
99
100int xmlw_saveTime( xmlTextWriterPtr writer, const char *name, time_t t )
101{
102 xmlw_elem( writer, name, "%lu", t );
103 return 0;
104}
105
106int xml_parseTime( xmlNodePtr node, time_t *t )
107{
108 *t = xml_getULong( node );
109 return 0;
110}
Header file with generic functions and naev-specifics.
#define PATH_MAX
Definition naev.h:50
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
Definition ndata.c:154
glTexture * xml_parseTexture(xmlNodePtr node, const char *path, int defsx, int defsy, const unsigned int flags)
Parses a texture handling the sx and sy elements.
Definition nxml.c:29
void xmlw_setParams(xmlTextWriterPtr writer)
Sets up the standard xml write parameters.
Definition nxml.c:64
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
Definition nxml.c:75
glTexture * gl_newSprite(const char *path, const int sx, const int sy, const unsigned int flags)
Loads the texture immediately, but also sets it as a sprite.
Definition opengl_tex.c:791
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:675
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:36