From: Peter Verthez Date: Sat, 8 Dec 2001 15:09:20 +0000 (+0000) Subject: New files: specifying the callback interface. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=68d7bc9d02cd738c2c56ba93c502e63e2b231dc8;p=gedcom-parse.git New files: specifying the callback interface. --- diff --git a/interface.c b/interface.c new file mode 100644 index 0000000..038a7d5 --- /dev/null +++ b/interface.c @@ -0,0 +1,48 @@ +#include "interface.h" + +Gedcom_rec_start_cb record_start_callback[] = + { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + +Gedcom_rec_end_cb record_end_callback[] = + { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + + +void subscribe_to_record(Gedcom_rec rec, + Gedcom_rec_start_cb cb_start, + Gedcom_rec_end_cb cb_end) +{ + record_start_callback[rec] = cb_start; + record_end_callback[rec] = cb_end; +} + +Gedcom_ctxt start_record(Gedcom_rec rec, char *xreftag) +{ + Gedcom_rec_start_cb cb = record_start_callback[rec]; + if (cb != NULL) + return (*cb)(xreftag); + else + return NULL; +} + +void end_record(Gedcom_rec rec, Gedcom_ctxt self) +{ + Gedcom_rec_end_cb cb = record_end_callback[rec]; + if (cb != NULL) + (*cb)(self); +} + +Gedcom_ctxt start_element(Gedcom_elt elt, Gedcom_ctxt parent, + int level, char *tag, char *raw_value, + void *parsed_value) +{ + printf("Start of element %d, parent context is %d\n", elt, (int)parent); + printf(" value is: %d %s %s\n", level, tag, raw_value); + return (Gedcom_ctxt)(elt+100); +} + +void end_element(Gedcom_ctxt parent, Gedcom_ctxt self) +{ + printf("End of element, context is %d, parent context is %d\n", + (int)self, (int)parent); +} + diff --git a/interface.h b/interface.h new file mode 100644 index 0000000..0840273 --- /dev/null +++ b/interface.h @@ -0,0 +1,16 @@ +#ifndef __INTERFACE_H +#define __INTERFACE_H + +#include "gedcom.h" +#include "external.h" + +Gedcom_ctxt start_record(Gedcom_rec rec, char *xreftag); +void end_record(Gedcom_rec rec, Gedcom_ctxt self); + +Gedcom_ctxt start_element(Gedcom_elt elt, Gedcom_ctxt parent, + int level, char *tag, char *raw_value, + void *parsed_value); +void end_element(Gedcom_ctxt parent, Gedcom_ctxt self); + + +#endif /* __INTERFACE_H */