Process also html subdirectory.
[gedcom-parse.git] / include / gedcom.h.in
index 263f9fba4d34055f46943ab1b3088e571bb4769b..4d73b97f7ce8ffc80034427f7cf0e229ec05c550 100644 (file)
@@ -37,14 +37,17 @@ extern "C" {
 
 #define GEDCOM_PARSE_VERSION_MAJOR @VERSION_MAJOR@
 #define GEDCOM_PARSE_VERSION_MINOR @VERSION_MINOR@
+#define GEDCOM_PARSE_VERSION_PATCH @VERSION_PATCH@
 #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                  ***/
 /**************************************************************************/
                                                                           
-typedef enum _REC {
+typedef enum Gedcom_rec {
   REC_HEAD,
   REC_FAM,
   REC_INDI,
@@ -58,8 +61,8 @@ typedef enum _REC {
   NR_OF_RECS     /* Just a final value to be used in array boundaries */
 } Gedcom_rec;
 
-typedef enum _ELT {
-  ELT_HEAD_SOUR = NR_OF_RECS + 1,
+typedef enum Gedcom_elt {
+  ELT_HEAD_SOUR = NR_OF_RECS,
   ELT_HEAD_SOUR_VERS,
   ELT_HEAD_SOUR_NAME,
   ELT_HEAD_SOUR_CORP,
@@ -236,26 +239,47 @@ typedef enum _ELT {
 /**************************************************************************/
 /***  Definition of some auxiliary types                                ***/
 /**************************************************************************/
-                                                                          
-typedef enum _MECH {
-  IMMED_FAIL,
-  DEFER_FAIL,
-  IGNORE_ERRORS
-} Gedcom_err_mech;
-
-typedef enum _MSG {
-  ERROR,
-  WARNING,
-  MESSAGE
-} Gedcom_msg_type;
-
-typedef enum _DATE_TYPE {
+
+  /** \addtogroup error */
+  /** @{ */
+  /** \brief Error handling mechanisms.
+      
+      These are the possible error handling mechanisms.
+      See \ref gedcom_set_error_handling.
+  */
+enum _Gedcom_err_mech {
+  IMMED_FAIL,    /**< immediately fail the parsing on an error (this is
+                      the default) */
+  DEFER_FAIL,    /**< continue parsing after an error, but return a failure
+                      code eventually */
+  IGNORE_ERRORS  /**< continue parsing after an error, return success always */
+};
+
+  /** \brief Error handling mechanisms. */
+typedef enum _Gedcom_err_mech Gedcom_err_mech;
+
+  /** \brief Message type in message handler callbacks
+      
+      This will be passed to the message callback to indicate the message type.
+      See \ref gedcom_set_message_handler.
+  */
+enum _Gedcom_msg_type {
+  ERROR,               /**< An error message */
+  WARNING,             /**< A warning message */
+  MESSAGE              /**< Just a message */
+};
+
+  /** \brief Message type in message handler callbacks */
+typedef enum _Gedcom_msg_type Gedcom_msg_type;
+  /** @} */
+
+typedef enum Date_type {
   DATE_UNRECOGNIZED,   /* Neither jday1 as jday2 are significant */
   DATE_EXACT,          /* Only jday1 is significant */
   DATE_BOUNDED         /* Both jday1 and jday2 are significant */
 } Date_type;
 
-typedef enum _CALENDAR_TYPE {
+typedef enum Calendar_type {
   CAL_GREGORIAN,
   CAL_JULIAN,
   CAL_HEBREW,
@@ -263,12 +287,12 @@ typedef enum _CALENDAR_TYPE {
   CAL_UNKNOWN
 } Calendar_type;
 
-typedef enum _YEAR_TYPE {
+typedef enum Year_type {
   YEAR_SINGLE,
   YEAR_DOUBLE     /* In this case, the 'year' indicates the last value */
 } Year_type;
 
-typedef enum _DATE_VAL_MOD {
+typedef enum Date_value_type {
   /* Simple date */
   DV_NO_MODIFIER,
   /* Range values */
@@ -321,7 +345,7 @@ struct date_value {
 /* Type for context handling, meant to be opaque */
 typedef void* Gedcom_ctxt;
 
-typedef enum _XREF_TYPE {
+typedef enum Xref_type {
   XREF_NONE,
   XREF_FAM,
   XREF_INDI,
@@ -341,7 +365,7 @@ struct xref_value {
   Gedcom_ctxt object;
 };
 
-typedef enum _AGE_TYPE {
+typedef enum Age_type {
   AGE_UNRECOGNIZED,
   AGE_CHILD,
   AGE_INFANT,
@@ -349,7 +373,7 @@ typedef enum _AGE_TYPE {
   AGE_NUMERIC
 } Age_type;
 
-typedef enum _AGE_MODIFIER {
+typedef enum Age_modifier {
   AGE_NO_MODIFIER,
   AGE_LESS_THAN,
   AGE_GREATER_THAN
@@ -364,18 +388,55 @@ struct age_value {
   char phrase[MAX_PHRASE_LEN + 1];
 };
 
+typedef enum Encoding {
+  ONE_BYTE      = 0x00,
+  TWO_BYTE_HILO = 0x01,
+  TWO_BYTE_LOHI = 0x02
+} Encoding;
+
+typedef enum Enc_bom {
+  WITHOUT_BOM = 0x00,
+  WITH_BOM    = 0x10
+} Enc_bom;
+
+typedef enum Enc_line_end {
+  END_CR    = 0,
+  END_LF    = 1,
+  END_CR_LF = 2,
+  END_LF_CR = 3
+} Enc_line_end;
+
+typedef enum Enc_from {
+  ENC_FROM_FILE = 0,
+  ENC_FROM_SYS  = 1,
+  ENC_MANUAL    = 2
+} Enc_from;
+
+struct encoding_state;
+
+typedef enum Date_input {
+  DI_FROM_STRINGS,
+  DI_FROM_NUMBERS,
+  DI_FROM_SDN
+} Date_input;
+
+typedef enum Gedcom_compat {
+  COMPAT_ALLOW_OUT_OF_CONTEXT = 0x01
+} Gedcom_compat;
+
 /**************************************************************************/
 /***  Things meant to be internal, susceptible to changes               ***/
 /***  Use the GEDCOM_STRING/GEDCOM_DATE interface instead of relying    ***/
 /***  on this !!                                                        ***/
 /**************************************************************************/
-                                                                          
+
+/* Update strings in interface.c if this changes */
 typedef enum _GEDCOM_VAL_TYPE {
-  GV_NULL,
-  GV_CHAR_PTR,
-  GV_DATE_VALUE,
-  GV_AGE_VALUE,
-  GV_XREF_PTR
+  GV_NULL       = 0x01,
+  GV_CHAR_PTR   = 0x02,
+  GV_DATE_VALUE = 0x04,
+  GV_AGE_VALUE  = 0x08,
+  GV_XREF_PTR   = 0x10
 } Gedcom_val_type;
 
 union _Gedcom_val_union {
@@ -399,12 +460,12 @@ extern struct age_value  def_age_val;
 extern struct xref_value def_xref_val;
 
 #define GV_CHECK_CAST(VAL, TYPE, MEMBER, DEFVAL)                              \
-   ((VAL->type == TYPE) ?                                                     \
-    VAL->value.MEMBER :                                                       \
-    (gedcom_cast_error(__FILE__,__LINE__, TYPE, VAL->type), DEFVAL))
+   (((VAL)->type == TYPE) ?                                                   \
+    (VAL)->value.MEMBER :                                                     \
+    (gedcom_cast_error(__FILE__,__LINE__, TYPE, (VAL)->type), DEFVAL))
 
 #define GV_IS_TYPE(VAL, TYPE)                                                 \
-   (VAL->type == TYPE)
+   ((VAL)->type == TYPE)
 
 /**************************************************************************/
 /***  Function interface                                                ***/
@@ -413,6 +474,10 @@ extern struct xref_value def_xref_val;
 /* Type for parsed values, meant to be opaque */
 typedef Gedcom_val_struct* Gedcom_val;
 
+/* Type for write handle, meant to be opaque */
+struct Gedcom_write_struct;
+typedef struct Gedcom_write_struct* Gedcom_write_hndl;
+
 /* Check to determine whether there is a parsed value or not */
 #define GEDCOM_IS_NULL(VAL) \
    GV_IS_TYPE(VAL, GV_NULL)
@@ -445,6 +510,10 @@ typedef Gedcom_val_struct* Gedcom_val;
 #define GEDCOM_IS_XREF_PTR(VAL) \
    GV_IS_TYPE(VAL, GV_XREF_PTR)
 
+  /** \brief Message handler callback
+      \ingroup error
+      See description of \ref gedcom_set_message_handler().
+  */
 typedef void
         (*Gedcom_msg_handler)
         (Gedcom_msg_type type, char *msg);
@@ -455,7 +524,7 @@ typedef Gedcom_ctxt
          char *raw_value, int tag_value, Gedcom_val parsed_value);
 typedef void
         (*Gedcom_rec_end_cb)
-        (Gedcom_rec rec, Gedcom_ctxt self);
+        (Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value);
 
 typedef Gedcom_ctxt
         (*Gedcom_elt_start_cb)
@@ -472,13 +541,27 @@ typedef void
         (Gedcom_elt elt, Gedcom_ctxt parent, int level, char *tag,
          char *raw_value, int tag_value);
 
-void    gedcom_init();
+  /** \addtogroup main */
+  /** @{ */
+  /** \brief Initializes the Gedcom parser library */
+int     gedcom_init();
+  /** \brief Parses an existing Gedcom file */
 int     gedcom_parse_file(const char* file_name);
+  /** \brief Starts a new Gedcom model */
 int     gedcom_new_model();
-void    gedcom_set_debug_level(int level, FILE* trace_output);
+  /** @} */
+
+  /** \addtogroup error */
+  /** @{ */
+  /** \brief Sets the error handler callback */
+void    gedcom_set_message_handler(Gedcom_msg_handler func);
+  /** \brief Determine what happens on an error */
 void    gedcom_set_error_handling(Gedcom_err_mech mechanism);
+  /** @} */
+  
+void    gedcom_set_debug_level(int level, FILE* trace_output);
 void    gedcom_set_compat_handling(int enable_compat);
-void    gedcom_set_message_handler(Gedcom_msg_handler func);
+void    gedcom_set_compat_options(Gedcom_compat options);
 void    gedcom_set_default_callback(Gedcom_def_cb func);
 
 void    gedcom_subscribe_to_record(Gedcom_rec rec,
@@ -489,8 +572,14 @@ void    gedcom_subscribe_to_element(Gedcom_elt elt,
                                    Gedcom_elt_end_cb cb_end);
 
 /* Separate value parsing functions */
-struct date_value gedcom_parse_date(const char* line_value);
+struct date_value  gedcom_parse_date(const char* line_value);
+char*              gedcom_date_to_string(const struct date_value* val);
+struct date_value* gedcom_new_date_value(const struct date_value* copy_from);
+int   gedcom_normalize_date(Date_input compute_from, struct date_value *val);
+
 struct age_value  gedcom_parse_age(const char* line_value);
+struct age_value* gedcom_new_age_value(const struct age_value* copy_from);
+char*             gedcom_age_to_string(const struct age_value* val);
 
 /* Handling cross-references */
 struct xref_value *gedcom_get_by_xref(const char *key);
@@ -500,6 +589,37 @@ 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);
 
+/* Writing support */
+Gedcom_write_hndl  gedcom_write_open(const char* filename);
+int  gedcom_write_close(Gedcom_write_hndl hndl, int *total_conv_fails);
+int  gedcom_write_set_encoding(Enc_from from,
+                              const char* charset, Encoding width,
+                               Enc_bom bom);
+int  gedcom_write_set_line_terminator(Enc_from from, Enc_line_end end);
+
+int  gedcom_write_record_str(Gedcom_write_hndl hndl,
+                            Gedcom_rec rec, const char* xrefstr,
+                             const char* val);
+  
+int gedcom_write_element_str(Gedcom_write_hndl hndl, Gedcom_elt elt,
+                            int parsed_tag, int parent_rec_or_elt,
+                            const char* val);
+int gedcom_write_element_xref(Gedcom_write_hndl hndl, Gedcom_elt elt,
+                              int parsed_tag, int parent_rec_or_elt,
+                             const struct xref_value* val);
+
+int gedcom_write_element_date(Gedcom_write_hndl hndl,
+                             Gedcom_elt elt, int tag, int parent_rec_or_elt,
+                             const struct date_value* val);
+int gedcom_write_element_age(Gedcom_write_hndl hndl,
+                            Gedcom_elt elt, int tag, int parent_rec_or_elt,
+                            const struct age_value* val);
+
+int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, const char* tag,
+                         const char* xrefstr, const char* value);
+int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, const char* tag,
+                          const char* xrefstr, const struct xref_value* val);
+
 /* For use in gom */
 int        gedcom_error(const char* s, ...);
 int        gedcom_warning(const char* s, ...);