+static void show_version(void)
+{
+ char vstr[20], sha1_str[41];
+
+ yaz_version(vstr, sha1_str);
+ printf("YAZ version: %s %s\n", YAZ_VERSION, YAZ_VERSION_SHA1);
+ if (strcmp(sha1_str, YAZ_VERSION_SHA1))
+ printf("YAZ DLL/SO: %s %s\n", vstr, sha1_str);
+ exit(0);
+}
+
+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_cstr(wrbuf), stdout);
+ wrbuf_destroy(wrbuf);
+ }
+ fclose(inf);
+}
+