YAZ  4.2.57
wrbuf.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Index Data nor the names of its contributors
13  * may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
33 #ifndef WRBUF_H
34 #define WRBUF_H
35 
36 #include <yaz/xmalloc.h>
37 #include <yaz/yaz-iconv.h>
38 
40 
42 typedef struct wrbuf
43 {
44  char *buf;
45  size_t pos;
46  size_t size;
47 } wrbuf, *WRBUF;
48 
52 YAZ_EXPORT WRBUF wrbuf_alloc(void);
53 
59 YAZ_EXPORT void wrbuf_destroy(WRBUF b);
60 
64 YAZ_EXPORT void wrbuf_rewind(WRBUF b);
65 
71 YAZ_EXPORT void wrbuf_write(WRBUF b, const char *buf, size_t size);
72 
79 YAZ_EXPORT void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size);
80 
85 YAZ_EXPORT void wrbuf_puts(WRBUF b, const char *buf);
86 
91 YAZ_EXPORT void wrbuf_vp_puts(const char *buf, void *client_data);
92 
98 YAZ_EXPORT void wrbuf_xmlputs_n(WRBUF b, const char *cp, size_t size);
99 
104 YAZ_EXPORT void wrbuf_xmlputs(WRBUF b, const char *cp);
105 
112 YAZ_EXPORT void wrbuf_puts_replace_char(WRBUF b, const char *buf,
113  const char from, const char to);
114 
121 YAZ_EXPORT void wrbuf_puts_escaped(WRBUF b, const char *str);
122 
130 YAZ_EXPORT void wrbuf_write_escaped(WRBUF b, const char *buf, size_t len);
131 
136 YAZ_EXPORT void wrbuf_printf(WRBUF b, const char *fmt, ...)
137 #ifdef __GNUC__
138  __attribute__ ((format (printf, 2, 3)))
139 #endif
140  ;
141 
151 int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf,
152  size_t size, int cdata);
153 
160 YAZ_EXPORT void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf,
161  size_t size);
162 
169 YAZ_EXPORT void wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd,
170  const char *buf, size_t size);
171 
177 YAZ_EXPORT void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *str);
178 
184 YAZ_EXPORT void wrbuf_iconv_puts_cdata(WRBUF b, yaz_iconv_t cd,
185  const char *str);
186 
192 YAZ_EXPORT void wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch);
193 
201 YAZ_EXPORT void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd);
202 
206 YAZ_EXPORT void wrbuf_chop_right(WRBUF b);
207 
212 YAZ_EXPORT void wrbuf_cut_right(WRBUF b, size_t no_to_remove);
213 
220 YAZ_EXPORT int wrbuf_grow(WRBUF b, size_t minsize);
221 
222 #define wrbuf_len(b) ((b)->pos)
223 #define wrbuf_buf(b) ((b)->buf)
224 
229 YAZ_EXPORT const char *wrbuf_cstr(WRBUF b);
230 
231 #define wrbuf_putc(b, c) \
232  ((void) ((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \
233  (b)->buf[(b)->pos++] = (c), 0)
234 
236 
237 #endif
238 /*
239  * Local variables:
240  * c-basic-offset: 4
241  * c-file-style: "Stroustrup"
242  * indent-tabs-mode: nil
243  * End:
244  * vim: shiftwidth=4 tabstop=8 expandtab
245  */
246