diff options
author | sanine <sanine.not@pm.me> | 2023-02-07 17:52:17 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-02-07 17:52:17 -0600 |
commit | 79f4b0d33cbb490f957d081bd7c8bc97bd4c689c (patch) | |
tree | be04a0dd98ca341a46bd65cf400a20e1c66f3563 /src/geometry/geometry.c | |
parent | f547164540f4ac7f8436fef8e981b1fef503f08c (diff) |
fix parser using REJECT so that example works
Diffstat (limited to 'src/geometry/geometry.c')
-rw-r--r-- | src/geometry/geometry.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c index 25b899b..7d2e6c2 100644 --- a/src/geometry/geometry.c +++ b/src/geometry/geometry.c @@ -470,3 +470,54 @@ void kai_release_geometry(struct ka_geometry_t g) free(g.name); kai_release_mesh(g.mesh); } + + +int kai_read_library_geometries(struct ka_library_geometries_t *dest, struct kai_tag_t *src) +{ + CHECK_TAG_TYPE("library_geometries"); + + dest->id = kai_tag_attr_to_dup(src, "id"); + dest->name = kai_tag_attr_to_dup(src, "name"); + + struct kai_tag_t *child; + unsigned int geometry_count = 0; + FOR_CHILD_OF_TYPE(src, child, "geometry") { geometry_count += 1; } + + dest->geometry = kai_alloc( + geometry_count * sizeof(struct ka_geometry_t), + "library_geometries geometry array" + ); + if (dest->geometry == NULL) { + free(dest->id); + free(dest->name); + return -1; + } + + int i=0; + FOR_CHILD_OF_TYPE(src, child, "geometry") { + int result = kai_read_geometry(dest->geometry + i, child); + if (result != 0) { + dest->geometry_count = i; + kai_release_library_geometries(*dest); + return -1; + } + i += 1; + } + dest->geometry_count = geometry_count; + + return 0; +} + +void kai_release_library_geometries(struct ka_library_geometries_t l) +{ + free(l.id); + free(l.name); + + int i; + for (i=0; i<l.geometry_count; i++) { + kai_release_geometry(l.geometry[i]); + } + free(l.geometry); +} + + |