1 /* External header for the Gedcom parser library.
2 Copyright (C) 2001,2002 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
6 The Gedcom parser library is free software; you can redistribute it
7 and/or modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The Gedcom parser library is distributed in the hope that it will be
12 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the Gedcom parser library; if not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
34 #ifndef GEDCOM_INTERNAL
35 #include <gedcom-tags.h>
38 #define GEDCOM_PARSE_VERSION_MAJOR @VERSION_MAJOR@
39 #define GEDCOM_PARSE_VERSION_MINOR @VERSION_MINOR@
40 #define GEDCOM_PARSE_VERSION_PATCH @VERSION_PATCH@
41 #define GEDCOM_PARSE_VERSION \
42 (GEDCOM_PARSE_VERSION_MAJOR * 1000 + GEDCOM_PARSE_VERSION_MINOR)
44 int gedcom_check_version(int major, int minor, int patch);
46 /**************************************************************************/
47 /*** First the records and elements to subscribe upon ***/
48 /**************************************************************************/
50 typedef enum Gedcom_rec {
61 NR_OF_RECS /* Just a final value to be used in array boundaries */
64 typedef enum Gedcom_elt {
65 ELT_HEAD_SOUR = NR_OF_RECS,
70 ELT_HEAD_SOUR_DATA_DATE,
71 ELT_HEAD_SOUR_DATA_COPR,
114 ELT_SOUR_DATA_EVEN_DATE,
115 ELT_SOUR_DATA_EVEN_PLAC,
168 ELT_SUB_FAM_EVT_HUSB,
169 ELT_SUB_FAM_EVT_WIFE,
171 ELT_SUB_FAM_EVT_EVEN,
174 ELT_SUB_IDENT_REFN_TYPE,
180 ELT_SUB_INDIV_BIRT_FAMC,
183 ELT_SUB_INDIV_ADOP_FAMC,
184 ELT_SUB_INDIV_ADOP_FAMC_ADOP,
188 ELT_SUB_LIO_BAPL_STAT,
189 ELT_SUB_LIO_BAPL_DATE,
190 ELT_SUB_LIO_BAPL_TEMP,
191 ELT_SUB_LIO_BAPL_PLAC,
193 ELT_SUB_LIO_SLGC_FAMC,
196 ELT_SUB_LSS_SLGS_STAT,
197 ELT_SUB_LSS_SLGS_DATE,
198 ELT_SUB_LSS_SLGS_TEMP,
199 ELT_SUB_LSS_SLGS_PLAC,
202 ELT_SUB_MULTIM_OBJE_FORM,
203 ELT_SUB_MULTIM_OBJE_TITL,
204 ELT_SUB_MULTIM_OBJE_FILE,
209 ELT_SUB_PERS_NAME_NPFX,
210 ELT_SUB_PERS_NAME_GIVN,
211 ELT_SUB_PERS_NAME_NICK,
212 ELT_SUB_PERS_NAME_SPFX,
213 ELT_SUB_PERS_NAME_SURN,
214 ELT_SUB_PERS_NAME_NSFX,
222 ELT_SUB_SOUR_EVEN_ROLE,
224 ELT_SUB_SOUR_DATA_DATE,
230 ELT_SUB_REPO_CALN_MEDI,
236 NR_OF_ELTS /* Just a final value to be used in array boundaries */
239 /**************************************************************************/
240 /*** Definition of some auxiliary types ***/
241 /**************************************************************************/
243 typedef enum Gedcom_err_mech {
249 /** \brief Message type in message handler callbacks
251 typedef enum Gedcom_msg_type {
257 typedef enum Date_type {
258 DATE_UNRECOGNIZED, /* Neither jday1 as jday2 are significant */
259 DATE_EXACT, /* Only jday1 is significant */
260 DATE_BOUNDED /* Both jday1 and jday2 are significant */
263 typedef enum Calendar_type {
271 typedef enum Year_type {
273 YEAR_DOUBLE /* In this case, the 'year' indicates the last value */
276 typedef enum Date_value_type {
282 DV_BETWEEN, /* Two dates are given */
286 DV_FROM_TO, /* Two dates are given */
292 DV_INTERPRETED, /* One date and a phrase is given */
293 DV_PHRASE /* Only phrase is given */
296 /* All Unicode characters between U+0000 and U+FFFF can be encoded in
297 UTF-8 with 3 or less bytes */
300 #define MAX_DAY_LEN 2
301 #define MAX_MONTH_LEN 4
302 #define MAX_YEAR_LEN 7
303 #define MAX_PHRASE_LEN 35 * UTF_FACTOR
307 char day_str[MAX_DAY_LEN + 1];
308 char month_str[MAX_MONTH_LEN + 1];
309 char year_str[MAX_YEAR_LEN + 1];
310 int day; /* starts at 1 */
311 int month; /* starts at 1 */
312 int year; /* the highest value for double years */
320 Date_value_type type;
323 char phrase[MAX_PHRASE_LEN + 1];
326 /* Type for context handling, meant to be opaque */
327 typedef void* Gedcom_ctxt;
329 typedef enum Xref_type {
349 typedef enum Age_type {
357 typedef enum Age_modifier {
369 char phrase[MAX_PHRASE_LEN + 1];
372 typedef enum Encoding {
374 TWO_BYTE_HILO = 0x01,
378 typedef enum Enc_bom {
383 typedef enum Enc_line_end {
390 typedef enum Enc_from {
396 struct encoding_state;
398 typedef enum Date_input {
404 typedef enum Gedcom_compat {
405 COMPAT_ALLOW_OUT_OF_CONTEXT = 0x01
408 /**************************************************************************/
409 /*** Things meant to be internal, susceptible to changes ***/
410 /*** Use the GEDCOM_STRING/GEDCOM_DATE interface instead of relying ***/
412 /**************************************************************************/
414 /* Update strings in interface.c if this changes */
415 typedef enum _GEDCOM_VAL_TYPE {
418 GV_DATE_VALUE = 0x04,
423 union _Gedcom_val_union {
425 struct date_value date_val;
426 struct age_value age_val;
427 struct xref_value *xref_val;
430 typedef struct _Gedcom_val_struct {
431 Gedcom_val_type type;
432 union _Gedcom_val_union value;
435 void gedcom_cast_error(const char* file, int line,
436 Gedcom_val_type tried_type,
437 Gedcom_val_type real_type);
439 extern struct date_value def_date_val;
440 extern struct age_value def_age_val;
441 extern struct xref_value def_xref_val;
443 #define GV_CHECK_CAST(VAL, TYPE, MEMBER, DEFVAL) \
444 (((VAL)->type == TYPE) ? \
445 (VAL)->value.MEMBER : \
446 (gedcom_cast_error(__FILE__,__LINE__, TYPE, (VAL)->type), DEFVAL))
448 #define GV_IS_TYPE(VAL, TYPE) \
449 ((VAL)->type == TYPE)
451 /**************************************************************************/
452 /*** Function interface ***/
453 /**************************************************************************/
455 /* Type for parsed values, meant to be opaque */
456 typedef Gedcom_val_struct* Gedcom_val;
458 /* Type for write handle, meant to be opaque */
459 struct Gedcom_write_struct;
460 typedef struct Gedcom_write_struct* Gedcom_write_hndl;
462 /* Check to determine whether there is a parsed value or not */
463 #define GEDCOM_IS_NULL(VAL) \
464 GV_IS_TYPE(VAL, GV_NULL)
466 /* This returns the char* from a Gedcom_val, if appropriate */
467 /* It gives a gedcom_warning if the cast is not correct */
468 #define GEDCOM_STRING(VAL) \
469 GV_CHECK_CAST(VAL, GV_CHAR_PTR, string_val, "<error>")
470 #define GEDCOM_IS_STRING(VAL) \
471 GV_IS_TYPE(VAL, GV_CHAR_PTR)
473 /* This returns the struct date_value from a Gedcom_val, if appropriate */
474 /* It gives a gedcom_warning if the cast is not correct */
475 #define GEDCOM_DATE(VAL) \
476 GV_CHECK_CAST(VAL, GV_DATE_VALUE, date_val, def_date_val)
477 #define GEDCOM_IS_DATE(VAL) \
478 GV_IS_TYPE(VAL, GV_DATE_VALUE)
480 /* This returns the struct age_value from a Gedcom_val, if appropriate */
481 /* It gives a gedcom_warning if the cast is not correct */
482 #define GEDCOM_AGE(VAL) \
483 GV_CHECK_CAST(VAL, GV_AGE_VALUE, age_val, def_age_val)
484 #define GEDCOM_IS_AGE(VAL) \
485 GV_IS_TYPE(VAL, GV_AGE_VALUE)
487 /* This returns the (struct xref_value *) from a Gedcom_val, if appropriate */
488 /* It gives a gedcom_warning if the cast is not correct */
489 #define GEDCOM_XREF_PTR(VAL) \
490 GV_CHECK_CAST(VAL, GV_XREF_PTR, xref_val, &def_xref_val)
491 #define GEDCOM_IS_XREF_PTR(VAL) \
492 GV_IS_TYPE(VAL, GV_XREF_PTR)
494 /** \brief Message handler callback
497 (*Gedcom_msg_handler)
498 (Gedcom_msg_type type, char *msg);
501 (*Gedcom_rec_start_cb)
502 (Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
503 char *raw_value, int tag_value, Gedcom_val parsed_value);
506 (Gedcom_rec rec, Gedcom_ctxt self, Gedcom_val parsed_value);
509 (*Gedcom_elt_start_cb)
510 (Gedcom_elt elt, Gedcom_ctxt parent,
511 int level, char *tag, char *raw_value,
512 int tag_value, Gedcom_val parsed_value);
515 (Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
516 Gedcom_val parsed_value);
520 (Gedcom_elt elt, Gedcom_ctxt parent, int level, char *tag,
521 char *raw_value, int tag_value);
523 /** \brief Initializes the Gedcom parser library
526 /** \brief Parses an existing Gedcom file
528 int gedcom_parse_file(const char* file_name);
529 /** \brief Starts a new Gedcom model
531 int gedcom_new_model();
533 /** \brief Sets the error handler callback
535 void gedcom_set_message_handler(Gedcom_msg_handler func);
537 void gedcom_set_error_handling(Gedcom_err_mech mechanism);
538 void gedcom_set_debug_level(int level, FILE* trace_output);
539 void gedcom_set_compat_handling(int enable_compat);
540 void gedcom_set_compat_options(Gedcom_compat options);
541 void gedcom_set_default_callback(Gedcom_def_cb func);
543 void gedcom_subscribe_to_record(Gedcom_rec rec,
544 Gedcom_rec_start_cb cb_start,
545 Gedcom_rec_end_cb cb_end);
546 void gedcom_subscribe_to_element(Gedcom_elt elt,
547 Gedcom_elt_start_cb cb_start,
548 Gedcom_elt_end_cb cb_end);
550 /* Separate value parsing functions */
551 struct date_value gedcom_parse_date(const char* line_value);
552 char* gedcom_date_to_string(const struct date_value* val);
553 struct date_value* gedcom_new_date_value(const struct date_value* copy_from);
554 int gedcom_normalize_date(Date_input compute_from, struct date_value *val);
556 struct age_value gedcom_parse_age(const char* line_value);
557 struct age_value* gedcom_new_age_value(const struct age_value* copy_from);
558 char* gedcom_age_to_string(const struct age_value* val);
560 /* Handling cross-references */
561 struct xref_value *gedcom_get_by_xref(const char *key);
562 struct xref_value *gedcom_add_xref(Xref_type type, const char* xrefstr,
564 struct xref_value *gedcom_link_xref(Xref_type type, const char* xrefstr);
565 struct xref_value *gedcom_unlink_xref(Xref_type type, const char* xrefstr);
566 int gedcom_delete_xref(const char* xrefstr);
568 /* Writing support */
569 Gedcom_write_hndl gedcom_write_open(const char* filename);
570 int gedcom_write_close(Gedcom_write_hndl hndl, int *total_conv_fails);
571 int gedcom_write_set_encoding(Enc_from from,
572 const char* charset, Encoding width,
574 int gedcom_write_set_line_terminator(Enc_from from, Enc_line_end end);
576 int gedcom_write_record_str(Gedcom_write_hndl hndl,
577 Gedcom_rec rec, const char* xrefstr,
580 int gedcom_write_element_str(Gedcom_write_hndl hndl, Gedcom_elt elt,
581 int parsed_tag, int parent_rec_or_elt,
583 int gedcom_write_element_xref(Gedcom_write_hndl hndl, Gedcom_elt elt,
584 int parsed_tag, int parent_rec_or_elt,
585 const struct xref_value* val);
587 int gedcom_write_element_date(Gedcom_write_hndl hndl,
588 Gedcom_elt elt, int tag, int parent_rec_or_elt,
589 const struct date_value* val);
590 int gedcom_write_element_age(Gedcom_write_hndl hndl,
591 Gedcom_elt elt, int tag, int parent_rec_or_elt,
592 const struct age_value* val);
594 int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, const char* tag,
595 const char* xrefstr, const char* value);
596 int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, const char* tag,
597 const char* xrefstr, const struct xref_value* val);
600 int gedcom_error(const char* s, ...);
601 int gedcom_warning(const char* s, ...);
602 int gedcom_message(const char* s, ...);
603 int gedcom_debug_print(const char* s, ...);
609 #endif /* __GEDCOM_H */