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))
46 printf("Converts a GEDCOM file to strict standard GEDCOM\n\n");
47 printf("Usage: gedcom-sanitize [options] file\n");
49 printf(" -h Show this help text\n");
50 printf(" -dg Debug setting: only libgedcom debug messages\n");
51 printf(" -da Debug setting: libgedcom + yacc debug messages\n");
52 printf(" -e <extension> Extension to give to file name (default 'new')\n");
53 printf("Errors, warnings, ... are sent to stdout\n");
56 void gedcom_message_handler(Gedcom_msg_type type UNUSED, char *msg)
58 char *converted = NULL;
60 converted = convert_utf8_to_locale(msg, &conv_fails);
61 printf("%s\n", converted);
64 int main(int argc, char* argv[])
66 Gedcom_err_mech mech = DEFER_FAIL;
67 int compat_enabled = 1;
69 char* file_name = NULL;
71 char* extension = "new";
75 for (i=1; i<argc; i++) {
76 if (!strncmp(argv[i], "-da", 4))
78 else if (!strncmp(argv[i], "-dg", 4))
80 else if (!strncmp(argv[i], "-e", 3)) {
82 extension = argv[++i];
89 else if (!strncmp(argv[i], "-h", 3)) {
93 else if (strncmp(argv[i], "-", 1)) {
98 printf ("Unrecognized option: %s\n", argv[i]);
106 printf("No file name given\n");
112 setlocale(LC_ALL, "");
113 gedcom_set_debug_level(debug_level, NULL);
114 gedcom_set_compat_handling(compat_enabled);
115 gedcom_set_error_handling(mech);
116 gedcom_set_message_handler(gedcom_message_handler);
118 result = gom_parse_file(file_name);
121 char* newfile = (char*)malloc(strlen(file_name) + strlen(extension) + 2);
122 sprintf(newfile, "%s.%s", file_name, extension);
123 printf(_("Parse succeeded, now writing file '%s'\n"), newfile);
124 result = gom_write_file(newfile, NULL);
127 printf(_("Write succeeded\n"));
130 printf(_("Write failed\n"));
134 printf(_("Parse failed\n"));