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.10 1997-10-02 12:10:24 quinn
8 * Attempt to fix bug in especs
10 * Revision 1.9 1997/09/17 12:10:35 adam
13 * Revision 1.8 1997/05/14 06:54:02 adam
16 * Revision 1.7 1997/04/30 08:52:11 quinn
19 * Revision 1.6 1996/10/11 11:57:22 quinn
22 * Revision 1.5 1996/07/06 19:58:34 quinn
23 * System headerfiles gathered in yconfig
25 * Revision 1.4 1996/06/07 11:04:32 quinn
26 * Fixed tag->tagset dependency
28 * Revision 1.3 1995/11/13 09:27:33 quinn
29 * Fiddling with the variant stuff.
31 * Revision 1.2 1995/11/01 13:54:45 quinn
34 * Revision 1.1 1995/11/01 11:56:07 quinn
35 * Added Retrieval (data management) functions en masse.
47 static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
50 static int match_children_wildpath(data1_node *n, Z_Espec1 *e, int i,
51 Z_ETagUnit **t, int num)
55 * Locate a specific triple within a variant.
56 * set is the set to look for, universal set is the set that applies to a
57 * triple with an unknown set.
59 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
60 oid_value set, int zclass, int type)
63 oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
64 oid_value defaultset = defaultsetent ? defaultsetent->value :
67 for (i = 0; i < var->num_triples; i++)
70 oid_getentbyoid(var->triples[i]->variantSetId);
71 oid_value curset = cursetent ? cursetent->value : defaultset;
74 *var->triples[i]->zclass == zclass &&
75 *var->triples[i]->type == type)
76 return var->triples[i];
81 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
82 int get_bytes, Z_Variant *vreq)
87 if (n->which == DATA1N_tag)
89 if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
91 * This seems to cause multi-level elements to fall out when only a
92 * top-level elementRequest has been given... Problem is, I can't figure
93 * out what it was supposed to ACHIEVE.... delete when code has been
98 n->u.tag.node_selected = 1;
99 n->u.tag.make_variantlist = make_variantlist;
100 n->u.tag.no_data_requested = no_data;
101 n->u.tag.get_bytes = get_bytes;
104 for (c = n->child; c; c = c->next)
106 if (c->which == DATA1N_tag && (!n->child ||
107 n->child->which != DATA1N_tag))
109 c->u.tag.node_selected = 1;
110 c->u.tag.make_variantlist = make_variantlist;
111 c->u.tag.no_data_requested = no_data;
112 c->u.tag.get_bytes = get_bytes;
114 mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
118 static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
119 Z_ETagUnit **t, int num)
121 int counter = 0, hits = 0;
124 Z_Occurrences *occur;
126 for (c = n->child; c ; c = c->next)
130 if (c->which != DATA1N_tag)
133 if (tp->which == Z_ETagUnit_specificTag)
135 Z_SpecificTag *want = tp->u.specificTag;
136 occur = want->occurrences;
137 if (c->u.tag.element)
138 tag = c->u.tag.element->tag;
139 if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
142 if (want->tagValue->which == Z_StringOrNumeric_numeric)
144 if (!tag || tag->which != DATA1T_numeric)
146 if (*want->tagValue->u.numeric != tag->value.numeric)
151 assert(want->tagValue->which == Z_StringOrNumeric_string);
152 if (tag && tag->which != DATA1T_string)
154 if (data1_matchstr(want->tagValue->u.string,
155 tag ? tag->value.string : c->u.tag.tag))
160 occur = tp->u.wildThing;
163 * Ok, so we have a matching tag. Are we within occurrences-range?
166 if (occur && occur->which == Z_Occurrences_last)
168 logf(LOG_WARN, "Can't do occurrences=last (yet)");
171 if (!occur || occur->which == Z_Occurrences_all ||
172 (occur->which == Z_Occurrences_values && counter >=
173 *occur->u.values->start))
175 if (match_children(c, e, i, t + 1, num - 1))
177 c->u.tag.node_selected = 1;
179 * Consider the variant specification if this is a complete
184 int show_variantlist = 0;
189 e->elements[i]->u.simpleElement->variantRequest;
190 oident *defset = oid_getentbyoid(e->defaultVariantSetId);
191 oid_value defsetval = defset ? defset->value : VAL_NONE;
192 oid_value var1 = oid_getvalbyname("Variant-1");
195 vreq = e->defaultVariantRequest;
202 * 6,5: meta-data requested, variant list.
204 if (find_triple(vreq, defsetval, var1, 6, 5))
205 show_variantlist = 1;
207 * 9,1: Miscellaneous, no data requested.
209 if (find_triple(vreq, defsetval, var1, 9, 1))
213 if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
214 if (r->which == Z_Triple_integer)
215 get_bytes = *r->value.integer;
217 mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
221 * have we looked at enough children?
223 if (!occur || (occur->which == Z_Occurrences_values &&
224 (!occur->u.values->howMany ||
225 counter - *occur->u.values->start >=
226 *occur->u.values->howMany - 1)))
234 static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
243 case Z_ETagUnit_wildThing:
244 case Z_ETagUnit_specificTag: res = match_children_here(n, e, i,
246 case Z_ETagUnit_wildPath: res = match_children_wildpath(n, e, i,
254 int data1_doespec1 (data1_handle dh, data1_node *n, Z_Espec1 *e)
258 for (i = 0; i < e->num_elements; i++)
260 if (e->elements[i]->which != Z_ERequest_simpleElement)
262 match_children(n, e, i, e->elements[i]->u.simpleElement->path->tags,
263 e->elements[i]->u.simpleElement->path->num_tags);