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.7 1997-04-30 08:52:11 quinn
10 * Revision 1.6 1996/10/11 11:57:22 quinn
13 * Revision 1.5 1996/07/06 19:58:34 quinn
14 * System headerfiles gathered in yconfig
16 * Revision 1.4 1996/06/07 11:04:32 quinn
17 * Fixed tag->tagset dependency
19 * Revision 1.3 1995/11/13 09:27:33 quinn
20 * Fiddling with the variant stuff.
22 * Revision 1.2 1995/11/01 13:54:45 quinn
25 * Revision 1.1 1995/11/01 11:56:07 quinn
26 * Added Retrieval (data management) functions en masse.
38 static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
41 static int match_children_wildpath(data1_node *n, Z_Espec1 *e, int i,
42 Z_ETagUnit **t, int num)
46 * Locate a specific triple within a variant.
47 * set is the set to look for, universal set is the set that applies to a
48 * triple with an unknown set.
50 static Z_Triple *find_triple(Z_Variant *var, oid_value universalset,
51 oid_value set, int class, int type)
54 oident *defaultsetent = oid_getentbyoid(var->globalVariantSetId);
55 oid_value defaultset = defaultsetent ? defaultsetent->value :
58 for (i = 0; i < var->num_triples; i++)
61 oid_getentbyoid(var->triples[i]->variantSetId);
62 oid_value curset = cursetent ? cursetent->value : defaultset;
65 *var->triples[i]->class == class &&
66 *var->triples[i]->type == type)
67 return var->triples[i];
72 static void mark_subtree(data1_node *n, int make_variantlist, int no_data,
73 int get_bytes, Z_Variant *vreq)
77 if (n->which == DATA1N_tag && (!n->child || n->child->which != DATA1N_tag))
79 n->u.tag.node_selected = 1;
80 n->u.tag.make_variantlist = make_variantlist;
81 n->u.tag.no_data_requested = no_data;
82 n->u.tag.get_bytes = get_bytes;
85 for (c = n->child; c; c = c->next)
87 if (c->which == DATA1N_tag && (!n->child ||
88 n->child->which != DATA1N_tag))
90 c->u.tag.node_selected = 1;
91 c->u.tag.make_variantlist = make_variantlist;
92 c->u.tag.no_data_requested = no_data;
93 c->u.tag.get_bytes = get_bytes;
95 mark_subtree(c, make_variantlist, no_data, get_bytes, vreq);
99 static int match_children_here(data1_node *n, Z_Espec1 *e, int i,
100 Z_ETagUnit **t, int num)
102 int counter = 0, hits = 0;
105 Z_Occurrences *occur;
107 for (c = n->child; c ; c = c->next)
111 if (c->which != DATA1N_tag)
114 if (tp->which == Z_ETagUnit_specificTag)
116 Z_SpecificTag *want = tp->u.specificTag;
117 occur = want->occurrences;
118 if (c->u.tag.element)
119 tag = c->u.tag.element->tag;
120 if (*want->tagType != ((tag && tag->tagset) ? tag->tagset->type :
123 if (want->tagValue->which == Z_StringOrNumeric_numeric)
125 if (!tag || tag->which != DATA1T_numeric)
127 if (*want->tagValue->u.numeric != tag->value.numeric)
132 assert(want->tagValue->which == Z_StringOrNumeric_string);
133 if (tag && tag->which != DATA1T_string)
135 if (data1_matchstr(want->tagValue->u.string,
136 tag ? tag->value.string : c->u.tag.tag))
141 occur = tp->u.wildThing;
144 * Ok, so we have a matching tag. Are we within occurrences-range?
147 if (occur && occur->which == Z_Occurrences_last)
149 logf(LOG_WARN, "Can't do occurrences=last (yet)");
152 if (!occur || occur->which == Z_Occurrences_all ||
153 (occur->which == Z_Occurrences_values && counter >=
154 *occur->u.values->start))
156 if (match_children(c, e, i, t + 1, num - 1))
158 c->u.tag.node_selected = 1;
160 * Consider the variant specification if this is a complete
165 int show_variantlist = 0;
170 e->elements[i]->u.simpleElement->variantRequest;
171 oident *defset = oid_getentbyoid(e->defaultVariantSetId);
172 oid_value defsetval = defset ? defset->value : VAL_NONE;
173 oid_value var1 = oid_getvalbyname("Variant-1");
176 vreq = e->defaultVariantRequest;
183 * 6,5: meta-data requested, variant list.
185 if (find_triple(vreq, defsetval, var1, 6, 5))
186 show_variantlist = 1;
188 * 9,1: Miscellaneous, no data requested.
190 if (find_triple(vreq, defsetval, var1, 9, 1))
194 if ((r = find_triple(vreq, defsetval, var1, 5, 5)))
195 if (r->which == Z_Triple_integer)
196 get_bytes = *r->value.integer;
198 mark_subtree(c, show_variantlist, no_data, get_bytes, vreq);
202 * have we looked at enough children?
204 if (!occur || (occur->which == Z_Occurrences_values &&
205 (!occur->u.values->howMany ||
206 counter - *occur->u.values->start >=
207 *occur->u.values->howMany - 1)))
215 static int match_children(data1_node *n, Z_Espec1 *e, int i, Z_ETagUnit **t,
224 case Z_ETagUnit_wildThing:
225 case Z_ETagUnit_specificTag: res = match_children_here(n, e, i,
227 case Z_ETagUnit_wildPath: res = match_children_wildpath(n, e, i,
235 int data1_doespec1(data1_node *n, Z_Espec1 *e)
239 for (i = 0; i < e->num_elements; i++)
241 if (e->elements[i]->which != Z_ERequest_simpleElement)
243 match_children(n, e, i, e->elements[i]->u.simpleElement->path->tags,
244 e->elements[i]->u.simpleElement->path->num_tags);