diff options
author | sanine <sanine.not@pm.me> | 2023-02-04 12:53:00 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-04 12:53:00 -0600 |
commit | ef5142f0d044b3480790606536c492719c6e73ef (patch) | |
tree | 8c7abad469ddfddeee5aabe537761a13a83d64ce /src/geometry/geometry.c | |
parent | db4aaea68f40f43e10ce73852630c94227001235 (diff) |
implement kai_read_accessor()
Diffstat (limited to 'src/geometry/geometry.c')
-rw-r--r-- | src/geometry/geometry.c | 32 |
1 files changed, 32 insertions, 0 deletions
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; i<dest->param_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; +} |