-/* $Id: rsbetween.c,v 1.12 2004-02-12 15:15:54 heikki Exp $
+/* $Id: rsbetween.c,v 1.13 2004-06-08 15:05:16 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
#include <rsbetween.h>
#include <zebrautl.h>
+#define RSBETWEEN_DEBUG 0
+
static void *r_create_between(RSET ct, const struct rset_control *sel, void *parms);
static RSFD r_open_between (RSET ct, int flag);
static void r_close_between (RSFD rfd);
struct rset_between_info *info;
};
+#if RSBETWEEN_DEBUG
static void log2 (struct rset_between_rfd *p, char *msg, int cmp_l, int cmp_r)
{
char buf_l[32];
(*p->info->printer)(p->buf_r, buf_r), p->more_r, cmp_r,
p->level);
}
+#endif
static void *r_create_between (RSET ct, const struct rset_control *sel,
void *parms)
struct rset_between_info *info = ((struct rset_between_rfd*)rfd)->info;
struct rset_between_rfd *p = (struct rset_between_rfd *) rfd;
+#if RSBETWEEN_DEBUG
logf (LOG_DEBUG, "rsbetween_rewind");
+#endif
rset_rewind (info->rset_l, p->rfd_l);
rset_rewind (info->rset_m, p->rfd_m);
rset_rewind (info->rset_r, p->rfd_r);
struct rset_between_info *info = ((struct rset_between_rfd*)rfd)->info;
struct rset_between_rfd *p = (struct rset_between_rfd *) rfd;
int rc;
+#if RSBETWEEN_DEBUG
log2( p, "fwd: before forward", 0,0);
+#endif
/* It is enough to forward the m pointer here, the read will */
/* naturally forward the l, m, and attr pointers */
if (p->more_m)
p->more_m=rset_forward(info->rset_m,p->rfd_m, p->buf_m,
&p->term_index_m, info->cmp,untilbuf);
+#if RSBETWEEN_DEBUG
log2( p, "fwd: after forward M", 0,0);
+#endif
rc = r_read_between(rfd, buf, term_index);
+#if RSBETWEEN_DEBUG
log2( p, "fwd: after forward", 0,0);
+#endif
return rc;
}
while (p->more_m)
{
+#if RSBETWEEN_DEBUG
log2( p, "start of loop", cmp_l, cmp_r);
+#endif
/* forward L until past m, count levels, note rec boundaries */
if (p->more_l)
p->level = 0;
cmp_l=2; /* past this record */
}
+#if RSBETWEEN_DEBUG
log2( p, "after first L", cmp_l, cmp_r);
+#endif
while (cmp_l < 0) /* l before m */
{
info->rset_attr, p->rfd_attr,
p->buf_attr, &dummy_term,
info->cmp, p->buf_l);
+#if RSBETWEEN_DEBUG
logf(LOG_DEBUG, "btw: after frowarding attr m=%d",p->more_attr);
+#endif
}
} /* while more_attr */
}
cmp_l= (*info->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
{
}
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= (*info->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 */
}
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)
{
memcpy (buf, p->buf_m, info->key_size);
*term_index = p->term_index_m;
+#if RSBETWEEN_DEBUG
log2( p, "Returning a hit (and forwarding m)", cmp_l, cmp_r);
+#endif
p->more_m = rset_read (info->rset_m, p->rfd_m, p->buf_m,
&p->term_index_m);
if (cmp_l == 2)
}
else if ( ! p->more_l ) /* not in data, no more starts */
{
+#if RSBETWEEN_DEBUG
log2( p, "no more starts, exiting without a hit", cmp_l, cmp_r);
+#endif
return 0; /* ergo, nothing can be found. stop scanning */
}
#if NEWCODE
p->more_m = rset_read (info->rset_m, p->rfd_m, p->buf_m,
&p->term_index_m);
#endif
+#if RSBETWEEN_DEBUG
log2( p, "End of M loop", cmp_l, cmp_r);
+#endif
} /* while more_m */
+#if RSBETWEEN_DEBUG
log2( p, "Exiting, nothing more in m", cmp_l, cmp_r);
+#endif
return 0; /* no more data possible */