Blob


1 /*
2 * Copyright (c) 2022 Omar Polo <op@omarpolo.com>
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 tp->tp_ret = -1;
32 return (-1);
33 }
35 return (0);
36 }
38 int
39 my_puts(struct template *tp, const char *s)
40 {
41 FILE *fp = tp->tp_arg;
43 if (fputs(s, fp) < 0) {
44 tp->tp_ret = -1;
45 return (-1);
46 }
48 return (0);
49 }
51 int
52 main(int argc, char **argv)
53 {
54 struct template *tp;
56 if ((tp = template(stdout, my_puts, my_putc)) == NULL)
57 err(1, "template");
59 base(tp, " *hello* ");
60 puts("");
62 template_reset(tp);
64 base(tp, "<hello>");
65 puts("");
67 free(tp);
68 return (0);
69 }