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 0
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 /**************************************************************************/
61 NR_OF_RECS /* Just a final value to be used in array boundaries */
65 ELT_HEAD_SOUR = NR_OF_RECS + 1,
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 /**************************************************************************/
255 typedef enum _DATE_TYPE {
256 DATE_UNRECOGNIZED, /* Neither jday1 as jday2 are significant */
257 DATE_EXACT, /* Only jday1 is significant */
258 DATE_BOUNDED /* Both jday1 and jday2 are significant */
261 typedef enum _CALENDAR_TYPE {
269 typedef enum _YEAR_TYPE {
271 YEAR_DOUBLE /* In this case, the 'year' indicates the last value */
274 typedef enum _DATE_VAL_MOD {
280 DV_BETWEEN, /* Two dates are given */
284 DV_FROM_TO, /* Two dates are given */
290 DV_INTERPRETED, /* One date and a phrase is given */
291 DV_PHRASE /* Only phrase is given */
294 /* All Unicode characters between U+0000 and U+FFFF can be encoded in
295 UTF-8 with 3 or less bytes */
298 #define MAX_DAY_LEN 2
299 #define MAX_MONTH_LEN 4
300 #define MAX_YEAR_LEN 7
301 #define MAX_PHRASE_LEN 35 * UTF_FACTOR
305 char day_str[MAX_DAY_LEN + 1];
306 char month_str[MAX_MONTH_LEN + 1];
307 char year_str[MAX_YEAR_LEN + 1];
308 int day; /* starts at 1 */
309 int month; /* starts at 1 */
310 int year; /* the highest value for double years */
318 Date_value_type type;
321 char phrase[MAX_PHRASE_LEN + 1];
324 /* Type for context handling, meant to be opaque */
325 typedef void* Gedcom_ctxt;
327 typedef enum _XREF_TYPE {
347 typedef enum _AGE_TYPE {
355 typedef enum _AGE_MODIFIER {
367 char phrase[MAX_PHRASE_LEN + 1];
370 /**************************************************************************/
371 /*** Things meant to be internal, susceptible to changes ***/
372 /*** Use the GEDCOM_STRING/GEDCOM_DATE interface instead of relying ***/
374 /**************************************************************************/
376 typedef enum _GEDCOM_VAL_TYPE {
384 union _Gedcom_val_union {
386 struct date_value date_val;
387 struct age_value age_val;
388 struct xref_value *xref_val;
391 typedef struct _Gedcom_val_struct {
392 Gedcom_val_type type;
393 union _Gedcom_val_union value;
396 void gedcom_cast_error(const char* file, int line,
397 Gedcom_val_type tried_type,
398 Gedcom_val_type real_type);
400 extern struct date_value def_date_val;
401 extern struct age_value def_age_val;
402 extern struct xref_value def_xref_val;
404 #define GV_CHECK_CAST(VAL, TYPE, MEMBER, DEFVAL) \
405 ((VAL->type == TYPE) ? \
406 VAL->value.MEMBER : \
407 (gedcom_cast_error(__FILE__,__LINE__, TYPE, VAL->type), DEFVAL))
409 #define GV_IS_TYPE(VAL, TYPE) \
412 /**************************************************************************/
413 /*** Function interface ***/
414 /**************************************************************************/
416 /* Type for parsed values, meant to be opaque */
417 typedef Gedcom_val_struct* Gedcom_val;
419 /* Check to determine whether there is a parsed value or not */
420 #define GEDCOM_IS_NULL(VAL) \
421 GV_IS_TYPE(VAL, GV_NULL)
423 /* This returns the char* from a Gedcom_val, if appropriate */
424 /* It gives a gedcom_warning if the cast is not correct */
425 #define GEDCOM_STRING(VAL) \
426 GV_CHECK_CAST(VAL, GV_CHAR_PTR, string_val, "<error>")
427 #define GEDCOM_IS_STRING(VAL) \
428 GV_IS_TYPE(VAL, GV_CHAR_PTR)
430 /* This returns the struct date_value from a Gedcom_val, if appropriate */
431 /* It gives a gedcom_warning if the cast is not correct */
432 #define GEDCOM_DATE(VAL) \
433 GV_CHECK_CAST(VAL, GV_DATE_VALUE, date_val, def_date_val)
434 #define GEDCOM_IS_DATE(VAL) \
435 GV_IS_TYPE(VAL, GV_DATE_VALUE)
437 /* This returns the struct age_value from a Gedcom_val, if appropriate */
438 /* It gives a gedcom_warning if the cast is not correct */
439 #define GEDCOM_AGE(VAL) \
440 GV_CHECK_CAST(VAL, GV_AGE_VALUE, age_val, def_age_val)
441 #define GEDCOM_IS_AGE(VAL) \
442 GV_IS_TYPE(VAL, GV_AGE_VALUE)
444 /* This returns the (struct xref_value *) from a Gedcom_val, if appropriate */
445 /* It gives a gedcom_warning if the cast is not correct */
446 #define GEDCOM_XREF_PTR(VAL) \
447 GV_CHECK_CAST(VAL, GV_XREF_PTR, xref_val, &def_xref_val)
448 #define GEDCOM_IS_XREF_PTR(VAL) \
449 GV_IS_TYPE(VAL, GV_XREF_PTR)
452 (*Gedcom_msg_handler)
453 (Gedcom_msg_type type, char *msg);
456 (*Gedcom_rec_start_cb)
457 (Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
458 char *raw_value, int tag_value, Gedcom_val parsed_value);
461 (Gedcom_rec rec, Gedcom_ctxt self);
464 (*Gedcom_elt_start_cb)
465 (Gedcom_elt elt, Gedcom_ctxt parent,
466 int level, char *tag, char *raw_value,
467 int tag_value, Gedcom_val parsed_value);
470 (Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
471 Gedcom_val parsed_value);
475 (Gedcom_elt elt, Gedcom_ctxt parent, int level, char *tag,
476 char *raw_value, int tag_value);
479 int gedcom_parse_file(const char* file_name);
480 int gedcom_new_model();
481 void gedcom_set_debug_level(int level, FILE* trace_output);
482 void gedcom_set_error_handling(Gedcom_err_mech mechanism);
483 void gedcom_set_compat_handling(int enable_compat);
484 void gedcom_set_message_handler(Gedcom_msg_handler func);
485 void gedcom_set_default_callback(Gedcom_def_cb func);
487 void gedcom_subscribe_to_record(Gedcom_rec rec,
488 Gedcom_rec_start_cb cb_start,
489 Gedcom_rec_end_cb cb_end);
490 void gedcom_subscribe_to_element(Gedcom_elt elt,
491 Gedcom_elt_start_cb cb_start,
492 Gedcom_elt_end_cb cb_end);
494 /* Separate value parsing functions */
495 struct date_value gedcom_parse_date(const char* line_value);
496 struct age_value gedcom_parse_age(const char* line_value);
498 /* Handling cross-references */
499 struct xref_value *gedcom_get_by_xref(const char *key);
500 struct xref_value *gedcom_add_xref(Xref_type type, const char* xrefstr,
502 struct xref_value *gedcom_link_xref(Xref_type type, const char* xrefstr);
503 struct xref_value *gedcom_unlink_xref(Xref_type type, const char* xrefstr);
504 int gedcom_delete_xref(const char* xrefstr);
507 int gedcom_error(const char* s, ...);
508 int gedcom_warning(const char* s, ...);
509 int gedcom_message(const char* s, ...);
510 int gedcom_debug_print(const char* s, ...);
516 #endif /* __GEDCOM_H */