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 #include <err.h>
18 #include <stdio.h>
19 #include <stdlib.h>
21 #include "tmpl.h"
23 int base(struct template *, const char *title);
25 int
26 my_putc(struct template *tp, int c)
27 {
28 FILE *fp = tp->tp_arg;
30 if (putc(c, fp) < 0)
31 return (-1);
33 return (0);
34 }
36 int
37 my_puts(struct template *tp, const char *s)
38 {
39 FILE *fp = tp->tp_arg;
41 if (fputs(s, fp) < 0)
42 return (-1);
44 return (0);
45 }
47 int
48 main(int argc, char **argv)
49 {
50 struct template *tp;
52 if ((tp = template(stdout, my_puts, my_putc)) == NULL)
53 err(1, "template");
55 if (base(tp, " *hello* ") == -1)
56 return (1);
57 puts("");
59 if (base(tp, "<hello>") == -1)
60 return (1);
61 puts("");
63 free(tp);
64 return (0);
65 }