summaryrefslogtreecommitdiff
path: root/src/geometry/geometry.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-01-08 22:35:38 -0600
committersanine <sanine.not@pm.me>2023-01-08 22:35:38 -0600
commit38a71a0e8eb25418f6a0be23960a30de566dfb7c (patch)
tree554a7ed5bdb6900af7b1bcb42d1f3548eea9bb96 /src/geometry/geometry.c
parenta18d004be2217bd59c34ba5a3600f72de70c9419 (diff)
add kai_parse_float_array
Diffstat (limited to 'src/geometry/geometry.c')
-rw-r--r--src/geometry/geometry.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c
new file mode 100644
index 0000000..1d26a70
--- /dev/null
+++ b/src/geometry/geometry.c
@@ -0,0 +1,29 @@
+#include <string.h>
+
+#include <kalmia.h>
+#include <ezxml.h>
+#include "util/util.h"
+#include "geometry.h"
+
+
+void kai_parse_float_array(struct ka_float_array_t *dest, ezxml_t src)
+{
+ /* get id, if present */
+ const char *id = ezxml_attr(src, "id");
+ if (id != NULL) {
+ size_t id_len = strlen(id) + 1;
+ dest->id = malloc(sizeof(char) * id_len);
+ strncpy(dest->id, id, id_len);
+ }
+ else {
+ dest->id = NULL;
+ }
+
+ /* get count */
+ const char *count = ezxml_attr(src, "count");
+ dest->count = strtol(count, NULL, 10);
+
+ /* parse floats */
+ dest->data = malloc(sizeof(ka_real_t) * dest->count);
+ kai_text_to_reals(dest->data, ezxml_txt(src), dest->count);
+}