2 * Copyright (c) 1995-2002, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: marcdump.c,v 1.18 2002-12-03 10:03:27 adam Exp $
17 #include <yaz/marcdisp.h>
18 #include <yaz/yaz-util.h>
19 #include <yaz/xmalloc.h>
20 #include <yaz/options.h>
29 static void usage(const char *prog)
31 fprintf (stderr, "Usage: %s [-c cfile] [-x] [-O] [-X] [-v] file...\n",
35 int main (int argc, char **argv)
47 while ((r = options("vc:xOX", argv, argc, &arg)) != -2)
56 cfile = fopen (arg, "w");
62 xml = YAZ_MARC_OAIMARC;
65 xml = YAZ_MARC_MARCXML;
68 inf = fopen (arg, "r");
72 fprintf (stderr, "%s: cannot open %s:%s\n",
73 prog, arg, strerror (errno));
77 fprintf (cfile, "char *marc_records[] = {\n");
80 WRBUF wr = wrbuf_alloc();
84 r = fread (buf, 1, 5, inf);
88 if (len < 25 || len > 100000)
91 r = fread (buf + 5, 1, len, inf);
94 r = yaz_marc_decode (buf, wr, verbose, -1, xml);
97 fwrite (wrbuf_buf(wr), wrbuf_len(wr), 1, stdout);
103 fprintf (cfile, ",");
104 fprintf (cfile, "\n");
105 for (i = 0; i < r; i++)
108 fprintf (cfile, " \"");
109 fprintf (cfile, "\\x%02X", p[i] & 255);
111 if (i < r - 1 && (i & 15) == 15)
112 fprintf (cfile, "\"\n");
115 fprintf (cfile, "\"\n");
120 fprintf (cfile, "};\n");