1 /* $Id: sgmlread.c,v 1.5 2007-03-19 21:50:39 adam Exp $
2 Copyright (C) 1995-2007
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <idzebra/recgrs.h>
29 struct sgml_getc_info {
34 struct ZebraRecStream *stream;
39 int sgml_getc (void *clientData)
41 struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
45 return p->buf[(p->off)++];
46 if (p->size < p->buf_size)
51 res = p->stream->readf(p->stream, p->buf, p->buf_size);
55 return p->buf[(p->off)++];
60 static data1_node *grs_read_sgml (struct grs_read_info *p)
62 struct sgml_getc_info *sgi = (struct sgml_getc_info *) p->clientData;
66 sgi->moffset = p->stream->tellf(p->stream);
67 sgi->stream = p->stream;
70 res = sgi->stream->readf(sgi->stream, sgi->buf, sgi->buf_size);
75 node = data1_read_nodex(p->dh, p->mem, sgml_getc, sgi, sgi->wrbuf);
76 if (node && p->stream->endf)
78 off_t end_offset = sgi->moffset + sgi->off;
79 p->stream->endf(sgi->stream, &end_offset);
84 static void *grs_init_sgml(Res res, RecType recType)
86 struct sgml_getc_info *p = (struct sgml_getc_info *) xmalloc (sizeof(*p));
88 p->buf = xmalloc (p->buf_size);
89 p->wrbuf = wrbuf_alloc();
93 static ZEBRA_RES grs_config_sgml(void *clientData, Res res, const char *args)
98 static void grs_destroy_sgml(void *clientData)
100 struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
102 wrbuf_destroy(p->wrbuf);
107 static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl)
109 return zebra_grs_extract(clientData, ctrl, grs_read_sgml);
112 static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl)
114 return zebra_grs_retrieve(clientData, ctrl, grs_read_sgml);
117 static struct recType grs_type_sgml =
129 #ifdef IDZEBRA_STATIC_GRS_SGML
130 idzebra_filter_grs_sgml
142 * indent-tabs-mode: nil
144 * vim: shiftwidth=4 tabstop=8 expandtab