X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Frectext.c;h=cfa97c0b16f8bf6b75c9e6ef0db2dcd7a2b14b0c;hp=64cefe55051a11a087b612485c7aaf950a450e98;hb=78b13a3ac6a79768fb609c14db2a8e0c94a9c4da;hpb=4478d785b7769691261005c98063b98a5a5971b3 diff --git a/index/rectext.c b/index/rectext.c index 64cefe5..cfa97c0 100644 --- a/index/rectext.c +++ b/index/rectext.c @@ -1,8 +1,5 @@ -/* $Id: rectext.c,v 1.2 2006-08-14 10:40:15 adam Exp $ - Copyright (C) 1995-2006 - Index Data ApS - -This file is part of the Zebra server. +/* This file is part of the Zebra server. + Copyright (C) 1995-2008 Index Data Zebra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -27,12 +24,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include struct filter_info { char *sep; }; -static void *filter_init (Res res, RecType recType) +static void *filter_init(Res res, RecType recType) { struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo)); tinfo->sep = 0; @@ -49,11 +47,11 @@ static ZEBRA_RES filter_config(void *clientData, Res res, const char *args) return ZEBRA_OK; } -static void filter_destroy (void *clientData) +static void filter_destroy(void *clientData) { struct filter_info *tinfo = clientData; - xfree (tinfo->sep); - xfree (tinfo); + xfree(tinfo->sep); + xfree(tinfo); } struct buf_info { @@ -63,24 +61,24 @@ struct buf_info { int max; }; -static struct buf_info *buf_open (struct recExtractCtrl *p) +static struct buf_info *buf_open(struct recExtractCtrl *p) { - struct buf_info *fi = (struct buf_info *) xmalloc (sizeof(*fi)); + struct buf_info *fi = (struct buf_info *) xmalloc(sizeof(*fi)); fi->p = p; - fi->buf = (char *) xmalloc (4096); + 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) +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->max = fi->p->stream->readf(fi->p->stream, fi->buf, 4096); fi->offset = 0; if (fi->max <= 0) return 0; @@ -88,26 +86,27 @@ static int buf_getchar (struct filter_info *tinfo, struct buf_info *fi, char *ds *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)); + off_t off = fi->p->stream->tellf(fi->p->stream); + off_t end_offset = off - (fi->max - fi->offset); + fi->p->stream->endf(fi->p->stream, &end_offset); return 0; } return 1; } -static void buf_close (struct buf_info *fi) +static void buf_close(struct buf_info *fi) { - xfree (fi->buf); - xfree (fi); + xfree(fi->buf); + xfree(fi); } -static int filter_extract (void *clientData, struct recExtractCtrl *p) +static int filter_extract(void *clientData, struct recExtractCtrl *p) { struct filter_info *tinfo = clientData; char w[512]; RecWord recWord; int r; - struct buf_info *fi = buf_open (p); + struct buf_info *fi = buf_open(p); int no_read = 0; #if 0 @@ -119,11 +118,11 @@ static int filter_extract (void *clientData, struct recExtractCtrl *p) { int i = 0; - r = buf_getchar (tinfo, fi, w); + r = buf_getchar(tinfo, fi, w); while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r') { i++; - r = buf_getchar (tinfo, fi, w + i); + r = buf_getchar(tinfo, fi, w + i); } if (i) { @@ -133,13 +132,13 @@ static int filter_extract (void *clientData, struct recExtractCtrl *p) (*p->tokenAdd)(&recWord); } } while (r > 0); - buf_close (fi); + buf_close(fi); if (no_read == 0) return RECCTRL_EXTRACT_EOF; return RECCTRL_EXTRACT_OK; } -static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) +static int filter_retrieve(void *clientData, struct recRetrieveCtrl *p) { int r, filter_ptr = 0; static char *filter_buf = NULL; @@ -175,11 +174,11 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) char *nb; filter_size = 2*filter_size + 8192; - nb = (char *) xmalloc (filter_size); + nb = (char *) xmalloc(filter_size); if (filter_buf) { - memcpy (nb, filter_buf, filter_ptr); - xfree (filter_buf); + memcpy(nb, filter_buf, filter_ptr); + xfree(filter_buf); } filter_buf = nb; } @@ -187,22 +186,22 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) { if (p->score >= 0) { - sprintf (filter_buf, "Rank: %d\n", p->score); + sprintf(filter_buf, "Rank: %d\n", p->score); filter_ptr = strlen(filter_buf); } - sprintf (filter_buf + filter_ptr, "Local Number: " ZINT_FORMAT "\n", + sprintf(filter_buf + filter_ptr, "Local Number: " ZINT_FORMAT "\n", p->localno); filter_ptr = strlen(filter_buf); if (p->fname) { - sprintf (filter_buf + filter_ptr, "Filename: %s\n", p->fname); + sprintf(filter_buf + filter_ptr, "Filename: %s\n", p->fname); filter_ptr = strlen(filter_buf); } strcpy(filter_buf+filter_ptr++, "\n"); } if (!make_body) break; - r = (*p->readf)(p->fh, filter_buf + filter_ptr, 4096); + r = p->stream->readf(p->stream, filter_buf + filter_ptr, 4096); if (r <= 0) break; filter_ptr += r; @@ -210,9 +209,9 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) filter_buf[filter_ptr] = '\0'; if (elementSetName) { - if (!strcmp (elementSetName, "B")) + if (!strcmp(elementSetName, "B")) no_lines = 4; - if (!strcmp (elementSetName, "M")) + if (!strcmp(elementSetName, "M")) no_lines = 20; } if (no_lines) @@ -220,7 +219,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) char *p = filter_buf; int i = 0; - while (++i <= no_lines && (p = strchr (p, '\n'))) + while (++i <= no_lines && (p = strchr(p, '\n'))) p++; if (p) { @@ -228,7 +227,7 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) filter_ptr = p-filter_buf; } } - p->output_format = VAL_SUTRS; + p->output_format = yaz_oid_recsyn_sutrs; p->rec_buf = filter_buf; p->rec_len = filter_ptr; return 0;