Also write empty CONT lines.
[gedcom-parse.git] / gom / personal_name.c
index fce4ca7d346850c8c9a180e041ebca5a49e0bad9..686422fc3b88f2e8a228ee95e464fd2d9d72ca29 100644 (file)
@@ -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,12 @@ Gedcom_ctxt sub_name_start(_ELT_PARAMS_)
   return (Gedcom_ctxt)result;
 }
 
+DEFINE_SUB_MAKEFUNC(personal_name)
+DEFINE_SUB_ADDFUNC(personal_name)
+DEFINE_SUB_FINDFUNC(personal_name)
+DEFINE_SUB_REMOVEFUNC(personal_name)
+DEFINE_SUB_MOVEFUNC(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)
@@ -93,6 +95,18 @@ void name_subscribe()
                              def_elt_end);
 }
 
+void UNREFALLFUNC(personal_name)(struct personal_name* obj)
+{
+  if (obj) {
+    struct personal_name* runner;
+    for (runner = obj; runner; runner = runner->next) {
+      UNREFALLFUNC(source_citation)(runner->citation);
+      UNREFALLFUNC(note_sub)(runner->note);
+      UNREFALLFUNC(user_data)(runner->extra);
+    }
+  }
+}
+
 void CLEANFUNC(personal_name)(struct personal_name* name)
 {
   if (name) {
@@ -122,22 +136,23 @@ int write_names(Gedcom_write_hndl hndl, int parent,
                                       parent, obj->name);
     if (obj->prefix)
       result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_NPFX, 0,
-                                        parent, obj->prefix);
+                                        ELT_SUB_PERS_NAME, obj->prefix);
     if (obj->given)
       result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_GIVN, 0,
-                                        parent, obj->given);
+                                        ELT_SUB_PERS_NAME, obj->given);
     if (obj->nickname)
       result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_NICK, 0,
-                                        parent, obj->nickname);
+                                        ELT_SUB_PERS_NAME, obj->nickname);
     if (obj->surname_prefix)
       result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_SPFX, 0,
-                                        parent, obj->surname_prefix);
+                                        ELT_SUB_PERS_NAME,
+                                        obj->surname_prefix);
     if (obj->surname)
       result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_SURN, 0,
-                                        parent, obj->surname);
+                                        ELT_SUB_PERS_NAME, obj->surname);
     if (obj->suffix)
       result |= gedcom_write_element_str(hndl, ELT_SUB_PERS_NAME_NSFX, 0,
-                                        parent, obj->suffix);
+                                        ELT_SUB_PERS_NAME, obj->suffix);
     if (obj->citation)
       result |= write_citations(hndl, ELT_SUB_PERS_NAME, obj->citation);
     if (obj->note)