Removed dup_date and dup_age.
[gedcom-parse.git] / gom / source.c
index 7ecb9777cf402834596d730e3ac679e5a307b0b3..2f353973d18fae5b840862ac9fca801f8cff23a0 100644 (file)
@@ -43,88 +43,16 @@ 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)
 NULL_CB(source, sour_auth_start)  /* value set by end callback */
+STRING_END_CB(source, sour_auth_end, author)
 NULL_CB(source, sour_titl_start)  /* value set by end callback */
+STRING_END_CB(source, sour_titl_end, title)
 STRING_CB(source, sour_abbr_start, abbreviation)
 NULL_CB(source, sour_publ_start)  /* value set by end callback */
+STRING_END_CB(source, sour_publ_end, publication)
 NULL_CB(source, sour_text_start)  /* value set by end callback */
+STRING_END_CB(source, sour_text_end, text)
 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);
@@ -255,3 +183,65 @@ struct source* make_source_record(const char* xrefstr)
   }
   return src;
 }
+
+int write_sources(Gedcom_write_hndl hndl)
+{
+  int result = 0;
+  struct source* obj;
+
+  for (obj = gom_first_source; obj; obj = obj->next) {
+    result |= gedcom_write_record_str(hndl, REC_SOUR, 0,
+                                     obj->xrefstr, NULL);
+    if (obj->data.event || obj->data.agency || obj->data.note)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA, 0,
+                                        REC_SOUR, NULL);
+    if (obj->data.event)
+      result |= write_source_events(hndl, ELT_SOUR_DATA, obj->data.event);
+    if (obj->data.agency)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_AGNC, 0,
+                                        ELT_SOUR_DATA, obj->data.agency);
+    if (obj->data.note)
+      result |= write_note_subs(hndl, ELT_SOUR_DATA, obj->data.note);
+    if (obj->author)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_AUTH, 0,
+                                        REC_SOUR, obj->author);
+    if (obj->title)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_TITL, 0,
+                                        REC_SOUR, obj->title);
+    if (obj->abbreviation)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_ABBR, 0,
+                                        REC_SOUR, obj->abbreviation);
+    if (obj->publication)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_PUBL, 0,
+                                        REC_SOUR, obj->publication);
+    if (obj->text)
+      result |= gedcom_write_element_str(hndl, ELT_SOUR_TEXT, 0,
+                                        REC_SOUR, obj->text);
+    if (obj->repository.link || obj->repository.note
+       || obj->repository.description) {
+      result |= gedcom_write_element_xref(hndl, ELT_SUB_REPO, 0,
+                                         REC_SOUR, obj->repository.link);
+    }
+    if (obj->repository.note)
+      result |= write_note_subs(hndl, ELT_SUB_REPO, obj->repository.note);
+    if (obj->repository.description)
+      result |= write_source_descriptions(hndl, ELT_SUB_REPO,
+                                         obj->repository.description);
+    if (obj->mm_link)
+      result |= write_multimedia_links(hndl, REC_SOUR, obj->mm_link);
+    if (obj->note)
+      result |= write_note_subs(hndl, REC_SOUR, obj->note);
+    if (obj->ref)
+      result |= write_user_refs(hndl, REC_SOUR, obj->ref);
+    if (obj->record_id)
+      result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0,
+                                        REC_SOUR, obj->record_id);
+    if (obj->change_date)
+      result |= write_change_date(hndl, REC_SOUR, obj->change_date);
+    if (obj->extra)
+      result |= write_user_data(hndl, obj->extra);
+  }
+  
+  return result;
+}
+