Reworked the xref functions.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 11 Jan 2003 18:42:53 +0000 (18:42 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 11 Jan 2003 18:42:53 +0000 (18:42 +0000)
gom/family.c
gom/func_template.h
gom/gom_internal.h
gom/gom_modify.c
gom/individual.c
gom/multimedia.c
gom/note.c
gom/repository.c
gom/source.c
gom/submission.c
gom/submitter.c

index 9375b1ff209dd172cb583eacc29aa1c6de3df4ed..8389569c0a93418e79d775762afc94569a19df4e 100644 (file)
@@ -45,7 +45,6 @@ DEFINE_DESTROYFUNC(family, gom_first_family)
 DEFINE_ADDFUNC(family, XREF_FAM)
 DEFINE_DELETEFUNC(family)
 DEFINE_GETXREFFUNC(family, XREF_FAM)
-DEFINE_MAKELINKFUNC(family, XREF_FAM)
      
 DEFINE_REC_CB(family, fam_start)
 DEFINE_XREF_CB(family, fam_husb_start, husband, individual)
index 24e1ea69a3711b71816d30e6b16ab2e2f950eda1..a21424d1b425b1847d3f2123b556da5a0758671d 100644 (file)
@@ -33,7 +33,6 @@
 #define SUB_ADDFUNC(STRUCTTYPE)  gom_add_ ## STRUCTTYPE
 #define DELETEFUNC(STRUCTTYPE)   gom_delete_ ## STRUCTTYPE
 #define SUB_DELETEFUNC(STRUCTTYPE) gom_delete_ ## STRUCTTYPE
-#define MAKELINKFUNC(STRUCTTYPE) gom_make_ ## STRUCTTYPE ## _link
 #define ADDFUNC2(T1,T2)          T1 ## _add_ ## T2
 #define ADDFUNC2_TOVAR(T1,T2,F)  T1 ## _add_ ## T2 ## _to_ ## F
 #define ADDFUNC2_NOLIST(T1,T2)   ADDFUNC2(T1,T2)
@@ -75,9 +74,9 @@
     }                                                                         \
     else {                                                                    \
       VAL->next = NULL;                                                       \
-      FIRSTVAL->previous->next = VAL;                                         \
-      VAL->previous = FIRSTVAL->previous;                                     \
-      FIRSTVAL->previous = VAL;                                               \
+      (FIRSTVAL)->previous->next = VAL;                                       \
+      VAL->previous = (FIRSTVAL)->previous;                                   \
+      (FIRSTVAL)->previous = VAL;                                             \
     }                                                                         \
   }
 
@@ -90,6 +89,8 @@
       VAL->previous->next = VAL->next;                                        \
     if (VAL->next)                                                            \
       VAL->next->previous = VAL->previous;                                    \
+    else if (FIRSTVAL)                                                        \
+      (FIRSTVAL)->previous = VAL->previous;                                   \
   }
 
 #define MAKE_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, VAL)                             \
     if (FIRSTVAL) {                                                           \
       struct STRUCTTYPE *runner, *next;                                       \
       runner = FIRSTVAL;                                                      \
+      FIRSTVAL = NULL;                                                        \
       while (runner) {                                                        \
        next = runner->next;                                                  \
         CLEANFUNC(STRUCTTYPE)(runner);                                        \
     if (obj) {                                                                \
       CLEANFUNC(STRUCTTYPE)(obj);                                             \
       UNLINK_CHAIN_ELT(STRUCTTYPE, FIRSTVAL, obj);                            \
-      free(obj);                                                              \
+      SAFE_FREE(obj);                                                         \
     }                                                                         \
   }
 
     return obj;                                                               \
   }
 
+/* TODO: Check whether there are still xrefs linked in */
 #define DEFINE_DELETEFUNC(STRUCTTYPE)                                         \
   int DELETEFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj)                          \
   {                                                                           \
     int result = 1;                                                           \
     if (obj && *obj) {                                                        \
       CLEANFUNC(STRUCTTYPE)(*obj);                                            \
-      free(*obj);                                                             \
-      *obj = NULL;                                                            \
+      SAFE_FREE(*obj);                                                        \
       result = 0;                                                             \
     }                                                                         \
     return result;                                                            \
   }
 
