Blame


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