+static int r_read_or (RSFD rfd, void *buf)
+{
+ struct rset_bool_rfd *p = rfd;
+ struct rset_bool_info *info = p->info;
+
+ while (p->more_l || p->more_r)
+ {
+ int cmp;
+
+ if (p->more_l && p->more_r)
+ cmp = (*info->cmp)(p->buf_l, p->buf_r);
+ else if (p->more_r)
+ cmp = 2;
+ else
+ cmp = -2;
+ if (!cmp)
+ {
+ memcpy (buf, p->buf_l, info->key_size);
+ p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+ p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+ return 1;
+ }
+ else if (cmp > 0)
+ {
+ memcpy (buf, p->buf_r, info->key_size);
+ p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+ return 1;
+ }
+ else
+ {
+ memcpy (buf, p->buf_l, info->key_size);
+ p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static int r_read_not (RSFD rfd, void *buf)
+{
+ struct rset_bool_rfd *p = rfd;
+ struct rset_bool_info *info = p->info;
+
+ while (p->more_l || p->more_r)
+ {
+ int cmp;
+
+ if (p->more_l && p->more_r)
+ cmp = (*info->cmp)(p->buf_l, p->buf_r);
+ else if (p->more_r)
+ cmp = 2;
+ else
+ cmp = -2;
+ if (cmp < -1)
+ {
+ memcpy (buf, p->buf_l, info->key_size);
+ p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+ return 1;
+ }
+ else if (cmp > 1)
+ p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+ else
+ {
+ memcpy (buf, p->buf_l, info->key_size);
+ do
+ {
+ p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l);
+ if (!p->more_l)
+ break;
+ cmp = (*info->cmp)(p->buf_l, buf);
+ } while (cmp >= -1 && cmp <= 1);
+ do
+ {
+ p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
+ if (!p->more_r)
+ break;
+ cmp = (*info->cmp)(p->buf_r, buf);
+ } while (cmp >= -1 && cmp <= 1);
+ }
+ }