From ef5142f0d044b3480790606536c492719c6e73ef Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 4 Feb 2023 12:53:00 -0600 Subject: implement kai_read_accessor() --- src/geometry/geometry.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/geometry/geometry.c') diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c index 6f6cbae..6c84b11 100644 --- a/src/geometry/geometry.c +++ b/src/geometry/geometry.c @@ -52,3 +52,35 @@ int kai_read_param(struct ka_param_t *dest, struct kai_tag_t *src) return 0; } + + +int kai_read_accessor(struct ka_accessor_t *dest, struct kai_tag_t *src) +{ + CHECK_TAG_TYPE("accessor"); + + long count = kai_tag_attr_to_long(src, "count", -1); + if (count == -1) { return -1; } + char *source = kai_tag_attr_to_dup(src, "source"); + if (source == NULL) { return -1; } + + dest->count = count; + dest->offset = kai_tag_attr_to_long(src, "offset", 0); + dest->source = source; + dest->stride = kai_tag_attr_to_long(src, "stride", 1); + + dest->param_count = kai_tag_num_children(src); + dest->param = malloc(dest->param_count * sizeof(struct ka_param_t)); + struct kai_tag_t *t = src->children; + int i; + for (i=0; iparam_count; i++) { + int result = kai_read_param(dest->param + i, t); + if (result != 0) { + free(dest->param); + free(dest->source); + return -1; + } + t = t->next; + } + + return 0; +} -- cgit v1.2.1