-#define DEFINE_MAKELINKFUNC(STRUCTTYPE,XREF_TYPE)                             \
-  struct xref_value* MAKELINKFUNC(STRUCTTYPE)(struct STRUCTTYPE* obj)         \
-  {                                                                           \
-    struct xref_value* xr = NULL;                                             \
-    if (obj && obj->xrefstr) {                                                \
-      xr = gedcom_get_by_xref(obj->xrefstr);                                  \
-    }                                                                         \
-    return xr;                                                                \
-  }
-
 #define DEFINE_ADDFUNC2(STRUCTTYPE,T2,FIELD)                                  \
   void ADDFUNC2(STRUCTTYPE,T2)(Gom_ctxt ctxt, struct T2* addobj)              \
   {                                                                           \
index 5b707a5791049b67df201fadd86bef398bcce12c..910e1569bf004689c59ee08d305b776e095ac67c 100644 (file)
@@ -116,8 +116,8 @@ int  update_time(char** tv, struct tm* tm_ptr);
 
 void NULL_DESTROY(void* anything);
 
-#define xref_list_cleanup NULL_DESTROY
-
 #include "func_template.h"
 
+DECLARE_CLEANFUNC(xref_list);
+  
 #endif /* __GOM_INTERNAL_H */
index 82205ffb4ca03cc02548ac0ed131aa9a748313b9..b876a9e5cfa2790ff825a629ceec8b915a6c7ccf 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "utf8tools.h"
+#include "user_rec.h"
 #include "gom.h"
 #include "gom_internal.h"
 
@@ -78,17 +79,31 @@ char* gom_set_string_for_locale(char** data, const char* locale_str)
   return result;
 }
 
