Blob


1 .\" Copyright (c) 2022 Omar Polo <op@openbsd.org>
2 .\"
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
6 .\"
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 .\"
15 .Dd September 27, 2022
16 .Dt TEMPLATE 1
17 .Os
18 .Sh NAME
19 .Nm template
20 .Nd templating system compiler
21 .Sh SYNOPSIS
22 .Nm
23 .Op Fl G
24 .Op Ar
25 .Sh DESCRIPTION
26 .Nm
27 is an utility that converts files written in the
28 .Xr template 7
29 format format to a set of routine writtens in the C programming
30 language.
31 .Nm
32 converts the files given as arguments or from standard input, and
33 writes to standard output.
34 .Pp
35 The options are as follows:
36 .Bl -tag -width Ds
37 .It Fl G
38 Do not emit debug info in the generated source.
39 It's disabled by default, unless
40 .Nm
41 is reading from standard input.
42 .El
43 .Sh EXIT STATUS
44 .Ex
45 .Sh EXAMPLES
46 The following example shows how to use
47 .Nm
48 in a Makefile:
49 .Bd -literal -offset indent
50 \&.SUFFIXES: .c .tmpl
51 \&.c.tmpl:
52 template $< > $@ || rm \-f $@
53 .Ed
54 .Sh SEE ALSO
55 .Xr template 7
56 .Sh AUTHORS
57 .An -nosplit
58 The
59 .Nm
60 utility was written by
61 .An Omar Polo Aq Mt op@openbsd.org .
62 .Sh CAVEATS
63 The compiler is very naive, so there are quite a few shortcomings:
64 .Bl -bullet -compact
65 .It
66 No attempt is made to validate the C code provided inline, nor the
67 validity of the arguments to many constructs.
68 .It
69 The generated code assumes that a variable called
70 .Va tp
71 of type
72 .Vt struct template *
73 is in scope inside the template.
74 .It
75 Each block may have additional variables used for the template
76 generation: to avoid clashes, don't define variables with the
77 .Sq tp_
78 prefix.
79 .It
80 Blanks are, in most cases, trimmed.
81 Normally this is not a problem, but a workaround is needed in case
82 they need to be preserved, for e.g.:
83 .Bd -literal -offset indent
84 Name: {{ " " }} {{ render name_field(tp) }}
85 .Ed
86 .El