/*
- * Copyright (c) 1995, Index Data.
+ * Copyright (c) 1995-1999, Index Data.
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: d1_doespec.c,v $
- * Revision 1.1 1995-11-01 11:56:07 quinn
+ * Revision 1.14 1999-11-30 13:47:12 adam
+ * Improved installation. Moved header files to include/yaz.
+ *
+ * Revision 1.13 1999/08/27 09:40:32 adam
+ * Renamed logf function to yaz_log. Removed VC++ project files.
+ *
+ * Revision 1.12 1999/04/23 13:34:33 adam
+ * Fixed bug in match_triple. Thanks to Franck Falcoz <franck@dtv.dk>.
+ *
+ * Revision 1.11 1997/11/06 11:36:44 adam
+ * Implemented variant match on simple elements -data1 tree and Espec-1.
+ *
+ * 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
+ * Minor adjustments
+ *
+ * Revision 1.1 1995/11/01 11:56:07 quinn
* Added Retrieval (data management) functions en masse.
*
*
#include <assert.h>
-#include <log.h>
-#include <proto.h>
-#include "data1.h"
-static int match_children(data1_node *n, Z_ETagUnit **t, int num);
+#include <yaz/oid.h>
+#include <yaz/log.h>
+#include <yaz/proto.h>
+#include <yaz/data1.h>
-static int match_children_wildpath(data1_node *n, Z_ETagUnit **t, int num)
-{return 0;}
+static int match_children(data1_handle dh, data1_node *n,
+ Z_Espec1 *e, int i, Z_ETagUnit **t,
+ int num);
+
+static int match_children_wildpath(data1_handle dh, data1_node *n,
+ Z_Espec1 *e, int i,
+ Z_ETagUnit **t, int num)
+{
+ return 0;
+}
-static int match_children_here(data1_node *n, Z_ETagUnit **t, int num)
+/*
+ * Locate a specific triple within a variant.
+ * set is the set to look for, universal set is the set that applies to a
+ * triple with an unknown set.
+ */
+static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
+ oid_value set, int zclass, int type)
+{
+ int i;
+ oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
+ oid_value defaultset = defaultsetent ? defaultsetent->value :
+ universalset;
+
+ for (i = 0; i < var->num_triples; i++)
+ {
+ oident *cursetent =
+ oid_getentbyoid(var->triples[i]->variantSetId);
+ oid_value curset = cursetent ? cursetent->value : defaultset;
+
+ if (set == curset &&
+ *var->triples[i]->zclass == zclass &&
+ *var->triples[i]->type == type)
+ return var->triples[i];
+ }
+ return 0;
+}
+
+static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
+ 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)
+ {
+ if (c->which == DATA1N_tag && (!n->child ||
+ n->child->which != DATA1N_tag))
+ {
+ 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, get_bytes, vreq);
+ }
+}
+
+
+static void match_triple (data1_handle dh, Z_Variant *vreq,
+ oid_value defsetval,
+ oid_value var1, data1_node *n)
+{
+ data1_node **c;
+
+ if (!(n = n->child))
+ return;
+ if (n->which != DATA1N_variant)
+ return;
+ c = &n->child;
+ while (*c)
+ {
+ int remove_flag = 0;
+ Z_Triple *r;
+
+ assert ((*c)->which == DATA1N_variant);
+
+ if ((*c)->u.variant.type->zclass->zclass == 4 &&
+ (*c)->u.variant.type->type == 1)
+ {
+ if ((r = find_triple(vreq, defsetval, var1, 4, 1)) &&
+ (r->which == Z_Triple_internationalString))
+ {
+ const char *string_value =
+ r->value.internationalString;
+ if (strcmp ((*c)->u.variant.value, string_value))
+ remove_flag = 1;
+ }
+ }
+ if (remove_flag)
+ {
+ data1_free_tree (dh, *c);
+ *c = (*c)->next;
+ }
+ else
+ {
+ match_triple (dh, vreq, defsetval, var1, *c);
+ c = &(*c)->next;
+ }
+ }
+}
+
+static int match_children_here (data1_handle dh, data1_node *n,
+ Z_Espec1 *e, int i,
+ Z_ETagUnit **t, int num)
{
int counter = 0, hits = 0;
data1_node *c;
for (c = n->child; c ; c = c->next)
{
data1_tag *tag = 0;
-
if (c->which != DATA1N_tag)
return 0;
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)
{
counter++;
if (occur && occur->which == Z_Occurrences_last)
{
- logf(LOG_WARN, "Can't do occurrences=last (yet)");
+ yaz_log(LOG_WARN, "Can't do occurrences=last (yet)");
return 0;
}
if (!occur || occur->which == Z_Occurrences_all ||
(occur->which == Z_Occurrences_values && counter >=
*occur->u.values->start))
{
- if (match_children(c, t + 1, num - 1))
+ if (match_children(dh, c, e, i, t + 1, num - 1))
{
c->u.tag.node_selected = 1;
+ /*
+ * Consider the variant specification if this is a complete
+ * match.
+ */
+ if (num == 1)
+ {
+ 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);
+ oid_value defsetval = defset ? defset->value : VAL_NONE;
+ oid_value var1 = oid_getvalbyname("Variant-1");
+
+ if (!vreq)
+ vreq = e->defaultVariantRequest;
+
+ if (vreq)
+ {
+ Z_Triple *r;
+
+ /*
+ * 6,5: meta-data requested, variant list.
+ */
+ if (find_triple(vreq, defsetval, var1, 6, 5))
+ show_variantlist = 1;
+ /*
+ * 9,1: Miscellaneous, no data requested.
+ */
+ 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;
+
+ if (!show_variantlist)
+ match_triple (dh, vreq, defsetval, var1, c);
+ }
+ 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;
}
}
return hits;
}
-static void mark_children(data1_node *n)
+static int match_children(data1_handle dh, data1_node *n, Z_Espec1 *e,
+ int i, Z_ETagUnit **t, int num)
{
- data1_node *c;
+ int res;
- for (c = n->child; c; c = c->next)
- {
- if (c->which != DATA1N_tag)
- continue;
- c->u.tag.node_selected = 1;
- mark_children(c);
- }
-}
-
-static int match_children(data1_node *n, Z_ETagUnit **t, int num)
-{
if (!num)
- {
- mark_children(n); /* Here there shall be variants, like, dude */
return 1;
- }
switch (t[0]->which)
{
case Z_ETagUnit_wildThing:
- case Z_ETagUnit_specificTag: return match_children_here(n, t, num);
- case Z_ETagUnit_wildPath: return match_children_wildpath(n, t, num);
+ case Z_ETagUnit_specificTag:
+ res = match_children_here(dh, n, e, i, t, num); break;
+ case Z_ETagUnit_wildPath:
+ res = match_children_wildpath(dh, n, e, i, t, num); break;
default:
abort();
}
+ 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;
for (i = 0; i < e->num_elements; i++)
- match_children(n, e->elements[i]->u.simpleElement->path->tags,
- e->elements[i]->u.simpleElement->path->num_tags);
+ {
+ if (e->elements[i]->which != Z_ERequest_simpleElement)
+ return 100;
+ match_children(dh, n, e, i,
+ e->elements[i]->u.simpleElement->path->tags,
+ e->elements[i]->u.simpleElement->path->num_tags);
+ }
return 0;
}