- while (cmp_l < 0) /* l before m */
- {
- if (cmp_l == -2)
- p->level=0; /* earlier record */
- if (cmp_l == -1)
- {
- p->level++; /* relevant start tag */
-
- if (!info->rset_attr)
- attr_match = 1;
- else
- {
- int cmp_attr;
- attr_match = 0;
- while (p->more_attr)
- {
- cmp_attr = (*kctrl->cmp)(p->buf_attr, p->buf_l);
- if (cmp_attr == 0)
- {
- attr_match = 1;
- break;
- }
- else if (cmp_attr > 0)
- break;
- else if (cmp_attr==-1)
- p->more_attr = rset_read (p->rfd_attr, p->buf_attr);
- /* if we had a forward that went all the way to
- * the seqno, we could use that. But fwd only goes
- * to the sysno */
- else if (cmp_attr==-2)
- {
- p->more_attr = rset_forward( p->rfd_attr,
- p->buf_attr, p->buf_l);
-#if RSBETWEEN_DEBUG
- logf(LOG_DEBUG, "btw: after frowarding attr m=%d",
- p->more_attr);
-#endif
- }
- } /* while more_attr */
- }
- }
-#define NEWCODE 1
-#if NEWCODE
- if (cmp_l==-2)
- {
- if (p->more_l)
- {
- p->more_l=rset_forward(p->rfd_l, p->buf_l, p->buf_m);
- if (p->more_l)
- cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
- else
- cmp_l=2;
-#if RSBETWEEN_DEBUG
- log2( p, "after forwarding L", cmp_l, cmp_r);
-#endif
- }
- } else
- {
- p->more_l = rset_read (p->rfd_l, p->buf_l);
- }
-#else
- p->more_l = rset_read (p->rfd_l, p->buf_l);
-#endif
- if (p->more_l)
- {
- cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
- }
- else
- cmp_l=2;
-#if RSBETWEEN_DEBUG
- log2( p, "end of L loop", cmp_l, cmp_r);
-#endif
- } /* forward L */
-
-
- /* forward R until past m, count levels */
-#if RSBETWEEN_DEBUG
- log2( p, "Before moving R", cmp_l, cmp_r);
-#endif
- if (p->more_r)
- cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
- else
- cmp_r=2;
-#if RSBETWEEN_DEBUG
- log2( p, "after first R", cmp_l, cmp_r);
-#endif
- while (cmp_r < 0) /* r before m */
- {
- /* -2, earlier record, don't count level */
- if (cmp_r == -1)
- p->level--; /* relevant end tag */
- if (p->more_r)
- {
-#if NEWCODE
- if (cmp_r==-2)
- {
- p->more_r=rset_forward(p->rfd_r, p->buf_r, p->buf_m);
- } else
- {
- p->more_r = rset_read (p->rfd_r, p->buf_r);
- }
- if (p->more_r)
- cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
-
-#else
- p->more_r = rset_read (p->rfd_r, p->buf_r);
- cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
-#endif
- }
- else
- cmp_r=2;
-#if RSBETWEEN_DEBUG
- log2( p, "End of R loop", cmp_l, cmp_r);
-#endif
- } /* forward R */
-
- if ( ( p->level <= 0 ) && ! p->more_l)
- return 0; /* no more start tags, nothing more to find */
-
- if ( attr_match && p->level > 0) /* within a tag pair (or deeper) */
- {
- memcpy (buf, p->buf_m, kctrl->key_size);
-#if RSBETWEEN_DEBUG
- log2( p, "Returning a hit (and forwarding m)", cmp_l, cmp_r);
-#endif
- p->more_m = rset_read (p->rfd_m, p->buf_m);
- if (cmp_l == 2)
- p->level = 0;
- p->hits++;
- return 1;
+static int r_read(RSFD rfd, void *buf, TERMID *term)
+{
+ struct rset_between_info *info =
+ (struct rset_between_info *)rfd->rset->priv;
+ struct rset_between_rfd *p = (struct rset_between_rfd *)rfd->priv;
+ const struct rset_key_control *kctrl = rfd->rset->keycontrol;
+ int cmp;
+ TERMID dummyterm = 0;
+ yaz_log(log_level, "== read: term=%p",term);
+ if (!term)
+ term = &dummyterm;
+ while (rset_read(p->andrfd, buf, term))
+ {
+ yaz_log(log_level,"read loop term=%p d=%d ad=%d",
+ *term, p->depth, p->attrdepth);
+ if (p->hits<0)
+ {/* first time? */
+ memcpy(p->recbuf, buf, kctrl->key_size);
+ p->hits = 0;
+ cmp = rfd->rset->scope; /* force newrecord */
+ }
+ else {
+ cmp = (kctrl->cmp)(buf, p->recbuf);
+ yaz_log(log_level, "cmp=%d", cmp);