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(int level, char *xref, char *tag)
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(int level, char *xref, char *tag)
50 printf("Family start, xref is %s\n", xref);
51 strcpy(family_xreftags[family_nr], xref);
52 return (Gedcom_ctxt)(family_nr++);
55 void family_end(Gedcom_ctxt self)
57 printf("Family end, xref is %s\n", family_xreftags[(int)self]);
60 Gedcom_ctxt submit_start(int level, char *xref, char *tag)
62 printf("Submitter, xref is %s\n", xref);
63 return (Gedcom_ctxt)10000;
66 Gedcom_ctxt source_start(Gedcom_ctxt parent, int level, char *tag,
67 char* raw_value, Gedcom_val parsed_value)
69 Gedcom_ctxt self = (Gedcom_ctxt)((int) parent + 1000);
70 printf("Source is %s (ctxt is %d, parent is %d)\n",
71 (char*)parsed_value, (int) self, (int) parent);
75 void source_end(Gedcom_ctxt parent, Gedcom_ctxt self, Gedcom_val parsed_value)
77 printf("Source context %d in parent %d\n", (int)self, (int)parent);
80 void default_cb(Gedcom_ctxt ctxt, int level, char *tag, char *raw_value)
82 printf("== %d %s %s (ctxt is %d)\n", level, tag, raw_value, (int)ctxt);
85 void subscribe_callbacks()
87 gedcom_subscribe_to_record(REC_HEAD, header_start, header_end);
88 gedcom_subscribe_to_record(REC_FAM, family_start, family_end);
89 gedcom_subscribe_to_record(REC_SUBM, submit_start, NULL);
90 gedcom_subscribe_to_element(ELT_HEAD_SOUR, source_start, source_end);
93 void gedcom_message_handler(Gedcom_msg_type type, char *msg)
96 fprintf(stderr, "MESSAGE: ");
97 else if (type == WARNING)
98 fprintf(stderr, "WARNING: ");
99 else if (type == ERROR)
100 fprintf(stderr, "ERROR: ");
101 fprintf(stderr, msg);
104 int main(int argc, char* argv[])
106 Gedcom_err_mech mech = IMMED_FAIL;
107 int compat_enabled = 1;
111 char* file_name = NULL;
115 for (i=1; i<argc; i++) {
116 if (!strncmp(argv[i], "-da", 4))
118 else if (!strncmp(argv[i], "-dg", 4))
120 else if (!strncmp(argv[i], "-fi", 4))
122 else if (!strncmp(argv[i], "-fd", 4))
124 else if (!strncmp(argv[i], "-fn", 4))
125 mech = IGNORE_ERRORS;
126 else if (!strncmp(argv[i], "-nc", 4))
128 else if (!strncmp(argv[i], "-h", 3)) {
132 else if (!strncmp(argv[i], "-2", 3)) {
135 else if (!strncmp(argv[i], "-3", 3)) {
138 else if (strncmp(argv[i], "-", 1)) {
143 printf ("Unrecognized option: %s\n", argv[i]);
151 printf("No file name given\n");
156 gedcom_set_debug_level(debug_level, NULL);
157 gedcom_set_compat_handling(compat_enabled);
158 gedcom_set_error_handling(mech);
159 gedcom_set_message_handler(gedcom_message_handler);
160 gedcom_set_default_callback(default_cb);
162 subscribe_callbacks();
163 while (run_times-- > 0) {
164 result |= gedcom_parse_file(file_name);
167 printf("Parse succeeded\n");
171 printf("Parse failed\n");