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.17 2002-10-04 10:19:58 adam Exp $
17 #include <yaz/wrbuf.h>
18 #include <yaz/marcdisp.h>
19 #include <yaz/yaz-util.h>
20 #include <yaz/xmalloc.h>
21 #include <yaz/options.h>
30 static void usage(const char *prog)
32 fprintf (stderr, "Usage: %s [-c cfile] [-x] [-O] [-v] file...\n", prog);
35 int main (int argc, char **argv)
47 while ((r = options("vc:xO", argv, argc, &arg)) != -2)
56 cfile = fopen (arg, "w");
65 inf = fopen (arg, "r");
69 fprintf (stderr, "%s: cannot open %s:%s\n",
70 prog, arg, strerror (errno));
74 fprintf (cfile, "char *marc_records[] = {\n");
77 WRBUF wr = wrbuf_alloc();
81 r = fread (buf, 1, 5, inf);
85 if (len < 25 || len > 100000)
88 r = fread (buf + 5, 1, len, inf);
91 r = yaz_marc_decode (buf, wr, verbose, -1, xml);
94 fwrite (wrbuf_buf(wr), wrbuf_len(wr), 1, stdout);
100 fprintf (cfile, ",");
101 fprintf (cfile, "\n");
102 for (i = 0; i < r; i++)
105 fprintf (cfile, " \"");
106 fprintf (cfile, "\\x%02X", p[i] & 255);
108 if (i < r - 1 && (i & 15) == 15)
109 fprintf (cfile, "\"\n");
112 fprintf (cfile, "\"\n");
117 fprintf (cfile, "};\n");