X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fmarcdump.c;h=c27e44f22425562326d13c2be76f1f402d556082;hb=cddd92d66e3a59179357c552a53cd7cba43f646f;hp=8014113897bec58d7088c36a17dfb3b3159fded7;hpb=d57ade59211707b9bcfacc61039e446c9fa3f36f;p=yaz-moved-to-github.git diff --git a/util/marcdump.c b/util/marcdump.c index 8014113..c27e44f 100644 --- a/util/marcdump.c +++ b/util/marcdump.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2006, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdump.c,v 1.37 2006-04-21 10:28:07 adam Exp $ + * $Id: marcdump.c,v 1.42 2006-08-28 14:18:23 adam Exp $ */ #define _FILE_OFFSET_BITS 64 @@ -11,7 +11,7 @@ #include #endif -#if HAVE_XML2 +#if YAZ_HAVE_XML2 #include #include @@ -50,11 +50,12 @@ static char *prog; static void usage(const char *prog) { - fprintf (stderr, "Usage: %s [-c cfile] [-f from] [-t to] [-x] [-X] [-e] [-I] [-v] [-s splitfname] file...\n", + fprintf (stderr, "Usage: %s [-c cfile] [-f from] [-t to] [-x] [-X] [-e] " + "[-I] [-l pos=value] [-v] [-s splitfname] file...\n", prog); } -#if HAVE_XML2 +#if YAZ_HAVE_XML2 static void marcdump_read_xml(yaz_marc_t mt, const char *fname) { xmlNodePtr ptr; @@ -84,11 +85,17 @@ static void marcdump_read_xml(yaz_marc_t mt, const char *fname) static void dump(const char *fname, const char *from, const char *to, int read_xml, int xml, int print_offset, const char *split_fname, int verbose, - FILE *cfile) + FILE *cfile, const char *leader_spec) { yaz_marc_t mt = yaz_marc_create(); yaz_iconv_t cd = 0; - + + if (yaz_marc_leader_spec(mt, leader_spec)) + { + fprintf(stderr, "bad leader spec: %s\n", leader_spec); + yaz_marc_destroy(mt); + exit(2); + } if (from && to) { cd = yaz_iconv_open(to, from); @@ -96,6 +103,7 @@ static void dump(const char *fname, const char *from, const char *to, { fprintf(stderr, "conversion from %s to %s " "unsupported\n", from, to); + yaz_marc_destroy(mt); exit(2); } yaz_marc_iconv(mt, cd); @@ -105,7 +113,7 @@ static void dump(const char *fname, const char *from, const char *to, if (read_xml) { -#if HAVE_XML2 +#if YAZ_HAVE_XML2 marcdump_read_xml(mt, fname); #else return; @@ -129,9 +137,9 @@ static void dump(const char *fname, const char *from, const char *to, int marc_no = 0; for(;; marc_no++) { - int len; + size_t len; char *result = 0; - int rlen; + size_t rlen; size_t r; char buf[100001]; @@ -204,7 +212,11 @@ static void dump(const char *fname, const char *from, const char *to, fclose(sf); } } - r = yaz_marc_decode_buf (mt, buf, -1, &result, &rlen); + { + int rlentmp = (int) rlen; + r = yaz_marc_decode_buf(mt, buf, -1, &result, &rlentmp); + rlen = (size_t) rlentmp; + } if (r > 0 && result) { fwrite (result, rlen, 1, stdout); @@ -212,7 +224,7 @@ static void dump(const char *fname, const char *from, const char *to, if (r > 0 && cfile) { char *p = buf; - int i; + size_t i; if (count) fprintf (cfile, ","); fprintf (cfile, "\n"); @@ -255,6 +267,7 @@ int main (int argc, char **argv) char *from = 0, *to = 0; int read_xml = 0; const char *split_fname = 0; + const char *leader_spec = 0; #if HAVE_LOCALE_H setlocale(LC_CTYPE, ""); @@ -266,11 +279,14 @@ int main (int argc, char **argv) #endif prog = *argv; - while ((r = options("pvc:xOeXIf:t:s:", argv, argc, &arg)) != -2) + while ((r = options("pvc:xOeXIf:t:s:l:", argv, argc, &arg)) != -2) { no++; switch (r) { + case 'l': + leader_spec = arg; + break; case 'f': from = arg; break; @@ -283,7 +299,7 @@ int main (int argc, char **argv) cfile = fopen(arg, "w"); break; case 'x': -#if HAVE_XML2 +#if YAZ_HAVE_XML2 read_xml = 1; #else fprintf(stderr, "%s: -x not supported." @@ -313,7 +329,7 @@ int main (int argc, char **argv) break; case 0: dump(arg, from, to, read_xml, xml, - print_offset, split_fname, verbose, cfile); + print_offset, split_fname, verbose, cfile, leader_spec); break; case 'v': verbose++;