* Seems to be coming along. Not convinced that the bowing conversions are right.
[scdataviz] / matdb.c
diff --git a/matdb.c b/matdb.c
index 891bec5..644eb40 100644 (file)
--- a/matdb.c
+++ b/matdb.c
 static void print_property(gpointer key, gpointer value, gpointer user_data) {
   fprintf(stderr, "\t\t%s=%g:\n", (char*)key, *(double*)value);
 }
+static void print_inner_bowing(gpointer key, gpointer value, gpointer user_data) {
+  struct matdb_bowing *bowing = (struct matdb_bowing*)value;
+  fprintf(stderr, "\tbowing %s:%s[%s:%s]:\n", bowing->from->str, bowing->to->str, (char*)user_data, (char*)key);
+  g_hash_table_foreach(bowing->properties, &print_property, NULL);
+}
 static void print_material(gpointer key, gpointer value, gpointer user_data) {
   struct matdb_material *mat = (struct matdb_material*)value;
   fprintf(stderr, "\tmaterial %s(%s):\n", mat->name->str, (char*)key);
-  g_hash_table_foreach(mat->properties, print_property, NULL);
+  g_hash_table_foreach(mat->properties, &print_property, NULL);
 }
 static void print_bowing(gpointer key, gpointer value, gpointer user_data) {
-  struct matdb_bowing *bowing = (struct matdb_bowing*)value;
-  fprintf(stderr, "\tbowing %s:%s(%s):\n", bowing->from->str, bowing->to->str, (char*)key);
-  g_hash_table_foreach(bowing->properties, print_property, NULL);
+  GHashTable *ht = value;
+  g_hash_table_foreach(ht, &print_inner_bowing, key);
 }
 
 void print_matdb(const struct matdb *mdb) {
@@ -51,13 +55,19 @@ void destroy_bowing_gpointer(gpointer data) {
   destroy_bowing((struct matdb_bowing *)data);
 }
 void destroy_material(struct matdb_material *mat) {
-  free(mat->name);
+  #ifdef DEBUG
+  fprintf(stderr, "destroy_material\n");
+  #endif
+  g_string_free(mat->name, TRUE);
   g_hash_table_unref(mat->properties);
   free(mat);
 }
 void destroy_bowing(struct matdb_bowing *bow) {
-  free(bow->from);
-  free(bow->to);
+  #ifdef DEBUG
+  fprintf(stderr, "destroy_bowing\n");
+  #endif
+  g_string_free(bow->from, TRUE);
+  g_string_free(bow->to, TRUE);
   g_hash_table_unref(bow->properties);
   free(bow);
 }