Attempt to fix bug in especs
[yaz-moved-to-github.git] / retrieval / d1_doespec.c
index 4a1e002..1f115b5 100644 (file)
@@ -4,7 +4,28 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: d1_doespec.c,v $
- * Revision 1.3  1995-11-13 09:27:33  quinn
+ * Revision 1.10  1997-10-02 12:10:24  quinn
+ * Attempt to fix bug in especs
+ *
+ * Revision 1.9  1997/09/17 12:10:35  adam
+ * YAZ version 1.4.
+ *
+ * Revision 1.8  1997/05/14 06:54:02  adam
+ * C++ support.
+ *
+ * Revision 1.7  1997/04/30 08:52:11  quinn
+ * Null
+ *
+ * Revision 1.6  1996/10/11  11:57:22  quinn
+ * Smallish
+ *
+ * Revision 1.5  1996/07/06  19:58:34  quinn
+ * System headerfiles gathered in yconfig
+ *
+ * Revision 1.4  1996/06/07  11:04:32  quinn
+ * Fixed tag->tagset dependency
+ *
+ * Revision 1.3  1995/11/13  09:27:33  quinn
  * Fiddling with the variant stuff.
  *
  * Revision 1.2  1995/11/01  13:54:45  quinn
@@ -36,7 +57,7 @@ static int match_children_wildpath(data1_node *n, Z_Espec1 *e, int i,
  * triple with an unknown set.
  */
 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
-    oid_value set, int class, int type)
+    oid_value set, int zclass, int type)
 {
     int i;
     oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
@@ -50,7 +71,7 @@ static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
        oid_value curset = cursetent ? cursetent->value : defaultset;
 
        if (set == curset &&
-           *var->triples[i]->class == class &&
+           *var->triples[i]->zclass == zclass &&
            *var->triples[i]->type == type)
            return var->triples[i];
     }
@@ -58,15 +79,26 @@ static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
 }
 
 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
-    Z_Variant *vreq)
+    int get_bytes, Z_Variant *vreq)
 {
     data1_node *c;
 
+#if 1
+    if (n->which == DATA1N_tag)
+#else
     if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
+    /*
+     * This seems to cause multi-level elements to fall out when only a
+     * top-level elementRequest has been given... Problem is, I can't figure
+     * out what it was supposed to ACHIEVE.... delete when code has been
+     * verified.
+     */
+#endif
     {
        n->u.tag.node_selected = 1;
        n->u.tag.make_variantlist = make_variantlist;
        n->u.tag.no_data_requested = no_data;
+       n->u.tag.get_bytes = get_bytes;
     }
 
     for (c = n->child; c; c = c->next)
@@ -77,8 +109,9 @@ static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
            c->u.tag.node_selected = 1;
            c->u.tag.make_variantlist = make_variantlist;
            c->u.tag.no_data_requested = no_data;
+           c->u.tag.get_bytes = get_bytes;
        }
-       mark_subtree(c, make_variantlist, no_data, vreq);
+       mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
     }
 }
 
@@ -103,7 +136,8 @@ static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
            occur = want->occurrences;
            if (c->u.tag.element)
                tag = c->u.tag.element->tag;
-           if (*want->tagType != (tag ? tag->tagset->type : 3))
+           if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
+               3))
                continue;
            if (want->tagValue->which == Z_StringOrNumeric_numeric)
            {
@@ -149,6 +183,8 @@ static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
                {
                    int show_variantlist = 0;
                    int no_data = 0;
+                   int get_bytes = -1;
+
                    Z_Variant *vreq =
                        e->elements[i]->u.simpleElement->variantRequest;
                    oident *defset = oid_getentbyoid(e->defaultVariantSetId);
@@ -160,6 +196,8 @@ static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
 
                    if (vreq)
                    {
+                       Z_Triple *r;
+
                        /*
                         * 6,5: meta-data requested, variant list.
                         */
@@ -170,16 +208,22 @@ static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
                         */
                        if (find_triple(vreq, defsetval, var1, 9, 1))
                            no_data = 1;
+
+                       /* howmuch */
+                       if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
+                           if (r->which == Z_Triple_integer)
+                               get_bytes = *r->value.integer;
                    }
-                   mark_subtree(c, show_variantlist, no_data, vreq);
+                   mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
                }
                hits++;
                /*
                 * have we looked at enough children?
                 */
                if (!occur || (occur->which == Z_Occurrences_values &&
+                   (!occur->u.values->howMany ||
                    counter - *occur->u.values->start >=
-                   *occur->u.values->howMany - 1))
+                   *occur->u.values->howMany - 1)))
                    return hits;
            }
        }
@@ -207,7 +251,7 @@ static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
     return res;
 }
 
-int data1_doespec1(data1_node *n, Z_Espec1 *e)
+int data1_doespec1 (data1_handle dh, data1_node *n, Z_Espec1 *e)
 {
     int i;