+static int r_forward_and(RSFD rfd, void *buf, TERMID *term,
+ const void *untilbuf)
+{
+ struct rfd_private *p = rfd->priv;
+ RSET ct = rfd->rset;
+ const struct rset_key_control *kctrl = ct->keycontrol;
+ int i;
+ int cmp;
+ int killtail = 0;
+
+ for (i = 0; i<ct->no_children; i++)
+ {
+ cmp = (*kctrl->cmp)(p->items[i].buf,untilbuf);
+ if (cmp <= -rfd->rset->scope)
+ {
+ killtail = 1; /* we are moving to a different hit */
+ if (!rset_forward(p->items[i].fd, p->items[i].buf,
+ &p->items[i].term, untilbuf))
+ {
+ p->eof = 1; /* game over */
+ p->tailcount = 0;
+ return 0;
+ }
+ }
+ }
+ if (killtail)
+ {
+ for (i = 0; i<ct->no_children; i++)
+ p->tailbits[i] = 0;
+ p->tailcount = 0;
+ }
+ return r_read_and(rfd,buf,term);