IDZEBRA  2.1.2
kdump.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <stdio.h>
24 #include <string.h>
25 #include <assert.h>
26 #include <stdlib.h>
27 #ifdef WIN32
28 #include <io.h>
29 #endif
30 #if HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
33 #include <assert.h>
34 
35 #include <charmap.h>
36 #include "index.h"
37 
38 char *prog;
39 
40 int main(int argc, char **argv)
41 {
42  exit(0);
43 }
44 
45 #if 0
46 /* old kdumper.. must be updated to use new codec .. */
47 int key_file_decode (FILE *f)
48 {
49  int c, d;
50 
51  c = getc (f);
52  switch (c & 192)
53  {
54  case 0:
55  d = c;
56  break;
57  case 64:
58  d = ((c&63) << 8) + (getc (f) & 0xff);
59  break;
60  case 128:
61  d = ((c&63) << 8) + (getc (f) & 0xff);
62  d = (d << 8) + (getc (f) & 0xff);
63  break;
64  case 192:
65  d = ((c&63) << 8) + (getc (f) & 0xff);
66  d = (d << 8) + (getc (f) & 0xff);
67  d = (d << 8) + (getc (f) & 0xff);
68  break;
69  default:
70  d = 0;
71  assert (0);
72  }
73  return d;
74 }
75 
76 
77 static int read_one (FILE *inf, char *name, char *key, struct it_key *prevk)
78 {
79  int c;
80  int i = 0;
81  struct it_key itkey;
82  do
83  {
84  if ((c=getc(inf)) == EOF)
85  return 0;
86  name[i++] = c;
87  } while (c);
88  if (i > 1)
89  prevk->sysno = 0;
90  c = key_file_decode (inf);
91  key[0] = c & 1;
92  c = c >> 1;
93  itkey.sysno = c + prevk->sysno;
94  if (c)
95  {
96  prevk->sysno = itkey.sysno;
97  prevk->seqno = 0;
98  }
99  c = key_file_decode (inf);
100  itkey.seqno = c + prevk->seqno;
101  prevk->seqno = itkey.seqno;
102 
103  memcpy (key+1, &itkey, sizeof(itkey));
104  return 1;
105 }
106 
107 
108 int main (int argc, char **argv)
109 {
110  int ret;
111  char *arg;
112  char *key_fname = NULL;
113  char key_string[IT_MAX_WORD];
114  char key_info[256];
115  ZebraMaps zm;
116  FILE *inf;
117  Res res = NULL;
118  struct it_key prevk;
119 
120  prevk.sysno = 0;
121  prevk.seqno = 0;
122 
123  prog = *argv;
124  while ((ret = options ("c:v:", argv, argc, &arg)) != -2)
125  {
126  if (ret == 0)
127  {
128  key_fname = arg;
129  }
130  else if (ret == 'v')
131  {
132  yaz_log_init (yaz_log_mask_str(arg), prog, NULL);
133  }
134  else if (ret == 'c')
135  {
136  if (!(res = res_open (arg, 0, 0)))
137  {
138  yaz_log(YLOG_FATAL, "Failed to open resource file %s", arg);
139  exit (1);
140  }
141  }
142  else
143  {
144  yaz_log (YLOG_FATAL, "Unknown option '-%s'", arg);
145  exit (1);
146  }
147  }
148  if (!key_fname)
149  {
150  fprintf (stderr, "kdump [-c config] [-v log] file\n");
151  exit (1);
152  }
153  if (!res)
154  res = res_open ("zebra.cfg", 0, 0);
155  zm = zebra_maps_open (res, 0);
156  if (!(inf = fopen (key_fname, "r")))
157  {
158  yaz_log (YLOG_FATAL|YLOG_ERRNO, "fopen %s", key_fname);
159  exit (1);
160  }
161  printf ("t rg op sysno seqno txt\n");
162  while (read_one (inf, key_string, key_info, &prevk))
163  {
164  struct it_key k;
165  int op;
166  char keybuf[IT_MAX_WORD+1];
167  char *to = keybuf;
168  const char *from = key_string;
169  int usedb_type = from[0];
170  int reg_type = from[1];
171 
172  op = key_info[0];
173  memcpy (&k, 1+key_info, sizeof(k));
174 
175  from += 2;
176  while (*from)
177  {
178  const char *res = zebra_maps_output (zm, reg_type, &from);
179  if (!res)
180  *to++ = *from++;
181  else
182  while (*res)
183  *to++ = *res++;
184  }
185  *to = '\0';
186  printf ("%c %3d %c %7d %5d %s\n", reg_type, usedb_type, op ? 'i':'d',
187  k.sysno, k.seqno, keybuf);
188  }
189  zebra_maps_close (zm);
190  if (fclose (inf))
191  {
192  yaz_log (YLOG_FATAL|YLOG_ERRNO, "fclose %s", key_fname);
193  exit (1);
194  }
195  exit (0);
196 }
197 #endif
198 /*
199  * Local variables:
200  * c-basic-offset: 4
201  * c-file-style: "Stroustrup"
202  * indent-tabs-mode: nil
203  * End:
204  * vim: shiftwidth=4 tabstop=8 expandtab
205  */
206 
int main(int argc, char **argv)
Definition: kdump.c:40
static FILE * inf
Definition: readfile.c:37
zebra_maps_t zebra_maps_open(Res res, const char *base_path, const char *profile_path)
Definition: zebramap.c:323
#define IT_MAX_WORD
Definition: it_key.h:27
Definition: res.c:46
void zebra_maps_close(zebra_maps_t zm)
Definition: zebramap.c:83
Res res_open(Res res_def, Res over_res)
Definition: res.c:234
char * prog
Definition: kdump.c:38
Definition: it_key.h:30
const char * zebra_maps_output(zebra_map_t zm, const char **from)
Definition: zebramap.c:437