Moved common code to gom_internal.h
[gedcom-parse.git] / gom / gom_internal.h
index d1b7706ed0306220ef7daa7fd3e9121bd587992d..b3075501a2541d1c8cc79fbab53904a19a735623 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <libintl.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include "gom.h"
 #include "gedcom.h"
-#ifdef WITH_DMALLOC
-#include <dmalloc.h>
-#endif
       
-#define _(string) gettext(string)
+#define _(string) dgettext(PACKAGE, string)
 #define N_(string) (string)
 
+#ifdef __GNUC__
+#define UNUSED __attribute__((unused))
+#else
+#define UNUSED
+#endif
+
 typedef enum {
   T_NULL,
   
@@ -94,17 +100,11 @@ void gom_mem_error(const char *filename, int line);
 
 #define MEMORY_ERROR gom_mem_error(__FILE__, __LINE__)
 
-void def_rec_end(Gedcom_rec rec, Gedcom_ctxt self);
-void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
-                Gedcom_val parsed_value);
+void def_rec_end(Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value);
+void def_elt_end(Gedcom_elt elt, Gedcom_ctxt parent,
+                Gedcom_ctxt self, Gedcom_val parsed_value);
 void set_xref_type(struct xref_value *xr, const char* str);
 
-typedef enum {
-  WITHOUT_NL,
-  WITH_NL
-} NL_TYPE;
-
-char* concat_strings(NL_TYPE type, char *str1, const char *str2);
 struct date_value* dup_date(struct date_value dv);
 struct age_value*  dup_age(struct age_value age);
 
@@ -152,11 +152,22 @@ void NULL_DESTROY(void* anything);
     }                                                                         \
   }
 
-#define _REC_PARAMS_ Gedcom_rec rec, int level, Gedcom_val xref, char *tag,   \
-                     char *raw_value, int parsed_tag, Gedcom_val parsed_value
+#define _REC_PARAMS_ Gedcom_rec rec UNUSED, int level UNUSED,                 \
+                     Gedcom_val xref UNUSED, char *tag UNUSED,                \
+                     char *raw_value UNUSED, int parsed_tag UNUSED,           \
+                     Gedcom_val parsed_value UNUSED
+
+#define _REC_END_PARAMS_ Gedcom_rec rec UNUSED, Gedcom_ctxt self UNUSED,      \
+                         Gedcom_val parsed_value UNUSED
 
-#define _ELT_PARAMS_ Gedcom_elt elt, Gedcom_ctxt parent, int level, char *tag,\
-                     char *raw_value, int parsed_tag, Gedcom_val parsed_value
+#define _ELT_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED,        \
+                     int level UNUSED, char *tag UNUSED,                      \
+                     char *raw_value UNUSED, int parsed_tag UNUSED,           \
+                     Gedcom_val parsed_value UNUSED
+
+#define _ELT_END_PARAMS_ Gedcom_elt elt UNUSED, Gedcom_ctxt parent UNUSED,    \
+                         Gedcom_ctxt self UNUSED,                             \
+                         Gedcom_val parsed_value UNUSED
 
 #define REC_CB(STRUCTTYPE,CB_NAME,FUNC)                                       \
   Gedcom_ctxt CB_NAME(_REC_PARAMS_)                                           \
@@ -201,6 +212,46 @@ void NULL_DESTROY(void* anything);
     return (Gedcom_ctxt)result;                                               \
   }
 
+#define STRING_END_CB(STRUCTTYPE,CB_NAME,FIELD)                               \
+  void CB_NAME(_ELT_END_PARAMS_)                                              \
+  {                                                                           \
+    Gom_ctxt ctxt = (Gom_ctxt)self;                                           \
+    if (! ctxt)                                                               \
+      NO_CONTEXT;                                                             \
+    else {                                                                    \
+      struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt);              \
+      if (obj) {                                                              \
+       char *str = GEDCOM_STRING(parsed_value);                              \
+       char *newvalue = strdup(str);                                         \
+       if (! newvalue)                                                       \
+         MEMORY_ERROR;                                                       \
+       else                                                                  \
+         obj->FIELD = newvalue;                                              \
+      }                                                                       \
+      destroy_gom_ctxt(ctxt);                                                 \
+    }                                                                         \
+  }
+
+#define STRING_END_REC_CB(STRUCTTYPE,CB_NAME,FIELD)                           \
+  void CB_NAME(_REC_END_PARAMS_)                                              \
+  {                                                                           \
+    Gom_ctxt ctxt = (Gom_ctxt)self;                                           \
+    if (! ctxt)                                                               \
+      NO_CONTEXT;                                                             \
+    else {                                                                    \
+      struct STRUCTTYPE *obj = SAFE_CTXT_CAST(STRUCTTYPE, ctxt);              \
+      if (obj) {                                                              \
+       char *str = GEDCOM_STRING(parsed_value);                              \
+       char *newvalue = strdup(str);                                         \
+       if (! newvalue)                                                       \
+         MEMORY_ERROR;                                                       \
+       else                                                                  \
+         obj->FIELD = newvalue;                                              \
+      }                                                                       \
+      destroy_gom_ctxt(ctxt);                                                 \
+    }                                                                         \
+  }
+
 #define DATE_CB(STRUCTTYPE,CB_NAME,FIELD)                                     \
   Gedcom_ctxt CB_NAME(_ELT_PARAMS_)                                           \
   {                                                                           \