summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2021-03-25 17:38:29 (EDT)
committer P. J. McDermott <pj@pehjota.net>2021-03-25 17:38:29 (EDT)
commit13a4cf550a771e314ed874c0ae17163a17fe06f0 (patch)
tree65d0ec378a8959c59edf7367b2ccd01da5931e04
parent9389cc62a79a534bf248f620eb495d8584465d27 (diff)
downloaddodge-balls-13a4cf550a771e314ed874c0ae17163a17fe06f0.zip
dodge-balls-13a4cf550a771e314ed874c0ae17163a17fe06f0.tar.gz
dodge-balls-13a4cf550a771e314ed874c0ae17163a17fe06f0.tar.bz2
db_xml_get_float_attr(): New function
-rw-r--r--src/xml.c20
-rw-r--r--src/xml.h2
2 files changed, 22 insertions, 0 deletions
diff --git a/src/xml.c b/src/xml.c
index 6fafd5b..30298e0 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -122,6 +122,26 @@ db_xml_get_int_attr(XML_Parser p, const char **attr, const char *name,
}
void
+db_xml_get_float_attr(XML_Parser p, const char **attr, const char *name,
+ float *dest, int req)
+{
+ for (; attr[0] != NULL; attr += 2) {
+ if (strcmp(attr[0], name) == 0) {
+ if (sscanf(attr[1], "%f", dest) == 1) {
+ 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_string_attr(XML_Parser p, const char **attr, const char *name,
char **dest, int req)
{
diff --git a/src/xml.h b/src/xml.h
index 5b2ad5a..fe88cb9 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -35,6 +35,8 @@ 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,
Uint32 *dest, int req);
+void db_xml_get_float_attr(XML_Parser p, const char **attr, const char *name,
+ float *dest, int req);
void db_xml_get_string_attr(XML_Parser p, const char **attr, const char *name,
char **dest, int req);
void db_xml_node_push(XML_Parser p, void *data,