-/* $Id: isamb.h,v 1.8 2004-06-01 12:56:38 adam Exp $
+/* $Id: isamb.h,v 1.9 2004-06-02 12:30:32 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
int isamb_block_info (ISAMB isamb, int cat);
+void isamb_dump (ISAMB b, ISAMB_P pos, void (*pr)(const char *str));
+
#endif
-/* $Id: isamb.c,v 1.35 2004-06-02 07:53:31 adam Exp $
+/* $Id: isamb.c,v 1.36 2004-06-02 12:30:32 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
xfree (isamb);
}
-
-struct ISAMB_block *open_block (ISAMB b, ISAMC_P pos)
+static struct ISAMB_block *open_block (ISAMB b, ISAMC_P pos)
{
int cat = pos&CAT_MASK;
struct ISAMB_block *p;
isamb_pp_close_x (pp, 0, 0);
}
+/* simple recursive dumper .. */
+static void isamb_dump_r (ISAMB b, ISAMB_P pos, void (*pr)(const char *str),
+ int level)
+{
+ char buf[1024];
+ char prefix_str[1024];
+ if (pos)
+ {
+ struct ISAMB_block *p = open_block (b, pos);
+ sprintf(prefix_str, "%*s %d cat=%d size=%d max=%d", level*2, "",
+ pos, p->cat, p->size, b->file[p->cat].head.block_max);
+ (*pr)(prefix_str);
+ sprintf(prefix_str, "%*s %d", level*2, "", pos);
+ if (p->leaf)
+ {
+ while (p->offset < p->size)
+ {
+ char *src = p->bytes + p->offset;
+ char *dst = buf;
+ (*b->method->code_item)(ISAMC_DECODE, p->decodeClientData,
+ &dst, &src);
+ (*b->method->log_item)(LOG_DEBUG, buf, prefix_str);
+ p->offset = src - (char*) p->bytes;
+ }
+ assert(p->offset == p->size);
+ }
+ else
+ {
+ char *src = p->bytes + p->offset;
+ int sub;
+ int item_len;
+
+ decode_ptr (&src, &sub);
+ p->offset = src - (char*) p->bytes;
+
+ isamb_dump_r(b, sub, pr, level+1);
+
+ while (p->offset < p->size)
+ {
+ decode_ptr (&src, &item_len);
+ (*b->method->log_item)(LOG_DEBUG, src, prefix_str);
+ src += item_len;
+ decode_ptr (&src, &sub);
+
+ p->offset = src - (char*) p->bytes;
+
+ isamb_dump_r(b, sub, pr, level+1);
+ }
+ }
+ close_block(b,p);
+ }
+}
+
+void isamb_dump (ISAMB b, ISAMB_P pos, void (*pr)(const char *str))
+{
+ return isamb_dump_r(b, pos, pr, 0);
+}
#if 0
/* Old isamb_pp_read that Adam wrote, kept as a reference in case we need to
-/* $Id: tstisamb.c,v 1.4 2004-06-02 07:51:52 adam Exp $
+/* $Id: tstisamb.c,v 1.5 2004-06-02 12:30:32 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <isamb.h>
#include <assert.h>
+static void log_item(int level, const void *b, const char *txt)
+{
+ int x;
+ memcpy(&x, b, sizeof(int));
+ yaz_log(LOG_DEBUG, "%s %d", txt, x);
+}
+
+static void log_pr(const char *txt)
+{
+ yaz_log(LOG_DEBUG, "%s", txt);
+}
+
int compare_item(const void *a, const void *b)
{
int ia, ib;
}
isamb_pp_close(pp);
+ isamb_dump(isb, isamc_p, log_pr);
isamb_unlink(isb, isamc_p);
}
-static void log_item(int level, const void *b, const char *txt)
-{
-}
-
int main(int argc, char **argv)
{
BFiles bfs;