summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-22 16:22:03 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-22 16:22:03 (EDT)
commit7621190b3e57bedd3cf4bd9bf23f793d0a3e401b (patch)
tree79c14459e845f6c2e3dcb552a8f1145b45702509 /src
parent6989f12a81529f617be367d2ec0b8ac11b90adee (diff)
downloaddodge-balls-7621190b3e57bedd3cf4bd9bf23f793d0a3e401b.zip
dodge-balls-7621190b3e57bedd3cf4bd9bf23f793d0a3e401b.tar.gz
dodge-balls-7621190b3e57bedd3cf4bd9bf23f793d0a3e401b.tar.bz2
db_xml_get_bool_attr(): New function
Diffstat (limited to 'src')
-rw-r--r--src/xml.c24
-rw-r--r--src/xml.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/src/xml.c b/src/xml.c
index b6315ab..6fafd5b 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -58,6 +58,30 @@ db_xml_unexpected_end_tag(XML_Parser p, const char *found,
}
void
+db_xml_get_bool_attr(XML_Parser p, const char **attr, const char *name,
+ SDL_bool *dest, int req)
+{
+ for (; attr[0] != NULL; attr += 2) {
+ if (strcmp(attr[0], name) == 0) {
+ if (strcmp(attr[1], "true") == 0) {
+ dest = SDL_TRUE;
+ return;
+ } else if (strcmp(attr[1], "false") == 0) {
+ dest = SDL_FALSE;
+ return;
+ } else if (req) {
+ db_warn("Invalid \"%s\" attribute value", name);
+ XML_StopParser(p, XML_FALSE);
+ }
+ }
+ }
+ if (req) {
+ db_warn("Required attribute \"%s\" not found", name);
+ XML_StopParser(p, XML_FALSE);
+ }
+}
+
+void
db_xml_get_uint32_attr(XML_Parser p, const char **attr, const char *name,
Uint32 *dest, int req)
{
diff --git a/src/xml.h b/src/xml.h
index 2002571..5b2ad5a 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -29,6 +29,8 @@ void db_xml_unexpected_start_tag(XML_Parser p, const char *found,
const char *expected);
void db_xml_unexpected_end_tag(XML_Parser p, const char *found,
const char *expected);
+void db_xml_get_bool_attr(XML_Parser p, const char **attr, const char *name,
+ SDL_bool *dest, int req);
void db_xml_get_int_attr(XML_Parser p, const char **attr, const char *name,
int *dest, int req);
void db_xml_get_uint32_attr(XML_Parser p, const char **attr, const char *name,