1 /* Repository object in the gedcom object model.
2 Copyright (C) 2002 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2002.
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
26 #include "repository.h"
30 #include "change_date.h"
34 #include "gom_internal.h"
36 struct repository* gom_first_repository = NULL;
38 DEFINE_MAKEFUNC(repository, gom_first_repository)
39 DEFINE_DESTROYFUNC(repository, gom_first_repository)
40 DEFINE_ADDFUNC(repository, XREF_REPO)
41 DEFINE_DELETEFUNC(repository)
42 DEFINE_GETXREFFUNC(repository, XREF_REPO)
44 DEFINE_REC_CB(repository, repo_start)
45 DEFINE_STRING_CB(repository, repo_name_start, name)
47 DEFINE_ADDFUNC2(repository, note_sub, note)
48 DEFINE_ADDFUNC2(repository, user_ref_number, ref)
49 DEFINE_ADDFUNC2(repository, user_data, extra)
50 DEFINE_ADDFUNC2_NOLIST(repository, address, address)
51 DEFINE_ADDFUNC2_NOLIST(repository, change_date, change_date)
52 DEFINE_ADDFUNC2_STRN(repository, phone, 3)
53 DEFINE_ADDFUNC2_STR(repository, record_id)
55 void repository_subscribe()
57 gedcom_subscribe_to_record(REC_REPO, repo_start, def_rec_end);
58 gedcom_subscribe_to_element(ELT_REPO_NAME, repo_name_start, def_elt_end);
61 void UNREFALLFUNC(repository)(struct repository *obj)
64 UNREFALLFUNC(address)(obj->address);
65 UNREFALLFUNC(note_sub)(obj->note);
66 UNREFALLFUNC(user_ref_number)(obj->ref);
67 UNREFALLFUNC(change_date)(obj->change_date);
68 UNREFALLFUNC(user_data)(obj->extra);
72 void CLEANFUNC(repository)(struct repository* repo)
75 SAFE_FREE(repo->xrefstr);
76 SAFE_FREE(repo->name);
77 CLEANFUNC(address)(repo->address);
78 SAFE_FREE(repo->phone[0]);
79 SAFE_FREE(repo->phone[1]);
80 SAFE_FREE(repo->phone[2]);
81 DESTROY_CHAIN_ELTS(note_sub, repo->note);
82 DESTROY_CHAIN_ELTS(user_ref_number, repo->ref);
83 SAFE_FREE(repo->record_id);
84 CLEANFUNC(change_date)(repo->change_date);
85 DESTROY_CHAIN_ELTS(user_data, repo->extra);
89 void repositories_cleanup()
91 DESTROY_CHAIN_ELTS(repository, gom_first_repository);
94 struct repository* gom_get_first_repository()
96 return gom_first_repository;
99 int write_repositories(Gedcom_write_hndl hndl)
103 struct repository* obj;
105 for (obj = gom_first_repository; obj; obj = obj->next) {
106 result |= gedcom_write_record_str(hndl, REC_REPO, obj->xrefstr, NULL);
108 result |= gedcom_write_element_str(hndl, ELT_REPO_NAME, 0,
109 REC_REPO, obj->name);
111 result |= write_address(hndl, REC_REPO, obj->address);
112 for (i = 0; i < 3 && obj->phone[i]; i++)
113 result |= gedcom_write_element_str(hndl, ELT_SUB_PHON, 0, REC_REPO,
116 result |= write_note_subs(hndl, REC_REPO, obj->note);
118 result |= write_user_refs(hndl, REC_REPO, obj->ref);
120 result |= gedcom_write_element_str(hndl, ELT_SUB_IDENT_RIN, 0,
121 REC_REPO, obj->record_id);
122 if (obj->change_date)
123 result |= write_change_date(hndl, REC_REPO, obj->change_date);
125 result |= write_user_data(hndl, obj->extra);