1 /* Check program using 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
26 #include "utf8tools.h"
35 #define _(string) dgettext(PACKAGE, string)
36 #define N_(string) (string)
39 #define UNUSED __attribute__((unused))
44 #define PROG_NAME "GEDCOM_PARSE"
48 printf("Converts a GEDCOM file to strict standard GEDCOM\n\n");
49 printf("Usage: gedcom-sanitize [options] file\n");
51 printf(" -h Show this help text\n");
52 printf(" -dg Debug setting: only libgedcom debug messages\n");
53 printf(" -da Debug setting: libgedcom + yacc debug messages\n");
54 printf(" -e <extension> Extension to give to file name (default 'new')\n");
55 printf(" -s Keep source string (otherwise: changed to GEDCOM_PARSE)\n");
56 printf("Errors, warnings, ... are sent to stdout\n");
59 void gedcom_message_handler(Gedcom_msg_type type UNUSED, char *msg)
61 char *converted = NULL;
63 converted = convert_utf8_to_locale(msg, &conv_fails);
64 printf("%s\n", converted);
69 struct header* head = NULL;
70 head = gom_get_header();
77 value = gom_set_string(&head->source.id, PROG_NAME);
78 if (value == NULL || strcmp (value, PROG_NAME))
81 value = gom_set_string(&head->source.name, NULL);
85 value = gom_set_string(&head->source.version, VERSION);
86 if (value == NULL || strcmp (value, VERSION))
89 value = gom_set_string(&head->source.corporation.name, NULL);
93 result = gom_delete_address(&head->source.corporation.address);
98 if (head->source.corporation.phone[i]) {
99 value = gom_set_string(&head->source.corporation.phone[i], NULL);
109 int main(int argc, char* argv[])
111 Gedcom_err_mech mech = DEFER_FAIL;
112 int compat_enabled = 1;
115 char* file_name = NULL;
117 char* extension = "new";
121 for (i=1; i<argc; i++) {
122 if (!strncmp(argv[i], "-da", 4))
124 else if (!strncmp(argv[i], "-dg", 4))
126 else if (!strncmp(argv[i], "-s", 3))
128 else if (!strncmp(argv[i], "-e", 3)) {
130 extension = argv[++i];
137 else if (!strncmp(argv[i], "-h", 3)) {
141 else if (strncmp(argv[i], "-", 1)) {
146 printf ("Unrecognized option: %s\n", argv[i]);
154 printf("No file name given\n");
160 setlocale(LC_ALL, "");
161 gedcom_set_debug_level(debug_level, NULL);
162 gedcom_set_compat_handling(compat_enabled);
163 gedcom_set_error_handling(mech);
164 gedcom_set_message_handler(gedcom_message_handler);
166 result = gom_parse_file(file_name);
169 char* newfile = (char*)malloc(strlen(file_name) + strlen(extension) + 2);
170 sprintf(newfile, "%s.%s", file_name, extension);
171 printf(_("Parse succeeded, now writing file '%s'\n"), newfile);
173 result = update_header();
176 result = gom_write_file(newfile, NULL);
179 printf(_("Write succeeded\n"));
182 printf(_("Write failed\n"));
186 printf(_("Parse failed\n"));