2 * Copyright (c) 1995-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: d1_doespec.c,v $
7 * Revision 1.12 1999-04-23 13:34:33 adam
8 * Fixed bug in match_triple. Thanks to Franck Falcoz <franck@dtv.dk>.
10 * Revision 1.11 1997/11/06 11:36:44 adam
11 * Implemented variant match on simple elements -data1 tree and Espec-1.
13 * Revision 1.10 1997/10/02 12:10:24 quinn
14 * Attempt to fix bug in especs
16 * Revision 1.9 1997/09/17 12:10:35 adam
19 * Revision 1.8 1997/05/14 06:54:02 adam
22 * Revision 1.7 1997/04/30 08:52:11 quinn
25 * Revision 1.6 1996/10/11 11:57:22 quinn
28 * Revision 1.5 1996/07/06 19:58:34 quinn
29 * System headerfiles gathered in yconfig
31 * Revision 1.4 1996/06/07 11:04:32 quinn
32 * Fixed tag->tagset dependency
34 * Revision 1.3 1995/11/13 09:27:33 quinn
35 * Fiddling with the variant stuff.
37 * Revision 1.2 1995/11/01 13:54:45 quinn
40 * Revision 1.1 1995/11/01 11:56:07 quinn
41 * Added Retrieval (data management) functions en masse.
53 static int match_children(data1_handle dh, data1_node *n,
54 Z_Espec1 *e, int i, Z_ETagUnit **t,
57 static int match_children_wildpath(data1_handle dh, data1_node *n,
59 Z_ETagUnit **t, int num)
65 * Locate a specific triple within a variant.
66 * set is the set to look for, universal set is the set that applies to a
67 * triple with an unknown set.
69 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
70 oid_value set, int zclass, int type)
73 oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
74 oid_value defaultset = defaultsetent ? defaultsetent->value :
77 for (i = 0; i < var->num_triples; i++)
80 oid_getentbyoid(var->triples[i]->variantSetId);
81 oid_value curset = cursetent ? cursetent->value : defaultset;
84 *var->triples[i]->zclass == zclass &&
85 *var->triples[i]->type == type)
86 return var->triples[i];
91 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
92 int get_bytes, Z_Variant *vreq)
97 if (n->which == DATA1N_tag)
99 if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
101 * This seems to cause multi-level elements to fall out when only a
102 * top-level elementRequest has been given... Problem is, I can't figure
103 * out what it was supposed to ACHIEVE.... delete when code has been
108 n->u.tag.node_selected = 1;
109 n->u.tag.make_variantlist = make_variantlist;
110 n->u.tag.no_data_requested = no_data;
111 n->u.tag.get_bytes = get_bytes;
114 for (c = n->child; c; c = c->next)
116 if (c->which == DATA1N_tag && (!n->child ||
117 n->child->which != DATA1N_tag))
119 c->u.tag.node_selected = 1;
120 c->u.tag.make_variantlist = make_variantlist;
121 c->u.tag.no_data_requested = no_data;
122 c->u.tag.get_bytes = get_bytes;
124 mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
129 static void match_triple (data1_handle dh, Z_Variant *vreq,
131 oid_value var1, data1_node *n)
137 if (n->which != DATA1N_variant)
145 assert ((*c)->which == DATA1N_variant);
147 if ((*c)->u.variant.type->zclass->zclass == 4 &&
148 (*c)->u.variant.type->type == 1)
150 if ((r = find_triple(vreq, defsetval, var1, 4, 1)) &&
151 (r->which == Z_Triple_internationalString))
153 const char *string_value =
154 r->value.internationalString;
155 if (strcmp ((*c)->u.variant.value, string_value))
161 data1_free_tree (dh, *c);
166 match_triple (dh, vreq, defsetval, var1, *c);
172 static int match_children_here (data1_handle dh, data1_node *n,
174 Z_ETagUnit **t, int num)
176 int counter = 0, hits = 0;
179 Z_Occurrences *occur;
181 for (c = n->child; c ; c = c->next)
184 if (c->which != DATA1N_tag)
187 if (tp->which == Z_ETagUnit_specificTag)
189 Z_SpecificTag *want = tp->u.specificTag;
190 occur = want->occurrences;
191 if (c->u.tag.element)
192 tag = c->u.tag.element->tag;
193 if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
196 if (want->tagValue->which == Z_StringOrNumeric_numeric)
198 if (!tag || tag->which != DATA1T_numeric)
200 if (*want->tagValue->u.numeric != tag->value.numeric)
205 assert(want->tagValue->which == Z_StringOrNumeric_string);
206 if (tag && tag->which != DATA1T_string)
208 if (data1_matchstr(want->tagValue->u.string,
209 tag ? tag->value.string : c->u.tag.tag))
214 occur = tp->u.wildThing;
217 * Ok, so we have a matching tag. Are we within occurrences-range?
220 if (occur && occur->which == Z_Occurrences_last)
222 logf(LOG_WARN, "Can't do occurrences=last (yet)");
225 if (!occur || occur->which == Z_Occurrences_all ||
226 (occur->which == Z_Occurrences_values && counter >=
227 *occur->u.values->start))
229 if (match_children(dh, c, e, i, t + 1, num - 1))
231 c->u.tag.node_selected = 1;
233 * Consider the variant specification if this is a complete
238 int show_variantlist = 0;
243 e->elements[i]->u.simpleElement->variantRequest;
244 oident *defset = oid_getentbyoid(e->defaultVariantSetId);
245 oid_value defsetval = defset ? defset->value : VAL_NONE;
246 oid_value var1 = oid_getvalbyname("Variant-1");
249 vreq = e->defaultVariantRequest;
256 * 6,5: meta-data requested, variant list.
258 if (find_triple(vreq, defsetval, var1, 6, 5))
259 show_variantlist = 1;
261 * 9,1: Miscellaneous, no data requested.
263 if (find_triple(vreq, defsetval, var1, 9, 1))
267 if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
268 if (r->which == Z_Triple_integer)
269 get_bytes = *r->value.integer;
271 if (!show_variantlist)
272 match_triple (dh, vreq, defsetval, var1, c);
274 mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
278 * have we looked at enough children?
280 if (!occur || (occur->which == Z_Occurrences_values &&
281 (!occur->u.values->howMany ||
282 counter - *occur->u.values->start >=
283 *occur->u.values->howMany - 1)))
291 static int match_children(data1_handle dh, data1_node *n, Z_Espec1 *e,
292 int i, Z_ETagUnit **t, int num)
300 case Z_ETagUnit_wildThing:
301 case Z_ETagUnit_specificTag:
302 res = match_children_here(dh, n, e, i, t, num); break;
303 case Z_ETagUnit_wildPath:
304 res = match_children_wildpath(dh, n, e, i, t, num); break;
311 int data1_doespec1 (data1_handle dh, data1_node *n, Z_Espec1 *e)
315 for (i = 0; i < e->num_elements; i++)
317 if (e->elements[i]->which != Z_ERequest_simpleElement)
319 match_children(dh, n, e, i,
320 e->elements[i]->u.simpleElement->path->tags,
321 e->elements[i]->u.simpleElement->path->num_tags);