Implemented loadable filters.
[idzebra-moved-to-github.git] / recctrl / danbibr.c
index 1235f87..f01a94d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: danbibr.c,v 1.3 2004-05-26 13:26:17 adam Exp $
+/* $Id: danbibr.c,v 1.5 2004-09-27 10:44:50 adam Exp $
    Copyright (C) 2004
    Index Data Aps
 
@@ -39,7 +39,7 @@ struct danbibr_info {
     char read_buf[READ_CHUNK+1];  /* space for \0 */
 };
 
-static void *grs_init_danbib(void)
+static void *init_danbib(Res res, RecType rt)
 {
     struct danbibr_info *p = (struct danbibr_info *) xmalloc (sizeof(*p));
 
@@ -84,13 +84,12 @@ static int read_rec(struct grs_read_info *p)
 static data1_node *mk_tree(struct grs_read_info *p, const char *rec_buf)
 {
     data1_node *root = data1_mk_root(p->dh, p->mem, "danbib");
+    data1_node *root_tag = data1_mk_tag(p->dh, p->mem, "danbib", 0, root);
     const char *cp = rec_buf;
 
-    root = data1_mk_tag(p->dh, p->mem, "danbib", 0, root);
-
     if (1)  /* <text> all </text> */
     {
-       data1_node *text_node = data1_mk_tag(p->dh, p->mem, "text", 0, root);
+       data1_node *text_node = data1_mk_tag(p->dh, p->mem, "text", 0, root_tag);
        data1_mk_text_n(p->dh, p->mem, rec_buf, strlen(rec_buf), text_node);
     }
     while (*cp)
@@ -121,7 +120,7 @@ static data1_node *mk_tree(struct grs_read_info *p, const char *rec_buf)
                        data1_node *hnode;
                        sprintf(elemstr, "head%d", no);
 
-                       hnode = data1_mk_tag(p->dh, p->mem, elemstr, 0, root);
+                       hnode = data1_mk_tag(p->dh, p->mem, elemstr, 0, root_tag);
                        data1_mk_text_n(p->dh, p->mem, start_text,
                                        cp - start_text, hnode);
                        start_text = cp+1;
@@ -137,7 +136,7 @@ static data1_node *mk_tree(struct grs_read_info *p, const char *rec_buf)
            {
                data1_node *tag_node =
                    data1_mk_tag_n(p->dh, p->mem,
-                                  start_tag, cp - start_tag, 0, root);
+                                  start_tag, cp - start_tag, 0, root_tag);
                cp++;
                start_text = cp;
                while (*cp != '\n' && *cp)
@@ -189,7 +188,7 @@ static data1_node *mk_tree(struct grs_read_info *p, const char *rec_buf)
     return root;
 }
 
-static data1_node *grs_read_danbib (struct grs_read_info *p)
+static data1_node *read_danbib (struct grs_read_info *p)
 {
     struct danbibr_info *info = p->clientData;
 
@@ -198,7 +197,7 @@ static data1_node *grs_read_danbib (struct grs_read_info *p)
     return 0;
 }
 
-static void grs_destroy_danbib(void *clientData)
+static void destroy_danbib(void *clientData)
 {
     struct danbibr_info *p = (struct danbibr_info *) clientData;
 
@@ -206,12 +205,37 @@ static void grs_destroy_danbib(void *clientData)
     xfree (p);
 }
 
-static struct recTypeGrs danbib_type = {
-    "danbib",
-    grs_init_danbib,
-    grs_destroy_danbib,
-    grs_read_danbib
+
+static int extract_danbib(void *clientData, struct recExtractCtrl *ctrl)
+{
+    return zebra_grs_extract(clientData, ctrl, read_danbib);
+}
+
+static int retrieve_danbib(void *clientData, struct recRetrieveCtrl *ctrl)
+{
+    return zebra_grs_retrieve(clientData, ctrl, read_danbib);
+}
+
+static struct recType danbib_type = {
+    "grs.danbib",
+    init_danbib,
+    0,
+    destroy_danbib,
+    extract_danbib,
+    retrieve_danbib,
+};
+
+RecType
+#ifdef IDZEBRA_STATIC_GRS_DANBIB
+idzebra_filter_grs_danbib
+#else
+idzebra_filter
+#endif
+
+[] = {
+    &danbib_type,
+    0,
 };
+    
 
-RecTypeGrs recTypeGrs_danbib = &danbib_type;