1 /* Test program for the Gedcom library.
2 Copyright (C) 2001, 2002 The Genes Development Team
3 This file is part of the Gedcom parser library.
4 Contributed by Peter Verthez <Peter.Verthez@advalvas.be>, 2001.
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 "portability.h"
31 #define WRITE_GEDCOM "gom_write.ged"
32 #define PROG_NAME "writegomtest"
33 #define PROG_VERSION "3.14"
35 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
38 output(1, "MESSAGE: ");
39 else if (type == WARNING)
40 output(1, "WARNING: ");
41 else if (type == ERROR)
43 output(1, "%s\n", msg);
48 printf("gedcom-parse test program for libgedcom\n\n");
49 printf("Usage: writegomtest [options]\n");
51 printf(" -h Show this help text\n");
52 printf(" -q No output to standard output\n");
53 printf(" -o <outfile> File to generate errors to (def. testgedcom.out)\n");
54 printf(" -w <gedfile> File to write gedcom to (def. %s)\n", WRITE_GEDCOM);
55 printf(" -e <encoding> Encoding (UNICODE, ASCII, ANSEL, ...: see gedcom.enc)\n");
56 printf(" -u <unicode_enc> Encoding details for Unicode\n");
57 printf(" <unicode_enc> can be: HILO, LOHI, HILO_BOM, LOHI_BOM\n");
58 printf(" -t <terminator> Line terminator\n");
59 printf(" <terminator> can be CR, LF, CR_LF, LF_CR\n");
62 int update_charset(char* encoding)
64 struct header* head = NULL;
67 head = gom_get_header();
71 value = gom_set_string(&head->charset.name, encoding);
72 if (value == NULL || strcmp(value, encoding))
79 int main(int argc, char* argv[])
82 int total_conv_fails = 0;
83 char* outfilename = NULL;
84 char* gedfilename = WRITE_GEDCOM;
85 char* encoding = "ASCII";
86 Encoding enc = ONE_BYTE;
87 Enc_bom bom = WITHOUT_BOM;
88 Enc_line_end end = END_LF;
92 for (i=1; i<argc; i++) {
93 if (!strncmp(argv[i], "-h", 3)) {
97 else if (!strncmp(argv[i], "-q", 3)) {
100 else if (!strncmp(argv[i], "-o", 3)) {
103 outfilename = argv[i];
106 printf ("Missing output file name\n");
111 else if (!strncmp(argv[i], "-w", 3)) {
114 gedfilename = argv[i];
117 printf ("Missing output file name\n");
122 else if (!strncmp(argv[i], "-e", 3)) {
128 printf ("Missing encoding\n");
133 else if (!strncmp(argv[i], "-u", 3)) {
136 char* details = argv[i];
137 if (!strncmp(details, "HILO", 4))
139 else if (!strncmp(details, "LOHI", 4))
142 printf("Unknown encoding details %s\n", details);
146 if (!strncmp(details+5, "BOM", 4))
150 printf ("Missing encoding details\n");
155 else if (!strncmp(argv[i], "-t", 3)) {
158 char* term = argv[i];
159 if (!strncmp(term, "CR", 3))
161 else if (!strncmp(term, "LF", 3))
163 else if (!strncmp(term, "CR_LF", 6))
165 else if (!strncmp(term, "LF_CR", 6))
168 printf("Unknown terminator: %s\n", term);
174 printf ("Missing terminator\n");
180 printf ("Unrecognized option: %s\n", argv[i]);
188 setlocale(LC_ALL, "");
189 gedcom_set_message_handler(gedcom_message_handler);
190 gedcom_write_set_encoding(encoding, enc, bom);
191 gedcom_write_set_line_terminator(end);
193 output_open(outfilename);
195 result = gom_new_model();
198 result |= update_charset(encoding);
201 result |= gom_write_file(gedfilename, &total_conv_fails);
202 if (result == 0 && total_conv_fails == 0) {
203 output(1, "Test succeeded\n");
206 output(1, "Test failed: %d\n", result);