Conversion from ANSEL to Unicode (iconv module).
[gedcom-parse.git] / standalone.c
1 /* $Id$ */
2 /* $Name$ */
3
4 #include "gedcom.h"
5 #include "multilex.h"
6
7 void show_help ()
8 {
9   printf("gedcom-parse test program for libgedcom\n\n");
10   printf("Usage:  gedcom-parse [options] file\n");
11   printf("Options:\n");
12   printf("  -h    Show this help text\n");
13   printf("  -nc   Disable compatibility mode\n");
14   printf("  -fi   Fail immediately on errors\n");
15   printf("  -fd   Deferred fail on errors, but parse completely\n");
16   printf("  -fn   No fail on errors\n");
17   printf("  -dg   Debug setting: only libgedcom debug messages\n");
18   printf("  -da   Debug setting: libgedcom + yacc debug messages\n");
19 }
20
21 int main(int argc, char* argv[])
22 {
23   MECHANISM mech = IMMED_FAIL;
24   int compat_enabled = 1;
25   int debug_level = 0;
26   char* file_name = NULL;
27
28   if (argc > 1) {
29     int i;
30     for (i=1; i<argc; i++) {
31       if (!strncmp(argv[i], "-da", 4))
32         debug_level = 2;
33       else if (!strncmp(argv[i], "-dg", 4))
34         debug_level = 1;
35       else if (!strncmp(argv[i], "-fi", 4))
36         mech = IMMED_FAIL;
37       else if (!strncmp(argv[i], "-fd", 4))
38         mech = DEFER_FAIL;
39       else if (!strncmp(argv[i], "-fn", 4))
40         mech = IGNORE_ERRORS;
41       else if (!strncmp(argv[i], "-nc", 4))
42         compat_enabled = 0;
43       else if (!strncmp(argv[i], "-h", 3)) {
44         show_help();
45         exit(1);
46       }
47       else if (strncmp(argv[i], "-", 1)) {
48         file_name = argv[i];
49         break;
50       }
51       else {
52         printf ("Unrecognized option: %s\n", argv[i]);
53         show_help();
54         exit(1);
55       }
56     }
57   }
58   
59   if (!file_name) {
60     printf("No file name given\n");
61     show_help();
62     exit(1);
63   }
64
65   gedcom_set_debug_level(debug_level);
66   gedcom_set_compat_handling(compat_enabled);
67   gedcom_set_error_handling(mech);
68   
69   if (gedcom_parse_file(file_name) == 0) {
70     printf("Parse succeeded\n");
71     return 0;
72   }
73   else {
74     printf("Parse failed\n");
75     return 1;
76   }  
77 }