+static int getbyte_stream(void *client_data)
+{
+ FILE *f = (FILE*) client_data;
+
+ int c = fgetc(f);
+ if (c == EOF)
+ return 0;
+ return c;
+}
+
+static void ungetbyte_stream(int c, void *client_data)
+{
+ FILE *f = (FILE*) client_data;
+
+ if (c == 0)
+ c = EOF;
+ ungetc(c, f);
+}
+
+static void marcdump_read_line(yaz_marc_t mt, const char *fname)
+{
+ FILE *inf = fopen(fname, "rb");
+ if (!inf)
+ {
+ fprintf (stderr, "%s: cannot open %s:%s\n",
+ prog, fname, strerror (errno));
+ exit(1);
+ }
+
+ while (yaz_marc_read_line(mt, getbyte_stream,
+ ungetbyte_stream, inf) == 0)
+ {
+ WRBUF wrbuf = wrbuf_alloc();
+ yaz_marc_write_mode(mt, wrbuf);
+ fputs(wrbuf_buf(wrbuf), stdout);
+ wrbuf_free(wrbuf, 1);
+ }
+ fclose(inf);
+}
+
+#if YAZ_HAVE_XML2