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"
34 #define TIMESTAMP 1000000000L
36 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
39 output(1, "MESSAGE: ");
40 else if (type == WARNING)
41 output(1, "WARNING: ");
42 else if (type == ERROR)
44 output(1, "%s\n", msg);
49 printf("gedcom-parse test program for libgedcom\n\n");
50 printf("Usage: writegomtest [options]\n");
52 printf(" -h Show this help text\n");
53 printf(" -q No output to standard output\n");
54 printf(" -o <outfile> File to generate errors to (def. testgedcom.out)\n");
55 printf(" -i <gedfile> File to read gedcom from (default: new file)\n");
56 printf(" -w <gedfile> File to write gedcom to (def. %s)\n", WRITE_GEDCOM);
57 printf(" -e <encoding> Encoding (UNICODE, ASCII, ANSEL, ...: see gedcom.enc)\n");
58 printf(" -u <unicode_enc> Encoding details for Unicode\n");
59 printf(" <unicode_enc> can be: HILO, LOHI, HILO_BOM, LOHI_BOM\n");
60 printf(" -t <terminator> Line terminator\n");
61 printf(" <terminator> can be CR, LF, CR_LF, LF_CR\n");
64 int update_header(char* encoding)
66 struct header* head = NULL;
68 char* long_note = "This note is for testing the continuation stuff\n"
69 "Some Specials: This line is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long but too long (255 caharcters is the limit), so this is going over the border\n"
70 "And now we have an at character: @, which should be doubled";
72 head = gom_get_header();
76 /* force warning for anything except UNICODE */
77 if (!strcmp(encoding, "UNICODE")) {
78 value = gom_set_string(&head->charset.name, encoding);
79 if (value == NULL || strcmp(value, encoding))
82 value = gom_set_string(&head->note, long_note);
83 if (value == NULL || strcmp(value, long_note))
90 int main(int argc, char* argv[])
95 int total_conv_fails = 0;
96 char* outfilename = NULL;
97 char* infilename = NULL;
98 char* gedfilename = WRITE_GEDCOM;
99 char* encoding = "ASCII";
100 Encoding enc = ONE_BYTE;
101 Enc_bom bom = WITHOUT_BOM;
102 Enc_line_end end = END_LF;
106 for (i=1; i<argc; i++) {
107 if (!strncmp(argv[i], "-h", 3)) {
111 else if (!strncmp(argv[i], "-q", 3)) {
114 else if (!strncmp(argv[i], "-o", 3)) {
117 outfilename = argv[i];
120 printf ("Missing output file name\n");
125 else if (!strncmp(argv[i], "-w", 3)) {
128 gedfilename = argv[i];
131 printf ("Missing output file name\n");
136 else if (!strncmp(argv[i], "-i", 3)) {
139 infilename = argv[i];
142 printf ("Missing input file name\n");
147 else if (!strncmp(argv[i], "-e", 3)) {
153 printf ("Missing encoding\n");
158 else if (!strncmp(argv[i], "-u", 3)) {
161 char* details = argv[i];
162 if (!strncmp(details, "HILO", 4))
164 else if (!strncmp(details, "LOHI", 4))
167 printf("Unknown encoding details %s\n", details);
171 if (!strncmp(details+5, "BOM", 4))
175 printf ("Missing encoding details\n");
180 else if (!strncmp(argv[i], "-t", 3)) {
183 char* term = argv[i];
184 if (!strncmp(term, "CR", 3))
186 else if (!strncmp(term, "LF", 3))
188 else if (!strncmp(term, "CR_LF", 6))
190 else if (!strncmp(term, "LF_CR", 6))
193 printf("Unknown terminator: %s\n", term);
199 printf ("Missing terminator\n");
205 printf ("Unrecognized option: %s\n", argv[i]);
213 setlocale(LC_ALL, "");
214 gedcom_set_message_handler(gedcom_message_handler);
215 gedcom_write_set_encoding(encoding, enc, bom);
216 gedcom_write_set_line_terminator(end);
218 output_open(outfilename);
221 result = gom_parse_file(infilename);
224 result = gom_new_model();
226 result |= update_header(encoding);
228 /* Make sure we get a reproduceable output, in different timezones */
231 tm_ptr = gmtime(&tval);
232 tm_ptr->tm_isdst = 0;
233 tval = mktime(tm_ptr);
234 result = gom_header_update_timestamp(tval);
237 result |= gom_write_file(gedfilename, &total_conv_fails);
238 if (result == 0 && total_conv_fails == 0) {
239 output(1, "Test succeeded\n");
242 output(1, "Test failed: %d\n", result);