Blame


1 bff58270 2022-09-19 op /*
2 52afe358 2022-12-17 op * Copyright (c) 2022 Omar Polo <op@openbsd.org>
3 bff58270 2022-09-19 op *
4 bff58270 2022-09-19 op * Permission to use, copy, modify, and distribute this software for any
5 bff58270 2022-09-19 op * purpose with or without fee is hereby granted, provided that the above
6 bff58270 2022-09-19 op * copyright notice and this permission notice appear in all copies.
7 bff58270 2022-09-19 op *
8 bff58270 2022-09-19 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 bff58270 2022-09-19 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 bff58270 2022-09-19 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 bff58270 2022-09-19 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 bff58270 2022-09-19 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 bff58270 2022-09-19 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 bff58270 2022-09-19 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 bff58270 2022-09-19 op */
16 bff58270 2022-09-19 op
17 bff58270 2022-09-19 op #include <err.h>
18 bff58270 2022-09-19 op #include <stdio.h>
19 bff58270 2022-09-19 op #include <stdlib.h>
20 bff58270 2022-09-19 op
21 bff58270 2022-09-19 op #include "tmpl.h"
22 bff58270 2022-09-19 op
23 bff58270 2022-09-19 op int base(struct template *, const char *title);
24 18906bcc 2023-09-13 op int my_write(void *, const void *, size_t);
25 bff58270 2022-09-19 op
26 bff58270 2022-09-19 op int
27 18906bcc 2023-09-13 op my_write(void *arg, const void *s, size_t len)
28 bff58270 2022-09-19 op {
29 18906bcc 2023-09-13 op FILE *fp = arg;
30 bff58270 2022-09-19 op
31 18906bcc 2023-09-13 op if (fwrite(s, 1, len, fp) < 0)
32 bff58270 2022-09-19 op return (-1);
33 bff58270 2022-09-19 op
34 bff58270 2022-09-19 op return (0);
35 bff58270 2022-09-19 op }
36 bff58270 2022-09-19 op
37 bff58270 2022-09-19 op int
38 bff58270 2022-09-19 op main(int argc, char **argv)
39 bff58270 2022-09-19 op {
40 18906bcc 2023-09-13 op struct template *tp;
41 18906bcc 2023-09-13 op char buf[3];
42 18906bcc 2023-09-13 op /* use a ridiculously small buffer in regress */
43 bff58270 2022-09-19 op
44 18906bcc 2023-09-13 op if ((tp = template(stdout, my_write, buf, sizeof(buf))) == NULL)
45 bff58270 2022-09-19 op err(1, "template");
46 bff58270 2022-09-19 op
47 18906bcc 2023-09-13 op if (base(tp, " *hello* ") == -1 ||
48 18906bcc 2023-09-13 op template_flush(tp) == -1)
49 95448b62 2022-09-29 op return (1);
50 bff58270 2022-09-19 op puts("");
51 bff58270 2022-09-19 op
52 18906bcc 2023-09-13 op if (base(tp, "<hello>") == -1 ||
53 18906bcc 2023-09-13 op template_flush(tp) == -1)
54 95448b62 2022-09-29 op return (1);
55 bff58270 2022-09-19 op puts("");
56 bff58270 2022-09-19 op
57 83991185 2023-09-13 op template_free(tp);
58 bff58270 2022-09-19 op return (0);
59 bff58270 2022-09-19 op }