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. *
6 (C) 2001 by The Genes Development Team
7 Original author: Peter Verthez (Peter.Verthez@advalvas.be)
20 printf("gedcom-parse test program for libgedcom\n\n");
21 printf("Usage: gedcom-parse [options] file\n");
23 printf(" -h Show this help text\n");
24 printf(" -nc Disable compatibility mode\n");
25 printf(" -fi Fail immediately on errors\n");
26 printf(" -fd Deferred fail on errors, but parse completely\n");
27 printf(" -fn No fail on errors\n");
28 printf(" -dg Debug setting: only libgedcom debug messages\n");
29 printf(" -da Debug setting: libgedcom + yacc debug messages\n");
30 printf(" -2 Run the test parse 2 times instead of once\n");
31 printf(" -3 Run the test parse 3 times instead of once\n");
34 Gedcom_ctxt header_start(char *xreftag __attribute__ ((unused)))
36 printf("Header start\n");
37 return (Gedcom_ctxt)0;
40 void header_end(Gedcom_ctxt self)
42 printf("Header end, context is %d\n", (int)self);
45 char family_xreftags[100][255];
48 Gedcom_ctxt family_start(char *xreftag)
50 printf("Family start, xreftag is %s\n", xreftag);
51 strcpy(family_xreftags[family_nr], xreftag);
52 return (Gedcom_ctxt)(family_nr++);
55 void family_end(Gedcom_ctxt self)
57 printf("Family end, xreftag is %s\n", family_xreftags[(int)self]);
60 void subscribe_callbacks()
62 subscribe_to_record(REC_HEAD, header_start, header_end);
63 subscribe_to_record(REC_FAM, family_start, family_end);
66 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
69 fprintf(stderr, "MESSAGE: ");
70 else if (type == WARNING)
71 fprintf(stderr, "WARNING: ");
72 else if (type == ERROR)
73 fprintf(stderr, "ERROR: ");
77 int main(int argc, char* argv[])
79 Gedcom_err_mech mech = IMMED_FAIL;
80 int compat_enabled = 1;
84 char* file_name = NULL;
88 for (i=1; i<argc; i++) {
89 if (!strncmp(argv[i], "-da", 4))
91 else if (!strncmp(argv[i], "-dg", 4))
93 else if (!strncmp(argv[i], "-fi", 4))
95 else if (!strncmp(argv[i], "-fd", 4))
97 else if (!strncmp(argv[i], "-fn", 4))
99 else if (!strncmp(argv[i], "-nc", 4))
101 else if (!strncmp(argv[i], "-h", 3)) {
105 else if (!strncmp(argv[i], "-2", 3)) {
108 else if (!strncmp(argv[i], "-3", 3)) {
111 else if (strncmp(argv[i], "-", 1)) {
116 printf ("Unrecognized option: %s\n", argv[i]);
124 printf("No file name given\n");
129 gedcom_set_debug_level(debug_level, NULL);
130 gedcom_set_compat_handling(compat_enabled);
131 gedcom_set_error_handling(mech);
132 gedcom_set_message_handler(gedcom_message_handler);
134 subscribe_callbacks();
135 while (run_times-- > 0) {
136 result |= gedcom_parse_file(file_name);
139 printf("Parse succeeded\n");
143 printf("Parse failed\n");