]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - scripts/kernel-doc
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 ##
8 ## Copyright (C) 2005-2012 Randy Dunlap ##
9 ## Copyright (C) 2012 Dan Luedtke ##
11 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
12 ## Copyright (c) 2000 MontaVista Software, Inc. ##
14 ## This software falls under the GNU General Public License. ##
15 ## Please read the COPYING file for more information ##
17 # 18/01/2001 - Cleanups
18 # Functions prototyped as foo(void) same as foo()
19 # Stop eval'ing where we don't need to.
22 # 27/06/2001 - Allowed whitespace after initial "/**" and
23 # allowed comments before function declarations.
24 # -- Christian Kreibich <ck@whoop.org>
27 # - add perldoc documentation
28 # - Look more closely at some of the scarier bits :)
30 # 26/05/2001 - Support for separate source and object trees.
32 # Keith Owens <kaos@ocs.com.au>
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>
39 # 25/07/2012 - Added support for HTML5
40 # -- Dan Luedtke <mail@danrl.de>
43 my $message = <<"EOF";
44 Usage: $0 [OPTION ...] FILE ...
46 Read C language source or header FILEs, extract embedded documentation comments,
47 and print formatted documentation to standard output.
49 The documentation comments are identified by "/**" opening comment mark. See
50 Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
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 -rst Output reStructuredText format.
59 -text Output plain text format.
61 Output selection (mutually exclusive):
62 -export Only output documentation for symbols that have been
63 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
65 -internal Only output documentation for symbols that have NOT been
66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
68 -function NAME Only output documentation for the given function(s)
69 or DOC: section title(s). All other functions and DOC:
70 sections are ignored. May be specified multiple times.
71 -nofunction NAME Do NOT output documentation for the given function(s);
72 only output documentation for the other functions and
73 DOC: sections. May be specified multiple times.
75 Output selection modifiers:
76 -no-doc-sections Do not output DOC: sections.
77 -enable-lineno Enable output of #define LINENO lines. Only works with
78 reStructuredText format.
81 -v Verbose output, more warnings and other information.
91 # In the following table, (...)? signifies optional structure.
92 # (...)* signifies 0 or more structure elements
94 # * function_name(:)? (- short description)?
95 # (* @parameterx: (description of parameter x)?)*
97 # * (Description:)? (Description of function)?
98 # * (section header: (section description)? )*
101 # So .. the trivial example would be:
107 # If the Description: header tag is omitted, then there must be a blank line
108 # after the last parameter specification.
111 # * my_function - does my stuff
112 # * @my_arg: its mine damnit
114 # * Does my stuff explained.
117 # or, could also use:
119 # * my_function - does my stuff
120 # * @my_arg: its mine damnit
121 # * Description: Does my stuff explained.
125 # Besides functions you can also write documentation for structs, unions,
126 # enums and typedefs. Instead of the function name you must write the name
127 # of the declaration; the struct/union/enum/typedef must always precede
128 # the name. Nesting of declarations is not supported.
129 # Use the argument mechanism to document members or constants.
132 # * struct my_struct - short description
134 # * @b: second member
136 # * Longer description
145 # All descriptions can be multiline, except the short function description.
147 # For really longs structs, you can also describe arguments inside the
148 # body of the struct.
151 # * struct my_struct - short description
153 # * @b: second member
155 # * Longer description
161 # * @c: This is longer description of C
163 # * You can use paragraphs to describe arguments
164 # * using this method.
169 # This should be use only for struct/enum members.
171 # You can also add additional sections. When documenting kernel functions you
172 # should document the "Context:" of the function, e.g. whether the functions
173 # can be called form interrupts. Unlike other sections you can end it with an
175 # A non-void function should have a "Return:" section describing the return
177 # Example-sections should contain the string EXAMPLE so that they are marked
178 # appropriately in DocBook.
182 # * user_function - function that can only be called in user context
183 # * @a: some argument
184 # * Context: !in_interrupt()
188 # * user_function(22);
193 # All descriptive text is further processed, scanning for the following special
194 # patterns, which are highlighted appropriately.
196 # 'funcname()' - function
197 # '$ENVVAR' - environmental variable
198 # '&struct_name' - name of a structure (up to two words including 'struct')
199 # '@parameter' - name of a parameter
200 # '%CONST' - name of a constant.
206 my $anon_struct_union = 0;
208 # match expressions used to find embedded type information
209 my $type_constant = '\%([-_\w]+)';
210 my $type_func = '(\w+)\(\)';
211 my $type_param = '\@(\w+)';
212 my $type_struct = '\&((struct\s*)*[_\w]+)';
213 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
214 my $type_env = '(\$\w+)';
215 my $type_enum_full = '\&(enum)\s*([_\w]+)';
216 my $type_struct_full = '\&(struct)\s*([_\w]+)';
217 my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
218 my $type_union_full = '\&(union)\s*([_\w]+)';
219 my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
220 my $type_member_func = $type_member . '\(\)';
222 # Output conversion substitutions.
223 # One for each output format
225 # these work fairly well
226 my @highlights_html = (
227 [$type_constant, "<i>\$1</i>"],
228 [$type_func, "<b>\$1</b>"],
229 [$type_struct_xml, "<i>\$1</i>"],
230 [$type_env, "<b><i>\$1</i></b>"],
231 [$type_param, "<tt><b>\$1</b></tt>"]
233 my $local_lt = "\\\\\\\\lt:";
234 my $local_gt = "\\\\\\\\gt:";
235 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
238 my @highlights_html5 = (
239 [$type_constant, "<span class=\"const\">\$1</span>"],
240 [$type_func, "<span class=\"func\">\$1</span>"],
241 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
242 [$type_env, "<span class=\"env\">\$1</span>"],
243 [$type_param, "<span class=\"param\">\$1</span>]"]
245 my $blankline_html5 = $local_lt . "br /" . $local_gt;
247 # XML, docbook format
248 my @highlights_xml = (
249 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
250 [$type_constant, "<constant>\$1</constant>"],
251 [$type_struct_xml, "<structname>\$1</structname>"],
252 [$type_param, "<parameter>\$1</parameter>"],
253 [$type_func, "<function>\$1</function>"],
254 [$type_env, "<envar>\$1</envar>"]
256 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
258 # gnome, docbook format
259 my @highlights_gnome = (
260 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
261 [$type_func, "<function>\$1</function>"],
262 [$type_struct, "<structname>\$1</structname>"],
263 [$type_env, "<envar>\$1</envar>"],
264 [$type_param, "<parameter>\$1</parameter>" ]
266 my $blankline_gnome = "</para><para>\n";
268 # these are pretty rough
269 my @highlights_man = (
270 [$type_constant, "\$1"],
271 [$type_func, "\\\\fB\$1\\\\fP"],
272 [$type_struct, "\\\\fI\$1\\\\fP"],
273 [$type_param, "\\\\fI\$1\\\\fP"]
275 my $blankline_man = "";
278 my @highlights_text = (
279 [$type_constant, "\$1"],
281 [$type_struct, "\$1"],
284 my $blankline_text = "";
287 my @highlights_rst = (
288 [$type_constant, "``\$1``"],
289 # Note: need to escape () to avoid func matching later
290 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
291 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
292 [$type_func, "\\:c\\:func\\:`\$1()`"],
293 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
294 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
295 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
296 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
297 # in rst this can refer to any type
298 [$type_struct, "\\:c\\:type\\:`\$1`"],
299 [$type_param, "**\$1**"]
301 my $blankline_rst = "\n";
304 my @highlights_list = (
305 [$type_constant, "\$1"],
307 [$type_struct, "\$1"],
310 my $blankline_list = "";
318 my $dohighlight = "";
321 my $output_mode = "man";
322 my $output_preformatted = 0;
323 my $no_doc_sections = 0;
324 my $enable_lineno = 0;
325 my @highlights = @highlights_man;
326 my $blankline = $blankline_man;
327 my $modulename = "Kernel API";
330 OUTPUT_ALL
=> 0, # output all symbols and doc sections
331 OUTPUT_INCLUDE
=> 1, # output only specified symbols
332 OUTPUT_EXCLUDE
=> 2, # output everything except specified symbols
333 OUTPUT_EXPORTED
=> 3, # output exported symbols
334 OUTPUT_INTERNAL
=> 4, # output non-exported symbols
336 my $output_selection = OUTPUT_ALL
;
337 my $show_not_found = 0;
340 if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
341 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
342 @build_time = gmtime($seconds);
344 @build_time = localtime;
347 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
348 'July', 'August', 'September', 'October',
349 'November', 'December')[$build_time[4]] .
350 " " . ($build_time[5]+1900);
352 # Essentially these are globals.
353 # They probably want to be tidied up, made more localised or something.
354 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
355 # could cause "use of undefined value" or other bugs.
356 my ($function, %function_table, %parametertypes, $declaration_purpose);
357 my $declaration_start_line;
358 my ($type, $declaration_name, $return_type);
359 my ($newsection, $newcontents, $prototype, $brcount, %source_map);
361 if (defined($ENV{'KBUILD_VERBOSE'})) {
362 $verbose = "$ENV{'KBUILD_VERBOSE'}";
365 # Generated docbook code is inserted in a template at a point where
366 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
367 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
368 # We keep track of number of generated entries and generate a dummy
369 # if needs be to ensure the expanded template can be postprocessed
371 my $section_counter = 0;
377 STATE_NORMAL => 0, # normal code
378 STATE_NAME => 1, # looking for function name
379 STATE_FIELD => 2, # scanning field start
380 STATE_PROTO => 3, # scanning prototype
381 STATE_DOCBLOCK => 4, # documentation block
382 STATE_INLINE => 5, # gathering documentation outside main block
387 # Inline documentation state
389 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
390 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
391 STATE_INLINE_TEXT => 2, # looking for member documentation
392 STATE_INLINE_END => 3, # done
393 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
394 # Spit a warning as it's not
395 # proper kernel-doc and ignore the rest.
397 my $inline_doc_state;
399 #declaration types: can be
400 # 'function', 'struct', 'union', 'enum', 'typedef'
403 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
405 my $doc_com = '\s*\*\s*';
406 my $doc_com_body = '\s*\* ?';
407 my $doc_decl = $doc_com . '(\w+)';
408 # @params and a strictly limited set of supported section names
409 my $doc_sect = $doc_com .
410 '\s*(\@\w+|description|context|returns?|notes?|examples?)\s*:(.*)';
411 my $doc_content = $doc_com_body . '(.*)';
412 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
413 my $doc_inline_start = '^\s*/\*\*\s*$';
414 my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
415 my $doc_inline_end = '^\s*\*/\s*$';
416 my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
419 my %parameterdesc_start_lines;
423 my %section_start_lines;
428 my $new_start_line = 0;
430 # the canonical section names. see also $doc_sect above.
431 my $section_default = "Description"; # default section
432 my $section_intro = "Introduction";
433 my $section = $section_default;
434 my $section_context = "Context";
435 my $section_return = "Return";
437 my $undescribed = "-- undescribed --";
441 while ($ARGV[0] =~ m/^-(.*)/) {
442 my $cmd = shift @ARGV;
443 if ($cmd eq "-html") {
444 $output_mode = "html";
445 @highlights = @highlights_html;
446 $blankline = $blankline_html;
447 } elsif ($cmd eq "-html5") {
448 $output_mode = "html5";
449 @highlights = @highlights_html5;
450 $blankline = $blankline_html5;
451 } elsif ($cmd eq "-man") {
452 $output_mode = "man";
453 @highlights = @highlights_man;
454 $blankline = $blankline_man;
455 } elsif ($cmd eq "-text") {
456 $output_mode = "text";
457 @highlights = @highlights_text;
458 $blankline = $blankline_text;
459 } elsif ($cmd eq "-rst") {
460 $output_mode = "rst";
461 @highlights = @highlights_rst;
462 $blankline = $blankline_rst;
463 } elsif ($cmd eq "-docbook") {
464 $output_mode = "xml";
465 @highlights = @highlights_xml;
466 $blankline = $blankline_xml;
467 } elsif ($cmd eq "-list") {
468 $output_mode = "list";
469 @highlights = @highlights_list;
470 $blankline = $blankline_list;
471 } elsif ($cmd eq "-gnome") {
472 $output_mode = "gnome";
473 @highlights = @highlights_gnome;
474 $blankline = $blankline_gnome;
475 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
476 $modulename = shift @ARGV;
477 } elsif ($cmd eq "-function") { # to only output specific functions
478 $output_selection = OUTPUT_INCLUDE;
479 $function = shift @ARGV;
480 $function_table{$function} = 1;
481 } elsif ($cmd eq "-nofunction") { # output all except specific functions
482 $output_selection = OUTPUT_EXCLUDE;
483 $function = shift @ARGV;
484 $function_table{$function} = 1;
485 } elsif ($cmd eq "-export") { # only exported symbols
486 $output_selection = OUTPUT_EXPORTED;
488 } elsif ($cmd eq "-internal") { # only non-exported symbols
489 $output_selection = OUTPUT_INTERNAL;
491 } elsif ($cmd eq "-v") {
493 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
495 } elsif ($cmd eq '-no-doc-sections') {
496 $no_doc_sections = 1;
497 } elsif ($cmd eq '-enable-lineno') {
499 } elsif ($cmd eq '-show-not-found') {
504 # continue execution near EOF;
506 # get kernel version from env
507 sub get_kernel_version() {
508 my $version = 'unknown kernel version';
510 if (defined($ENV{'KERNELVERSION'})) {
511 $version = $ENV{'KERNELVERSION'};
519 if ($enable_lineno && defined($lineno)) {
520 print "#define LINENO " . $lineno . "\n";
524 # dumps section contents to arrays/hashes intended for that purpose.
529 my $contents = join "\n", @_;
531 if ($name =~ m/$type_param/) {
533 $parameterdescs{$name} = $contents;
534 $sectcheck = $sectcheck . $name . " ";
535 $parameterdesc_start_lines{$name} = $new_start_line;
537 } elsif ($name eq "@\.\.\.") {
539 $parameterdescs{$name} = $contents;
540 $sectcheck = $sectcheck . $name . " ";
541 $parameterdesc_start_lines{$name} = $new_start_line;
544 if (defined($sections{$name}) && ($sections{$name} ne "")) {
545 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
547 $sections{$name} .= $contents;
549 $sections{$name} = $contents;
550 push @sectionlist, $name;
551 $section_start_lines{$name} = $new_start_line;
558 # dump DOC: section after checking that it should go out
560 sub dump_doc_section {
563 my $contents = join "\n", @_;
565 if ($no_doc_sections) {
569 if (($output_selection == OUTPUT_ALL) ||
570 ($output_selection == OUTPUT_INCLUDE &&
571 defined($function_table{$name})) ||
572 ($output_selection == OUTPUT_EXCLUDE &&
573 !defined($function_table{$name})))
575 dump_section($file, $name, $contents);
576 output_blockhead({'sectionlist' => \@sectionlist,
577 'sections' => \%sections,
578 'module' => $modulename,
579 'content-only' => ($output_selection != OUTPUT_ALL), });
586 # parameterdescs, a hash.
587 # function => "function name"
588 # parameterlist => @list of parameters
589 # parameterdescs => %parameter descriptions
590 # sectionlist => @list of sections
591 # sections => %section descriptions
594 sub output_highlight {
595 my $contents = join "\n",@_;
599 # if (!defined $contents) {
601 # confess "output_highlight got called with no args?\n";
604 if ($output_mode eq "html" || $output_mode eq "html5" ||
605 $output_mode eq "xml") {
606 $contents = local_unescape($contents);
607 # convert data read & converted thru xml_escape() into &xyz; format:
608 $contents =~ s/\\\\\\/\&/g;
610 # print STDERR "contents b4:$contents\n";
613 # print STDERR "contents af:$contents\n";
615 # strip whitespaces when generating html5
616 if ($output_mode eq "html5") {
617 $contents =~ s/^\s+//;
618 $contents =~ s/\s+$//;
620 foreach $line (split "\n", $contents) {
621 if (! $output_preformatted) {
625 if (! $output_preformatted) {
626 print $lineprefix, local_unescape($blankline);
629 $line =~ s/\\\\\\/\&/g;
630 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
633 print $lineprefix, $line;
640 # output sections in html
641 sub output_section_html(%) {
645 foreach $section (@{$args{'sectionlist'}}) {
646 print "<h3>$section</h3>\n";
647 print "<blockquote>\n";
648 output_highlight($args{'sections'}{$section});
649 print "</blockquote>\n";
653 # output enum in html
654 sub output_enum_html(%) {
658 print "<h2>enum " . $args{'enum'} . "</h2>\n";
660 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
662 foreach $parameter (@{$args{'parameterlist'}}) {
663 print " <b>" . $parameter . "</b>";
664 if ($count != $#{$args{'parameterlist'}}) {
672 print "<h3>Constants</h3>\n";
674 foreach $parameter (@{$args{'parameterlist'}}) {
675 print "<dt><b>" . $parameter . "</b>\n";
677 output_highlight($args{'parameterdescs'}{$parameter});
680 output_section_html(@_);
684 # output typedef in html
685 sub output_typedef_html(%) {
689 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
691 print "<b>typedef " . $args{'typedef'} . "</b>\n";
692 output_section_html(@_);
696 # output struct in html
697 sub output_struct_html(%) {
701 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
702 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
703 foreach $parameter (@{$args{'parameterlist'}}) {
704 if ($parameter =~ /^#/) {
705 print "$parameter<br>\n";
708 my $parameter_name = $parameter;
709 $parameter_name =~ s/\[.*//;
711 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
712 $type = $args{'parametertypes'}{$parameter};
713 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
714 # pointer-to-function
715 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
716 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
718 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
720 print " <i>$type</i> <b>$parameter</b>;<br>\n";
725 print "<h3>Members</h3>\n";
727 foreach $parameter (@{$args{'parameterlist'}}) {
728 ($parameter =~ /^#/) && next;
730 my $parameter_name = $parameter;
731 $parameter_name =~ s/\[.*//;
733 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
734 print "<dt><b>" . $parameter . "</b>\n";
736 output_highlight($args{'parameterdescs'}{$parameter_name});
739 output_section_html(@_);
743 # output function in html
744 sub output_function_html(%) {
746 my ($parameter, $section);
749 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
750 print "<i>" . $args{'functiontype'} . "</i>\n";
751 print "<b>" . $args{'function'} . "</b>\n";
754 foreach $parameter (@{$args{'parameterlist'}}) {
755 $type = $args{'parametertypes'}{$parameter};
756 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
757 # pointer-to-function
758 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
760 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
762 if ($count != $#{$args{'parameterlist'}}) {
769 print "<h3>Arguments</h3>\n";
771 foreach $parameter (@{$args{'parameterlist'}}) {
772 my $parameter_name = $parameter;
773 $parameter_name =~ s/\[.*//;
775 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
776 print "<dt><b>" . $parameter . "</b>\n";
778 output_highlight($args{'parameterdescs'}{$parameter_name});
781 output_section_html(@_);
785 # output DOC: block header in html
786 sub output_blockhead_html(%) {
788 my ($parameter, $section);
791 foreach $section (@{$args{'sectionlist'}}) {
792 print "<h3>$section</h3>\n";
794 output_highlight($args{'sections'}{$section});
800 # output sections in html5
801 sub output_section_html5(%) {
805 foreach $section (@{$args{'sectionlist'}}) {
807 print "<h1>$section</h1>\n";
809 output_highlight($args{'sections'}{$section});
811 print "</section>\n";
815 # output enum in html5
816 sub output_enum_html5(%) {
822 $html5id = $args{'enum'};
823 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
824 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
825 print "<h1>enum " . $args{'enum'} . "</h1>\n";
826 print "<ol class=\"code\">\n";
828 print "<span class=\"keyword\">enum</span> ";
829 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
832 foreach $parameter (@{$args{'parameterlist'}}) {
833 print "<li class=\"indent\">";
834 print "<span class=\"param\">" . $parameter . "</span>";
835 if ($count != $#{$args{'parameterlist'}}) {
841 print "<li>};</li>\n";
845 print "<h1>Constants</h1>\n";
847 foreach $parameter (@{$args{'parameterlist'}}) {
848 print "<dt>" . $parameter . "</dt>\n";
850 output_highlight($args{'parameterdescs'}{$parameter});
854 print "</section>\n";
855 output_section_html5(@_);
856 print "</article>\n";
859 # output typedef in html5
860 sub output_typedef_html5(%) {
866 $html5id = $args{'typedef'};
867 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
868 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
869 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
871 print "<ol class=\"code\">\n";
873 print "<span class=\"keyword\">typedef</span> ";
874 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
877 output_section_html5(@_);
878 print "</article>\n";
881 # output struct in html5
882 sub output_struct_html5(%) {
887 $html5id = $args{'struct'};
888 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
889 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
891 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
892 print "<h2>". $args{'purpose'} . "</h2>\n";
894 print "<ol class=\"code\">\n";
896 print "<span class=\"type\">" . $args{'type'} . "</span> ";
897 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
899 foreach $parameter (@{$args{'parameterlist'}}) {
900 print "<li class=\"indent\">";
901 if ($parameter =~ /^#/) {
902 print "<span class=\"param\">" . $parameter ."</span>\n";
906 my $parameter_name = $parameter;
907 $parameter_name =~ s/\[.*//;
909 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
910 $type = $args{'parametertypes'}{$parameter};
911 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
912 # pointer-to-function
913 print "<span class=\"type\">$1</span> ";
914 print "<span class=\"param\">$parameter</span>";
915 print "<span class=\"type\">)</span> ";
916 print "(<span class=\"args\">$2</span>);";
917 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
919 print "<span class=\"type\">$1</span> ";
920 print "<span class=\"param\">$parameter</span>";
921 print "<span class=\"bits\">$2</span>;";
923 print "<span class=\"type\">$type</span> ";
924 print "<span class=\"param\">$parameter</span>;";
928 print "<li>};</li>\n";
932 print "<h1>Members</h1>\n";
934 foreach $parameter (@{$args{'parameterlist'}}) {
935 ($parameter =~ /^#/) && next;
937 my $parameter_name = $parameter;
938 $parameter_name =~ s/\[.*//;
940 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
941 print "<dt>" . $parameter . "</dt>\n";
943 output_highlight($args{'parameterdescs'}{$parameter_name});
947 print "</section>\n";
948 output_section_html5(@_);
949 print "</article>\n";
952 # output function in html5
953 sub output_function_html5(%) {
955 my ($parameter, $section);
959 $html5id = $args{'function'};
960 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
961 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
963 print "<h1>" . $args{'function'} . "</h1>";
964 print "<h2>" . $args{'purpose'} . "</h2>\n";
966 print "<ol class=\"code\">\n";
968 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
969 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
972 foreach $parameter (@{$args{'parameterlist'}}) {
973 print "<li class=\"indent\">";
974 $type = $args{'parametertypes'}{$parameter};
975 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
976 # pointer-to-function
977 print "<span class=\"type\">$1</span> ";
978 print "<span class=\"param\">$parameter</span>";
979 print "<span class=\"type\">)</span> ";
980 print "(<span class=\"args\">$2</span>)";
982 print "<span class=\"type\">$type</span> ";
983 print "<span class=\"param\">$parameter</span>";
985 if ($count != $#{$args{'parameterlist'}}) {
991 print "<li>)</li>\n";
995 print "<h1>Arguments</h1>\n";
998 foreach $parameter (@{$args{'parameterlist'}}) {
999 my $parameter_name = $parameter;
1000 $parameter_name =~ s/\[.*//;
1002 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1003 print "<dt>" . $parameter . "</dt>\n";
1005 output_highlight($args{'parameterdescs'}{$parameter_name});
1009 print "</section>\n";
1010 output_section_html5(@_);
1011 print "</article>\n";
1014 # output DOC: block header in html5
1015 sub output_blockhead_html5(%) {
1016 my %args = %{$_[0]};
1017 my ($parameter, $section);
1021 foreach $section (@{$args{'sectionlist'}}) {
1022 $html5id = $section;
1023 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1024 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1025 print "<h1>$section</h1>\n";
1027 output_highlight($args{'sections'}{$section});
1030 print "</article>\n";
1033 sub output_section_xml(%) {
1034 my %args = %{$_[0]};
1036 # print out each section
1038 foreach $section (@{$args{'sectionlist'}}) {
1039 print "<refsect1>\n";
1040 print "<title>$section</title>\n";
1041 if ($section =~ m/EXAMPLE/i) {
1042 print "<informalexample><programlisting>\n";
1043 $output_preformatted = 1;
1047 output_highlight($args{'sections'}{$section});
1048 $output_preformatted = 0;
1049 if ($section =~ m/EXAMPLE/i) {
1050 print "</programlisting></informalexample>\n";
1054 print "</refsect1>\n";
1058 # output function in XML DocBook
1059 sub output_function_xml(%) {
1060 my %args = %{$_[0]};
1061 my ($parameter, $section);
1065 $id = "API-" . $args{'function'};
1066 $id =~ s/[^A-Za-z0-9]/-/g;
1068 print "<refentry id=\"$id\">\n";
1069 print "<refentryinfo>\n";
1070 print " <title>LINUX</title>\n";
1071 print " <productname>Kernel Hackers Manual</productname>\n";
1072 print " <date>$man_date</date>\n";
1073 print "</refentryinfo>\n";
1074 print "<refmeta>\n";
1075 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
1076 print " <manvolnum>9</manvolnum>\n";
1077 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1078 print "</refmeta>\n";
1079 print "<refnamediv>\n";
1080 print " <refname>" . $args{'function'} . "</refname>\n";
1081 print " <refpurpose>\n";
1083 output_highlight ($args{'purpose'});
1084 print " </refpurpose>\n";
1085 print "</refnamediv>\n";
1087 print "<refsynopsisdiv>\n";
1088 print " <title>Synopsis</title>\n";
1089 print " <funcsynopsis><funcprototype>\n";
1090 print " <funcdef>" . $args{'functiontype'} . " ";
1091 print "<function>" . $args{'function'} . " </function></funcdef>\n";
1094 if ($#{$args{'parameterlist'}} >= 0) {
1095 foreach $parameter (@{$args{'parameterlist'}}) {
1096 $type = $args{'parametertypes'}{$parameter};
1097 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1098 # pointer-to-function
1099 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1100 print " <funcparams>$2</funcparams></paramdef>\n";
1102 print " <paramdef>" . $type;
1103 print " <parameter>$parameter</parameter></paramdef>\n";
1109 print " </funcprototype></funcsynopsis>\n";
1110 print "</refsynopsisdiv>\n";
1113 print "<refsect1>\n <title>Arguments</title>\n";
1114 if ($#{$args{'parameterlist'}} >= 0) {
1115 print " <variablelist>\n";
1116 foreach $parameter (@{$args{'parameterlist'}}) {
1117 my $parameter_name = $parameter;
1118 $parameter_name =~ s/\[.*//;
1120 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1121 print " <listitem>\n <para>\n";
1123 output_highlight($args{'parameterdescs'}{$parameter_name});
1124 print " </para>\n </listitem>\n </varlistentry>\n";
1126 print " </variablelist>\n";
1128 print " <para>\n None\n </para>\n";
1130 print "</refsect1>\n";
1132 output_section_xml(@_);
1133 print "</refentry>\n\n";
1136 # output struct in XML DocBook
1137 sub output_struct_xml(%) {
1138 my %args = %{$_[0]};
1139 my ($parameter, $section);
1142 $id = "API-struct-" . $args{'struct'};
1143 $id =~ s/[^A-Za-z0-9]/-/g;
1145 print "<refentry id=\"$id\">\n";
1146 print "<refentryinfo>\n";
1147 print " <title>LINUX</title>\n";
1148 print " <productname>Kernel Hackers Manual</productname>\n";
1149 print " <date>$man_date</date>\n";
1150 print "</refentryinfo>\n";
1151 print "<refmeta>\n";
1152 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
1153 print " <manvolnum>9</manvolnum>\n";
1154 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1155 print "</refmeta>\n";
1156 print "<refnamediv>\n";
1157 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
1158 print " <refpurpose>\n";
1160 output_highlight ($args{'purpose'});
1161 print " </refpurpose>\n";
1162 print "</refnamediv>\n";
1164 print "<refsynopsisdiv>\n";
1165 print " <title>Synopsis</title>\n";
1166 print " <programlisting>\n";
1167 print $args{'type'} . " " . $args{'struct'} . " {\n";
1168 foreach $parameter (@{$args{'parameterlist'}}) {
1169 if ($parameter =~ /^#/) {
1170 my $prm = $parameter;
1171 # convert data read & converted thru xml_escape() into &xyz; format:
1172 # This allows us to have #define macros interspersed in a struct.
1173 $prm =~ s/\\\\\\/\&/g;
1178 my $parameter_name = $parameter;
1179 $parameter_name =~ s/\[.*//;
1181 defined($args{'parameterdescs'}{$parameter_name}) || next;
1182 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1183 $type = $args{'parametertypes'}{$parameter};
1184 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1185 # pointer-to-function
1186 print " $1 $parameter) ($2);\n";
1187 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1189 print " $1 $parameter$2;\n";
1191 print " " . $type . " " . $parameter . ";\n";
1195 print " </programlisting>\n";
1196 print "</refsynopsisdiv>\n";
1198 print " <refsect1>\n";
1199 print " <title>Members</title>\n";
1201 if ($#{$args{'parameterlist'}} >= 0) {
1202 print " <variablelist>\n";
1203 foreach $parameter (@{$args{'parameterlist'}}) {
1204 ($parameter =~ /^#/) && next;
1206 my $parameter_name = $parameter;
1207 $parameter_name =~ s/\[.*//;
1209 defined($args{'parameterdescs'}{$parameter_name}) || next;
1210 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1211 print " <varlistentry>";
1212 print " <term>$parameter</term>\n";
1213 print " <listitem><para>\n";
1214 output_highlight($args{'parameterdescs'}{$parameter_name});
1215 print " </para></listitem>\n";
1216 print " </varlistentry>\n";
1218 print " </variablelist>\n";
1220 print " <para>\n None\n </para>\n";
1222 print " </refsect1>\n";
1224 output_section_xml(@_);
1226 print "</refentry>\n\n";
1229 # output enum in XML DocBook
1230 sub output_enum_xml(%) {
1231 my %args = %{$_[0]};
1232 my ($parameter, $section);
1236 $id = "API-enum-" . $args{'enum'};
1237 $id =~ s/[^A-Za-z0-9]/-/g;
1239 print "<refentry id=\"$id\">\n";
1240 print "<refentryinfo>\n";
1241 print " <title>LINUX</title>\n";
1242 print " <productname>Kernel Hackers Manual</productname>\n";
1243 print " <date>$man_date</date>\n";
1244 print "</refentryinfo>\n";
1245 print "<refmeta>\n";
1246 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
1247 print " <manvolnum>9</manvolnum>\n";
1248 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1249 print "</refmeta>\n";
1250 print "<refnamediv>\n";
1251 print " <refname>enum " . $args{'enum'} . "</refname>\n";
1252 print " <refpurpose>\n";
1254 output_highlight ($args{'purpose'});
1255 print " </refpurpose>\n";
1256 print "</refnamediv>\n";
1258 print "<refsynopsisdiv>\n";
1259 print " <title>Synopsis</title>\n";
1260 print " <programlisting>\n";
1261 print "enum " . $args{'enum'} . " {\n";
1263 foreach $parameter (@{$args{'parameterlist'}}) {
1264 print " $parameter";
1265 if ($count != $#{$args{'parameterlist'}}) {
1272 print " </programlisting>\n";
1273 print "</refsynopsisdiv>\n";
1275 print "<refsect1>\n";
1276 print " <title>Constants</title>\n";
1277 print " <variablelist>\n";
1278 foreach $parameter (@{$args{'parameterlist'}}) {
1279 my $parameter_name = $parameter;
1280 $parameter_name =~ s/\[.*//;
1282 print " <varlistentry>";
1283 print " <term>$parameter</term>\n";
1284 print " <listitem><para>\n";
1285 output_highlight($args{'parameterdescs'}{$parameter_name});
1286 print " </para></listitem>\n";
1287 print " </varlistentry>\n";
1289 print " </variablelist>\n";
1290 print "</refsect1>\n";
1292 output_section_xml(@_);
1294 print "</refentry>\n\n";
1297 # output typedef in XML DocBook
1298 sub output_typedef_xml(%) {
1299 my %args = %{$_[0]};
1300 my ($parameter, $section);
1303 $id = "API-typedef-" . $args{'typedef'};
1304 $id =~ s/[^A-Za-z0-9]/-/g;
1306 print "<refentry id=\"$id\">\n";
1307 print "<refentryinfo>\n";
1308 print " <title>LINUX</title>\n";
1309 print " <productname>Kernel Hackers Manual</productname>\n";
1310 print " <date>$man_date</date>\n";
1311 print "</refentryinfo>\n";
1312 print "<refmeta>\n";
1313 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
1314 print " <manvolnum>9</manvolnum>\n";
1315 print "</refmeta>\n";
1316 print "<refnamediv>\n";
1317 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
1318 print " <refpurpose>\n";
1320 output_highlight ($args{'purpose'});
1321 print " </refpurpose>\n";
1322 print "</refnamediv>\n";
1324 print "<refsynopsisdiv>\n";
1325 print " <title>Synopsis</title>\n";
1326 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
1327 print "</refsynopsisdiv>\n";
1329 output_section_xml(@_);
1331 print "</refentry>\n\n";
1334 # output in XML DocBook
1335 sub output_blockhead_xml(%) {
1336 my %args = %{$_[0]};
1337 my ($parameter, $section);
1340 my $id = $args{'module'};
1341 $id =~ s/[^A-Za-z0-9]/-/g;
1343 # print out each section
1345 foreach $section (@{$args{'sectionlist'}}) {
1346 if (!$args{'content-only'}) {
1347 print "<refsect1>\n <title>$section</title>\n";
1349 if ($section =~ m/EXAMPLE/i) {
1350 print "<example><para>\n";
1351 $output_preformatted = 1;
1355 output_highlight($args{'sections'}{$section});
1356 $output_preformatted = 0;
1357 if ($section =~ m/EXAMPLE/i) {
1358 print "</para></example>\n";
1362 if (!$args{'content-only'}) {
1363 print "\n</refsect1>\n";
1370 # output in XML DocBook
1371 sub output_function_gnome {
1372 my %args = %{$_[0]};
1373 my ($parameter, $section);
1377 $id = $args{'module'} . "-" . $args{'function'};
1378 $id =~ s/[^A-Za-z0-9]/-/g;
1381 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
1383 print " <funcsynopsis>\n";
1384 print " <funcdef>" . $args{'functiontype'} . " ";
1385 print "<function>" . $args{'function'} . " ";
1386 print "</function></funcdef>\n";
1389 if ($#{$args{'parameterlist'}} >= 0) {
1390 foreach $parameter (@{$args{'parameterlist'}}) {
1391 $type = $args{'parametertypes'}{$parameter};
1392 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1393 # pointer-to-function
1394 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1395 print " <funcparams>$2</funcparams></paramdef>\n";
1397 print " <paramdef>" . $type;
1398 print " <parameter>$parameter</parameter></paramdef>\n";
1404 print " </funcsynopsis>\n";
1405 if ($#{$args{'parameterlist'}} >= 0) {
1406 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1407 print "<tgroup cols=\"2\">\n";
1408 print "<colspec colwidth=\"2*\">\n";
1409 print "<colspec colwidth=\"8*\">\n";
1411 foreach $parameter (@{$args{'parameterlist'}}) {
1412 my $parameter_name = $parameter;
1413 $parameter_name =~ s/\[.*//;
1415 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1418 output_highlight($args{'parameterdescs'}{$parameter_name});
1419 print " </entry></row>\n";
1421 print " </tbody></tgroup></informaltable>\n";
1423 print " <para>\n None\n </para>\n";
1426 # print out each section
1428 foreach $section (@{$args{'sectionlist'}}) {
1429 print "<simplesect>\n <title>$section</title>\n";
1430 if ($section =~ m/EXAMPLE/i) {
1431 print "<example><programlisting>\n";
1432 $output_preformatted = 1;
1436 output_highlight($args{'sections'}{$section});
1437 $output_preformatted = 0;
1439 if ($section =~ m/EXAMPLE/i) {
1440 print "</programlisting></example>\n";
1443 print " </simplesect>\n";
1446 print "</sect2>\n\n";
1450 # output function in man
1451 sub output_function_man(%) {
1452 my %args = %{$_[0]};
1453 my ($parameter, $section);
1456 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1459 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1461 print ".SH SYNOPSIS\n";
1462 if ($args{'functiontype'} ne "") {
1463 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1465 print ".B \"" . $args{'function'} . "\n";
1470 foreach my $parameter (@{$args{'parameterlist'}}) {
1471 if ($count == $#{$args{'parameterlist'}}) {
1474 $type = $args{'parametertypes'}{$parameter};
1475 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1476 # pointer-to-function
1477 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1479 $type =~ s/([^\*])$/$1 /;
1480 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1486 print ".SH ARGUMENTS\n";
1487 foreach $parameter (@{$args{'parameterlist'}}) {
1488 my $parameter_name = $parameter;
1489 $parameter_name =~ s/\[.*//;
1491 print ".IP \"" . $parameter . "\" 12\n";
1492 output_highlight($args{'parameterdescs'}{$parameter_name});
1494 foreach $section (@{$args{'sectionlist'}}) {
1495 print ".SH \"", uc $section, "\"\n";
1496 output_highlight($args{'sections'}{$section});
1501 # output enum in man
1502 sub output_enum_man(%) {
1503 my %args = %{$_[0]};
1504 my ($parameter, $section);
1507 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1510 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1512 print ".SH SYNOPSIS\n";
1513 print "enum " . $args{'enum'} . " {\n";
1515 foreach my $parameter (@{$args{'parameterlist'}}) {
1516 print ".br\n.BI \" $parameter\"\n";
1517 if ($count == $#{$args{'parameterlist'}}) {
1527 print ".SH Constants\n";
1528 foreach $parameter (@{$args{'parameterlist'}}) {
1529 my $parameter_name = $parameter;
1530 $parameter_name =~ s/\[.*//;
1532 print ".IP \"" . $parameter . "\" 12\n";
1533 output_highlight($args{'parameterdescs'}{$parameter_name});
1535 foreach $section (@{$args{'sectionlist'}}) {
1536 print ".SH \"$section\"\n";
1537 output_highlight($args{'sections'}{$section});
1542 # output struct in man
1543 sub output_struct_man(%) {
1544 my %args = %{$_[0]};
1545 my ($parameter, $section);
1547 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1550 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1552 print ".SH SYNOPSIS\n";
1553 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1555 foreach my $parameter (@{$args{'parameterlist'}}) {
1556 if ($parameter =~ /^#/) {
1557 print ".BI \"$parameter\"\n.br\n";
1560 my $parameter_name = $parameter;
1561 $parameter_name =~ s/\[.*//;
1563 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1564 $type = $args{'parametertypes'}{$parameter};
1565 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1566 # pointer-to-function
1567 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1568 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1570 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1572 $type =~ s/([^\*])$/$1 /;
1573 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1579 print ".SH Members\n";
1580 foreach $parameter (@{$args{'parameterlist'}}) {
1581 ($parameter =~ /^#/) && next;
1583 my $parameter_name = $parameter;
1584 $parameter_name =~ s/\[.*//;
1586 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1587 print ".IP \"" . $parameter . "\" 12\n";
1588 output_highlight($args{'parameterdescs'}{$parameter_name});
1590 foreach $section (@{$args{'sectionlist'}}) {
1591 print ".SH \"$section\"\n";
1592 output_highlight($args{'sections'}{$section});
1597 # output typedef in man
1598 sub output_typedef_man(%) {
1599 my %args = %{$_[0]};
1600 my ($parameter, $section);
1602 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1605 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1607 foreach $section (@{$args{'sectionlist'}}) {
1608 print ".SH \"$section\"\n";
1609 output_highlight($args{'sections'}{$section});
1613 sub output_blockhead_man(%) {
1614 my %args = %{$_[0]};
1615 my ($parameter, $section);
1618 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1620 foreach $section (@{$args{'sectionlist'}}) {
1621 print ".SH \"$section\"\n";
1622 output_highlight($args{'sections'}{$section});
1628 sub output_function_text(%) {
1629 my %args = %{$_[0]};
1630 my ($parameter, $section);
1634 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1636 print "\nSynopsis:\n\n";
1637 if ($args{'functiontype'} ne "") {
1638 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1640 $start = $args{'function'} . " (";
1645 foreach my $parameter (@{$args{'parameterlist'}}) {
1646 $type = $args{'parametertypes'}{$parameter};
1647 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1648 # pointer-to-function
1649 print $1 . $parameter . ") (" . $2;
1651 print $type . " " . $parameter;
1653 if ($count != $#{$args{'parameterlist'}}) {
1656 print " " x length($start);
1662 print "Arguments:\n\n";
1663 foreach $parameter (@{$args{'parameterlist'}}) {
1664 my $parameter_name = $parameter;
1665 $parameter_name =~ s/\[.*//;
1667 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1669 output_section_text(@_);
1672 #output sections in text
1673 sub output_section_text(%) {
1674 my %args = %{$_[0]};
1678 foreach $section (@{$args{'sectionlist'}}) {
1679 print "$section:\n\n";
1680 output_highlight($args{'sections'}{$section});
1685 # output enum in text
1686 sub output_enum_text(%) {
1687 my %args = %{$_[0]};
1692 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1693 print "enum " . $args{'enum'} . " {\n";
1695 foreach $parameter (@{$args{'parameterlist'}}) {
1696 print "\t$parameter";
1697 if ($count != $#{$args{'parameterlist'}}) {
1705 print "Constants:\n\n";
1706 foreach $parameter (@{$args{'parameterlist'}}) {
1707 print "$parameter\n\t";
1708 print $args{'parameterdescs'}{$parameter} . "\n";
1711 output_section_text(@_);
1714 # output typedef in text
1715 sub output_typedef_text(%) {
1716 my %args = %{$_[0]};
1719 print "Typedef:\n\n";
1721 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1722 output_section_text(@_);
1725 # output struct as text
1726 sub output_struct_text(%) {
1727 my %args = %{$_[0]};
1730 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1731 print $args{'type'} . " " . $args{'struct'} . " {\n";
1732 foreach $parameter (@{$args{'parameterlist'}}) {
1733 if ($parameter =~ /^#/) {
1734 print "$parameter\n";
1738 my $parameter_name = $parameter;
1739 $parameter_name =~ s/\[.*//;
1741 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1742 $type = $args{'parametertypes'}{$parameter};
1743 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1744 # pointer-to-function
1745 print "\t$1 $parameter) ($2);\n";
1746 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1748 print "\t$1 $parameter$2;\n";
1750 print "\t" . $type . " " . $parameter . ";\n";
1755 print "Members:\n\n";
1756 foreach $parameter (@{$args{'parameterlist'}}) {
1757 ($parameter =~ /^#/) && next;
1759 my $parameter_name = $parameter;
1760 $parameter_name =~ s/\[.*//;
1762 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1763 print "$parameter\n\t";
1764 print $args{'parameterdescs'}{$parameter_name} . "\n";
1767 output_section_text(@_);
1770 sub output_blockhead_text(%) {
1771 my %args = %{$_[0]};
1772 my ($parameter, $section);
1774 foreach $section (@{$args{'sectionlist'}}) {
1775 print " $section:\n";
1777 output_highlight($args{'sections'}{$section});
1782 # output in restructured text
1786 # This could use some work; it's used to output the DOC: sections, and
1787 # starts by putting out the name of the doc section itself, but that tends
1788 # to duplicate a header already in the template file.
1790 sub output_blockhead_rst(%) {
1791 my %args = %{$_[0]};
1792 my ($parameter, $section);
1794 foreach $section (@{$args{'sectionlist'}}) {
1795 if ($output_selection != OUTPUT_INCLUDE) {
1796 print "**$section**\n\n";
1798 print_lineno($section_start_lines{$section});
1799 output_highlight_rst($args{'sections'}{$section});
1804 sub output_highlight_rst {
1805 my $contents = join "\n",@_;
1808 # undo the evil effects of xml_escape() earlier
1809 $contents = xml_unescape($contents);
1814 foreach $line (split "\n", $contents) {
1815 print $lineprefix . $line . "\n";
1819 sub output_function_rst(%) {
1820 my %args = %{$_[0]};
1821 my ($parameter, $section);
1822 my $oldprefix = $lineprefix;
1825 print ".. c:function:: ";
1826 if ($args{'functiontype'} ne "") {
1827 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1829 $start = $args{'function'} . " (";
1834 foreach my $parameter (@{$args{'parameterlist'}}) {
1839 $type = $args{'parametertypes'}{$parameter};
1840 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1841 # pointer-to-function
1842 print $1 . $parameter . ") (" . $2;
1844 print $type . " " . $parameter;
1848 print_lineno($declaration_start_line);
1850 output_highlight_rst($args{'purpose'});
1853 print "**Parameters**\n\n";
1855 foreach $parameter (@{$args{'parameterlist'}}) {
1856 my $parameter_name = $parameter;
1857 #$parameter_name =~ s/\[.*//;
1858 $type = $args{'parametertypes'}{$parameter};
1861 print "``$type $parameter``\n";
1863 print "``$parameter``\n";
1866 print_lineno($parameterdesc_start_lines{$parameter_name});
1868 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1869 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
1870 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1872 print " *undescribed*\n";
1877 $lineprefix = $oldprefix;
1878 output_section_rst(@_);
1881 sub output_section_rst(%) {
1882 my %args = %{$_[0]};
1884 my $oldprefix = $lineprefix;
1887 foreach $section (@{$args{'sectionlist'}}) {
1888 print "**$section**\n\n";
1889 print_lineno($section_start_lines{$section});
1890 output_highlight_rst($args{'sections'}{$section});
1894 $lineprefix = $oldprefix;
1897 sub output_enum_rst(%) {
1898 my %args = %{$_[0]};
1900 my $oldprefix = $lineprefix;
1902 my $name = "enum " . $args{'enum'};
1904 print "\n\n.. c:type:: " . $name . "\n\n";
1905 print_lineno($declaration_start_line);
1907 output_highlight_rst($args{'purpose'});
1910 print "**Constants**\n\n";
1912 foreach $parameter (@{$args{'parameterlist'}}) {
1913 print "``$parameter``\n";
1914 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1915 output_highlight_rst($args{'parameterdescs'}{$parameter});
1917 print " *undescribed*\n";
1922 $lineprefix = $oldprefix;
1923 output_section_rst(@_);
1926 sub output_typedef_rst(%) {
1927 my %args = %{$_[0]};
1929 my $oldprefix = $lineprefix;
1930 my $name = "typedef " . $args{'typedef'};
1932 print "\n\n.. c:type:: " . $name . "\n\n";
1933 print_lineno($declaration_start_line);
1935 output_highlight_rst($args{'purpose'});
1938 $lineprefix = $oldprefix;
1939 output_section_rst(@_);
1942 sub output_struct_rst(%) {
1943 my %args = %{$_[0]};
1945 my $oldprefix = $lineprefix;
1946 my $name = $args{'type'} . " " . $args{'struct'};
1948 print "\n\n.. c:type:: " . $name . "\n\n";
1949 print_lineno($declaration_start_line);
1951 output_highlight_rst($args{'purpose'});
1954 print "**Definition**\n\n";
1956 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1957 foreach $parameter (@{$args{'parameterlist'}}) {
1958 if ($parameter =~ /^#/) {
1959 print " " . "$parameter\n";
1963 my $parameter_name = $parameter;
1964 $parameter_name =~ s/\[.*//;
1966 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1967 $type = $args{'parametertypes'}{$parameter};
1968 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1969 # pointer-to-function
1970 print " $1 $parameter) ($2);\n";
1971 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1973 print " $1 $parameter$2;\n";
1975 print " " . $type . " " . $parameter . ";\n";
1980 print "**Members**\n\n";
1982 foreach $parameter (@{$args{'parameterlist'}}) {
1983 ($parameter =~ /^#/) && next;
1985 my $parameter_name = $parameter;
1986 $parameter_name =~ s/\[.*//;
1988 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1989 $type = $args{'parametertypes'}{$parameter};
1990 print_lineno($parameterdesc_start_lines{$parameter_name});
1991 print "``$type $parameter``\n";
1992 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1997 $lineprefix = $oldprefix;
1998 output_section_rst(@_);
2002 ## list mode output functions
2004 sub output_function_list(%) {
2005 my %args = %{$_[0]};
2007 print $args{'function'} . "\n";
2010 # output enum in list
2011 sub output_enum_list(%) {
2012 my %args = %{$_[0]};
2013 print $args{'enum'} . "\n";
2016 # output typedef in list
2017 sub output_typedef_list(%) {
2018 my %args = %{$_[0]};
2019 print $args{'typedef'} . "\n";
2022 # output struct as list
2023 sub output_struct_list(%) {
2024 my %args = %{$_[0]};
2026 print $args{'struct'} . "\n";
2029 sub output_blockhead_list(%) {
2030 my %args = %{$_[0]};
2031 my ($parameter, $section);
2033 foreach $section (@{$args{'sectionlist'}}) {
2034 print "DOC: $section\n";
2039 # generic output function for all types (function, struct/union, typedef, enum);
2040 # calls the generated, variable output_ function name based on
2041 # functype and output_mode
2042 sub output_declaration {
2045 my $functype = shift;
2046 my $func = "output_${functype}_$output_mode";
2047 if (($output_selection == OUTPUT_ALL) ||
2048 (($output_selection == OUTPUT_INCLUDE ||
2049 $output_selection == OUTPUT_EXPORTED) &&
2050 defined($function_table{$name})) ||
2051 (($output_selection == OUTPUT_EXCLUDE ||
2052 $output_selection == OUTPUT_INTERNAL) &&
2053 !($functype eq "function" && defined($function_table{$name}))))
2061 # generic output function - calls the right one based on current output mode.
2062 sub output_blockhead {
2064 my $func = "output_blockhead_" . $output_mode;
2070 # takes a declaration (struct, union, enum, typedef) and
2071 # invokes the right handler. NOT called for functions.
2072 sub dump_declaration($$) {
2074 my ($prototype, $file) = @_;
2075 my $func = "dump_" . $decl_type;
2079 sub dump_union($$) {
2083 sub dump_struct($$) {
2088 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2089 #my $decl_type = $1;
2090 $declaration_name = $2;
2093 # ignore embedded structs or unions
2094 $members =~ s/({.*})//g;
2097 # ignore members marked private:
2098 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2099 $members =~ s/\/\*\s*private:.*//gosi;
2101 $members =~ s/\/\*.*?\*\///gos;
2102 $nested =~ s/\/\*.*?\*\///gos;
2103 # strip kmemcheck_bitfield_{begin,end}.*;
2104 $members =~ s/kmemcheck_bitfield_.*?;//gos;
2106 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
2107 $members =~ s/__aligned\s*\([^;]*\)//gos;
2108 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
2109 # replace DECLARE_BITMAP
2110 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
2112 create_parameterlist($members, ';', $file);
2113 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
2115 output_declaration($declaration_name,
2117 {'struct' => $declaration_name,
2118 'module' => $modulename,
2119 'parameterlist' => \@parameterlist,
2120 'parameterdescs' => \%parameterdescs,
2121 'parametertypes' => \%parametertypes,
2122 'sectionlist' => \@sectionlist,
2123 'sections' => \%sections,
2124 'purpose' => $declaration_purpose,
2125 'type' => $decl_type
2129 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
2138 $x =~ s@/\*.*?\*/@@gos; # strip comments.
2139 # strip #define macros inside enums
2140 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
2142 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
2143 $declaration_name = $1;
2146 foreach my $arg (split ',', $members) {
2147 $arg =~ s/^\s*(\w+).*/$1/;
2148 push @parameterlist, $arg;
2149 if (!$parameterdescs{$arg}) {
2150 $parameterdescs{$arg} = $undescribed;
2151 print STDERR "${file}:$.: warning: Enum value '$arg' ".
2152 "not described in enum '$declaration_name'\n";
2157 output_declaration($declaration_name,
2159 {'enum' => $declaration_name,
2160 'module' => $modulename,
2161 'parameterlist' => \@parameterlist,
2162 'parameterdescs' => \%parameterdescs,
2163 'sectionlist' => \@sectionlist,
2164 'sections' => \%sections,
2165 'purpose' => $declaration_purpose
2169 print STDERR "${file}:$.: error: Cannot parse enum!\n";
2174 sub dump_typedef($$) {
2178 $x =~ s@/\*.*?\*/@@gos; # strip comments.
2180 # Parse function prototypes
2181 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2184 $declaration_name = $2;
2187 create_parameterlist($args, ',', $file);
2189 output_declaration($declaration_name,
2191 {'function' => $declaration_name,
2192 'module' => $modulename,
2193 'functiontype' => $return_type,
2194 'parameterlist' => \@parameterlist,
2195 'parameterdescs' => \%parameterdescs,
2196 'parametertypes' => \%parametertypes,
2197 'sectionlist' => \@sectionlist,
2198 'sections' => \%sections,
2199 'purpose' => $declaration_purpose
2204 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
2205 $x =~ s/\(*.\)\s*;$/;/;
2206 $x =~ s/\[*.\]\s*;$/;/;
2209 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
2210 $declaration_name = $1;
2212 output_declaration($declaration_name,
2214 {'typedef' => $declaration_name,
2215 'module' => $modulename,
2216 'sectionlist' => \@sectionlist,
2217 'sections' => \%sections,
2218 'purpose' => $declaration_purpose
2222 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
2227 sub save_struct_actual($) {
2230 # strip all spaces from the actual param so that it looks like one string item
2231 $actual =~ s/\s*//g;
2232 $struct_actual = $struct_actual . $actual . " ";
2235 sub create_parameterlist($$$) {
2237 my $splitter = shift;
2242 # temporarily replace commas inside function pointer definition
2243 while ($args =~ /(\([^\),]+),/) {
2244 $args =~ s/(\([^\),]+),/$1#/g;
2247 foreach my $arg (split($splitter, $args)) {
2249 $arg =~ s/\/\*.*\*\///;
2250 # strip leading/trailing spaces
2256 # Treat preprocessor directive as a typeless variable just to fill
2257 # corresponding data structures "correctly". Catch it later in
2259 push_parameter($arg, "", $file);
2260 } elsif ($arg =~ m/\(.+\)\s*\(/) {
2261 # pointer-to-function
2263 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
2266 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
2267 save_struct_actual($param);
2268 push_parameter($param, $type, $file);
2270 $arg =~ s/\s*:\s*/:/g;
2271 $arg =~ s/\s*\[/\[/g;
2273 my @args = split('\s*,\s*', $arg);
2274 if ($args[0] =~ m/\*/) {
2275 $args[0] =~ s/(\*+)\s*/ $1/;
2279 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2281 push(@first_arg, split('\s+', $1));
2282 push(@first_arg, $2);
2284 @first_arg = split('\s+', shift @args);
2287 unshift(@args, pop @first_arg);
2288 $type = join " ", @first_arg;
2290 foreach $param (@args) {
2291 if ($param =~ m/^(\*+)\s*(.*)/) {
2292 save_struct_actual($2);
2293 push_parameter($2, "$type $1", $file);
2295 elsif ($param =~ m/(.*?):(\d+)/) {
2296 if ($type ne "") { # skip unnamed bit-fields
2297 save_struct_actual($1);
2298 push_parameter($1, "$type:$2", $file)
2302 save_struct_actual($param);
2303 push_parameter($param, $type, $file);
2310 sub push_parameter($$$) {
2315 if (($anon_struct_union == 1) && ($type eq "") &&
2317 return; # ignore the ending }; from anon. struct/union
2320 $anon_struct_union = 0;
2321 my $param_name = $param;
2322 $param_name =~ s/\[.*//;
2324 if ($type eq "" && $param =~ /\.\.\.$/)
2326 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2327 $parameterdescs{$param} = "variable arguments";
2330 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2333 $parameterdescs{void} = "no arguments";
2335 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2336 # handle unnamed (anonymous) union or struct:
2339 $param = "{unnamed_" . $param . "}";
2340 $parameterdescs{$param} = "anonymous\n";
2341 $anon_struct_union = 1;
2344 # warn if parameter has no description
2345 # (but ignore ones starting with # as these are not parameters
2346 # but inline preprocessor statements);
2347 # also ignore unnamed structs/unions;
2348 if (!$anon_struct_union) {
2349 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2351 $parameterdescs{$param_name} = $undescribed;
2353 if (($type eq 'function') || ($type eq 'enum')) {
2354 print STDERR "${file}:$.: warning: Function parameter ".
2355 "or member '$param' not " .
2356 "described in '$declaration_name'\n";
2358 print STDERR "${file}:$.: warning:" .
2359 " No description found for parameter '$param'\n";
2364 $param = xml_escape($param);
2366 # strip spaces from $param so that it is one continuous string
2367 # on @parameterlist;
2368 # this fixes a problem where check_sections() cannot find
2369 # a parameter like "addr[6 + 2]" because it actually appears
2370 # as "addr[6", "+", "2]" on the parameter list;
2371 # but it's better to maintain the param string unchanged for output,
2372 # so just weaken the string compare in check_sections() to ignore
2373 # "[blah" in a parameter string;
2374 ###$param =~ s/\s*//g;
2375 push @parameterlist, $param;
2376 $parametertypes{$param} = $type;
2379 sub check_sections($$$$$$) {
2380 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2381 my @sects = split ' ', $sectcheck;
2382 my @prms = split ' ', $prmscheck;
2385 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2387 foreach $sx (0 .. $#sects) {
2389 foreach $px (0 .. $#prms) {
2390 $prm_clean = $prms[$px];
2391 $prm_clean =~ s/\[.*\]//;
2392 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
2393 # ignore array size in a parameter string;
2394 # however, the original param string may contain
2395 # spaces, e.g.: addr[6 + 2]
2396 # and this appears in @prms as "addr[6" since the
2397 # parameter list is split at spaces;
2398 # hence just ignore "[..." for the sections check;
2399 $prm_clean =~ s/\[.*//;
2401 ##$prm_clean =~ s/^\**//;
2402 if ($prm_clean eq $sects[$sx]) {
2408 if ($decl_type eq "function") {
2409 print STDERR "${file}:$.: warning: " .
2410 "Excess function parameter " .
2412 "description in '$decl_name'\n";
2415 if ($nested !~ m/\Q$sects[$sx]\E/) {
2416 print STDERR "${file}:$.: warning: " .
2417 "Excess struct/union/enum/typedef member " .
2419 "description in '$decl_name'\n";
2428 # Checks the section describing the return value of a function.
2429 sub check_return_section {
2431 my $declaration_name = shift;
2432 my $return_type = shift;
2434 # Ignore an empty return type (It's a macro)
2435 # Ignore functions with a "void" return type. (But don't ignore "void *")
2436 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2440 if (!defined($sections{$section_return}) ||
2441 $sections{$section_return} eq "") {
2442 print STDERR "${file}:$.: warning: " .
2443 "No description found for return value of " .
2444 "'$declaration_name'\n";
2450 # takes a function prototype and the name of the current file being
2451 # processed and spits out all the details stored in the global
2453 sub dump_function($$) {
2454 my $prototype = shift;
2458 $prototype =~ s/^static +//;
2459 $prototype =~ s/^extern +//;
2460 $prototype =~ s/^asmlinkage +//;
2461 $prototype =~ s/^inline +//;
2462 $prototype =~ s/^__inline__ +//;
2463 $prototype =~ s/^__inline +//;
2464 $prototype =~ s/^__always_inline +//;
2465 $prototype =~ s/^noinline +//;
2466 $prototype =~ s/__init +//;
2467 $prototype =~ s/__init_or_module +//;
2468 $prototype =~ s/__meminit +//;
2469 $prototype =~ s/__must_check +//;
2470 $prototype =~ s/__weak +//;
2471 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
2472 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
2474 # Yes, this truly is vile. We are looking for:
2475 # 1. Return type (may be nothing if we're looking at a macro)
2477 # 3. Function parameters.
2479 # All the while we have to watch out for function pointer parameters
2480 # (which IIRC is what the two sections are for), C types (these
2481 # regexps don't even start to express all the possibilities), and
2484 # If you mess with these regexps, it's a good idea to check that
2485 # the following functions' documentation still comes out right:
2486 # - parport_register_device (function pointer parameters)
2487 # - atomic_set (macro)
2488 # - pci_match_device, __copy_to_user (long return type)
2490 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2491 # This is an object-like macro, it has no return type and no parameter
2493 # Function-like macros are not allowed to have spaces between
2494 # declaration_name and opening parenthesis (notice the \s+).
2496 $declaration_name = $2;
2498 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2499 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2500 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2501 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2502 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2503 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2504 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2505 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2506 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2507 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2508 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2509 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2510 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2511 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2512 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2513 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2514 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
2516 $declaration_name = $2;
2519 create_parameterlist($args, ',', $file);
2521 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
2525 my $prms = join " ", @parameterlist;
2526 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2528 # This check emits a lot of warnings at the moment, because many
2529 # functions don't have a 'Return' doc section. So until the number
2530 # of warnings goes sufficiently down, the check is only performed in
2532 # TODO: always perform the check.
2533 if ($verbose && !$noret) {
2534 check_return_section($file, $declaration_name, $return_type);
2537 output_declaration($declaration_name,
2539 {'function' => $declaration_name,
2540 'module' => $modulename,
2541 'functiontype' => $return_type,
2542 'parameterlist' => \@parameterlist,
2543 'parameterdescs' => \%parameterdescs,
2544 'parametertypes' => \%parametertypes,
2545 'sectionlist' => \@sectionlist,
2546 'sections' => \%sections,
2547 'purpose' => $declaration_purpose
2553 %parameterdescs = ();
2554 %parametertypes = ();
2555 @parameterlist = ();
2559 $struct_actual = "";
2562 $state = STATE_NORMAL;
2563 $inline_doc_state = STATE_INLINE_NA;
2566 sub tracepoint_munge($) {
2568 my $tracepointname = 0;
2569 my $tracepointargs = 0;
2571 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
2572 $tracepointname = $1;
2574 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2575 $tracepointname = $1;
2577 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2578 $tracepointname = $2;
2580 $tracepointname =~ s/^\s+//; #strip leading whitespace
2581 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
2582 $tracepointargs = $1;
2584 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
2585 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
2588 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2592 sub syscall_munge() {
2595 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2596 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2597 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2599 ## $prototype = "long sys_$1(void)";
2602 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2603 if ($prototype =~ m/long (sys_.*?),/) {
2604 $prototype =~ s/,/\(/;
2606 $prototype =~ s/\)/\(void\)/;
2609 # now delete all of the odd-number commas in $prototype
2610 # so that arg types & arg names don't have a comma between them
2612 my $len = length($prototype);
2614 $len = 0; # skip the for-loop
2616 for (my $ix = 0; $ix < $len; $ix++) {
2617 if (substr($prototype, $ix, 1) eq ',') {
2619 if ($count % 2 == 1) {
2620 substr($prototype, $ix, 1) = ' ';
2626 sub process_proto_function($$) {
2630 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2632 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
2635 elsif ($x =~ /([^\{]*)/) {
2639 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
2640 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
2641 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2642 $prototype =~ s@^\s+@@gos; # strip leading spaces
2643 if ($prototype =~ /SYSCALL_DEFINE/) {
2646 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2647 $prototype =~ /DEFINE_SINGLE_EVENT/)
2649 tracepoint_munge($file);
2651 dump_function($prototype, $file);
2656 sub process_proto_type($$) {
2660 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2661 $x =~ s@^\s+@@gos; # strip leading spaces
2662 $x =~ s@\s+$@@gos; # strip trailing spaces
2663 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2666 # To distinguish preprocessor directive from regular declaration later.
2671 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
2672 $prototype .= $1 . $2;
2673 ($2 eq '{') && $brcount++;
2674 ($2 eq '}') && $brcount--;
2675 if (($2 eq ';') && ($brcount == 0)) {
2676 dump_declaration($prototype, $file);
2688 # xml_escape: replace <, >, and & in the text stream;
2690 # however, formatting controls that are generated internally/locally in the
2691 # kernel-doc script are not escaped here; instead, they begin life like
2692 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2693 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2694 # just before actual output; (this is done by local_unescape())
2697 if (($output_mode eq "text") || ($output_mode eq "man")) {
2700 $text =~ s/\&/\\\\\\amp;/g;
2701 $text =~ s/\</\\\\\\lt;/g;
2702 $text =~ s/\>/\\\\\\gt;/g;
2706 # xml_unescape: reverse the effects of xml_escape
2707 sub xml_unescape($) {
2709 if (($output_mode eq "text") || ($output_mode eq "man")) {
2712 $text =~ s/\\\\\\amp;/\&/g;
2713 $text =~ s/\\\\\\lt;/</g;
2714 $text =~ s/\\\\\\gt;/>/g;
2718 # convert local escape strings to html
2719 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2720 sub local_unescape($) {
2722 if (($output_mode eq "text") || ($output_mode eq "man")) {
2725 $text =~ s/\\\\\\\\lt:/</g;
2726 $text =~ s/\\\\\\\\gt:/>/g;
2730 sub process_file($) {
2736 my $initial_section_counter = $section_counter;
2737 my ($orig_file) = @_;
2740 if (defined($ENV{'SRCTREE'})) {
2741 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2746 if (defined($source_map{$file})) {
2747 $file = $source_map{$file};
2750 if (!open(IN,"<$file")) {
2751 print STDERR "Error: Cannot open file $file\n";
2756 # two passes for -export and -internal
2757 if ($output_selection == OUTPUT_EXPORTED ||
2758 $output_selection == OUTPUT_INTERNAL) {
2760 if (/$export_symbol/o) {
2761 $function_table{$2} = 1;
2769 $section_counter = 0;
2771 while (s/\\\s*$//) {
2774 if ($state == STATE_NORMAL) {
2775 if (/$doc_start/o) {
2776 $state = STATE_NAME; # next line is always the function name
2778 $declaration_start_line = $. + 1;
2780 } elsif ($state == STATE_NAME) {# this line is the function name (always)
2781 if (/$doc_block/o) {
2782 $state = STATE_DOCBLOCK;
2784 $new_start_line = $. + 1;
2787 $section = $section_intro;
2792 elsif (/$doc_decl/o) {
2794 if (/\s*([\w\s]+?)\s*-/) {
2798 $state = STATE_FIELD;
2799 # if there's no @param blocks need to set up default section
2802 $section = $section_default;
2803 $new_start_line = $. + 1;
2805 # strip leading/trailing/multiple spaces
2809 $descr =~ s/\s+/ /g;
2810 $declaration_purpose = xml_escape($descr);
2813 $declaration_purpose = "";
2816 if (($declaration_purpose eq "") && $verbose) {
2817 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
2822 if ($identifier =~ m/^struct/) {
2823 $decl_type = 'struct';
2824 } elsif ($identifier =~ m/^union/) {
2825 $decl_type = 'union';
2826 } elsif ($identifier =~ m/^enum/) {
2827 $decl_type = 'enum';
2828 } elsif ($identifier =~ m/^typedef/) {
2829 $decl_type = 'typedef';
2831 $decl_type = 'function';
2835 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
2838 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
2839 " - I thought it was a doc line\n";
2841 $state = STATE_NORMAL;
2843 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
2844 if (/$doc_sect/i) { # case insensitive for supported section names
2848 # map the supported section names to the canonical names
2849 if ($newsection =~ m/^description$/i) {
2850 $newsection = $section_default;
2851 } elsif ($newsection =~ m/^context$/i) {
2852 $newsection = $section_context;
2853 } elsif ($newsection =~ m/^returns?$/i) {
2854 $newsection = $section_return;
2855 } elsif ($newsection =~ m/^\@return$/) {
2856 # special: @return is a section, not a param description
2857 $newsection = $section_return;
2860 if (($contents ne "") && ($contents ne "\n")) {
2861 if (!$in_doc_sect && $verbose) {
2862 print STDERR "${file}:$.: warning: contents before sections\n";
2865 dump_section($file, $section, xml_escape($contents));
2866 $section = $section_default;
2871 $contents = $newcontents;
2872 $new_start_line = $.;
2873 while ((substr($contents, 0, 1) eq " ") ||
2874 substr($contents, 0, 1) eq "\t") {
2875 $contents = substr($contents, 1);
2877 if ($contents ne "") {
2880 $section = $newsection;
2881 $leading_space = undef;
2882 } elsif (/$doc_end/) {
2883 if (($contents ne "") && ($contents ne "\n")) {
2884 dump_section($file, $section, xml_escape($contents));
2885 $section = $section_default;
2888 # look for doc_com + <text> + doc_end:
2889 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2890 print STDERR "${file}:$.: warning: suspicious ending line: $_";
2895 $state = STATE_PROTO;
2897 # print STDERR "end of doc comment, looking for prototype\n";
2898 } elsif (/$doc_content/) {
2899 # miguel-style comment kludge, look for blank lines after
2900 # @parameter line to signify start of description
2902 if ($section =~ m/^@/ || $section eq $section_context) {
2903 dump_section($file, $section, xml_escape($contents));
2904 $section = $section_default;
2906 $new_start_line = $.;
2911 } elsif ($in_purpose == 1) {
2912 # Continued declaration purpose
2913 chomp($declaration_purpose);
2914 $declaration_purpose .= " " . xml_escape($1);
2915 $declaration_purpose =~ s/\s+/ /g;
2918 if ($section =~ m/^@/ || $section eq $section_context) {
2919 if (!defined $leading_space) {
2920 if ($cont =~ m/^(\s+)/) {
2921 $leading_space = $1;
2923 $leading_space = "";
2927 $cont =~ s/^$leading_space//;
2929 $contents .= $cont . "\n";
2932 # i dont know - bad line? ignore.
2933 print STDERR "${file}:$.: warning: bad line: $_";
2936 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
2937 # First line (state 1) needs to be a @parameter
2938 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
2941 $new_start_line = $.;
2942 if ($contents ne "") {
2943 while ((substr($contents, 0, 1) eq " ") ||
2944 substr($contents, 0, 1) eq "\t") {
2945 $contents = substr($contents, 1);
2949 $inline_doc_state = STATE_INLINE_TEXT;
2950 # Documentation block end */
2951 } elsif (/$doc_inline_end/) {
2952 if (($contents ne "") && ($contents ne "\n")) {
2953 dump_section($file, $section, xml_escape($contents));
2954 $section = $section_default;
2957 $state = STATE_PROTO;
2958 $inline_doc_state = STATE_INLINE_NA;
2960 } elsif (/$doc_content/) {
2961 if ($inline_doc_state == STATE_INLINE_TEXT) {
2962 $contents .= $1 . "\n";
2963 # nuke leading blank lines
2964 if ($contents =~ /^\s*$/) {
2967 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2968 $inline_doc_state = STATE_INLINE_ERROR;
2969 print STDERR "Warning(${file}:$.): ";
2970 print STDERR "Incorrect use of kernel-doc format: $_";
2974 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2975 if (/$doc_inline_start/) {
2976 $state = STATE_INLINE;
2977 $inline_doc_state = STATE_INLINE_NAME;
2978 } elsif ($decl_type eq 'function') {
2979 process_proto_function($_, $file);
2981 process_proto_type($_, $file);
2983 } elsif ($state == STATE_DOCBLOCK) {
2986 dump_doc_section($file, $section, xml_escape($contents));
2987 $section = $section_default;
2990 %parameterdescs = ();
2991 %parametertypes = ();
2992 @parameterlist = ();
2996 $state = STATE_NORMAL;
2998 elsif (/$doc_content/)
3002 $contents .= $blankline;
3006 $contents .= $1 . "\n";
3011 if ($initial_section_counter == $section_counter) {
3012 print STDERR "${file}:1: warning: no structured comments found\n";
3013 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
3014 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3016 if ($output_mode eq "xml") {
3017 # The template wants at least one RefEntry here; make one.
3018 print "<refentry>\n";
3019 print " <refnamediv>\n";
3020 print " <refname>\n";
3021 print " ${orig_file}\n";
3022 print " </refname>\n";
3023 print " <refpurpose>\n";
3024 print " Document generation inconsistency\n";
3025 print " </refpurpose>\n";
3026 print " </refnamediv>\n";
3027 print " <refsect1>\n";
3030 print " </title>\n";
3031 print " <warning>\n";
3033 print " The template for this document tried to insert\n";
3034 print " the structured comment from the file\n";
3035 print " <filename>${orig_file}</filename> at this point,\n";
3036 print " but none was found.\n";
3037 print " This dummy section is inserted to allow\n";
3038 print " generation to continue.\n";
3040 print " </warning>\n";
3041 print " </refsect1>\n";
3042 print "</refentry>\n";
3048 $kernelversion = get_kernel_version();
3050 # generate a sequence of code that will splice in highlighting information
3051 # using the s// operator.
3052 for (my $k = 0; $k < @highlights; $k++) {
3053 my $pattern = $highlights[$k][0];
3054 my $result = $highlights[$k][1];
3055 # print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3056 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
3059 # Read the file that maps relative names to absolute names for
3060 # separate source and object directories and for shadow trees.
3061 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3062 my ($relname, $absname);
3063 while(<SOURCE_MAP>) {
3065 ($relname, $absname) = (split())[0..1];
3066 $relname =~ s:^/+::;
3067 $source_map{$relname} = $absname;
3076 if ($verbose && $errors) {
3077 print STDERR "$errors errors\n";
3079 if ($verbose && $warnings) {
3080 print STDERR "$warnings warnings\n";