New files: specifying the callback interface.
authorPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 8 Dec 2001 15:09:20 +0000 (15:09 +0000)
committerPeter Verthez <Peter.Verthez@advalvas.be>
Sat, 8 Dec 2001 15:09:20 +0000 (15:09 +0000)
interface.c [new file with mode: 0644]
interface.h [new file with mode: 0644]

diff --git a/interface.c b/interface.c
new file mode 100644 (file)
index 0000000..038a7d5
--- /dev/null
@@ -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 (file)
index 0000000..0840273
--- /dev/null
@@ -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 */