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.8 1997-05-14 06:54:02 adam
10 * Revision 1.7 1997/04/30 08:52:11 quinn
13 * Revision 1.6 1996/10/11 11:57:22 quinn
16 * Revision 1.5 1996/07/06 19:58:34 quinn
17 * System headerfiles gathered in yconfig
19 * Revision 1.4 1996/06/07 11:04:32 quinn
20 * Fixed tag->tagset dependency
22 * Revision 1.3 1995/11/13 09:27:33 quinn
23 * Fiddling with the variant stuff.
25 * Revision 1.2 1995/11/01 13:54:45 quinn
28 * Revision 1.1 1995/11/01 11:56:07 quinn
29 * Added Retrieval (data management) functions en masse.
41 static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
44 static int match_children_wildpath(data1_node *n, Z_Espec1 *e, int i,
45 Z_ETagUnit **t, int num)
49 * Locate a specific triple within a variant.
50 * set is the set to look for, universal set is the set that applies to a
51 * triple with an unknown set.
53 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
54 oid_value set, int zclass, int type)
57 oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
58 oid_value defaultset = defaultsetent ? defaultsetent->value :
61 for (i = 0; i < var->num_triples; i++)
64 oid_getentbyoid(var->triples[i]->variantSetId);
65 oid_value curset = cursetent ? cursetent->value : defaultset;
68 *var->triples[i]->zclass == zclass &&
69 *var->triples[i]->type == type)
70 return var->triples[i];
75 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
76 int get_bytes, Z_Variant *vreq)
80 if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
82 n->u.tag.node_selected = 1;
83 n->u.tag.make_variantlist = make_variantlist;
84 n->u.tag.no_data_requested = no_data;
85 n->u.tag.get_bytes = get_bytes;
88 for (c = n->child; c; c = c->next)
90 if (c->which == DATA1N_tag && (!n->child ||
91 n->child->which != DATA1N_tag))
93 c->u.tag.node_selected = 1;
94 c->u.tag.make_variantlist = make_variantlist;
95 c->u.tag.no_data_requested = no_data;
96 c->u.tag.get_bytes = get_bytes;
98 mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
102 static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
103 Z_ETagUnit **t, int num)
105 int counter = 0, hits = 0;
108 Z_Occurrences *occur;
110 for (c = n->child; c ; c = c->next)
114 if (c->which != DATA1N_tag)
117 if (tp->which == Z_ETagUnit_specificTag)
119 Z_SpecificTag *want = tp->u.specificTag;
120 occur = want->occurrences;
121 if (c->u.tag.element)
122 tag = c->u.tag.element->tag;
123 if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
126 if (want->tagValue->which == Z_StringOrNumeric_numeric)
128 if (!tag || tag->which != DATA1T_numeric)
130 if (*want->tagValue->u.numeric != tag->value.numeric)
135 assert(want->tagValue->which == Z_StringOrNumeric_string);
136 if (tag && tag->which != DATA1T_string)
138 if (data1_matchstr(want->tagValue->u.string,
139 tag ? tag->value.string : c->u.tag.tag))
144 occur = tp->u.wildThing;
147 * Ok, so we have a matching tag. Are we within occurrences-range?
150 if (occur && occur->which == Z_Occurrences_last)
152 logf(LOG_WARN, "Can't do occurrences=last (yet)");
155 if (!occur || occur->which == Z_Occurrences_all ||
156 (occur->which == Z_Occurrences_values && counter >=
157 *occur->u.values->start))
159 if (match_children(c, e, i, t + 1, num - 1))
161 c->u.tag.node_selected = 1;
163 * Consider the variant specification if this is a complete
168 int show_variantlist = 0;
173 e->elements[i]->u.simpleElement->variantRequest;
174 oident *defset = oid_getentbyoid(e->defaultVariantSetId);
175 oid_value defsetval = defset ? defset->value : VAL_NONE;
176 oid_value var1 = oid_getvalbyname("Variant-1");
179 vreq = e->defaultVariantRequest;
186 * 6,5: meta-data requested, variant list.
188 if (find_triple(vreq, defsetval, var1, 6, 5))
189 show_variantlist = 1;
191 * 9,1: Miscellaneous, no data requested.
193 if (find_triple(vreq, defsetval, var1, 9, 1))
197 if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
198 if (r->which == Z_Triple_integer)
199 get_bytes = *r->value.integer;
201 mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
205 * have we looked at enough children?
207 if (!occur || (occur->which == Z_Occurrences_values &&
208 (!occur->u.values->howMany ||
209 counter - *occur->u.values->start >=
210 *occur->u.values->howMany - 1)))
218 static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
227 case Z_ETagUnit_wildThing:
228 case Z_ETagUnit_specificTag: res = match_children_here(n, e, i,
230 case Z_ETagUnit_wildPath: res = match_children_wildpath(n, e, i,
238 int data1_doespec1(data1_node *n, Z_Espec1 *e)
242 for (i = 0; i < e->num_elements; i++)
244 if (e->elements[i]->which != Z_ERequest_simpleElement)
246 match_children(n, e, i, e->elements[i]->u.simpleElement->path->tags,
247 e->elements[i]->u.simpleElement->path->num_tags);