+static void index_xpath (data1_node *n, struct recExtractCtrl *p,
+ int level, RecWord *wrd, int use)
+{
+ int i;
+ char tag_path_full[1024];
+ size_t flen = 0;
+ data1_node *nn;
+
+ switch (n->which)
+ {
+ case DATA1N_data:
+ wrd->reg_type = 'w';
+ wrd->string = n->u.data.data;
+ wrd->length = n->u.data.len;
+ wrd->attrSet = VAL_IDXPATH,
+ wrd->attrUse = use;
+ if (p->flagShowRecords)
+ {
+ printf("%*s data=", (level + 1) * 4, "");
+ for (i = 0; i<wrd->length && i < 8; i++)
+ fputc (wrd->string[i], stdout);
+ printf("\n");
+ }
+ else
+ {
+ (*p->tokenAdd)(wrd);
+ }
+ break;
+ case DATA1N_tag:
+ for (nn = n; nn; nn = nn->parent)
+ {
+ if (n->which == DATA1N_tag)
+ {
+ size_t tlen = strlen(nn->u.tag.tag);
+ if (tlen + flen > (sizeof(tag_path_full)-2))
+ return;
+ memcpy (tag_path_full + flen, nn->u.tag.tag, tlen);
+ flen += tlen;
+ tag_path_full[flen++] = '/';
+ }
+ else if (n->which == DATA1N_root)
+ {
+ size_t tlen = strlen(nn->u.root.type);
+ if (tlen + flen > (sizeof(tag_path_full)-2))
+ return;
+ memcpy (tag_path_full + flen, nn->u.root.type, tlen);
+ flen += tlen;
+ tag_path_full[flen++] = '/';
+ break;
+ }
+ }
+ wrd->reg_type = '0';
+ wrd->string = tag_path_full;
+ wrd->length = flen;
+ wrd->attrSet = VAL_IDXPATH,
+ wrd->attrUse = use;
+ if (p->flagShowRecords)
+ {
+ printf("%*s tag=", (level + 1) * 4, "");
+ for (i = 0; i<wrd->length && i < 40; i++)
+ fputc (wrd->string[i], stdout);
+ if (i == 40)
+ printf (" ..");
+ printf("\n");
+ }
+ else
+ {
+ (*p->tokenAdd)(wrd);
+ }
+ break;
+ }
+}
+
+static void index_termlist (data1_node *par, data1_node *n,
+ struct recExtractCtrl *p, int level, RecWord *wrd)
+{
+ data1_termlist *tlist = 0;
+ data1_datatype dtype = DATA1K_string;
+ /*
+ * cycle up towards the root until we find a tag with an att..
+ * this has the effect of indexing locally defined tags with
+ * the attribute of their ancestor in the record.
+ */
+
+ while (!par->u.tag.element)
+ if (!par->parent || !(par=get_parent_tag(p->dh, par->parent)))
+ break;
+ if (!par || !(tlist = par->u.tag.element->termlists))
+ return;
+ if (par->u.tag.element->tag)
+ dtype = par->u.tag.element->tag->kind;
+
+ for (; tlist; tlist = tlist->next)
+ {
+ char xattr[512];
+ /* consider source */
+ wrd->string = 0;
+
+ if (!strcmp (tlist->source, "data") && n->which == DATA1N_data)
+ {
+ wrd->string = n->u.data.data;
+ wrd->length = n->u.data.len;
+ }
+ else if (!strcmp (tlist->source, "tag") && n->which == DATA1N_tag)
+ {
+ wrd->string = n->u.tag.tag;
+ wrd->length = strlen(n->u.tag.tag);
+ }
+ else if (sscanf (tlist->source, "attr(%511[^)])", xattr) == 1 &&
+ n->which == DATA1N_tag)
+ {
+ data1_xattr *p = n->u.tag.attributes;
+ while (p && strcmp (p->name, xattr))
+ p = p->next;
+ if (p)
+ {
+ wrd->string = p->value;
+ wrd->length = strlen(p->value);
+ }
+ }
+ if (wrd->string)
+ {
+ if (p->flagShowRecords)
+ {
+ int i;
+ printf("%*sIdx: [%s]", (level + 1) * 4, "",
+ tlist->structure);
+ printf("%s:%s [%d] %s",
+ tlist->att->parent->name,
+ tlist->att->name, tlist->att->value,
+ tlist->source);
+ printf (" data=\"");
+ for (i = 0; i<wrd->length && i < 8; i++)
+ fputc (wrd->string[i], stdout);
+ fputc ('"', stdout);
+ if (wrd->length > 8)
+ printf (" ...");
+ fputc ('\n', stdout);
+ }
+ else
+ {
+ wrd->reg_type = *tlist->structure;
+ wrd->attrSet = (int) (tlist->att->parent->reference);
+ wrd->attrUse = tlist->att->locals->local;
+ (*p->tokenAdd)(wrd);
+ }
+ }
+ }
+}
+