1 /* $Id: kdump.c,v 1.30 2005-08-05 10:40:13 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 int main(int argc, char **argv)
46 /* old kdumper.. must be updated to use new codec .. */
47 int key_file_decode (FILE *f)
58 d = ((c&63) << 8) + (getc (f) & 0xff);
61 d = ((c&63) << 8) + (getc (f) & 0xff);
62 d = (d << 8) + (getc (f) & 0xff);
65 d = ((c&63) << 8) + (getc (f) & 0xff);
66 d = (d << 8) + (getc (f) & 0xff);
67 d = (d << 8) + (getc (f) & 0xff);
77 static int read_one (FILE *inf, char *name, char *key, struct it_key *prevk)
84 if ((c=getc(inf)) == EOF)
90 c = key_file_decode (inf);
93 itkey.sysno = c + prevk->sysno;
96 prevk->sysno = itkey.sysno;
99 c = key_file_decode (inf);
100 itkey.seqno = c + prevk->seqno;
101 prevk->seqno = itkey.seqno;
103 memcpy (key+1, &itkey, sizeof(itkey));
108 int main (int argc, char **argv)
112 char *key_fname = NULL;
113 char key_string[IT_MAX_WORD];
124 while ((ret = options ("c:v:", argv, argc, &arg)) != -2)
132 yaz_log_init (yaz_log_mask_str(arg), prog, NULL);
136 if (!(res = res_open (arg, 0, 0)))
138 yaz_log(YLOG_FATAL, "Failed to open resource file %s", arg);
144 yaz_log (YLOG_FATAL, "Unknown option '-%s'", arg);
150 fprintf (stderr, "kdump [-c config] [-v log] file\n");
154 res = res_open ("zebra.cfg", 0, 0);
155 zm = zebra_maps_open (res, 0);
156 if (!(inf = fopen (key_fname, "r")))
158 yaz_log (YLOG_FATAL|YLOG_ERRNO, "fopen %s", key_fname);
161 printf ("t rg op sysno seqno txt\n");
162 while (read_one (inf, key_string, key_info, &prevk))
166 char keybuf[IT_MAX_WORD+1];
168 const char *from = key_string;
169 int usedb_type = from[0];
170 int reg_type = from[1];
173 memcpy (&k, 1+key_info, sizeof(k));
178 const char *res = zebra_maps_output (zm, reg_type, &from);
186 printf ("%c %3d %c %7d %5d %s\n", reg_type, usedb_type, op ? 'i':'d',
187 k.sysno, k.seqno, keybuf);
189 zebra_maps_close (zm);
192 yaz_log (YLOG_FATAL|YLOG_ERRNO, "fclose %s", key_fname);