+/*
+ * 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)