1 /* Change date sub-structure 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
27 #include "change_date.h"
29 #include "individual.h"
31 #include "multimedia.h"
33 #include "repository.h"
35 #include "submitter.h"
37 #include "gom_internal.h"
41 Gedcom_ctxt sub_chan_start(_ELT_PARAMS_)
43 Gom_ctxt ctxt = (Gom_ctxt)parent;
44 Gom_ctxt result = NULL;
49 struct change_date *chan = SUB_MAKEFUNC(change_date)();
51 int type = ctxt_type(ctxt);
54 ADDFUNC2_NOLIST(family,change_date)(ctxt, chan); break;
56 ADDFUNC2_NOLIST(individual,change_date)(ctxt, chan); break;
58 ADDFUNC2_NOLIST(multimedia,change_date)(ctxt, chan); break;
60 ADDFUNC2_NOLIST(note,change_date)(ctxt, chan); break;
62 ADDFUNC2_NOLIST(repository,change_date)(ctxt, chan); break;
64 ADDFUNC2_NOLIST(source,change_date)(ctxt, chan); break;
66 ADDFUNC2_NOLIST(submitter,change_date)(ctxt, chan); break;
68 UNEXPECTED_CONTEXT(type);
70 result = MAKE_GOM_CTXT(elt, change_date, chan);
74 return (Gedcom_ctxt)result;
77 DEFINE_SUB_MAKEFUNC(change_date)
78 DEFINE_SUB_SETFUNC(change_date)
79 DEFINE_SUB_DELETEFUNC(change_date)
81 DEFINE_DATE_CB(change_date, sub_chan_date_start, date)
82 DEFINE_STRING_CB(change_date, sub_chan_time_start, time)
84 DEFINE_ADDFUNC2(change_date, note_sub, note)
85 DEFINE_ADDFUNC2(change_date, user_data, extra)
87 void change_date_subscribe()
89 gedcom_subscribe_to_element(ELT_SUB_CHAN, sub_chan_start, def_elt_end);
90 gedcom_subscribe_to_element(ELT_SUB_CHAN_DATE, sub_chan_date_start,
92 gedcom_subscribe_to_element(ELT_SUB_CHAN_TIME, sub_chan_time_start,
96 void UNREFALLFUNC(change_date)(struct change_date* obj)
99 UNREFALLFUNC(note_sub)(obj->note);
100 UNREFALLFUNC(user_data)(obj->extra);
104 void CLEANFUNC(change_date)(struct change_date *chan)
107 SAFE_FREE(chan->date);
108 SAFE_FREE(chan->time);
109 DESTROY_CHAIN_ELTS(note_sub, chan->note);
110 DESTROY_CHAIN_ELTS(user_data, chan->extra);
115 int update_date(struct date_value** dv, struct tm* tm_ptr)
118 struct date_value* dval = gedcom_new_date_value(NULL);
119 dval->type = DV_NO_MODIFIER;
120 dval->date1.cal = CAL_GREGORIAN;
121 dval->date1.day = tm_ptr->tm_mday;
122 dval->date1.month = tm_ptr->tm_mon + 1;
123 dval->date1.year = tm_ptr->tm_year + 1900;
124 result = gedcom_normalize_date(DI_FROM_NUMBERS, dval);
133 int update_time(char** tv, struct tm* tm_ptr)
136 sprintf(tval, "%02d:%02d:%02d",
137 tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec);
139 if (gom_set_string(tv, tval))
145 int gom_update_timestamp(struct change_date** chan, time_t t)
149 if (! *chan) gom_set_new_change_date(chan);
151 struct tm *tm_ptr = localtime(&t);
153 result |= update_date(&((*chan)->date), tm_ptr);
154 result |= update_time(&((*chan)->time), tm_ptr);
160 int write_change_date(Gedcom_write_hndl hndl, int parent,
161 struct change_date *chan)
167 result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN, 0, parent, NULL);
169 result |= gedcom_write_element_date(hndl, ELT_SUB_CHAN_DATE, 0,
170 ELT_SUB_CHAN, chan->date);
172 result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN_TIME, 0,
173 ELT_SUB_CHAN_DATE, chan->time);
175 result |= write_note_subs(hndl, ELT_SUB_CHAN, chan->note);
177 result |= write_user_data(hndl, chan->extra);