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 # This will read a 'c' file and scan for embedded comments in the
44 # style of gnome comments (+minor extensions - see below).
47 # Note: This only supports 'c'.
50 # kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ]
51 # [ -no-doc-sections ]
52 # [ -function funcname [ -function funcname ...] ]
53 # c file(s)s > outputfile
55 # [ -nofunction funcname [ -function funcname ...] ]
56 # c file(s)s > outputfile
58 # Set output format using one of -docbook -html -html5 -text or -man.
60 # The -list format is for internal use by docproc.
63 # Do not output DOC: sections
66 # If set, then only generate documentation for the given function(s) or
67 # DOC: section titles. All other functions and DOC: sections are ignored.
69 # -nofunction funcname
70 # If set, then only generate documentation for the other function(s)/DOC:
71 # sections. Cannot be used together with -function (yes, that's a bug --
72 # perl hackers can fix it 8))
74 # c files - list of 'c' files to process
76 # All output goes to stdout, with errors to stderr.
80 # In the following table, (...)? signifies optional structure.
81 # (...)* signifies 0 or more structure elements
83 # * function_name(:)? (- short description)?
84 # (* @parameterx: (description of parameter x)?)*
86 # * (Description:)? (Description of function)?
87 # * (section header: (section description)? )*
90 # So .. the trivial example would be:
96 # If the Description: header tag is omitted, then there must be a blank line
97 # after the last parameter specification.
100 # * my_function - does my stuff
101 # * @my_arg: its mine damnit
103 # * Does my stuff explained.
106 # or, could also use:
108 # * my_function - does my stuff
109 # * @my_arg: its mine damnit
110 # * Description: Does my stuff explained.
114 # Besides functions you can also write documentation for structs, unions,
115 # enums and typedefs. Instead of the function name you must write the name
116 # of the declaration; the struct/union/enum/typedef must always precede
117 # the name. Nesting of declarations is not supported.
118 # Use the argument mechanism to document members or constants.
121 # * struct my_struct - short description
123 # * @b: second member
125 # * Longer description
134 # All descriptions can be multiline, except the short function description.
136 # You can also add additional sections. When documenting kernel functions you
137 # should document the "Context:" of the function, e.g. whether the functions
138 # can be called form interrupts. Unlike other sections you can end it with an
140 # A non-void function should have a "Return:" section describing the return
142 # Example-sections should contain the string EXAMPLE so that they are marked
143 # appropriately in DocBook.
147 # * user_function - function that can only be called in user context
148 # * @a: some argument
149 # * Context: !in_interrupt()
153 # * user_function(22);
158 # All descriptive text is further processed, scanning for the following special
159 # patterns, which are highlighted appropriately.
161 # 'funcname()' - function
162 # '$ENVVAR' - environmental variable
163 # '&struct_name' - name of a structure (up to two words including 'struct')
164 # '@parameter' - name of a parameter
165 # '%CONST' - name of a constant.
171 my $anon_struct_union = 0;
173 # match expressions used to find embedded type information
174 my $type_constant = '\%([-_\w]+)';
175 my $type_func = '(\w+)\(\)';
176 my $type_param = '\@(\w+)';
177 my $type_struct = '\&((struct\s*)*[_\w]+)';
178 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
179 my $type_env = '(\$\w+)';
181 # Output conversion substitutions.
182 # One for each output format
184 # these work fairly well
185 my %highlights_html = ( $type_constant, "<i>\$1</i>",
186 $type_func, "<b>\$1</b>",
187 $type_struct_xml, "<i>\$1</i>",
188 $type_env, "<b><i>\$1</i></b>",
189 $type_param, "<tt><b>\$1</b></tt>" );
190 my $local_lt = "\\\\\\\\lt:";
191 my $local_gt = "\\\\\\\\gt:";
192 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
195 my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>",
196 $type_func, "<span class=\"func\">\$1</span>",
197 $type_struct_xml, "<span class=\"struct\">\$1</span>",
198 $type_env, "<span class=\"env\">\$1</span>",
199 $type_param, "<span class=\"param\">\$1</span>" );
200 my $blankline_html5 = $local_lt . "br /" . $local_gt;
202 # XML, docbook format
203 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
204 $type_constant, "<constant>\$1</constant>",
205 $type_func, "<function>\$1</function>",
206 $type_struct_xml, "<structname>\$1</structname>",
207 $type_env, "<envar>\$1</envar>",
208 $type_param, "<parameter>\$1</parameter>" );
209 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
211 # gnome, docbook format
212 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
213 $type_func, "<function>\$1</function>",
214 $type_struct, "<structname>\$1</structname>",
215 $type_env, "<envar>\$1</envar>",
216 $type_param, "<parameter>\$1</parameter>" );
217 my $blankline_gnome = "</para><para>\n";
219 # these are pretty rough
220 my %highlights_man = ( $type_constant, "\$1",
221 $type_func, "\\\\fB\$1\\\\fP",
222 $type_struct, "\\\\fI\$1\\\\fP",
223 $type_param, "\\\\fI\$1\\\\fP" );
224 my $blankline_man = "";
227 my %highlights_text = ( $type_constant, "\$1",
230 $type_param, "\$1" );
231 my $blankline_text = "";
234 my %highlights_list = ( $type_constant, "\$1",
237 $type_param, "\$1" );
238 my $blankline_list = "";
246 my $dohighlight = "";
249 my $output_mode = "man";
250 my $output_preformatted = 0;
251 my $no_doc_sections = 0;
252 my %highlights = %highlights_man;
253 my $blankline = $blankline_man;
254 my $modulename = "Kernel API";
255 my $function_only = 0;
256 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
257 'July', 'August', 'September', 'October',
258 'November', 'December')[(localtime)[4]] .
259 " " . ((localtime)[5]+1900);
260 my $show_not_found = 0;
262 # Essentially these are globals.
263 # They probably want to be tidied up, made more localised or something.
264 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
265 # could cause "use of undefined value" or other bugs.
266 my ($function, %function_table, %parametertypes, $declaration_purpose);
267 my ($type, $declaration_name, $return_type);
268 my ($newsection, $newcontents, $prototype, $brcount, %source_map);
270 if (defined($ENV{'KBUILD_VERBOSE'})) {
271 $verbose = "$ENV{'KBUILD_VERBOSE'}";
274 # Generated docbook code is inserted in a template at a point where
275 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
276 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
277 # We keep track of number of generated entries and generate a dummy
278 # if needs be to ensure the expanded template can be postprocessed
280 my $section_counter = 0;
286 # 1 - looking for function name
287 # 2 - scanning field start.
288 # 3 - scanning prototype.
289 # 4 - documentation block
293 #declaration types: can be
294 # 'function', 'struct', 'union', 'enum', 'typedef'
297 my $doc_special = "\@\%\$\&";
299 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
301 my $doc_com = '\s*\*\s*';
302 my $doc_com_body = '\s*\* ?';
303 my $doc_decl = $doc_com . '(\w+)';
304 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
305 my $doc_content = $doc_com_body . '(.*)';
306 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
317 my $section_default = "Description"; # default section
318 my $section_intro = "Introduction";
319 my $section = $section_default;
320 my $section_context = "Context";
321 my $section_return = "Return";
323 my $undescribed = "-- undescribed --";
327 while ($ARGV[0] =~ m/^-(.*)/) {
328 my $cmd = shift @ARGV;
329 if ($cmd eq "-html") {
330 $output_mode = "html";
331 %highlights = %highlights_html;
332 $blankline = $blankline_html;
333 } elsif ($cmd eq "-html5") {
334 $output_mode = "html5";
335 %highlights = %highlights_html5;
336 $blankline = $blankline_html5;
337 } elsif ($cmd eq "-man") {
338 $output_mode = "man";
339 %highlights = %highlights_man;
340 $blankline = $blankline_man;
341 } elsif ($cmd eq "-text") {
342 $output_mode = "text";
343 %highlights = %highlights_text;
344 $blankline = $blankline_text;
345 } elsif ($cmd eq "-docbook") {
346 $output_mode = "xml";
347 %highlights = %highlights_xml;
348 $blankline = $blankline_xml;
349 } elsif ($cmd eq "-list") {
350 $output_mode = "list";
351 %highlights = %highlights_list;
352 $blankline = $blankline_list;
353 } elsif ($cmd eq "-gnome") {
354 $output_mode = "gnome";
355 %highlights = %highlights_gnome;
356 $blankline = $blankline_gnome;
357 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
358 $modulename = shift @ARGV;
359 } elsif ($cmd eq "-function") { # to only output specific functions
361 $function = shift @ARGV;
362 $function_table{$function} = 1;
363 } elsif ($cmd eq "-nofunction") { # to only output specific functions
365 $function = shift @ARGV;
366 $function_table{$function} = 1;
367 } elsif ($cmd eq "-v") {
369 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
371 } elsif ($cmd eq '-no-doc-sections') {
372 $no_doc_sections = 1;
373 } elsif ($cmd eq '-show-not-found') {
378 # continue execution near EOF;
381 print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n";
382 print " [ -no-doc-sections ]\n";
383 print " [ -function funcname [ -function funcname ...] ]\n";
384 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
386 print " c source file(s) > outputfile\n";
387 print " -v : verbose output, more warnings & other info listed\n";
391 # get kernel version from env
392 sub get_kernel_version() {
393 my $version = 'unknown kernel version';
395 if (defined($ENV{'KERNELVERSION'})) {
396 $version = $ENV{'KERNELVERSION'};
402 # dumps section contents to arrays/hashes intended for that purpose.
407 my $contents = join "\n", @_;
409 if ($name =~ m/$type_constant/) {
411 # print STDERR "constant section '$1' = '$contents'\n";
412 $constants{$name} = $contents;
413 } elsif ($name =~ m/$type_param/) {
414 # print STDERR "parameter def '$1' = '$contents'\n";
416 $parameterdescs{$name} = $contents;
417 $sectcheck = $sectcheck . $name . " ";
418 } elsif ($name eq "@\.\.\.") {
419 # print STDERR "parameter def '...' = '$contents'\n";
421 $parameterdescs{$name} = $contents;
422 $sectcheck = $sectcheck . $name . " ";
424 # print STDERR "other section '$name' = '$contents'\n";
425 if (defined($sections{$name}) && ($sections{$name} ne "")) {
426 print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
429 $sections{$name} = $contents;
430 push @sectionlist, $name;
435 # dump DOC: section after checking that it should go out
437 sub dump_doc_section {
440 my $contents = join "\n", @_;
442 if ($no_doc_sections) {
446 if (($function_only == 0) ||
447 ( $function_only == 1 && defined($function_table{$name})) ||
448 ( $function_only == 2 && !defined($function_table{$name})))
450 dump_section($file, $name, $contents);
451 output_blockhead({'sectionlist' => \@sectionlist,
452 'sections' => \%sections,
453 'module' => $modulename,
454 'content-only' => ($function_only != 0), });
461 # parameterdescs, a hash.
462 # function => "function name"
463 # parameterlist => @list of parameters
464 # parameterdescs => %parameter descriptions
465 # sectionlist => @list of sections
466 # sections => %section descriptions
469 sub output_highlight {
470 my $contents = join "\n",@_;
474 # if (!defined $contents) {
476 # confess "output_highlight got called with no args?\n";
479 if ($output_mode eq "html" || $output_mode eq "html5" ||
480 $output_mode eq "xml") {
481 $contents = local_unescape($contents);
482 # convert data read & converted thru xml_escape() into &xyz; format:
483 $contents =~ s/\\\\\\/\&/g;
485 # print STDERR "contents b4:$contents\n";
488 # print STDERR "contents af:$contents\n";
490 # strip whitespaces when generating html5
491 if ($output_mode eq "html5") {
492 $contents =~ s/^\s+//;
493 $contents =~ s/\s+$//;
495 foreach $line (split "\n", $contents) {
496 if (! $output_preformatted) {
500 if (! $output_preformatted) {
501 print $lineprefix, local_unescape($blankline);
504 $line =~ s/\\\\\\/\&/g;
505 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
508 print $lineprefix, $line;
515 # output sections in html
516 sub output_section_html(%) {
520 foreach $section (@{$args{'sectionlist'}}) {
521 print "<h3>$section</h3>\n";
522 print "<blockquote>\n";
523 output_highlight($args{'sections'}{$section});
524 print "</blockquote>\n";
528 # output enum in html
529 sub output_enum_html(%) {
533 print "<h2>enum " . $args{'enum'} . "</h2>\n";
535 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
537 foreach $parameter (@{$args{'parameterlist'}}) {
538 print " <b>" . $parameter . "</b>";
539 if ($count != $#{$args{'parameterlist'}}) {
547 print "<h3>Constants</h3>\n";
549 foreach $parameter (@{$args{'parameterlist'}}) {
550 print "<dt><b>" . $parameter . "</b>\n";
552 output_highlight($args{'parameterdescs'}{$parameter});
555 output_section_html(@_);
559 # output typedef in html
560 sub output_typedef_html(%) {
564 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
566 print "<b>typedef " . $args{'typedef'} . "</b>\n";
567 output_section_html(@_);
571 # output struct in html
572 sub output_struct_html(%) {
576 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
577 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
578 foreach $parameter (@{$args{'parameterlist'}}) {
579 if ($parameter =~ /^#/) {
580 print "$parameter<br>\n";
583 my $parameter_name = $parameter;
584 $parameter_name =~ s/\[.*//;
586 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
587 $type = $args{'parametertypes'}{$parameter};
588 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
589 # pointer-to-function
590 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
591 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
593 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
595 print " <i>$type</i> <b>$parameter</b>;<br>\n";
600 print "<h3>Members</h3>\n";
602 foreach $parameter (@{$args{'parameterlist'}}) {
603 ($parameter =~ /^#/) && next;
605 my $parameter_name = $parameter;
606 $parameter_name =~ s/\[.*//;
608 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
609 print "<dt><b>" . $parameter . "</b>\n";
611 output_highlight($args{'parameterdescs'}{$parameter_name});
614 output_section_html(@_);
618 # output function in html
619 sub output_function_html(%) {
621 my ($parameter, $section);
624 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
625 print "<i>" . $args{'functiontype'} . "</i>\n";
626 print "<b>" . $args{'function'} . "</b>\n";
629 foreach $parameter (@{$args{'parameterlist'}}) {
630 $type = $args{'parametertypes'}{$parameter};
631 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
632 # pointer-to-function
633 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
635 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
637 if ($count != $#{$args{'parameterlist'}}) {
644 print "<h3>Arguments</h3>\n";
646 foreach $parameter (@{$args{'parameterlist'}}) {
647 my $parameter_name = $parameter;
648 $parameter_name =~ s/\[.*//;
650 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
651 print "<dt><b>" . $parameter . "</b>\n";
653 output_highlight($args{'parameterdescs'}{$parameter_name});
656 output_section_html(@_);
660 # output DOC: block header in html
661 sub output_blockhead_html(%) {
663 my ($parameter, $section);
666 foreach $section (@{$args{'sectionlist'}}) {
667 print "<h3>$section</h3>\n";
669 output_highlight($args{'sections'}{$section});
675 # output sections in html5
676 sub output_section_html5(%) {
680 foreach $section (@{$args{'sectionlist'}}) {
682 print "<h1>$section</h1>\n";
684 output_highlight($args{'sections'}{$section});
686 print "</section>\n";
690 # output enum in html5
691 sub output_enum_html5(%) {
697 $html5id = $args{'enum'};
698 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
699 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
700 print "<h1>enum " . $args{'enum'} . "</h1>\n";
701 print "<ol class=\"code\">\n";
703 print "<span class=\"keyword\">enum</span> ";
704 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
707 foreach $parameter (@{$args{'parameterlist'}}) {
708 print "<li class=\"indent\">";
709 print "<span class=\"param\">" . $parameter . "</span>";
710 if ($count != $#{$args{'parameterlist'}}) {
716 print "<li>};</li>\n";
720 print "<h1>Constants</h1>\n";
722 foreach $parameter (@{$args{'parameterlist'}}) {
723 print "<dt>" . $parameter . "</dt>\n";
725 output_highlight($args{'parameterdescs'}{$parameter});
729 print "</section>\n";
730 output_section_html5(@_);
731 print "</article>\n";
734 # output typedef in html5
735 sub output_typedef_html5(%) {
741 $html5id = $args{'typedef'};
742 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
743 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
744 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
746 print "<ol class=\"code\">\n";
748 print "<span class=\"keyword\">typedef</span> ";
749 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
752 output_section_html5(@_);
753 print "</article>\n";
756 # output struct in html5
757 sub output_struct_html5(%) {
762 $html5id = $args{'struct'};
763 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
764 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
766 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
767 print "<h2>". $args{'purpose'} . "</h2>\n";
769 print "<ol class=\"code\">\n";
771 print "<span class=\"type\">" . $args{'type'} . "</span> ";
772 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
774 foreach $parameter (@{$args{'parameterlist'}}) {
775 print "<li class=\"indent\">";
776 if ($parameter =~ /^#/) {
777 print "<span class=\"param\">" . $parameter ."</span>\n";
781 my $parameter_name = $parameter;
782 $parameter_name =~ s/\[.*//;
784 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
785 $type = $args{'parametertypes'}{$parameter};
786 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
787 # pointer-to-function
788 print "<span class=\"type\">$1</span> ";
789 print "<span class=\"param\">$parameter</span>";
790 print "<span class=\"type\">)</span> ";
791 print "(<span class=\"args\">$2</span>);";
792 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
794 print "<span class=\"type\">$1</span> ";
795 print "<span class=\"param\">$parameter</span>";
796 print "<span class=\"bits\">$2</span>;";
798 print "<span class=\"type\">$type</span> ";
799 print "<span class=\"param\">$parameter</span>;";
803 print "<li>};</li>\n";
807 print "<h1>Members</h1>\n";
809 foreach $parameter (@{$args{'parameterlist'}}) {
810 ($parameter =~ /^#/) && next;
812 my $parameter_name = $parameter;
813 $parameter_name =~ s/\[.*//;
815 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
816 print "<dt>" . $parameter . "</dt>\n";
818 output_highlight($args{'parameterdescs'}{$parameter_name});
822 print "</section>\n";
823 output_section_html5(@_);
824 print "</article>\n";
827 # output function in html5
828 sub output_function_html5(%) {
830 my ($parameter, $section);
834 $html5id = $args{'function'};
835 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
836 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
838 print "<h1>" . $args{'function'} . "</h1>";
839 print "<h2>" . $args{'purpose'} . "</h2>\n";
841 print "<ol class=\"code\">\n";
843 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
844 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
847 foreach $parameter (@{$args{'parameterlist'}}) {
848 print "<li class=\"indent\">";
849 $type = $args{'parametertypes'}{$parameter};
850 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
851 # pointer-to-function
852 print "<span class=\"type\">$1</span> ";
853 print "<span class=\"param\">$parameter</span>";
854 print "<span class=\"type\">)</span> ";
855 print "(<span class=\"args\">$2</span>)";
857 print "<span class=\"type\">$type</span> ";
858 print "<span class=\"param\">$parameter</span>";
860 if ($count != $#{$args{'parameterlist'}}) {
866 print "<li>)</li>\n";
870 print "<h1>Arguments</h1>\n";
873 foreach $parameter (@{$args{'parameterlist'}}) {
874 my $parameter_name = $parameter;
875 $parameter_name =~ s/\[.*//;
877 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
878 print "<dt>" . $parameter . "</dt>\n";
880 output_highlight($args{'parameterdescs'}{$parameter_name});
884 print "</section>\n";
885 output_section_html5(@_);
886 print "</article>\n";
889 # output DOC: block header in html5
890 sub output_blockhead_html5(%) {
892 my ($parameter, $section);
896 foreach $section (@{$args{'sectionlist'}}) {
898 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
899 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
900 print "<h1>$section</h1>\n";
902 output_highlight($args{'sections'}{$section});
905 print "</article>\n";
908 sub output_section_xml(%) {
911 # print out each section
913 foreach $section (@{$args{'sectionlist'}}) {
914 print "<refsect1>\n";
915 print "<title>$section</title>\n";
916 if ($section =~ m/EXAMPLE/i) {
917 print "<informalexample><programlisting>\n";
918 $output_preformatted = 1;
922 output_highlight($args{'sections'}{$section});
923 $output_preformatted = 0;
924 if ($section =~ m/EXAMPLE/i) {
925 print "</programlisting></informalexample>\n";
929 print "</refsect1>\n";
933 # output function in XML DocBook
934 sub output_function_xml(%) {
936 my ($parameter, $section);
940 $id = "API-" . $args{'function'};
941 $id =~ s/[^A-Za-z0-9]/-/g;
943 print "<refentry id=\"$id\">\n";
944 print "<refentryinfo>\n";
945 print " <title>LINUX</title>\n";
946 print " <productname>Kernel Hackers Manual</productname>\n";
947 print " <date>$man_date</date>\n";
948 print "</refentryinfo>\n";
950 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
951 print " <manvolnum>9</manvolnum>\n";
952 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
953 print "</refmeta>\n";
954 print "<refnamediv>\n";
955 print " <refname>" . $args{'function'} . "</refname>\n";
956 print " <refpurpose>\n";
958 output_highlight ($args{'purpose'});
959 print " </refpurpose>\n";
960 print "</refnamediv>\n";
962 print "<refsynopsisdiv>\n";
963 print " <title>Synopsis</title>\n";
964 print " <funcsynopsis><funcprototype>\n";
965 print " <funcdef>" . $args{'functiontype'} . " ";
966 print "<function>" . $args{'function'} . " </function></funcdef>\n";
969 if ($#{$args{'parameterlist'}} >= 0) {
970 foreach $parameter (@{$args{'parameterlist'}}) {
971 $type = $args{'parametertypes'}{$parameter};
972 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
973 # pointer-to-function
974 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
975 print " <funcparams>$2</funcparams></paramdef>\n";
977 print " <paramdef>" . $type;
978 print " <parameter>$parameter</parameter></paramdef>\n";
984 print " </funcprototype></funcsynopsis>\n";
985 print "</refsynopsisdiv>\n";
988 print "<refsect1>\n <title>Arguments</title>\n";
989 if ($#{$args{'parameterlist'}} >= 0) {
990 print " <variablelist>\n";
991 foreach $parameter (@{$args{'parameterlist'}}) {
992 my $parameter_name = $parameter;
993 $parameter_name =~ s/\[.*//;
995 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
996 print " <listitem>\n <para>\n";
998 output_highlight($args{'parameterdescs'}{$parameter_name});
999 print " </para>\n </listitem>\n </varlistentry>\n";
1001 print " </variablelist>\n";
1003 print " <para>\n None\n </para>\n";
1005 print "</refsect1>\n";
1007 output_section_xml(@_);
1008 print "</refentry>\n\n";
1011 # output struct in XML DocBook
1012 sub output_struct_xml(%) {
1013 my %args = %{$_[0]};
1014 my ($parameter, $section);
1017 $id = "API-struct-" . $args{'struct'};
1018 $id =~ s/[^A-Za-z0-9]/-/g;
1020 print "<refentry id=\"$id\">\n";
1021 print "<refentryinfo>\n";
1022 print " <title>LINUX</title>\n";
1023 print " <productname>Kernel Hackers Manual</productname>\n";
1024 print " <date>$man_date</date>\n";
1025 print "</refentryinfo>\n";
1026 print "<refmeta>\n";
1027 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
1028 print " <manvolnum>9</manvolnum>\n";
1029 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1030 print "</refmeta>\n";
1031 print "<refnamediv>\n";
1032 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
1033 print " <refpurpose>\n";
1035 output_highlight ($args{'purpose'});
1036 print " </refpurpose>\n";
1037 print "</refnamediv>\n";
1039 print "<refsynopsisdiv>\n";
1040 print " <title>Synopsis</title>\n";
1041 print " <programlisting>\n";
1042 print $args{'type'} . " " . $args{'struct'} . " {\n";
1043 foreach $parameter (@{$args{'parameterlist'}}) {
1044 if ($parameter =~ /^#/) {
1045 my $prm = $parameter;
1046 # convert data read & converted thru xml_escape() into &xyz; format:
1047 # This allows us to have #define macros interspersed in a struct.
1048 $prm =~ s/\\\\\\/\&/g;
1053 my $parameter_name = $parameter;
1054 $parameter_name =~ s/\[.*//;
1056 defined($args{'parameterdescs'}{$parameter_name}) || next;
1057 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1058 $type = $args{'parametertypes'}{$parameter};
1059 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1060 # pointer-to-function
1061 print " $1 $parameter) ($2);\n";
1062 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1064 print " $1 $parameter$2;\n";
1066 print " " . $type . " " . $parameter . ";\n";
1070 print " </programlisting>\n";
1071 print "</refsynopsisdiv>\n";
1073 print " <refsect1>\n";
1074 print " <title>Members</title>\n";
1076 if ($#{$args{'parameterlist'}} >= 0) {
1077 print " <variablelist>\n";
1078 foreach $parameter (@{$args{'parameterlist'}}) {
1079 ($parameter =~ /^#/) && next;
1081 my $parameter_name = $parameter;
1082 $parameter_name =~ s/\[.*//;
1084 defined($args{'parameterdescs'}{$parameter_name}) || next;
1085 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1086 print " <varlistentry>";
1087 print " <term>$parameter</term>\n";
1088 print " <listitem><para>\n";
1089 output_highlight($args{'parameterdescs'}{$parameter_name});
1090 print " </para></listitem>\n";
1091 print " </varlistentry>\n";
1093 print " </variablelist>\n";
1095 print " <para>\n None\n </para>\n";
1097 print " </refsect1>\n";
1099 output_section_xml(@_);
1101 print "</refentry>\n\n";
1104 # output enum in XML DocBook
1105 sub output_enum_xml(%) {
1106 my %args = %{$_[0]};
1107 my ($parameter, $section);
1111 $id = "API-enum-" . $args{'enum'};
1112 $id =~ s/[^A-Za-z0-9]/-/g;
1114 print "<refentry id=\"$id\">\n";
1115 print "<refentryinfo>\n";
1116 print " <title>LINUX</title>\n";
1117 print " <productname>Kernel Hackers Manual</productname>\n";
1118 print " <date>$man_date</date>\n";
1119 print "</refentryinfo>\n";
1120 print "<refmeta>\n";
1121 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
1122 print " <manvolnum>9</manvolnum>\n";
1123 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1124 print "</refmeta>\n";
1125 print "<refnamediv>\n";
1126 print " <refname>enum " . $args{'enum'} . "</refname>\n";
1127 print " <refpurpose>\n";
1129 output_highlight ($args{'purpose'});
1130 print " </refpurpose>\n";
1131 print "</refnamediv>\n";
1133 print "<refsynopsisdiv>\n";
1134 print " <title>Synopsis</title>\n";
1135 print " <programlisting>\n";
1136 print "enum " . $args{'enum'} . " {\n";
1138 foreach $parameter (@{$args{'parameterlist'}}) {
1139 print " $parameter";
1140 if ($count != $#{$args{'parameterlist'}}) {
1147 print " </programlisting>\n";
1148 print "</refsynopsisdiv>\n";
1150 print "<refsect1>\n";
1151 print " <title>Constants</title>\n";
1152 print " <variablelist>\n";
1153 foreach $parameter (@{$args{'parameterlist'}}) {
1154 my $parameter_name = $parameter;
1155 $parameter_name =~ s/\[.*//;
1157 print " <varlistentry>";
1158 print " <term>$parameter</term>\n";
1159 print " <listitem><para>\n";
1160 output_highlight($args{'parameterdescs'}{$parameter_name});
1161 print " </para></listitem>\n";
1162 print " </varlistentry>\n";
1164 print " </variablelist>\n";
1165 print "</refsect1>\n";
1167 output_section_xml(@_);
1169 print "</refentry>\n\n";
1172 # output typedef in XML DocBook
1173 sub output_typedef_xml(%) {
1174 my %args = %{$_[0]};
1175 my ($parameter, $section);
1178 $id = "API-typedef-" . $args{'typedef'};
1179 $id =~ s/[^A-Za-z0-9]/-/g;
1181 print "<refentry id=\"$id\">\n";
1182 print "<refentryinfo>\n";
1183 print " <title>LINUX</title>\n";
1184 print " <productname>Kernel Hackers Manual</productname>\n";
1185 print " <date>$man_date</date>\n";
1186 print "</refentryinfo>\n";
1187 print "<refmeta>\n";
1188 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
1189 print " <manvolnum>9</manvolnum>\n";
1190 print "</refmeta>\n";
1191 print "<refnamediv>\n";
1192 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
1193 print " <refpurpose>\n";
1195 output_highlight ($args{'purpose'});
1196 print " </refpurpose>\n";
1197 print "</refnamediv>\n";
1199 print "<refsynopsisdiv>\n";
1200 print " <title>Synopsis</title>\n";
1201 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
1202 print "</refsynopsisdiv>\n";
1204 output_section_xml(@_);
1206 print "</refentry>\n\n";
1209 # output in XML DocBook
1210 sub output_blockhead_xml(%) {
1211 my %args = %{$_[0]};
1212 my ($parameter, $section);
1215 my $id = $args{'module'};
1216 $id =~ s/[^A-Za-z0-9]/-/g;
1218 # print out each section
1220 foreach $section (@{$args{'sectionlist'}}) {
1221 if (!$args{'content-only'}) {
1222 print "<refsect1>\n <title>$section</title>\n";
1224 if ($section =~ m/EXAMPLE/i) {
1225 print "<example><para>\n";
1226 $output_preformatted = 1;
1230 output_highlight($args{'sections'}{$section});
1231 $output_preformatted = 0;
1232 if ($section =~ m/EXAMPLE/i) {
1233 print "</para></example>\n";
1237 if (!$args{'content-only'}) {
1238 print "\n</refsect1>\n";
1245 # output in XML DocBook
1246 sub output_function_gnome {
1247 my %args = %{$_[0]};
1248 my ($parameter, $section);
1252 $id = $args{'module'} . "-" . $args{'function'};
1253 $id =~ s/[^A-Za-z0-9]/-/g;
1256 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
1258 print " <funcsynopsis>\n";
1259 print " <funcdef>" . $args{'functiontype'} . " ";
1260 print "<function>" . $args{'function'} . " ";
1261 print "</function></funcdef>\n";
1264 if ($#{$args{'parameterlist'}} >= 0) {
1265 foreach $parameter (@{$args{'parameterlist'}}) {
1266 $type = $args{'parametertypes'}{$parameter};
1267 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1268 # pointer-to-function
1269 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1270 print " <funcparams>$2</funcparams></paramdef>\n";
1272 print " <paramdef>" . $type;
1273 print " <parameter>$parameter</parameter></paramdef>\n";
1279 print " </funcsynopsis>\n";
1280 if ($#{$args{'parameterlist'}} >= 0) {
1281 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1282 print "<tgroup cols=\"2\">\n";
1283 print "<colspec colwidth=\"2*\">\n";
1284 print "<colspec colwidth=\"8*\">\n";
1286 foreach $parameter (@{$args{'parameterlist'}}) {
1287 my $parameter_name = $parameter;
1288 $parameter_name =~ s/\[.*//;
1290 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1293 output_highlight($args{'parameterdescs'}{$parameter_name});
1294 print " </entry></row>\n";
1296 print " </tbody></tgroup></informaltable>\n";
1298 print " <para>\n None\n </para>\n";
1301 # print out each section
1303 foreach $section (@{$args{'sectionlist'}}) {
1304 print "<simplesect>\n <title>$section</title>\n";
1305 if ($section =~ m/EXAMPLE/i) {
1306 print "<example><programlisting>\n";
1307 $output_preformatted = 1;
1311 output_highlight($args{'sections'}{$section});
1312 $output_preformatted = 0;
1314 if ($section =~ m/EXAMPLE/i) {
1315 print "</programlisting></example>\n";
1318 print " </simplesect>\n";
1321 print "</sect2>\n\n";
1325 # output function in man
1326 sub output_function_man(%) {
1327 my %args = %{$_[0]};
1328 my ($parameter, $section);
1331 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1334 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1336 print ".SH SYNOPSIS\n";
1337 if ($args{'functiontype'} ne "") {
1338 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1340 print ".B \"" . $args{'function'} . "\n";
1345 foreach my $parameter (@{$args{'parameterlist'}}) {
1346 if ($count == $#{$args{'parameterlist'}}) {
1349 $type = $args{'parametertypes'}{$parameter};
1350 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1351 # pointer-to-function
1352 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1354 $type =~ s/([^\*])$/$1 /;
1355 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1361 print ".SH ARGUMENTS\n";
1362 foreach $parameter (@{$args{'parameterlist'}}) {
1363 my $parameter_name = $parameter;
1364 $parameter_name =~ s/\[.*//;
1366 print ".IP \"" . $parameter . "\" 12\n";
1367 output_highlight($args{'parameterdescs'}{$parameter_name});
1369 foreach $section (@{$args{'sectionlist'}}) {
1370 print ".SH \"", uc $section, "\"\n";
1371 output_highlight($args{'sections'}{$section});
1376 # output enum in man
1377 sub output_enum_man(%) {
1378 my %args = %{$_[0]};
1379 my ($parameter, $section);
1382 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1385 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1387 print ".SH SYNOPSIS\n";
1388 print "enum " . $args{'enum'} . " {\n";
1390 foreach my $parameter (@{$args{'parameterlist'}}) {
1391 print ".br\n.BI \" $parameter\"\n";
1392 if ($count == $#{$args{'parameterlist'}}) {
1402 print ".SH Constants\n";
1403 foreach $parameter (@{$args{'parameterlist'}}) {
1404 my $parameter_name = $parameter;
1405 $parameter_name =~ s/\[.*//;
1407 print ".IP \"" . $parameter . "\" 12\n";
1408 output_highlight($args{'parameterdescs'}{$parameter_name});
1410 foreach $section (@{$args{'sectionlist'}}) {
1411 print ".SH \"$section\"\n";
1412 output_highlight($args{'sections'}{$section});
1417 # output struct in man
1418 sub output_struct_man(%) {
1419 my %args = %{$_[0]};
1420 my ($parameter, $section);
1422 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1425 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1427 print ".SH SYNOPSIS\n";
1428 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1430 foreach my $parameter (@{$args{'parameterlist'}}) {
1431 if ($parameter =~ /^#/) {
1432 print ".BI \"$parameter\"\n.br\n";
1435 my $parameter_name = $parameter;
1436 $parameter_name =~ s/\[.*//;
1438 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1439 $type = $args{'parametertypes'}{$parameter};
1440 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1441 # pointer-to-function
1442 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1443 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1445 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1447 $type =~ s/([^\*])$/$1 /;
1448 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1454 print ".SH Members\n";
1455 foreach $parameter (@{$args{'parameterlist'}}) {
1456 ($parameter =~ /^#/) && next;
1458 my $parameter_name = $parameter;
1459 $parameter_name =~ s/\[.*//;
1461 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1462 print ".IP \"" . $parameter . "\" 12\n";
1463 output_highlight($args{'parameterdescs'}{$parameter_name});
1465 foreach $section (@{$args{'sectionlist'}}) {
1466 print ".SH \"$section\"\n";
1467 output_highlight($args{'sections'}{$section});
1472 # output typedef in man
1473 sub output_typedef_man(%) {
1474 my %args = %{$_[0]};
1475 my ($parameter, $section);
1477 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1480 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1482 foreach $section (@{$args{'sectionlist'}}) {
1483 print ".SH \"$section\"\n";
1484 output_highlight($args{'sections'}{$section});
1488 sub output_blockhead_man(%) {
1489 my %args = %{$_[0]};
1490 my ($parameter, $section);
1493 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1495 foreach $section (@{$args{'sectionlist'}}) {
1496 print ".SH \"$section\"\n";
1497 output_highlight($args{'sections'}{$section});
1503 sub output_function_text(%) {
1504 my %args = %{$_[0]};
1505 my ($parameter, $section);
1509 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1511 print "\nSynopsis:\n\n";
1512 if ($args{'functiontype'} ne "") {
1513 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1515 $start = $args{'function'} . " (";
1520 foreach my $parameter (@{$args{'parameterlist'}}) {
1521 $type = $args{'parametertypes'}{$parameter};
1522 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1523 # pointer-to-function
1524 print $1 . $parameter . ") (" . $2;
1526 print $type . " " . $parameter;
1528 if ($count != $#{$args{'parameterlist'}}) {
1531 print " " x length($start);
1537 print "Arguments:\n\n";
1538 foreach $parameter (@{$args{'parameterlist'}}) {
1539 my $parameter_name = $parameter;
1540 $parameter_name =~ s/\[.*//;
1542 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1544 output_section_text(@_);
1547 #output sections in text
1548 sub output_section_text(%) {
1549 my %args = %{$_[0]};
1553 foreach $section (@{$args{'sectionlist'}}) {
1554 print "$section:\n\n";
1555 output_highlight($args{'sections'}{$section});
1560 # output enum in text
1561 sub output_enum_text(%) {
1562 my %args = %{$_[0]};
1567 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1568 print "enum " . $args{'enum'} . " {\n";
1570 foreach $parameter (@{$args{'parameterlist'}}) {
1571 print "\t$parameter";
1572 if ($count != $#{$args{'parameterlist'}}) {
1580 print "Constants:\n\n";
1581 foreach $parameter (@{$args{'parameterlist'}}) {
1582 print "$parameter\n\t";
1583 print $args{'parameterdescs'}{$parameter} . "\n";
1586 output_section_text(@_);
1589 # output typedef in text
1590 sub output_typedef_text(%) {
1591 my %args = %{$_[0]};
1594 print "Typedef:\n\n";
1596 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1597 output_section_text(@_);
1600 # output struct as text
1601 sub output_struct_text(%) {
1602 my %args = %{$_[0]};
1605 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1606 print $args{'type'} . " " . $args{'struct'} . " {\n";
1607 foreach $parameter (@{$args{'parameterlist'}}) {
1608 if ($parameter =~ /^#/) {
1609 print "$parameter\n";
1613 my $parameter_name = $parameter;
1614 $parameter_name =~ s/\[.*//;
1616 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1617 $type = $args{'parametertypes'}{$parameter};
1618 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1619 # pointer-to-function
1620 print "\t$1 $parameter) ($2);\n";
1621 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1623 print "\t$1 $parameter$2;\n";
1625 print "\t" . $type . " " . $parameter . ";\n";
1630 print "Members:\n\n";
1631 foreach $parameter (@{$args{'parameterlist'}}) {
1632 ($parameter =~ /^#/) && next;
1634 my $parameter_name = $parameter;
1635 $parameter_name =~ s/\[.*//;
1637 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1638 print "$parameter\n\t";
1639 print $args{'parameterdescs'}{$parameter_name} . "\n";
1642 output_section_text(@_);
1645 sub output_blockhead_text(%) {
1646 my %args = %{$_[0]};
1647 my ($parameter, $section);
1649 foreach $section (@{$args{'sectionlist'}}) {
1650 print " $section:\n";
1652 output_highlight($args{'sections'}{$section});
1656 ## list mode output functions
1658 sub output_function_list(%) {
1659 my %args = %{$_[0]};
1661 print $args{'function'} . "\n";
1664 # output enum in list
1665 sub output_enum_list(%) {
1666 my %args = %{$_[0]};
1667 print $args{'enum'} . "\n";
1670 # output typedef in list
1671 sub output_typedef_list(%) {
1672 my %args = %{$_[0]};
1673 print $args{'typedef'} . "\n";
1676 # output struct as list
1677 sub output_struct_list(%) {
1678 my %args = %{$_[0]};
1680 print $args{'struct'} . "\n";
1683 sub output_blockhead_list(%) {
1684 my %args = %{$_[0]};
1685 my ($parameter, $section);
1687 foreach $section (@{$args{'sectionlist'}}) {
1688 print "DOC: $section\n";
1693 # generic output function for all types (function, struct/union, typedef, enum);
1694 # calls the generated, variable output_ function name based on
1695 # functype and output_mode
1696 sub output_declaration {
1699 my $functype = shift;
1700 my $func = "output_${functype}_$output_mode";
1701 if (($function_only==0) ||
1702 ( $function_only == 1 && defined($function_table{$name})) ||
1703 ( $function_only == 2 && !defined($function_table{$name})))
1711 # generic output function - calls the right one based on current output mode.
1712 sub output_blockhead {
1714 my $func = "output_blockhead_" . $output_mode;
1720 # takes a declaration (struct, union, enum, typedef) and
1721 # invokes the right handler. NOT called for functions.
1722 sub dump_declaration($$) {
1724 my ($prototype, $file) = @_;
1725 my $func = "dump_" . $decl_type;
1729 sub dump_union($$) {
1733 sub dump_struct($$) {
1738 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1739 #my $decl_type = $1;
1740 $declaration_name = $2;
1743 # ignore embedded structs or unions
1744 $members =~ s/({.*})//g;
1747 # ignore members marked private:
1748 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
1749 $members =~ s/\/\*\s*private:.*//gos;
1751 $members =~ s/\/\*.*?\*\///gos;
1752 $nested =~ s/\/\*.*?\*\///gos;
1753 # strip kmemcheck_bitfield_{begin,end}.*;
1754 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1756 $members =~ s/__aligned\s*\([^;]*\)//gos;
1758 create_parameterlist($members, ';', $file);
1759 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1761 output_declaration($declaration_name,
1763 {'struct' => $declaration_name,
1764 'module' => $modulename,
1765 'parameterlist' => \@parameterlist,
1766 'parameterdescs' => \%parameterdescs,
1767 'parametertypes' => \%parametertypes,
1768 'sectionlist' => \@sectionlist,
1769 'sections' => \%sections,
1770 'purpose' => $declaration_purpose,
1771 'type' => $decl_type
1775 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1784 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1785 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1787 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1788 $declaration_name = $1;
1791 foreach my $arg (split ',', $members) {
1792 $arg =~ s/^\s*(\w+).*/$1/;
1793 push @parameterlist, $arg;
1794 if (!$parameterdescs{$arg}) {
1795 $parameterdescs{$arg} = $undescribed;
1796 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1797 "not described in enum '$declaration_name'\n";
1802 output_declaration($declaration_name,
1804 {'enum' => $declaration_name,
1805 'module' => $modulename,
1806 'parameterlist' => \@parameterlist,
1807 'parameterdescs' => \%parameterdescs,
1808 'sectionlist' => \@sectionlist,
1809 'sections' => \%sections,
1810 'purpose' => $declaration_purpose
1814 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1819 sub dump_typedef($$) {
1823 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1824 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1825 $x =~ s/\(*.\)\s*;$/;/;
1826 $x =~ s/\[*.\]\s*;$/;/;
1829 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1830 $declaration_name = $1;
1832 output_declaration($declaration_name,
1834 {'typedef' => $declaration_name,
1835 'module' => $modulename,
1836 'sectionlist' => \@sectionlist,
1837 'sections' => \%sections,
1838 'purpose' => $declaration_purpose
1842 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1847 sub save_struct_actual($) {
1850 # strip all spaces from the actual param so that it looks like one string item
1851 $actual =~ s/\s*//g;
1852 $struct_actual = $struct_actual . $actual . " ";
1855 sub create_parameterlist($$$) {
1857 my $splitter = shift;
1862 # temporarily replace commas inside function pointer definition
1863 while ($args =~ /(\([^\),]+),/) {
1864 $args =~ s/(\([^\),]+),/$1#/g;
1867 foreach my $arg (split($splitter, $args)) {
1869 $arg =~ s/\/\*.*\*\///;
1870 # strip leading/trailing spaces
1876 # Treat preprocessor directive as a typeless variable just to fill
1877 # corresponding data structures "correctly". Catch it later in
1879 push_parameter($arg, "", $file);
1880 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1881 # pointer-to-function
1883 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1886 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1887 save_struct_actual($param);
1888 push_parameter($param, $type, $file);
1890 $arg =~ s/\s*:\s*/:/g;
1891 $arg =~ s/\s*\[/\[/g;
1893 my @args = split('\s*,\s*', $arg);
1894 if ($args[0] =~ m/\*/) {
1895 $args[0] =~ s/(\*+)\s*/ $1/;
1899 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1901 push(@first_arg, split('\s+', $1));
1902 push(@first_arg, $2);
1904 @first_arg = split('\s+', shift @args);
1907 unshift(@args, pop @first_arg);
1908 $type = join " ", @first_arg;
1910 foreach $param (@args) {
1911 if ($param =~ m/^(\*+)\s*(.*)/) {
1912 save_struct_actual($2);
1913 push_parameter($2, "$type $1", $file);
1915 elsif ($param =~ m/(.*?):(\d+)/) {
1916 if ($type ne "") { # skip unnamed bit-fields
1917 save_struct_actual($1);
1918 push_parameter($1, "$type:$2", $file)
1922 save_struct_actual($param);
1923 push_parameter($param, $type, $file);
1930 sub push_parameter($$$) {
1935 if (($anon_struct_union == 1) && ($type eq "") &&
1937 return; # ignore the ending }; from anon. struct/union
1940 $anon_struct_union = 0;
1941 my $param_name = $param;
1942 $param_name =~ s/\[.*//;
1944 if ($type eq "" && $param =~ /\.\.\.$/)
1946 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1947 $parameterdescs{$param} = "variable arguments";
1950 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1953 $parameterdescs{void} = "no arguments";
1955 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1956 # handle unnamed (anonymous) union or struct:
1959 $param = "{unnamed_" . $param . "}";
1960 $parameterdescs{$param} = "anonymous\n";
1961 $anon_struct_union = 1;
1964 # warn if parameter has no description
1965 # (but ignore ones starting with # as these are not parameters
1966 # but inline preprocessor statements);
1967 # also ignore unnamed structs/unions;
1968 if (!$anon_struct_union) {
1969 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1971 $parameterdescs{$param_name} = $undescribed;
1973 if (($type eq 'function') || ($type eq 'enum')) {
1974 print STDERR "Warning(${file}:$.): Function parameter ".
1975 "or member '$param' not " .
1976 "described in '$declaration_name'\n";
1978 print STDERR "Warning(${file}:$.):" .
1979 " No description found for parameter '$param'\n";
1984 $param = xml_escape($param);
1986 # strip spaces from $param so that it is one continuous string
1987 # on @parameterlist;
1988 # this fixes a problem where check_sections() cannot find
1989 # a parameter like "addr[6 + 2]" because it actually appears
1990 # as "addr[6", "+", "2]" on the parameter list;
1991 # but it's better to maintain the param string unchanged for output,
1992 # so just weaken the string compare in check_sections() to ignore
1993 # "[blah" in a parameter string;
1994 ###$param =~ s/\s*//g;
1995 push @parameterlist, $param;
1996 $parametertypes{$param} = $type;
1999 sub check_sections($$$$$$) {
2000 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2001 my @sects = split ' ', $sectcheck;
2002 my @prms = split ' ', $prmscheck;
2005 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2007 foreach $sx (0 .. $#sects) {
2009 foreach $px (0 .. $#prms) {
2010 $prm_clean = $prms[$px];
2011 $prm_clean =~ s/\[.*\]//;
2012 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
2013 # ignore array size in a parameter string;
2014 # however, the original param string may contain
2015 # spaces, e.g.: addr[6 + 2]
2016 # and this appears in @prms as "addr[6" since the
2017 # parameter list is split at spaces;
2018 # hence just ignore "[..." for the sections check;
2019 $prm_clean =~ s/\[.*//;
2021 ##$prm_clean =~ s/^\**//;
2022 if ($prm_clean eq $sects[$sx]) {
2028 if ($decl_type eq "function") {
2029 print STDERR "Warning(${file}:$.): " .
2030 "Excess function parameter " .
2032 "description in '$decl_name'\n";
2035 if ($nested !~ m/\Q$sects[$sx]\E/) {
2036 print STDERR "Warning(${file}:$.): " .
2037 "Excess struct/union/enum/typedef member " .
2039 "description in '$decl_name'\n";
2048 # Checks the section describing the return value of a function.
2049 sub check_return_section {
2051 my $declaration_name = shift;
2052 my $return_type = shift;
2054 # Ignore an empty return type (It's a macro)
2055 # Ignore functions with a "void" return type. (But don't ignore "void *")
2056 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2060 if (!defined($sections{$section_return}) ||
2061 $sections{$section_return} eq "") {
2062 print STDERR "Warning(${file}:$.): " .
2063 "No description found for return value of " .
2064 "'$declaration_name'\n";
2070 # takes a function prototype and the name of the current file being
2071 # processed and spits out all the details stored in the global
2073 sub dump_function($$) {
2074 my $prototype = shift;
2078 $prototype =~ s/^static +//;
2079 $prototype =~ s/^extern +//;
2080 $prototype =~ s/^asmlinkage +//;
2081 $prototype =~ s/^inline +//;
2082 $prototype =~ s/^__inline__ +//;
2083 $prototype =~ s/^__inline +//;
2084 $prototype =~ s/^__always_inline +//;
2085 $prototype =~ s/^noinline +//;
2086 $prototype =~ s/__init +//;
2087 $prototype =~ s/__init_or_module +//;
2088 $prototype =~ s/__meminit +//;
2089 $prototype =~ s/__must_check +//;
2090 $prototype =~ s/__weak +//;
2091 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
2092 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
2094 # Yes, this truly is vile. We are looking for:
2095 # 1. Return type (may be nothing if we're looking at a macro)
2097 # 3. Function parameters.
2099 # All the while we have to watch out for function pointer parameters
2100 # (which IIRC is what the two sections are for), C types (these
2101 # regexps don't even start to express all the possibilities), and
2104 # If you mess with these regexps, it's a good idea to check that
2105 # the following functions' documentation still comes out right:
2106 # - parport_register_device (function pointer parameters)
2107 # - atomic_set (macro)
2108 # - pci_match_device, __copy_to_user (long return type)
2110 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2111 # This is an object-like macro, it has no return type and no parameter
2113 # Function-like macros are not allowed to have spaces between
2114 # declaration_name and opening parenthesis (notice the \s+).
2116 $declaration_name = $2;
2118 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2119 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2120 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2121 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2122 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2123 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2124 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2125 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2126 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2127 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2128 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2129 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2130 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2131 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2132 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2133 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2134 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
2136 $declaration_name = $2;
2139 create_parameterlist($args, ',', $file);
2141 print STDERR "Warning(${file}:$.): cannot understand function prototype: '$prototype'\n";
2145 my $prms = join " ", @parameterlist;
2146 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2148 # This check emits a lot of warnings at the moment, because many
2149 # functions don't have a 'Return' doc section. So until the number
2150 # of warnings goes sufficiently down, the check is only performed in
2152 # TODO: always perform the check.
2153 if ($verbose && !$noret) {
2154 check_return_section($file, $declaration_name, $return_type);
2157 output_declaration($declaration_name,
2159 {'function' => $declaration_name,
2160 'module' => $modulename,
2161 'functiontype' => $return_type,
2162 'parameterlist' => \@parameterlist,
2163 'parameterdescs' => \%parameterdescs,
2164 'parametertypes' => \%parametertypes,
2165 'sectionlist' => \@sectionlist,
2166 'sections' => \%sections,
2167 'purpose' => $declaration_purpose
2174 %parameterdescs = ();
2175 %parametertypes = ();
2176 @parameterlist = ();
2180 $struct_actual = "";
2186 sub tracepoint_munge($) {
2188 my $tracepointname = 0;
2189 my $tracepointargs = 0;
2191 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
2192 $tracepointname = $1;
2194 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2195 $tracepointname = $1;
2197 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2198 $tracepointname = $2;
2200 $tracepointname =~ s/^\s+//; #strip leading whitespace
2201 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
2202 $tracepointargs = $1;
2204 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
2205 print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
2208 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2212 sub syscall_munge() {
2215 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2216 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2217 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2219 ## $prototype = "long sys_$1(void)";
2222 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2223 if ($prototype =~ m/long (sys_.*?),/) {
2224 $prototype =~ s/,/\(/;
2226 $prototype =~ s/\)/\(void\)/;
2229 # now delete all of the odd-number commas in $prototype
2230 # so that arg types & arg names don't have a comma between them
2232 my $len = length($prototype);
2234 $len = 0; # skip the for-loop
2236 for (my $ix = 0; $ix < $len; $ix++) {
2237 if (substr($prototype, $ix, 1) eq ',') {
2239 if ($count % 2 == 1) {
2240 substr($prototype, $ix, 1) = ' ';
2246 sub process_state3_function($$) {
2250 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2252 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
2255 elsif ($x =~ /([^\{]*)/) {
2259 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
2260 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
2261 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2262 $prototype =~ s@^\s+@@gos; # strip leading spaces
2263 if ($prototype =~ /SYSCALL_DEFINE/) {
2266 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2267 $prototype =~ /DEFINE_SINGLE_EVENT/)
2269 tracepoint_munge($file);
2271 dump_function($prototype, $file);
2276 sub process_state3_type($$) {
2280 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2281 $x =~ s@^\s+@@gos; # strip leading spaces
2282 $x =~ s@\s+$@@gos; # strip trailing spaces
2283 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2286 # To distinguish preprocessor directive from regular declaration later.
2291 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
2292 $prototype .= $1 . $2;
2293 ($2 eq '{') && $brcount++;
2294 ($2 eq '}') && $brcount--;
2295 if (($2 eq ';') && ($brcount == 0)) {
2296 dump_declaration($prototype, $file);
2308 # xml_escape: replace <, >, and & in the text stream;
2310 # however, formatting controls that are generated internally/locally in the
2311 # kernel-doc script are not escaped here; instead, they begin life like
2312 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2313 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2314 # just before actual output; (this is done by local_unescape())
2317 if (($output_mode eq "text") || ($output_mode eq "man")) {
2320 $text =~ s/\&/\\\\\\amp;/g;
2321 $text =~ s/\</\\\\\\lt;/g;
2322 $text =~ s/\>/\\\\\\gt;/g;
2326 # convert local escape strings to html
2327 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2328 sub local_unescape($) {
2330 if (($output_mode eq "text") || ($output_mode eq "man")) {
2333 $text =~ s/\\\\\\\\lt:/</g;
2334 $text =~ s/\\\\\\\\gt:/>/g;
2338 sub process_file($) {
2344 my $initial_section_counter = $section_counter;
2346 if (defined($ENV{'SRCTREE'})) {
2347 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2352 if (defined($source_map{$file})) {
2353 $file = $source_map{$file};
2356 if (!open(IN,"<$file")) {
2357 print STDERR "Error: Cannot open file $file\n";
2364 $section_counter = 0;
2366 while (s/\\\s*$//) {
2370 if (/$doc_start/o) {
2371 $state = 1; # next line is always the function name
2374 } elsif ($state == 1) { # this line is the function name (always)
2375 if (/$doc_block/o) {
2379 $section = $section_intro;
2384 elsif (/$doc_decl/o) {
2386 if (/\s*([\w\s]+?)\s*-/) {
2392 # strip leading/trailing/multiple spaces
2396 $descr =~ s/\s+/ /g;
2397 $declaration_purpose = xml_escape($descr);
2400 $declaration_purpose = "";
2403 if (($declaration_purpose eq "") && $verbose) {
2404 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
2409 if ($identifier =~ m/^struct/) {
2410 $decl_type = 'struct';
2411 } elsif ($identifier =~ m/^union/) {
2412 $decl_type = 'union';
2413 } elsif ($identifier =~ m/^enum/) {
2414 $decl_type = 'enum';
2415 } elsif ($identifier =~ m/^typedef/) {
2416 $decl_type = 'typedef';
2418 $decl_type = 'function';
2422 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
2425 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
2426 " - I thought it was a doc line\n";
2430 } elsif ($state == 2) { # look for head: lines, and include content
2435 if (($contents ne "") && ($contents ne "\n")) {
2436 if (!$in_doc_sect && $verbose) {
2437 print STDERR "Warning(${file}:$.): contents before sections\n";
2440 dump_section($file, $section, xml_escape($contents));
2441 $section = $section_default;
2446 $contents = $newcontents;
2447 if ($contents ne "") {
2448 while ((substr($contents, 0, 1) eq " ") ||
2449 substr($contents, 0, 1) eq "\t") {
2450 $contents = substr($contents, 1);
2454 $section = $newsection;
2455 } elsif (/$doc_end/) {
2457 if (($contents ne "") && ($contents ne "\n")) {
2458 dump_section($file, $section, xml_escape($contents));
2459 $section = $section_default;
2462 # look for doc_com + <text> + doc_end:
2463 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2464 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
2471 # print STDERR "end of doc comment, looking for prototype\n";
2472 } elsif (/$doc_content/) {
2473 # miguel-style comment kludge, look for blank lines after
2474 # @parameter line to signify start of description
2476 if ($section =~ m/^@/ || $section eq $section_context) {
2477 dump_section($file, $section, xml_escape($contents));
2478 $section = $section_default;
2484 } elsif ($in_purpose == 1) {
2485 # Continued declaration purpose
2486 chomp($declaration_purpose);
2487 $declaration_purpose .= " " . xml_escape($1);
2488 $declaration_purpose =~ s/\s+/ /g;
2490 $contents .= $1 . "\n";
2493 # i dont know - bad line? ignore.
2494 print STDERR "Warning(${file}:$.): bad line: $_";
2497 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2498 if ($decl_type eq 'function') {
2499 process_state3_function($_, $file);
2501 process_state3_type($_, $file);
2503 } elsif ($state == 4) {
2504 # Documentation block
2506 dump_doc_section($file, $section, xml_escape($contents));
2510 %parameterdescs = ();
2511 %parametertypes = ();
2512 @parameterlist = ();
2517 $section = $section_intro;
2524 dump_doc_section($file, $section, xml_escape($contents));
2528 %parameterdescs = ();
2529 %parametertypes = ();
2530 @parameterlist = ();
2536 elsif (/$doc_content/)
2540 $contents .= $blankline;
2544 $contents .= $1 . "\n";
2549 if ($initial_section_counter == $section_counter) {
2550 print STDERR "Warning(${file}): no structured comments found\n";
2551 if (($function_only == 1) && ($show_not_found == 1)) {
2552 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2554 if ($output_mode eq "xml") {
2555 # The template wants at least one RefEntry here; make one.
2556 print "<refentry>\n";
2557 print " <refnamediv>\n";
2558 print " <refname>\n";
2560 print " </refname>\n";
2561 print " <refpurpose>\n";
2562 print " Document generation inconsistency\n";
2563 print " </refpurpose>\n";
2564 print " </refnamediv>\n";
2565 print " <refsect1>\n";
2568 print " </title>\n";
2569 print " <warning>\n";
2571 print " The template for this document tried to insert\n";
2572 print " the structured comment from the file\n";
2573 print " <filename>${file}</filename> at this point,\n";
2574 print " but none was found.\n";
2575 print " This dummy section is inserted to allow\n";
2576 print " generation to continue.\n";
2578 print " </warning>\n";
2579 print " </refsect1>\n";
2580 print "</refentry>\n";
2586 $kernelversion = get_kernel_version();
2588 # generate a sequence of code that will splice in highlighting information
2589 # using the s// operator.
2590 foreach my $pattern (keys %highlights) {
2591 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2592 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2595 # Read the file that maps relative names to absolute names for
2596 # separate source and object directories and for shadow trees.
2597 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2598 my ($relname, $absname);
2599 while(<SOURCE_MAP>) {
2601 ($relname, $absname) = (split())[0..1];
2602 $relname =~ s:^/+::;
2603 $source_map{$relname} = $absname;
2612 if ($verbose && $errors) {
2613 print STDERR "$errors errors\n";
2615 if ($verbose && $warnings) {
2616 print STDERR "$warnings warnings\n";