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.2 1995-11-01 13:54:45 quinn
10 * Revision 1.1 1995/11/01 11:56:07 quinn
11 * Added Retrieval (data management) functions en masse.
22 static int match_children(data1_node *n, Z_ETagUnit **t, int num);
24 static int match_children_wildpath(data1_node *n, Z_ETagUnit **t, int num)
27 static int match_children_here(data1_node *n, Z_ETagUnit **t, int num)
29 int counter = 0, hits = 0;
34 for (c = n->child; c ; c = c->next)
38 if (c->which != DATA1N_tag)
41 if (tp->which == Z_ETagUnit_specificTag)
43 Z_SpecificTag *want = tp->u.specificTag;
44 occur = want->occurrences;
46 tag = c->u.tag.element->tag;
47 if (*want->tagType != (tag ? tag->tagset->type : 3))
49 if (want->tagValue->which == Z_StringOrNumeric_numeric)
51 if (!tag || tag->which != DATA1T_numeric)
53 if (*want->tagValue->u.numeric != tag->value.numeric)
58 assert(want->tagValue->which == Z_StringOrNumeric_string);
59 if (tag && tag->which != DATA1T_string)
61 if (data1_matchstr(want->tagValue->u.string,
62 tag ? tag->value.string : c->u.tag.tag))
67 occur = tp->u.wildThing;
70 * Ok, so we have a matching tag. Are we within occurrences-range?
73 if (occur && occur->which == Z_Occurrences_last)
75 logf(LOG_WARN, "Can't do occurrences=last (yet)");
78 if (!occur || occur->which == Z_Occurrences_all ||
79 (occur->which == Z_Occurrences_values && counter >=
80 *occur->u.values->start))
82 if (match_children(c, t + 1, num - 1))
84 c->u.tag.node_selected = 1;
87 * have we looked at enough children?
89 if (!occur || (occur->which == Z_Occurrences_values &&
90 counter - *occur->u.values->start >=
91 *occur->u.values->howMany - 1))
99 static void mark_children(data1_node *n)
103 for (c = n->child; c; c = c->next)
105 if (c->which != DATA1N_tag)
107 c->u.tag.node_selected = 1;
112 static int match_children(data1_node *n, Z_ETagUnit **t, int num)
116 mark_children(n); /* Here there shall be variants, like, dude */
121 case Z_ETagUnit_wildThing:
122 case Z_ETagUnit_specificTag: return match_children_here(n, t, num);
123 case Z_ETagUnit_wildPath: return match_children_wildpath(n, t, num);
129 int data1_doespec1(data1_node *n, Z_Espec1 *e)
133 for (i = 0; i < e->num_elements; i++)
134 match_children(n, e->elements[i]->u.simpleElement->path->tags,
135 e->elements[i]->u.simpleElement->path->num_tags);