}
Gedcom_ctxt familia_gedcom_header_source_start(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
int level,
char* tag,
char* raw_value,
{
char *source = GEDCOM_STRING(parsed_value);
printf("This file was created by %s\n", source);
- return parent;
+ return ctxt;
}
/*
void familia_gedcom_header_source_end(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
Gedcom_ctxt self,
Gedcom_val parsed_value)
{
*/
Gedcom_ctxt familia_gedcom_header_version_start(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
int level,
char* tag,
char* raw_value,
{
char *source = GEDCOM_STRING(parsed_value);
printf("Program version: %s (l: %d, tag: %s, raw:%s) \n", source, level, tag, raw_value);
- return parent;
+ return ctxt;
}
/*
void familia_gedcom_header_version_end(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
Gedcom_ctxt self,
Gedcom_val parsed_value)
{
}
*/
Gedcom_ctxt familia_gedcom_individual_set_first_name(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
int level,
char* tag,
char* raw_value,
int parsed_tag,
Gedcom_val parsed_value)
{
- familia_individual_set_first_name(parent, GEDCOM_STRING(parsed_value));
- return parent;
+ familia_individual_set_first_name(ctxt, GEDCOM_STRING(parsed_value));
+ return ctxt;
}
/*
void familia_gedcom_individual_first_name_end(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
Gedcom_ctxt self,
Gedcom_val parsed_value)
{
}
*/
Gedcom_ctxt familia_gedcom_individual_last_name_start(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
int level,
char* tag,
char* raw_value,
Gedcom_val parsed_value)
{
if (GEDCOM_IS_STRING(parsed_value)) {
- familia_individual_set_last_name(parent, GEDCOM_STRING(parsed_value));
+ familia_individual_set_last_name(ctxt, GEDCOM_STRING(parsed_value));
}
- return parent;
+ return ctxt;
}
/*
void familia_gedcom_individual_last_name_end(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
Gedcom_ctxt self,
Gedcom_val parsed_value)
{
*/
Gedcom_ctxt familia_gedcom_individual_add_family(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
int level,
char* tag,
char* raw_value,
int parsed_tag,
Gedcom_val parsed_value)
{
- void * object = NULL;
+ void * family = NULL;
struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
- object = familia_memory_stack_find(xr->string, FS_FAMILY);
- familia_individual_add_family(parent, object);
+ family = familia_memory_stack_find(xr->string, FS_FAMILY);
+ familia_individual_add_family(ctxt, family);
- return parent;
+ return ctxt;
+}
+
+/**
+ * Set parents for child
+ */
+Gedcom_ctxt familia_gedcom_individual_set_parents(Gedcom_elt elt,
+ Gedcom_ctxt ctxt,
+ int level,
+ char* tag,
+ char* raw_value,
+ int parsed_tag,
+ Gedcom_val parsed_value)
+{
+ void * child = NULL;
+ /* XREF_PTR(FAM) */
+ struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
+
+ child = familia_memory_stack_find(xr->string, FS_INDIVIDUAL);
+ familia_individual_set_parents(child, ctxt);
+
+ return ctxt;
}
/**
* Adds child to the family
*/
Gedcom_ctxt familia_gedcom_family_add_child(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
int level,
char* tag,
char* raw_value,
int parsed_tag,
Gedcom_val parsed_value)
{
- void * object = NULL;
+ void * family = NULL;
/* XREF_PTR(FAM) */
struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
- object = familia_memory_stack_find(xr->string, FS_FAMILY);
- /* parent: REC_INDI */
- familia_family_add_child(object, parent);
+ family = familia_memory_stack_find(xr->string, FS_FAMILY);
+ familia_family_add_child(family, ctxt);
+
+ return ctxt;
+}
+
+/**
+ * Adds first parent to the family
+ * Parent is the first individual in family. It can be e.g. Husband
+ */
+Gedcom_ctxt familia_gedcom_family_set_parent1(Gedcom_elt elt,
+ Gedcom_ctxt ctxt,
+ int level,
+ char* tag,
+ char* raw_value,
+ int parsed_tag,
+ Gedcom_val parsed_value)
+{
+ void * parent = NULL;
+ /* XREF_PTR(INDI) */
+ struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
+
+ parent = familia_memory_stack_find(xr->string, FS_FAMILY);
+ /* ctxt: REC_FAM */
+ familia_family_set_parent(ctxt, parent, Individual1);
+
+ return ctxt;
+}
+
+/**
+ * Adds second parent to the family
+ * Parent is the first individual in family. It can be e.g. Wife
+ */
+Gedcom_ctxt familia_gedcom_family_set_parent2(Gedcom_elt elt,
+ Gedcom_ctxt ctxt,
+ int level,
+ char* tag,
+ char* raw_value,
+ int parsed_tag,
+ Gedcom_val parsed_value)
+{
+ void * parent = NULL;
+ /* XREF_PTR(INDI) */
+ struct xref_value *xr = GEDCOM_XREF_PTR(parsed_value);
+
+ parent = familia_memory_stack_find(xr->string, FS_FAMILY);
+ /* ctxt: REC_FAM */
+ familia_family_set_parent(ctxt, parent, Individual2);
- return parent;
+ return ctxt;
}
/*
void familia_gedcom_individual_family_end(Gedcom_elt elt,
- Gedcom_ctxt parent,
+ Gedcom_ctxt ctxt,
Gedcom_ctxt self,
Gedcom_val parsed_value)
{
{
gedcom_set_message_handler(familia_gedcom_error);
- gedcom_subscribe_to_record(REC_HEAD,
- familia_gedcom_header_start,
- familia_gedcom_header_end);
- gedcom_subscribe_to_element(ELT_HEAD_SOUR,
- familia_gedcom_header_source_start,
- NULL);
- gedcom_subscribe_to_element(ELT_HEAD_SOUR_VERS,
- familia_gedcom_header_version_start,
- NULL);
- gedcom_subscribe_to_record(REC_FAM,
- familia_gedcom_family_start,
- NULL);
- gedcom_subscribe_to_record(REC_INDI,
- familia_gedcom_individual_start,
- NULL);
- gedcom_subscribe_to_element(ELT_SUB_PERS_NAME,
- familia_gedcom_individual_set_first_name,
- NULL);
- gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_SURN,
- familia_gedcom_individual_last_name_start,
- NULL);
- gedcom_subscribe_to_element(ELT_SUB_FAMS,
- familia_gedcom_family_add_child,
- NULL);
- gedcom_subscribe_to_element(ELT_SUB_FAMC,
- familia_gedcom_family_add_child,
- NULL);
+ gedcom_subscribe_to_record(REC_HEAD, familia_gedcom_header_start, familia_gedcom_header_end);
+ /* Create and set family as current (set to ctxt) */
+ gedcom_subscribe_to_record(REC_FAM, familia_gedcom_family_start, NULL);
+ /* Create and set individual as current (set to ctxt) */
+ gedcom_subscribe_to_record(REC_INDI, familia_gedcom_individual_start, NULL);
+ gedcom_subscribe_to_element(ELT_HEAD_SOUR, familia_gedcom_header_source_start, NULL);
+ gedcom_subscribe_to_element(ELT_HEAD_SOUR_VERS, familia_gedcom_header_version_start, NULL);
+ /* Set in current individual first name */
+ gedcom_subscribe_to_element(ELT_SUB_PERS_NAME, familia_gedcom_individual_set_first_name, NULL);
+ /* Set in current individual last name */
+ gedcom_subscribe_to_element(ELT_SUB_PERS_NAME_SURN, familia_gedcom_individual_last_name_start, NULL);
+ /* Add to current individual new family */
+ gedcom_subscribe_to_element(ELT_SUB_FAMS, familia_gedcom_individual_add_family, NULL);
+ /* Set current family as parents to child */
+ gedcom_subscribe_to_element(ELT_FAM_CHIL, familia_gedcom_individual_set_parents, NULL);
+ /* Set current individual new parents */
+ gedcom_subscribe_to_element(ELT_SUB_FAMC, familia_gedcom_family_add_child, NULL);
+ /* Set in current family first parent (e.g. husband) */
+ gedcom_subscribe_to_element(ELT_FAM_HUSB, familia_gedcom_family_set_parent1, NULL);
+ /* Set in current family second parent (e.g. wife) */
+ gedcom_subscribe_to_element(ELT_FAM_WIFE, familia_gedcom_family_set_parent2, NULL);
familia_memory_stack_init();
}
assert(memory_stack == NULL);
memory_stack = (struct familia_memory_stack*)malloc(sizeof(struct familia_memory_stack));
+ memory_stack->objects = NULL;
+ memory_stack->objects_no = 0;
assert(storage != NULL);
}
free(family);
}
-void familia_family_set_individual(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index)
+void familia_family_set_parent(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index)
{
switch (index) {
case Individual1:
}
}
-struct familia_individual * familia_family_get_individual(struct familia_family * family, enum FFamilyIndividualIndex index)
+struct familia_individual * familia_family_get_parent(struct familia_family * family, enum FFamilyIndividualIndex index)
{
struct familia_individual * individual = NULL;
switch (index) {
case Individual1:
individual = family->individual1;
+ break;
case Individual2:
individual = family->individual2;
+ break;
}
return individual;
}
-struct familia_individual * familia_family_remove_individual(struct familia_family * family, enum FFamilyIndividualIndex index)
+struct familia_individual * familia_family_remove_parent(struct familia_family * family, enum FFamilyIndividualIndex index)
{
struct familia_individual * individual = NULL;
family->children = tmp;
family->children[family->children_no] = individual;
family->children_no++;
- familia_individual_set_parents(individual, family);
+/* familia_individual_set_parents(individual, family);*/
}
else {
debug("There were problems with allocating memory for family children.\n");
* @parameter family to set the individual
* @parameter individual which will be set
*/
-void familia_family_set_individual(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index);
+void familia_family_set_parent(struct familia_family * family, struct familia_individual * individual, enum FFamilyIndividualIndex index);
/**
* Gets individual from the given family
* @parameter family to get the individual
* @parameter individual index of which individual get
*/
-struct familia_individual * familia_family_get_individual(struct familia_family * family, enum FFamilyIndividualIndex index);
+struct familia_individual * familia_family_get_parent(struct familia_family * family, enum FFamilyIndividualIndex index);
/**
* Removes individual from the given family
* @parameter individual index of which individual to remove
* @return returns removed individual, NULL if such does not exist.
*/
-struct familia_individual * familia_family_remove_individual(struct familia_family * family, enum FFamilyIndividualIndex index);
+struct familia_individual * familia_family_remove_parent(struct familia_family * family, enum FFamilyIndividualIndex index);
/**
* Adds new child in the given family
individual->last_name = NULL;
individual->families = NULL;
individual->families_no = 0;
+ individual->parents = NULL;
return individual;
}
individual->families_no = 0;
}
+ if (individual->parents) {
+ individual->parents = NULL;
+ }
+
free(individual);
}
char * familia_individual_get_first_name(struct familia_individual * individual)
{
- if (!individual) {
- return NULL;
- }
-
return individual->first_name;
}
storage->families = NULL;
storage->families_no = 0;
- _familia_storage_positions_init();
+/* _familia_storage_positions_init();*/
return storage;
}
storage->families_no = 0;
}
- _familia_storage_positions_free();
+/* _familia_storage_positions_free();*/
}
void familia_storage_add_individual(struct familia_storage * storage, struct familia_individual * individual)
tmp = realloc(storage->individuals, size * sizeof(struct familia_individual *));
if (tmp) {
+ individual->id = storage->individuals_no;
storage->individuals = tmp;
storage->individuals[storage->individuals_no] = individual;
storage->individuals_no++;
tmp = realloc(storage->families, size * sizeof(struct familia_family *));
if (tmp) {
+ family->id = storage->families_no;
storage->families = tmp;
storage->families[storage->families_no] = family;
storage->families_no++;
void familia_storage_dump_all()
{
- int i;
+ unsigned int i;
struct familia_storage * storage = NULL;
struct familia_family * family = NULL;
struct familia_individual * individual = NULL;
+ struct familia_individual * i1 = NULL;
+ struct familia_individual * i2 = NULL;
storage = familia_storage_get_current();
for (i = 0; i < storage->individuals_no; i++) {
+ struct familia_family * f = NULL;
+
individual = storage->individuals[i];
+
printf("Individual (%d)\n", individual->id);
printf("\t First name: %s\n", individual->first_name);
printf("\t Last name: %s\n", individual->last_name);
+
if (individual->families_no > 0) {
- int j;
- struct familia_family * f = NULL;
- struct familia_individual * i1 = NULL;
- struct familia_individual * i2 = NULL;
+ unsigned int j;
printf("\t Families:\n");
for (j = 0; j < individual->families_no; j++) {
f = individual->families[j];
- i1 = familia_family_get_individual(f, Individual1);
- i2 = familia_family_get_individual(f, Individual2);
+ i1 = familia_family_get_parent(f, Individual1);
+ i2 = familia_family_get_parent(f, Individual2);
- printf("\t > %s&%s\n", familia_individual_get_first_name(i1), familia_individual_get_first_name(i2));
+ printf("\t > %s&%s\n",
+ i1 ? familia_individual_get_first_name(i1) : "NULL",
+ i2 ? familia_individual_get_first_name(i2) : "NULL");
}
- printf("\t Parents:\n");
- f = familia_individual_get_parents(individual);
- i1 = familia_family_get_individual(f, Individual1);
- i2 = familia_family_get_individual(f, Individual2);
-
- printf("\t > %s&%s\n", familia_individual_get_first_name(i1), familia_individual_get_first_name(i2));
+ }
+
+ printf("\t Parents:\n");
+ f = NULL;
+ f = familia_individual_get_parents(individual);
+
+ if (f) {
+ i1 = familia_family_get_parent(f, Individual1);
+ i2 = familia_family_get_parent(f, Individual2);
+
+ printf("\t > %s&%s\n",
+ i1 ? familia_individual_get_first_name(i1) : "NULL",
+ i2 ? familia_individual_get_first_name(i2) : "NULL");
+ }
+ else {
+ printf("\t (none)\n");
}
}
for (i = 0; i < storage->families_no; i++) {
- int j;
- struct familia_individual * i1 = NULL;
- struct familia_individual * i2 = NULL;
+ unsigned int j;
family = storage->families[i];
printf("Family (%d)\n", family->id);
- i1 = familia_family_get_individual(family, Individual1);
- i2 = familia_family_get_individual(family, Individual2);
- printf("\t First parent: %s\n", familia_individual_get_first_name(i1));
- printf("\t Second parent: %s\n", familia_individual_get_first_name(i2));
+ i1 = familia_family_get_parent(family, Individual1);
+ printf("\t First parent: %s\n", i1 ? familia_individual_get_first_name(i1) : "NULL");
+
+ i2 = familia_family_get_parent(family, Individual2);
+ printf("\t Second parent: %s\n", i2 ? familia_individual_get_first_name(i2) : "NULL");
printf("\t Children:\n");
if (family->children_no > 0) {
for (j = 0; j < family->children_no; j++) {
i1 = family->children[j];
- printf("\t > %s\n", familia_individual_get_first_name(i1));
+ printf("\t > %s\n", i1 ? familia_individual_get_first_name(i1) : "NULL");
}
}
}