Added proper copyright notice.
[gedcom-parse.git] / standalone.c
1 /*  This program is free software; you can redistribute it and/or modify  *
2  *  it under the terms of the GNU General Public License as published by  *
3  *  the Free Software Foundation; either version 2 of the License, or     *
4  *  (at your option) any later version.                                   *
5
6  (C) 2001 by The Genes Development Team
7  Original author: Peter Verthez (Peter.Verthez@advalvas.be)
8 */
9
10 /* $Id$ */
11 /* $Name$ */
12
13 #include "gedcom.h"
14 #include "multilex.h"
15
16 void show_help ()
17 {
18   printf("gedcom-parse test program for libgedcom\n\n");
19   printf("Usage:  gedcom-parse [options] file\n");
20   printf("Options:\n");
21   printf("  -h    Show this help text\n");
22   printf("  -nc   Disable compatibility mode\n");
23   printf("  -fi   Fail immediately on errors\n");
24   printf("  -fd   Deferred fail on errors, but parse completely\n");
25   printf("  -fn   No fail on errors\n");
26   printf("  -dg   Debug setting: only libgedcom debug messages\n");
27   printf("  -da   Debug setting: libgedcom + yacc debug messages\n");
28 }
29
30 int main(int argc, char* argv[])
31 {
32   MECHANISM mech = IMMED_FAIL;
33   int compat_enabled = 1;
34   int debug_level = 0;
35   char* file_name = NULL;
36
37   if (argc > 1) {
38     int i;
39     for (i=1; i<argc; i++) {
40       if (!strncmp(argv[i], "-da", 4))
41         debug_level = 2;
42       else if (!strncmp(argv[i], "-dg", 4))
43         debug_level = 1;
44       else if (!strncmp(argv[i], "-fi", 4))
45         mech = IMMED_FAIL;
46       else if (!strncmp(argv[i], "-fd", 4))
47         mech = DEFER_FAIL;
48       else if (!strncmp(argv[i], "-fn", 4))
49         mech = IGNORE_ERRORS;
50       else if (!strncmp(argv[i], "-nc", 4))
51         compat_enabled = 0;
52       else if (!strncmp(argv[i], "-h", 3)) {
53         show_help();
54         exit(1);
55       }
56       else if (strncmp(argv[i], "-", 1)) {
57         file_name = argv[i];
58         break;
59       }
60       else {
61         printf ("Unrecognized option: %s\n", argv[i]);
62         show_help();
63         exit(1);
64       }
65     }
66   }
67   
68   if (!file_name) {
69     printf("No file name given\n");
70     show_help();
71     exit(1);
72   }
73
74   gedcom_set_debug_level(debug_level);
75   gedcom_set_compat_handling(compat_enabled);
76   gedcom_set_error_handling(mech);
77   
78   if (gedcom_parse_file(file_name) == 0) {
79     printf("Parse succeeded\n");
80     return 0;
81   }
82   else {
83     printf("Parse failed\n");
84     return 1;
85   }  
86 }