1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <idzebra/recgrs.h>
26 struct sgml_getc_info {
31 struct ZebraRecStream *stream;
36 int sgml_getc (void *clientData)
38 struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
42 return p->buf[(p->off)++];
43 if (p->size < p->buf_size)
48 res = p->stream->readf(p->stream, p->buf, p->buf_size);
52 return p->buf[(p->off)++];
57 static data1_node *grs_read_sgml (struct grs_read_info *p)
59 struct sgml_getc_info *sgi = (struct sgml_getc_info *) p->clientData;
63 sgi->moffset = p->stream->tellf(p->stream);
64 sgi->stream = p->stream;
67 res = sgi->stream->readf(sgi->stream, sgi->buf, sgi->buf_size);
72 node = data1_read_nodex(p->dh, p->mem, sgml_getc, sgi, sgi->wrbuf);
73 if (node && p->stream->endf)
75 off_t end_offset = sgi->moffset + sgi->off;
76 p->stream->endf(sgi->stream, &end_offset);
81 static void *grs_init_sgml(Res res, RecType recType)
83 struct sgml_getc_info *p = (struct sgml_getc_info *) xmalloc (sizeof(*p));
85 p->buf = xmalloc (p->buf_size);
86 p->wrbuf = wrbuf_alloc();
90 static ZEBRA_RES grs_config_sgml(void *clientData, Res res, const char *args)
95 static void grs_destroy_sgml(void *clientData)
97 struct sgml_getc_info *p = (struct sgml_getc_info *) clientData;
99 wrbuf_destroy(p->wrbuf);
104 static int grs_extract_sgml(void *clientData, struct recExtractCtrl *ctrl)
106 return zebra_grs_extract(clientData, ctrl, grs_read_sgml);
109 static int grs_retrieve_sgml(void *clientData, struct recRetrieveCtrl *ctrl)
111 return zebra_grs_retrieve(clientData, ctrl, grs_read_sgml);
114 static struct recType grs_type_sgml =
126 #ifdef IDZEBRA_STATIC_GRS_SGML
127 idzebra_filter_grs_sgml
139 * c-file-style: "Stroustrup"
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab