X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=recctrl%2Fsgmlread.c;h=d0cca8ce04e13952142f45a72f9c869f0d9b3521;hp=f75a1c5afa173fb6fc0b9dfa4d95af1db8a0db36;hb=6c9fcd3b5d3108702fa1ffc92dab4ab6060f9a19;hpb=1f793b6c2f61fd47c7a26c0274f0c7e6ab9d1a07 diff --git a/recctrl/sgmlread.c b/recctrl/sgmlread.c index f75a1c5..d0cca8c 100644 --- a/recctrl/sgmlread.c +++ b/recctrl/sgmlread.c @@ -1,25 +1,136 @@ -/* - * Copyright (C) 1994-1996, Index Data I/S - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Log: sgmlread.c,v $ - * Revision 1.3 1997-09-04 13:54:41 adam - * Added MARC filter - type grs.marc. where syntax refers - * to abstract syntax. New method tellf in retrieve/extract method. - * - * Revision 1.2 1997/04/30 08:56:08 quinn - * null - * - * Revision 1.1 1996/10/11 10:57:32 adam - * New module recctrl. Used to manage records (extract/retrieval). - * - */ -#include - -#include "grsread.h" - -data1_node *grs_read_sgml (struct grs_read_info *p) -{ - return data1_read_record (p->readf, p->fh, p->mem); +/* $Id: sgmlread.c,v 1.16 2005-01-15 19:38:32 adam Exp $ + Copyright (C) 1995-2005 + Index Data ApS + +This file is part of the Zebra server. + +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 +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +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. +*/ + + +#include +#include + +#include + +struct sgml_getc_info { + char *buf; + int buf_size; + int size; + int off; + int moffset; + void *fh; + int (*readf)(void *, char *, size_t); + WRBUF wrbuf; +}; + +int sgml_getc (void *clientData) +{ + struct sgml_getc_info *p = (struct sgml_getc_info *) clientData; + int res; + + if (p->off < p->size) + return p->buf[(p->off)++]; + if (p->size < p->buf_size) + return 0; + p->moffset += p->off; + p->off = 0; + p->size = 0; + res = (*p->readf)(p->fh, p->buf, p->buf_size); + if (res > 0) + { + p->size += res; + return p->buf[(p->off)++]; + } + return 0; +} + +static data1_node *grs_read_sgml (struct grs_read_info *p) +{ + struct sgml_getc_info *sgi = (struct sgml_getc_info *) p->clientData; + data1_node *node; + int res; + + sgi->moffset = p->offset; + sgi->fh = p->fh; + sgi->readf = p->readf; + sgi->off = 0; + sgi->size = 0; + res = (*sgi->readf)(sgi->fh, sgi->buf, sgi->buf_size); + if (res > 0) + sgi->size += res; + else + return 0; + node = data1_read_nodex (p->dh, p->mem, sgml_getc, sgi, sgi->wrbuf); + if (node && p->endf) + (*p->endf)(sgi->fh, sgi->moffset + sgi->off); + return node; +} + +static void *grs_init_sgml(Res res, RecType recType) +{ + struct sgml_getc_info *p = (struct sgml_getc_info *) xmalloc (sizeof(*p)); + p->buf_size = 512; + p->buf = xmalloc (p->buf_size); + p->wrbuf = wrbuf_alloc(); + return p; +} + +static void grs_config_sgml(void *clientData, Res res, const char *args) +{ + } + +static void grs_destroy_sgml(void *clientData) +{ + struct sgml_getc_info *p = (struct sgml_getc_info *) clientData; + + wrbuf_free(p->wrbuf, 1); + xfree (p->buf); + xfree (p); +} + +static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl) +{ + return zebra_grs_extract(clientData, ctrl, grs_read_sgml); +} + +static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl) +{ + return zebra_grs_retrieve(clientData, ctrl, grs_read_sgml); +} + +static struct recType grs_type_sgml = +{ + "grs.sgml", + grs_init_sgml, + grs_config_sgml, + grs_destroy_sgml, + grs_extract_sgml, + grs_retrieve_sgml +}; + +RecType +#ifdef IDZEBRA_STATIC_GRS_SGML +idzebra_filter_grs_sgml +#else +idzebra_filter +#endif + +[] = { + &grs_type_sgml, + 0, +};