+ yaz_log(YLOG_DEBUG, "isamb_pp_descend_to_leaf "
+ "returning at lev %d node %d ofs=%d lf=%d",
+ pp->level, p->pos, p->offset, p->leaf);
+#endif
+} /* descend_to_leaf */
+
+static int isamb_pp_find_next_leaf(ISAMB_PP pp)
+{ /* finds the next leaf by climbing up and down */
+ ISAM_P pos;
+ if (!isamb_pp_climb_level(pp, &pos))
+ return 0;
+ isamb_pp_descend_to_leaf(pp, pos, 0);
+ return 1;
+}
+
+static int isamb_pp_climb_desc(ISAMB_PP pp, const void *untilbuf)
+{ /* climbs up and descends to a leaf where values >= *untilbuf are found */
+ ISAM_P pos;
+#if ISAMB_DEBUG
+ struct ISAMB_block *p = pp->block[pp->level];
+ yaz_log(YLOG_DEBUG, "isamb_pp_climb_desc starting "
+ "at level %d node %d ofs=%d sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ if (!isamb_pp_climb_level(pp, &pos))
+ return 0;
+ /* see if it would pay to climb one higher */
+ if (!isamb_pp_on_right_node(pp, pp->level, untilbuf))
+ if (!isamb_pp_climb_level(pp, &pos))
+ return 0;
+ isamb_pp_descend_to_leaf(pp, pos, untilbuf);
+#if ISAMB_DEBUG
+ p = pp->block[pp->level];
+ yaz_log(YLOG_DEBUG, "isamb_pp_climb_desc done "
+ "at level %d node %d ofs=%d sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ return 1;
+} /* climb_desc */
+
+int isamb_pp_forward (ISAMB_PP pp, void *buf, const void *untilbuf)
+{
+#if ISAMB_DEBUG
+ struct ISAMB_block *p = pp->block[pp->level];
+ assert(p->leaf);
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward starting "
+ "at level %d node %d ofs=%d sz=%d u=%p sc=%d",
+ pp->level, p->pos, p->offset, p->size, untilbuf, scope);
+#endif
+ if (untilbuf)
+ {
+ if (isamb_pp_forward_on_leaf(pp, buf, untilbuf))
+ {
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward (f) returning (A) "
+ "at level %d node %d ofs=%d sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ return 1;
+ }
+ if (! isamb_pp_climb_desc(pp, untilbuf))
+ {
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward (f) returning notfound (B) "
+ "at level %d node %d ofs=%d sz=%d",
+ pp->level, p->pos, p->offset, p->size);
+#endif
+ return 0; /* could not find a leaf */
+ }
+ do {
+ if (isamb_pp_forward_on_leaf(pp, buf, untilbuf))
+ {
+#if ISAMB_DEBUG
+ yaz_log(YLOG_DEBUG, "isamb_pp_forward (f) returning (c) "
+ "at level %d node %d ofs=%d sz=%d",
+ pp->level, p->pos, p->offset, p->size);