-struct xref_value* gom_set_xref_value(struct xref_value** data,
-                                     struct xref_value* newval)
+void CLEANFUNC(xref_list)(struct xref_list *obj)
+{
+  if (obj) {
+    DESTROY_CHAIN_ELTS(user_data, obj->extra);
+  }
+}
+
+struct xref_value* gom_set_xref(struct xref_value** data, const char* xref)
 {
   struct xref_value* result = NULL;
+  struct xref_value* newval = NULL;
+  
   if (data) {
+    if (xref) {
+      newval = gedcom_get_by_xref(xref);
+      if (!newval)
+       gedcom_error(_("No record found for xref '%s'"), xref);
+    }
+    
     /* Unreference the old value if not NULL */
     if (*data)
       result = gedcom_unlink_xref((*data)->type, (*data)->string);
     else
       result = newval;
-
+    
     /* Reference the new value if not NULL */
     if (result != NULL && newval) {
       result = gedcom_link_xref(newval->type, newval->string);
@@ -104,3 +119,54 @@ struct xref_value* gom_set_xref_value(struct xref_value** data,
   }
   return result;
 }
+
+struct xref_list* gom_add_xref(struct xref_list** data, const char* xref)
+{
+  struct xref_value* result = NULL;
+  struct xref_value* newval = NULL;
+  struct xref_list* xrl = NULL;
+
+  if (data && xref) {
+    newval = gedcom_get_by_xref(xref);
+    if (!newval)
+      gedcom_error(_("No record found for xref '%s'"), xref);
+    else {
+      result = gedcom_link_xref(newval->type, newval->string);
+      if (result != NULL) {
+       MAKE_CHAIN_ELT(xref_list, *data, xrl);
+       if (xrl) xrl->xref = newval;
+      }
+    }
+  }
+
+  return xrl;
+}
+
+int gom_remove_xref(struct xref_list** data, const char* xref)
+{
+  struct xref_value* xr = NULL;
+  int result = 1;
+  
+  if (data && xref) {
+    xr = gedcom_get_by_xref(xref);
+    if (!xr)
+      gedcom_error(_("No record found for xref '%s'"), xref);
+    else {
+      struct xref_list* xrl = NULL;
+      for (xrl = *data ; xrl ; xrl = xrl->next) {
+       if (xrl->xref == xr) {
+         UNLINK_CHAIN_ELT(xref_list, *data, xrl);
+         gedcom_unlink_xref(xr->type, xr->string);
+         CLEANFUNC(xref_list)(xrl);
+         SAFE_FREE(xrl);
+         result = 0;
+         break;
+       }
+      }
+      if (result == 1)
+       gedcom_error(_("Xref '%s' to remove not part of chain"), xref);
+    }
+  }
+
+  return result;
+}
index 33c4c6c512ff60c8156f476edc500b8758a275c5..103ad31216ccb77d7fc4928041fa2d2fc200a36a 100644 (file)
@@ -47,7 +47,6 @@ DEFINE_DESTROYFUNC(individual, gom_first_individual)
 DEFINE_ADDFUNC(individual, XREF_INDI)
 DEFINE_DELETEFUNC(individual)
 DEFINE_GETXREFFUNC(individual, XREF_INDI)
-DEFINE_MAKELINKFUNC(individual, XREF_INDI)
      
 DEFINE_REC_CB(individual, indi_start)
 DEFINE_STRING_CB(individual, indi_resn_start, restriction_notice)
index 1b1f923ff4833213637efb1423ebfb728179c088..38ffa3ff6f8973ad04b30bdcc8a7e78cdc61b636 100644 (file)
@@ -39,7 +39,6 @@ DEFINE_DESTROYFUNC(multimedia, gom_first_multimedia)
 DEFINE_ADDFUNC(multimedia, XREF_OBJE)
 DEFINE_DELETEFUNC(multimedia)
 DEFINE_GETXREFFUNC(multimedia, XREF_OBJE)
-DEFINE_MAKELINKFUNC(multimedia, XREF_OBJE)
      
 DEFINE_REC_CB(multimedia, obje_start)
 DEFINE_STRING_CB(multimedia, obje_form_start, form)
index fbe253f9778061b5d464f275b243fcd33713bfb8..3c8bc69f7095fa1f72c67c67b013b056e194d8f2 100644 (file)
@@ -56,7 +56,6 @@ DEFINE_DESTROYFUNC(note, gom_first_note)
 DEFINE_ADDFUNC(note, XREF_NOTE)
 DEFINE_DELETEFUNC(note)
 DEFINE_GETXREFFUNC(note, XREF_NOTE)
-DEFINE_MAKELINKFUNC(note, XREF_NOTE)
      
 DEFINE_STRING_END_REC_CB(note, note_end, text)
 
index 2d070c676bab02d0080ed0cff2c14a17948fed74..9d383fa6347f1297592ef48f0ffec6c7dff2c919 100644 (file)
@@ -40,7 +40,6 @@ DEFINE_DESTROYFUNC(repository, gom_first_repository)
 DEFINE_ADDFUNC(repository, XREF_REPO)
 DEFINE_DELETEFUNC(repository)
 DEFINE_GETXREFFUNC(repository, XREF_REPO)
-DEFINE_MAKELINKFUNC(repository, XREF_REPO)
      
 DEFINE_REC_CB(repository, repo_start)
 DEFINE_STRING_CB(repository, repo_name_start, name)
index fc46d0352a270e73dd69f001012602c8a46ae8b8..c13acb38f0edab45392c4f64b01411d014c42309 100644 (file)
@@ -43,7 +43,6 @@ DEFINE_DESTROYFUNC(source, gom_first_source)
 DEFINE_ADDFUNC(source, XREF_SOUR)
 DEFINE_DELETEFUNC(source)
 DEFINE_GETXREFFUNC(source, XREF_SOUR)
-DEFINE_MAKELINKFUNC(source, XREF_SOUR)
      
 DEFINE_REC_CB(source, sour_start)
 DEFINE_NULL_CB(source, sour_data_start)
index 7e5260f54991e7b9aba53f077bff9912697fc81b..3ecee29232686349a6d31381e6ab90d53188eecc 100644 (file)
@@ -32,8 +32,6 @@
 
 struct submission* gom_submission = NULL;
 
-DEFINE_MAKELINKFUNC(submission, XREF_SUBN)
-     
 DEFINE_REC_CB(submission, subn_start)
 DEFINE_XREF_CB(submission, subn_subm_start, submitter, submitter)
 DEFINE_STRING_CB(submission, subn_famf_start, family_file)
index bb2ef3e9273458db971f5fe6f22cae212683553d..29de511f9e4dee349789b842df1b8a07d0ebbbf5 100644 (file)
@@ -39,7 +39,6 @@ DEFINE_DESTROYFUNC(submitter, gom_first_submitter)
 DEFINE_ADDFUNC(submitter, XREF_SUBM)
 DEFINE_DELETEFUNC(submitter)
 DEFINE_GETXREFFUNC(submitter, XREF_SUBM)
-DEFINE_MAKELINKFUNC(submitter, XREF_SUBM)
      
 DEFINE_REC_CB(submitter, subm_start)
 DEFINE_STRING_CB(submitter, subm_name_start, name)