From 79f4b0d33cbb490f957d081bd7c8bc97bd4c689c Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 7 Feb 2023 17:52:17 -0600 Subject: fix parser using REJECT so that example works --- src/geometry/geometry.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ src/geometry/geometry.h | 3 +++ 2 files changed, 54 insertions(+) (limited to 'src/geometry') 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