Beginnings of write support.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Wed, 4 Dec 2002 18:43:19 +0000 (18:43 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Wed, 4 Dec 2002 18:43:19 +0000 (18:43 +0000)
41 files changed:
acinclude.m4
configure.in
gom/gom.c
gom/header.c
gom/header.h
include/gedcom.h.in
include/gom.h
po/POTFILES.in
t/Makefile.am
t/output/write_gom_ansel.ged [new file with mode: 0644]
t/output/write_gom_ansel.ref [new file with mode: 0644]
t/output/write_gom_ascii.ged [new file with mode: 0644]
t/output/write_gom_ascii.ref [new file with mode: 0644]
t/output/write_gom_uhlbomcl.ged [new file with mode: 0644]
t/output/write_gom_uhlbomcl.ref [new file with mode: 0644]
t/output/write_gom_uhlcl.ged [new file with mode: 0644]
t/output/write_gom_uhlcl.ref [new file with mode: 0644]
t/output/write_gom_ulhbomcl.ged [new file with mode: 0644]
t/output/write_gom_ulhbomcl.ref [new file with mode: 0644]
t/output/write_gom_ulhc.ged [new file with mode: 0644]
t/output/write_gom_ulhc.ref [new file with mode: 0644]
t/output/write_gom_ulhcl.ged [new file with mode: 0644]
t/output/write_gom_ulhcl.ref [new file with mode: 0644]
t/output/write_gom_ulhl.ged [new file with mode: 0644]
t/output/write_gom_ulhl.ref [new file with mode: 0644]
t/output/write_gom_ulhlc.ged [new file with mode: 0644]
t/output/write_gom_ulhlc.ref [new file with mode: 0644]
t/src/Makefile.am
t/src/gom_write.c [new file with mode: 0644]
t/src/test_bulk.sh
t/src/test_prologue.sh
t/src/test_writegom [new file with mode: 0755]
t/write_gom_ansel.test [new file with mode: 0755]
t/write_gom_ascii.test [new file with mode: 0755]
t/write_gom_uhlbomcl.test [new file with mode: 0755]
t/write_gom_uhlcl.test [new file with mode: 0755]
t/write_gom_ulhbomcl.test [new file with mode: 0755]
t/write_gom_ulhc.test [new file with mode: 0755]
t/write_gom_ulhcl.test [new file with mode: 0755]
t/write_gom_ulhl.test [new file with mode: 0755]
t/write_gom_ulhlc.test [new file with mode: 0755]

index ac07948cde1ddf32d1c549be97cfd233fc687869..8328aab3f92ad9ff2e767e03be6321c78574e956 100644 (file)
@@ -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 <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])
+])
index fbb85eca367a1ea203a88a156acf8471baa3ff7c..b13d759b2e1e94f80358b479b1d214078e297e48 100644 (file)
@@ -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
index cc388ee2be9dbd7484d4a5d55e9ed3b4a26eea72..ed9d5e5f530011d73e5881280c4bb808ff68f053 100644 (file)
--- 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));
index f9032d8f1368af31d6541dc0b93b55310d98ffec..130d06e06ad110614d8082ec228d7e6f76dbf7ee 100644 (file)
@@ -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;
+}
index 7882a2b183ee8ad721555986136f33be6ba08906..0a5bd9e72e38956e211b695b4de0605838838a76 100644 (file)
@@ -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 */
index b708cf0e5c0e555ffcca0d220b41450b6446fe58..c2c0bf1c59f099c83e540503b9a74aac0c87d5fc 100644 (file)
@@ -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, ...);
index 46ce4a6d1ee65723c1840806f61465897fd8fd04..15d52a9eea1149cf19c04467802e584bc5fd6e4f 100644 (file)
@@ -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();
index 47e3ba19e079c4e13878aa3a96f031c59bd40e58..07bd744b87bf82e33f8b626bb01a783c3c8021fc 100644 (file)
@@ -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
 
