3 #include "familia_gedcom.h"
5 #include "../storage/storage.h"
6 #include "../storage/individual.h"
7 #include "../memory_stack.h"
9 Gedcom_ctxt familia_gedcom_header_start (Gedcom_rec rec,
15 Gedcom_val parsed_value)
17 fprintf(stderr, "The header starts (l: %d, tag: %s, raw:%s) \n", level, tag, raw_value);
18 return (Gedcom_ctxt)1;
21 void familia_gedcom_header_end (Gedcom_rec rec, Gedcom_ctxt self)
23 /* context will print as "1" */
24 fprintf(stderr, "The header ends, context is %d\n", (int)self);
27 Gedcom_ctxt familia_gedcom_header_source_start(Gedcom_elt elt,
33 Gedcom_val parsed_value)
35 char *source = GEDCOM_STRING(parsed_value);
36 printf("This file was created by %s\n", source);
41 void familia_gedcom_header_source_end(Gedcom_elt elt,
44 Gedcom_val parsed_value)
46 printf("End of the source description\n");
50 Gedcom_ctxt familia_gedcom_header_version_start(Gedcom_elt elt,
56 Gedcom_val parsed_value)
58 char *source = GEDCOM_STRING(parsed_value);
59 printf("Program version: %s (l: %d, tag: %s, raw:%s) \n", source, level, tag, raw_value);
63 void familia_gedcom_header_version_end(Gedcom_elt elt,
66 Gedcom_val parsed_value)
68 printf("End of the version description\n");
71 Gedcom_ctxt familia_gedcom_family_start (Gedcom_rec rec,
77 Gedcom_val parsed_value)
79 struct familia_family * family = NULL;
80 struct xref_value *xr = GEDCOM_XREF_PTR(xref);
82 family = familia_memory_stack_find(xr->string, FS_FAMILY);
84 return (Gedcom_ctxt)family;
87 void familia_gedcom_family_end (Gedcom_rec rec, Gedcom_ctxt self)
89 familia_storage_add_family(familia_storage_get_current(), self);
92 Gedcom_ctxt familia_gedcom_individual_start (Gedcom_rec rec,
98 Gedcom_val parsed_value)
100 struct familia_individual * individual = NULL;
101 struct xref_value *xr = GEDCOM_XREF_PTR(xref);
103 individual = familia_memory_stack_find(xr->string, FS_INDIVIDUAL);
105 return (Gedcom_ctxt)individual;
108 void familia_gedcom_individual_end (Gedcom_rec rec, Gedcom_ctxt self)
110 familia_storage_add_individual(familia_storage_get_current(), self);
113 Gedcom_ctxt familia_gedcom_individual_set_first_name(Gedcom_elt elt,
119 Gedcom_val parsed_value)
121 familia_individual_set_first_name(ctxt, GEDCOM_STRING(parsed_value));
125 void familia_gedcom_individual_first_name_end(Gedcom_elt elt,
128 Gedcom_val parsed_value)
132 Gedcom_ctxt familia_gedcom_individual_last_name_start(Gedcom_elt elt,
138 Gedcom_val parsed_value)
140 if (GEDCOM_IS_STRING(parsed_value)) {
141 familia_individual_set_last_name(ctxt, GEDCOM_STRING(parsed_value));
146 void familia_gedcom_individual_last_name_end(Gedcom_elt elt,
149 Gedcom_val parsed_value)
154 Gedcom_ctxt familia_gedcom_individual_add_family(Gedcom_elt elt,
160 Gedcom_val parsed_value)
162 void * family = NULL;
163 struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
165 family = familia_memory_stack_find(xr->string, FS_FAMILY);
166 familia_individual_add_family(ctxt, family);
172 * Set parents for child
174 Gedcom_ctxt familia_gedcom_individual_set_parents(Gedcom_elt elt,
180 Gedcom_val parsed_value)
184 struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
186 child = familia_memory_stack_find(xr->string, FS_INDIVIDUAL);
187 familia_individual_set_parents(child, ctxt);
193 * Adds child to the family
195 Gedcom_ctxt familia_gedcom_family_add_child(Gedcom_elt elt,
201 Gedcom_val parsed_value)
203 void * family = NULL;
205 struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
207 family = familia_memory_stack_find(xr->string, FS_FAMILY);
208 familia_family_add_child(family, ctxt);
214 * Adds first parent to the family
215 * Parent is the first individual in family. It can be e.g. Husband
217 Gedcom_ctxt familia_gedcom_family_set_parent1(Gedcom_elt elt,
223 Gedcom_val parsed_value)
225 void * parent = NULL;
227 struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
229 parent = familia_memory_stack_find(xr->string, FS_FAMILY);
231 familia_family_set_parent(ctxt, parent, Individual1);
237 * Adds second parent to the family
238 * Parent is the first individual in family. It can be e.g. Wife
240 Gedcom_ctxt familia_gedcom_family_set_parent2(Gedcom_elt elt,
246 Gedcom_val parsed_value)
248 void * parent = NULL;
250 struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
252 parent = familia_memory_stack_find(xr->string, FS_FAMILY);
254 familia_family_set_parent(ctxt, parent, Individual2);
260 void familia_gedcom_individual_family_end(Gedcom_elt elt,
263 Gedcom_val parsed_value)
267 void familia_gedcom_error (Gedcom_msg_type type, char *msg)
269 fprintf(stderr, "> %s\n", msg);
274 void familia_gedcom_init()
276 gedcom_set_message_handler(familia_gedcom_error);
278 gedcom_subscribe_to_record(REC_HEAD, familia_gedcom_header_start, familia_gedcom_header_end);
279 /* Create and set family as current (set to ctxt) */
280 gedcom_subscribe_to_record(REC_FAM, familia_gedcom_family_start, NULL);
281 /* Create and set individual as current (set to ctxt) */
282 gedcom_subscribe_to_record(REC_INDI, familia_gedcom_individual_start, NULL);
283 gedcom_subscribe_to_element(ELT_HEAD_SOUR, familia_gedcom_header_source_start, NULL);
284 gedcom_subscribe_to_element(ELT_HEAD_SOUR_VERS, familia_gedcom_header_version_start, NULL);
285 /* Set in current individual first name */
286 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME, familia_gedcom_individual_set_first_name, NULL);
287 /* Set in current individual last name */
288 gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_SURN, familia_gedcom_individual_last_name_start, NULL);
289 /* Add to current individual new family */
290 gedcom_subscribe_to_element(ELT_SUB_FAMS, familia_gedcom_individual_add_family, NULL);
291 /* Set current family as parents to child */
292 gedcom_subscribe_to_element(ELT_FAM_CHIL, familia_gedcom_individual_set_parents, NULL);
293 /* Set current individual new parents */
294 gedcom_subscribe_to_element(ELT_SUB_FAMC, familia_gedcom_family_add_child, NULL);
295 /* Set in current family first parent (e.g. husband) */
296 gedcom_subscribe_to_element(ELT_FAM_HUSB, familia_gedcom_family_set_parent1, NULL);
297 /* Set in current family second parent (e.g. wife) */
298 gedcom_subscribe_to_element(ELT_FAM_WIFE, familia_gedcom_family_set_parent2, NULL);
300 familia_memory_stack_init();
303 void familia_gedcom_dump_val(Gedcom_val val)
305 if (GEDCOM_IS_NULL(val)) {
306 fprintf(stderr, "| %25s |\n", "NULL");
308 else if (GEDCOM_IS_STRING(val)) {
309 fprintf(stderr, "| %4s | %20s |\n", "STRING", GEDCOM_STRING(val));
311 else if (GEDCOM_IS_DATE(val)) {
312 fprintf(stderr, "| %4s | %20s |\n", "DATE", "(@todo)");
314 else if (GEDCOM_IS_AGE(val)) {
315 fprintf(stderr, "| %4s | %20s |\n", "AGE", "(@todo)");
317 else if (GEDCOM_IS_XREF_PTR(val)) {
318 struct xref_value *xref = NULL;
319 fprintf(stderr, "| %25s | %15s | %4s |\n", "STRING", "OBJECT", "TYPE");
320 xref = GEDCOM_XREF_PTR(val);
321 fprintf(stderr, "| %25s | %15s | %4s |\n",
323 xref->object ? "initialized" : "NULL",
324 (xref->type == XREF_NONE) ? "NONE" :
325 (xref->type == XREF_FAM ) ? "FAM" :
326 (xref->type == XREF_INDI) ? "INDI" :
327 (xref->type == XREF_NOTE) ? "NOTE" :
328 (xref->type == XREF_OBJE) ? "OBJE" :
329 (xref->type == XREF_REPO) ? "REPO" :
330 (xref->type == XREF_SOUR) ? "SOUR" :
331 (xref->type == XREF_SUBM) ? "SUBM" :
332 (xref->type == XREF_SUBN) ? "SUBN" :
333 (xref->type == XREF_ANY ) ? "ANY" :
334 (xref->type == XREF_USER) ? "USER" : "???");
337 fprintf(stderr, "| %20s |\n", "???");