2 * Sherlock Library -- Charset Conversion Wrapper for Fast Buffered I/O
4 * (c) 2003 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/fastbuf.h"
12 #include "charset/charconv.h"
13 #include "charset/fb-charconv.h"
22 struct conv_context ctxt;
25 #define FB_CC(f) ((struct fb_charconv *)(f)->is_fastbuf)
28 fb_cc_spout(struct fastbuf *f)
30 struct conv_context *ct = &FB_CC(f)->ctxt;
33 ct->source = f->buffer;
34 ct->source_end = f->bptr;
38 if (ct->dest > ct->dest_start)
39 bdirect_write_commit(FB_CC(f)->out, ct->dest);
40 uns l = bdirect_write_prepare(FB_CC(f)->out, &ct->dest_start);
41 ct->dest = ct->dest_start;
42 ct->dest_end = ct->dest + l;
44 while (!(flags & CONV_SOURCE_END));
50 fb_cc_close(struct fastbuf *f)
52 bclose(FB_CC(f)->out);
57 fb_wrap_charconv_out(struct fastbuf *f, int cs_from, int cs_to)
62 struct fastbuf *g = xmalloc_zero(sizeof(struct fb_charconv));
64 conv_init(&FB_CC(g)->ctxt);
65 conv_set_charset(&FB_CC(g)->ctxt, cs_from, cs_to);
66 g->name = "<charconv-out>";
67 g->spout = fb_cc_spout;
68 g->close = fb_cc_close;
69 g->buffer = g->bstop = g->bptr = FB_CC(g)->buf;
70 g->bufend = g->buffer + BUFSIZE;