diff options
author | sanine <sanine.not@pm.me> | 2023-01-03 23:31:48 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-01-03 23:31:48 -0600 |
commit | 13a7c902c051fa8da1e476687c17bb5431d258e1 (patch) | |
tree | ec75993aba0b8264f0dffd03eee2191020b206be /src/geometry/geometry.c | |
parent | e68e6d4e433fe42a0c6df18b2f2d7990b91b7cd6 (diff) |
add kai_expand_array
Diffstat (limited to 'src/geometry/geometry.c')
-rw-r--r-- | src/geometry/geometry.c | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c deleted file mode 100644 index be9ce25..0000000 --- a/src/geometry/geometry.c +++ /dev/null @@ -1,71 +0,0 @@ -#include <string.h> -#include <stdlib.h> - -#include <kalmia.h> -#include <ezxml.h> -#include "geometry.h" - - -static int copy_str(char **dest, const char *src) -{ - if (src == NULL) { - *dest = NULL; - return 0; - } - - size_t len = strlen(src)+1; - *dest = malloc(len * sizeof(char)); - if (*dest == NULL) - return -1; - strncpy(*dest, src, len); - return 0; -} - - -ka_float_array_t * kai_parse_float_array(ezxml_t tag) -{ - if (strcmp(ezxml_name(tag), "float_array") != 0) { - /* wrong tag type */ - return NULL; - } - - /* allocate struct */ - ka_float_array_t *a = malloc(sizeof(ka_float_array_t)); - if (a == NULL) return NULL; - - /* inspect attributes */ - const char *count_str = ezxml_attr(tag, "count"); - a->count = strtol(count_str, NULL, 10); - - const char *id_str = ezxml_attr(tag, "id"); - if (copy_str(&(a->id), id_str) < 0) { - free(a); - return NULL; - } - - /* parse data */ - a->array = malloc(a->count * sizeof(ka_real_t)); - if (a->array == NULL) { - free(a->id); - free(a); - return NULL; - } - - char *data = ezxml_txt(tag); - char *end; - int i; - for (i=0; i<a->count; i++) { - a->array[i] = KA_STR_TO_REAL(data, &end); - data = end; - } - - return a; -} - - -void kai_free_float_array(ka_float_array_t *a) -{ - free(a->array); - free(a->id); - free(a); -} |