summaryrefslogtreecommitdiff
path: root/src/xml/xml.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-03 23:55:45 -0600
committersanine <sanine.not@pm.me>2023-02-03 23:55:45 -0600
commitb183f50a84efc495b322370976b22bad486800f3 (patch)
tree581116a19816f6da06cb4502204a85822899f32d /src/xml/xml.c
parent414bc3c6db05ec6d5127967eae39dbaa7f48ad2c (diff)
add kai_tag_attr_to_long
Diffstat (limited to 'src/xml/xml.c')
-rw-r--r--src/xml/xml.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/xml/xml.c b/src/xml/xml.c
index 33782c4..24d544c 100644
--- a/src/xml/xml.c
+++ b/src/xml/xml.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include "xml.h"
/* parse a string into a document */
@@ -31,3 +32,21 @@ char * kai_tag_get_attr(struct kai_tag_t *t, const char *attr)
}
return NULL;
}
+
+
+long kai_tag_attr_to_long(
+ struct kai_tag_t *t, const char *attr,
+ long base, int *flag)
+{
+ char *val = kai_tag_get_attr(t, attr);
+ if (val == NULL) {
+ /* attribute not present, fall back to base */
+ if (flag != NULL)
+ *flag = 1;
+ return base;
+ }
+
+ if (flag != NULL)
+ *flag = 0;
+ return strtol(val, NULL, 10);
+}