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 #include <err.h>
18 6509b181 2022-12-30 thomas #include <stdio.h>
19 6509b181 2022-12-30 thomas #include <stdlib.h>
20 6509b181 2022-12-30 thomas
21 6509b181 2022-12-30 thomas #include "tmpl.h"
22 6509b181 2022-12-30 thomas
23 6509b181 2022-12-30 thomas int base(struct template *, const char *title);
24 d8bf4f25 2023-09-14 thomas int my_write(void *, const void *, size_t);
25 6509b181 2022-12-30 thomas
26 6509b181 2022-12-30 thomas int
27 d8bf4f25 2023-09-14 thomas my_write(void *arg, const void *s, size_t len)
28 6509b181 2022-12-30 thomas {
29 d8bf4f25 2023-09-14 thomas FILE *fp = arg;
30 6509b181 2022-12-30 thomas
31 d8bf4f25 2023-09-14 thomas if (fwrite(s, 1, len, fp) < 0)
32 6509b181 2022-12-30 thomas return (-1);
33 6509b181 2022-12-30 thomas
34 6509b181 2022-12-30 thomas return (0);
35 6509b181 2022-12-30 thomas }
36 6509b181 2022-12-30 thomas
37 6509b181 2022-12-30 thomas int
38 6509b181 2022-12-30 thomas main(int argc, char **argv)
39 6509b181 2022-12-30 thomas {
40 d8bf4f25 2023-09-14 thomas struct template *tp;
41 d8bf4f25 2023-09-14 thomas char buf[3];
42 d8bf4f25 2023-09-14 thomas /* use a ridiculously small buffer in regress */
43 6509b181 2022-12-30 thomas
44 d8bf4f25 2023-09-14 thomas if ((tp = template(stdout, my_write, buf, sizeof(buf))) == NULL)
45 6509b181 2022-12-30 thomas err(1, "template");
46 6509b181 2022-12-30 thomas
47 d8bf4f25 2023-09-14 thomas if (base(tp, " *hello* ") == -1 ||
48 d8bf4f25 2023-09-14 thomas template_flush(tp) == -1)
49 6509b181 2022-12-30 thomas return (1);
50 6509b181 2022-12-30 thomas puts("");
51 6509b181 2022-12-30 thomas
52 d8bf4f25 2023-09-14 thomas if (base(tp, "<hello>") == -1 ||
53 d8bf4f25 2023-09-14 thomas template_flush(tp) == -1)
54 6509b181 2022-12-30 thomas return (1);
55 6509b181 2022-12-30 thomas puts("");
56 6509b181 2022-12-30 thomas
57 7b7c01fc 2023-09-12 thomas template_free(tp);
58 6509b181 2022-12-30 thomas return (0);
59 6509b181 2022-12-30 thomas }