From 5b045164f4a11b1f4d709820e784e1ca77b61b3f Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Sat, 7 Dec 2002 16:43:14 +0000 Subject: [PATCH] Use complete concatenated text instead of concatenating the texts itself. --- gom/address.c | 72 ++++++++++---------- gom/gom.c | 25 ------- gom/gom_internal.h | 13 ++-- gom/header.c | 35 ++++++---- gom/header.h | 1 - gom/multimedia.c | 38 +++++------ gom/note.c | 58 ++++++---------- gom/note.h | 1 - gom/note_sub.c | 138 ++++++++++++++++++------------------- gom/note_sub.h | 1 - gom/source.c | 132 +++++++++++++++++++++++------------- gom/source.h | 1 - gom/source_citation.c | 153 +++++++++++++++++++++--------------------- gom/source_citation.h | 2 - 14 files changed, 332 insertions(+), 338 deletions(-) diff --git a/gom/address.c b/gom/address.c index f8972e6..ed2ae35 100644 --- a/gom/address.c +++ b/gom/address.c @@ -45,61 +45,61 @@ Gedcom_ctxt sub_addr_start(_ELT_PARAMS_) if (!addr) MEMORY_ERROR; else { - char *str = GEDCOM_STRING(parsed_value); memset (addr, 0, sizeof(struct address)); - addr->full_label = strdup(str); - - if (! addr->full_label) { - MEMORY_ERROR; - free(addr); - } - else { - switch (ctxt->ctxt_type) { - case ELT_HEAD_SOUR_CORP: - header_add_address(ctxt, addr); break; - case ELT_SUB_FAM_EVT: - case ELT_SUB_FAM_EVT_EVEN: - case ELT_SUB_INDIV_ATTR: - case ELT_SUB_INDIV_RESI: - case ELT_SUB_INDIV_BIRT: - case ELT_SUB_INDIV_GEN: - case ELT_SUB_INDIV_ADOP: - case ELT_SUB_INDIV_EVEN: - event_add_address(ctxt, addr); break; - case REC_REPO: - repository_add_address(ctxt, addr); break; - case REC_SUBM: - submitter_add_address(ctxt, addr); break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); - } - result = MAKE_GOM_CTXT(elt, address, addr); + switch (ctxt->ctxt_type) { + case ELT_HEAD_SOUR_CORP: + header_add_address(ctxt, addr); break; + case ELT_SUB_FAM_EVT: + case ELT_SUB_FAM_EVT_EVEN: + case ELT_SUB_INDIV_ATTR: + case ELT_SUB_INDIV_RESI: + case ELT_SUB_INDIV_BIRT: + case ELT_SUB_INDIV_GEN: + case ELT_SUB_INDIV_ADOP: + case ELT_SUB_INDIV_EVEN: + event_add_address(ctxt, addr); break; + case REC_REPO: + repository_add_address(ctxt, addr); break; + case REC_SUBM: + submitter_add_address(ctxt, addr); break; + default: + UNEXPECTED_CONTEXT(ctxt->ctxt_type); } + result = MAKE_GOM_CTXT(elt, address, addr); } } return (Gedcom_ctxt)result; } -Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_) +void sub_addr_end(_ELT_END_PARAMS_) { - Gom_ctxt ctxt = (Gom_ctxt)parent; - Gom_ctxt result = NULL; + Gom_ctxt ctxt = (Gom_ctxt)self; + if (! ctxt) NO_CONTEXT; else { struct address *addr = SAFE_CTXT_CAST(address, ctxt); if (addr) { char *str = GEDCOM_STRING(parsed_value); - char *newvalue = concat_strings (WITH_NL, addr->full_label, str); + char *newvalue = strdup(str); if (! newvalue) MEMORY_ERROR; - else { + else addr->full_label = newvalue; - result = MAKE_GOM_CTXT(elt, address, addr); - } } } +} + +Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)parent; + Gom_ctxt result = NULL; + if (! ctxt) + NO_CONTEXT; + else { + result = make_gom_ctxt(elt, ctxt->ctxt_type, ctxt->ctxt_ptr); + } return (Gedcom_ctxt)result; } @@ -144,7 +144,7 @@ Gedcom_ctxt sub_phon_start(_ELT_PARAMS_) void address_subscribe() { - gedcom_subscribe_to_element(ELT_SUB_ADDR, sub_addr_start, def_elt_end); + gedcom_subscribe_to_element(ELT_SUB_ADDR, sub_addr_start, sub_addr_end); gedcom_subscribe_to_element(ELT_SUB_ADDR_CONT, sub_addr_cont_start, def_elt_end); gedcom_subscribe_to_element(ELT_SUB_ADDR_ADR1, diff --git a/gom/gom.c b/gom/gom.c index 2a8aa20..1770efd 100644 --- a/gom/gom.c +++ b/gom/gom.c @@ -221,31 +221,6 @@ void set_xref_type(struct xref_value* xr, const char *str) xr->type = XREF_ANY; } -char* concat_strings(NL_TYPE type, char *str1, const char *str2) -{ - if (str1 != NULL && str2 != NULL) { - char *newp; - char *wp; - size_t len1 = strlen(str1); - size_t len2 = strlen(str2); - size_t len = len1 + len2 + 1; - if (type == WITH_NL) - len++; - newp = (char*) realloc(str1, len); - if (newp == NULL) - return NULL; - wp = newp + len1; - str1 = newp; - if (type == WITH_NL) - *wp++ = '\n'; - wp = memcpy (wp, str2, len2); - wp += len2; - *wp++ = '\0'; - } - - return str1; -} - struct date_value* dup_date(struct date_value dv) { struct date_value* dv_ptr; diff --git a/gom/gom_internal.h b/gom/gom_internal.h index 829b13d..91a6932 100644 --- a/gom/gom_internal.h +++ b/gom/gom_internal.h @@ -105,12 +105,6 @@ void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self, Gedcom_val parsed_value); void set_xref_type(struct xref_value *xr, const char* str); -typedef enum { - WITHOUT_NL, - WITH_NL -} NL_TYPE; - -char* concat_strings(NL_TYPE type, char *str1, const char *str2); struct date_value* dup_date(struct date_value dv); struct age_value* dup_age(struct age_value age); @@ -163,11 +157,18 @@ void NULL_DESTROY(void* anything); char *raw_value UNUSED, int parsed_tag UNUSED, \ Gedcom_val parsed_value UNUSED +#define _REC_END_PARAMS_ Gedcom_rec rec UNUSED, Gedcom_ctxt self UNUSED, \ + Gedcom_val parsed_value UNUSED + #define _ELT_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, \ int level UNUSED, char *tag UNUSED, \ char *raw_value UNUSED, int parsed_tag UNUSED, \ Gedcom_val parsed_value UNUSED +#define _ELT_END_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED, \ + Gedcom_ctxt self UNUSED, \ + Gedcom_val parsed_value UNUSED + #define REC_CB(STRUCTTYPE,CB_NAME,FUNC) \ Gedcom_ctxt CB_NAME(_REC_PARAMS_) \ { \ diff --git a/gom/header.c b/gom/header.c index 130d06e..69fb4df 100644 --- a/gom/header.c +++ b/gom/header.c @@ -60,8 +60,27 @@ STRING_CB(header, head_char_vers_start, charset.version) STRING_CB(header, head_lang_start, language) NULL_CB(header, head_plac_start) STRING_CB(header, head_plac_form_start, place_hierarchy) -STRING_CB(header, head_note_start, note) +NULL_CB(header, head_note_start) /* the end callback will fill the value */ +void head_note_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct header *head = SAFE_CTXT_CAST(header, ctxt); + if (head) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + head->note = newvalue; + } + } +} + void header_add_address(Gom_ctxt ctxt, struct address* addr) { struct header *head = SAFE_CTXT_CAST(header, ctxt); @@ -83,18 +102,6 @@ void header_add_phone(Gom_ctxt ctxt, const char* phone) } } -void header_add_to_note(NL_TYPE type, Gom_ctxt ctxt, const char* str) -{ - struct header *head = SAFE_CTXT_CAST(header, ctxt); - if (head) { - char *newvalue = concat_strings(type, head->note, str); - if (newvalue) - head->note = newvalue; - else - MEMORY_ERROR; - } -} - void header_add_user_data(Gom_ctxt ctxt, struct user_data* data) { struct header *head = SAFE_CTXT_CAST(header, ctxt); @@ -138,7 +145,7 @@ void header_subscribe() gedcom_subscribe_to_element(ELT_HEAD_PLAC, head_plac_start, def_elt_end); gedcom_subscribe_to_element(ELT_HEAD_PLAC_FORM, head_plac_form_start, def_elt_end); - gedcom_subscribe_to_element(ELT_HEAD_NOTE, head_note_start, def_elt_end); + gedcom_subscribe_to_element(ELT_HEAD_NOTE, head_note_start, head_note_end); } void header_cleanup() diff --git a/gom/header.h b/gom/header.h index 0a5bd9e..689fd85 100644 --- a/gom/header.h +++ b/gom/header.h @@ -31,7 +31,6 @@ void header_subscribe(); void header_cleanup(); void header_add_address(Gom_ctxt header, struct address* addr); void header_add_phone (Gom_ctxt header, const char* phone); -void header_add_to_note(NL_TYPE type, Gom_ctxt header, const char* str); void header_add_user_data(Gom_ctxt ctxt, struct user_data* data); int write_header(Gedcom_write_hndl hndl); diff --git a/gom/multimedia.c b/gom/multimedia.c index 8013292..13c8b3e 100644 --- a/gom/multimedia.c +++ b/gom/multimedia.c @@ -41,10 +41,9 @@ STRING_CB(multimedia, obje_titl_start, title) NULL_CB(multimedia, obje_blob_start) XREF_CB(multimedia, obje_obje_start, continued, make_multimedia_record) -Gedcom_ctxt obje_blob_cont_start(_ELT_PARAMS_) +void obje_blob_end(_ELT_END_PARAMS_) { - Gom_ctxt ctxt = (Gom_ctxt)parent; - Gom_ctxt result = NULL; + Gom_ctxt ctxt = (Gom_ctxt)self; if (! ctxt) NO_CONTEXT; @@ -52,26 +51,25 @@ Gedcom_ctxt obje_blob_cont_start(_ELT_PARAMS_) struct multimedia *obj = SAFE_CTXT_CAST(multimedia, ctxt); if (obj) { char *str = GEDCOM_STRING(parsed_value); - if (obj->data) { - char *newvalue = concat_strings (WITHOUT_NL, obj->data, str); - if (newvalue) - obj->data = newvalue; - else { - free(obj->data); - obj->data = NULL; - } - } - else - obj->data = strdup(str); - - if (! obj->data) { + char *newvalue = strdup(str); + if (! newvalue) MEMORY_ERROR; - free(obj); - } else - result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + obj->data = newvalue; } } +} + +Gedcom_ctxt obje_blob_cont_start(_ELT_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)parent; + Gom_ctxt result = NULL; + + if (! ctxt) + NO_CONTEXT; + else + result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); + return (Gedcom_ctxt)result; } @@ -80,7 +78,7 @@ void multimedia_subscribe() gedcom_subscribe_to_record(REC_OBJE, obje_start, def_rec_end); gedcom_subscribe_to_element(ELT_OBJE_FORM, obje_form_start, def_elt_end); gedcom_subscribe_to_element(ELT_OBJE_TITL, obje_titl_start, def_elt_end); - gedcom_subscribe_to_element(ELT_OBJE_BLOB, obje_blob_start, def_elt_end); + gedcom_subscribe_to_element(ELT_OBJE_BLOB, obje_blob_start, obje_blob_end); gedcom_subscribe_to_element(ELT_OBJE_BLOB_CONT, obje_blob_cont_start, def_elt_end); gedcom_subscribe_to_element(ELT_OBJE_OBJE, obje_obje_start, def_elt_end); diff --git a/gom/note.c b/gom/note.c index c6fb9e3..b3ff370 100644 --- a/gom/note.c +++ b/gom/note.c @@ -56,6 +56,25 @@ Gedcom_ctxt note_start(_REC_PARAMS_) return (Gedcom_ctxt)result; } +void note_end(_REC_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct note *note = SAFE_CTXT_CAST(note, ctxt); + if (note) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + note->text = newvalue; + } + } +} + GET_REC_BY_XREF(note, XREF_NOTE, gom_get_note_by_xref) Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_) @@ -65,52 +84,19 @@ Gedcom_ctxt sub_cont_conc_start(_ELT_PARAMS_) if (! ctxt) NO_CONTEXT; - else { - char *str = GEDCOM_STRING(parsed_value); - NL_TYPE type = (elt == ELT_SUB_CONT ? WITH_NL : WITHOUT_NL); - switch (ctxt->ctxt_type) { - case ELT_HEAD_NOTE: - header_add_to_note(type, ctxt, str); break; - case ELT_SUB_SOUR: - citation_add_to_desc(type, ctxt, str); break; - case ELT_SUB_SOUR_TEXT: - citation_add_to_text(type, ctxt, str); break; - case ELT_SUB_NOTE: - note_sub_add_to_note(type, ctxt, str); break; - case REC_NOTE: - note_add_to_note(type, ctxt, str); break; - case ELT_SOUR_AUTH: - case ELT_SOUR_TITL: - case ELT_SOUR_PUBL: - case ELT_SOUR_TEXT: - source_add_to_value(type, ctxt, str); break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); - } + else result = make_gom_ctxt(elt, ctxt->obj_type, ctxt->ctxt_ptr); - } + return (Gedcom_ctxt)result; } void note_subscribe() { - gedcom_subscribe_to_record(REC_NOTE, note_start, def_rec_end); + gedcom_subscribe_to_record(REC_NOTE, note_start, note_end); gedcom_subscribe_to_element(ELT_SUB_CONT, sub_cont_conc_start, def_elt_end); gedcom_subscribe_to_element(ELT_SUB_CONC, sub_cont_conc_start, def_elt_end); } -void note_add_to_note(NL_TYPE type, Gom_ctxt ctxt, const char* str) -{ - struct note *note = SAFE_CTXT_CAST(note, ctxt); - if (note) { - char *newvalue = concat_strings (type, note->text, str); - if (newvalue) - note->text = newvalue; - else - MEMORY_ERROR; - } -} - void note_add_citation(Gom_ctxt ctxt, struct source_citation* cit) { struct note *note = SAFE_CTXT_CAST(note, ctxt); diff --git a/gom/note.h b/gom/note.h index 4f5f9cd..ffbe3b6 100644 --- a/gom/note.h +++ b/gom/note.h @@ -30,7 +30,6 @@ void note_subscribe(); void notes_cleanup(); struct note* make_note_record(const char* xref); -void note_add_to_note(NL_TYPE type, Gom_ctxt ctxt, const char* str); void note_add_citation(Gom_ctxt ctxt, struct source_citation* cit); void note_add_user_ref(Gom_ctxt ctxt, struct user_ref_number* ref); void note_set_record_id(Gom_ctxt ctxt, const char *rin); diff --git a/gom/note_sub.c b/gom/note_sub.c index bdfb1e6..221dcfc 100644 --- a/gom/note_sub.c +++ b/gom/note_sub.c @@ -56,77 +56,85 @@ Gedcom_ctxt sub_note_start(_ELT_PARAMS_) if (! note) MEMORY_ERROR; else { - int err = 0; memset (note, 0, sizeof(struct note_sub)); - if (GEDCOM_IS_STRING(parsed_value)) { - note->text = strdup(GEDCOM_STRING(parsed_value)); - if (! note->text) { - MEMORY_ERROR; - free(note); - err = 1; - } - } - else if (GEDCOM_IS_XREF_PTR(parsed_value)) + if (GEDCOM_IS_XREF_PTR(parsed_value)) note->reference = GEDCOM_XREF_PTR(parsed_value); - if (! err) { - switch (ctxt->ctxt_type) { - case ELT_SUB_PLAC: - place_add_note(ctxt, note); break; - case ELT_SUB_FAM_EVT: - case ELT_SUB_FAM_EVT_EVEN: - case ELT_SUB_INDIV_ATTR: - case ELT_SUB_INDIV_RESI: - case ELT_SUB_INDIV_BIRT: - case ELT_SUB_INDIV_GEN: - case ELT_SUB_INDIV_ADOP: - case ELT_SUB_INDIV_EVEN: - event_add_note(ctxt, note); break; - case ELT_SUB_SOUR: - citation_add_note(ctxt, note); break; - case ELT_SUB_MULTIM_OBJE: - multimedia_link_add_note(ctxt, note); break; - case ELT_SUB_LSS_SLGS: - case ELT_SUB_LIO_BAPL: - case ELT_SUB_LIO_SLGC: - lds_event_add_note(ctxt, note); break; - case REC_FAM: - family_add_note(ctxt, note); break; - case ELT_SUB_CHAN: - change_date_add_note(ctxt, note); break; - case ELT_SUB_PERS_NAME: - name_add_note(ctxt, note); break; - case ELT_SUB_FAMC: - case ELT_SUB_FAMS: - family_link_add_note(ctxt, note); break; - case ELT_SUB_ASSO: - association_add_note(ctxt, note); break; - case REC_INDI: - individual_add_note(ctxt, note); break; - case REC_OBJE: - multimedia_add_note(ctxt, note); break; - case REC_REPO: - repository_add_note(ctxt, note); break; - case ELT_SOUR_DATA: - source_add_note_to_data(ctxt, note); break; - case ELT_SUB_REPO: - source_add_note_to_repo(ctxt, note); break; - case REC_SOUR: - source_add_note(ctxt, note); break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); - } - result = MAKE_GOM_CTXT(elt, note_sub, note); + switch (ctxt->ctxt_type) { + case ELT_SUB_PLAC: + place_add_note(ctxt, note); break; + case ELT_SUB_FAM_EVT: + case ELT_SUB_FAM_EVT_EVEN: + case ELT_SUB_INDIV_ATTR: + case ELT_SUB_INDIV_RESI: + case ELT_SUB_INDIV_BIRT: + case ELT_SUB_INDIV_GEN: + case ELT_SUB_INDIV_ADOP: + case ELT_SUB_INDIV_EVEN: + event_add_note(ctxt, note); break; + case ELT_SUB_SOUR: + citation_add_note(ctxt, note); break; + case ELT_SUB_MULTIM_OBJE: + multimedia_link_add_note(ctxt, note); break; + case ELT_SUB_LSS_SLGS: + case ELT_SUB_LIO_BAPL: + case ELT_SUB_LIO_SLGC: + lds_event_add_note(ctxt, note); break; + case REC_FAM: + family_add_note(ctxt, note); break; + case ELT_SUB_CHAN: + change_date_add_note(ctxt, note); break; + case ELT_SUB_PERS_NAME: + name_add_note(ctxt, note); break; + case ELT_SUB_FAMC: + case ELT_SUB_FAMS: + family_link_add_note(ctxt, note); break; + case ELT_SUB_ASSO: + association_add_note(ctxt, note); break; + case REC_INDI: + individual_add_note(ctxt, note); break; + case REC_OBJE: + multimedia_add_note(ctxt, note); break; + case REC_REPO: + repository_add_note(ctxt, note); break; + case ELT_SOUR_DATA: + source_add_note_to_data(ctxt, note); break; + case ELT_SUB_REPO: + source_add_note_to_repo(ctxt, note); break; + case REC_SOUR: + source_add_note(ctxt, note); break; + default: + UNEXPECTED_CONTEXT(ctxt->ctxt_type); } + result = MAKE_GOM_CTXT(elt, note_sub, note); } } return (Gedcom_ctxt)result; } +void sub_note_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct note_sub *note = SAFE_CTXT_CAST(note_sub, ctxt); + if (note) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + note->text = newvalue; + } + } +} + void note_sub_subscribe() { - gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, def_elt_end); + gedcom_subscribe_to_element(ELT_SUB_NOTE, sub_note_start, sub_note_end); } void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit) @@ -136,18 +144,6 @@ void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit) LINK_CHAIN_ELT(source_citation, note->citation, cit); } -void note_sub_add_to_note(NL_TYPE type, Gom_ctxt ctxt, const char* str) -{ - struct note_sub *note = SAFE_CTXT_CAST(note_sub, ctxt); - if (note) { - char *newvalue = concat_strings (type, note->text, str); - if (newvalue) - note->text = newvalue; - else - MEMORY_ERROR; - } -} - void note_sub_add_user_data(Gom_ctxt ctxt, struct user_data* data) { struct note_sub *obj = SAFE_CTXT_CAST(note_sub, ctxt); diff --git a/gom/note_sub.h b/gom/note_sub.h index f014d45..630f3d8 100644 --- a/gom/note_sub.h +++ b/gom/note_sub.h @@ -30,7 +30,6 @@ void note_sub_subscribe(); void note_sub_cleanup(struct note_sub* note); void note_sub_add_citation(Gom_ctxt ctxt, struct source_citation* cit); -void note_sub_add_to_note(NL_TYPE type, Gom_ctxt ctxt, const char* str); void note_sub_add_user_data(Gom_ctxt ctxt, struct user_data* data); #endif /* __NOTE_SUB_H */ diff --git a/gom/source.c b/gom/source.c index edf53ed..7ecb977 100644 --- a/gom/source.c +++ b/gom/source.c @@ -42,24 +42,100 @@ REC_CB(source, sour_start, make_source_record) GET_REC_BY_XREF(source, XREF_SOUR, gom_get_source_by_xref) NULL_CB(source, sour_data_start) STRING_CB(source, sour_data_agnc_start, data.agency) -STRING_CB(source, sour_auth_start, author) -STRING_CB(source, sour_titl_start, title) +NULL_CB(source, sour_auth_start) /* value set by end callback */ +NULL_CB(source, sour_titl_start) /* value set by end callback */ STRING_CB(source, sour_abbr_start, abbreviation) -STRING_CB(source, sour_publ_start, publication) -STRING_CB(source, sour_text_start, text) +NULL_CB(source, sour_publ_start) /* value set by end callback */ +NULL_CB(source, sour_text_start) /* value set by end callback */ XREF_CB(source, sour_repo_start, repository.link, make_repository_record) +void sour_auth_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct source *sour = SAFE_CTXT_CAST(source, ctxt); + if (sour) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + sour->author = newvalue; + } + } +} + +void sour_titl_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct source *sour = SAFE_CTXT_CAST(source, ctxt); + if (sour) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + sour->title = newvalue; + } + } +} + +void sour_publ_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct source *sour = SAFE_CTXT_CAST(source, ctxt); + if (sour) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + sour->publication = newvalue; + } + } +} + +void sour_text_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + struct source *sour = SAFE_CTXT_CAST(source, ctxt); + if (sour) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + sour->text = newvalue; + } + } +} + void source_subscribe() { gedcom_subscribe_to_record(REC_SOUR, sour_start, def_rec_end); gedcom_subscribe_to_element(ELT_SOUR_DATA, sour_data_start, def_elt_end); gedcom_subscribe_to_element(ELT_SOUR_DATA_AGNC, sour_data_agnc_start, def_elt_end); - gedcom_subscribe_to_element(ELT_SOUR_AUTH, sour_auth_start, def_elt_end); - gedcom_subscribe_to_element(ELT_SOUR_TITL, sour_titl_start, def_elt_end); + gedcom_subscribe_to_element(ELT_SOUR_AUTH, sour_auth_start, sour_auth_end); + gedcom_subscribe_to_element(ELT_SOUR_TITL, sour_titl_start, sour_titl_end); gedcom_subscribe_to_element(ELT_SOUR_ABBR, sour_abbr_start, def_elt_end); - gedcom_subscribe_to_element(ELT_SOUR_PUBL, sour_publ_start, def_elt_end); - gedcom_subscribe_to_element(ELT_SOUR_TEXT, sour_text_start, def_elt_end); + gedcom_subscribe_to_element(ELT_SOUR_PUBL, sour_publ_start, sour_publ_end); + gedcom_subscribe_to_element(ELT_SOUR_TEXT, sour_text_start, sour_text_end); gedcom_subscribe_to_element(ELT_SUB_REPO, sour_repo_start, def_elt_end); } @@ -91,46 +167,6 @@ void source_add_description(Gom_ctxt ctxt, struct source_description* desc) LINK_CHAIN_ELT(source_description, sour->repository.description, desc); } -void source_add_to_value(NL_TYPE type, Gom_ctxt ctxt, const char* str) -{ - struct source *sour = SAFE_CTXT_CAST(source, ctxt); - if (sour) { - switch (ctxt->ctxt_type) { - char *newvalue; - case ELT_SOUR_AUTH: - newvalue = concat_strings (type, sour->author, str); - if (newvalue) - sour->author = newvalue; - else - MEMORY_ERROR; - break; - case ELT_SOUR_TITL: - newvalue = concat_strings (type, sour->title, str); - if (newvalue) - sour->title = newvalue; - else - MEMORY_ERROR; - break; - case ELT_SOUR_PUBL: - newvalue = concat_strings (type, sour->publication, str); - if (newvalue) - sour->publication = newvalue; - else - MEMORY_ERROR; - break; - case ELT_SOUR_TEXT: - newvalue = concat_strings (type, sour->text, str); - if (newvalue) - sour->text = newvalue; - else - MEMORY_ERROR; - break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); - } - } -} - void source_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link) { struct source *sour = SAFE_CTXT_CAST(source, ctxt); diff --git a/gom/source.h b/gom/source.h index 0846698..27a4a39 100644 --- a/gom/source.h +++ b/gom/source.h @@ -32,7 +32,6 @@ void sources_cleanup(); struct source* make_source_record(const char* xref); void source_add_event(Gom_ctxt ctxt, struct source_event* evt); void source_add_note_to_data(Gom_ctxt ctxt, struct note_sub* note); -void source_add_to_value(NL_TYPE type, Gom_ctxt ctxt, const char* str); void source_add_note_to_repo(Gom_ctxt ctxt, struct note_sub* note); void source_add_description(Gom_ctxt ctxt, struct source_description* desc); void source_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* link); diff --git a/gom/source_citation.c b/gom/source_citation.c index c31e32c..ef03835 100644 --- a/gom/source_citation.c +++ b/gom/source_citation.c @@ -53,59 +53,69 @@ Gedcom_ctxt sub_citation_start(_ELT_PARAMS_) if (! cit) MEMORY_ERROR; else { - int err = 0; memset (cit, 0, sizeof(struct source_citation)); - if (GEDCOM_IS_STRING(parsed_value)) { - cit->description = strdup(GEDCOM_STRING(parsed_value)); - if (! cit->description) { - MEMORY_ERROR; - free(cit); - err = 1; - } - } - else if (GEDCOM_IS_XREF_PTR(parsed_value)) + if (GEDCOM_IS_XREF_PTR(parsed_value)) cit->reference = GEDCOM_XREF_PTR(parsed_value); - if (! err) { - switch (ctxt->ctxt_type) { - case ELT_SUB_PLAC: - place_add_citation(ctxt, cit); break; - case ELT_SUB_FAM_EVT: - case ELT_SUB_FAM_EVT_EVEN: - case ELT_SUB_INDIV_ATTR: - case ELT_SUB_INDIV_RESI: - case ELT_SUB_INDIV_BIRT: - case ELT_SUB_INDIV_GEN: - case ELT_SUB_INDIV_ADOP: - case ELT_SUB_INDIV_EVEN: - event_add_citation(ctxt, cit); break; - case ELT_SUB_NOTE: - note_sub_add_citation(ctxt, cit); break; - case ELT_SUB_LSS_SLGS: - case ELT_SUB_LIO_BAPL: - case ELT_SUB_LIO_SLGC: - lds_event_add_citation(ctxt, cit); break; - case REC_FAM: - family_add_citation(ctxt, cit); break; - case ELT_SUB_PERS_NAME: - name_add_citation(ctxt, cit); break; - case REC_INDI: - individual_add_citation(ctxt, cit); break; - case ELT_SUB_ASSO: - association_add_citation(ctxt, cit); break; - case REC_NOTE: - note_add_citation(ctxt, cit); break; - default: - UNEXPECTED_CONTEXT(ctxt->ctxt_type); - } - result = MAKE_GOM_CTXT(elt, source_citation, cit); + switch (ctxt->ctxt_type) { + case ELT_SUB_PLAC: + place_add_citation(ctxt, cit); break; + case ELT_SUB_FAM_EVT: + case ELT_SUB_FAM_EVT_EVEN: + case ELT_SUB_INDIV_ATTR: + case ELT_SUB_INDIV_RESI: + case ELT_SUB_INDIV_BIRT: + case ELT_SUB_INDIV_GEN: + case ELT_SUB_INDIV_ADOP: + case ELT_SUB_INDIV_EVEN: + event_add_citation(ctxt, cit); break; + case ELT_SUB_NOTE: + note_sub_add_citation(ctxt, cit); break; + case ELT_SUB_LSS_SLGS: + case ELT_SUB_LIO_BAPL: + case ELT_SUB_LIO_SLGC: + lds_event_add_citation(ctxt, cit); break; + case REC_FAM: + family_add_citation(ctxt, cit); break; + case ELT_SUB_PERS_NAME: + name_add_citation(ctxt, cit); break; + case REC_INDI: + individual_add_citation(ctxt, cit); break; + case ELT_SUB_ASSO: + association_add_citation(ctxt, cit); break; + case REC_NOTE: + note_add_citation(ctxt, cit); break; + default: + UNEXPECTED_CONTEXT(ctxt->ctxt_type); } + result = MAKE_GOM_CTXT(elt, source_citation, cit); } } return (Gedcom_ctxt)result; } +void sub_citation_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + if (GEDCOM_IS_STRING(parsed_value)) { + struct source_citation *cit = SAFE_CTXT_CAST(source_citation, ctxt); + if (cit) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) + MEMORY_ERROR; + else + cit->description = newvalue; + } + } + } +} + Gedcom_ctxt sub_cit_text_start(_ELT_PARAMS_) { Gom_ctxt ctxt = (Gom_ctxt)parent; @@ -118,19 +128,33 @@ Gedcom_ctxt sub_cit_text_start(_ELT_PARAMS_) if (cit) { struct text *t = NULL; MAKE_CHAIN_ELT(text, cit->text, t); + if (t) + result = MAKE_GOM_CTXT(elt, text, t); + } + } + + return (Gedcom_ctxt)result; +} + +void sub_cit_text_end(_ELT_END_PARAMS_) +{ + Gom_ctxt ctxt = (Gom_ctxt)self; + + if (! ctxt) + NO_CONTEXT; + else { + if (GEDCOM_IS_STRING(parsed_value)) { + struct text *t = SAFE_CTXT_CAST(text, ctxt); if (t) { - t->text = strdup(GEDCOM_STRING(parsed_value)); - if (! t->text) { + char *str = GEDCOM_STRING(parsed_value); + char *newvalue = strdup(str); + if (! newvalue) MEMORY_ERROR; - free(t); - } else - result = MAKE_GOM_CTXT(elt, text, t); + t->text = newvalue; } } } - - return (Gedcom_ctxt)result; } STRING_CB(source_citation, sub_cit_page_start, page) @@ -142,7 +166,8 @@ STRING_CB(source_citation, sub_cit_quay_start, quality) void citation_subscribe() { - gedcom_subscribe_to_element(ELT_SUB_SOUR, sub_citation_start, def_elt_end); + gedcom_subscribe_to_element(ELT_SUB_SOUR, sub_citation_start, + sub_citation_end); gedcom_subscribe_to_element(ELT_SUB_SOUR_PAGE, sub_cit_page_start, def_elt_end); gedcom_subscribe_to_element(ELT_SUB_SOUR_EVEN, sub_cit_even_start, @@ -154,7 +179,7 @@ void citation_subscribe() gedcom_subscribe_to_element(ELT_SUB_SOUR_DATA_DATE, sub_cit_data_date_start, def_elt_end); gedcom_subscribe_to_element(ELT_SUB_SOUR_TEXT, sub_cit_text_start, - def_elt_end); + sub_cit_text_end); gedcom_subscribe_to_element(ELT_SUB_SOUR_QUAY, sub_cit_quay_start, def_elt_end); } @@ -173,30 +198,6 @@ void citation_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm) LINK_CHAIN_ELT(multimedia_link, cit->mm_link, mm); } -void citation_add_to_desc(NL_TYPE type, Gom_ctxt ctxt, const char* str) -{ - struct source_citation *cit = SAFE_CTXT_CAST(source_citation, ctxt); - if (cit) { - char *newvalue = concat_strings (type, cit->description, str); - if (newvalue) - cit->description = newvalue; - else - MEMORY_ERROR; - } -} - -void citation_add_to_text(NL_TYPE type, Gom_ctxt ctxt, const char* str) -{ - struct text *t = SAFE_CTXT_CAST(text, ctxt); - if (t) { - char *newvalue = concat_strings (type, t->text, str); - if (newvalue) - t->text = newvalue; - else - MEMORY_ERROR; - } -} - void citation_add_user_data(Gom_ctxt ctxt, struct user_data* data) { struct source_citation *obj = SAFE_CTXT_CAST(source_citation, ctxt); diff --git a/gom/source_citation.h b/gom/source_citation.h index f6765c1..d5b183a 100644 --- a/gom/source_citation.h +++ b/gom/source_citation.h @@ -32,8 +32,6 @@ void citation_subscribe(); void citation_cleanup(struct source_citation* cit); void citation_add_note(Gom_ctxt ctxt, struct note_sub* note); void citation_add_mm_link(Gom_ctxt ctxt, struct multimedia_link* mm); -void citation_add_to_desc(NL_TYPE type, Gom_ctxt ctxt, const char* str); -void citation_add_to_text(NL_TYPE type, Gom_ctxt ctxt, const char* str); void citation_add_user_data(Gom_ctxt ctxt, struct user_data* data); #endif /* __SOURCE_CITATION_H */ -- 2.30.2