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 if (head->source.corporation.address) {
94 result = gom_delete_address(&head->source.corporation.address);
100 if (head->source.corporation.phone[i]) {
101 value = gom_set_string(&head->source.corporation.phone[i], NULL);
111 int main(int argc, char* argv[])
113 Gedcom_err_mech mech = DEFER_FAIL;
114 int compat_enabled = 1;
117 char* file_name = NULL;
119 char* extension = "new";
123 for (i=1; i<argc; i++) {
124 if (!strncmp(argv[i], "-da", 4))
126 else if (!strncmp(argv[i], "-dg", 4))
128 else if (!strncmp(argv[i], "-s", 3))
130 else if (!strncmp(argv[i], "-e", 3)) {
132 extension = argv[++i];
139 else if (!strncmp(argv[i], "-h", 3)) {
143 else if (strncmp(argv[i], "-", 1)) {
148 printf ("Unrecognized option: %s\n", argv[i]);
156 printf("No file name given\n");
162 setlocale(LC_ALL, "");
163 gedcom_set_debug_level(debug_level, NULL);
164 gedcom_set_compat_handling(compat_enabled);
165 gedcom_set_error_handling(mech);
166 gedcom_set_message_handler(gedcom_message_handler);
168 result = gom_parse_file(file_name);
171 char* newfile = (char*)malloc(strlen(file_name) + strlen(extension) + 2);
172 sprintf(newfile, "%s.%s", file_name, extension);
173 printf(_("Parse succeeded, now writing file '%s'\n"), newfile);
175 result = update_header();
178 result = gom_write_file(newfile, NULL);
181 printf(_("Write succeeded\n"));
184 printf(_("Write failed\n"));
188 printf(_("Parse failed\n"));