fi
])
])
+
+dnl gedcom_SYS_NEWLINE()
+dnl Checks how newline is written on the system
+dnl SYS_NEWLINE is set to one of the following:
+dnl END_CR, END_LF, END_CR_LF, END_LF_CR
+AC_DEFUN(gedcom_SYS_NEWLINE, [
+ AC_CACHE_CHECK(how to represent newline, ac_cv_system_newline, [
+ echo > newlinetest
+ AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+int main() {
+ char buffer[11];
+ int i, fd;
+ FILE* f;
+ for (i=0; i<10; i++) { buffer[i] = '\0'; }
+ fd = open("newlinetest", O_RDONLY);
+ if (fd == -1) return 1;
+ read(fd, buffer, 10);
+ close(fd);
+ f = fopen("newlinetest", "w");
+ if (!f) return 1;
+ i = 0;
+ while (buffer[i] != '\0') { fprintf(f, "%02x", buffer[i++]); }
+ fclose(f);
+ return 0;
+}
+ ],
+ [system_newline_output=`cat newlinetest`
+ case "$system_newline_output" in
+ 0a0d) ac_cv_system_newline="\"\x0A\x0D\"" ;;
+ 0d0a) ac_cv_system_newline="\"\x0D\x0A\"" ;;
+ 0a) ac_cv_system_newline="\"\x0A\"" ;;
+ 0d) ac_cv_system_newline="\"\x0D\"" ;;
+ *) ac_cv_system_newline="\"\x0A\"" ;;
+ esac],
+ ac_cv_system_newline="\"\x0A\"",
+ ac_cv_system_newline="\"\x0A\"")
+ rm -f newlinetest
+ ])
+ AC_DEFINE_UNQUOTED(SYS_NEWLINE,$ac_cv_system_newline,
+ [The representation of newline in text files in the system])
+])
dnl ==========================================================
dnl My local stuff
+gedcom_SYS_NEWLINE
AM_ICONV
gedcom_SANE_ICONV
if test "$am_cv_func_iconv" != yes -o "$is_iconv_sane" != yes; then
return gedcom_new_model();
}
+int gom_write_file(const char* file_name, int *total_conv_fails)
+{
+ Gedcom_write_hndl hndl;
+ int result = 1;
+
+ hndl = gedcom_write_open(file_name);
+ if (hndl) {
+ result = write_header(hndl);
+ result |= gedcom_write_close(hndl, total_conv_fails);
+ }
+
+ return result;
+}
+
Gom_ctxt make_gom_ctxt(int ctxt_type, OBJ_TYPE obj_type, void *ctxt_ptr)
{
Gom_ctxt ctxt = (Gom_ctxt)malloc(sizeof(struct Gom_ctxt_struct));
{
return &gom_header;
}
+
+int write_header(Gedcom_write_hndl hndl)
+{
+ int result = 0;
+
+ result |= gedcom_write_record_str(hndl, REC_HEAD, NULL, NULL, NULL);
+ if (gom_header.source.id)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR, NULL, REC_HEAD,
+ gom_header.source.id);
+ if (gom_header.source.name)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_NAME, NULL,
+ ELT_HEAD_SOUR,
+ gom_header.source.name);
+ if (gom_header.source.version)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_VERS, NULL,
+ ELT_HEAD_SOUR,
+ gom_header.source.version);
+ if (gom_header.source.corporation.name)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_CORP, NULL,
+ ELT_HEAD_SOUR,
+ gom_header.source.corporation.name);
+ if (gom_header.source.data.name)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_DATA, NULL,
+ ELT_HEAD_SOUR,
+ gom_header.source.data.name);
+ if (gom_header.source.data.copyright)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_SOUR_DATA_COPR, NULL,
+ ELT_HEAD_SOUR_DATA,
+ gom_header.source.data.copyright);
+ if (gom_header.destination)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_DEST, NULL, REC_HEAD,
+ gom_header.destination);
+ if (gom_header.filename)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_FILE, NULL, REC_HEAD,
+ gom_header.filename);
+ if (gom_header.copyright)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_COPR, NULL, REC_HEAD,
+ gom_header.copyright);
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_GEDC, NULL, REC_HEAD,
+ NULL);
+ if (gom_header.gedcom.version)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_GEDC_VERS, NULL,
+ ELT_HEAD_GEDC,
+ gom_header.gedcom.version);
+ if (gom_header.gedcom.form)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_GEDC_FORM, NULL,
+ ELT_HEAD_GEDC,
+ gom_header.gedcom.form);
+ if (gom_header.charset.name)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_CHAR, NULL,
+ REC_HEAD,
+ gom_header.charset.name);
+ if (gom_header.charset.version)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_CHAR_VERS, NULL,
+ ELT_HEAD_CHAR,
+ gom_header.charset.version);
+ if (gom_header.language)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_LANG, NULL,
+ REC_HEAD,
+ gom_header.language);
+ if (gom_header.place_hierarchy) {
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_PLAC, NULL, REC_HEAD,
+ NULL);
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_PLAC_FORM, NULL,
+ ELT_HEAD_PLAC,
+ gom_header.place_hierarchy);
+ }
+ if (gom_header.note)
+ result |= gedcom_write_element_str(hndl, ELT_HEAD_NOTE, NULL,
+ REC_HEAD,
+ gom_header.note);
+ return result;
+}
void header_add_phone (Gom_ctxt header, const char* phone);
void header_add_to_note(NL_TYPE type, Gom_ctxt header, const char* str);
void header_add_user_data(Gom_ctxt ctxt, struct user_data* data);
+int write_header(Gedcom_write_hndl hndl);
#endif /* __HEADER_H */
} Gedcom_rec;
typedef enum _ELT {
- ELT_HEAD_SOUR = NR_OF_RECS + 1,
+ ELT_HEAD_SOUR = NR_OF_RECS,
ELT_HEAD_SOUR_VERS,
ELT_HEAD_SOUR_NAME,
ELT_HEAD_SOUR_CORP,
char phrase[MAX_PHRASE_LEN + 1];
};
+typedef enum _ENC {
+ ONE_BYTE = 0x00,
+ TWO_BYTE_HILO = 0x01,
+ TWO_BYTE_LOHI = 0x02
+} Encoding;
+
+typedef enum _ENC_BOM {
+ WITHOUT_BOM = 0x00,
+ WITH_BOM = 0x10
+} Enc_bom;
+
+typedef enum _ENC_LINE_END {
+ END_CR = 0,
+ END_LF = 1,
+ END_CR_LF = 2,
+ END_LF_CR = 3
+} Enc_line_end;
+
/**************************************************************************/
/*** Things meant to be internal, susceptible to changes ***/
/*** Use the GEDCOM_STRING/GEDCOM_DATE interface instead of relying ***/
/**************************************************************************/
typedef enum _GEDCOM_VAL_TYPE {
- GV_NULL,
- GV_CHAR_PTR,
- GV_DATE_VALUE,
- GV_AGE_VALUE,
- GV_XREF_PTR
+ GV_NULL = 0x01,
+ GV_CHAR_PTR = 0x02,
+ GV_DATE_VALUE = 0x04,
+ GV_AGE_VALUE = 0x08,
+ GV_XREF_PTR = 0x10
} Gedcom_val_type;
union _Gedcom_val_union {
/* Type for parsed values, meant to be opaque */
typedef Gedcom_val_struct* Gedcom_val;
+/* Type for write handle, meant to be opaque */
+struct Gedcom_write_struct;
+typedef struct Gedcom_write_struct* Gedcom_write_hndl;
+
/* Check to determine whether there is a parsed value or not */
#define GEDCOM_IS_NULL(VAL) \
GV_IS_TYPE(VAL, GV_NULL)
struct xref_value *gedcom_unlink_xref(Xref_type type, const char* xrefstr);
int gedcom_delete_xref(const char* xrefstr);
+/* Writing support */
+Gedcom_write_hndl gedcom_write_open(const char* filename);
+int gedcom_write_close(Gedcom_write_hndl hndl, int *total_conv_fails);
+int gedcom_write_set_encoding(const char* charset, Encoding width,
+ Enc_bom bom);
+int gedcom_write_set_line_terminator(Enc_line_end end);
+int gedcom_write_record_str(Gedcom_write_hndl hndl,
+ Gedcom_rec rec, char* tag,
+ struct xref_value* xref, char* val);
+int gedcom_write_element_str(Gedcom_write_hndl hndl,
+ Gedcom_elt elt, char* tag, int parent_rec_or_elt,
+ char* val);
+
/* For use in gom */
int gedcom_error(const char* s, ...);
int gedcom_warning(const char* s, ...);
int gom_parse_file(const char *file_name);
int gom_new_model();
+int gom_write_file(const char* file_name, int *total_conv_fails);
struct header* gom_get_header();
struct submission* gom_get_submission();
gedcom/interface.c
gedcom/xref.c
gedcom/compat.c
+gedcom/write.c
gom/gom.c
gom/gom_modify.c
TESTS_ENVIRONMENT=ICONV_PATH=@ICONV_PATH@
all-local:
- @rm -f *.out
+ @rm -f *.out *.ged
check-% : %.test all
@srcdir=$(srcdir); export srcdir; \
--- /dev/null
+0 HEAD
+1 SOUR GEDCOM_PARSE
+2 VERS 0.17
+1 GEDC
+2 VERS 5.5
+2 FORM LINEAGE-LINKED
+1 CHAR ASCII
+0 TRLR
--- /dev/null
+Test succeeded
--- /dev/null
+0 HEAD
+1 SOUR GEDCOM_PARSE
+2 VERS 0.17
+1 GEDC
+2 VERS 5.5
+2 FORM LINEAGE-LINKED
+1 CHAR ASCII
+0 TRLR
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
--- /dev/null
+Test succeeded
-I $(srcdir)/../../utf8
CFLAGS = -g -O2 @EXTRA_CFLAGS@
-noinst_PROGRAMS = testgedcom pathtest gomtest updatetest testintl updategomtest
+noinst_PROGRAMS = testgedcom pathtest gomtest updatetest testintl updategomtest \
+ writegomtest
noinst_HEADERS = output.h dump_gom.h portability.h
testgedcom_SOURCES = standalone.c output.c portability.c
updategomtest_LDFLAGS = -L../../gedcom/.libs -L../../gom/.libs
updategomtest_LDADD = -lgedcom_gom -lgedcom @INTLLIBS@
+writegomtest_SOURCES = gom_write.c output.c portability.c
+writegomtest_LDFLAGS = -L../../gedcom/.libs -L../../gom/.libs
+writegomtest_LDADD = -lgedcom_gom -lgedcom @INTLLIBS@
+
testintl_SOURCES = testintl.c output.c
testintl_LDFLAGS = -L../../gedcom/.libs
testintl_LDADD = -lgedcom @INTLLIBS@
-TEST_SCRIPT=test_script test_gom test_update test_intl test_updategom
+TEST_SCRIPT=test_script test_gom test_update test_intl test_updategom test_writegom
EXTRA_DIST=$(TEST_SCRIPT)
--- /dev/null
+/* Test program for the Gedcom library.
+ Copyright (C) 2001, 2002 The Genes Development Team
+ This file is part of the Gedcom parser library.
+ Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
+
+ The Gedcom parser library is free software; you can redistribute it
+ and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The Gedcom parser library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the Gedcom parser library; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+/* $Id$ */
+/* $Name$ */
+
+#include "gedcom.h"
+#include "gom.h"
+#include "output.h"
+#include "portability.h"
+#include <locale.h>
+#include <stdio.h>
+
+#define WRITE_GEDCOM "gom_write.ged"
+#define PROG_NAME "writegomtest"
+#define PROG_VERSION "3.14"
+
+void gedcom_message_handler(Gedcom_msg_type type, char *msg)
+{
+ if (type == MESSAGE)
+ output(1, "MESSAGE: ");
+ else if (type == WARNING)
+ output(1, "WARNING: ");
+ else if (type == ERROR)
+ output(1, "ERROR: ");
+ output(1, "%s\n", msg);
+}
+
+void show_help ()
+{
+ printf("gedcom-parse test program for libgedcom\n\n");
+ printf("Usage: writegomtest [options]\n");
+ printf("Options:\n");
+ printf(" -h Show this help text\n");
+ printf(" -q No output to standard output\n");
+ printf(" -o <outfile> File to generate errors to (def. testgedcom.out)\n");
+ printf(" -w <gedfile> File to write gedcom to (def. %s)\n", WRITE_GEDCOM);
+ printf(" -e <encoding> Encoding (UNICODE, ASCII, ANSEL, ...: see gedcom.enc)\n");
+ printf(" -u <unicode_enc> Encoding details for Unicode\n");
+ printf(" <unicode_enc> can be: HILO, LOHI, HILO_BOM, LOHI_BOM\n");
+ printf(" -t <terminator> Line terminator\n");
+ printf(" <terminator> can be CR, LF, CR_LF, LF_CR\n");
+}
+
+int update_charset(char* encoding)
+{
+ struct header* head = NULL;
+ char* value;
+
+ head = gom_get_header();
+ if (head == NULL)
+ return 1;
+ else {
+ value = gom_set_string(&head->charset.name, encoding);
+ if (value == NULL || strcmp(value, encoding))
+ return 1;
+ else
+ return 0;
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ int result;
+ int total_conv_fails = 0;
+ char* outfilename = NULL;
+ char* gedfilename = WRITE_GEDCOM;
+ char* encoding = "ASCII";
+ Encoding enc = ONE_BYTE;
+ Enc_bom bom = WITHOUT_BOM;
+ Enc_line_end end = END_LF;
+
+ if (argc > 1) {
+ int i;
+ for (i=1; i<argc; i++) {
+ if (!strncmp(argv[i], "-h", 3)) {
+ show_help();
+ exit(1);
+ }
+ else if (!strncmp(argv[i], "-q", 3)) {
+ output_set_quiet(1);
+ }
+ else if (!strncmp(argv[i], "-o", 3)) {
+ i++;
+ if (i < argc) {
+ outfilename = argv[i];
+ }
+ else {
+ printf ("Missing output file name\n");
+ show_help();
+ exit(1);
+ }
+ }
+ else if (!strncmp(argv[i], "-w", 3)) {
+ i++;
+ if (i < argc) {
+ gedfilename = argv[i];
+ }
+ else {
+ printf ("Missing output file name\n");
+ show_help();
+ exit(1);
+ }
+ }
+ else if (!strncmp(argv[i], "-e", 3)) {
+ i++;
+ if (i < argc) {
+ encoding = argv[i];
+ }
+ else {
+ printf ("Missing encoding\n");
+ show_help();
+ exit(1);
+ }
+ }
+ else if (!strncmp(argv[i], "-u", 3)) {
+ i++;
+ if (i < argc) {
+ char* details = argv[i];
+ if (!strncmp(details, "HILO", 4))
+ enc = TWO_BYTE_HILO;
+ else if (!strncmp(details, "LOHI", 4))
+ enc = TWO_BYTE_LOHI;
+ else {
+ printf("Unknown encoding details %s\n", details);
+ show_help();
+ exit(1);
+ }
+ if (!strncmp(details+5, "BOM", 4))
+ bom = WITH_BOM;
+ }
+ else {
+ printf ("Missing encoding details\n");
+ show_help();
+ exit(1);
+ }
+ }
+ else if (!strncmp(argv[i], "-t", 3)) {
+ i++;
+ if (i < argc) {
+ char* term = argv[i];
+ if (!strncmp(term, "CR", 3))
+ end = END_CR;
+ else if (!strncmp(term, "LF", 3))
+ end = END_LF;
+ else if (!strncmp(term, "CR_LF", 6))
+ end = END_CR_LF;
+ else if (!strncmp(term, "LF_CR", 6))
+ end = END_LF_CR;
+ else {
+ printf("Unknown terminator: %s\n", term);
+ show_help();
+ exit(1);
+ }
+ }
+ else {
+ printf ("Missing terminator\n");
+ show_help();
+ exit(1);
+ }
+ }
+ else {
+ printf ("Unrecognized option: %s\n", argv[i]);
+ show_help();
+ exit(1);
+ }
+ }
+ }
+
+ gedcom_init();
+ setlocale(LC_ALL, "");
+ gedcom_set_message_handler(gedcom_message_handler);
+ gedcom_write_set_encoding(encoding, enc, bom);
+ gedcom_write_set_line_terminator(end);
+
+ output_open(outfilename);
+
+ result = gom_new_model();
+ /*
+ if (result == 0)
+ result |= update_charset(encoding);
+ */
+ if (result == 0)
+ result |= gom_write_file(gedfilename, &total_conv_fails);
+ if (result == 0 && total_conv_fails == 0) {
+ output(1, "Test succeeded\n");
+ }
+ else {
+ output(1, "Test failed: %d\n", result);
+ }
+
+ output_close();
+ return result;
+}
then
echo "Output agrees with reference output" >> $logfile
rm $outfile
+ if [ "$gedcom_out" ]
+ then
+ if diff $gedfile $gedreffile >/dev/null 2>>$logfile
+ then
+ echo "Gedcom output agrees with reference output" >> $logfile
+ rm $gedfile
+ exit 0
+ else
+ echo "Differences with reference gedcom output detected!" >> $logfile
+ exit 1
+ fi
+ fi
exit 0
else
echo "Differences with reference output detected!" >> $logfile
reffile=$srcdir/output/$test_name.ref
options="$options -o $outfile"
+if [ "$gedcom_out" ]
+then
+ gedfile=$test_name.ged
+ gedreffile=$srcdir/output/$test_name.ged
+ options="$options -w $gedfile"
+fi
+
GCONV_PATH=.:$GCONV_PATH
export GCONV_PATH
LC_ALL=$GEDCOM_LANG
--- /dev/null
+#!/bin/sh
+# $Id$
+# $Name$
+
+builddir=`pwd`
+if [ -z "$srcdir" ]
+then
+ srcdir=.
+fi
+
+test_program=writegomtest
+test_libs="$builddir/../gedcom/libgedcom.la $builddir/../gom/libgedcom_gom.la"
+gedcom_out=1
+
+. $srcdir/src/test_prologue.sh
+
+terminator=$1
+encoding=$2
+unicode_details=$3
+options="$options -t $terminator -e $encoding"
+
+if [ "$encoding" == "UNICODE" ]
+then
+ options="$options -u $unicode_details"
+fi
+
+. $srcdir/src/test_bulk.sh
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 LF ANSEL
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 LF ASCII
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 CR_LF UNICODE HILO_BOM
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 CR_LF UNICODE HILO
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 CR_LF UNICODE LOHI_BOM
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 CR UNICODE LOHI
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 CR_LF UNICODE LOHI
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 LF UNICODE LOHI
--- /dev/null
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 LF_CR UNICODE LOHI