From: Adam Dickmeiss Date: Wed, 2 Jun 2004 12:30:32 +0000 (+0000) Subject: Added isamb_dump utility. X-Git-Tag: ZEBRA.1.3.16~80 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=39b9f004ecc7242730ef003f387a16c50dac33f0 Added isamb_dump utility. --- diff --git a/include/isamb.h b/include/isamb.h index 849ed24..a41e598 100644 --- a/include/isamb.h +++ b/include/isamb.h @@ -1,4 +1,4 @@ -/* $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 @@ -53,4 +53,6 @@ void isamb_pp_close_x (ISAMB_PP pp, int *size, int *blocks); int isamb_block_info (ISAMB isamb, int cat); +void isamb_dump (ISAMB b, ISAMB_P pos, void (*pr)(const char *str)); + #endif diff --git a/isamb/isamb.c b/isamb/isamb.c index 2f43971..1bf6389 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -1,4 +1,4 @@ -/* $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 @@ -326,8 +326,7 @@ void isamb_close (ISAMB isamb) 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; @@ -1008,6 +1007,63 @@ void isamb_pp_close (ISAMB_PP pp) 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 diff --git a/isamb/tstisamb.c b/isamb/tstisamb.c index 872ef0a..66a2b2f 100644 --- a/isamb/tstisamb.c +++ b/isamb/tstisamb.c @@ -1,4 +1,4 @@ -/* $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 @@ -26,6 +26,18 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include +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; @@ -172,13 +184,10 @@ void tst_insert(ISAMB isb, int n) } 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;