-/* $Id: safari.c,v 1.1 2006-07-03 14:27:09 adam Exp $
- Copyright (C) 1995-2005
+/* $Id: safari.c,v 1.5 2007-01-15 15:10:17 adam Exp $
+ Copyright (C) 1995-2007
Index Data ApS
This file is part of the Zebra server.
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
#include <idzebra/recctrl.h>
struct filter_info {
- char *sep;
+ int segments;
};
-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->segments = 0;
+ return tinfo;
+}
+
+static void *filter_init2(Res res, RecType recType)
{
struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo));
- tinfo->sep = 0;
+ tinfo->segments = 1;
return tinfo;
}
static void filter_destroy(void *clientData)
{
struct filter_info *tinfo = clientData;
- xfree (tinfo->sep);
xfree (tinfo);
}
{
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;
yaz_log(YLOG_LOG, "filter_extract off=%ld",
(long) (*fi->p->tellf)(fi->p->fh));
#endif
- xfree(tinfo->sep);
- tinfo->sep = 0;
(*p->init)(p, &recWord);
if (!fi_gets(fi, line, sizeof(line)-1))
#if 0
yaz_log(YLOG_LOG, "safari line: %s", line);
#endif
- if (sscanf(line, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT " %39s %n",
- &recWord.record_id, &recWord.section_id, &recWord.seqno,
- field, &nor) < 4)
- {
- yaz_log(YLOG_WARN, "Bad safari record line: %s", line);
- return RECCTRL_EXTRACT_ERROR_GENERIC;
- }
+ if (tinfo->segments)
+ {
+ if (sscanf(line, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT
+ ZINT_FORMAT " %39s %n",
+ &recWord.record_id, &recWord.section_id,
+ &recWord.segment,
+ &recWord.seqno,
+ field, &nor) < 5)
+ {
+ yaz_log(YLOG_WARN, "Bad safari record line: %s", line);
+ return RECCTRL_EXTRACT_ERROR_GENERIC;
+ }
+ }
+ else
+ {
+ if (sscanf(line, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT " %39s %n",
+ &recWord.record_id, &recWord.section_id, &recWord.seqno,
+ field, &nor) < 4)
+ {
+ yaz_log(YLOG_WARN, "Bad safari record line: %s", line);
+ return RECCTRL_EXTRACT_ERROR_GENERIC;
+ }
+ }
for (cp = line + nor; *cp == ' '; cp++)
;
recWord.index_name = field;
}
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;
filter_retrieve
};
+static struct recType filter_type2 = {
+ 0,
+ "safari2",
+ filter_init2,
+ filter_config,
+ filter_destroy,
+ filter_extract,
+ filter_retrieve
+};
+
RecType
#ifdef IDZEBRA_STATIC_SAFARI
idzebra_filter_safari
[] = {
&filter_type,
+ &filter_type2,
0,
};
/*