2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Id: marcdump.c,v 1.20 2003-01-06 08:20:28 adam Exp $
25 #include <yaz/marcdisp.h>
26 #include <yaz/yaz-util.h>
27 #include <yaz/xmalloc.h>
28 #include <yaz/options.h>
37 static void usage(const char *prog)
39 fprintf (stderr, "Usage: %s [-c cfile] [-f from] [-t to] [-x] [-O] [-X] [-v] file...\n",
43 int main (int argc, char **argv)
54 char *from = 0, *to = 0;
58 setlocale(LC_CTYPE, "");
61 to = nl_langinfo(CODESET);
64 while ((r = options("vc:xOXf:t:", argv, argc, &arg)) != -2)
79 cfile = fopen (arg, "w");
82 xml = YAZ_MARC_SIMPLEXML;
85 xml = YAZ_MARC_OAIMARC;
88 xml = YAZ_MARC_MARCXML;
91 inf = fopen (arg, "r");
95 fprintf (stderr, "%s: cannot open %s:%s\n",
96 prog, arg, strerror (errno));
100 fprintf (cfile, "char *marc_records[] = {\n");
103 yaz_marc_t mt = yaz_marc_create();
108 cd = yaz_iconv_open(to, from);
111 fprintf(stderr, "conversion from %s to %s "
112 "unsupported\n", from, to);
116 yaz_marc_xml(mt, xml);
117 yaz_marc_debug(mt, verbose);
124 r = fread (buf, 1, 5, inf);
127 len = atoi_n(buf, 5);
128 if (len < 25 || len > 100000)
131 r = fread (buf + 5, 1, len, inf);
134 r = yaz_marc_decode_buf (mt, buf, -1, &result, &rlen);
138 fwrite (result, rlen, 1, stdout);
142 size_t inbytesleft = rlen;
143 const char *inp = result;
148 size_t outbytesleft = sizeof(outbuf);
150 size_t r = yaz_iconv (cd, (char**) &inp,
152 &outp, &outbytesleft);
153 if (r == (size_t) (-1))
155 int e = yaz_iconv_error(cd);
156 if (e != YAZ_ICONV_E2BIG)
159 fwrite (outbuf, outp - outbuf, 1, stdout);
168 fprintf (cfile, ",");
169 fprintf (cfile, "\n");
170 for (i = 0; i < r; i++)
173 fprintf (cfile, " \"");
174 fprintf (cfile, "\\x%02X", p[i] & 255);
176 if (i < r - 1 && (i & 15) == 15)
177 fprintf (cfile, "\"\n");
180 fprintf (cfile, "\"\n");
188 fprintf (cfile, "};\n");