+
+int isamb_pp_forward2(ISAMB_PP pp, void *buf, const void *untilb)
+{
+ char *dst = buf;
+ const char *src;
+ struct ISAMB_block *p = pp->block[pp->level];
+ ISAMB b = pp->isamb;
+ if (!p)
+ return 0;
+again:
+ while (p->offset == p->size)
+ {
+ ISAMB_P pos;
+#if INT_ENCODE
+ const char *src_0;
+ void *c1;
+ char file_item_buf[DST_ITEM_MAX];
+ char *file_item = file_item_buf;
+#else
+ zint item_len;
+#endif
+ while (p->offset == p->size)
+ {
+ if (pp->level == 0)
+ return 0;
+ close_block (pp->isamb, pp->block[pp->level]);
+ pp->block[pp->level] = 0;
+ (pp->level)--;
+ p = pp->block[pp->level];
+ assert (!p->leaf);
+ }
+
+ assert(!p->leaf);
+ src = p->bytes + p->offset;
+
+#if INT_ENCODE
+ c1 = (*b->method->codec.start)();
+ (*b->method->codec.decode)(c1, &file_item, &src);
+#else
+ decode_ptr (&src, &item_len);
+ src += item_len;
+#endif
+ decode_ptr (&src, &pos);
+ p->offset = src - (char*) p->bytes;
+
+ src = p->bytes + p->offset;
+
+ while(1)
+ {
+ if (!untilb || p->offset == p->size)
+ break;
+ assert(p->offset < p->size);
+#if INT_ENCODE
+ src_0 = src;
+ file_item = file_item_buf;
+ (*b->method->codec.reset)(c1);
+ (*b->method->codec.decode)(c1, &file_item, &src);
+ if ((*b->method->compare_item)(untilb, file_item_buf) <= 1)
+ {
+ src = src_0;
+ break;
+ }
+#else
+ decode_item_len(&src, &item_len);
+ if ((*b->method->compare_item)(untilb, src) <= 1)
+ break;
+ src += item_len;
+#endif
+ decode_ptr (&src, &pos);
+ p->offset = src - (char*) p->bytes;
+ }
+
+ pp->level++;
+
+ while (1)
+ {
+ pp->block[pp->level] = p = open_block (pp->isamb, pos);
+
+ pp->total_size += p->size;
+ pp->no_blocks++;
+
+ if (p->leaf)
+ {
+ break;
+ }
+
+ src = p->bytes + p->offset;
+ while(1)
+ {
+ decode_ptr (&src, &pos);
+ p->offset = src - (char*) p->bytes;
+
+ if (!untilb || p->offset == p->size)
+ break;
+ assert(p->offset < p->size);
+#if INT_ENCODE
+ src_0 = src;
+ file_item = file_item_buf;
+ (*b->method->codec.reset)(c1);
+ (*b->method->codec.decode)(c1, &file_item, &src);
+ if ((*b->method->compare_item)(untilb, file_item_buf) <= 1)
+ {
+ src = src_0;
+ break;
+ }
+#else
+ decode_ptr (&src, &item_len);
+ if ((*b->method->compare_item)(untilb, src) <= 1)
+ break;
+ src += item_len;
+#endif
+ }
+ pp->level++;
+ }
+#if INT_ENCODE
+ (*b->method->codec.stop)(c1);
+#endif
+ }
+ assert (p->offset < p->size);
+ assert (p->leaf);
+ while(1)
+ {
+ char *dst0 = dst;
+ src = p->bytes + p->offset;
+ (*pp->isamb->method->codec.decode)(p->decodeClientData, &dst, &src);
+ p->offset = src - (char*) p->bytes;
+ if (!untilb || (*pp->isamb->method->compare_item)(untilb, dst0) <= 1)
+ break;
+ dst = dst0;
+ if (p->offset == p->size) goto again;
+ }
+ return 1;
+}