1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
changequote(`«', `»')dnl
define(«IFNBLANK», «ifelse(translit(««$1»», «
»), «», «», «$2»)»)dnl
define(«DECL_ARGLIST», «ifelse(«$#», «2», ««$1»», «dnl
«$1», DECL_ARGLIST(shift(shift($@)))»)»)dnl
ifelse(OUTPUT_MODE, «C», «dnl --------- C output
define(«STRIP_TABS», «translit(««$1»», « »)»)dnl
define(«CHOP_FIRST», «translit(patsubst(translit(««««$1»»»», «
», « »), «^.... \(.*\)....$», «««\1»»»), « », «
»)»)dnl
define(«CHOP_LAST»,
«format(««%.*s»», regexp(translit(««$1»», «
/», «/ »), «/*$»), «$1»)»)dnl
define(«NORMALIZE», «CHOP_LAST(CHOP_FIRST(STRIP_TABS(«$1»)))»)dnl
define(«COMMENT», «patsubst(patsubst(«««$1»»», «^\(.\)», « \1»), «^», «$2»)»)dnl
define(«INDENT», «COMMENT(NORMALIZE(«$1»), « *»)»)dnl
define(«INDENT_PARAM», «COMMENT(NORMALIZE(«$1»), « * »)»)dnl
define(«INDENT_PARAM_DOC», «COMMENT(NORMALIZE(«$1»), « * »)»)dnl
define(«INDENT_RETVAL_DOC», «COMMENT(NORMALIZE(«$1»), « * »)»)dnl
define(«INDENT_MEMBER_DOC», «COMMENT(NORMALIZE(«$1»), « *»)»)dnl
define(«INDENT_MEMBER», «patsubst(NORMALIZE(««$1»»), «^[ ]*», « »)»)dnl
define(«DECL_ARG_TEXT», «ifelse(«$#», «1», «», «
INDENT_PARAM(«$1»):
INDENT_PARAM_DOC(«$2»)«»dnl
DECL_ARG_TEXT(shift(shift($@)))»)»)dnl
define(«PRINT_ARGS», «ifelse(«$2», «», «», «dnl
*
* Parameter(s):DECL_ARG_TEXT($@)»
)»)dnl
define(«DECLARE_FUNCTION», «dnl
/*
* «$1»(): «$2»
IFNBLANK(«$3», «dnl
*
INDENT(«$3»)
»)dnl
PRINT_ARGS($4)dnl
IFNBLANK(«$5», «dnl
*
INDENT(«$5»)
»)dnl
IFNBLANK(«$7», «dnl
*
* Return («$6»):
INDENT_RETVAL_DOC(«$7»)
»)dnl
IFNBLANK(«$8», «dnl
*
INDENT(«$8»)
»)dnl
*/
«$6» «$1»(DECL_ARGLIST($4));dnl
»)dnl
define(«STATEMENT», «dnl
/*
INDENT(«$2»)
IFNBLANK(«$3», «dnl
*
INDENT(«$3»)
»)dnl
*/
«$1»;»)dnl
define(«COMPOUND_MEMBERS», «ifelse(«$#», «1», «»,
« /*
INDENT_MEMBER_DOC(«$2»)
*/
INDENT_MEMBER(«$1»);
COMPOUND_MEMBERS(shift(shift($@)))»)»)dnl
define(«DECLARE_COMPOUND», «dnl
/*
* «$2»
IFNBLANK(«$3», «dnl
*
INDENT(«$3»)
»)dnl
*/
«$1» {
COMPOUND_MEMBERS($4)dnl
};dnl
»)dnl
define(«ENUM_MEMBERS», «ifelse(«$#», «1», «»,
« /*
INDENT_MEMBER_DOC(«$2»)
*/
INDENT_MEMBER(«$1»),
ENUM_MEMBERS(shift(shift($@)))»)»)dnl
define(«DECLARE_ENUM», «/* «$2» */
IFNBLANK(«$3», «dnl
*
patsubst(«$3», «^\s*», « * »)
»)dnl
enum «$1» {
ENUM_MEMBERS($4)dnl
};dnl
»)dnl
define(«VERBATIM_C», «NORMALIZE(«$1»)»)dnl
», OUTPUT_MODE, «HTML», «dnl --------- HTML output
define(«LINK_COUNT», 0)dnl
define(«FIXUP_LT», «patsubst(«$1», «<», «<»)»)
define(«FIXUP_GT», «patsubst(«$1», «>», «>»)»)
define(«FIXUP_AMPERSAND», «patsubst(«$1», «&», «&»)»)
define(«HANDLE_EMPTY_LINES», «patsubst(«$1», «^\s*$», «</p><p>»)»)
define(«FIXUP_HTML», «FIXUP_AMPERSAND(FIXUP_LT(FIXUP_GT(««««$1»»»»)))»)
define(«FORMAT_LIST_HTML», «ifelse(«$#», «1», «», «
IFNBLANK(«$2», «<li> <tt>«$1»</tt>: HANDLE_EMPTY_LINES(FIXUP_HTML(««$2»»)) </li>
FORMAT_LIST_HTML(shift(shift($@)))»)»
)»)
define(«ANCHOR», «
id="link_«»LINK_COUNT"
»)
define(«HREF», «
define(«LINK_COUNT», incr(LINK_COUNT))
<a href = "«#»link_«»LINK_COUNT"> «$1» </a>
»)
define(«DECLARE_FUNCTION», «
divert
<tr> <td> <tt> HREF(«$1()») </tt> </td> <td> «$2» </td> </tr>
divert(«1»)
<h2 ANCHOR()> <tt> «$6» «$1»(DECL_ARGLIST($4)) </tt> </h2>
<strong> FIXUP_HTML(«$2») </strong>
<p> HANDLE_EMPTY_LINES(FIXUP_HTML(««$3»»)) </p>
<ul> FORMAT_LIST_HTML($4) </ul>
<p> HANDLE_EMPTY_LINES(FIXUP_HTML(««$5»»)) </p>
IFNBLANK(«$7», «Return (<tt>«$6»</tt>):
<ul><li> FIXUP_HTML(«$7») </li></ul>»)
<p> HANDLE_EMPTY_LINES(FIXUP_HTML(««$8»»)) </p>
<hr>
»)
define(«STATEMENT», «
divert
<tr> <td> <tt> HREF(«$1») </tt> </td> <td> «$2» </td>
divert(«1»)
<h2 ANCHOR()> <tt> «$1» </tt> </h2>
<strong> FIXUP_HTML(«$2») </strong>
<p> HANDLE_EMPTY_LINES(FIXUP_HTML(««$3»»)) </p>
<hr>
»)
define(«DECLARE_COMPOUND», «
divert
<tr> <td> <tt> HREF(«$1») </tt> </td> <td> «$2» </td>
divert(«1»)
<h2 ANCHOR()> <tt> «$1» </tt> </h2>
<strong> FIXUP_HTML(«$2») </strong>
<p> HANDLE_EMPTY_LINES(FIXUP_HTML(««$3»»)) </p>
Members:
<ul> FORMAT_LIST_HTML($4) </ul>
<hr>
»)
define(«DECLARE_ENUM», «
divert
<tr> <td> <tt> HREF(«enum $1») </tt> </td> <td> «$2» </td>
divert(«1»)
<h2 ANCHOR()> <tt> enum «$1» </tt> </h2>
<strong> FIXUP_HTML(«$2») </strong>
<p> HANDLE_EMPTY_LINES(FIXUP_HTML(««$3»»)) </p>
Enumeration Constants:
<ul> FORMAT_LIST_HTML($4) </ul>
<hr>
»)
define(«VERBATIM_C»)
divert(«1») </table> <hr> </div> divert
<center> <h1> API Reference </h1> </center>
<div class="toc"> <table>
»)dnl
ifdef(«EXAMPLES», «
dnl $1: name, $2: one-line summary, $3: prolog, $4: parameters,
dnl $5: parameter documentation, $6: return type, $7: return text,
dnl $8: epilog
DECLARE_FUNCTION(
«simple_func»,
«This is the one-line summary.»,
«This is the prolog.»,
«
«int param1»,
«documentation of first parameter»,
«char *param2»,
«documentation of second parameter»
»,
«This is the parameter documentation section.»,
«int»,
«This is the documentation of the return value»,
«This is the epilog.»
)
DECLARE_FUNCTION(
«complex_func»,
«Example of a function which uses all features of gendoc»,
«Prolog: The three free text sections (prolog, arg-doc and epilog) may
all consist of several paragraphs, and each may contain multiple lines.
Paragraphs are separated by lines containing only whitespace.
Formatting is kept intact, but lines are wrapped into C comments.»,
«
«int par1»,
«The parameter list consists of any number of parameter/comment
pairs. The parameters are plain C code like the "int par1" above.
The list must be quoted, and both the declaration and its
comment must also be quoted. Comments must not be empty.»,
«int par2»,
«For the parameter documentation the same rules as for the free text
sections apply: Multiple paragraphs are possible, and each may spawn
multiple lines.»
»,
«The par-doc section. It is printed after the parameter list but before
the return value (if any).
It is supposed to describe the function or its parameters in more
detail, possibly referring to one or more of the above parameters.
This function returns non-void, so this paragraph is followed by the
return value documentation.»,
«int»,
«Like the parameter/comment pairs, the return value consists of two parts:
the return type and the documentation.
This return documentation consists of two paragraphs.»,
«Finally, there is the (optional) epilog.
It might contain references to related documentation, for example a
"see also" section.»
)
DECLARE_FUNCTION(
«dwim»,
«Example of a function with no parameters and no return value.»,
«This is the description. It could consist of several paragraphs.»,
«
«void»,
»,
«Par-doc: For functions with no parameters, the par-doc section
is kind of pointless.»,
«void»,
«»,
«Epilog: For functions with no return value, the epilog directly
follows the par-doc section.»,
)
DECLARE_FUNCTION(
«minimal_documented_function»,
«This documentation conists of only the summary line.»,
«»,
«
«void»,
»,
«»,
«void»,
«»,
«»,
)
dnl $1: name, $2: one-line summary, $3: description, $4: members
DECLARE_COMPOUND(
«struct foo»,
«summary: Illustrate the DECLARE_COMPOUND macro»,
«description: The macro works for both structs and unions. The
structure of the documentation is simpler than for functions because
instead of three free-text sections (prolog, par-doc, epilog), it
has only one: the description. Of course the description may spawn
multiple paragraphs, each of which which may consist of multiple lines.
The member list is similar to the list of function parameters.»,
«
«float member1»,
«The description of the members may also spawn multiple paragraphs,
and each of them may spawn multiple lines.
This description has two paragraphs.»,
«float member2»,
«The documentation might be pretty short, though»
»
)
dnl $1: name, $2: one-line summary, $3: description, $4: members
DECLARE_ENUM(
«example_enum»,
«Summary: Illustrate the DECLARE_ENUM macro»,
«Enumerations are similar to compounds in that they receive a one-line
summary and an optional long description, The member list (paramter
#4) is expected to be a list of identifier/comment pairs.»,
«
«ENUM_ID1»,
«comment 1»,
«ENUM_ID2»,
«Comments can span multiple lines. Formatting is retained, but
leading and trailing newlines are stripped and leading tabs are
adjusted to make the C output look nice.»
»
)
dnl $1: name, $2: one-line summary, $3 description
STATEMENT(
«extern int bar»,
«Summary: Illustrate the STATMENT macro»,
«If the header file contains simple statements, they can be documented
with a one-line summary and an optional multi-paragraph description.
This is the second paragrapgh of the description.»
)
STATEMENT(
«struct opaque»,
«Summary: A statement without a description»,
)
»)dnl
|