Gedcom_ctxt sub_sour_even_start(_ELT_PARAMS_)
{
Gom_ctxt ctxt = (Gom_ctxt)parent;
- struct source_event *evt = NULL;
-
- if (ctxt) {
- evt = (struct source_event *)malloc(sizeof(struct source_event));
- memset (evt, 0, sizeof(struct source_event));
- evt->recorded_events = strdup(GEDCOM_STRING(parsed_value));
-
- switch (ctxt->ctxt_type) {
- case ELT_SOUR_DATA:
- source_add_event(ctxt, evt); break;
- default:
- UNEXPECTED_CONTEXT(ctxt->ctxt_type);
+ Gom_ctxt result = NULL;
+
+ if (! ctxt)
+ NO_CONTEXT;
+ else {
+ struct source_event *evt = SUB_MAKEFUNC(source_event)();
+ if (evt) {
+ evt->recorded_events = strdup(GEDCOM_STRING(parsed_value));
+
+ if (! evt->recorded_events) {
+ MEMORY_ERROR;
+ free(evt);
+ }
+ else {
+ int type = ctxt_type(ctxt);
+ switch (type) {
+ case ELT_SOUR_DATA:
+ ADDFUNC2(source,source_event)(ctxt, evt); break;
+ default:
+ UNEXPECTED_CONTEXT(type);
+ }
+ result = MAKE_GOM_CTXT(elt, source_event, evt);
+ }
}
}
- return (Gedcom_ctxt) MAKE_GOM_CTXT(elt, source_event, evt);
+ return (Gedcom_ctxt)result;
}
-DATE_CB(source_event, sub_sour_even_date_start, date_period)
-STRING_CB(source_event, sub_sour_even_plac_start, jurisdiction)
+DEFINE_SUB_MAKEFUNC(source_event)
+DEFINE_SUB_ADDFUNC(source_event)
+DEFINE_SUB_FINDFUNC(source_event)
+DEFINE_SUB_REMOVEFUNC(source_event)
+DEFINE_SUB_MOVEFUNC(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)
+
+DEFINE_ADDFUNC2(source_event, user_data, extra)
void source_event_subscribe()
{
sub_sour_even_plac_start, def_elt_end);
}
-void source_event_add_user_data(Gom_ctxt ctxt, struct user_data* data)
+void UNREFALLFUNC(source_event)(struct source_event* obj)
{
- struct source_event *obj = SAFE_CTXT_CAST(source_event, ctxt);
- LINK_CHAIN_ELT(user_data, obj->extra, data)
+ if (obj) {
+ struct source_event* runner;
+ for (runner = obj; runner; runner = runner->next) {
+ UNREFALLFUNC(user_data)(runner->extra);
+ }
+ }
}
-void source_event_cleanup(struct source_event* evt)
+void CLEANFUNC(source_event)(struct source_event* evt)
{
if (evt) {
SAFE_FREE(evt->recorded_events);
SAFE_FREE(evt->date_period);
SAFE_FREE(evt->jurisdiction);
- DESTROY_CHAIN_ELTS(user_data, evt->extra, user_data_cleanup)
+ DESTROY_CHAIN_ELTS(user_data, evt->extra);
}
}
+
+int write_source_events(Gedcom_write_hndl hndl, int parent,
+ struct source_event *evt)
+{
+ int result = 0;
+ struct source_event* obj;
+
+ if (!evt) return 1;
+
+ for (obj = evt; obj; obj = obj->next) {
+ result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_EVEN, 0,
+ parent, obj->recorded_events);
+ if (obj->date_period)
+ result |= gedcom_write_element_date(hndl, ELT_SOUR_DATA_EVEN_DATE, 0,
+ ELT_SOUR_DATA_EVEN, obj->date_period);
+ if (obj->jurisdiction)
+ result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_EVEN_PLAC, 0,
+ ELT_SOUR_DATA_EVEN, obj->jurisdiction);
+ if (obj->extra)
+ result |= write_user_data(hndl, obj->extra);
+ }
+
+ return result;
+}