index bb6331421119d0b22b572e6c21e632849ccce779..c1f50b45b5522a01040d1b282aebb9978fcd4c95 100644 (file)
@@ -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 (file)
index 0000000..6e3a959
--- /dev/null
@@ -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 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -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 (file)
index 0000000..6e3a959
--- /dev/null
@@ -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 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -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 (file)
index 0000000..3830cfc
Binary files /dev/null and b/t/output/write_gom_uhlbomcl.ged differ
diff --git a/t/output/write_gom_uhlbomcl.ref b/t/output/write_gom_uhlbomcl.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -0,0 +1 @@
+Test succeeded
diff --git a/t/output/write_gom_uhlcl.ged b/t/output/write_gom_uhlcl.ged
new file mode 100644 (file)
index 0000000..2e10525
Binary files /dev/null and b/t/output/write_gom_uhlcl.ged differ
diff --git a/t/output/write_gom_uhlcl.ref b/t/output/write_gom_uhlcl.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -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 (file)
index 0000000..6672931
Binary files /dev/null and b/t/output/write_gom_ulhbomcl.ged differ
diff --git a/t/output/write_gom_ulhbomcl.ref b/t/output/write_gom_ulhbomcl.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -0,0 +1 @@
+Test succeeded
diff --git a/t/output/write_gom_ulhc.ged b/t/output/write_gom_ulhc.ged
new file mode 100644 (file)
index 0000000..5e66b5b
Binary files /dev/null and b/t/output/write_gom_ulhc.ged differ
diff --git a/t/output/write_gom_ulhc.ref b/t/output/write_gom_ulhc.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -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 (file)
index 0000000..baf199d
Binary files /dev/null and b/t/output/write_gom_ulhcl.ged differ
diff --git a/t/output/write_gom_ulhcl.ref b/t/output/write_gom_ulhcl.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -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 (file)
index 0000000..b02d6b9
Binary files /dev/null and b/t/output/write_gom_ulhl.ged differ
diff --git a/t/output/write_gom_ulhl.ref b/t/output/write_gom_ulhl.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -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 (file)
index 0000000..8b7ec45
Binary files /dev/null and b/t/output/write_gom_ulhlc.ged differ
diff --git a/t/output/write_gom_ulhlc.ref b/t/output/write_gom_ulhlc.ref
new file mode 100644 (file)
index 0000000..2fc8ba6
--- /dev/null
@@ -0,0 +1 @@
+Test succeeded
index 66ee63c8511342d325b4691c8a68be071b8cca46..0244bf77b87094b18406be63d97f1dd8cd697f97 100644 (file)
@@ -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 (file)
index 0000000..3884328
--- /dev/null
@@ -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 <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;
+}
index c4f29e6464c7dfab459f765c9515ec6fdc94c808..47120413f9c15792bd548fd3cabf0c30752774f1 100644 (file)
@@ -32,6 +32,18 @@ else
     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
index 5a5f330bc8a73badcfc4fe54ab4df25b03f64a60..d548ea387d6075e8a870d9203b962ba2160d1f65 100644 (file)
@@ -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 (executable)
index 0000000..24ec246
--- /dev/null
@@ -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 (executable)
index 0000000..d199593
--- /dev/null
@@ -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 (executable)
index 0000000..6a11f64
--- /dev/null
@@ -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 (executable)
index 0000000..11f2bf5
--- /dev/null
@@ -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 (executable)
index 0000000..0b7a087
--- /dev/null
@@ -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 (executable)
index 0000000..6fbfab0
--- /dev/null
@@ -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 (executable)
index 0000000..23d1195
--- /dev/null
@@ -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 (executable)
index 0000000..61d8c7c
--- /dev/null
@@ -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 (executable)
index 0000000..a170ca2
--- /dev/null
@@ -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 (executable)
index 0000000..d7f1c98
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+$srcdir/src/test_writegom $0 0 LF_CR UNICODE LOHI