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 \
41 (GEDCOM_PARSE_VERSION_MAJOR * 1000 + GEDCOM_PARSE_VERSION_MINOR)
43 /**************************************************************************/
44 /*** First the records and elements to subscribe upon ***/
45 /**************************************************************************/
58 NR_OF_RECS /* Just a final value to be used in array boundaries */
62 ELT_HEAD_SOUR = NR_OF_RECS + 1,
67 ELT_HEAD_SOUR_DATA_DATE,
68 ELT_HEAD_SOUR_DATA_COPR,
111 ELT_SOUR_DATA_EVEN_DATE,
112 ELT_SOUR_DATA_EVEN_PLAC,
165 ELT_SUB_FAM_EVT_HUSB,
166 ELT_SUB_FAM_EVT_WIFE,
168 ELT_SUB_FAM_EVT_EVEN,
171 ELT_SUB_IDENT_REFN_TYPE,
177 ELT_SUB_INDIV_BIRT_FAMC,
180 ELT_SUB_INDIV_ADOP_FAMC,
181 ELT_SUB_INDIV_ADOP_FAMC_ADOP,
185 ELT_SUB_LIO_BAPL_STAT,
186 ELT_SUB_LIO_BAPL_DATE,
187 ELT_SUB_LIO_BAPL_TEMP,
188 ELT_SUB_LIO_BAPL_PLAC,
190 ELT_SUB_LIO_SLGC_FAMC,
193 ELT_SUB_LSS_SLGS_STAT,
194 ELT_SUB_LSS_SLGS_DATE,
195 ELT_SUB_LSS_SLGS_TEMP,
196 ELT_SUB_LSS_SLGS_PLAC,
199 ELT_SUB_MULTIM_OBJE_FORM,
200 ELT_SUB_MULTIM_OBJE_TITL,
201 ELT_SUB_MULTIM_OBJE_FILE,
206 ELT_SUB_PERS_NAME_NPFX,
207 ELT_SUB_PERS_NAME_GIVN,
208 ELT_SUB_PERS_NAME_NICK,
209 ELT_SUB_PERS_NAME_SPFX,
210 ELT_SUB_PERS_NAME_SURN,
211 ELT_SUB_PERS_NAME_NSFX,
219 ELT_SUB_SOUR_EVEN_ROLE,
221 ELT_SUB_SOUR_DATA_DATE,
227 ELT_SUB_REPO_CALN_MEDI,
233 NR_OF_ELTS /* Just a final value to be used in array boundaries */
236 /**************************************************************************/
237 /*** Definition of some auxiliary types ***/
238 /**************************************************************************/
252 typedef enum _DATE_TYPE {
253 DATE_UNRECOGNIZED, /* Neither jday1 as jday2 are significant */
254 DATE_EXACT, /* Only jday1 is significant */
255 DATE_BOUNDED /* Both jday1 and jday2 are significant */
258 typedef enum _CALENDAR_TYPE {
266 typedef enum _YEAR_TYPE {
268 YEAR_DOUBLE /* In this case, the 'year' indicates the last value */
271 typedef enum _DATE_VAL_MOD {
277 DV_BETWEEN, /* Two dates are given */
281 DV_FROM_TO, /* Two dates are given */
287 DV_INTERPRETED, /* One date and a phrase is given */
288 DV_PHRASE /* Only phrase is given */
291 /* All Unicode characters between U+0000 and U+FFFF can be encoded in
292 UTF-8 with 3 or less bytes */
295 #define MAX_DAY_LEN 2
296 #define MAX_MONTH_LEN 4
297 #define MAX_YEAR_LEN 7
298 #define MAX_PHRASE_LEN 35 * UTF_FACTOR
302 char day_str[MAX_DAY_LEN + 1];
303 char month_str[MAX_MONTH_LEN + 1];
304 char year_str[MAX_YEAR_LEN + 1];
305 int day; /* starts at 1 */
306 int month; /* starts at 1 */
307 int year; /* the highest value for double years */
315 Date_value_type type;
318 char phrase[MAX_PHRASE_LEN + 1];
321 /* Type for context handling, meant to be opaque */
322 typedef void* Gedcom_ctxt;
324 typedef enum _XREF_TYPE {
344 typedef enum _AGE_TYPE {
352 typedef enum _AGE_MODIFIER {
364 char phrase[MAX_PHRASE_LEN + 1];
367 /**************************************************************************/
368 /*** Things meant to be internal, susceptible to changes ***/
369 /*** Use the GEDCOM_STRING/GEDCOM_DATE interface instead of relying ***/
371 /**************************************************************************/
373 typedef enum _GEDCOM_VAL_TYPE {
381 union _Gedcom_val_union {
383 struct date_value date_val;
384 struct age_value age_val;
385 struct xref_value *xref_val;
388 typedef struct _Gedcom_val_struct {
389 Gedcom_val_type type;
390 union _Gedcom_val_union value;
393 void gedcom_cast_error(const char* file, int line,
394 Gedcom_val_type tried_type,
395 Gedcom_val_type real_type);
397 extern struct date_value def_date_val;
398 extern struct age_value def_age_val;
399 extern struct xref_value def_xref_val;
401 #define GV_CHECK_CAST(VAL, TYPE, MEMBER, DEFVAL) \
402 ((VAL->type == TYPE) ? \
403 VAL->value.MEMBER : \
404 (gedcom_cast_error(__FILE__,__LINE__, TYPE, VAL->type), DEFVAL))
406 #define GV_IS_TYPE(VAL, TYPE) \
409 /**************************************************************************/
410 /*** Function interface ***/
411 /**************************************************************************/
413 /* Type for parsed values, meant to be opaque */
414 typedef Gedcom_val_struct* Gedcom_val;
416 /* Check to determine whether there is a parsed value or not */
417 #define GEDCOM_IS_NULL(VAL) \
418 GV_IS_TYPE(VAL, GV_NULL)
420 /* This returns the char* from a Gedcom_val, if appropriate */
421 /* It gives a gedcom_warning if the cast is not correct */
422 #define GEDCOM_STRING(VAL) \
423 GV_CHECK_CAST(VAL, GV_CHAR_PTR, string_val, "<error>")
424 #define GEDCOM_IS_STRING(VAL) \
425 GV_IS_TYPE(VAL, GV_CHAR_PTR)
427 /* This returns the struct date_value from a Gedcom_val, if appropriate */
428 /* It gives a gedcom_warning if the cast is not correct */
429 #define GEDCOM_DATE(VAL) \
430 GV_CHECK_CAST(VAL, GV_DATE_VALUE, date_val, def_date_val)
431 #define GEDCOM_IS_DATE(VAL) \
432 GV_IS_TYPE(VAL, GV_DATE_VALUE)
434 /* This returns the struct age_value from a Gedcom_val, if appropriate */
435 /* It gives a gedcom_warning if the cast is not correct */
436 #define GEDCOM_AGE(VAL) \
437 GV_CHECK_CAST(VAL, GV_AGE_VALUE, age_val, def_age_val)
438 #define GEDCOM_IS_AGE(VAL) \
439 GV_IS_TYPE(VAL, GV_AGE_VALUE)
441 /* This returns the (struct xref_value *) from a Gedcom_val, if appropriate */
442 /* It gives a gedcom_warning if the cast is not correct */
443 #define GEDCOM_XREF_PTR(VAL) \
444 GV_CHECK_CAST(VAL, GV_XREF_PTR, xref_val, &def_xref_val)
445 #define GEDCOM_IS_XREF_PTR(VAL) \
446 GV_IS_TYPE(VAL, GV_XREF_PTR)
449 (*Gedcom_msg_handler)
450 (Gedcom_msg_type type, char *msg);
453 (*Gedcom_rec_start_cb)
454 (Gedcom_rec rec, int level, Gedcom_val xref, char *tag,
455 char *raw_value, int tag_value, Gedcom_val parsed_value);
458 (Gedcom_rec rec, Gedcom_ctxt self);
461 (*Gedcom_elt_start_cb)
462 (Gedcom_elt elt, Gedcom_ctxt parent,
463 int level, char *tag, char *raw_value,
464 int tag_value, Gedcom_val parsed_value);
467 (Gedcom_elt elt, Gedcom_ctxt parent, Gedcom_ctxt self,
468 Gedcom_val parsed_value);
472 (Gedcom_elt elt, Gedcom_ctxt parent, int level, char *tag,
473 char *raw_value, int tag_value);
476 int gedcom_parse_file(const char* file_name);
477 int gedcom_new_model();
478 void gedcom_set_debug_level(int level, FILE* trace_output);
479 void gedcom_set_error_handling(Gedcom_err_mech mechanism);
480 void gedcom_set_compat_handling(int enable_compat);
481 void gedcom_set_message_handler(Gedcom_msg_handler func);
482 void gedcom_set_default_callback(Gedcom_def_cb func);
484 void gedcom_subscribe_to_record(Gedcom_rec rec,
485 Gedcom_rec_start_cb cb_start,
486 Gedcom_rec_end_cb cb_end);
487 void gedcom_subscribe_to_element(Gedcom_elt elt,
488 Gedcom_elt_start_cb cb_start,
489 Gedcom_elt_end_cb cb_end);
491 /* Separate value parsing functions */
492 struct date_value gedcom_parse_date(const char* line_value);
493 struct age_value gedcom_parse_age(const char* line_value);
495 /* Handling cross-references */
496 struct xref_value *gedcom_get_by_xref(const char *key);
497 struct xref_value *gedcom_add_xref(Xref_type type, const char* xrefstr,
499 struct xref_value *gedcom_link_xref(Xref_type type, const char* xrefstr);
500 struct xref_value *gedcom_unlink_xref(Xref_type type, const char* xrefstr);
501 int gedcom_delete_xref(const char* xrefstr);
504 int gedcom_error(const char* s, ...);
505 int gedcom_warning(const char* s, ...);
506 int gedcom_message(const char* s, ...);
507 int gedcom_debug_print(const char* s, ...);
513 #endif /* __GEDCOM_H */