1 /* $Id: rectext.c,v 1.15 2002-08-02 19:26:56 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 static void *text_init (RecType recType)
36 static void text_destroy (void *clientData)
41 struct recExtractCtrl *p;
47 struct buf_info *buf_open (struct recExtractCtrl *p)
49 struct buf_info *fi = (struct buf_info *) xmalloc (sizeof(*fi));
52 fi->buf = (char *) xmalloc (4096);
58 int buf_read (struct buf_info *fi, char *dst)
60 if (fi->offset >= fi->max)
64 fi->max = (*fi->p->readf)(fi->p->fh, fi->buf, 4096);
69 *dst = fi->buf[(fi->offset)++];
73 void buf_close (struct buf_info *fi)
79 static int text_extract (void *clientData, struct recExtractCtrl *p)
84 struct buf_info *fi = buf_open (p);
86 (*p->init)(p, &recWord);
87 recWord.reg_type = 'w';
93 while (r > 0 && i < 511 && w[i] != '\n' && w[i] != '\r')
96 r = buf_read (fi, w + i);
102 (*p->tokenAdd)(&recWord);
106 return RECCTRL_EXTRACT_OK;
109 static int text_retrieve (void *clientData, struct recRetrieveCtrl *p)
112 static char *text_buf = NULL;
113 static int text_size = 0;
115 const char *elementSetName = NULL;
118 if (p->comp && p->comp->which == Z_RecordComp_simple &&
119 p->comp->u.simple->which == Z_ElementSetNames_generic)
120 elementSetName = p->comp->u.simple->u.generic;
122 /* don't make header for the R(aw) element set name */
123 if (elementSetName && !strcmp(elementSetName, "R"))
127 if (text_ptr + 4096 >= text_size)
131 text_size = 2*text_size + 8192;
132 nb = (char *) xmalloc (text_size);
135 memcpy (nb, text_buf, text_ptr);
145 sprintf (text_buf, "Rank: %d\n", p->score);
146 text_ptr = strlen(text_buf);
148 sprintf (text_buf + text_ptr, "Local Number: %d\n", p->localno);
149 text_ptr = strlen(text_buf);
151 r = (*p->readf)(p->fh, text_buf + text_ptr, 4096);
156 text_buf[text_ptr] = '\0';
159 if (!strcmp (elementSetName, "B"))
161 if (!strcmp (elementSetName, "M"))
169 while (++i <= no_lines && (p = strchr (p, '\n')))
174 text_ptr = p-text_buf;
177 p->output_format = VAL_SUTRS;
178 p->rec_buf = text_buf;
179 p->rec_len = text_ptr;
183 static struct recType text_type = {
191 RecType recTypeText = &text_type;