]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | ||
5 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## | |
6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## | |
7 | ## Copyright (C) 2001 Simon Huggins ## | |
70c95b00 | 8 | ## Copyright (C) 2005-2012 Randy Dunlap ## |
1b40c194 | 9 | ## Copyright (C) 2012 Dan Luedtke ## |
1da177e4 LT |
10 | ## ## |
11 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## | |
12 | ## Copyright (c) 2000 MontaVista Software, Inc. ## | |
13 | ## ## | |
14 | ## This software falls under the GNU General Public License. ## | |
15 | ## Please read the COPYING file for more information ## | |
16 | ||
1da177e4 LT |
17 | # 18/01/2001 - Cleanups |
18 | # Functions prototyped as foo(void) same as foo() | |
19 | # Stop eval'ing where we don't need to. | |
20 | # -- huggie@earth.li | |
21 | ||
22 | # 27/06/2001 - Allowed whitespace after initial "/**" and | |
23 | # allowed comments before function declarations. | |
24 | # -- Christian Kreibich <ck@whoop.org> | |
25 | ||
26 | # Still to do: | |
27 | # - add perldoc documentation | |
28 | # - Look more closely at some of the scarier bits :) | |
29 | ||
30 | # 26/05/2001 - Support for separate source and object trees. | |
31 | # Return error code. | |
32 | # Keith Owens <kaos@ocs.com.au> | |
33 | ||
34 | # 23/09/2001 - Added support for typedefs, structs, enums and unions | |
35 | # Support for Context section; can be terminated using empty line | |
36 | # Small fixes (like spaces vs. \s in regex) | |
37 | # -- Tim Jansen <tim@tjansen.de> | |
38 | ||
1b40c194 DL |
39 | # 25/07/2012 - Added support for HTML5 |
40 | # -- Dan Luedtke <mail@danrl.de> | |
1da177e4 | 41 | |
fadc0b31 JN |
42 | sub usage { |
43 | my $message = <<"EOF"; | |
44 | Usage: $0 [OPTION ...] FILE ... | |
45 | ||
46 | Read C language source or header FILEs, extract embedded documentation comments, | |
47 | and print formatted documentation to standard output. | |
48 | ||
49 | The documentation comments are identified by "/**" opening comment mark. See | |
50 | Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. | |
51 | ||
52 | Output format selection (mutually exclusive): | |
53 | -docbook Output DocBook format. | |
54 | -html Output HTML format. | |
55 | -html5 Output HTML5 format. | |
56 | -list Output symbol list format. This is for use by docproc. | |
57 | -man Output troff manual page format. This is the default. | |
c0d1b6ee | 58 | -rst Output reStructuredText format. |
fadc0b31 JN |
59 | -text Output plain text format. |
60 | ||
61 | Output selection (mutually exclusive): | |
86ae2e38 JN |
62 | -export Only output documentation for symbols that have been |
63 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | |
64 | in the same FILE. | |
65 | -internal Only output documentation for symbols that have NOT been | |
66 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | |
67 | in the same FILE. | |
fadc0b31 JN |
68 | -function NAME Only output documentation for the given function(s) |
69 | or DOC: section title(s). All other functions and DOC: | |
70 | sections are ignored. May be specified multiple times. | |
71 | -nofunction NAME Do NOT output documentation for the given function(s); | |
72 | only output documentation for the other functions and | |
73 | DOC: sections. May be specified multiple times. | |
74 | ||
75 | Output selection modifiers: | |
76 | -no-doc-sections Do not output DOC: sections. | |
77 | ||
78 | Other parameters: | |
79 | -v Verbose output, more warnings and other information. | |
80 | -h Print this help. | |
81 | ||
82 | EOF | |
83 | print $message; | |
84 | exit 1; | |
85 | } | |
1da177e4 LT |
86 | |
87 | # | |
88 | # format of comments. | |
89 | # In the following table, (...)? signifies optional structure. | |
90 | # (...)* signifies 0 or more structure elements | |
91 | # /** | |
92 | # * function_name(:)? (- short description)? | |
93 | # (* @parameterx: (description of parameter x)?)* | |
94 | # (* a blank line)? | |
95 | # * (Description:)? (Description of function)? | |
96 | # * (section header: (section description)? )* | |
97 | # (*)?*/ | |
98 | # | |
99 | # So .. the trivial example would be: | |
100 | # | |
101 | # /** | |
102 | # * my_function | |
b9d97328 | 103 | # */ |
1da177e4 | 104 | # |
891dcd2f | 105 | # If the Description: header tag is omitted, then there must be a blank line |
1da177e4 LT |
106 | # after the last parameter specification. |
107 | # e.g. | |
108 | # /** | |
109 | # * my_function - does my stuff | |
110 | # * @my_arg: its mine damnit | |
111 | # * | |
3c3b809e | 112 | # * Does my stuff explained. |
1da177e4 LT |
113 | # */ |
114 | # | |
115 | # or, could also use: | |
116 | # /** | |
117 | # * my_function - does my stuff | |
118 | # * @my_arg: its mine damnit | |
3c3b809e | 119 | # * Description: Does my stuff explained. |
1da177e4 LT |
120 | # */ |
121 | # etc. | |
122 | # | |
b9d97328 | 123 | # Besides functions you can also write documentation for structs, unions, |
3c3b809e RD |
124 | # enums and typedefs. Instead of the function name you must write the name |
125 | # of the declaration; the struct/union/enum/typedef must always precede | |
126 | # the name. Nesting of declarations is not supported. | |
1da177e4 LT |
127 | # Use the argument mechanism to document members or constants. |
128 | # e.g. | |
129 | # /** | |
130 | # * struct my_struct - short description | |
131 | # * @a: first member | |
132 | # * @b: second member | |
3c3b809e | 133 | # * |
1da177e4 LT |
134 | # * Longer description |
135 | # */ | |
136 | # struct my_struct { | |
137 | # int a; | |
138 | # int b; | |
aeec46b9 MW |
139 | # /* private: */ |
140 | # int c; | |
1da177e4 LT |
141 | # }; |
142 | # | |
143 | # All descriptions can be multiline, except the short function description. | |
3c3b809e | 144 | # |
a4c6ebed DCLP |
145 | # For really longs structs, you can also describe arguments inside the |
146 | # body of the struct. | |
147 | # eg. | |
148 | # /** | |
149 | # * struct my_struct - short description | |
150 | # * @a: first member | |
151 | # * @b: second member | |
152 | # * | |
153 | # * Longer description | |
154 | # */ | |
155 | # struct my_struct { | |
156 | # int a; | |
157 | # int b; | |
158 | # /** | |
159 | # * @c: This is longer description of C | |
160 | # * | |
161 | # * You can use paragraphs to describe arguments | |
162 | # * using this method. | |
163 | # */ | |
164 | # int c; | |
165 | # }; | |
166 | # | |
167 | # This should be use only for struct/enum members. | |
168 | # | |
3c3b809e RD |
169 | # You can also add additional sections. When documenting kernel functions you |
170 | # should document the "Context:" of the function, e.g. whether the functions | |
1da177e4 | 171 | # can be called form interrupts. Unlike other sections you can end it with an |
3c3b809e | 172 | # empty line. |
4092bac7 YB |
173 | # A non-void function should have a "Return:" section describing the return |
174 | # value(s). | |
3c3b809e | 175 | # Example-sections should contain the string EXAMPLE so that they are marked |
1da177e4 LT |
176 | # appropriately in DocBook. |
177 | # | |
178 | # Example: | |
179 | # /** | |
180 | # * user_function - function that can only be called in user context | |
181 | # * @a: some argument | |
182 | # * Context: !in_interrupt() | |
3c3b809e | 183 | # * |
1da177e4 LT |
184 | # * Some description |
185 | # * Example: | |
186 | # * user_function(22); | |
187 | # */ | |
188 | # ... | |
189 | # | |
190 | # | |
191 | # All descriptive text is further processed, scanning for the following special | |
192 | # patterns, which are highlighted appropriately. | |
193 | # | |
194 | # 'funcname()' - function | |
195 | # '$ENVVAR' - environmental variable | |
196 | # '&struct_name' - name of a structure (up to two words including 'struct') | |
197 | # '@parameter' - name of a parameter | |
198 | # '%CONST' - name of a constant. | |
199 | ||
8484baaa RD |
200 | ## init lots of data |
201 | ||
1da177e4 LT |
202 | my $errors = 0; |
203 | my $warnings = 0; | |
5f8c7c98 | 204 | my $anon_struct_union = 0; |
1da177e4 LT |
205 | |
206 | # match expressions used to find embedded type information | |
207 | my $type_constant = '\%([-_\w]+)'; | |
208 | my $type_func = '(\w+)\(\)'; | |
209 | my $type_param = '\@(\w+)'; | |
3eb014a1 | 210 | my $type_struct = '\&((struct\s*)*[_\w]+)'; |
6b5b55f6 | 211 | my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; |
1da177e4 | 212 | my $type_env = '(\$\w+)'; |
c0d1b6ee JC |
213 | my $type_enum_full = '\&(enum)\s*([_\w]+)'; |
214 | my $type_struct_full = '\&(struct)\s*([_\w]+)'; | |
1da177e4 LT |
215 | |
216 | # Output conversion substitutions. | |
217 | # One for each output format | |
218 | ||
219 | # these work fairly well | |
4d732701 DCLP |
220 | my @highlights_html = ( |
221 | [$type_constant, "<i>\$1</i>"], | |
222 | [$type_func, "<b>\$1</b>"], | |
223 | [$type_struct_xml, "<i>\$1</i>"], | |
224 | [$type_env, "<b><i>\$1</i></b>"], | |
225 | [$type_param, "<tt><b>\$1</b></tt>"] | |
226 | ); | |
6b5b55f6 RD |
227 | my $local_lt = "\\\\\\\\lt:"; |
228 | my $local_gt = "\\\\\\\\gt:"; | |
229 | my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" | |
1da177e4 | 230 | |
1b40c194 | 231 | # html version 5 |
4d732701 DCLP |
232 | my @highlights_html5 = ( |
233 | [$type_constant, "<span class=\"const\">\$1</span>"], | |
234 | [$type_func, "<span class=\"func\">\$1</span>"], | |
235 | [$type_struct_xml, "<span class=\"struct\">\$1</span>"], | |
236 | [$type_env, "<span class=\"env\">\$1</span>"], | |
237 | [$type_param, "<span class=\"param\">\$1</span>]"] | |
238 | ); | |
1b40c194 DL |
239 | my $blankline_html5 = $local_lt . "br /" . $local_gt; |
240 | ||
1da177e4 | 241 | # XML, docbook format |
4d732701 DCLP |
242 | my @highlights_xml = ( |
243 | ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], | |
244 | [$type_constant, "<constant>\$1</constant>"], | |
245 | [$type_struct_xml, "<structname>\$1</structname>"], | |
246 | [$type_param, "<parameter>\$1</parameter>"], | |
247 | [$type_func, "<function>\$1</function>"], | |
248 | [$type_env, "<envar>\$1</envar>"] | |
249 | ); | |
5c98fc03 | 250 | my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; |
1da177e4 LT |
251 | |
252 | # gnome, docbook format | |
4d732701 DCLP |
253 | my @highlights_gnome = ( |
254 | [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], | |
255 | [$type_func, "<function>\$1</function>"], | |
256 | [$type_struct, "<structname>\$1</structname>"], | |
257 | [$type_env, "<envar>\$1</envar>"], | |
258 | [$type_param, "<parameter>\$1</parameter>" ] | |
259 | ); | |
1da177e4 LT |
260 | my $blankline_gnome = "</para><para>\n"; |
261 | ||
262 | # these are pretty rough | |
4d732701 DCLP |
263 | my @highlights_man = ( |
264 | [$type_constant, "\$1"], | |
265 | [$type_func, "\\\\fB\$1\\\\fP"], | |
266 | [$type_struct, "\\\\fI\$1\\\\fP"], | |
267 | [$type_param, "\\\\fI\$1\\\\fP"] | |
268 | ); | |
1da177e4 LT |
269 | my $blankline_man = ""; |
270 | ||
271 | # text-mode | |
4d732701 DCLP |
272 | my @highlights_text = ( |
273 | [$type_constant, "\$1"], | |
274 | [$type_func, "\$1"], | |
275 | [$type_struct, "\$1"], | |
276 | [$type_param, "\$1"] | |
277 | ); | |
1da177e4 LT |
278 | my $blankline_text = ""; |
279 | ||
c0d1b6ee JC |
280 | # rst-mode |
281 | my @highlights_rst = ( | |
282 | [$type_constant, "``\$1``"], | |
283 | [$type_func, "\\:c\\:func\\:`\$1`"], | |
62850976 JN |
284 | [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], |
285 | [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], | |
286 | [$type_struct, "\\:c\\:type\\:`struct \$1 <\$1>`"], | |
c0d1b6ee JC |
287 | [$type_param, "**\$1**"] |
288 | ); | |
289 | my $blankline_rst = "\n"; | |
290 | ||
eda603f6 | 291 | # list mode |
4d732701 DCLP |
292 | my @highlights_list = ( |
293 | [$type_constant, "\$1"], | |
294 | [$type_func, "\$1"], | |
295 | [$type_struct, "\$1"], | |
296 | [$type_param, "\$1"] | |
297 | ); | |
eda603f6 | 298 | my $blankline_list = ""; |
1da177e4 | 299 | |
1da177e4 | 300 | # read arguments |
b9d97328 | 301 | if ($#ARGV == -1) { |
1da177e4 LT |
302 | usage(); |
303 | } | |
304 | ||
8484baaa RD |
305 | my $kernelversion; |
306 | my $dohighlight = ""; | |
307 | ||
1da177e4 LT |
308 | my $verbose = 0; |
309 | my $output_mode = "man"; | |
e314ba31 | 310 | my $output_preformatted = 0; |
4b44595a | 311 | my $no_doc_sections = 0; |
4d732701 | 312 | my @highlights = @highlights_man; |
1da177e4 LT |
313 | my $blankline = $blankline_man; |
314 | my $modulename = "Kernel API"; | |
315 | my $function_only = 0; | |
b2c4105b BH |
316 | my $show_not_found = 0; |
317 | ||
318 | my @build_time; | |
319 | if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && | |
320 | (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { | |
321 | @build_time = gmtime($seconds); | |
322 | } else { | |
323 | @build_time = localtime; | |
324 | } | |
325 | ||
3c3b809e RD |
326 | my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', |
327 | 'July', 'August', 'September', 'October', | |
b2c4105b BH |
328 | 'November', 'December')[$build_time[4]] . |
329 | " " . ($build_time[5]+1900); | |
1da177e4 | 330 | |
8484baaa | 331 | # Essentially these are globals. |
b9d97328 RD |
332 | # They probably want to be tidied up, made more localised or something. |
333 | # CAVEAT EMPTOR! Some of the others I localised may not want to be, which | |
1da177e4 | 334 | # could cause "use of undefined value" or other bugs. |
b9d97328 RD |
335 | my ($function, %function_table, %parametertypes, $declaration_purpose); |
336 | my ($type, $declaration_name, $return_type); | |
1c32fd0c | 337 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); |
1da177e4 | 338 | |
bd0e88e5 RD |
339 | if (defined($ENV{'KBUILD_VERBOSE'})) { |
340 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; | |
341 | } | |
342 | ||
3c3b809e | 343 | # Generated docbook code is inserted in a template at a point where |
1da177e4 LT |
344 | # docbook v3.1 requires a non-zero sequence of RefEntry's; see: |
345 | # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html | |
346 | # We keep track of number of generated entries and generate a dummy | |
347 | # if needs be to ensure the expanded template can be postprocessed | |
348 | # into html. | |
349 | my $section_counter = 0; | |
350 | ||
351 | my $lineprefix=""; | |
352 | ||
48af606a JN |
353 | # Parser states |
354 | use constant { | |
355 | STATE_NORMAL => 0, # normal code | |
356 | STATE_NAME => 1, # looking for function name | |
357 | STATE_FIELD => 2, # scanning field start | |
358 | STATE_PROTO => 3, # scanning prototype | |
359 | STATE_DOCBLOCK => 4, # documentation block | |
360 | STATE_INLINE => 5, # gathering documentation outside main block | |
361 | }; | |
1da177e4 | 362 | my $state; |
850622df | 363 | my $in_doc_sect; |
1da177e4 | 364 | |
48af606a JN |
365 | # Inline documentation state |
366 | use constant { | |
367 | STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) | |
368 | STATE_INLINE_NAME => 1, # looking for member name (@foo:) | |
369 | STATE_INLINE_TEXT => 2, # looking for member documentation | |
370 | STATE_INLINE_END => 3, # done | |
371 | STATE_INLINE_ERROR => 4, # error - Comment without header was found. | |
372 | # Spit a warning as it's not | |
373 | # proper kernel-doc and ignore the rest. | |
374 | }; | |
375 | my $inline_doc_state; | |
a4c6ebed | 376 | |
1da177e4 LT |
377 | #declaration types: can be |
378 | # 'function', 'struct', 'union', 'enum', 'typedef' | |
379 | my $decl_type; | |
380 | ||
381 | my $doc_special = "\@\%\$\&"; | |
382 | ||
383 | my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. | |
384 | my $doc_end = '\*/'; | |
385 | my $doc_com = '\s*\*\s*'; | |
12ae6779 | 386 | my $doc_com_body = '\s*\* ?'; |
b9d97328 RD |
387 | my $doc_decl = $doc_com . '(\w+)'; |
388 | my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; | |
12ae6779 | 389 | my $doc_content = $doc_com_body . '(.*)'; |
b9d97328 | 390 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
48af606a JN |
391 | my $doc_inline_start = '^\s*/\*\*\s*$'; |
392 | my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; | |
393 | my $doc_inline_end = '^\s*\*/\s*$'; | |
86ae2e38 | 394 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
1da177e4 LT |
395 | |
396 | my %constants; | |
397 | my %parameterdescs; | |
398 | my @parameterlist; | |
399 | my %sections; | |
400 | my @sectionlist; | |
a1d94aa5 RD |
401 | my $sectcheck; |
402 | my $struct_actual; | |
1da177e4 LT |
403 | |
404 | my $contents = ""; | |
405 | my $section_default = "Description"; # default section | |
406 | my $section_intro = "Introduction"; | |
407 | my $section = $section_default; | |
408 | my $section_context = "Context"; | |
4092bac7 | 409 | my $section_return = "Return"; |
1da177e4 LT |
410 | |
411 | my $undescribed = "-- undescribed --"; | |
412 | ||
413 | reset_state(); | |
414 | ||
415 | while ($ARGV[0] =~ m/^-(.*)/) { | |
416 | my $cmd = shift @ARGV; | |
417 | if ($cmd eq "-html") { | |
418 | $output_mode = "html"; | |
4d732701 | 419 | @highlights = @highlights_html; |
1da177e4 | 420 | $blankline = $blankline_html; |
1b40c194 DL |
421 | } elsif ($cmd eq "-html5") { |
422 | $output_mode = "html5"; | |
4d732701 | 423 | @highlights = @highlights_html5; |
1b40c194 | 424 | $blankline = $blankline_html5; |
1da177e4 LT |
425 | } elsif ($cmd eq "-man") { |
426 | $output_mode = "man"; | |
4d732701 | 427 | @highlights = @highlights_man; |
1da177e4 LT |
428 | $blankline = $blankline_man; |
429 | } elsif ($cmd eq "-text") { | |
430 | $output_mode = "text"; | |
4d732701 | 431 | @highlights = @highlights_text; |
1da177e4 | 432 | $blankline = $blankline_text; |
c0d1b6ee JC |
433 | } elsif ($cmd eq "-rst") { |
434 | $output_mode = "rst"; | |
435 | @highlights = @highlights_rst; | |
436 | $blankline = $blankline_rst; | |
1da177e4 LT |
437 | } elsif ($cmd eq "-docbook") { |
438 | $output_mode = "xml"; | |
4d732701 | 439 | @highlights = @highlights_xml; |
1da177e4 | 440 | $blankline = $blankline_xml; |
eda603f6 JB |
441 | } elsif ($cmd eq "-list") { |
442 | $output_mode = "list"; | |
4d732701 | 443 | @highlights = @highlights_list; |
eda603f6 | 444 | $blankline = $blankline_list; |
1da177e4 LT |
445 | } elsif ($cmd eq "-gnome") { |
446 | $output_mode = "gnome"; | |
4d732701 | 447 | @highlights = @highlights_gnome; |
1da177e4 LT |
448 | $blankline = $blankline_gnome; |
449 | } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document | |
450 | $modulename = shift @ARGV; | |
451 | } elsif ($cmd eq "-function") { # to only output specific functions | |
452 | $function_only = 1; | |
453 | $function = shift @ARGV; | |
454 | $function_table{$function} = 1; | |
455 | } elsif ($cmd eq "-nofunction") { # to only output specific functions | |
456 | $function_only = 2; | |
457 | $function = shift @ARGV; | |
458 | $function_table{$function} = 1; | |
86ae2e38 JN |
459 | } elsif ($cmd eq "-export") { # only exported symbols |
460 | $function_only = 3; | |
461 | %function_table = () | |
462 | } elsif ($cmd eq "-internal") { # only non-exported symbols | |
463 | $function_only = 4; | |
464 | %function_table = () | |
1da177e4 LT |
465 | } elsif ($cmd eq "-v") { |
466 | $verbose = 1; | |
467 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { | |
468 | usage(); | |
4b44595a JB |
469 | } elsif ($cmd eq '-no-doc-sections') { |
470 | $no_doc_sections = 1; | |
e946c43a JB |
471 | } elsif ($cmd eq '-show-not-found') { |
472 | $show_not_found = 1; | |
1da177e4 LT |
473 | } |
474 | } | |
475 | ||
8484baaa RD |
476 | # continue execution near EOF; |
477 | ||
53f049fa BP |
478 | # get kernel version from env |
479 | sub get_kernel_version() { | |
1b9bc22d | 480 | my $version = 'unknown kernel version'; |
53f049fa BP |
481 | |
482 | if (defined($ENV{'KERNELVERSION'})) { | |
483 | $version = $ENV{'KERNELVERSION'}; | |
484 | } | |
485 | return $version; | |
486 | } | |
1da177e4 LT |
487 | |
488 | ## | |
489 | # dumps section contents to arrays/hashes intended for that purpose. | |
490 | # | |
491 | sub dump_section { | |
94dc7ad5 | 492 | my $file = shift; |
1da177e4 LT |
493 | my $name = shift; |
494 | my $contents = join "\n", @_; | |
495 | ||
496 | if ($name =~ m/$type_constant/) { | |
497 | $name = $1; | |
498 | # print STDERR "constant section '$1' = '$contents'\n"; | |
499 | $constants{$name} = $contents; | |
500 | } elsif ($name =~ m/$type_param/) { | |
501 | # print STDERR "parameter def '$1' = '$contents'\n"; | |
502 | $name = $1; | |
503 | $parameterdescs{$name} = $contents; | |
a1d94aa5 | 504 | $sectcheck = $sectcheck . $name . " "; |
ced69090 RD |
505 | } elsif ($name eq "@\.\.\.") { |
506 | # print STDERR "parameter def '...' = '$contents'\n"; | |
507 | $name = "..."; | |
508 | $parameterdescs{$name} = $contents; | |
a1d94aa5 | 509 | $sectcheck = $sectcheck . $name . " "; |
1da177e4 LT |
510 | } else { |
511 | # print STDERR "other section '$name' = '$contents'\n"; | |
94dc7ad5 | 512 | if (defined($sections{$name}) && ($sections{$name} ne "")) { |
d40e1e65 | 513 | print STDERR "${file}:$.: error: duplicate section name '$name'\n"; |
94dc7ad5 RD |
514 | ++$errors; |
515 | } | |
1da177e4 LT |
516 | $sections{$name} = $contents; |
517 | push @sectionlist, $name; | |
518 | } | |
519 | } | |
520 | ||
b112e0f7 JB |
521 | ## |
522 | # dump DOC: section after checking that it should go out | |
523 | # | |
524 | sub dump_doc_section { | |
94dc7ad5 | 525 | my $file = shift; |
b112e0f7 JB |
526 | my $name = shift; |
527 | my $contents = join "\n", @_; | |
528 | ||
4b44595a JB |
529 | if ($no_doc_sections) { |
530 | return; | |
531 | } | |
532 | ||
b112e0f7 JB |
533 | if (($function_only == 0) || |
534 | ( $function_only == 1 && defined($function_table{$name})) || | |
535 | ( $function_only == 2 && !defined($function_table{$name}))) | |
536 | { | |
94dc7ad5 | 537 | dump_section($file, $name, $contents); |
b112e0f7 JB |
538 | output_blockhead({'sectionlist' => \@sectionlist, |
539 | 'sections' => \%sections, | |
540 | 'module' => $modulename, | |
541 | 'content-only' => ($function_only != 0), }); | |
542 | } | |
543 | } | |
544 | ||
1da177e4 LT |
545 | ## |
546 | # output function | |
547 | # | |
548 | # parameterdescs, a hash. | |
549 | # function => "function name" | |
550 | # parameterlist => @list of parameters | |
551 | # parameterdescs => %parameter descriptions | |
552 | # sectionlist => @list of sections | |
a21217da | 553 | # sections => %section descriptions |
3c3b809e | 554 | # |
1da177e4 LT |
555 | |
556 | sub output_highlight { | |
557 | my $contents = join "\n",@_; | |
558 | my $line; | |
559 | ||
560 | # DEBUG | |
561 | # if (!defined $contents) { | |
562 | # use Carp; | |
563 | # confess "output_highlight got called with no args?\n"; | |
564 | # } | |
565 | ||
1b40c194 DL |
566 | if ($output_mode eq "html" || $output_mode eq "html5" || |
567 | $output_mode eq "xml") { | |
6b5b55f6 RD |
568 | $contents = local_unescape($contents); |
569 | # convert data read & converted thru xml_escape() into &xyz; format: | |
2b35f4d9 | 570 | $contents =~ s/\\\\\\/\&/g; |
6b5b55f6 | 571 | } |
3eb014a1 | 572 | # print STDERR "contents b4:$contents\n"; |
1da177e4 LT |
573 | eval $dohighlight; |
574 | die $@ if $@; | |
3eb014a1 RD |
575 | # print STDERR "contents af:$contents\n"; |
576 | ||
1b40c194 DL |
577 | # strip whitespaces when generating html5 |
578 | if ($output_mode eq "html5") { | |
579 | $contents =~ s/^\s+//; | |
580 | $contents =~ s/\s+$//; | |
581 | } | |
1da177e4 | 582 | foreach $line (split "\n", $contents) { |
12ae6779 DS |
583 | if (! $output_preformatted) { |
584 | $line =~ s/^\s*//; | |
585 | } | |
3c308798 | 586 | if ($line eq ""){ |
e314ba31 DS |
587 | if (! $output_preformatted) { |
588 | print $lineprefix, local_unescape($blankline); | |
589 | } | |
1da177e4 | 590 | } else { |
3c308798 | 591 | $line =~ s/\\\\\\/\&/g; |
cdccb316 RD |
592 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { |
593 | print "\\&$line"; | |
594 | } else { | |
595 | print $lineprefix, $line; | |
596 | } | |
1da177e4 LT |
597 | } |
598 | print "\n"; | |
599 | } | |
600 | } | |
601 | ||
1b40c194 | 602 | # output sections in html |
1da177e4 LT |
603 | sub output_section_html(%) { |
604 | my %args = %{$_[0]}; | |
605 | my $section; | |
606 | ||
607 | foreach $section (@{$args{'sectionlist'}}) { | |
608 | print "<h3>$section</h3>\n"; | |
609 | print "<blockquote>\n"; | |
610 | output_highlight($args{'sections'}{$section}); | |
611 | print "</blockquote>\n"; | |
3c3b809e | 612 | } |
1da177e4 LT |
613 | } |
614 | ||
615 | # output enum in html | |
616 | sub output_enum_html(%) { | |
617 | my %args = %{$_[0]}; | |
618 | my ($parameter); | |
619 | my $count; | |
b9d97328 | 620 | print "<h2>enum " . $args{'enum'} . "</h2>\n"; |
1da177e4 | 621 | |
b9d97328 | 622 | print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; |
1da177e4 LT |
623 | $count = 0; |
624 | foreach $parameter (@{$args{'parameterlist'}}) { | |
b9d97328 | 625 | print " <b>" . $parameter . "</b>"; |
1da177e4 LT |
626 | if ($count != $#{$args{'parameterlist'}}) { |
627 | $count++; | |
628 | print ",\n"; | |
629 | } | |
630 | print "<br>"; | |
631 | } | |
632 | print "};<br>\n"; | |
633 | ||
634 | print "<h3>Constants</h3>\n"; | |
635 | print "<dl>\n"; | |
636 | foreach $parameter (@{$args{'parameterlist'}}) { | |
b9d97328 | 637 | print "<dt><b>" . $parameter . "</b>\n"; |
1da177e4 LT |
638 | print "<dd>"; |
639 | output_highlight($args{'parameterdescs'}{$parameter}); | |
640 | } | |
641 | print "</dl>\n"; | |
642 | output_section_html(@_); | |
643 | print "<hr>\n"; | |
644 | } | |
645 | ||
d28bee0c | 646 | # output typedef in html |
1da177e4 LT |
647 | sub output_typedef_html(%) { |
648 | my %args = %{$_[0]}; | |
649 | my ($parameter); | |
650 | my $count; | |
b9d97328 | 651 | print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; |
1da177e4 | 652 | |
b9d97328 | 653 | print "<b>typedef " . $args{'typedef'} . "</b>\n"; |
1da177e4 LT |
654 | output_section_html(@_); |
655 | print "<hr>\n"; | |
656 | } | |
657 | ||
658 | # output struct in html | |
659 | sub output_struct_html(%) { | |
660 | my %args = %{$_[0]}; | |
661 | my ($parameter); | |
662 | ||
b9d97328 RD |
663 | print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; |
664 | print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; | |
1da177e4 LT |
665 | foreach $parameter (@{$args{'parameterlist'}}) { |
666 | if ($parameter =~ /^#/) { | |
667 | print "$parameter<br>\n"; | |
668 | next; | |
669 | } | |
670 | my $parameter_name = $parameter; | |
671 | $parameter_name =~ s/\[.*//; | |
672 | ||
3c308798 | 673 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
674 | $type = $args{'parametertypes'}{$parameter}; |
675 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
676 | # pointer-to-function | |
3eb014a1 | 677 | print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; |
1da177e4 | 678 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
3eb014a1 RD |
679 | # bitfield |
680 | print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; | |
1da177e4 | 681 | } else { |
3eb014a1 | 682 | print " <i>$type</i> <b>$parameter</b>;<br>\n"; |
1da177e4 LT |
683 | } |
684 | } | |
685 | print "};<br>\n"; | |
686 | ||
687 | print "<h3>Members</h3>\n"; | |
688 | print "<dl>\n"; | |
689 | foreach $parameter (@{$args{'parameterlist'}}) { | |
690 | ($parameter =~ /^#/) && next; | |
691 | ||
692 | my $parameter_name = $parameter; | |
693 | $parameter_name =~ s/\[.*//; | |
694 | ||
3c308798 | 695 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 696 | print "<dt><b>" . $parameter . "</b>\n"; |
1da177e4 LT |
697 | print "<dd>"; |
698 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
699 | } | |
700 | print "</dl>\n"; | |
701 | output_section_html(@_); | |
702 | print "<hr>\n"; | |
703 | } | |
704 | ||
705 | # output function in html | |
706 | sub output_function_html(%) { | |
707 | my %args = %{$_[0]}; | |
708 | my ($parameter, $section); | |
709 | my $count; | |
1da177e4 | 710 | |
b9d97328 RD |
711 | print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; |
712 | print "<i>" . $args{'functiontype'} . "</i>\n"; | |
713 | print "<b>" . $args{'function'} . "</b>\n"; | |
1da177e4 LT |
714 | print "("; |
715 | $count = 0; | |
716 | foreach $parameter (@{$args{'parameterlist'}}) { | |
717 | $type = $args{'parametertypes'}{$parameter}; | |
718 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
719 | # pointer-to-function | |
720 | print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; | |
721 | } else { | |
b9d97328 | 722 | print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; |
1da177e4 LT |
723 | } |
724 | if ($count != $#{$args{'parameterlist'}}) { | |
725 | $count++; | |
726 | print ",\n"; | |
727 | } | |
728 | } | |
729 | print ")\n"; | |
730 | ||
731 | print "<h3>Arguments</h3>\n"; | |
732 | print "<dl>\n"; | |
733 | foreach $parameter (@{$args{'parameterlist'}}) { | |
734 | my $parameter_name = $parameter; | |
735 | $parameter_name =~ s/\[.*//; | |
736 | ||
3c308798 | 737 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 738 | print "<dt><b>" . $parameter . "</b>\n"; |
1da177e4 LT |
739 | print "<dd>"; |
740 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
741 | } | |
742 | print "</dl>\n"; | |
743 | output_section_html(@_); | |
744 | print "<hr>\n"; | |
745 | } | |
746 | ||
b112e0f7 JB |
747 | # output DOC: block header in html |
748 | sub output_blockhead_html(%) { | |
1da177e4 LT |
749 | my %args = %{$_[0]}; |
750 | my ($parameter, $section); | |
751 | my $count; | |
752 | ||
753 | foreach $section (@{$args{'sectionlist'}}) { | |
754 | print "<h3>$section</h3>\n"; | |
755 | print "<ul>\n"; | |
756 | output_highlight($args{'sections'}{$section}); | |
757 | print "</ul>\n"; | |
758 | } | |
759 | print "<hr>\n"; | |
760 | } | |
761 | ||
1b40c194 DL |
762 | # output sections in html5 |
763 | sub output_section_html5(%) { | |
764 | my %args = %{$_[0]}; | |
765 | my $section; | |
766 | ||
767 | foreach $section (@{$args{'sectionlist'}}) { | |
768 | print "<section>\n"; | |
769 | print "<h1>$section</h1>\n"; | |
770 | print "<p>\n"; | |
771 | output_highlight($args{'sections'}{$section}); | |
772 | print "</p>\n"; | |
773 | print "</section>\n"; | |
774 | } | |
775 | } | |
776 | ||
777 | # output enum in html5 | |
778 | sub output_enum_html5(%) { | |
779 | my %args = %{$_[0]}; | |
780 | my ($parameter); | |
781 | my $count; | |
782 | my $html5id; | |
783 | ||
784 | $html5id = $args{'enum'}; | |
785 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
786 | print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; | |
787 | print "<h1>enum " . $args{'enum'} . "</h1>\n"; | |
788 | print "<ol class=\"code\">\n"; | |
789 | print "<li>"; | |
790 | print "<span class=\"keyword\">enum</span> "; | |
791 | print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; | |
792 | print "</li>\n"; | |
793 | $count = 0; | |
794 | foreach $parameter (@{$args{'parameterlist'}}) { | |
795 | print "<li class=\"indent\">"; | |
796 | print "<span class=\"param\">" . $parameter . "</span>"; | |
797 | if ($count != $#{$args{'parameterlist'}}) { | |
798 | $count++; | |
799 | print ","; | |
800 | } | |
801 | print "</li>\n"; | |
802 | } | |
803 | print "<li>};</li>\n"; | |
804 | print "</ol>\n"; | |
805 | ||
806 | print "<section>\n"; | |
807 | print "<h1>Constants</h1>\n"; | |
808 | print "<dl>\n"; | |
809 | foreach $parameter (@{$args{'parameterlist'}}) { | |
810 | print "<dt>" . $parameter . "</dt>\n"; | |
811 | print "<dd>"; | |
812 | output_highlight($args{'parameterdescs'}{$parameter}); | |
813 | print "</dd>\n"; | |
814 | } | |
815 | print "</dl>\n"; | |
816 | print "</section>\n"; | |
817 | output_section_html5(@_); | |
818 | print "</article>\n"; | |
819 | } | |
820 | ||
821 | # output typedef in html5 | |
822 | sub output_typedef_html5(%) { | |
823 | my %args = %{$_[0]}; | |
824 | my ($parameter); | |
825 | my $count; | |
826 | my $html5id; | |
827 | ||
828 | $html5id = $args{'typedef'}; | |
829 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
830 | print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; | |
831 | print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; | |
832 | ||
833 | print "<ol class=\"code\">\n"; | |
834 | print "<li>"; | |
835 | print "<span class=\"keyword\">typedef</span> "; | |
836 | print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; | |
837 | print "</li>\n"; | |
838 | print "</ol>\n"; | |
839 | output_section_html5(@_); | |
840 | print "</article>\n"; | |
841 | } | |
842 | ||
843 | # output struct in html5 | |
844 | sub output_struct_html5(%) { | |
845 | my %args = %{$_[0]}; | |
846 | my ($parameter); | |
847 | my $html5id; | |
848 | ||
849 | $html5id = $args{'struct'}; | |
850 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
851 | print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; | |
852 | print "<hgroup>\n"; | |
853 | print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; | |
854 | print "<h2>". $args{'purpose'} . "</h2>\n"; | |
855 | print "</hgroup>\n"; | |
856 | print "<ol class=\"code\">\n"; | |
857 | print "<li>"; | |
858 | print "<span class=\"type\">" . $args{'type'} . "</span> "; | |
859 | print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; | |
860 | print "</li>\n"; | |
861 | foreach $parameter (@{$args{'parameterlist'}}) { | |
862 | print "<li class=\"indent\">"; | |
863 | if ($parameter =~ /^#/) { | |
864 | print "<span class=\"param\">" . $parameter ."</span>\n"; | |
865 | print "</li>\n"; | |
866 | next; | |
867 | } | |
868 | my $parameter_name = $parameter; | |
869 | $parameter_name =~ s/\[.*//; | |
870 | ||
871 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
872 | $type = $args{'parametertypes'}{$parameter}; | |
873 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
874 | # pointer-to-function | |
875 | print "<span class=\"type\">$1</span> "; | |
876 | print "<span class=\"param\">$parameter</span>"; | |
877 | print "<span class=\"type\">)</span> "; | |
878 | print "(<span class=\"args\">$2</span>);"; | |
879 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
880 | # bitfield | |
881 | print "<span class=\"type\">$1</span> "; | |
882 | print "<span class=\"param\">$parameter</span>"; | |
883 | print "<span class=\"bits\">$2</span>;"; | |
884 | } else { | |
885 | print "<span class=\"type\">$type</span> "; | |
886 | print "<span class=\"param\">$parameter</span>;"; | |
887 | } | |
888 | print "</li>\n"; | |
889 | } | |
890 | print "<li>};</li>\n"; | |
891 | print "</ol>\n"; | |
892 | ||
893 | print "<section>\n"; | |
894 | print "<h1>Members</h1>\n"; | |
895 | print "<dl>\n"; | |
896 | foreach $parameter (@{$args{'parameterlist'}}) { | |
897 | ($parameter =~ /^#/) && next; | |
898 | ||
899 | my $parameter_name = $parameter; | |
900 | $parameter_name =~ s/\[.*//; | |
901 | ||
902 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
903 | print "<dt>" . $parameter . "</dt>\n"; | |
904 | print "<dd>"; | |
905 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
906 | print "</dd>\n"; | |
907 | } | |
908 | print "</dl>\n"; | |
909 | print "</section>\n"; | |
910 | output_section_html5(@_); | |
911 | print "</article>\n"; | |
912 | } | |
913 | ||
914 | # output function in html5 | |
915 | sub output_function_html5(%) { | |
916 | my %args = %{$_[0]}; | |
917 | my ($parameter, $section); | |
918 | my $count; | |
919 | my $html5id; | |
920 | ||
921 | $html5id = $args{'function'}; | |
922 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
923 | print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; | |
924 | print "<hgroup>\n"; | |
925 | print "<h1>" . $args{'function'} . "</h1>"; | |
926 | print "<h2>" . $args{'purpose'} . "</h2>\n"; | |
927 | print "</hgroup>\n"; | |
928 | print "<ol class=\"code\">\n"; | |
929 | print "<li>"; | |
930 | print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; | |
931 | print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; | |
932 | print "</li>"; | |
933 | $count = 0; | |
934 | foreach $parameter (@{$args{'parameterlist'}}) { | |
935 | print "<li class=\"indent\">"; | |
936 | $type = $args{'parametertypes'}{$parameter}; | |
937 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
938 | # pointer-to-function | |
939 | print "<span class=\"type\">$1</span> "; | |
940 | print "<span class=\"param\">$parameter</span>"; | |
941 | print "<span class=\"type\">)</span> "; | |
942 | print "(<span class=\"args\">$2</span>)"; | |
943 | } else { | |
944 | print "<span class=\"type\">$type</span> "; | |
945 | print "<span class=\"param\">$parameter</span>"; | |
946 | } | |
947 | if ($count != $#{$args{'parameterlist'}}) { | |
948 | $count++; | |
949 | print ","; | |
950 | } | |
951 | print "</li>\n"; | |
952 | } | |
953 | print "<li>)</li>\n"; | |
954 | print "</ol>\n"; | |
955 | ||
956 | print "<section>\n"; | |
957 | print "<h1>Arguments</h1>\n"; | |
958 | print "<p>\n"; | |
959 | print "<dl>\n"; | |
960 | foreach $parameter (@{$args{'parameterlist'}}) { | |
961 | my $parameter_name = $parameter; | |
962 | $parameter_name =~ s/\[.*//; | |
963 | ||
964 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
965 | print "<dt>" . $parameter . "</dt>\n"; | |
966 | print "<dd>"; | |
967 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
968 | print "</dd>\n"; | |
969 | } | |
970 | print "</dl>\n"; | |
971 | print "</section>\n"; | |
972 | output_section_html5(@_); | |
973 | print "</article>\n"; | |
974 | } | |
975 | ||
976 | # output DOC: block header in html5 | |
977 | sub output_blockhead_html5(%) { | |
978 | my %args = %{$_[0]}; | |
979 | my ($parameter, $section); | |
980 | my $count; | |
981 | my $html5id; | |
982 | ||
983 | foreach $section (@{$args{'sectionlist'}}) { | |
984 | $html5id = $section; | |
985 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
986 | print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; | |
987 | print "<h1>$section</h1>\n"; | |
988 | print "<p>\n"; | |
989 | output_highlight($args{'sections'}{$section}); | |
990 | print "</p>\n"; | |
991 | } | |
992 | print "</article>\n"; | |
993 | } | |
994 | ||
1da177e4 LT |
995 | sub output_section_xml(%) { |
996 | my %args = %{$_[0]}; | |
3c3b809e | 997 | my $section; |
1da177e4 LT |
998 | # print out each section |
999 | $lineprefix=" "; | |
1000 | foreach $section (@{$args{'sectionlist'}}) { | |
c73894c1 RW |
1001 | print "<refsect1>\n"; |
1002 | print "<title>$section</title>\n"; | |
1da177e4 | 1003 | if ($section =~ m/EXAMPLE/i) { |
c73894c1 | 1004 | print "<informalexample><programlisting>\n"; |
e314ba31 | 1005 | $output_preformatted = 1; |
c73894c1 RW |
1006 | } else { |
1007 | print "<para>\n"; | |
1da177e4 LT |
1008 | } |
1009 | output_highlight($args{'sections'}{$section}); | |
e314ba31 | 1010 | $output_preformatted = 0; |
1da177e4 | 1011 | if ($section =~ m/EXAMPLE/i) { |
c73894c1 RW |
1012 | print "</programlisting></informalexample>\n"; |
1013 | } else { | |
1014 | print "</para>\n"; | |
1da177e4 | 1015 | } |
c73894c1 | 1016 | print "</refsect1>\n"; |
1da177e4 LT |
1017 | } |
1018 | } | |
1019 | ||
1020 | # output function in XML DocBook | |
1021 | sub output_function_xml(%) { | |
1022 | my %args = %{$_[0]}; | |
1023 | my ($parameter, $section); | |
1024 | my $count; | |
1025 | my $id; | |
1026 | ||
b9d97328 | 1027 | $id = "API-" . $args{'function'}; |
1da177e4 LT |
1028 | $id =~ s/[^A-Za-z0-9]/-/g; |
1029 | ||
5449bc94 | 1030 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1031 | print "<refentryinfo>\n"; |
1032 | print " <title>LINUX</title>\n"; | |
1033 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1034 | print " <date>$man_date</date>\n"; | |
1035 | print "</refentryinfo>\n"; | |
1da177e4 | 1036 | print "<refmeta>\n"; |
b9d97328 | 1037 | print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1038 | print " <manvolnum>9</manvolnum>\n"; |
0366299b | 1039 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
1da177e4 LT |
1040 | print "</refmeta>\n"; |
1041 | print "<refnamediv>\n"; | |
b9d97328 | 1042 | print " <refname>" . $args{'function'} . "</refname>\n"; |
1da177e4 LT |
1043 | print " <refpurpose>\n"; |
1044 | print " "; | |
1045 | output_highlight ($args{'purpose'}); | |
1046 | print " </refpurpose>\n"; | |
1047 | print "</refnamediv>\n"; | |
1048 | ||
1049 | print "<refsynopsisdiv>\n"; | |
1050 | print " <title>Synopsis</title>\n"; | |
1051 | print " <funcsynopsis><funcprototype>\n"; | |
b9d97328 RD |
1052 | print " <funcdef>" . $args{'functiontype'} . " "; |
1053 | print "<function>" . $args{'function'} . " </function></funcdef>\n"; | |
1da177e4 LT |
1054 | |
1055 | $count = 0; | |
1056 | if ($#{$args{'parameterlist'}} >= 0) { | |
1057 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1058 | $type = $args{'parametertypes'}{$parameter}; | |
1059 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1060 | # pointer-to-function | |
1061 | print " <paramdef>$1<parameter>$parameter</parameter>)\n"; | |
1062 | print " <funcparams>$2</funcparams></paramdef>\n"; | |
1063 | } else { | |
b9d97328 | 1064 | print " <paramdef>" . $type; |
1da177e4 LT |
1065 | print " <parameter>$parameter</parameter></paramdef>\n"; |
1066 | } | |
1067 | } | |
1068 | } else { | |
6013d544 | 1069 | print " <void/>\n"; |
1da177e4 LT |
1070 | } |
1071 | print " </funcprototype></funcsynopsis>\n"; | |
1072 | print "</refsynopsisdiv>\n"; | |
1073 | ||
1074 | # print parameters | |
1075 | print "<refsect1>\n <title>Arguments</title>\n"; | |
1076 | if ($#{$args{'parameterlist'}} >= 0) { | |
1077 | print " <variablelist>\n"; | |
1078 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1079 | my $parameter_name = $parameter; | |
1080 | $parameter_name =~ s/\[.*//; | |
1081 | ||
1082 | print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; | |
1083 | print " <listitem>\n <para>\n"; | |
1084 | $lineprefix=" "; | |
1085 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1086 | print " </para>\n </listitem>\n </varlistentry>\n"; | |
1087 | } | |
1088 | print " </variablelist>\n"; | |
1089 | } else { | |
1090 | print " <para>\n None\n </para>\n"; | |
1091 | } | |
1092 | print "</refsect1>\n"; | |
1093 | ||
1094 | output_section_xml(@_); | |
1095 | print "</refentry>\n\n"; | |
1096 | } | |
1097 | ||
1098 | # output struct in XML DocBook | |
1099 | sub output_struct_xml(%) { | |
1100 | my %args = %{$_[0]}; | |
1101 | my ($parameter, $section); | |
1102 | my $id; | |
1103 | ||
b9d97328 | 1104 | $id = "API-struct-" . $args{'struct'}; |
1da177e4 LT |
1105 | $id =~ s/[^A-Za-z0-9]/-/g; |
1106 | ||
5449bc94 | 1107 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1108 | print "<refentryinfo>\n"; |
1109 | print " <title>LINUX</title>\n"; | |
1110 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1111 | print " <date>$man_date</date>\n"; | |
1112 | print "</refentryinfo>\n"; | |
1da177e4 | 1113 | print "<refmeta>\n"; |
b9d97328 | 1114 | print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1115 | print " <manvolnum>9</manvolnum>\n"; |
0366299b | 1116 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
1da177e4 LT |
1117 | print "</refmeta>\n"; |
1118 | print "<refnamediv>\n"; | |
b9d97328 | 1119 | print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; |
1da177e4 LT |
1120 | print " <refpurpose>\n"; |
1121 | print " "; | |
1122 | output_highlight ($args{'purpose'}); | |
1123 | print " </refpurpose>\n"; | |
1124 | print "</refnamediv>\n"; | |
1125 | ||
1126 | print "<refsynopsisdiv>\n"; | |
1127 | print " <title>Synopsis</title>\n"; | |
1128 | print " <programlisting>\n"; | |
b9d97328 | 1129 | print $args{'type'} . " " . $args{'struct'} . " {\n"; |
1da177e4 LT |
1130 | foreach $parameter (@{$args{'parameterlist'}}) { |
1131 | if ($parameter =~ /^#/) { | |
2b35f4d9 RD |
1132 | my $prm = $parameter; |
1133 | # convert data read & converted thru xml_escape() into &xyz; format: | |
1134 | # This allows us to have #define macros interspersed in a struct. | |
1135 | $prm =~ s/\\\\\\/\&/g; | |
1136 | print "$prm\n"; | |
1da177e4 LT |
1137 | next; |
1138 | } | |
1139 | ||
1140 | my $parameter_name = $parameter; | |
1141 | $parameter_name =~ s/\[.*//; | |
1142 | ||
1143 | defined($args{'parameterdescs'}{$parameter_name}) || next; | |
3c308798 | 1144 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
1145 | $type = $args{'parametertypes'}{$parameter}; |
1146 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1147 | # pointer-to-function | |
1148 | print " $1 $parameter) ($2);\n"; | |
1149 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
51f5a0c8 | 1150 | # bitfield |
1da177e4 LT |
1151 | print " $1 $parameter$2;\n"; |
1152 | } else { | |
b9d97328 | 1153 | print " " . $type . " " . $parameter . ";\n"; |
1da177e4 LT |
1154 | } |
1155 | } | |
1156 | print "};"; | |
1157 | print " </programlisting>\n"; | |
1158 | print "</refsynopsisdiv>\n"; | |
1159 | ||
1160 | print " <refsect1>\n"; | |
1161 | print " <title>Members</title>\n"; | |
1162 | ||
39f00c08 | 1163 | if ($#{$args{'parameterlist'}} >= 0) { |
1da177e4 LT |
1164 | print " <variablelist>\n"; |
1165 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1166 | ($parameter =~ /^#/) && next; | |
1167 | ||
1168 | my $parameter_name = $parameter; | |
1169 | $parameter_name =~ s/\[.*//; | |
1170 | ||
1171 | defined($args{'parameterdescs'}{$parameter_name}) || next; | |
1172 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
1173 | print " <varlistentry>"; | |
1174 | print " <term>$parameter</term>\n"; | |
1175 | print " <listitem><para>\n"; | |
1176 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1177 | print " </para></listitem>\n"; | |
1178 | print " </varlistentry>\n"; | |
1179 | } | |
1180 | print " </variablelist>\n"; | |
39f00c08 RD |
1181 | } else { |
1182 | print " <para>\n None\n </para>\n"; | |
1183 | } | |
1da177e4 LT |
1184 | print " </refsect1>\n"; |
1185 | ||
1186 | output_section_xml(@_); | |
1187 | ||
1188 | print "</refentry>\n\n"; | |
1189 | } | |
1190 | ||
1191 | # output enum in XML DocBook | |
1192 | sub output_enum_xml(%) { | |
1193 | my %args = %{$_[0]}; | |
1194 | my ($parameter, $section); | |
1195 | my $count; | |
1196 | my $id; | |
1197 | ||
b9d97328 | 1198 | $id = "API-enum-" . $args{'enum'}; |
1da177e4 LT |
1199 | $id =~ s/[^A-Za-z0-9]/-/g; |
1200 | ||
5449bc94 | 1201 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1202 | print "<refentryinfo>\n"; |
1203 | print " <title>LINUX</title>\n"; | |
1204 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1205 | print " <date>$man_date</date>\n"; | |
1206 | print "</refentryinfo>\n"; | |
1da177e4 | 1207 | print "<refmeta>\n"; |
b9d97328 | 1208 | print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1209 | print " <manvolnum>9</manvolnum>\n"; |
0366299b | 1210 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
1da177e4 LT |
1211 | print "</refmeta>\n"; |
1212 | print "<refnamediv>\n"; | |
b9d97328 | 1213 | print " <refname>enum " . $args{'enum'} . "</refname>\n"; |
1da177e4 LT |
1214 | print " <refpurpose>\n"; |
1215 | print " "; | |
1216 | output_highlight ($args{'purpose'}); | |
1217 | print " </refpurpose>\n"; | |
1218 | print "</refnamediv>\n"; | |
1219 | ||
1220 | print "<refsynopsisdiv>\n"; | |
1221 | print " <title>Synopsis</title>\n"; | |
1222 | print " <programlisting>\n"; | |
b9d97328 | 1223 | print "enum " . $args{'enum'} . " {\n"; |
1da177e4 LT |
1224 | $count = 0; |
1225 | foreach $parameter (@{$args{'parameterlist'}}) { | |
3c308798 RD |
1226 | print " $parameter"; |
1227 | if ($count != $#{$args{'parameterlist'}}) { | |
1da177e4 LT |
1228 | $count++; |
1229 | print ","; | |
3c308798 | 1230 | } |
1da177e4 LT |
1231 | print "\n"; |
1232 | } | |
1233 | print "};"; | |
1234 | print " </programlisting>\n"; | |
1235 | print "</refsynopsisdiv>\n"; | |
1236 | ||
1237 | print "<refsect1>\n"; | |
3c3b809e | 1238 | print " <title>Constants</title>\n"; |
1da177e4 LT |
1239 | print " <variablelist>\n"; |
1240 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1241 | my $parameter_name = $parameter; | |
1242 | $parameter_name =~ s/\[.*//; | |
1243 | ||
1244 | print " <varlistentry>"; | |
1245 | print " <term>$parameter</term>\n"; | |
1246 | print " <listitem><para>\n"; | |
1247 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1248 | print " </para></listitem>\n"; | |
1249 | print " </varlistentry>\n"; | |
1250 | } | |
1251 | print " </variablelist>\n"; | |
1252 | print "</refsect1>\n"; | |
1253 | ||
1254 | output_section_xml(@_); | |
1255 | ||
1256 | print "</refentry>\n\n"; | |
1257 | } | |
1258 | ||
1259 | # output typedef in XML DocBook | |
1260 | sub output_typedef_xml(%) { | |
1261 | my %args = %{$_[0]}; | |
1262 | my ($parameter, $section); | |
1263 | my $id; | |
1264 | ||
b9d97328 | 1265 | $id = "API-typedef-" . $args{'typedef'}; |
1da177e4 LT |
1266 | $id =~ s/[^A-Za-z0-9]/-/g; |
1267 | ||
5449bc94 | 1268 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1269 | print "<refentryinfo>\n"; |
1270 | print " <title>LINUX</title>\n"; | |
1271 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1272 | print " <date>$man_date</date>\n"; | |
1273 | print "</refentryinfo>\n"; | |
1da177e4 | 1274 | print "<refmeta>\n"; |
b9d97328 | 1275 | print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1276 | print " <manvolnum>9</manvolnum>\n"; |
1da177e4 LT |
1277 | print "</refmeta>\n"; |
1278 | print "<refnamediv>\n"; | |
b9d97328 | 1279 | print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; |
1da177e4 LT |
1280 | print " <refpurpose>\n"; |
1281 | print " "; | |
1282 | output_highlight ($args{'purpose'}); | |
1283 | print " </refpurpose>\n"; | |
1284 | print "</refnamediv>\n"; | |
1285 | ||
1286 | print "<refsynopsisdiv>\n"; | |
1287 | print " <title>Synopsis</title>\n"; | |
b9d97328 | 1288 | print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; |
1da177e4 LT |
1289 | print "</refsynopsisdiv>\n"; |
1290 | ||
1291 | output_section_xml(@_); | |
1292 | ||
1293 | print "</refentry>\n\n"; | |
1294 | } | |
1295 | ||
1296 | # output in XML DocBook | |
b112e0f7 | 1297 | sub output_blockhead_xml(%) { |
1da177e4 LT |
1298 | my %args = %{$_[0]}; |
1299 | my ($parameter, $section); | |
1300 | my $count; | |
1301 | ||
1302 | my $id = $args{'module'}; | |
1303 | $id =~ s/[^A-Za-z0-9]/-/g; | |
1304 | ||
1305 | # print out each section | |
1306 | $lineprefix=" "; | |
1307 | foreach $section (@{$args{'sectionlist'}}) { | |
b112e0f7 JB |
1308 | if (!$args{'content-only'}) { |
1309 | print "<refsect1>\n <title>$section</title>\n"; | |
1310 | } | |
1da177e4 LT |
1311 | if ($section =~ m/EXAMPLE/i) { |
1312 | print "<example><para>\n"; | |
e314ba31 | 1313 | $output_preformatted = 1; |
b112e0f7 JB |
1314 | } else { |
1315 | print "<para>\n"; | |
1da177e4 LT |
1316 | } |
1317 | output_highlight($args{'sections'}{$section}); | |
e314ba31 | 1318 | $output_preformatted = 0; |
1da177e4 LT |
1319 | if ($section =~ m/EXAMPLE/i) { |
1320 | print "</para></example>\n"; | |
b112e0f7 JB |
1321 | } else { |
1322 | print "</para>"; | |
1323 | } | |
1324 | if (!$args{'content-only'}) { | |
1325 | print "\n</refsect1>\n"; | |
1da177e4 | 1326 | } |
1da177e4 LT |
1327 | } |
1328 | ||
1329 | print "\n\n"; | |
1330 | } | |
1331 | ||
1332 | # output in XML DocBook | |
1333 | sub output_function_gnome { | |
1334 | my %args = %{$_[0]}; | |
1335 | my ($parameter, $section); | |
1336 | my $count; | |
1337 | my $id; | |
1338 | ||
b9d97328 | 1339 | $id = $args{'module'} . "-" . $args{'function'}; |
1da177e4 LT |
1340 | $id =~ s/[^A-Za-z0-9]/-/g; |
1341 | ||
1342 | print "<sect2>\n"; | |
b9d97328 | 1343 | print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; |
1da177e4 LT |
1344 | |
1345 | print " <funcsynopsis>\n"; | |
b9d97328 RD |
1346 | print " <funcdef>" . $args{'functiontype'} . " "; |
1347 | print "<function>" . $args{'function'} . " "; | |
1da177e4 LT |
1348 | print "</function></funcdef>\n"; |
1349 | ||
1350 | $count = 0; | |
1351 | if ($#{$args{'parameterlist'}} >= 0) { | |
1352 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1353 | $type = $args{'parametertypes'}{$parameter}; | |
1354 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1355 | # pointer-to-function | |
1356 | print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; | |
1357 | print " <funcparams>$2</funcparams></paramdef>\n"; | |
1358 | } else { | |
b9d97328 | 1359 | print " <paramdef>" . $type; |
1da177e4 LT |
1360 | print " <parameter>$parameter</parameter></paramdef>\n"; |
1361 | } | |
1362 | } | |
1363 | } else { | |
1364 | print " <void>\n"; | |
1365 | } | |
1366 | print " </funcsynopsis>\n"; | |
1367 | if ($#{$args{'parameterlist'}} >= 0) { | |
1368 | print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; | |
1369 | print "<tgroup cols=\"2\">\n"; | |
1370 | print "<colspec colwidth=\"2*\">\n"; | |
1371 | print "<colspec colwidth=\"8*\">\n"; | |
1372 | print "<tbody>\n"; | |
1373 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1374 | my $parameter_name = $parameter; | |
1375 | $parameter_name =~ s/\[.*//; | |
1376 | ||
1377 | print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; | |
1378 | print " <entry>\n"; | |
1379 | $lineprefix=" "; | |
1380 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1381 | print " </entry></row>\n"; | |
1382 | } | |
1383 | print " </tbody></tgroup></informaltable>\n"; | |
1384 | } else { | |
1385 | print " <para>\n None\n </para>\n"; | |
1386 | } | |
1387 | ||
1388 | # print out each section | |
1389 | $lineprefix=" "; | |
1390 | foreach $section (@{$args{'sectionlist'}}) { | |
1391 | print "<simplesect>\n <title>$section</title>\n"; | |
1392 | if ($section =~ m/EXAMPLE/i) { | |
1393 | print "<example><programlisting>\n"; | |
e314ba31 | 1394 | $output_preformatted = 1; |
1da177e4 LT |
1395 | } else { |
1396 | } | |
1397 | print "<para>\n"; | |
1398 | output_highlight($args{'sections'}{$section}); | |
e314ba31 | 1399 | $output_preformatted = 0; |
1da177e4 LT |
1400 | print "</para>\n"; |
1401 | if ($section =~ m/EXAMPLE/i) { | |
1402 | print "</programlisting></example>\n"; | |
1403 | } else { | |
1404 | } | |
1405 | print " </simplesect>\n"; | |
1406 | } | |
1407 | ||
1408 | print "</sect2>\n\n"; | |
1409 | } | |
1410 | ||
1411 | ## | |
1412 | # output function in man | |
1413 | sub output_function_man(%) { | |
1414 | my %args = %{$_[0]}; | |
1415 | my ($parameter, $section); | |
1416 | my $count; | |
1417 | ||
1418 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; | |
1419 | ||
1420 | print ".SH NAME\n"; | |
b9d97328 | 1421 | print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1422 | |
1423 | print ".SH SYNOPSIS\n"; | |
a21217da | 1424 | if ($args{'functiontype'} ne "") { |
b9d97328 | 1425 | print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; |
a21217da | 1426 | } else { |
b9d97328 | 1427 | print ".B \"" . $args{'function'} . "\n"; |
a21217da | 1428 | } |
1da177e4 LT |
1429 | $count = 0; |
1430 | my $parenth = "("; | |
1431 | my $post = ","; | |
1432 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1433 | if ($count == $#{$args{'parameterlist'}}) { | |
1434 | $post = ");"; | |
1435 | } | |
1436 | $type = $args{'parametertypes'}{$parameter}; | |
1437 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1438 | # pointer-to-function | |
b9d97328 | 1439 | print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; |
1da177e4 LT |
1440 | } else { |
1441 | $type =~ s/([^\*])$/$1 /; | |
b9d97328 | 1442 | print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; |
1da177e4 LT |
1443 | } |
1444 | $count++; | |
1445 | $parenth = ""; | |
1446 | } | |
1447 | ||
1448 | print ".SH ARGUMENTS\n"; | |
1449 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1450 | my $parameter_name = $parameter; | |
1451 | $parameter_name =~ s/\[.*//; | |
1452 | ||
b9d97328 | 1453 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
1454 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
1455 | } | |
1456 | foreach $section (@{$args{'sectionlist'}}) { | |
1457 | print ".SH \"", uc $section, "\"\n"; | |
1458 | output_highlight($args{'sections'}{$section}); | |
1459 | } | |
1460 | } | |
1461 | ||
1462 | ## | |
1463 | # output enum in man | |
1464 | sub output_enum_man(%) { | |
1465 | my %args = %{$_[0]}; | |
1466 | my ($parameter, $section); | |
1467 | my $count; | |
1468 | ||
1469 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
1470 | ||
1471 | print ".SH NAME\n"; | |
b9d97328 | 1472 | print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1473 | |
1474 | print ".SH SYNOPSIS\n"; | |
b9d97328 | 1475 | print "enum " . $args{'enum'} . " {\n"; |
1da177e4 LT |
1476 | $count = 0; |
1477 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
3c308798 | 1478 | print ".br\n.BI \" $parameter\"\n"; |
1da177e4 LT |
1479 | if ($count == $#{$args{'parameterlist'}}) { |
1480 | print "\n};\n"; | |
1481 | last; | |
1482 | } | |
1483 | else { | |
1484 | print ", \n.br\n"; | |
1485 | } | |
1486 | $count++; | |
1487 | } | |
1488 | ||
1489 | print ".SH Constants\n"; | |
1490 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1491 | my $parameter_name = $parameter; | |
1492 | $parameter_name =~ s/\[.*//; | |
1493 | ||
b9d97328 | 1494 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
1495 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
1496 | } | |
1497 | foreach $section (@{$args{'sectionlist'}}) { | |
1498 | print ".SH \"$section\"\n"; | |
1499 | output_highlight($args{'sections'}{$section}); | |
1500 | } | |
1501 | } | |
1502 | ||
1503 | ## | |
1504 | # output struct in man | |
1505 | sub output_struct_man(%) { | |
1506 | my %args = %{$_[0]}; | |
1507 | my ($parameter, $section); | |
1508 | ||
b9d97328 | 1509 | print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; |
1da177e4 LT |
1510 | |
1511 | print ".SH NAME\n"; | |
b9d97328 | 1512 | print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1513 | |
1514 | print ".SH SYNOPSIS\n"; | |
b9d97328 | 1515 | print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; |
1da177e4 LT |
1516 | |
1517 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1518 | if ($parameter =~ /^#/) { | |
1519 | print ".BI \"$parameter\"\n.br\n"; | |
1520 | next; | |
1521 | } | |
1522 | my $parameter_name = $parameter; | |
1523 | $parameter_name =~ s/\[.*//; | |
1524 | ||
3c308798 | 1525 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
1526 | $type = $args{'parametertypes'}{$parameter}; |
1527 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1528 | # pointer-to-function | |
b9d97328 | 1529 | print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; |
1da177e4 | 1530 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
1d7e1d45 | 1531 | # bitfield |
b9d97328 | 1532 | print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; |
1da177e4 LT |
1533 | } else { |
1534 | $type =~ s/([^\*])$/$1 /; | |
b9d97328 | 1535 | print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; |
1da177e4 LT |
1536 | } |
1537 | print "\n.br\n"; | |
1538 | } | |
1539 | print "};\n.br\n"; | |
1540 | ||
c51d3dac | 1541 | print ".SH Members\n"; |
1da177e4 LT |
1542 | foreach $parameter (@{$args{'parameterlist'}}) { |
1543 | ($parameter =~ /^#/) && next; | |
1544 | ||
1545 | my $parameter_name = $parameter; | |
1546 | $parameter_name =~ s/\[.*//; | |
1547 | ||
3c308798 | 1548 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 1549 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
1550 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
1551 | } | |
1552 | foreach $section (@{$args{'sectionlist'}}) { | |
1553 | print ".SH \"$section\"\n"; | |
1554 | output_highlight($args{'sections'}{$section}); | |
1555 | } | |
1556 | } | |
1557 | ||
1558 | ## | |
1559 | # output typedef in man | |
1560 | sub output_typedef_man(%) { | |
1561 | my %args = %{$_[0]}; | |
1562 | my ($parameter, $section); | |
1563 | ||
1564 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
1565 | ||
1566 | print ".SH NAME\n"; | |
b9d97328 | 1567 | print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1568 | |
1569 | foreach $section (@{$args{'sectionlist'}}) { | |
1570 | print ".SH \"$section\"\n"; | |
1571 | output_highlight($args{'sections'}{$section}); | |
1572 | } | |
1573 | } | |
1574 | ||
b112e0f7 | 1575 | sub output_blockhead_man(%) { |
1da177e4 LT |
1576 | my %args = %{$_[0]}; |
1577 | my ($parameter, $section); | |
1578 | my $count; | |
1579 | ||
1580 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
1581 | ||
1582 | foreach $section (@{$args{'sectionlist'}}) { | |
1583 | print ".SH \"$section\"\n"; | |
1584 | output_highlight($args{'sections'}{$section}); | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | ## | |
1589 | # output in text | |
1590 | sub output_function_text(%) { | |
1591 | my %args = %{$_[0]}; | |
1592 | my ($parameter, $section); | |
a21217da | 1593 | my $start; |
1da177e4 | 1594 | |
f47634b2 | 1595 | print "Name:\n\n"; |
b9d97328 | 1596 | print $args{'function'} . " - " . $args{'purpose'} . "\n"; |
f47634b2 RD |
1597 | |
1598 | print "\nSynopsis:\n\n"; | |
a21217da | 1599 | if ($args{'functiontype'} ne "") { |
b9d97328 | 1600 | $start = $args{'functiontype'} . " " . $args{'function'} . " ("; |
a21217da | 1601 | } else { |
b9d97328 | 1602 | $start = $args{'function'} . " ("; |
a21217da | 1603 | } |
1da177e4 | 1604 | print $start; |
a21217da | 1605 | |
1da177e4 LT |
1606 | my $count = 0; |
1607 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1608 | $type = $args{'parametertypes'}{$parameter}; | |
1609 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1610 | # pointer-to-function | |
b9d97328 | 1611 | print $1 . $parameter . ") (" . $2; |
1da177e4 | 1612 | } else { |
b9d97328 | 1613 | print $type . " " . $parameter; |
1da177e4 LT |
1614 | } |
1615 | if ($count != $#{$args{'parameterlist'}}) { | |
1616 | $count++; | |
1617 | print ",\n"; | |
1618 | print " " x length($start); | |
1619 | } else { | |
1620 | print ");\n\n"; | |
1621 | } | |
1622 | } | |
1623 | ||
1624 | print "Arguments:\n\n"; | |
1625 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1626 | my $parameter_name = $parameter; | |
1627 | $parameter_name =~ s/\[.*//; | |
1628 | ||
b9d97328 | 1629 | print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; |
1da177e4 LT |
1630 | } |
1631 | output_section_text(@_); | |
1632 | } | |
1633 | ||
1634 | #output sections in text | |
1635 | sub output_section_text(%) { | |
1636 | my %args = %{$_[0]}; | |
1637 | my $section; | |
1638 | ||
1639 | print "\n"; | |
1640 | foreach $section (@{$args{'sectionlist'}}) { | |
1641 | print "$section:\n\n"; | |
1642 | output_highlight($args{'sections'}{$section}); | |
3c3b809e | 1643 | } |
1da177e4 LT |
1644 | print "\n\n"; |
1645 | } | |
1646 | ||
1647 | # output enum in text | |
1648 | sub output_enum_text(%) { | |
1649 | my %args = %{$_[0]}; | |
1650 | my ($parameter); | |
1651 | my $count; | |
1652 | print "Enum:\n\n"; | |
1653 | ||
b9d97328 RD |
1654 | print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; |
1655 | print "enum " . $args{'enum'} . " {\n"; | |
1da177e4 LT |
1656 | $count = 0; |
1657 | foreach $parameter (@{$args{'parameterlist'}}) { | |
3c308798 | 1658 | print "\t$parameter"; |
1da177e4 LT |
1659 | if ($count != $#{$args{'parameterlist'}}) { |
1660 | $count++; | |
1661 | print ","; | |
1662 | } | |
1663 | print "\n"; | |
1664 | } | |
1665 | print "};\n\n"; | |
1666 | ||
1667 | print "Constants:\n\n"; | |
1668 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1669 | print "$parameter\n\t"; | |
b9d97328 | 1670 | print $args{'parameterdescs'}{$parameter} . "\n"; |
1da177e4 LT |
1671 | } |
1672 | ||
1673 | output_section_text(@_); | |
1674 | } | |
1675 | ||
1676 | # output typedef in text | |
1677 | sub output_typedef_text(%) { | |
1678 | my %args = %{$_[0]}; | |
1679 | my ($parameter); | |
1680 | my $count; | |
1681 | print "Typedef:\n\n"; | |
1682 | ||
b9d97328 | 1683 | print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1684 | output_section_text(@_); |
1685 | } | |
1686 | ||
1687 | # output struct as text | |
1688 | sub output_struct_text(%) { | |
1689 | my %args = %{$_[0]}; | |
1690 | my ($parameter); | |
1691 | ||
b9d97328 RD |
1692 | print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; |
1693 | print $args{'type'} . " " . $args{'struct'} . " {\n"; | |
1da177e4 LT |
1694 | foreach $parameter (@{$args{'parameterlist'}}) { |
1695 | if ($parameter =~ /^#/) { | |
1696 | print "$parameter\n"; | |
1697 | next; | |
1698 | } | |
1699 | ||
1700 | my $parameter_name = $parameter; | |
1701 | $parameter_name =~ s/\[.*//; | |
1702 | ||
3c308798 | 1703 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
1704 | $type = $args{'parametertypes'}{$parameter}; |
1705 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1706 | # pointer-to-function | |
1707 | print "\t$1 $parameter) ($2);\n"; | |
1708 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
51f5a0c8 | 1709 | # bitfield |
1da177e4 LT |
1710 | print "\t$1 $parameter$2;\n"; |
1711 | } else { | |
b9d97328 | 1712 | print "\t" . $type . " " . $parameter . ";\n"; |
1da177e4 LT |
1713 | } |
1714 | } | |
1715 | print "};\n\n"; | |
1716 | ||
1717 | print "Members:\n\n"; | |
1718 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1719 | ($parameter =~ /^#/) && next; | |
1720 | ||
1721 | my $parameter_name = $parameter; | |
1722 | $parameter_name =~ s/\[.*//; | |
1723 | ||
3c308798 | 1724 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 | 1725 | print "$parameter\n\t"; |
b9d97328 | 1726 | print $args{'parameterdescs'}{$parameter_name} . "\n"; |
1da177e4 LT |
1727 | } |
1728 | print "\n"; | |
1729 | output_section_text(@_); | |
1730 | } | |
1731 | ||
b112e0f7 | 1732 | sub output_blockhead_text(%) { |
1da177e4 LT |
1733 | my %args = %{$_[0]}; |
1734 | my ($parameter, $section); | |
1735 | ||
1736 | foreach $section (@{$args{'sectionlist'}}) { | |
1737 | print " $section:\n"; | |
1738 | print " -> "; | |
1739 | output_highlight($args{'sections'}{$section}); | |
1740 | } | |
1741 | } | |
1742 | ||
c0d1b6ee JC |
1743 | ## |
1744 | # output in restructured text | |
1745 | # | |
1746 | ||
1747 | # | |
1748 | # This could use some work; it's used to output the DOC: sections, and | |
1749 | # starts by putting out the name of the doc section itself, but that tends | |
1750 | # to duplicate a header already in the template file. | |
1751 | # | |
1752 | sub output_blockhead_rst(%) { | |
1753 | my %args = %{$_[0]}; | |
1754 | my ($parameter, $section); | |
1755 | ||
1756 | foreach $section (@{$args{'sectionlist'}}) { | |
1757 | print "**$section**\n\n"; | |
1758 | output_highlight_rst($args{'sections'}{$section}); | |
1759 | print "\n"; | |
1760 | } | |
1761 | } | |
1762 | ||
1763 | sub output_highlight_rst { | |
1764 | my $contents = join "\n",@_; | |
1765 | my $line; | |
1766 | ||
1767 | # undo the evil effects of xml_escape() earlier | |
1768 | $contents = xml_unescape($contents); | |
1769 | ||
1770 | eval $dohighlight; | |
1771 | die $@ if $@; | |
1772 | ||
1773 | foreach $line (split "\n", $contents) { | |
1774 | if ($line eq "") { | |
1775 | print $lineprefix, $blankline; | |
1776 | } else { | |
1777 | $line =~ s/\\\\\\/\&/g; | |
1778 | print $lineprefix, $line; | |
1779 | } | |
1780 | print "\n"; | |
1781 | } | |
1782 | } | |
1783 | ||
1784 | sub output_function_rst(%) { | |
1785 | my %args = %{$_[0]}; | |
1786 | my ($parameter, $section); | |
1787 | my $start; | |
1788 | ||
1789 | print ".. c:function:: "; | |
1790 | if ($args{'functiontype'} ne "") { | |
1791 | $start = $args{'functiontype'} . " " . $args{'function'} . " ("; | |
1792 | } else { | |
1793 | $start = $args{'function'} . " ("; | |
1794 | } | |
1795 | print $start; | |
1796 | ||
1797 | my $count = 0; | |
1798 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1799 | if ($count ne 0) { | |
1800 | print ", "; | |
1801 | } | |
1802 | $count++; | |
1803 | $type = $args{'parametertypes'}{$parameter}; | |
1804 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1805 | # pointer-to-function | |
1806 | print $1 . $parameter . ") (" . $2; | |
1807 | } else { | |
1808 | print $type . " " . $parameter; | |
1809 | } | |
1810 | } | |
1811 | print ")\n\n " . $args{'purpose'} . "\n\n"; | |
1812 | ||
1813 | print ":Parameters:\n\n"; | |
1814 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1815 | my $parameter_name = $parameter; | |
1816 | #$parameter_name =~ s/\[.*//; | |
1817 | $type = $args{'parametertypes'}{$parameter}; | |
1818 | ||
1819 | if ($type ne "") { | |
1820 | print " ``$type $parameter``\n"; | |
1821 | } else { | |
1822 | print " ``$parameter``\n"; | |
1823 | } | |
5e64fa9c JN |
1824 | if (defined($args{'parameterdescs'}{$parameter_name}) && |
1825 | $args{'parameterdescs'}{$parameter_name} ne $undescribed) { | |
c0d1b6ee JC |
1826 | my $oldprefix = $lineprefix; |
1827 | $lineprefix = " "; | |
1828 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | |
1829 | $lineprefix = $oldprefix; | |
1830 | } else { | |
1831 | print "\n _undescribed_\n"; | |
1832 | } | |
1833 | print "\n"; | |
1834 | } | |
1835 | output_section_rst(@_); | |
1836 | } | |
1837 | ||
1838 | sub output_section_rst(%) { | |
1839 | my %args = %{$_[0]}; | |
1840 | my $section; | |
1841 | my $oldprefix = $lineprefix; | |
1842 | $lineprefix = " "; | |
1843 | ||
1844 | foreach $section (@{$args{'sectionlist'}}) { | |
1845 | print ":$section:\n\n"; | |
1846 | output_highlight_rst($args{'sections'}{$section}); | |
1847 | print "\n"; | |
1848 | } | |
1849 | print "\n"; | |
1850 | $lineprefix = $oldprefix; | |
1851 | } | |
1852 | ||
1853 | sub output_enum_rst(%) { | |
1854 | my %args = %{$_[0]}; | |
1855 | my ($parameter); | |
1856 | my $count; | |
c0d1b6ee | 1857 | my $name = "enum " . $args{'enum'}; |
62850976 JN |
1858 | |
1859 | print "\n\n.. c:type:: " . $name . "\n\n"; | |
c0d1b6ee JC |
1860 | print " " . $args{'purpose'} . "\n\n"; |
1861 | ||
1862 | print "..\n\n:Constants:\n\n"; | |
1863 | my $oldprefix = $lineprefix; | |
1864 | $lineprefix = " "; | |
1865 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1866 | print " `$parameter`\n"; | |
1867 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { | |
1868 | output_highlight_rst($args{'parameterdescs'}{$parameter}); | |
1869 | } else { | |
1870 | print " undescribed\n"; | |
1871 | } | |
1872 | print "\n"; | |
1873 | } | |
1874 | $lineprefix = $oldprefix; | |
1875 | output_section_rst(@_); | |
1876 | } | |
1877 | ||
1878 | sub output_typedef_rst(%) { | |
1879 | my %args = %{$_[0]}; | |
1880 | my ($parameter); | |
1881 | my $count; | |
1882 | my $name = "typedef " . $args{'typedef'}; | |
1883 | ||
62850976 JN |
1884 | ### FIXME: should the name below contain "typedef" or not? |
1885 | print "\n\n.. c:type:: " . $name . "\n\n"; | |
1886 | print " " . $args{'purpose'} . "\n\n"; | |
c0d1b6ee JC |
1887 | |
1888 | output_section_rst(@_); | |
1889 | } | |
1890 | ||
1891 | sub output_struct_rst(%) { | |
1892 | my %args = %{$_[0]}; | |
1893 | my ($parameter); | |
1894 | my $name = $args{'type'} . " " . $args{'struct'}; | |
1895 | ||
62850976 | 1896 | print "\n\n.. c:type:: " . $name . "\n\n"; |
c0d1b6ee JC |
1897 | print " " . $args{'purpose'} . "\n\n"; |
1898 | ||
1899 | print ":Definition:\n\n"; | |
1900 | print " ::\n\n"; | |
1901 | print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; | |
1902 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1903 | if ($parameter =~ /^#/) { | |
1904 | print " " . "$parameter\n"; | |
1905 | next; | |
1906 | } | |
1907 | ||
1908 | my $parameter_name = $parameter; | |
1909 | $parameter_name =~ s/\[.*//; | |
1910 | ||
1911 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
1912 | $type = $args{'parametertypes'}{$parameter}; | |
1913 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1914 | # pointer-to-function | |
1915 | print " $1 $parameter) ($2);\n"; | |
1916 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
1917 | # bitfield | |
1918 | print " $1 $parameter$2;\n"; | |
1919 | } else { | |
1920 | print " " . $type . " " . $parameter . ";\n"; | |
1921 | } | |
1922 | } | |
1923 | print " };\n\n"; | |
1924 | ||
1925 | print ":Members:\n\n"; | |
1926 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1927 | ($parameter =~ /^#/) && next; | |
1928 | ||
1929 | my $parameter_name = $parameter; | |
1930 | $parameter_name =~ s/\[.*//; | |
1931 | ||
1932 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
1933 | $type = $args{'parametertypes'}{$parameter}; | |
1934 | print " `$type $parameter`" . "\n"; | |
1935 | my $oldprefix = $lineprefix; | |
1936 | $lineprefix = " "; | |
1937 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | |
1938 | $lineprefix = $oldprefix; | |
1939 | print "\n"; | |
1940 | } | |
1941 | print "\n"; | |
1942 | output_section_rst(@_); | |
1943 | } | |
1944 | ||
1945 | ||
eda603f6 JB |
1946 | ## list mode output functions |
1947 | ||
1948 | sub output_function_list(%) { | |
1949 | my %args = %{$_[0]}; | |
1950 | ||
1951 | print $args{'function'} . "\n"; | |
1952 | } | |
1953 | ||
1954 | # output enum in list | |
1955 | sub output_enum_list(%) { | |
1956 | my %args = %{$_[0]}; | |
1957 | print $args{'enum'} . "\n"; | |
1958 | } | |
1959 | ||
1960 | # output typedef in list | |
1961 | sub output_typedef_list(%) { | |
1962 | my %args = %{$_[0]}; | |
1963 | print $args{'typedef'} . "\n"; | |
1964 | } | |
1965 | ||
1966 | # output struct as list | |
1967 | sub output_struct_list(%) { | |
1968 | my %args = %{$_[0]}; | |
1969 | ||
1970 | print $args{'struct'} . "\n"; | |
1971 | } | |
1972 | ||
1973 | sub output_blockhead_list(%) { | |
1974 | my %args = %{$_[0]}; | |
1975 | my ($parameter, $section); | |
1976 | ||
1977 | foreach $section (@{$args{'sectionlist'}}) { | |
1978 | print "DOC: $section\n"; | |
1979 | } | |
1980 | } | |
1981 | ||
1da177e4 | 1982 | ## |
27205744 RD |
1983 | # generic output function for all types (function, struct/union, typedef, enum); |
1984 | # calls the generated, variable output_ function name based on | |
1985 | # functype and output_mode | |
1da177e4 LT |
1986 | sub output_declaration { |
1987 | no strict 'refs'; | |
1988 | my $name = shift; | |
1989 | my $functype = shift; | |
1990 | my $func = "output_${functype}_$output_mode"; | |
3c3b809e | 1991 | if (($function_only==0) || |
86ae2e38 JN |
1992 | ( ($function_only == 1 || $function_only == 3) && |
1993 | defined($function_table{$name})) || | |
1994 | ( ($function_only == 2 || $function_only == 4) && | |
1995 | !($functype eq "function" && defined($function_table{$name})))) | |
1da177e4 | 1996 | { |
3c308798 | 1997 | &$func(@_); |
1da177e4 LT |
1998 | $section_counter++; |
1999 | } | |
2000 | } | |
2001 | ||
2002 | ## | |
27205744 | 2003 | # generic output function - calls the right one based on current output mode. |
b112e0f7 | 2004 | sub output_blockhead { |
1da177e4 | 2005 | no strict 'refs'; |
b9d97328 | 2006 | my $func = "output_blockhead_" . $output_mode; |
1da177e4 LT |
2007 | &$func(@_); |
2008 | $section_counter++; | |
2009 | } | |
2010 | ||
2011 | ## | |
3c3b809e | 2012 | # takes a declaration (struct, union, enum, typedef) and |
1da177e4 LT |
2013 | # invokes the right handler. NOT called for functions. |
2014 | sub dump_declaration($$) { | |
2015 | no strict 'refs'; | |
2016 | my ($prototype, $file) = @_; | |
b9d97328 | 2017 | my $func = "dump_" . $decl_type; |
1da177e4 LT |
2018 | &$func(@_); |
2019 | } | |
2020 | ||
2021 | sub dump_union($$) { | |
2022 | dump_struct(@_); | |
2023 | } | |
2024 | ||
2025 | sub dump_struct($$) { | |
2026 | my $x = shift; | |
2027 | my $file = shift; | |
a1d94aa5 | 2028 | my $nested; |
1da177e4 | 2029 | |
52dc5aec RD |
2030 | if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { |
2031 | #my $decl_type = $1; | |
3c308798 RD |
2032 | $declaration_name = $2; |
2033 | my $members = $3; | |
1da177e4 LT |
2034 | |
2035 | # ignore embedded structs or unions | |
a1d94aa5 RD |
2036 | $members =~ s/({.*})//g; |
2037 | $nested = $1; | |
1da177e4 | 2038 | |
aeec46b9 | 2039 | # ignore members marked private: |
0d8c39e6 MCC |
2040 | $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; |
2041 | $members =~ s/\/\*\s*private:.*//gosi; | |
aeec46b9 MW |
2042 | # strip comments: |
2043 | $members =~ s/\/\*.*?\*\///gos; | |
a1d94aa5 | 2044 | $nested =~ s/\/\*.*?\*\///gos; |
d960eea9 RD |
2045 | # strip kmemcheck_bitfield_{begin,end}.*; |
2046 | $members =~ s/kmemcheck_bitfield_.*?;//gos; | |
ef5da59f | 2047 | # strip attributes |
f0074929 | 2048 | $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
7b990789 | 2049 | $members =~ s/__aligned\s*\([^;]*\)//gos; |
f0074929 | 2050 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; |
b22b5a9e CN |
2051 | # replace DECLARE_BITMAP |
2052 | $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; | |
aeec46b9 | 2053 | |
1da177e4 | 2054 | create_parameterlist($members, ';', $file); |
a1d94aa5 | 2055 | check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); |
1da177e4 LT |
2056 | |
2057 | output_declaration($declaration_name, | |
2058 | 'struct', | |
2059 | {'struct' => $declaration_name, | |
2060 | 'module' => $modulename, | |
2061 | 'parameterlist' => \@parameterlist, | |
2062 | 'parameterdescs' => \%parameterdescs, | |
2063 | 'parametertypes' => \%parametertypes, | |
2064 | 'sectionlist' => \@sectionlist, | |
2065 | 'sections' => \%sections, | |
2066 | 'purpose' => $declaration_purpose, | |
2067 | 'type' => $decl_type | |
2068 | }); | |
2069 | } | |
2070 | else { | |
d40e1e65 | 2071 | print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; |
1da177e4 LT |
2072 | ++$errors; |
2073 | } | |
2074 | } | |
2075 | ||
2076 | sub dump_enum($$) { | |
2077 | my $x = shift; | |
2078 | my $file = shift; | |
2079 | ||
aeec46b9 | 2080 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
4468e21e CN |
2081 | # strip #define macros inside enums |
2082 | $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; | |
b6d676db | 2083 | |
1da177e4 | 2084 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { |
3c308798 RD |
2085 | $declaration_name = $1; |
2086 | my $members = $2; | |
1da177e4 LT |
2087 | |
2088 | foreach my $arg (split ',', $members) { | |
2089 | $arg =~ s/^\s*(\w+).*/$1/; | |
2090 | push @parameterlist, $arg; | |
2091 | if (!$parameterdescs{$arg}) { | |
3c308798 | 2092 | $parameterdescs{$arg} = $undescribed; |
d40e1e65 | 2093 | print STDERR "${file}:$.: warning: Enum value '$arg' ". |
1da177e4 LT |
2094 | "not described in enum '$declaration_name'\n"; |
2095 | } | |
2096 | ||
2097 | } | |
3c3b809e | 2098 | |
1da177e4 LT |
2099 | output_declaration($declaration_name, |
2100 | 'enum', | |
2101 | {'enum' => $declaration_name, | |
2102 | 'module' => $modulename, | |
2103 | 'parameterlist' => \@parameterlist, | |
2104 | 'parameterdescs' => \%parameterdescs, | |
2105 | 'sectionlist' => \@sectionlist, | |
2106 | 'sections' => \%sections, | |
2107 | 'purpose' => $declaration_purpose | |
2108 | }); | |
2109 | } | |
2110 | else { | |
d40e1e65 | 2111 | print STDERR "${file}:$.: error: Cannot parse enum!\n"; |
1da177e4 LT |
2112 | ++$errors; |
2113 | } | |
2114 | } | |
2115 | ||
2116 | sub dump_typedef($$) { | |
2117 | my $x = shift; | |
2118 | my $file = shift; | |
2119 | ||
aeec46b9 | 2120 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
1da177e4 | 2121 | |
83766452 MCC |
2122 | # Parse function prototypes |
2123 | if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { | |
2124 | # Function typedefs | |
2125 | $return_type = $1; | |
2126 | $declaration_name = $2; | |
2127 | my $args = $3; | |
2128 | ||
2129 | create_parameterlist($args, ',', $file); | |
1da177e4 LT |
2130 | |
2131 | output_declaration($declaration_name, | |
83766452 MCC |
2132 | 'function', |
2133 | {'function' => $declaration_name, | |
1da177e4 | 2134 | 'module' => $modulename, |
83766452 MCC |
2135 | 'functiontype' => $return_type, |
2136 | 'parameterlist' => \@parameterlist, | |
2137 | 'parameterdescs' => \%parameterdescs, | |
2138 | 'parametertypes' => \%parametertypes, | |
1da177e4 LT |
2139 | 'sectionlist' => \@sectionlist, |
2140 | 'sections' => \%sections, | |
2141 | 'purpose' => $declaration_purpose | |
2142 | }); | |
83766452 MCC |
2143 | return; |
2144 | } | |
2145 | ||
2146 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { | |
2147 | $x =~ s/\(*.\)\s*;$/;/; | |
2148 | $x =~ s/\[*.\]\s*;$/;/; | |
1da177e4 | 2149 | } |
83766452 MCC |
2150 | |
2151 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { | |
3a80a766 MCC |
2152 | $declaration_name = $1; |
2153 | ||
2154 | output_declaration($declaration_name, | |
2155 | 'typedef', | |
2156 | {'typedef' => $declaration_name, | |
2157 | 'module' => $modulename, | |
2158 | 'sectionlist' => \@sectionlist, | |
2159 | 'sections' => \%sections, | |
2160 | 'purpose' => $declaration_purpose | |
2161 | }); | |
2162 | } | |
1da177e4 | 2163 | else { |
d40e1e65 | 2164 | print STDERR "${file}:$.: error: Cannot parse typedef!\n"; |
1da177e4 LT |
2165 | ++$errors; |
2166 | } | |
2167 | } | |
2168 | ||
a1d94aa5 RD |
2169 | sub save_struct_actual($) { |
2170 | my $actual = shift; | |
2171 | ||
2172 | # strip all spaces from the actual param so that it looks like one string item | |
2173 | $actual =~ s/\s*//g; | |
2174 | $struct_actual = $struct_actual . $actual . " "; | |
2175 | } | |
2176 | ||
1da177e4 LT |
2177 | sub create_parameterlist($$$) { |
2178 | my $args = shift; | |
2179 | my $splitter = shift; | |
2180 | my $file = shift; | |
2181 | my $type; | |
2182 | my $param; | |
2183 | ||
a6d3fe77 | 2184 | # temporarily replace commas inside function pointer definition |
1da177e4 | 2185 | while ($args =~ /(\([^\),]+),/) { |
3c308798 | 2186 | $args =~ s/(\([^\),]+),/$1#/g; |
1da177e4 | 2187 | } |
3c3b809e | 2188 | |
1da177e4 LT |
2189 | foreach my $arg (split($splitter, $args)) { |
2190 | # strip comments | |
2191 | $arg =~ s/\/\*.*\*\///; | |
3c308798 RD |
2192 | # strip leading/trailing spaces |
2193 | $arg =~ s/^\s*//; | |
1da177e4 LT |
2194 | $arg =~ s/\s*$//; |
2195 | $arg =~ s/\s+/ /; | |
2196 | ||
2197 | if ($arg =~ /^#/) { | |
2198 | # Treat preprocessor directive as a typeless variable just to fill | |
2199 | # corresponding data structures "correctly". Catch it later in | |
2200 | # output_* subs. | |
2201 | push_parameter($arg, "", $file); | |
00d62961 | 2202 | } elsif ($arg =~ m/\(.+\)\s*\(/) { |
1da177e4 LT |
2203 | # pointer-to-function |
2204 | $arg =~ tr/#/,/; | |
00d62961 | 2205 | $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; |
1da177e4 LT |
2206 | $param = $1; |
2207 | $type = $arg; | |
00d62961 | 2208 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
a1d94aa5 | 2209 | save_struct_actual($param); |
1da177e4 | 2210 | push_parameter($param, $type, $file); |
aeec46b9 | 2211 | } elsif ($arg) { |
1da177e4 LT |
2212 | $arg =~ s/\s*:\s*/:/g; |
2213 | $arg =~ s/\s*\[/\[/g; | |
2214 | ||
2215 | my @args = split('\s*,\s*', $arg); | |
2216 | if ($args[0] =~ m/\*/) { | |
2217 | $args[0] =~ s/(\*+)\s*/ $1/; | |
2218 | } | |
884f2810 BP |
2219 | |
2220 | my @first_arg; | |
2221 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { | |
2222 | shift @args; | |
2223 | push(@first_arg, split('\s+', $1)); | |
2224 | push(@first_arg, $2); | |
2225 | } else { | |
2226 | @first_arg = split('\s+', shift @args); | |
2227 | } | |
2228 | ||
1da177e4 LT |
2229 | unshift(@args, pop @first_arg); |
2230 | $type = join " ", @first_arg; | |
2231 | ||
2232 | foreach $param (@args) { | |
2233 | if ($param =~ m/^(\*+)\s*(.*)/) { | |
a1d94aa5 | 2234 | save_struct_actual($2); |
1da177e4 LT |
2235 | push_parameter($2, "$type $1", $file); |
2236 | } | |
2237 | elsif ($param =~ m/(.*?):(\d+)/) { | |
7b97887e | 2238 | if ($type ne "") { # skip unnamed bit-fields |
a1d94aa5 | 2239 | save_struct_actual($1); |
7b97887e RD |
2240 | push_parameter($1, "$type:$2", $file) |
2241 | } | |
1da177e4 LT |
2242 | } |
2243 | else { | |
a1d94aa5 | 2244 | save_struct_actual($param); |
1da177e4 LT |
2245 | push_parameter($param, $type, $file); |
2246 | } | |
2247 | } | |
2248 | } | |
2249 | } | |
2250 | } | |
2251 | ||
2252 | sub push_parameter($$$) { | |
2253 | my $param = shift; | |
2254 | my $type = shift; | |
2255 | my $file = shift; | |
2256 | ||
5f8c7c98 RD |
2257 | if (($anon_struct_union == 1) && ($type eq "") && |
2258 | ($param eq "}")) { | |
2259 | return; # ignore the ending }; from anon. struct/union | |
2260 | } | |
2261 | ||
2262 | $anon_struct_union = 0; | |
1da177e4 LT |
2263 | my $param_name = $param; |
2264 | $param_name =~ s/\[.*//; | |
2265 | ||
a6d3fe77 | 2266 | if ($type eq "" && $param =~ /\.\.\.$/) |
1da177e4 | 2267 | { |
ced69090 RD |
2268 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { |
2269 | $parameterdescs{$param} = "variable arguments"; | |
2270 | } | |
1da177e4 LT |
2271 | } |
2272 | elsif ($type eq "" && ($param eq "" or $param eq "void")) | |
2273 | { | |
1da177e4 LT |
2274 | $param="void"; |
2275 | $parameterdescs{void} = "no arguments"; | |
2276 | } | |
134fe01b RD |
2277 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) |
2278 | # handle unnamed (anonymous) union or struct: | |
2279 | { | |
2280 | $type = $param; | |
5f8c7c98 | 2281 | $param = "{unnamed_" . $param . "}"; |
134fe01b | 2282 | $parameterdescs{$param} = "anonymous\n"; |
5f8c7c98 | 2283 | $anon_struct_union = 1; |
134fe01b RD |
2284 | } |
2285 | ||
a6d3fe77 | 2286 | # warn if parameter has no description |
134fe01b RD |
2287 | # (but ignore ones starting with # as these are not parameters |
2288 | # but inline preprocessor statements); | |
2289 | # also ignore unnamed structs/unions; | |
5f8c7c98 | 2290 | if (!$anon_struct_union) { |
a6d3fe77 MW |
2291 | if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { |
2292 | ||
1da177e4 LT |
2293 | $parameterdescs{$param_name} = $undescribed; |
2294 | ||
2295 | if (($type eq 'function') || ($type eq 'enum')) { | |
d40e1e65 | 2296 | print STDERR "${file}:$.: warning: Function parameter ". |
1da177e4 LT |
2297 | "or member '$param' not " . |
2298 | "described in '$declaration_name'\n"; | |
2299 | } | |
d40e1e65 | 2300 | print STDERR "${file}:$.: warning:" . |
3c308798 | 2301 | " No description found for parameter '$param'\n"; |
1da177e4 | 2302 | ++$warnings; |
3c308798 RD |
2303 | } |
2304 | } | |
1da177e4 | 2305 | |
2b35f4d9 RD |
2306 | $param = xml_escape($param); |
2307 | ||
25985edc | 2308 | # strip spaces from $param so that it is one continuous string |
e34e7dbb RD |
2309 | # on @parameterlist; |
2310 | # this fixes a problem where check_sections() cannot find | |
2311 | # a parameter like "addr[6 + 2]" because it actually appears | |
2312 | # as "addr[6", "+", "2]" on the parameter list; | |
2313 | # but it's better to maintain the param string unchanged for output, | |
2314 | # so just weaken the string compare in check_sections() to ignore | |
2315 | # "[blah" in a parameter string; | |
2316 | ###$param =~ s/\s*//g; | |
1da177e4 LT |
2317 | push @parameterlist, $param; |
2318 | $parametertypes{$param} = $type; | |
2319 | } | |
2320 | ||
a1d94aa5 RD |
2321 | sub check_sections($$$$$$) { |
2322 | my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; | |
2323 | my @sects = split ' ', $sectcheck; | |
2324 | my @prms = split ' ', $prmscheck; | |
2325 | my $err; | |
2326 | my ($px, $sx); | |
2327 | my $prm_clean; # strip trailing "[array size]" and/or beginning "*" | |
2328 | ||
2329 | foreach $sx (0 .. $#sects) { | |
2330 | $err = 1; | |
2331 | foreach $px (0 .. $#prms) { | |
2332 | $prm_clean = $prms[$px]; | |
2333 | $prm_clean =~ s/\[.*\]//; | |
1f3a6688 | 2334 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
e34e7dbb RD |
2335 | # ignore array size in a parameter string; |
2336 | # however, the original param string may contain | |
2337 | # spaces, e.g.: addr[6 + 2] | |
2338 | # and this appears in @prms as "addr[6" since the | |
2339 | # parameter list is split at spaces; | |
2340 | # hence just ignore "[..." for the sections check; | |
2341 | $prm_clean =~ s/\[.*//; | |
2342 | ||
a1d94aa5 RD |
2343 | ##$prm_clean =~ s/^\**//; |
2344 | if ($prm_clean eq $sects[$sx]) { | |
2345 | $err = 0; | |
2346 | last; | |
2347 | } | |
2348 | } | |
2349 | if ($err) { | |
2350 | if ($decl_type eq "function") { | |
d40e1e65 | 2351 | print STDERR "${file}:$.: warning: " . |
a1d94aa5 RD |
2352 | "Excess function parameter " . |
2353 | "'$sects[$sx]' " . | |
2354 | "description in '$decl_name'\n"; | |
2355 | ++$warnings; | |
2356 | } else { | |
2357 | if ($nested !~ m/\Q$sects[$sx]\E/) { | |
d40e1e65 | 2358 | print STDERR "${file}:$.: warning: " . |
a1d94aa5 RD |
2359 | "Excess struct/union/enum/typedef member " . |
2360 | "'$sects[$sx]' " . | |
2361 | "description in '$decl_name'\n"; | |
2362 | ++$warnings; | |
2363 | } | |
2364 | } | |
2365 | } | |
2366 | } | |
2367 | } | |
2368 | ||
4092bac7 YB |
2369 | ## |
2370 | # Checks the section describing the return value of a function. | |
2371 | sub check_return_section { | |
2372 | my $file = shift; | |
2373 | my $declaration_name = shift; | |
2374 | my $return_type = shift; | |
2375 | ||
2376 | # Ignore an empty return type (It's a macro) | |
2377 | # Ignore functions with a "void" return type. (But don't ignore "void *") | |
2378 | if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { | |
2379 | return; | |
2380 | } | |
2381 | ||
2382 | if (!defined($sections{$section_return}) || | |
2383 | $sections{$section_return} eq "") { | |
d40e1e65 | 2384 | print STDERR "${file}:$.: warning: " . |
4092bac7 YB |
2385 | "No description found for return value of " . |
2386 | "'$declaration_name'\n"; | |
2387 | ++$warnings; | |
2388 | } | |
2389 | } | |
2390 | ||
1da177e4 LT |
2391 | ## |
2392 | # takes a function prototype and the name of the current file being | |
2393 | # processed and spits out all the details stored in the global | |
2394 | # arrays/hashes. | |
2395 | sub dump_function($$) { | |
2396 | my $prototype = shift; | |
2397 | my $file = shift; | |
cbb4d3e6 | 2398 | my $noret = 0; |
1da177e4 LT |
2399 | |
2400 | $prototype =~ s/^static +//; | |
2401 | $prototype =~ s/^extern +//; | |
4dc3b16b | 2402 | $prototype =~ s/^asmlinkage +//; |
1da177e4 LT |
2403 | $prototype =~ s/^inline +//; |
2404 | $prototype =~ s/^__inline__ +//; | |
32e79401 RD |
2405 | $prototype =~ s/^__inline +//; |
2406 | $prototype =~ s/^__always_inline +//; | |
2407 | $prototype =~ s/^noinline +//; | |
74fc5c65 | 2408 | $prototype =~ s/__init +//; |
20072205 | 2409 | $prototype =~ s/__init_or_module +//; |
270a0096 | 2410 | $prototype =~ s/__meminit +//; |
70c95b00 | 2411 | $prototype =~ s/__must_check +//; |
0df7c0e3 | 2412 | $prototype =~ s/__weak +//; |
cbb4d3e6 | 2413 | my $define = $prototype =~ s/^#\s*define\s+//; #ak added |
328d2440 | 2414 | $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; |
1da177e4 LT |
2415 | |
2416 | # Yes, this truly is vile. We are looking for: | |
2417 | # 1. Return type (may be nothing if we're looking at a macro) | |
2418 | # 2. Function name | |
2419 | # 3. Function parameters. | |
2420 | # | |
2421 | # All the while we have to watch out for function pointer parameters | |
2422 | # (which IIRC is what the two sections are for), C types (these | |
2423 | # regexps don't even start to express all the possibilities), and | |
2424 | # so on. | |
2425 | # | |
2426 | # If you mess with these regexps, it's a good idea to check that | |
2427 | # the following functions' documentation still comes out right: | |
2428 | # - parport_register_device (function pointer parameters) | |
2429 | # - atomic_set (macro) | |
9598f91f | 2430 | # - pci_match_device, __copy_to_user (long return type) |
1da177e4 | 2431 | |
cbb4d3e6 HG |
2432 | if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { |
2433 | # This is an object-like macro, it has no return type and no parameter | |
2434 | # list. | |
2435 | # Function-like macros are not allowed to have spaces between | |
2436 | # declaration_name and opening parenthesis (notice the \s+). | |
2437 | $return_type = $1; | |
2438 | $declaration_name = $2; | |
2439 | $noret = 1; | |
2440 | } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
1da177e4 LT |
2441 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
2442 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
2443 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
94b3e03c | 2444 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
1da177e4 LT |
2445 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
2446 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
2447 | $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2448 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2449 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2450 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2451 | $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2452 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
9598f91f MW |
2453 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
2454 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
412ecd77 RD |
2455 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
2456 | $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { | |
1da177e4 LT |
2457 | $return_type = $1; |
2458 | $declaration_name = $2; | |
2459 | my $args = $3; | |
2460 | ||
2461 | create_parameterlist($args, ',', $file); | |
2462 | } else { | |
d40e1e65 | 2463 | print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; |
1da177e4 LT |
2464 | return; |
2465 | } | |
2466 | ||
a1d94aa5 RD |
2467 | my $prms = join " ", @parameterlist; |
2468 | check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); | |
2469 | ||
4092bac7 YB |
2470 | # This check emits a lot of warnings at the moment, because many |
2471 | # functions don't have a 'Return' doc section. So until the number | |
2472 | # of warnings goes sufficiently down, the check is only performed in | |
2473 | # verbose mode. | |
2474 | # TODO: always perform the check. | |
cbb4d3e6 | 2475 | if ($verbose && !$noret) { |
4092bac7 YB |
2476 | check_return_section($file, $declaration_name, $return_type); |
2477 | } | |
2478 | ||
3c3b809e | 2479 | output_declaration($declaration_name, |
1da177e4 LT |
2480 | 'function', |
2481 | {'function' => $declaration_name, | |
2482 | 'module' => $modulename, | |
2483 | 'functiontype' => $return_type, | |
2484 | 'parameterlist' => \@parameterlist, | |
2485 | 'parameterdescs' => \%parameterdescs, | |
2486 | 'parametertypes' => \%parametertypes, | |
2487 | 'sectionlist' => \@sectionlist, | |
2488 | 'sections' => \%sections, | |
2489 | 'purpose' => $declaration_purpose | |
2490 | }); | |
2491 | } | |
2492 | ||
1da177e4 LT |
2493 | sub reset_state { |
2494 | $function = ""; | |
2495 | %constants = (); | |
2496 | %parameterdescs = (); | |
2497 | %parametertypes = (); | |
2498 | @parameterlist = (); | |
2499 | %sections = (); | |
2500 | @sectionlist = (); | |
a1d94aa5 RD |
2501 | $sectcheck = ""; |
2502 | $struct_actual = ""; | |
1da177e4 | 2503 | $prototype = ""; |
3c3b809e | 2504 | |
48af606a JN |
2505 | $state = STATE_NORMAL; |
2506 | $inline_doc_state = STATE_INLINE_NA; | |
1da177e4 LT |
2507 | } |
2508 | ||
56afb0f8 JB |
2509 | sub tracepoint_munge($) { |
2510 | my $file = shift; | |
2511 | my $tracepointname = 0; | |
2512 | my $tracepointargs = 0; | |
2513 | ||
3a9089fd | 2514 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { |
56afb0f8 JB |
2515 | $tracepointname = $1; |
2516 | } | |
3a9089fd JB |
2517 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { |
2518 | $tracepointname = $1; | |
2519 | } | |
2520 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { | |
2521 | $tracepointname = $2; | |
2522 | } | |
2523 | $tracepointname =~ s/^\s+//; #strip leading whitespace | |
2524 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { | |
56afb0f8 JB |
2525 | $tracepointargs = $1; |
2526 | } | |
2527 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { | |
d40e1e65 | 2528 | print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". |
56afb0f8 JB |
2529 | "$prototype\n"; |
2530 | } else { | |
2531 | $prototype = "static inline void trace_$tracepointname($tracepointargs)"; | |
2532 | } | |
2533 | } | |
2534 | ||
b4870bc5 RD |
2535 | sub syscall_munge() { |
2536 | my $void = 0; | |
2537 | ||
2538 | $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs | |
2539 | ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { | |
2540 | if ($prototype =~ m/SYSCALL_DEFINE0/) { | |
2541 | $void = 1; | |
2542 | ## $prototype = "long sys_$1(void)"; | |
2543 | } | |
2544 | ||
2545 | $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name | |
2546 | if ($prototype =~ m/long (sys_.*?),/) { | |
2547 | $prototype =~ s/,/\(/; | |
2548 | } elsif ($void) { | |
2549 | $prototype =~ s/\)/\(void\)/; | |
2550 | } | |
2551 | ||
2552 | # now delete all of the odd-number commas in $prototype | |
2553 | # so that arg types & arg names don't have a comma between them | |
2554 | my $count = 0; | |
2555 | my $len = length($prototype); | |
2556 | if ($void) { | |
2557 | $len = 0; # skip the for-loop | |
2558 | } | |
2559 | for (my $ix = 0; $ix < $len; $ix++) { | |
2560 | if (substr($prototype, $ix, 1) eq ',') { | |
2561 | $count++; | |
2562 | if ($count % 2 == 1) { | |
2563 | substr($prototype, $ix, 1) = ' '; | |
2564 | } | |
2565 | } | |
2566 | } | |
2567 | } | |
2568 | ||
3c3b809e | 2569 | sub process_state3_function($$) { |
1da177e4 LT |
2570 | my $x = shift; |
2571 | my $file = shift; | |
2572 | ||
51f5a0c8 RD |
2573 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
2574 | ||
890c78c2 | 2575 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { |
1da177e4 LT |
2576 | # do nothing |
2577 | } | |
2578 | elsif ($x =~ /([^\{]*)/) { | |
3c308798 | 2579 | $prototype .= $1; |
1da177e4 | 2580 | } |
b4870bc5 | 2581 | |
890c78c2 | 2582 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { |
3c308798 | 2583 | $prototype =~ s@/\*.*?\*/@@gos; # strip comments. |
1da177e4 LT |
2584 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
2585 | $prototype =~ s@^\s+@@gos; # strip leading spaces | |
b4870bc5 RD |
2586 | if ($prototype =~ /SYSCALL_DEFINE/) { |
2587 | syscall_munge(); | |
2588 | } | |
3a9089fd JB |
2589 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || |
2590 | $prototype =~ /DEFINE_SINGLE_EVENT/) | |
2591 | { | |
56afb0f8 JB |
2592 | tracepoint_munge($file); |
2593 | } | |
b4870bc5 | 2594 | dump_function($prototype, $file); |
1da177e4 LT |
2595 | reset_state(); |
2596 | } | |
2597 | } | |
2598 | ||
3c3b809e | 2599 | sub process_state3_type($$) { |
1da177e4 LT |
2600 | my $x = shift; |
2601 | my $file = shift; | |
2602 | ||
1da177e4 LT |
2603 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
2604 | $x =~ s@^\s+@@gos; # strip leading spaces | |
2605 | $x =~ s@\s+$@@gos; # strip trailing spaces | |
51f5a0c8 RD |
2606 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
2607 | ||
1da177e4 LT |
2608 | if ($x =~ /^#/) { |
2609 | # To distinguish preprocessor directive from regular declaration later. | |
2610 | $x .= ";"; | |
2611 | } | |
2612 | ||
2613 | while (1) { | |
3c308798 | 2614 | if ( $x =~ /([^{};]*)([{};])(.*)/ ) { |
1da177e4 LT |
2615 | $prototype .= $1 . $2; |
2616 | ($2 eq '{') && $brcount++; | |
2617 | ($2 eq '}') && $brcount--; | |
2618 | if (($2 eq ';') && ($brcount == 0)) { | |
b9d97328 | 2619 | dump_declaration($prototype, $file); |
1da177e4 | 2620 | reset_state(); |
3c308798 | 2621 | last; |
1da177e4 LT |
2622 | } |
2623 | $x = $3; | |
3c308798 | 2624 | } else { |
1da177e4 LT |
2625 | $prototype .= $x; |
2626 | last; | |
2627 | } | |
2628 | } | |
2629 | } | |
2630 | ||
6b5b55f6 RD |
2631 | # xml_escape: replace <, >, and & in the text stream; |
2632 | # | |
2633 | # however, formatting controls that are generated internally/locally in the | |
2634 | # kernel-doc script are not escaped here; instead, they begin life like | |
2635 | # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings | |
2636 | # are converted to their mnemonic-expected output, without the 4 * '\' & ':', | |
2637 | # just before actual output; (this is done by local_unescape()) | |
1da177e4 LT |
2638 | sub xml_escape($) { |
2639 | my $text = shift; | |
ecfb251a RD |
2640 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
2641 | return $text; | |
2642 | } | |
1da177e4 LT |
2643 | $text =~ s/\&/\\\\\\amp;/g; |
2644 | $text =~ s/\</\\\\\\lt;/g; | |
2645 | $text =~ s/\>/\\\\\\gt;/g; | |
2646 | return $text; | |
2647 | } | |
2648 | ||
c0d1b6ee JC |
2649 | # xml_unescape: reverse the effects of xml_escape |
2650 | sub xml_unescape($) { | |
2651 | my $text = shift; | |
2652 | if (($output_mode eq "text") || ($output_mode eq "man")) { | |
2653 | return $text; | |
2654 | } | |
2655 | $text =~ s/\\\\\\amp;/\&/g; | |
2656 | $text =~ s/\\\\\\lt;/</g; | |
2657 | $text =~ s/\\\\\\gt;/>/g; | |
2658 | return $text; | |
2659 | } | |
2660 | ||
6b5b55f6 RD |
2661 | # convert local escape strings to html |
2662 | # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) | |
2663 | sub local_unescape($) { | |
2664 | my $text = shift; | |
2665 | if (($output_mode eq "text") || ($output_mode eq "man")) { | |
2666 | return $text; | |
2667 | } | |
2668 | $text =~ s/\\\\\\\\lt:/</g; | |
2669 | $text =~ s/\\\\\\\\gt:/>/g; | |
2670 | return $text; | |
2671 | } | |
2672 | ||
1da177e4 | 2673 | sub process_file($) { |
2283a117 | 2674 | my $file; |
1da177e4 LT |
2675 | my $identifier; |
2676 | my $func; | |
a21217da | 2677 | my $descr; |
6423133b | 2678 | my $in_purpose = 0; |
1da177e4 | 2679 | my $initial_section_counter = $section_counter; |
68f86662 | 2680 | my ($orig_file) = @_; |
1da177e4 | 2681 | |
2283a117 | 2682 | if (defined($ENV{'SRCTREE'})) { |
68f86662 | 2683 | $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; |
2283a117 RD |
2684 | } |
2685 | else { | |
68f86662 | 2686 | $file = $orig_file; |
2283a117 | 2687 | } |
1da177e4 LT |
2688 | if (defined($source_map{$file})) { |
2689 | $file = $source_map{$file}; | |
2690 | } | |
2691 | ||
2692 | if (!open(IN,"<$file")) { | |
2693 | print STDERR "Error: Cannot open file $file\n"; | |
2694 | ++$errors; | |
2695 | return; | |
2696 | } | |
2697 | ||
86ae2e38 JN |
2698 | # two passes for -export and -internal |
2699 | if ($function_only == 3 || $function_only == 4) { | |
2700 | while (<IN>) { | |
2701 | if (/$export_symbol/o) { | |
2702 | $function_table{$2} = 1; | |
2703 | } | |
2704 | } | |
2705 | seek(IN, 0, 0); | |
2706 | } | |
2707 | ||
a9e7314b ID |
2708 | $. = 1; |
2709 | ||
1da177e4 LT |
2710 | $section_counter = 0; |
2711 | while (<IN>) { | |
65478428 DS |
2712 | while (s/\\\s*$//) { |
2713 | $_ .= <IN>; | |
2714 | } | |
48af606a | 2715 | if ($state == STATE_NORMAL) { |
1da177e4 | 2716 | if (/$doc_start/o) { |
48af606a | 2717 | $state = STATE_NAME; # next line is always the function name |
850622df | 2718 | $in_doc_sect = 0; |
1da177e4 | 2719 | } |
48af606a | 2720 | } elsif ($state == STATE_NAME) {# this line is the function name (always) |
1da177e4 | 2721 | if (/$doc_block/o) { |
48af606a | 2722 | $state = STATE_DOCBLOCK; |
1da177e4 LT |
2723 | $contents = ""; |
2724 | if ( $1 eq "" ) { | |
2725 | $section = $section_intro; | |
2726 | } else { | |
2727 | $section = $1; | |
2728 | } | |
3c308798 | 2729 | } |
1da177e4 LT |
2730 | elsif (/$doc_decl/o) { |
2731 | $identifier = $1; | |
2732 | if (/\s*([\w\s]+?)\s*-/) { | |
2733 | $identifier = $1; | |
2734 | } | |
2735 | ||
48af606a | 2736 | $state = STATE_FIELD; |
1da177e4 | 2737 | if (/-(.*)/) { |
51f5a0c8 | 2738 | # strip leading/trailing/multiple spaces |
a21217da RD |
2739 | $descr= $1; |
2740 | $descr =~ s/^\s*//; | |
2741 | $descr =~ s/\s*$//; | |
12ae6779 | 2742 | $descr =~ s/\s+/ /g; |
a21217da | 2743 | $declaration_purpose = xml_escape($descr); |
6423133b | 2744 | $in_purpose = 1; |
1da177e4 LT |
2745 | } else { |
2746 | $declaration_purpose = ""; | |
2747 | } | |
77cc23b8 RD |
2748 | |
2749 | if (($declaration_purpose eq "") && $verbose) { | |
d40e1e65 | 2750 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; |
77cc23b8 RD |
2751 | print STDERR $_; |
2752 | ++$warnings; | |
2753 | } | |
2754 | ||
1da177e4 LT |
2755 | if ($identifier =~ m/^struct/) { |
2756 | $decl_type = 'struct'; | |
2757 | } elsif ($identifier =~ m/^union/) { | |
2758 | $decl_type = 'union'; | |
2759 | } elsif ($identifier =~ m/^enum/) { | |
2760 | $decl_type = 'enum'; | |
2761 | } elsif ($identifier =~ m/^typedef/) { | |
2762 | $decl_type = 'typedef'; | |
2763 | } else { | |
2764 | $decl_type = 'function'; | |
2765 | } | |
2766 | ||
2767 | if ($verbose) { | |
d40e1e65 | 2768 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; |
1da177e4 LT |
2769 | } |
2770 | } else { | |
d40e1e65 | 2771 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", |
1da177e4 LT |
2772 | " - I thought it was a doc line\n"; |
2773 | ++$warnings; | |
48af606a | 2774 | $state = STATE_NORMAL; |
1da177e4 | 2775 | } |
48af606a | 2776 | } elsif ($state == STATE_FIELD) { # look for head: lines, and include content |
1da177e4 LT |
2777 | if (/$doc_sect/o) { |
2778 | $newsection = $1; | |
2779 | $newcontents = $2; | |
2780 | ||
792aa2f2 | 2781 | if (($contents ne "") && ($contents ne "\n")) { |
850622df | 2782 | if (!$in_doc_sect && $verbose) { |
d40e1e65 | 2783 | print STDERR "${file}:$.: warning: contents before sections\n"; |
850622df RD |
2784 | ++$warnings; |
2785 | } | |
94dc7ad5 | 2786 | dump_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2787 | $section = $section_default; |
2788 | } | |
2789 | ||
850622df | 2790 | $in_doc_sect = 1; |
6423133b | 2791 | $in_purpose = 0; |
1da177e4 LT |
2792 | $contents = $newcontents; |
2793 | if ($contents ne "") { | |
27205744 RD |
2794 | while ((substr($contents, 0, 1) eq " ") || |
2795 | substr($contents, 0, 1) eq "\t") { | |
2796 | $contents = substr($contents, 1); | |
05189497 | 2797 | } |
1da177e4 LT |
2798 | $contents .= "\n"; |
2799 | } | |
2800 | $section = $newsection; | |
2801 | } elsif (/$doc_end/) { | |
4c98ecaf | 2802 | if (($contents ne "") && ($contents ne "\n")) { |
94dc7ad5 | 2803 | dump_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2804 | $section = $section_default; |
2805 | $contents = ""; | |
2806 | } | |
46b958eb RD |
2807 | # look for doc_com + <text> + doc_end: |
2808 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { | |
d40e1e65 | 2809 | print STDERR "${file}:$.: warning: suspicious ending line: $_"; |
46b958eb RD |
2810 | ++$warnings; |
2811 | } | |
1da177e4 LT |
2812 | |
2813 | $prototype = ""; | |
48af606a | 2814 | $state = STATE_PROTO; |
1da177e4 | 2815 | $brcount = 0; |
232acbcf | 2816 | # print STDERR "end of doc comment, looking for prototype\n"; |
1da177e4 LT |
2817 | } elsif (/$doc_content/) { |
2818 | # miguel-style comment kludge, look for blank lines after | |
2819 | # @parameter line to signify start of description | |
6423133b JW |
2820 | if ($1 eq "") { |
2821 | if ($section =~ m/^@/ || $section eq $section_context) { | |
2822 | dump_section($file, $section, xml_escape($contents)); | |
2823 | $section = $section_default; | |
2824 | $contents = ""; | |
2825 | } else { | |
2826 | $contents .= "\n"; | |
2827 | } | |
2828 | $in_purpose = 0; | |
2829 | } elsif ($in_purpose == 1) { | |
2830 | # Continued declaration purpose | |
2831 | chomp($declaration_purpose); | |
2832 | $declaration_purpose .= " " . xml_escape($1); | |
12ae6779 | 2833 | $declaration_purpose =~ s/\s+/ /g; |
1da177e4 | 2834 | } else { |
b9d97328 | 2835 | $contents .= $1 . "\n"; |
1da177e4 LT |
2836 | } |
2837 | } else { | |
2838 | # i dont know - bad line? ignore. | |
d40e1e65 | 2839 | print STDERR "${file}:$.: warning: bad line: $_"; |
1da177e4 LT |
2840 | ++$warnings; |
2841 | } | |
48af606a | 2842 | } elsif ($state == STATE_INLINE) { # scanning for inline parameters |
a4c6ebed | 2843 | # First line (state 1) needs to be a @parameter |
48af606a | 2844 | if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { |
a4c6ebed DCLP |
2845 | $section = $1; |
2846 | $contents = $2; | |
2847 | if ($contents ne "") { | |
2848 | while ((substr($contents, 0, 1) eq " ") || | |
2849 | substr($contents, 0, 1) eq "\t") { | |
2850 | $contents = substr($contents, 1); | |
2851 | } | |
2852 | $contents .= "\n"; | |
2853 | } | |
48af606a | 2854 | $inline_doc_state = STATE_INLINE_TEXT; |
a4c6ebed | 2855 | # Documentation block end */ |
48af606a | 2856 | } elsif (/$doc_inline_end/) { |
a4c6ebed DCLP |
2857 | if (($contents ne "") && ($contents ne "\n")) { |
2858 | dump_section($file, $section, xml_escape($contents)); | |
2859 | $section = $section_default; | |
2860 | $contents = ""; | |
2861 | } | |
48af606a JN |
2862 | $state = STATE_PROTO; |
2863 | $inline_doc_state = STATE_INLINE_NA; | |
a4c6ebed DCLP |
2864 | # Regular text |
2865 | } elsif (/$doc_content/) { | |
48af606a | 2866 | if ($inline_doc_state == STATE_INLINE_TEXT) { |
a4c6ebed | 2867 | $contents .= $1 . "\n"; |
48af606a JN |
2868 | } elsif ($inline_doc_state == STATE_INLINE_NAME) { |
2869 | $inline_doc_state = STATE_INLINE_ERROR; | |
a4c6ebed DCLP |
2870 | print STDERR "Warning(${file}:$.): "; |
2871 | print STDERR "Incorrect use of kernel-doc format: $_"; | |
2872 | ++$warnings; | |
2873 | } | |
2874 | } | |
48af606a JN |
2875 | } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) |
2876 | if (/$doc_inline_start/) { | |
2877 | $state = STATE_INLINE; | |
2878 | $inline_doc_state = STATE_INLINE_NAME; | |
a4c6ebed | 2879 | } elsif ($decl_type eq 'function') { |
3c308798 | 2880 | process_state3_function($_, $file); |
1da177e4 | 2881 | } else { |
3c308798 | 2882 | process_state3_type($_, $file); |
1da177e4 | 2883 | } |
48af606a | 2884 | } elsif ($state == STATE_DOCBLOCK) { |
1da177e4 | 2885 | # Documentation block |
3c308798 | 2886 | if (/$doc_block/) { |
94dc7ad5 | 2887 | dump_doc_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2888 | $contents = ""; |
2889 | $function = ""; | |
2890 | %constants = (); | |
2891 | %parameterdescs = (); | |
2892 | %parametertypes = (); | |
2893 | @parameterlist = (); | |
2894 | %sections = (); | |
2895 | @sectionlist = (); | |
2896 | $prototype = ""; | |
2897 | if ( $1 eq "" ) { | |
2898 | $section = $section_intro; | |
2899 | } else { | |
2900 | $section = $1; | |
2901 | } | |
3c308798 | 2902 | } |
1da177e4 LT |
2903 | elsif (/$doc_end/) |
2904 | { | |
94dc7ad5 | 2905 | dump_doc_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2906 | $contents = ""; |
2907 | $function = ""; | |
2908 | %constants = (); | |
2909 | %parameterdescs = (); | |
2910 | %parametertypes = (); | |
2911 | @parameterlist = (); | |
2912 | %sections = (); | |
2913 | @sectionlist = (); | |
2914 | $prototype = ""; | |
48af606a | 2915 | $state = STATE_NORMAL; |
1da177e4 LT |
2916 | } |
2917 | elsif (/$doc_content/) | |
2918 | { | |
2919 | if ( $1 eq "" ) | |
2920 | { | |
2921 | $contents .= $blankline; | |
2922 | } | |
2923 | else | |
2924 | { | |
2925 | $contents .= $1 . "\n"; | |
3c3b809e | 2926 | } |
3c308798 RD |
2927 | } |
2928 | } | |
1da177e4 LT |
2929 | } |
2930 | if ($initial_section_counter == $section_counter) { | |
d40e1e65 | 2931 | print STDERR "${file}:1: warning: no structured comments found\n"; |
e946c43a JB |
2932 | if (($function_only == 1) && ($show_not_found == 1)) { |
2933 | print STDERR " Was looking for '$_'.\n" for keys %function_table; | |
2934 | } | |
1da177e4 LT |
2935 | if ($output_mode eq "xml") { |
2936 | # The template wants at least one RefEntry here; make one. | |
2937 | print "<refentry>\n"; | |
2938 | print " <refnamediv>\n"; | |
2939 | print " <refname>\n"; | |
68f86662 | 2940 | print " ${orig_file}\n"; |
1da177e4 LT |
2941 | print " </refname>\n"; |
2942 | print " <refpurpose>\n"; | |
2943 | print " Document generation inconsistency\n"; | |
2944 | print " </refpurpose>\n"; | |
2945 | print " </refnamediv>\n"; | |
2946 | print " <refsect1>\n"; | |
2947 | print " <title>\n"; | |
2948 | print " Oops\n"; | |
2949 | print " </title>\n"; | |
2950 | print " <warning>\n"; | |
2951 | print " <para>\n"; | |
2952 | print " The template for this document tried to insert\n"; | |
2953 | print " the structured comment from the file\n"; | |
68f86662 | 2954 | print " <filename>${orig_file}</filename> at this point,\n"; |
1da177e4 LT |
2955 | print " but none was found.\n"; |
2956 | print " This dummy section is inserted to allow\n"; | |
2957 | print " generation to continue.\n"; | |
2958 | print " </para>\n"; | |
2959 | print " </warning>\n"; | |
2960 | print " </refsect1>\n"; | |
2961 | print "</refentry>\n"; | |
2962 | } | |
2963 | } | |
2964 | } | |
8484baaa RD |
2965 | |
2966 | ||
2967 | $kernelversion = get_kernel_version(); | |
2968 | ||
2969 | # generate a sequence of code that will splice in highlighting information | |
2970 | # using the s// operator. | |
1ef06233 | 2971 | for (my $k = 0; $k < @highlights; $k++) { |
4d732701 DCLP |
2972 | my $pattern = $highlights[$k][0]; |
2973 | my $result = $highlights[$k][1]; | |
2974 | # print STDERR "scanning pattern:$pattern, highlight:($result)\n"; | |
2975 | $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; | |
8484baaa RD |
2976 | } |
2977 | ||
2978 | # Read the file that maps relative names to absolute names for | |
2979 | # separate source and object directories and for shadow trees. | |
2980 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { | |
2981 | my ($relname, $absname); | |
2982 | while(<SOURCE_MAP>) { | |
2983 | chop(); | |
2984 | ($relname, $absname) = (split())[0..1]; | |
2985 | $relname =~ s:^/+::; | |
2986 | $source_map{$relname} = $absname; | |
2987 | } | |
2988 | close(SOURCE_MAP); | |
2989 | } | |
2990 | ||
2991 | foreach (@ARGV) { | |
2992 | chomp; | |
2993 | process_file($_); | |
2994 | } | |
2995 | if ($verbose && $errors) { | |
2996 | print STDERR "$errors errors\n"; | |
2997 | } | |
2998 | if ($verbose && $warnings) { | |
2999 | print STDERR "$warnings warnings\n"; | |
3000 | } | |
3001 | ||
3002 | exit($errors); |