summaryrefslogtreecommitdiff
path: root/src/kalmia.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kalmia.c')
-rw-r--r--src/kalmia.c51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/kalmia.c b/src/kalmia.c
index 1ae0588..b789c4d 100644
--- a/src/kalmia.c
+++ b/src/kalmia.c
@@ -1,8 +1,19 @@
#include <kalmia.h>
#include "geometry/geometry.h"
+#include "image/image.h"
+#include "material/material.h"
#include "util/util.h"
#include "xml/xml.h"
+#define CHECK_ERROR(condition) \
+do { \
+ if (condition) { \
+ kai_tag_destroy(document); \
+ kalmia_destroy(k); \
+ return NULL; \
+ } \
+} while (0)
+
struct kalmia_t * kalmia_parse_file(const char *filename)
{
@@ -12,6 +23,7 @@ struct kalmia_t * kalmia_parse_file(const char *filename)
}
struct kai_tag_t *lib;
+ int result;
/* create kalmia_t */
struct kalmia_t *k = kai_alloc(sizeof(struct kalmia_t), "kalmia_t");
@@ -20,6 +32,10 @@ struct kalmia_t * kalmia_parse_file(const char *filename)
return NULL;
}
+ k->library_geometries = NULL;
+ k->library_materials = NULL;
+ k->library_images = NULL;
+
/* parse geometry */
lib = kai_tag_get_first_child_with_type(document, "library_geometries");
if (lib == NULL) {
@@ -28,12 +44,35 @@ struct kalmia_t * kalmia_parse_file(const char *filename)
}
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);
+ CHECK_ERROR(k->library_geometries == NULL);
+ result = kai_read_library_geometries(k->library_geometries, lib);
+ CHECK_ERROR(result != 0);
+ }
+
+ /* parse materials */
+ lib = kai_tag_get_first_child_with_type(document, "library_materials");
+ if (lib == NULL) {
+ /* no materials to read */
+ k->library_materials = NULL;
+ }
+ else {
+ k->library_materials = kai_alloc(sizeof(struct ka_library_materials_t), "library_materials");
+ CHECK_ERROR(k->library_materials == NULL);
+ result = kai_read_library_materials(k->library_materials, lib);
+ CHECK_ERROR(result != 0);
+ }
+
+ /* parse images */
+ lib = kai_tag_get_first_child_with_type(document, "library_images");
+ if (lib == NULL) {
+ /* no images to read */
+ k->library_images = NULL;
+ }
+ else {
+ k->library_images = kai_alloc(sizeof(struct ka_library_images_t), "library_images");
+ CHECK_ERROR(k->library_images == NULL);
+ result = kai_read_library_images(k->library_images, lib);
+ CHECK_ERROR(result != 0);
}
/* clean up */