Getting and setting strings.
[gedcom-parse.git] / gom / lds_event.c
index 578c0c8519406245cc3015ce6da7fbceab6ca374..5abaa2ec7af4cfd70e4ac68aac573827ba522231 100644 (file)
 Gedcom_ctxt sub_lds_event_start(_ELT_PARAMS_)
 {
   Gom_ctxt ctxt = (Gom_ctxt)parent;
-  struct lds_event *lds_evt = NULL;
+  Gom_ctxt result = NULL;
 
-  if (ctxt) {
-    lds_evt = (struct lds_event*)malloc(sizeof(struct lds_event));
-    memset (lds_evt, 0, sizeof(struct lds_event));
-
-    switch (ctxt->ctxt_type) {
-      case REC_FAM:
-       family_add_lss(ctxt, lds_evt); break;
-      case REC_INDI:
-       individual_add_lio(ctxt, lds_evt); break;
-      default:
-       UNEXPECTED_CONTEXT(ctxt->ctxt_type);
+  if (! ctxt)
+    NO_CONTEXT;
+  else {
+    struct lds_event *lds_evt
+      = (struct lds_event*)malloc(sizeof(struct lds_event));
+    if (! lds_evt)
+      MEMORY_ERROR;
+    else {
+      memset (lds_evt, 0, sizeof(struct lds_event));
+      
+      switch (ctxt->ctxt_type) {
+       case REC_FAM:
+         family_add_lss(ctxt, lds_evt); break;
+       case REC_INDI:
+         individual_add_lio(ctxt, lds_evt); break;
+       default:
+         UNEXPECTED_CONTEXT(ctxt->ctxt_type);
+      }
+      result = MAKE_GOM_CTXT(elt, lds_event, lds_evt);
     }
   }
 
-  return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, lds_event, lds_evt);
+  return (Gedcom_ctxt)result;
 }
 
 STRING_CB(lds_event, sub_lds_event_stat_start, date_status)
@@ -92,19 +100,22 @@ void lds_event_subscribe()
 void lds_event_add_note(Gom_ctxt ctxt, struct note_sub* note)
 {
   struct lds_event *lds = SAFE_CTXT_CAST(lds_event, ctxt);
-  LINK_CHAIN_ELT(note_sub, lds->note, note)    
+  if (lds)
+    LINK_CHAIN_ELT(note_sub, lds->note, note);    
 }
 
 void lds_event_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
 {
   struct lds_event *lds = SAFE_CTXT_CAST(lds_event, ctxt);
-  LINK_CHAIN_ELT(source_citation, lds->citation, cit)    
+  if (lds)
+    LINK_CHAIN_ELT(source_citation, lds->citation, cit);    
 }
 
 void lds_event_add_user_data(Gom_ctxt ctxt, struct user_data* data)
 {
   struct lds_event *obj = SAFE_CTXT_CAST(lds_event, ctxt);
-  LINK_CHAIN_ELT(user_data, obj->extra, data)
+  if (obj)
+    LINK_CHAIN_ELT(user_data, obj->extra, data);
 }
 
 void lds_event_cleanup(struct lds_event* lds)
@@ -114,8 +125,8 @@ void lds_event_cleanup(struct lds_event* lds)
     SAFE_FREE(lds->date);
     SAFE_FREE(lds->temple_code);
     SAFE_FREE(lds->place_living_ordinance);
-    DESTROY_CHAIN_ELTS(source_citation, lds->citation, citation_cleanup)  
-    DESTROY_CHAIN_ELTS(note_sub, lds->note, note_sub_cleanup)
-    DESTROY_CHAIN_ELTS(user_data, lds->extra, user_data_cleanup)
+    DESTROY_CHAIN_ELTS(source_citation, lds->citation, citation_cleanup);  
+    DESTROY_CHAIN_ELTS(note_sub, lds->note, note_sub_cleanup);
+    DESTROY_CHAIN_ELTS(user_data, lds->extra, user_data_cleanup);
   }
 }