From: Peter Verthez Date: Sun, 5 Jan 2003 17:46:09 +0000 (+0000) Subject: Definition of SUB_MAKEFUNC. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=763e8737b5118c5f23dca84a3290c2d805bbefe6;p=gedcom-parse.git Definition of SUB_MAKEFUNC. --- diff --git a/gom/association.c b/gom/association.c index 7c7ec68..2d9cc2d 100644 --- a/gom/association.c +++ b/gom/association.c @@ -40,12 +40,8 @@ Gedcom_ctxt sub_assoc_start(_ELT_PARAMS_) if (!ctxt) NO_CONTEXT; else { - struct association *assoc; - assoc = (struct association *)malloc(sizeof(struct association)); - if (! assoc) - MEMORY_ERROR; - else { - memset (assoc, 0, sizeof(struct association)); + struct association *assoc = SUB_MAKEFUNC(association)(); + if (assoc) { assoc->to = GEDCOM_XREF_PTR(parsed_value); switch (ctxt->ctxt_type) { @@ -61,6 +57,8 @@ Gedcom_ctxt sub_assoc_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(association) + DEFINE_STRING_CB(association, sub_assoc_rela_start, relation) DEFINE_ADDFUNC2(association, note_sub, note) diff --git a/gom/event.c b/gom/event.c index 2d05ee9..af6e912 100644 --- a/gom/event.c +++ b/gom/event.c @@ -44,11 +44,8 @@ Gedcom_ctxt sub_evt_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct event *evt = (struct event *)malloc(sizeof(struct event)); - if (! evt) - MEMORY_ERROR; - else { - memset (evt, 0, sizeof(struct event)); + struct event *evt = SUB_MAKEFUNC(event)(); + if (evt) { evt->event = parsed_tag; evt->event_name = strdup(tag); if (! evt->event_name) { @@ -93,11 +90,8 @@ Gedcom_ctxt sub_attr_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct event *evt = (struct event *)malloc(sizeof(struct event)); - if (! evt) - MEMORY_ERROR; - else { - memset (evt, 0, sizeof(struct event)); + struct event *evt = SUB_MAKEFUNC(event)(); + if (evt) { evt->event = parsed_tag; evt->event_name = strdup(tag); if (! evt->event_name) { @@ -131,6 +125,8 @@ Gedcom_ctxt sub_attr_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(event) + DEFINE_STRING_CB(event, sub_evt_type_start, type) DEFINE_DATE_CB(event, sub_evt_date_start, date) DEFINE_AGE_CB(event, sub_evt_age_start, age) diff --git a/gom/family_link.c b/gom/family_link.c index 39a2140..cb266b2 100644 --- a/gom/family_link.c +++ b/gom/family_link.c @@ -39,12 +39,8 @@ Gedcom_ctxt sub_fam_link_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct family_link *link - = (struct family_link *)malloc(sizeof(struct family_link)); - if (! link) - MEMORY_ERROR; - else { - memset (link, 0, sizeof(struct family_link)); + struct family_link *link = SUB_MAKEFUNC(family_link)(); + if (link) { link->family = GEDCOM_XREF_PTR(parsed_value); switch (ctxt->ctxt_type) { @@ -87,6 +83,8 @@ Gedcom_ctxt sub_fam_link_pedi_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(family_link) + DEFINE_ADDFUNC2(family_link, note_sub, note) DEFINE_ADDFUNC2(family_link, user_data, extra) diff --git a/gom/lds_event.c b/gom/lds_event.c index c498729..8587b11 100644 --- a/gom/lds_event.c +++ b/gom/lds_event.c @@ -41,12 +41,8 @@ Gedcom_ctxt sub_lds_event_start(_ELT_PARAMS_) 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)); + struct lds_event *lds_evt = SUB_MAKEFUNC(lds_event)(); + if (lds_evt) { lds_evt->event = parsed_tag; lds_evt->event_name = strdup(tag); if (! lds_evt->event_name) { @@ -70,6 +66,8 @@ Gedcom_ctxt sub_lds_event_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(lds_event) + DEFINE_STRING_CB(lds_event, sub_lds_event_stat_start, date_status) DEFINE_DATE_CB(lds_event, sub_lds_event_date_start, date) DEFINE_STRING_CB(lds_event, sub_lds_event_temp_start, temple_code) diff --git a/gom/multimedia_link.c b/gom/multimedia_link.c index 147b838..0b1c4eb 100644 --- a/gom/multimedia_link.c +++ b/gom/multimedia_link.c @@ -44,12 +44,8 @@ Gedcom_ctxt sub_obje_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct multimedia_link *mm - = (struct multimedia_link *)malloc(sizeof(struct multimedia_link)); - if (! mm) - MEMORY_ERROR; - else { - memset (mm, 0, sizeof(struct multimedia_link)); + struct multimedia_link *mm = SUB_MAKEFUNC(multimedia_link)(); + if (mm) { if (GEDCOM_IS_XREF_PTR(parsed_value)) mm->reference = GEDCOM_XREF_PTR(parsed_value); @@ -83,6 +79,8 @@ Gedcom_ctxt sub_obje_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(multimedia_link) + DEFINE_STRING_CB(multimedia_link, sub_obje_form_start, form) DEFINE_STRING_CB(multimedia_link, sub_obje_titl_start, title) DEFINE_STRING_CB(multimedia_link, sub_obje_file_start, file) diff --git a/gom/note_sub.c b/gom/note_sub.c index 5af12ca..2d748a6 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -52,11 +52,8 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct note_sub *note = (struct note_sub *)malloc(sizeof(struct note_sub)); - if (! note) - MEMORY_ERROR; - else { - memset (note, 0, sizeof(struct note_sub)); + struct note_sub *note = SUB_MAKEFUNC(note_sub)(); + if (note) { if (GEDCOM_IS_XREF_PTR(parsed_value)) note->reference = GEDCOM_XREF_PTR(parsed_value); @@ -113,6 +110,8 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(note_sub) + DEFINE_STRING_END_CB(note_sub, sub_note_end, text) DEFINE_ADDFUNC2(note_sub, source_citation, citation) diff --git a/gom/personal_name.c b/gom/personal_name.c index fce4ca7..3b6bb8e 100644 --- a/gom/personal_name.c +++ b/gom/personal_name.c @@ -38,12 +38,8 @@ Gedcom_ctxt sub_name_start(_ELT_PARAMS_) Gom_ctxt result = NULL; if (ctxt) { - struct personal_name *name - = (struct personal_name *)malloc(sizeof(struct personal_name)); - if (! name) - MEMORY_ERROR; - else { - memset (name, 0, sizeof(struct personal_name)); + struct personal_name *name = SUB_MAKEFUNC(personal_name)(); + if (name) { name->name = strdup(GEDCOM_STRING(parsed_value)); if (! name->name) { @@ -65,6 +61,8 @@ Gedcom_ctxt sub_name_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(personal_name) + DEFINE_STRING_CB(personal_name, sub_name_npfx_start, prefix) DEFINE_STRING_CB(personal_name, sub_name_givn_start, given) DEFINE_STRING_CB(personal_name, sub_name_nick_start, nickname) diff --git a/gom/source_citation.c b/gom/source_citation.c index 8e186cc..c79efcc 100644 --- a/gom/source_citation.c +++ b/gom/source_citation.c @@ -47,13 +47,8 @@ Gedcom_ctxt sub_citation_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct source_citation *cit - = (struct source_citation *)malloc(sizeof(struct source_citation)); - - if (! cit) - MEMORY_ERROR; - else { - memset (cit, 0, sizeof(struct source_citation)); + struct source_citation *cit = SUB_MAKEFUNC(source_citation)(); + if (cit) { if (GEDCOM_IS_XREF_PTR(parsed_value)) cit->reference = GEDCOM_XREF_PTR(parsed_value); @@ -137,6 +132,8 @@ Gedcom_ctxt sub_cit_text_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(source_citation) + DEFINE_STRING_CB(source_citation, sub_cit_page_start, page) DEFINE_STRING_CB(source_citation, sub_cit_even_start, event) DEFINE_STRING_CB(source_citation, sub_cit_even_role_start, role) diff --git a/gom/source_description.c b/gom/source_description.c index 34ca521..87f34ab 100644 --- a/gom/source_description.c +++ b/gom/source_description.c @@ -38,12 +38,8 @@ Gedcom_ctxt sub_sour_caln_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct source_description *desc - = (struct source_description *)malloc(sizeof(struct source_description)); - if (! desc) - MEMORY_ERROR; - else { - memset (desc, 0, sizeof(struct source_description)); + struct source_description *desc = SUB_MAKEFUNC(source_description)(); + if (desc) { desc->call_number = strdup(GEDCOM_STRING(parsed_value)); if (! desc->call_number) { @@ -65,6 +61,8 @@ Gedcom_ctxt sub_sour_caln_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(source_description) + DEFINE_STRING_CB(source_description, sub_sour_caln_medi_start, media) DEFINE_ADDFUNC2(source_description, user_data, extra) diff --git a/gom/source_event.c b/gom/source_event.c index 51a4b60..02882dc 100644 --- a/gom/source_event.c +++ b/gom/source_event.c @@ -38,12 +38,8 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct source_event *evt - = (struct source_event *)malloc(sizeof(struct source_event)); - if (! evt) - MEMORY_ERROR; - else { - memset (evt, 0, sizeof(struct source_event)); + struct source_event *evt = SUB_MAKEFUNC(source_event)(); + if (evt) { evt->recorded_events = strdup(GEDCOM_STRING(parsed_value)); if (! evt->recorded_events) { @@ -65,6 +61,8 @@ Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(source_event) + DEFINE_DATE_CB(source_event, sub_sour_even_date_start, date_period) DEFINE_STRING_CB(source_event, sub_sour_even_plac_start, jurisdiction) diff --git a/gom/user_ref.c b/gom/user_ref.c index 77b2b7d..c9440ab 100644 --- a/gom/user_ref.c +++ b/gom/user_ref.c @@ -43,13 +43,8 @@ Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; else { - struct user_ref_number *refn - = (struct user_ref_number *)malloc(sizeof(struct user_ref_number)); - - if (! refn) - MEMORY_ERROR; - else { - memset (refn, 0, sizeof(struct user_ref_number)); + struct user_ref_number *refn = SUB_MAKEFUNC(user_ref_number)(); + if (refn) { refn->value = strdup(GEDCOM_STRING(parsed_value)); if (! refn->value) { MEMORY_ERROR; @@ -81,6 +76,8 @@ Gedcom_ctxt sub_user_ref_start(_ELT_PARAMS_) return (Gedcom_ctxt)result; } +DEFINE_SUB_MAKEFUNC(user_ref_number) + DEFINE_STRING_CB(user_ref_number, sub_user_ref_type_start, type) DEFINE_ADDFUNC2(user_ref_number, user_data, extra)