X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fmarcdump.c;h=e65aed5715a83de9e1b9c1846d0c186887d901e3;hb=f98b671ac4ece0194de14c04ef7c281a410e0831;hp=254c2d48b3a7d72b7521678d4ff8bf1593d64294;hpb=cd2f012a70ebadf660acb71936e32192287dc30a;p=yaz-moved-to-github.git diff --git a/util/marcdump.c b/util/marcdump.c index 254c2d4..e65aed5 100644 --- a/util/marcdump.c +++ b/util/marcdump.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2006, Index Data ApS + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: marcdump.c,v 1.45 2006-12-15 19:28:48 adam Exp $ + * $Id: marcdump.c,v 1.53 2007-09-23 07:40:13 adam Exp $ */ #define _FILE_OFFSET_BITS 64 @@ -52,7 +52,7 @@ static void usage(const char *prog) { fprintf (stderr, "Usage: %s [-c cfile] [-f from] [-t to] " "[-i format] [-o format] " - "[-n] [-l pos=value] [-v] [-C chunk] [-s splitfname] file...\n", + "[-n] [-l pos=value] [-v] [-C chunk] [-s splitfname] [-p] file...\n", prog); } @@ -90,8 +90,8 @@ static void marcdump_read_line(yaz_marc_t mt, const char *fname) { WRBUF wrbuf = wrbuf_alloc(); yaz_marc_write_mode(mt, wrbuf); - fputs(wrbuf_buf(wrbuf), stdout); - wrbuf_free(wrbuf, 1); + fputs(wrbuf_cstr(wrbuf), stdout); + wrbuf_destroy(wrbuf); } fclose(inf); } @@ -116,9 +116,9 @@ static void marcdump_read_xml(yaz_marc_t mt, const char *fname) { yaz_marc_write_mode(mt, wrbuf); - fputs(wrbuf_buf(wrbuf), stdout); + fputs(wrbuf_cstr(wrbuf), stdout); } - wrbuf_free(wrbuf, 1); + wrbuf_destroy(wrbuf); } xmlFreeDoc(doc); } @@ -126,6 +126,7 @@ 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 input_format, int output_format, + int write_using_libxml2, int print_offset, const char *split_fname, int split_chunk, int verbose, FILE *cfile, const char *leader_spec) { @@ -151,6 +152,7 @@ static void dump(const char *fname, const char *from, const char *to, yaz_marc_iconv(mt, cd); } yaz_marc_xml(mt, output_format); + yaz_marc_write_using_libxml2(mt, write_using_libxml2); yaz_marc_debug(mt, verbose); if (input_format == YAZ_MARC_MARCXML || input_format == YAZ_MARC_XCHANGE) @@ -179,10 +181,10 @@ static void dump(const char *fname, const char *from, const char *to, fprintf (cfile, "char *marc_records[] = {\n"); for(;; marc_no++) { - char *result = 0; + const char *result = 0; size_t len; size_t rlen; - int len_result; + size_t len_result; size_t r; char buf[100001]; @@ -233,6 +235,15 @@ static void dump(const char *fname, const char *from, const char *to, r = fread (buf + 5, 1, rlen, inf); if (r < rlen) break; + while (buf[len-1] != ISO2709_RS) + { + if (len > sizeof(buf)-2) + break; + r = fread (buf + len, 1, 1, inf); + if (r != 1) + break; + len++; + } if (split_fname) { char fname[256]; @@ -263,7 +274,7 @@ static void dump(const char *fname, const char *from, const char *to, fclose(sf); } } - len_result = (int) rlen; + len_result = rlen; r = yaz_marc_decode_buf(mt, buf, -1, &result, &len_result); if (r > 0 && result) { @@ -315,7 +326,8 @@ int main (int argc, char **argv) int split_chunk = 1; const char *split_fname = 0; const char *leader_spec = 0; - + int write_using_libxml2 = 0; + #if HAVE_LOCALE_H setlocale(LC_CTYPE, ""); #endif @@ -338,8 +350,24 @@ int main (int argc, char **argv) fprintf(stderr, "%s: bad input format: %s\n", prog, arg); exit(1); } +#if YAZ_HAVE_XML2 +#else + if (input_format == YAZ_MARC_MARCXML + || input_format == YAZ_MARC_XCHANGE) + { + fprintf(stderr, "%s: Libxml2 support not enabled\n", prog); + exit(3); + } +#endif break; case 'o': + /* dirty hack so we can make Libxml2 do the writing .. + rather than WRBUF */ + if (strlen(arg) > 4 && strncmp(arg, "xml,", 4) == 0) + { + arg = arg + 4; + write_using_libxml2 = 1; + } output_format = yaz_marc_decode_formatstr(arg); if (output_format == -1) { @@ -400,6 +428,7 @@ int main (int argc, char **argv) break; case 0: dump(arg, from, to, input_format, output_format, + write_using_libxml2, print_offset, split_fname, split_chunk, verbose, cfile, leader_spec); break;