1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
11 #include <yaz/options.h>
12 #include <yaz/record_conv.h>
13 #include <yaz/backtrace.h>
15 const char *prog = "yaz-record-conv";
17 static void usage(void)
19 fprintf(stderr, "%s: usage\nyaz-record-conf config file ..\n", prog);
22 int main (int argc, char **argv)
26 yaz_record_conv_t p = 0;
29 yaz_enable_panic_backtrace(*argv);
30 while ((r = options("V", argv, argc, &arg)) != -2)
40 xmlDocPtr doc = xmlParseFile(arg);
43 p = yaz_record_conv_create();
46 xmlNodePtr ptr = xmlDocGetRootElement(doc);
49 r = yaz_record_conv_configure(p, ptr);
52 fprintf(stderr, "record conf error: %s\n",
53 yaz_record_conv_get_error(p));
60 yaz_record_conv_destroy(p);
66 WRBUF input_record = wrbuf_alloc();
67 WRBUF output_record = wrbuf_alloc();
68 FILE *f = fopen(arg, "rb");
72 fprintf(stderr, "%s: open failed: %s\n",
76 while ((c = getc(f)) != EOF)
77 wrbuf_putc(input_record, c);
79 r = yaz_record_conv_record(p,
80 wrbuf_buf(input_record),
81 wrbuf_len(input_record),
85 fprintf(stderr, "%s: %s: Error %s\n",
87 yaz_record_conv_get_error(p));
92 fwrite(wrbuf_buf(output_record), 1,
93 wrbuf_len(output_record), stdout);
95 wrbuf_destroy(input_record);
96 wrbuf_destroy(output_record);
101 fprintf(stderr, "%s: YAZ not compiled with Libxml2 support\n",
111 yaz_record_conv_destroy(p);
120 * c-file-style: "Stroustrup"
121 * indent-tabs-mode: nil
123 * vim: shiftwidth=4 tabstop=8 expandtab