From e5f86c3d527897be1f7e7135ffdfc023831aaebd Mon Sep 17 00:00:00 2001 From: Peter Verthez Date: Wed, 4 Dec 2002 18:43:19 +0000 Subject: [PATCH] Beginnings of write support. --- acinclude.m4 | 45 +++++++ configure.in | 1 + gom/gom.c | 14 +++ gom/header.c | 73 +++++++++++ gom/header.h | 1 + include/gedcom.h.in | 47 ++++++- include/gom.h | 1 + po/POTFILES.in | 1 + t/Makefile.am | 2 +- t/output/write_gom_ansel.ged | 8 ++ t/output/write_gom_ansel.ref | 1 + t/output/write_gom_ascii.ged | 8 ++ t/output/write_gom_ascii.ref | 1 + t/output/write_gom_uhlbomcl.ged | Bin 0 -> 216 bytes t/output/write_gom_uhlbomcl.ref | 1 + t/output/write_gom_uhlcl.ged | Bin 0 -> 214 bytes t/output/write_gom_uhlcl.ref | 1 + t/output/write_gom_ulhbomcl.ged | Bin 0 -> 216 bytes t/output/write_gom_ulhbomcl.ref | 1 + t/output/write_gom_ulhc.ged | Bin 0 -> 198 bytes t/output/write_gom_ulhc.ref | 1 + t/output/write_gom_ulhcl.ged | Bin 0 -> 214 bytes t/output/write_gom_ulhcl.ref | 1 + t/output/write_gom_ulhl.ged | Bin 0 -> 198 bytes t/output/write_gom_ulhl.ref | 1 + t/output/write_gom_ulhlc.ged | Bin 0 -> 214 bytes t/output/write_gom_ulhlc.ref | 1 + t/src/Makefile.am | 9 +- t/src/gom_write.c | 211 ++++++++++++++++++++++++++++++++ t/src/test_bulk.sh | 12 ++ t/src/test_prologue.sh | 7 ++ t/src/test_writegom | 27 ++++ t/write_gom_ansel.test | 3 + t/write_gom_ascii.test | 3 + t/write_gom_uhlbomcl.test | 3 + t/write_gom_uhlcl.test | 3 + t/write_gom_ulhbomcl.test | 3 + t/write_gom_ulhc.test | 3 + t/write_gom_ulhcl.test | 3 + t/write_gom_ulhl.test | 3 + t/write_gom_ulhlc.test | 3 + 41 files changed, 494 insertions(+), 9 deletions(-) create mode 100644 t/output/write_gom_ansel.ged create mode 100644 t/output/write_gom_ansel.ref create mode 100644 t/output/write_gom_ascii.ged create mode 100644 t/output/write_gom_ascii.ref create mode 100644 t/output/write_gom_uhlbomcl.ged create mode 100644 t/output/write_gom_uhlbomcl.ref create mode 100644 t/output/write_gom_uhlcl.ged create mode 100644 t/output/write_gom_uhlcl.ref create mode 100644 t/output/write_gom_ulhbomcl.ged create mode 100644 t/output/write_gom_ulhbomcl.ref create mode 100644 t/output/write_gom_ulhc.ged create mode 100644 t/output/write_gom_ulhc.ref create mode 100644 t/output/write_gom_ulhcl.ged create mode 100644 t/output/write_gom_ulhcl.ref create mode 100644 t/output/write_gom_ulhl.ged create mode 100644 t/output/write_gom_ulhl.ref create mode 100644 t/output/write_gom_ulhlc.ged create mode 100644 t/output/write_gom_ulhlc.ref create mode 100644 t/src/gom_write.c create mode 100755 t/src/test_writegom create mode 100755 t/write_gom_ansel.test create mode 100755 t/write_gom_ascii.test create mode 100755 t/write_gom_uhlbomcl.test create mode 100755 t/write_gom_uhlcl.test create mode 100755 t/write_gom_ulhbomcl.test create mode 100755 t/write_gom_ulhc.test create mode 100755 t/write_gom_ulhcl.test create mode 100755 t/write_gom_ulhl.test create mode 100755 t/write_gom_ulhlc.test diff --git a/acinclude.m4 b/acinclude.m4 index ac07948..8328aab 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -130,3 +130,48 @@ AC_DEFUN(gedcom_LIBICONV_HAS_ANSEL, [ 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 +#include +#include +#include +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]) +]) diff --git a/configure.in b/configure.in index fbb85ec..b13d759 100644 --- a/configure.in +++ b/configure.in @@ -76,6 +76,7 @@ jm_GLIBC21 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 diff --git a/gom/gom.c b/gom/gom.c index cc388ee..ed9d5e5 100644 --- a/gom/gom.c +++ b/gom/gom.c @@ -115,6 +115,20 @@ int gom_new_model() 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)); diff --git a/gom/header.c b/gom/header.c index f9032d8..130d06e 100644 --- a/gom/header.c +++ b/gom/header.c @@ -173,3 +173,76 @@ struct header* gom_get_header() { 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; +} diff --git a/gom/header.h b/gom/header.h index 7882a2b..0a5bd9e 100644 --- a/gom/header.h +++ b/gom/header.h @@ -33,5 +33,6 @@ void header_add_address(Gom_ctxt header, struct address* addr); 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 */ diff --git a/include/gedcom.h.in b/include/gedcom.h.in index b708cf0..c2c0bf1 100644 --- a/include/gedcom.h.in +++ b/include/gedcom.h.in @@ -62,7 +62,7 @@ typedef enum _REC { } 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, @@ -367,6 +367,24 @@ struct age_value { 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 ***/ @@ -374,11 +392,11 @@ struct age_value { /**************************************************************************/ 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 { @@ -416,6 +434,10 @@ extern struct xref_value def_xref_val; /* 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) @@ -503,6 +525,19 @@ struct xref_value *gedcom_link_xref(Xref_type type, const char* xrefstr); 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, ...); diff --git a/include/gom.h b/include/gom.h index 46ce4a6..15d52a9 100644 --- a/include/gom.h +++ b/include/gom.h @@ -417,6 +417,7 @@ struct user_rec { 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(); diff --git a/po/POTFILES.in b/po/POTFILES.in index 47e3ba1..07bd744 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -12,6 +12,7 @@ gedcom/message.c gedcom/interface.c gedcom/xref.c gedcom/compat.c +gedcom/write.c gom/gom.c gom/gom_modify.c diff --git a/t/Makefile.am b/t/Makefile.am index bb63314..c1f50b4 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -11,7 +11,7 @@ EXTRA_DIST=$(TESTS) test_valgrind untest_valgrind TESTS_ENVIRONMENT=ICONV_PATH=@ICONV_PATH@ all-local: - @rm -f *.out + @rm -f *.out *.ged check-% : %.test all @srcdir=$(srcdir); export srcdir; \ diff --git a/t/output/write_gom_ansel.ged b/t/output/write_gom_ansel.ged new file mode 100644 index 0000000..6e3a959 --- /dev/null +++ b/t/output/write_gom_ansel.ged @@ -0,0 +1,8 @@ +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 diff --git a/t/output/write_gom_ansel.ref b/t/output/write_gom_ansel.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_ansel.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/output/write_gom_ascii.ged b/t/output/write_gom_ascii.ged new file mode 100644 index 0000000..6e3a959 --- /dev/null +++ b/t/output/write_gom_ascii.ged @@ -0,0 +1,8 @@ +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 diff --git a/t/output/write_gom_ascii.ref b/t/output/write_gom_ascii.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_ascii.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/output/write_gom_uhlbomcl.ged b/t/output/write_gom_uhlbomcl.ged new file mode 100644 index 0000000000000000000000000000000000000000..3830cfcc638cc898cf3fa4b11a2881d0aad3ff7f GIT binary patch literal 216 zcmY+9OA5k35JcZv@D6hUMTOv6lBmJ>VWMum|0UGdA&JN^LsxfIbHy9%QS7lZsM&=EY4`c3St$jq|5-Sw|;PuvNRCJ$}mYTrw+})$GveopnzP^jxPTq1}A( Z+4`TXHfv-^zN5K%Pi%-^JnRo%@dxoU7mok{ literal 0 HcmV?d00001 diff --git a/t/output/write_gom_uhlcl.ref b/t/output/write_gom_uhlcl.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_uhlcl.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/output/write_gom_ulhbomcl.ged b/t/output/write_gom_ulhbomcl.ged new file mode 100644 index 0000000000000000000000000000000000000000..66729316a40788c11b16f702d2ab8b9287091749 GIT binary patch literal 216 zcmY+9OA5k35JcZv@D6hUB?`f{%KBPPTC8 zMHY?rdph}*4-Ylj>7Z`!^erkpXxQpJRR8MwSGB6z>OHwLyET}Zxc%~rZ&Ue2yx!A! TUr7%C#cL*CGBbGEovp+d8I2b| literal 0 HcmV?d00001 diff --git a/t/output/write_gom_ulhc.ref b/t/output/write_gom_ulhc.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_ulhc.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/output/write_gom_ulhcl.ged b/t/output/write_gom_ulhcl.ged new file mode 100644 index 0000000000000000000000000000000000000000..baf199d6808305533353d5ceffa2bf201c7b8150 GIT binary patch literal 214 zcmY+8TMEK36hzOr;2yF8B?`rF=|hY4L8|_`|6O=)(TaqGnR{m@lSv$D+0(FO!A3rE z7 Y|C-fyjSk6ov{&zmAF`9X^T8YZ4G7Q|j{pDw literal 0 HcmV?d00001 diff --git a/t/output/write_gom_ulhcl.ref b/t/output/write_gom_ulhcl.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_ulhcl.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/output/write_gom_ulhl.ged b/t/output/write_gom_ulhl.ged new file mode 100644 index 0000000000000000000000000000000000000000..b02d6b92e52d37880dd0fcb1d00f33a51a7fa7e0 GIT binary patch literal 198 zcmZ9GOAf*?3`E~Lr|<ph+K TmE`bWyk_zxGlQqy*-Cr?5kVIx literal 0 HcmV?d00001 diff --git a/t/output/write_gom_ulhl.ref b/t/output/write_gom_ulhl.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_ulhl.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/output/write_gom_ulhlc.ged b/t/output/write_gom_ulhlc.ged new file mode 100644 index 0000000000000000000000000000000000000000..8b7ec454db624b5d7b4f4ccc35bb7e9caa06db6f GIT binary patch literal 214 zcmY+8TMEK36hzOr;2yF8B?`rF=|hY4L8|_`|6O=)(TaqGnR{m@lSv$D+0(FK$woeM z7 Y|C-fyjSk6ov{&zmAF`9X^T8YZ4G5qYj{pDw literal 0 HcmV?d00001 diff --git a/t/output/write_gom_ulhlc.ref b/t/output/write_gom_ulhlc.ref new file mode 100644 index 0000000..2fc8ba6 --- /dev/null +++ b/t/output/write_gom_ulhlc.ref @@ -0,0 +1 @@ +Test succeeded diff --git a/t/src/Makefile.am b/t/src/Makefile.am index 66ee63c..0244bf7 100644 --- a/t/src/Makefile.am +++ b/t/src/Makefile.am @@ -6,7 +6,8 @@ INCLUDES = -DPKGDATADIR=\"$(pkgdatadir)\" -I $(srcdir)/../../include \ -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 @@ -29,10 +30,14 @@ updategomtest_SOURCES = update_gom.c output.c dump_gom.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) diff --git a/t/src/gom_write.c b/t/src/gom_write.c new file mode 100644 index 0000000..3884328 --- /dev/null +++ b/t/src/gom_write.c @@ -0,0 +1,211 @@ +/* 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 , 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 +#include + +#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 File to generate errors to (def. testgedcom.out)\n"); + printf(" -w File to write gedcom to (def. %s)\n", WRITE_GEDCOM); + printf(" -e Encoding (UNICODE, ASCII, ANSEL, ...: see gedcom.enc)\n"); + printf(" -u Encoding details for Unicode\n"); + printf(" can be: HILO, LOHI, HILO_BOM, LOHI_BOM\n"); + printf(" -t Line terminator\n"); + printf(" 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> $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 diff --git a/t/src/test_prologue.sh b/t/src/test_prologue.sh index 5a5f330..d548ea3 100644 --- a/t/src/test_prologue.sh +++ b/t/src/test_prologue.sh @@ -43,6 +43,13 @@ logfile=check.out 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 diff --git a/t/src/test_writegom b/t/src/test_writegom new file mode 100755 index 0000000..24ec246 --- /dev/null +++ b/t/src/test_writegom @@ -0,0 +1,27 @@ +#!/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 diff --git a/t/write_gom_ansel.test b/t/write_gom_ansel.test new file mode 100755 index 0000000..d199593 --- /dev/null +++ b/t/write_gom_ansel.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 LF ANSEL diff --git a/t/write_gom_ascii.test b/t/write_gom_ascii.test new file mode 100755 index 0000000..6a11f64 --- /dev/null +++ b/t/write_gom_ascii.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 LF ASCII diff --git a/t/write_gom_uhlbomcl.test b/t/write_gom_uhlbomcl.test new file mode 100755 index 0000000..11f2bf5 --- /dev/null +++ b/t/write_gom_uhlbomcl.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 CR_LF UNICODE HILO_BOM diff --git a/t/write_gom_uhlcl.test b/t/write_gom_uhlcl.test new file mode 100755 index 0000000..0b7a087 --- /dev/null +++ b/t/write_gom_uhlcl.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 CR_LF UNICODE HILO diff --git a/t/write_gom_ulhbomcl.test b/t/write_gom_ulhbomcl.test new file mode 100755 index 0000000..6fbfab0 --- /dev/null +++ b/t/write_gom_ulhbomcl.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 CR_LF UNICODE LOHI_BOM diff --git a/t/write_gom_ulhc.test b/t/write_gom_ulhc.test new file mode 100755 index 0000000..23d1195 --- /dev/null +++ b/t/write_gom_ulhc.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 CR UNICODE LOHI diff --git a/t/write_gom_ulhcl.test b/t/write_gom_ulhcl.test new file mode 100755 index 0000000..61d8c7c --- /dev/null +++ b/t/write_gom_ulhcl.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 CR_LF UNICODE LOHI diff --git a/t/write_gom_ulhl.test b/t/write_gom_ulhl.test new file mode 100755 index 0000000..a170ca2 --- /dev/null +++ b/t/write_gom_ulhl.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 LF UNICODE LOHI diff --git a/t/write_gom_ulhlc.test b/t/write_gom_ulhlc.test new file mode 100755 index 0000000..d7f1c98 --- /dev/null +++ b/t/write_gom_ulhlc.test @@ -0,0 +1,3 @@ +#!/bin/sh + +$srcdir/src/test_writegom $0 0 LF_CR UNICODE LOHI -- 2.30.2