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.22 2003-02-25 18:35:49 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, "");
62 to = nl_langinfo(CODESET);
66 while ((r = options("vc:xOXf:t:", argv, argc, &arg)) != -2)
81 cfile = fopen (arg, "w");
84 xml = YAZ_MARC_SIMPLEXML;
87 xml = YAZ_MARC_OAIMARC;
90 xml = YAZ_MARC_MARCXML;
93 inf = fopen (arg, "r");
97 fprintf (stderr, "%s: cannot open %s:%s\n",
98 prog, arg, strerror (errno));
102 fprintf (cfile, "char *marc_records[] = {\n");
105 yaz_marc_t mt = yaz_marc_create();
110 cd = yaz_iconv_open(to, from);
113 fprintf(stderr, "conversion from %s to %s "
114 "unsupported\n", from, to);
118 yaz_marc_xml(mt, xml);
119 yaz_marc_debug(mt, verbose);
126 r = fread (buf, 1, 5, inf);
129 len = atoi_n(buf, 5);
130 if (len < 25 || len > 100000)
133 r = fread (buf + 5, 1, len, inf);
136 r = yaz_marc_decode_buf (mt, buf, -1, &result, &rlen);
140 fwrite (result, rlen, 1, stdout);
144 size_t inbytesleft = rlen;
145 const char *inp = result;
149 size_t outbytesleft = sizeof(outbuf);
151 size_t r = yaz_iconv (cd, (char**) &inp,
153 &outp, &outbytesleft);
154 if (r == (size_t) (-1))
156 int e = yaz_iconv_error(cd);
157 if (e != YAZ_ICONV_E2BIG)
160 fwrite (outbuf, outp - outbuf, 1, stdout);
169 fprintf (cfile, ",");
170 fprintf (cfile, "\n");
171 for (i = 0; i < r; i++)
174 fprintf (cfile, " \"");
175 fprintf (cfile, "\\x%02X", p[i] & 255);
177 if (i < r - 1 && (i & 15) == 15)
178 fprintf (cfile, "\"\n");
181 fprintf (cfile, "\"\n");
189 fprintf (cfile, "};\n");