Declare unused parameters directly instead of relying on -Wno-unused-parameters.
[gedcom-parse.git] / gom / family.c
index 34a5c5af3a41ba2d9297f4f961a37ae5e9ac1164..83ad0b1e6d05b0e926c8feeca16cf0c84bf32547 100644 (file)
@@ -61,72 +61,85 @@ void family_subscribe()
 void family_add_event(Gom_ctxt ctxt, struct event* evt)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(event, fam->event, evt)
+  if (fam)
+    LINK_CHAIN_ELT(event, fam->event, evt);
 }
 
 void family_add_lss(Gom_ctxt ctxt, struct lds_event* lss)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(lds_event, fam->lds_spouse_sealing, lss)
+  if (fam)
+    LINK_CHAIN_ELT(lds_event, fam->lds_spouse_sealing, lss);
 }
 
 void family_add_citation(Gom_ctxt ctxt, struct source_citation* cit)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(source_citation, fam->citation, cit)
+  if (fam)
+    LINK_CHAIN_ELT(source_citation, fam->citation, cit);
 }
 
 void family_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(multimedia_link, fam->mm_link, link)
+  if (fam)
+    LINK_CHAIN_ELT(multimedia_link, fam->mm_link, link);
 }
 
 void family_add_note(Gom_ctxt ctxt, struct note_sub* note)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(note_sub, fam->note, note)
+  if (fam)
+    LINK_CHAIN_ELT(note_sub, fam->note, note);
 }
 
 void family_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(user_ref_number, fam->ref, ref)
+  if (fam)
+    LINK_CHAIN_ELT(user_ref_number, fam->ref, ref);
 }
 
-void family_set_record_id(Gom_ctxt ctxt, char *rin)
+void family_set_record_id(Gom_ctxt ctxt, const char *rin)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  fam->record_id = strdup(rin);
+  if (fam) {
+    fam->record_id = strdup(rin);
+    if (! fam->record_id) MEMORY_ERROR;
+  }
 }
 
 void family_set_change_date(Gom_ctxt ctxt, struct change_date* chan)
 {
   struct family *fam = SAFE_CTXT_CAST(family, ctxt);
-  fam->change_date = chan;
+  if (fam)
+    fam->change_date = chan;
 }
 
 void family_add_user_data(Gom_ctxt ctxt, struct user_data* data)
 {
   struct family *obj = SAFE_CTXT_CAST(family, ctxt);
-  LINK_CHAIN_ELT(user_data, obj->extra, data)
+  if (obj)
+    LINK_CHAIN_ELT(user_data, obj->extra, data);
 }
 
 void family_cleanup(struct family* fam)
 {
-  SAFE_FREE(fam->xrefstr);
-  DESTROY_CHAIN_ELTS(event, fam->event, event_cleanup)  
-  DESTROY_CHAIN_ELTS(xref_list, fam->children, NULL_DESTROY)
-  SAFE_FREE(fam->nr_of_children);
-  DESTROY_CHAIN_ELTS(xref_list, fam->submitters, NULL_DESTROY)
-  DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing, lds_event_cleanup)
-  DESTROY_CHAIN_ELTS(source_citation, fam->citation, citation_cleanup)
-  DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link, multimedia_link_cleanup)
-  DESTROY_CHAIN_ELTS(note_sub, fam->note, note_sub_cleanup)
-  DESTROY_CHAIN_ELTS(user_ref_number, fam->ref, user_ref_cleanup)
-  SAFE_FREE(fam->record_id);
-  change_date_cleanup(fam->change_date);
-  DESTROY_CHAIN_ELTS(user_data, fam->extra, user_data_cleanup)
+  if (fam) {
+    SAFE_FREE(fam->xrefstr);
+    DESTROY_CHAIN_ELTS(event, fam->event, event_cleanup); 
+    DESTROY_CHAIN_ELTS(xref_list, fam->children, NULL_DESTROY);
+    SAFE_FREE(fam->nr_of_children);
+    DESTROY_CHAIN_ELTS(xref_list, fam->submitters, NULL_DESTROY);
+    DESTROY_CHAIN_ELTS(lds_event, fam->lds_spouse_sealing, lds_event_cleanup);
+    DESTROY_CHAIN_ELTS(source_citation, fam->citation, citation_cleanup);
+    DESTROY_CHAIN_ELTS(multimedia_link, fam->mm_link, multimedia_link_cleanup);
+    DESTROY_CHAIN_ELTS(note_sub, fam->note, note_sub_cleanup);
+    DESTROY_CHAIN_ELTS(user_ref_number, fam->ref, user_ref_cleanup);
+    SAFE_FREE(fam->record_id);
+    change_date_cleanup(fam->change_date);
+    DESTROY_CHAIN_ELTS(user_data, fam->extra, user_data_cleanup);
+  }
 }
 
 void families_cleanup()
@@ -139,10 +152,13 @@ struct family* gom_get_first_family()
   return gom_first_family;
 }
 
-struct family* make_family_record(char* xrefstr)
+struct family* make_family_record(const char* xrefstr)
 {
-  struct family* fam;
+  struct family* fam = NULL;
   MAKE_CHAIN_ELT(family, gom_first_family, fam);
-  fam->xrefstr = strdup(xrefstr);
+  if (fam) {
+    fam->xrefstr = strdup(xrefstr);
+    if (! fam->xrefstr) MEMORY_ERROR;
+  }
   return fam;
 }