X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=include%2Fgedcom.h.in;h=8129975e38fce31ee121a57f45c608be419f97bb;hb=31fb8432ef01f9d5a08cc801a785a07b4e9d12bd;hp=8a2fb5abd4ee71d19435ac72a14613ec82e4cc11;hpb=f08bf1b4ba225219726e65ba65f41f11120933d8;p=gedcom-parse.git diff --git a/include/gedcom.h.in b/include/gedcom.h.in index 8a2fb5a..8129975 100644 --- a/include/gedcom.h.in +++ b/include/gedcom.h.in @@ -25,8 +25,11 @@ #define __GEDCOM_H #include +#include -__BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif #ifndef GEDCOM_INTERNAL #include @@ -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 @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 ***/ /**************************************************************************/ @@ -56,7 +62,7 @@ typedef enum _REC { } Gedcom_rec; typedef enum _ELT { - ELT_HEAD_SOUR = NR_OF_RECS + 1, + ELT_HEAD_SOUR = NR_OF_RECS, ELT_HEAD_SOUR_VERS, ELT_HEAD_SOUR_NAME, ELT_HEAD_SOUR_CORP, @@ -361,18 +367,51 @@ struct age_value { char phrase[MAX_PHRASE_LEN + 1]; }; +typedef enum _ENC { + 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; + /**************************************************************************/ /*** 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 { @@ -387,7 +426,7 @@ 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); @@ -410,6 +449,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) @@ -452,7 +495,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) @@ -469,8 +512,9 @@ typedef void (Gedcom_elt elt, Gedcom_ctxt parent, int level, char *tag, char *raw_value, int tag_value); -void gedcom_init(); -int gedcom_parse_file(char* file_name); +int gedcom_init(); +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); @@ -485,10 +529,62 @@ 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); -struct age_value gedcom_parse_age(char* line_value); -struct xref_value *gedcom_get_by_xref(char *key); - -__END_DECLS +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); +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); + +/* 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, ...); +int gedcom_message(const char* s, ...); +int gedcom_debug_print(const char* s, ...); + +#ifdef __cplusplus +} +#endif #endif /* __GEDCOM_H */