#include <errno.h>
#include <limits.h>
#include "gedcom_internal.h"
+#include "buffer.h"
#include "age.h"
struct age_value age_s;
struct age_value def_age_val;
+void cleanup_age_buffer();
+struct safe_buffer age_buffer = { NULL, 0, NULL, 0, cleanup_age_buffer };
+
+void cleanup_age_buffer()
+{
+ cleanup_buffer(&age_buffer);
+}
+
void copy_age(struct age_value *to, struct age_value from)
{
memcpy(to, &from, sizeof(struct age_value));
return age_s;
}
+char* gedcom_age_to_string(struct age_value* val)
+{
+ int num = 0;
+ reset_buffer(&age_buffer);
+
+ switch (val->mod) {
+ case AGE_LESS_THAN:
+ safe_buf_append(&age_buffer, "<"); break;
+ case AGE_GREATER_THAN:
+ safe_buf_append(&age_buffer, ">"); break;
+ default:
+ break;
+ }
+
+ switch (val->type) {
+ case AGE_UNRECOGNIZED:
+ return val->phrase; break;
+ case AGE_CHILD:
+ safe_buf_append(&age_buffer, "CHILD"); break;
+ case AGE_INFANT:
+ safe_buf_append(&age_buffer, "INFANT"); break;
+ case AGE_STILLBORN:
+ safe_buf_append(&age_buffer, "STILLBORN"); break;
+ case AGE_NUMERIC:
+ if (val->years != -1) {
+ num = 1;
+ safe_buf_append(&age_buffer, "%dy", val->years);
+ }
+ if (val->months != -1) {
+ if (num)
+ safe_buf_append(&age_buffer, " ");
+ num = 1;
+ safe_buf_append(&age_buffer, "%dm", val->months);
+ }
+ if (val->days != -1) {
+ if (num)
+ safe_buf_append(&age_buffer, " ");
+ num = 1;
+ safe_buf_append(&age_buffer, "%dd", val->days);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return get_buf_string(&age_buffer);
+}
#include "gedcom_internal.h"
#include "sdncal.h"
+#include "buffer.h"
#include "date.h"
struct date_value dv_s;
const char* curr_line_value;
+void cleanup_date_buffer();
+struct safe_buffer date_buffer = { NULL, 0, NULL, 0, cleanup_date_buffer };
+
+void cleanup_date_buffer()
+{
+ cleanup_buffer(&date_buffer);
+}
+
int max_month[] = { 12, /* CAL_GREGORIAN */
12, /* CAL_JULIAN */
13, /* CAL_HEBREW */
return dv_s;
}
+void add_date(struct date* d)
+{
+ switch (d->cal) {
+ case CAL_GREGORIAN: break;
+ case CAL_JULIAN:
+ safe_buf_append(&date_buffer, "@#DJULIAN@ "); break;
+ case CAL_HEBREW:
+ safe_buf_append(&date_buffer, "@#DHEBREW@ "); break;
+ case CAL_FRENCH_REV:
+ safe_buf_append(&date_buffer, "@#DFRENCH R@ "); break;
+ case CAL_UNKNOWN:
+ safe_buf_append(&date_buffer, "@#DUNKNOWN@ "); break;
+ default:
+ break;
+ }
+ if (d->day_str)
+ safe_buf_append(&date_buffer, "%s ", d->day_str);
+ if (d->month_str)
+ safe_buf_append(&date_buffer, "%s ", d->month_str);
+ safe_buf_append(&date_buffer, "%s", d->year_str);
+}
+
+char* gedcom_date_to_string(struct date_value* val)
+{
+ reset_buffer(&date_buffer);
+
+ switch (val->type) {
+ case DV_NO_MODIFIER:
+ add_date(&val->date1); break;
+ case DV_BEFORE:
+ safe_buf_append(&date_buffer, "BEF ");
+ add_date(&val->date1); break;
+ case DV_AFTER:
+ safe_buf_append(&date_buffer, "AFT ");
+ add_date(&val->date1); break;
+ case DV_BETWEEN:
+ safe_buf_append(&date_buffer, "BET ");
+ add_date(&val->date1);
+ safe_buf_append(&date_buffer, " AND ");
+ add_date(&val->date2); break;
+ case DV_FROM:
+ safe_buf_append(&date_buffer, "FROM ");
+ add_date(&val->date1); break;
+ case DV_TO:
+ safe_buf_append(&date_buffer, "TO ");
+ add_date(&val->date1); break;
+ case DV_FROM_TO:
+ safe_buf_append(&date_buffer, "FROM ");
+ add_date(&val->date1);
+ safe_buf_append(&date_buffer, " TO ");
+ add_date(&val->date2); break;
+ case DV_ABOUT:
+ safe_buf_append(&date_buffer, "ABT ");
+ add_date(&val->date1); break;
+ case DV_CALCULATED:
+ safe_buf_append(&date_buffer, "CAL ");
+ add_date(&val->date1); break;
+ case DV_ESTIMATED:
+ safe_buf_append(&date_buffer, "EST ");
+ add_date(&val->date1); break;
+ case DV_INTERPRETED:
+ safe_buf_append(&date_buffer, "INT ");
+ add_date(&val->date1);
+ safe_buf_append(&date_buffer, " (%s)", val->phrase); break;
+ case DV_PHRASE:
+ safe_buf_append(&date_buffer, "(%s)", val->phrase); break;
+ default:
+ break;
+ }
+
+ return get_buf_string(&date_buffer);
+}
return result;
}
+int gedcom_write_element_date(Gedcom_write_hndl hndl,
+ Gedcom_elt elt, int tag, int parent_rec_or_elt,
+ struct date_value* val)
+{
+ int result = 1;
+ if (check_type(elt, (val ? GV_DATE_VALUE : GV_NULL)))
+ result = _gedcom_write_val(hndl, elt, tag, parent_rec_or_elt, NULL,
+ gedcom_date_to_string(val));
+ return result;
+}
+
+int gedcom_write_element_age(Gedcom_write_hndl hndl,
+ Gedcom_elt elt, int tag, int parent_rec_or_elt,
+ struct age_value* val)
+{
+ int result = 1;
+ if (check_type(elt, (val ? GV_AGE_VALUE : GV_NULL)))
+ result = _gedcom_write_val(hndl, elt, tag, parent_rec_or_elt, NULL,
+ gedcom_age_to_string(val));
+ return result;
+}
+
int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, char* tag,
char* xrefstr, char* value)
{
if (!chan) return 1;
result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN, 0, parent, NULL);
+ if (chan->date)
+ result |= gedcom_write_element_date(hndl, ELT_SUB_CHAN_DATE, 0,
+ ELT_SUB_CHAN, chan->date);
+ if (chan->time)
+ result |= gedcom_write_element_str(hndl, ELT_SUB_CHAN_TIME, 0,
+ ELT_SUB_CHAN_DATE, chan->time);
if (chan->note)
result |= write_note_subs(hndl, ELT_SUB_CHAN, chan->note);
if (chan->extra)
if (obj->type)
result |= gedcom_write_element_str(hndl, ELT_SUB_EVT_TYPE, 0,
obj_elt, obj->type);
+ if (obj->date)
+ result |= gedcom_write_element_date(hndl, ELT_SUB_EVT_DATE, 0,
+ obj_elt, obj->date);
if (obj->place)
result |= write_place(hndl, obj_elt, obj->place);
if (obj->address)
for (i = 0; i < 3 && obj->phone[i]; i++)
result |= gedcom_write_element_str(hndl, ELT_SUB_PHON, 0, obj_elt,
obj->phone[i]);
+ if (obj->age)
+ result |= gedcom_write_element_age(hndl, ELT_SUB_EVT_AGE, 0,
+ obj_elt, obj->age);
if (obj->agency)
result |= gedcom_write_element_str(hndl, ELT_SUB_EVT_AGNC, 0,
obj_elt, obj->agency);
result |= write_multimedia_links(hndl, obj_elt, obj->mm_link);
if (obj->note)
result |= write_note_subs(hndl, obj_elt, obj->note);
+ if (obj->husband_age) {
+ result |= gedcom_write_element_str(hndl, ELT_SUB_FAM_EVT_HUSB, 0,
+ obj_elt, NULL);
+ result |= gedcom_write_element_age(hndl, ELT_SUB_FAM_EVT_AGE, 0,
+ ELT_SUB_FAM_EVT_HUSB,
+ obj->husband_age);
+ }
+ if (obj->wife_age) {
+ result |= gedcom_write_element_str(hndl, ELT_SUB_FAM_EVT_WIFE, 0,
+ obj_elt, NULL);
+ result |= gedcom_write_element_age(hndl, ELT_SUB_FAM_EVT_AGE, 0,
+ ELT_SUB_FAM_EVT_WIFE,
+ obj->wife_age);
+ }
if (obj->family) {
int fam_obj_elt = get_gedcom_fam_elt(obj_elt);
result |= gedcom_write_element_xref(hndl, fam_obj_elt, 0,
result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_DATA, 0,
ELT_HEAD_SOUR,
gom_header.source.data.name);
+ if (gom_header.source.data.date)
+ result |= gedcom_write_element_date(hndl, ELT_HEAD_SOUR_DATA_DATE, 0,
+ ELT_HEAD_SOUR_DATA,
+ gom_header.source.data.date);
if (gom_header.source.data.copyright)
result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_DATA_COPR, 0,
ELT_HEAD_SOUR_DATA,
if (gom_header.destination)
result |= gedcom_write_element_str(hndl, ELT_HEAD_DEST, 0, REC_HEAD,
gom_header.destination);
+ if (gom_header.date)
+ result |= gedcom_write_element_date(hndl, ELT_HEAD_DATE, 0, REC_HEAD,
+ gom_header.date);
+ if (gom_header.time)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_DATE_TIME, 0,
+ ELT_HEAD_DATE, gom_header.time);
if (gom_header.submitter)
result |= gedcom_write_element_xref(hndl, ELT_HEAD_SUBM, 0, REC_HEAD,
gom_header.submitter);
parent, NULL);
if (obj->date_status)
result |= gedcom_write_element_str(hndl, ELT_SUB_LIO_BAPL_STAT, 0,
- parent, obj->date_status);
+ obj_elt, obj->date_status);
+ if (obj->date)
+ result |= gedcom_write_element_date(hndl, ELT_SUB_LIO_BAPL_DATE, 0,
+ obj_elt, obj->date);
if (obj->temple_code)
result |= gedcom_write_element_str(hndl, ELT_SUB_LIO_BAPL_TEMP, 0,
- parent, obj->temple_code);
+ obj_elt, obj->temple_code);
if (obj->place_living_ordinance)
result |= gedcom_write_element_str(hndl, ELT_SUB_LIO_BAPL_PLAC, 0,
- parent, obj->place_living_ordinance);
+ obj_elt, obj->place_living_ordinance);
if (obj->family)
result |= gedcom_write_element_xref(hndl, ELT_SUB_LIO_SLGC_FAMC, 0,
- parent, obj->family);
+ obj_elt, obj->family);
if (obj->citation)
result |= write_citations(hndl, obj_elt, obj->citation);
if (obj->note)
if (obj->date || obj->text)
result |= gedcom_write_element_str(hndl, ELT_SUB_SOUR_DATA, 0,
ELT_SUB_SOUR, NULL);
+ if (obj->date)
+ result |= gedcom_write_element_date(hndl, ELT_SUB_SOUR_DATA_DATE, 0,
+ ELT_SUB_SOUR_DATA, obj->date);
if (obj->text)
result |= write_texts(hndl, ELT_SUB_SOUR_DATA, obj->text);
if (obj->quality)
for (obj = evt; obj; obj = obj->next) {
result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_EVEN, 0,
parent, obj->recorded_events);
+ if (obj->date_period)
+ result |= gedcom_write_element_date(hndl, ELT_SOUR_DATA_EVEN_DATE, 0,
+ ELT_SOUR_DATA_EVEN, obj->date_period);
if (obj->jurisdiction)
result |= gedcom_write_element_str(hndl, ELT_SOUR_DATA_EVEN_PLAC, 0,
ELT_SOUR_DATA_EVEN, obj->jurisdiction);
/* Separate value parsing functions */
struct date_value gedcom_parse_date(const char* line_value);
+char* gedcom_date_to_string(struct date_value* val);
struct age_value gedcom_parse_age(const char* line_value);
+char* gedcom_age_to_string(struct age_value* val);
/* Handling cross-references */
struct xref_value *gedcom_get_by_xref(const char *key);
int parsed_tag, int parent_rec_or_elt,
struct xref_value* val);
+int gedcom_write_element_date(Gedcom_write_hndl hndl,
+ Gedcom_elt elt, int tag, int parent_rec_or_elt,
+ struct date_value* val);
+int gedcom_write_element_age(Gedcom_write_hndl hndl,
+ Gedcom_elt elt, int tag, int parent_rec_or_elt,
+ struct age_value* val);
+
int gedcom_write_user_str(Gedcom_write_hndl hndl, int level, char* tag,
char* xrefstr, char* value);
int gedcom_write_user_xref(Gedcom_write_hndl hndl, int level, char* tag,