10 search(Object *rt, Object *parent, Reprog *preg) {
11 /* Create a `search object', a subtree of rt containing
12 * only objects with s in their value of key fields plus
15 * Algorithm: depth-first traversal of rt. On the way down,
16 * copy rt to nr (new root), on the way back up, delete
17 * subtrees without match.
19 * returns null when there are no matches in rt's subtree
26 nr = newobject(rt->type, parent);
27 nr->orig = rt->orig?rt->orig:rt;
28 nr->value = rt->value;
29 strncpy(nr->key, rt->key, KEYLEN);
31 if((((s = nr->value)) && regexec(preg, s, nil, 0) == 1)
32 || (((s = nr->value)) && regexec(preg, s, nil, 0) == 1))
34 for(i = 0; i < rt->nchildren; i++)
35 if((o = search((Object*)rt->children[i], nr, preg))){
37 addchild(nr, o, "search");