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/kalmia.c | |
parent | f547164540f4ac7f8436fef8e981b1fef503f08c (diff) |
fix parser using REJECT so that example works
Diffstat (limited to 'src/kalmia.c')
-rw-r--r-- | src/kalmia.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/kalmia.c b/src/kalmia.c new file mode 100644 index 0000000..1ae0588 --- /dev/null +++ b/src/kalmia.c @@ -0,0 +1,54 @@ +#include <kalmia.h> +#include "geometry/geometry.h" +#include "util/util.h" +#include "xml/xml.h" + + +struct kalmia_t * kalmia_parse_file(const char *filename) +{ + struct kai_tag_t *document = kai_parse_file(filename); + if (document == NULL) { + return NULL; + } + + struct kai_tag_t *lib; + + /* create kalmia_t */ + struct kalmia_t *k = kai_alloc(sizeof(struct kalmia_t), "kalmia_t"); + if (k == NULL) { + kai_tag_destroy(document); + return NULL; + } + + /* parse geometry */ + lib = kai_tag_get_first_child_with_type(document, "library_geometries"); + if (lib == NULL) { + /* no geometry to read */ + k->library_geometries = NULL; + } + else { + k->library_geometries = kai_alloc(sizeof(struct ka_library_geometries_t), "library_geometries"); + if (k->library_geometries == NULL) { + kai_tag_destroy(document); + free(k); + return NULL; + } + kai_read_library_geometries(k->library_geometries, lib); + } + + /* clean up */ + kai_tag_destroy(document); + + return k; +} + + +void kalmia_destroy(struct kalmia_t *k) +{ + if (k->library_geometries != NULL) { + kai_release_library_geometries(*(k->library_geometries)); + free(k->library_geometries); + } + + free(k); +} |