-/* $Id: rectext.c,v 1.16 2004-03-22 20:52:11 adam Exp $
+/* $Id: rectext.c,v 1.21 2004-09-28 10:15:03 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <ctype.h>
#include <zebrautl.h>
-#include "rectext.h"
+#include <idzebra/recctrl.h>
-static void *text_init (RecType recType)
+struct text_info {
+ char *sep;
+};
+
+static void *text_init (Res res, RecType recType)
{
- return 0;
+ struct text_info *tinfo = (struct text_info *) xmalloc(sizeof(*tinfo));
+ tinfo->sep = 0;
+ return tinfo;
+}
+
+static void text_config(void *clientData, Res res, const char *args)
+{
+
}
static void text_destroy (void *clientData)
{
+ struct text_info *tinfo = clientData;
+ xfree (tinfo->sep);
+ xfree (tinfo);
}
struct buf_info {
return fi;
}
-int buf_read (struct buf_info *fi, char *dst)
+int buf_read (struct text_info *tinfo, struct buf_info *fi, char *dst)
{
if (fi->offset >= fi->max)
{
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;
}
static int text_extract (void *clientData, struct recExtractCtrl *p)
{
+ struct text_info *tinfo = clientData;
char w[512];
RecWord recWord;
int r;
struct buf_info *fi = buf_open (p);
+#if 0
+ yaz_log(LOG_LOG, "text_extract off=%ld",
+ (long) (*fi->p->tellf)(fi->p->fh));
+#endif
+ xfree(tinfo->sep);
+ tinfo->sep = 0;
(*p->init)(p, &recWord);
recWord.reg_type = 'w';
do
{
int i = 0;
- r = buf_read (fi, w);
+ r = buf_read (tinfo, fi, w);
while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
{
i++;
- r = buf_read (fi, w + i);
- }
+ r = buf_read (tinfo, fi, w + i);
+ }
if (i)
{
recWord.string = w;
sprintf (text_buf, "Rank: %d\n", p->score);
text_ptr = strlen(text_buf);
}
- sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
+ sprintf (text_buf + text_ptr, "Local Number: " ZINT_FORMAT "\n",
+ p->localno);
text_ptr = strlen(text_buf);
if (p->fname)
{
static struct recType text_type = {
"text",
text_init,
+ text_config,
text_destroy,
text_extract,
text_retrieve
};
-RecType recTypeText = &text_type;
+RecType
+#ifdef IDZEBRA_STATIC_TEXT
+idzebra_filter_text
+#else
+idzebra_filter
+#endif
+
+[] = {
+ &text_type,
+ 0,
+};