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.16 2002-03-18 21:33:48 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] [-v] file...\n", prog);
35 int main (int argc, char **argv)
47 while ((r = options("vc:x", argv, argc, &arg)) != -2)
56 cfile = fopen (arg, "w");
62 inf = fopen (arg, "r");
66 fprintf (stderr, "%s: cannot open %s:%s\n",
67 prog, arg, strerror (errno));
71 fprintf (cfile, "char *marc_records[] = {\n");
74 WRBUF wr = wrbuf_alloc();
78 r = fread (buf, 1, 5, inf);
82 if (len < 25 || len > 100000)
85 r = fread (buf + 5, 1, len, inf);
88 r = yaz_marc_decode (buf, wr, verbose, -1, xml);
91 fwrite (wrbuf_buf(wr), wrbuf_len(wr), 1, stdout);
98 fprintf (cfile, "\n");
99 for (i = 0; i < r; i++)
102 fprintf (cfile, " \"");
103 fprintf (cfile, "\\x%02X", p[i] & 255);
105 if (i < r - 1 && (i & 15) == 15)
106 fprintf (cfile, "\"\n");
109 fprintf (cfile, "\"\n");
114 fprintf (cfile, "};\n");