2 * Copyright (c) 1995, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_doespec.c,v $
7 * Revision 1.11 1997-11-06 11:36:44 adam
8 * Implemented variant match on simple elements -data1 tree and Espec-1.
10 * Revision 1.10 1997/10/02 12:10:24 quinn
11 * Attempt to fix bug in especs
13 * Revision 1.9 1997/09/17 12:10:35 adam
16 * Revision 1.8 1997/05/14 06:54:02 adam
19 * Revision 1.7 1997/04/30 08:52:11 quinn
22 * Revision 1.6 1996/10/11 11:57:22 quinn
25 * Revision 1.5 1996/07/06 19:58:34 quinn
26 * System headerfiles gathered in yconfig
28 * Revision 1.4 1996/06/07 11:04:32 quinn
29 * Fixed tag->tagset dependency
31 * Revision 1.3 1995/11/13 09:27:33 quinn
32 * Fiddling with the variant stuff.
34 * Revision 1.2 1995/11/01 13:54:45 quinn
37 * Revision 1.1 1995/11/01 11:56:07 quinn
38 * Added Retrieval (data management) functions en masse.
50 static int match_children(data1_handle dh, data1_node *n,
51 Z_Espec1 *e, int i, Z_ETagUnit **t,
54 static int match_children_wildpath(data1_handle dh, data1_node *n,
56 Z_ETagUnit **t, int num)
62 * Locate a specific triple within a variant.
63 * set is the set to look for, universal set is the set that applies to a
64 * triple with an unknown set.
66 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
67 oid_value set, int zclass, int type)
70 oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
71 oid_value defaultset = defaultsetent ? defaultsetent->value :
74 for (i = 0; i < var->num_triples; i++)
77 oid_getentbyoid(var->triples[i]->variantSetId);
78 oid_value curset = cursetent ? cursetent->value : defaultset;
81 *var->triples[i]->zclass == zclass &&
82 *var->triples[i]->type == type)
83 return var->triples[i];
88 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
89 int get_bytes, Z_Variant *vreq)
94 if (n->which == DATA1N_tag)
96 if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
98 * This seems to cause multi-level elements to fall out when only a
99 * top-level elementRequest has been given... Problem is, I can't figure
100 * out what it was supposed to ACHIEVE.... delete when code has been
105 n->u.tag.node_selected = 1;
106 n->u.tag.make_variantlist = make_variantlist;
107 n->u.tag.no_data_requested = no_data;
108 n->u.tag.get_bytes = get_bytes;
111 for (c = n->child; c; c = c->next)
113 if (c->which == DATA1N_tag && (!n->child ||
114 n->child->which != DATA1N_tag))
116 c->u.tag.node_selected = 1;
117 c->u.tag.make_variantlist = make_variantlist;
118 c->u.tag.no_data_requested = no_data;
119 c->u.tag.get_bytes = get_bytes;
121 mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
126 static void match_triple (data1_handle dh, Z_Variant *vreq,
128 oid_value var1, data1_node *n)
133 if (n->which != DATA1N_variant)
141 assert ((*c)->which == DATA1N_variant);
143 if ((*c)->u.variant.type->zclass->zclass == 4 &&
144 (*c)->u.variant.type->type == 1)
146 if ((r = find_triple(vreq, defsetval, var1, 4, 1)) &&
147 (r->which == Z_Triple_internationalString))
149 const char *string_value =
150 r->value.internationalString;
151 if (strcmp ((*c)->u.variant.value, string_value))
157 data1_free_tree (dh, *c);
162 match_triple (dh, vreq, defsetval, var1, *c);
168 static int match_children_here (data1_handle dh, data1_node *n,
170 Z_ETagUnit **t, int num)
172 int counter = 0, hits = 0;
175 Z_Occurrences *occur;
177 for (c = n->child; c ; c = c->next)
180 if (c->which != DATA1N_tag)
183 if (tp->which == Z_ETagUnit_specificTag)
185 Z_SpecificTag *want = tp->u.specificTag;
186 occur = want->occurrences;
187 if (c->u.tag.element)
188 tag = c->u.tag.element->tag;
189 if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
192 if (want->tagValue->which == Z_StringOrNumeric_numeric)
194 if (!tag || tag->which != DATA1T_numeric)
196 if (*want->tagValue->u.numeric != tag->value.numeric)
201 assert(want->tagValue->which == Z_StringOrNumeric_string);
202 if (tag && tag->which != DATA1T_string)
204 if (data1_matchstr(want->tagValue->u.string,
205 tag ? tag->value.string : c->u.tag.tag))
210 occur = tp->u.wildThing;
213 * Ok, so we have a matching tag. Are we within occurrences-range?
216 if (occur && occur->which == Z_Occurrences_last)
218 logf(LOG_WARN, "Can't do occurrences=last (yet)");
221 if (!occur || occur->which == Z_Occurrences_all ||
222 (occur->which == Z_Occurrences_values && counter >=
223 *occur->u.values->start))
225 if (match_children(dh, c, e, i, t + 1, num - 1))
227 c->u.tag.node_selected = 1;
229 * Consider the variant specification if this is a complete
234 int show_variantlist = 0;
239 e->elements[i]->u.simpleElement->variantRequest;
240 oident *defset = oid_getentbyoid(e->defaultVariantSetId);
241 oid_value defsetval = defset ? defset->value : VAL_NONE;
242 oid_value var1 = oid_getvalbyname("Variant-1");
245 vreq = e->defaultVariantRequest;
252 * 6,5: meta-data requested, variant list.
254 if (find_triple(vreq, defsetval, var1, 6, 5))
255 show_variantlist = 1;
257 * 9,1: Miscellaneous, no data requested.
259 if (find_triple(vreq, defsetval, var1, 9, 1))
263 if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
264 if (r->which == Z_Triple_integer)
265 get_bytes = *r->value.integer;
267 if (!show_variantlist)
268 match_triple (dh, vreq, defsetval, var1, c);
270 mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
274 * have we looked at enough children?
276 if (!occur || (occur->which == Z_Occurrences_values &&
277 (!occur->u.values->howMany ||
278 counter - *occur->u.values->start >=
279 *occur->u.values->howMany - 1)))
287 static int match_children(data1_handle dh, data1_node *n, Z_Espec1 *e,
288 int i, Z_ETagUnit **t, int num)
296 case Z_ETagUnit_wildThing:
297 case Z_ETagUnit_specificTag:
298 res = match_children_here(dh, n, e, i, t, num); break;
299 case Z_ETagUnit_wildPath:
300 res = match_children_wildpath(dh, n, e, i, t, num); break;
307 int data1_doespec1 (data1_handle dh, data1_node *n, Z_Espec1 *e)
311 for (i = 0; i < e->num_elements; i++)
313 if (e->elements[i]->which != Z_ERequest_simpleElement)
315 match_children(dh, n, e, i,
316 e->elements[i]->u.simpleElement->path->tags,
317 e->elements[i]->u.simpleElement->path->num_tags);