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