From 0bd27325c14ad88221c6909231682f0cf1e777fa Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 30 Apr 2010 21:44:48 +0200 Subject: [PATCH] Command line tool yaz-record-conv This is a simple program that allows testing of the record-conv utilities of YAZ (used by YAZ GFS and Metaproxy). --- util/.gitignore | 1 + util/Makefile.am | 5 ++- util/yaz-record-conv.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 util/yaz-record-conv.c diff --git a/util/.gitignore b/util/.gitignore index bdcde5e..352981d 100644 --- a/util/.gitignore +++ b/util/.gitignore @@ -21,3 +21,4 @@ yaz-xmlquery yaz-illclient yaz-icu yaz-json-parse +yaz-record-conv diff --git a/util/Makefile.am b/util/Makefile.am index f1fa8dd..be5bf68 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -11,7 +11,7 @@ AM_CPPFLAGS=-I$(top_srcdir)/include $(XML2_CFLAGS) $(ICU_CPPFLAGS) bin_PROGRAMS = yaz-marcdump yaz-iconv yaz-illclient yaz-icu yaz-json-parse noinst_PROGRAMS = cclsh cql2pqf cql2xcql srwtst yaz-benchmark \ - yaz-xmlquery + yaz-xmlquery yaz-record-conv # MARC dumper utility yaz_marcdump_SOURCES = marcdump.c @@ -48,3 +48,6 @@ yaz_icu_LDADD =../src/libyaz_icu.la ../src/libyaz.la $(ICU_LIBS) yaz_json_parse_SOURCES = json-parse.c yaz_json_parse_LDADD = ../src/libyaz.la +yaz_record_conv_SOURCES = yaz-record-conv.c +yaz_record_conv_LDADD = ../src/libyaz.la + diff --git a/util/yaz-record-conv.c b/util/yaz-record-conv.c new file mode 100644 index 0000000..4f943b6 --- /dev/null +++ b/util/yaz-record-conv.c @@ -0,0 +1,112 @@ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2010 Index Data + * See the file LICENSE for details. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include + +const char *prog = "yaz-record-conv"; + +static void usage(void) +{ + fprintf(stderr, "%s: usage\nyaz-record-conf config file ..\n", prog); + exit(1); +} +int main (int argc, char **argv) +{ + int r; + char *arg; + yaz_record_conv_t p = 0; + int no_errors = 0; + while ((r = options("V", argv, argc, &arg)) != -2) + { + switch (r) + { + case 'V': + break; + case 0: + if (!p) + { + xmlDocPtr doc = xmlParseFile(arg); + int r = -1; + + p = yaz_record_conv_create(); + if (doc) + { + xmlNodePtr ptr = xmlDocGetRootElement(doc); + if (ptr) + { + r = yaz_record_conv_configure(p, ptr); + if (r) + { + fprintf(stderr, "record conf error: %s\n", + yaz_record_conv_get_error(p)); + } + } + } + xmlFreeDoc(doc); + if (r) + { + yaz_record_conv_destroy(p); + exit(2); + } + } + else + { + WRBUF input_record = wrbuf_alloc(); + WRBUF output_record = wrbuf_alloc(); + FILE *f = fopen(arg, "rb"); + int c, r; + if (!f) + { + fprintf(stderr, "%s: open failed: %s\n", + prog, arg); + exit(3); + } + while ((c = getc(f)) != EOF) + wrbuf_putc(input_record, c); + + r = yaz_record_conv_record(p, + wrbuf_buf(input_record), + wrbuf_len(input_record), + output_record); + if (r) + { + fprintf(stderr, "%s: %s: Error %s\n", + prog, arg, + yaz_record_conv_get_error(p)); + no_errors++; + } + else + { + fwrite(wrbuf_buf(output_record), 1, + wrbuf_len(output_record), stdout); + } + wrbuf_destroy(input_record); + wrbuf_destroy(output_record); + fclose(f); + } + break; + default: + usage(); + } + } + yaz_record_conv_destroy(p); + if (no_errors) + exit(1); + exit(0); +} +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + -- 1.7.10.4