Release 0.9
[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   printf("  -2    Run the test parse 2 times instead of once\n");
29   printf("  -3    Run the test parse 3 times instead of once\n");
30 }
31
32 int main(int argc, char* argv[])
33 {
34   MECHANISM mech = IMMED_FAIL;
35   int compat_enabled = 1;
36   int debug_level = 0;
37   int run_times   = 1;
38   int result      = 0;
39   char* file_name = NULL;
40
41   if (argc > 1) {
42     int i;
43     for (i=1; i<argc; i++) {
44       if (!strncmp(argv[i], "-da", 4))
45         debug_level = 2;
46       else if (!strncmp(argv[i], "-dg", 4))
47         debug_level = 1;
48       else if (!strncmp(argv[i], "-fi", 4))
49         mech = IMMED_FAIL;
50       else if (!strncmp(argv[i], "-fd", 4))
51         mech = DEFER_FAIL;
52       else if (!strncmp(argv[i], "-fn", 4))
53         mech = IGNORE_ERRORS;
54       else if (!strncmp(argv[i], "-nc", 4))
55         compat_enabled = 0;
56       else if (!strncmp(argv[i], "-h", 3)) {
57         show_help();
58         exit(1);
59       }
60       else if (!strncmp(argv[i], "-2", 3)) {
61         run_times = 2;
62       }
63       else if (!strncmp(argv[i], "-3", 3)) {
64         run_times = 3;
65       }
66       else if (strncmp(argv[i], "-", 1)) {
67         file_name = argv[i];
68         break;
69       }
70       else {
71         printf ("Unrecognized option: %s\n", argv[i]);
72         show_help();
73         exit(1);
74       }
75     }
76   }
77   
78   if (!file_name) {
79     printf("No file name given\n");
80     show_help();
81     exit(1);
82   }
83
84   gedcom_set_debug_level(debug_level);
85   gedcom_set_compat_handling(compat_enabled);
86   gedcom_set_error_handling(mech);
87
88   while (run_times-- > 0) {
89     result |= gedcom_parse_file(file_name);
90   }
91   if (result == 0) {
92     printf("Parse succeeded\n");
93     return 0;
94   }
95   else {
96     printf("Parse failed\n");
97     return 1;
98   }  
99 }