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.1 1995-11-01 11:56:07 quinn
8 * Added Retrieval (data management) functions en masse.
19 static int match_children(data1_node *n, Z_ETagUnit **t, int num);
21 static int match_children_wildpath(data1_node *n, Z_ETagUnit **t, int num)
24 static int match_children_here(data1_node *n, Z_ETagUnit **t, int num)
26 int counter = 0, hits = 0;
31 for (c = n->child; c ; c = c->next)
35 if (c->which != DATA1N_tag)
38 if (tp->which == Z_ETagUnit_specificTag)
40 Z_SpecificTag *want = tp->u.specificTag;
41 occur = want->occurrences;
43 tag = c->u.tag.element->tag;
44 if (*want->tagType != (tag ? tag->tagset->type : 3))
46 if (want->tagValue->which == Z_StringOrNumeric_numeric)
48 if (!tag || tag->which != DATA1T_numeric)
50 if (*want->tagValue->u.numeric != tag->value.numeric)
55 assert(want->tagValue->which == Z_StringOrNumeric_string);
56 if (tag && tag->which != DATA1T_string)
58 if (data1_matchstr(want->tagValue->u.string,
59 tag ? tag->value.string : c->u.tag.tag))
64 occur = tp->u.wildThing;
67 * Ok, so we have a matching tag. Are we within occurrences-range?
70 if (occur && occur->which == Z_Occurrences_last)
72 logf(LOG_WARN, "Can't do occurrences=last (yet)");
75 if (!occur || occur->which == Z_Occurrences_all ||
76 (occur->which == Z_Occurrences_values && counter >=
77 *occur->u.values->start))
79 if (match_children(c, t + 1, num - 1))
81 c->u.tag.node_selected = 1;
84 * have we looked at enough children?
86 if (!occur || (occur->which == Z_Occurrences_values &&
87 counter - *occur->u.values->start >=
88 *occur->u.values->howMany - 1))
96 static void mark_children(data1_node *n)
100 for (c = n->child; c; c = c->next)
102 if (c->which != DATA1N_tag)
104 c->u.tag.node_selected = 1;
109 static int match_children(data1_node *n, Z_ETagUnit **t, int num)
113 mark_children(n); /* Here there shall be variants, like, dude */
118 case Z_ETagUnit_wildThing:
119 case Z_ETagUnit_specificTag: return match_children_here(n, t, num);
120 case Z_ETagUnit_wildPath: return match_children_wildpath(n, t, num);
126 int data1_doespec1(data1_node *n, Z_Espec1 *e)
130 for (i = 0; i < e->num_elements; i++)
131 match_children(n, e->elements[i]->u.simpleElement->path->tags,
132 e->elements[i]->u.simpleElement->path->num_tags);