Removed dup_date and dup_age.
[gedcom-parse.git] / gom / address.c
index ed2ae35a41d70cc4ac452fa215e138ff4a14ab08..6c0332a64a89727d4f1fa3ab61a2a9541c3703c3 100644 (file)
@@ -72,25 +72,6 @@ Gedcom_ctxt sub_addr_start(_ELT_PARAMS_)
   return (Gedcom_ctxt)result;
 }
 
-void sub_addr_end(_ELT_END_PARAMS_)
-{
-  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 = strdup(str);
-      if (! newvalue)
-       MEMORY_ERROR;
-      else
-       addr->full_label = newvalue;
-    }
-  }
-}
-
 Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_)
 {
   Gom_ctxt ctxt = (Gom_ctxt)parent;
@@ -103,6 +84,7 @@ Gedcom_ctxt sub_addr_cont_start(_ELT_PARAMS_)
   return (Gedcom_ctxt)result;
 }
 
+STRING_END_CB(address, sub_addr_end, full_label)
 STRING_CB(address, sub_addr_adr1_start, line1)
 STRING_CB(address, sub_addr_adr2_start, line2)
 STRING_CB(address, sub_addr_city_start, city)
@@ -183,3 +165,36 @@ void address_cleanup(struct address *address)
   }
   SAFE_FREE(address);
 }
+
+int write_address(Gedcom_write_hndl hndl, int parent, struct address *address)
+{
+  int result = 0;
+
+  if (!address) return 1;
+  
+  if (address->full_label)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR, 0, parent,
+                                      address->full_label);
+  if (address->line1)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_ADR1, 0,
+                                      ELT_SUB_ADDR, address->line1);
+  if (address->line2)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_ADR2, 0,
+                                      ELT_SUB_ADDR, address->line2);
+  if (address->city)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_CITY, 0,
+                                      ELT_SUB_ADDR, address->city);
+  if (address->state)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_STAE, 0,
+                                      ELT_SUB_ADDR, address->state);
+  if (address->postal)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_POST, 0,
+                                      ELT_SUB_ADDR, address->postal);
+  if (address->country)
+    result |= gedcom_write_element_str(hndl, ELT_SUB_ADDR_CTRY, 0,
+                                      ELT_SUB_ADDR, address->country);
+  if (address->extra)
+    result |= write_user_data(hndl, address->extra);
+
+  return result;
+}