summaryrefslogtreecommitdiff
path: root/src/geometry/geometry.c
blob: 7046f1e951e92312151ee7831f4e1abd863f5d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <string.h>

#include <kalmia.h>
#include <ezxml.h>
#include "util/util.h"
#include "geometry.h"


int kai_parse_float_array(struct ka_float_array_t *dest, ezxml_t src)
{
	/* get count */
	const char *count = ezxml_attr(src, "count");
	if (count == NULL) {
		fprintf(stderr, "[kalmia] ERROR: required \"count\" parameter not present for float_array\n");
		return -1;
	}
	char *end;
	dest->count = strtol(count, &end, 10);

	/* get id, if present */
	const char *id = ezxml_attr(src, "id");
	if (id != NULL) {
		size_t id_len = strlen(id) + 1;
		dest->id = kai_alloc(sizeof(char) * id_len, "float_array id");
		if (dest->id == NULL) {
			return -1;
		}
		strncpy(dest->id, id, id_len);
	}
	else {
		dest->id = NULL;
	}

	/* parse floats */
	dest->data = kai_alloc(sizeof(ka_real_t) * dest->count, "float_array data");
	if (dest->data == NULL) {
		free(dest->id);
		return -1;
	}
	kai_text_to_reals(dest->data, ezxml_txt(src), dest->count);
}