Blob


1 /*
2 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #ifndef TMPL_H
18 #define TMPL_H
20 struct template;
22 typedef int (*tmpl_write)(void *, const void *, size_t);
24 struct template {
25 void *tp_arg;
26 char *tp_tmp;
27 tmpl_write tp_write;
28 char *tp_buf;
29 size_t tp_len;
30 size_t tp_cap;
31 };
33 int tp_write(struct template *, const char *, size_t);
34 int tp_writes(struct template *, const char *);
35 int tp_writef(struct template *, const char *, ...)
36 __attribute__((__format__ (printf, 2, 3)));
37 int tp_urlescape(struct template *, const char *);
38 int tp_htmlescape(struct template *, const char *);
39 int tp_write_htmlescape(struct template *, const char *, size_t);
41 struct template *template(void *, tmpl_write, char *, size_t);
42 int template_flush(struct template *);
43 void template_free(struct template *);
45 #endif