+#include <idzebra/util.h>
+#include <idzebra/recctrl.h>
+
+struct filter_info {
+ char *sep;
+};
+
+static void *filter_init (Res res, RecType recType)
+{
+ struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo));
+ tinfo->sep = 0;
+ return tinfo;
+}
+
+static void filter_config(void *clientData, Res res, const char *args)
+{
+ struct filter_info *tinfo = (struct filter_info*) clientData;
+ xfree(tinfo->sep);
+ tinfo->sep = 0;
+ if (args && *args)
+ tinfo->sep = xstrdup(args);
+}
+
+static void filter_destroy (void *clientData)
+{
+ struct filter_info *tinfo = clientData;
+ xfree (tinfo->sep);
+ xfree (tinfo);
+}
+
+struct buf_info {
+ struct recExtractCtrl *p;
+ char *buf;
+ int offset;
+ int max;
+};
+
+static struct buf_info *buf_open (struct recExtractCtrl *p)
+{
+ struct buf_info *fi = (struct buf_info *) xmalloc (sizeof(*fi));
+
+ fi->p = p;
+ fi->buf = (char *) xmalloc (4096);
+ fi->offset = 1;
+ fi->max = 1;
+ return fi;
+}
+
+static int buf_getchar (struct filter_info *tinfo, struct buf_info *fi, char *dst)
+{
+ if (fi->offset >= fi->max)
+ {
+ if (fi->max <= 0)
+ return 0;
+ fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
+ fi->offset = 0;
+ if (fi->max <= 0)
+ return 0;
+ }
+ *dst = fi->buf[(fi->offset)++];
+ if (tinfo->sep && *dst == *tinfo->sep)
+ {
+ off_t off = (*fi->p->tellf)(fi->p->fh);
+ (*fi->p->endf)(fi->p->fh, off - (fi->max - fi->offset));
+ return 0;
+ }
+ return 1;
+}