- if (!memcmp (type, gh->type->type, cp-type))
+ sp->lookahead = *sp->src;
+ if (*sp->src)
+ sp->src++;
+ }
+ return sp->lookahead;
+}
+
+
+static int sp_expr(struct source_parser *sp, data1_node *n, RecWord *wrd)
+{
+ if (sp->lookahead != 't')
+ return 0;
+ if (sp->len == 4 && !memcmp(sp->tok, "data", sp->len))
+ {
+ if (n->which == DATA1N_data)
+ {
+ wrd->string = n->u.data.data;
+ wrd->length = n->u.data.len;
+ }
+ sp_lex(sp);
+ }
+ else if (sp->len == 3 && !memcmp(sp->tok, "tag", sp->len))
+ {
+ if (n->which == DATA1N_tag)
+ {
+ wrd->string = n->u.tag.tag;
+ wrd->length = strlen(n->u.tag.tag);
+ }
+ sp_lex(sp);
+ }
+ else if (sp->len == 4 && !memcmp(sp->tok, "attr", sp->len))
+ {
+ sp_lex(sp);
+ if (sp->lookahead != '(')
+ return 0;
+ sp_lex(sp);
+ if (sp->lookahead != 't')
+ return 0;
+
+ if (n->which == DATA1N_tag)
- /* If we have a matching termlist... */
- if ((tl = xpath_termlist_by_tagpath(tag_path_full, n))) {
- for (; tl; tl = tl->next) {
- wrd->reg_type = *tl->structure;
- /* this is the ! case, so structure is for the xpath index */
- if (!tl->att) {
- wrd->attrSet = VAL_IDXPATH;
- wrd->attrUse = use;
- (*p->tokenAdd)(wrd);
- xpdone = 1;
- /* this is just the old fashioned attribute based index */
- } else {
- wrd->attrSet = (int) (tl->att->parent->reference);
- wrd->attrUse = tl->att->locals->local;
- (*p->tokenAdd)(wrd);
- }
- }
- }
- /* xpath indexing is done, if there was no termlist given,
- or no ! in the termlist, and default indexing is enabled... */
- if ((!xpdone) && (!termlist_only)) {
- wrd->attrSet = VAL_IDXPATH;
- wrd->attrUse = use;
- wrd->reg_type = 'w';
- (*p->tokenAdd)(wrd);
- }
+ /* we have to fetch the whole path to the data tag */
+ for (nn = n; nn; nn = nn->parent) {
+ if (nn->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 (nn->which == DATA1N_root) break;
+ }
+
+ tag_path_full[flen] = 0;
+
+ /* If we have a matching termlist... */
+ if (n->root->u.root.absyn &&
+ (tl = xpath_termlist_by_tagpath(tag_path_full, n)))
+ {
+ for (; tl; tl = tl->next)
+ {
+ /* need to copy recword because it may be changed */
+ RecWord wrd_tl;
+ wrd->reg_type = *tl->structure;
+ /* this is the ! case, so structure is for the xpath index */
+ memcpy (&wrd_tl, wrd, sizeof(*wrd));
+ if (tl->source)
+ sp_parse(n, &wrd_tl, tl->source);
+ if (!tl->att) {
+ wrd_tl.attrSet = VAL_IDXPATH;
+ wrd_tl.attrUse = use;
+ if (p->flagShowRecords)
+ {
+ int i;
+ printf("%*sXPath index", (level + 1) * 4, "");
+ printf (" XData:\"");
+ for (i = 0; i<wrd_tl.length && i < 40; i++)
+ fputc (wrd_tl.string[i], stdout);
+ fputc ('"', stdout);
+ if (wrd_tl.length > 40)
+ printf (" ...");
+ fputc ('\n', stdout);
+ }
+ else
+ (*p->tokenAdd)(&wrd_tl);
+ xpdone = 1;
+ } else {
+ /* this is just the old fashioned attribute based index */
+ wrd_tl.attrSet = (int) (tl->att->parent->reference);
+ wrd_tl.attrUse = tl->att->locals->local;
+ if (p->flagShowRecords)
+ {
+ int i;
+ printf("%*sIdx: [%s]", (level + 1) * 4, "",
+ tl->structure);
+ printf("%s:%s [%d] %s",
+ tl->att->parent->name,
+ tl->att->name, tl->att->value,
+ tl->source);
+ printf (" XData:\"");
+ for (i = 0; i<wrd_tl.length && i < 40; i++)
+ fputc (wrd_tl.string[i], stdout);
+ fputc ('"', stdout);
+ if (wrd_tl.length > 40)
+ printf (" ...");
+ fputc ('\n', stdout);
+ }
+ else
+ (*p->tokenAdd)(&wrd_tl);
+ }
+ }
+ }
+ /* xpath indexing is done, if there was no termlist given,
+ or no ! in the termlist, and default indexing is enabled... */
+ if (!p->flagShowRecords && !xpdone && !termlist_only)
+ {
+ wrd->attrSet = VAL_IDXPATH;
+ wrd->attrUse = use;
+ wrd->reg_type = 'w';
+ (*p->tokenAdd)(wrd);
-
- data1_termlist *tll[MAX_ATTR_COUNT];
-
- int i = 0;
-
- /* get termlists for attributes, and find out, if we have to do xpath indexing */
- for (xp = n->u.tag.attributes; xp; xp = xp->next) {
- i++;
- }
-
- i = 0;
- for (xp = n->u.tag.attributes; xp; xp = xp->next) {
- char comb[512];
- int do_xpindex = 1 - termlist_only;
- data1_termlist *tl;
- char attr_tag_path_full[1024];
- int int_len = flen;
-
- /* this could be cached as well */
- sprintf (attr_tag_path_full, "@%s/%.*s",
- xp->name, int_len, tag_path_full);
-
- tll[i] = xpath_termlist_by_tagpath(attr_tag_path_full,n);
-
- /* if there is a ! in the xelm termlist, or default indexing is on,
- proceed with xpath idx */
- if ((tl = tll[i]))
- {
- for (; tl; tl = tl->next)
- {
- if (!tl->att)
- do_xpindex = 1;
- }
- }
-
- if (do_xpindex) {
-
- /* attribute (no value) */
- wrd->reg_type = '0';
- wrd->attrUse = 3;
- wrd->string = xp->name;
- wrd->length = strlen(xp->name);
-
- wrd->seqno--;
- (*p->tokenAdd)(wrd);
-
- if (xp->value &&
- strlen(xp->name) + strlen(xp->value) < sizeof(comb)-2) {
-
- /* attribute value exact */
- strcpy (comb, xp->name);
- strcat (comb, "=");
- strcat (comb, xp->value);
-
- wrd->attrUse = 3;
- wrd->reg_type = '0';
- wrd->string = comb;
- wrd->length = strlen(comb);
- wrd->seqno--;
-
- (*p->tokenAdd)(wrd);
- }
- }
- i++;
- }
-
- i = 0;
- for (xp = n->u.tag.attributes; xp; xp = xp->next) {
- data1_termlist *tl;
- char attr_tag_path_full[1024];
- int int_len = flen;
- int xpdone = 0;
-
- sprintf (attr_tag_path_full, "@%s/%.*s",
- xp->name, int_len, tag_path_full);
-
- if ((tl = tll[i]))
- {
- /* If there is a termlist given (=xelm directive) */
- for (; tl; tl = tl->next)
- {
- if (!tl->att) {
- /* add xpath index for the attribute */
- index_xpath_attr (attr_tag_path_full, xp->name,
- xp->value, tl->structure,
- p, wrd);
- xpdone = 1;
- } else {
- /* add attribute based index for the attribute */
- if (xp->value) {
- wrd->attrSet = (int)
- (tl->att->parent->reference);
- wrd->attrUse = tl->att->locals->local;
- wrd->reg_type = *tl->structure;
- wrd->string = xp->value;
- wrd->length = strlen(xp->value);
- (*p->tokenAdd)(wrd);
- }
- }
- }
- }
- /* if there was no termlist for the given path,
- or the termlist didn't have a ! element, index
- the attribute as "w" */
- if ((!xpdone) && (!termlist_only))
- {
- index_xpath_attr (attr_tag_path_full, xp->name,
- xp->value, "w", p, wrd);
- }
- i++;
- }
- }
+ data1_termlist *tll[MAX_ATTR_COUNT];
+
+ int i = 0;
+
+ /* get termlists for attributes, and find out, if we have to do xpath indexing */
+ for (xp = n->u.tag.attributes; xp; xp = xp->next) {
+ i++;
+ }
+
+ i = 0;
+ for (xp = n->u.tag.attributes; xp; xp = xp->next) {
+ char comb[512];
+ int do_xpindex = 1 - termlist_only;
+ data1_termlist *tl;
+ char attr_tag_path_full[1024];
+ int int_len = flen;
+
+ /* this could be cached as well */
+ sprintf (attr_tag_path_full, "@%s/%.*s",
+ xp->name, int_len, tag_path_full);
+
+ tll[i] = xpath_termlist_by_tagpath(attr_tag_path_full,n);
+
+ /* if there is a ! in the xelm termlist, or default indexing is on,
+ proceed with xpath idx */
+ if ((tl = tll[i]))
+ {
+ for (; tl; tl = tl->next)
+ {
+ if (!tl->att)
+ do_xpindex = 1;
+ }
+ }
+
+ if (do_xpindex) {
+
+ /* attribute (no value) */
+ wrd->reg_type = '0';
+ wrd->attrUse = 3;
+ wrd->string = xp->name;
+ wrd->length = strlen(xp->name);
+
+ wrd->seqno--;
+ (*p->tokenAdd)(wrd);
+
+ if (xp->value &&
+ strlen(xp->name) + strlen(xp->value) < sizeof(comb)-2) {
+
+ /* attribute value exact */
+ strcpy (comb, xp->name);
+ strcat (comb, "=");
+ strcat (comb, xp->value);
+
+ wrd->attrUse = 3;
+ wrd->reg_type = '0';
+ wrd->string = comb;
+ wrd->length = strlen(comb);
+ wrd->seqno--;
+
+ (*p->tokenAdd)(wrd);
+ }
+ }
+ i++;
+ }
+
+ i = 0;
+ for (xp = n->u.tag.attributes; xp; xp = xp->next) {
+ data1_termlist *tl;
+ char attr_tag_path_full[1024];
+ int int_len = flen;
+ int xpdone = 0;
+
+ sprintf (attr_tag_path_full, "@%s/%.*s",
+ xp->name, int_len, tag_path_full);
+
+ if ((tl = tll[i]))
+ {
+ /* If there is a termlist given (=xelm directive) */
+ for (; tl; tl = tl->next)
+ {
+ if (!tl->att) {
+ /* add xpath index for the attribute */
+ index_xpath_attr (attr_tag_path_full, xp->name,
+ xp->value, tl->structure,
+ p, wrd);
+ xpdone = 1;
+ } else {
+ /* add attribute based index for the attribute */
+ if (xp->value) {
+ wrd->attrSet = (int)
+ (tl->att->parent->reference);
+ wrd->attrUse = tl->att->locals->local;
+ wrd->reg_type = *tl->structure;
+ wrd->string = xp->value;
+ wrd->length = strlen(xp->value);
+ (*p->tokenAdd)(wrd);
+ }
+ }
+ }
+ }
+ /* if there was no termlist for the given path,
+ or the termlist didn't have a ! element, index
+ the attribute as "w" */
+ if ((!xpdone) && (!termlist_only))
+ {
+ index_xpath_attr (attr_tag_path_full, xp->name,
+ xp->value, "w", p, wrd);
+ }
+ i++;
+ }
+ }