Added function gedcom_check_version.
[gedcom-parse.git] / include / gedcom.h.in
index b2662fb22f99d79a1b94d6e8e397349fb5e84d18..f9a6bd4ff793e90fa9f156aedaec85f1c70ced30 100644 (file)
 #define __GEDCOM_H
 
 #include <stdio.h>
+#include <stdarg.h>
 
-__BEGIN_DECLS
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 #ifndef GEDCOM_INTERNAL
 #include <gedcom-tags.h>
@@ -34,9 +37,12 @@ __BEGIN_DECLS
 
 #define GEDCOM_PARSE_VERSION_MAJOR @VERSION_MAJOR@
 #define GEDCOM_PARSE_VERSION_MINOR @VERSION_MINOR@
+#define GEDCOM_PARSE_VERSION_PATCH 0
 #define GEDCOM_PARSE_VERSION \
   (GEDCOM_PARSE_VERSION_MAJOR * 1000 + GEDCOM_PARSE_VERSION_MINOR)
 
+int gedcom_check_version(int major, int minor, int patch);
+
 /**************************************************************************/
 /***  First the records and elements to subscribe upon                  ***/
 /**************************************************************************/
@@ -328,7 +334,8 @@ typedef enum _XREF_TYPE {
   XREF_SOUR,
   XREF_SUBM,
   XREF_SUBN,
-  XREF_USER
+  XREF_USER,
+  XREF_ANY
 } Xref_type;
 
 struct xref_value {
@@ -337,6 +344,29 @@ struct xref_value {
   Gedcom_ctxt object;
 };
 
+typedef enum _AGE_TYPE {
+  AGE_UNRECOGNIZED,
+  AGE_CHILD,
+  AGE_INFANT,
+  AGE_STILLBORN,
+  AGE_NUMERIC
+} Age_type;
+
+typedef enum _AGE_MODIFIER {
+  AGE_NO_MODIFIER,
+  AGE_LESS_THAN,
+  AGE_GREATER_THAN
+} Age_modifier;
+
+struct age_value {
+  Age_type type;
+  Age_modifier mod;
+  int years;
+  int months;
+  int days;
+  char phrase[MAX_PHRASE_LEN + 1];
+};
+
 /**************************************************************************/
 /***  Things meant to be internal, susceptible to changes               ***/
 /***  Use the GEDCOM_STRING/GEDCOM_DATE interface instead of relying    ***/
@@ -347,12 +377,14 @@ typedef enum _GEDCOM_VAL_TYPE {
   GV_NULL,
   GV_CHAR_PTR,
   GV_DATE_VALUE,
+  GV_AGE_VALUE,
   GV_XREF_PTR
 } Gedcom_val_type;
 
 union _Gedcom_val_union {
   char* string_val;
   struct date_value date_val;
+  struct age_value age_val;
   struct xref_value *xref_val;
 };
 
@@ -361,11 +393,12 @@ typedef struct _Gedcom_val_struct {
   union _Gedcom_val_union value;
 } Gedcom_val_struct;
 
-void gedcom_cast_error(char* file, int line,
+void gedcom_cast_error(const char* file, int line,
                       Gedcom_val_type tried_type,
                       Gedcom_val_type real_type);
 
 extern struct date_value def_date_val;
+extern struct age_value  def_age_val;
 extern struct xref_value def_xref_val;
 
 #define GV_CHECK_CAST(VAL, TYPE, MEMBER, DEFVAL)                              \
@@ -401,6 +434,13 @@ typedef Gedcom_val_struct* Gedcom_val;
 #define GEDCOM_IS_DATE(VAL) \
    GV_IS_TYPE(VAL, GV_DATE_VALUE)
 
+/* This returns the struct age_value from a Gedcom_val, if appropriate  */
+/* It gives a gedcom_warning if the cast is not correct                 */
+#define GEDCOM_AGE(VAL) \
+   GV_CHECK_CAST(VAL, GV_AGE_VALUE, age_val, def_age_val)
+#define GEDCOM_IS_AGE(VAL) \
+   GV_IS_TYPE(VAL, GV_AGE_VALUE)
+
 /* This returns the (struct xref_value *) from a Gedcom_val, if appropriate */
 /* It gives a gedcom_warning if the cast is not correct                     */
 #define GEDCOM_XREF_PTR(VAL) \
@@ -436,7 +476,8 @@ typedef void
          char *raw_value, int tag_value);
 
 void    gedcom_init();
-int     gedcom_parse_file(char* file_name);
+int     gedcom_parse_file(const char* file_name);
+int     gedcom_new_model();
 void    gedcom_set_debug_level(int level, FILE* trace_output);
 void    gedcom_set_error_handling(Gedcom_err_mech mechanism);
 void    gedcom_set_compat_handling(int enable_compat);
@@ -451,8 +492,25 @@ void    gedcom_subscribe_to_element(Gedcom_elt elt,
                                    Gedcom_elt_end_cb cb_end);
 
 /* Separate value parsing functions */
-struct date_value gedcom_parse_date(char* line_value);
-
-__END_DECLS
+struct date_value gedcom_parse_date(const char* line_value);
+struct age_value  gedcom_parse_age(const char* line_value);
+
+/* Handling cross-references */
+struct xref_value *gedcom_get_by_xref(const char *key);
+struct xref_value *gedcom_add_xref(Xref_type type, const char* xrefstr,
+                                   Gedcom_ctxt object);
+struct xref_value *gedcom_link_xref(Xref_type type, const char* xrefstr);
+struct xref_value *gedcom_unlink_xref(Xref_type type, const char* xrefstr);
+int                gedcom_delete_xref(const char* xrefstr);
+
+/* For use in gom */
+int        gedcom_error(const char* s, ...);
+int        gedcom_warning(const char* s, ...);
+int        gedcom_message(const char* s, ...);
+int        gedcom_debug_print(const char* s, ...);
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* __GEDCOM_H */