1 /* $Id: kdump.c,v 1.29 2005-06-14 20:28:54 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
39 int main(int argc, char **argv)
45 /* old kdumper.. must be updated to use new codec .. */
46 int key_file_decode (FILE *f)
57 d = ((c&63) << 8) + (getc (f) & 0xff);
60 d = ((c&63) << 8) + (getc (f) & 0xff);
61 d = (d << 8) + (getc (f) & 0xff);
64 d = ((c&63) << 8) + (getc (f) & 0xff);
65 d = (d << 8) + (getc (f) & 0xff);
66 d = (d << 8) + (getc (f) & 0xff);
76 static int read_one (FILE *inf, char *name, char *key, struct it_key *prevk)
83 if ((c=getc(inf)) == EOF)
89 c = key_file_decode (inf);
92 itkey.sysno = c + prevk->sysno;
95 prevk->sysno = itkey.sysno;
98 c = key_file_decode (inf);
99 itkey.seqno = c + prevk->seqno;
100 prevk->seqno = itkey.seqno;
102 memcpy (key+1, &itkey, sizeof(itkey));
107 int main (int argc, char **argv)
111 char *key_fname = NULL;
112 char key_string[IT_MAX_WORD];
123 while ((ret = options ("c:v:", argv, argc, &arg)) != -2)
131 yaz_log_init (yaz_log_mask_str(arg), prog, NULL);
135 if (!(res = res_open (arg, 0, 0)))
137 yaz_log(YLOG_FATAL, "Failed to open resource file %s", arg);
143 yaz_log (YLOG_FATAL, "Unknown option '-%s'", arg);
149 fprintf (stderr, "kdump [-c config] [-v log] file\n");
153 res = res_open ("zebra.cfg", 0, 0);
154 zm = zebra_maps_open (res, 0);
155 if (!(inf = fopen (key_fname, "r")))
157 yaz_log (YLOG_FATAL|YLOG_ERRNO, "fopen %s", key_fname);
160 printf ("t rg op sysno seqno txt\n");
161 while (read_one (inf, key_string, key_info, &prevk))
165 char keybuf[IT_MAX_WORD+1];
167 const char *from = key_string;
168 int usedb_type = from[0];
169 int reg_type = from[1];
172 memcpy (&k, 1+key_info, sizeof(k));
177 const char *res = zebra_maps_output (zm, reg_type, &from);
185 printf ("%c %3d %c %7d %5d %s\n", reg_type, usedb_type, op ? 'i':'d',
186 k.sysno, k.seqno, keybuf);
188 zebra_maps_close (zm);
191 yaz_log (YLOG_FATAL|YLOG_ERRNO, "fclose %s", key_fname);