From 23eeb22223e34cfae61897bc1b15f45c41cc6df5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Wed, 15 Jan 2014 00:10:13 +0100 Subject: [PATCH] Added debugging code for dumping data from memory using GUI. --- data/gui.glade | 45 +++++++++++++++++++++++++++ src/gedcom/familia_gedcom.c | 28 ++++++++++++++++- src/math/positions.c | 24 --------------- src/math/positions.h | 2 +- src/storage/individual.c | 4 +++ src/storage/storage.c | 61 +++++++++++++++++++++++++++++++++++++ src/storage/storage.h | 2 ++ 7 files changed, 140 insertions(+), 26 deletions(-) diff --git a/data/gui.glade b/data/gui.glade index 0cd0c54..1c512ed 100644 --- a/data/gui.glade +++ b/data/gui.glade @@ -86,6 +86,17 @@ + + True + False + gtk-missing-image + 1 + + + True + False + gtk-missing-image + False center @@ -255,6 +266,40 @@ + + + True + False + True + Debug + + + True + False + + + imagemenuitem + True + False + image2 + False + + + + + + imagemenuitem + True + False + image1 + False + + + + + + + False diff --git a/src/gedcom/familia_gedcom.c b/src/gedcom/familia_gedcom.c index 740d6b2..dcb8032 100644 --- a/src/gedcom/familia_gedcom.c +++ b/src/gedcom/familia_gedcom.c @@ -167,6 +167,29 @@ Gedcom_ctxt familia_gedcom_individual_add_family(Gedcom_elt elt, return parent; } + +/** + * Adds child to the family + */ +Gedcom_ctxt familia_gedcom_family_add_child(Gedcom_elt elt, + Gedcom_ctxt parent, + int level, + char* tag, + char* raw_value, + int parsed_tag, + Gedcom_val parsed_value) +{ + void * object = 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); + + return parent; +} + /* void familia_gedcom_individual_family_end(Gedcom_elt elt, Gedcom_ctxt parent, @@ -208,7 +231,10 @@ void familia_gedcom_init() familia_gedcom_individual_last_name_start, NULL); gedcom_subscribe_to_element(ELT_SUB_FAMS, - familia_gedcom_individual_add_family, + familia_gedcom_family_add_child, + NULL); + gedcom_subscribe_to_element(ELT_SUB_FAMC, + familia_gedcom_family_add_child, NULL); familia_memory_stack_init(); diff --git a/src/math/positions.c b/src/math/positions.c index 4fd47bf..dfd8fc0 100644 --- a/src/math/positions.c +++ b/src/math/positions.c @@ -1,25 +1,3 @@ -/**************************************************************************** - * Familia Lignum - Genealogical program * - * Copyright (C) 2011-2012 Rafał Długołęcki * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; version 2 of the License. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * * - ****************************************************************************/ - -#ifndef _FAMILIA_MATH_POSITIONS_H -#define _FAMILIA_MATH_POSITIONS_H - #include #include "positions.h" @@ -37,5 +15,3 @@ struct position * familia_position_calculate_family_position(struct familia_fami /* TODO: Implement this function*/ return NULL; } - -#endif /* _FAMILIA_MATH_3D_H */ diff --git a/src/math/positions.h b/src/math/positions.h index 6db7f3d..058cfc5 100644 --- a/src/math/positions.h +++ b/src/math/positions.h @@ -39,4 +39,4 @@ struct position * familia_position_calculate_individual_position(struct familia_ */ struct position * familia_position_calculate_family_position(struct familia_family * family); -#endif /* _FAMILIA_MATH_3D_H */ +#endif /* _FAMILIA_MATH_POSITIONS_H */ diff --git a/src/storage/individual.c b/src/storage/individual.c index 5e55bb6..856796d 100644 --- a/src/storage/individual.c +++ b/src/storage/individual.c @@ -74,6 +74,10 @@ void familia_individual_set_first_name(struct familia_individual * individual, c char * familia_individual_get_first_name(struct familia_individual * individual) { + if (!individual) { + return NULL; + } + return individual->first_name; } diff --git a/src/storage/storage.c b/src/storage/storage.c index 272e6af..8b00a71 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -1,3 +1,4 @@ +#include #include #include "storage.h" @@ -198,3 +199,63 @@ void familia_storage_remove_family_by_id(struct familia_storage * storage, unsig } } +void familia_storage_dump_all() +{ + int i; + struct familia_storage * storage = NULL; + struct familia_family * family = NULL; + struct familia_individual * individual = NULL; + + storage = familia_storage_get_current(); + + for (i = 0; i < storage->individuals_no; i++) { + 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; + + 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); + + printf("\t > %s&%s\n", familia_individual_get_first_name(i1), familia_individual_get_first_name(i2)); + } + 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)); + } + } + + + for (i = 0; i < storage->families_no; i++) { + int j; + struct familia_individual * i1 = NULL; + struct familia_individual * i2 = NULL; + + 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)); + + 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)); + } + } + } +} diff --git a/src/storage/storage.h b/src/storage/storage.h index 49991fa..8800399 100644 --- a/src/storage/storage.h +++ b/src/storage/storage.h @@ -129,4 +129,6 @@ struct familia_family * familia_storage_get_family_by_id(struct familia_storage */ void familia_storage_remove_family_by_id(struct familia_storage * storage, unsigned int id); +void familia_storage_dump_all(); + #endif /*_FAMILIA_STORAGE_H */ -- 2.30.2