1fmt-ptrn(1)                 General Commands Manual                fmt-ptrn(1)
2
3
4

NAME

6       fmt-ptrn - A simple template system
7

SYNOPSIS

9       fmt-ptrn [options] filename [template]
10

OVERVIEW

12       New  is a template system, especially useful in conjunction with a sim‐
13       ple text editor such as vi. The user maintains templates which may con‐
14       tain  format  strings. At run time, nf replaces the format strings in a
15       template with appropriate values to create a new file.
16
17
18       For example, given the following template:
19
20
21              //   FILE: %%(FILE)
22              // AUTHOR: %%(FULLNAME)
23              //   DATE: %%(DATE)
24
25              // Copyright (C) 1999 %%(FULLNAME) %%(EMAIL)
26              // All rights reserved.
27
28       nf will create:
29
30
31              //   FILE: foo.cpp
32              // AUTHOR: W. Michael Petullo
33              //   DATE: 11 September 1999
34
35              // Copyright (C) 1999 W. Michael Petullo new@flyn.org
36              // All rights reserved.
37
38       on my computer.
39
40
41       The program understands plaintext or gziped template files.
42
43
44       The fmt-ptrn system also provides a shared library which allows a  pro‐
45       grammer  access  to  nf's functionality. The system was developed to be
46       light and fast.  Its only external  dependencies  are  the  C  library,
47       glib2 and zlib.
48
49
50

DETAILS

52       Nf  first  looks  for  templates  in ~/.fmt-ptrn/templates.  Second, nf
53       looks for templates in <datadir>/fmt-ptrn/template,  where  datadir  is
54       defined  by  autoconf.   This  directory is usually /usr/local/share or
55       /usr/share.
56
57
58
59       The templates directory contains several subdirectories matching  file‐
60       name  extensions.   This  may include directories such as html, cpp, c,
61       and tex.  Within each subdirectory are the actual template files.   The
62       template  file named default is the default template used for the file‐
63       name extension.  Other templates can be used by specifying their  file‐
64       name to nf on the command line (see NF(1)).
65
66
67
68       Certain  types of files generally don't have extensions.  In this case,
69       nf looks for a template directory with the same name as the file  being
70       created.   This  is  useful  when  using templates to create files with
71       names such as Makefile and README.
72
73
74
75       When filling a format pattern, nf knows the  value  for  the  following
76       format patterns:
77
78
79
80       DATE   Today's date.
81
82       FILE   The name of the file being created.
83
84       FULLNAME
85              The user's full name (from GECOS field).
86
87       FIRSTNAME
88              The user's first name (from GECOS field).
89
90       MIDDLENAME
91              The user's middle name (from GECOS field).
92
93       LASTNAME
94              The user's last name (from GECOS field).
95
96       EMPTY_STR
97              The empty string.
98
99       In  addition, any environment variable can be used as a format pattern.
100       An alternate string to be used in the case of an  environment  variable
101       being undefined can be specified as follows:
102
103
104
105       %(UNDEFINED:foo)
106
107
108       This  will be replaced with ``foo'' in the created file if UNDEFINED is
109       not a part of one's environment.
110
111
112
113       The alternative may be a format pattern, too.  If FIRSTNAME is  defined
114       a Mike, the following:
115
116
117
118       %(UNDEFINED:%(before="My name is " FIRSTNAME))
119
120
121
122       will print ``My name is Mike.''
123
124
125
126       A  format  pattern  can  also be acted on by a modifier.  The following
127       will print the value of FOO in capital letters:
128
129
130
131       %(upper FOO)
132
133
134       It makes sense to use some modifiers with a literal, instead of  a  key
135       which will be replaced by a value.  For example:
136
137
138
139       %(file FOO)
140
141
142       will insert the text contained in a the file whose path is the value of
143       the key FOO.  But:
144
145
146
147       %(file "foo")
148
149
150       will insert the contents of the file named foo.
151
152
153
154       The following modifiers are currently available:
155
156
157       upper  Convert to upper case.
158
159       lower  Convert to lower case.
160
161       basename
162              Convert to the basename of a filename.
163
164       before="str"
165              Append the string str before.
166
167       after="str"
168              Append the string str after.
169
170       fn     Tag a " ()" on the end.
171
172       c_delim
173              Print enveloped in a C style deliminator, ie: /* == foo == */.
174
175       cpp_delim
176              Print enveloped in a C++ style deliminator, ie: // == foo.
177
178       sh_delim
179              Print enveloped in a shell script style deliminator,  ie:  #  ==
180              foo.
181
182       tex_delim
183              Print eveloped in a LaTeX style deliminator, ie: % == foo.
184
185       newlines
186              Replaces occurrences of " " in the string with new lines
187
188       no_newlines
189              Replaces occurrences of "0 in the string with ' '
190
191       remove_underscore
192              Replaces occurrences of '_' in the string with '-'
193
194       file   Treats the key as the path to a file, which is included
195
196       template
197              Treats  the  key  as the path to a template, which is filled and
198              included
199
200       #      A comment, this will not appear in  destination  file  %(#  Com‐
201              ment.)
202
203       Several modifiers can act within one format string as illustrated:
204
205
206       %(basename upper FOO)
207
208
209       Modifiers  use a stack to be applied.  The first modifier to be applied
210       is the one farthest to the right.  The last to be applied  it  the  one
211       farthest to the left.
212
213
214

AUTHORS

216       W. Michael Petullo <mike@flyn.org>
217
218
219
220                                                                   fmt-ptrn(1)
Impressum