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 # For really longs structs, you can also describe arguments inside the
137 # body of the struct.
140 # * struct my_struct - short description
142 # * @b: second member
144 # * Longer description
150 # * @c: This is longer description of C
152 # * You can use paragraphs to describe arguments
153 # * using this method.
158 # This should be use only for struct/enum members.
160 # You can also add additional sections. When documenting kernel functions you
161 # should document the "Context:" of the function, e.g. whether the functions
162 # can be called form interrupts. Unlike other sections you can end it with an
164 # A non-void function should have a "Return:" section describing the return
166 # Example-sections should contain the string EXAMPLE so that they are marked
167 # appropriately in DocBook.
171 # * user_function - function that can only be called in user context
172 # * @a: some argument
173 # * Context: !in_interrupt()
177 # * user_function(22);
182 # All descriptive text is further processed, scanning for the following special
183 # patterns, which are highlighted appropriately.
185 # 'funcname()' - function
186 # '$ENVVAR' - environmental variable
187 # '&struct_name' - name of a structure (up to two words including 'struct')
188 # '@parameter' - name of a parameter
189 # '%CONST' - name of a constant.
195 my $anon_struct_union = 0;
197 # match expressions used to find embedded type information
198 my $type_constant = '\%([-_\w]+)';
199 my $type_func = '(\w+)\(\)';
200 my $type_param = '\@(\w+)';
201 my $type_struct = '\&((struct\s*)*[_\w]+)';
202 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
203 my $type_env = '(\$\w+)';
205 # Output conversion substitutions.
206 # One for each output format
208 # these work fairly well
209 my %highlights_html = ( $type_constant, "<i>\$1</i>",
210 $type_func, "<b>\$1</b>",
211 $type_struct_xml, "<i>\$1</i>",
212 $type_env, "<b><i>\$1</i></b>",
213 $type_param, "<tt><b>\$1</b></tt>" );
214 my $local_lt = "\\\\\\\\lt:";
215 my $local_gt = "\\\\\\\\gt:";
216 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
219 my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>",
220 $type_func, "<span class=\"func\">\$1</span>",
221 $type_struct_xml, "<span class=\"struct\">\$1</span>",
222 $type_env, "<span class=\"env\">\$1</span>",
223 $type_param, "<span class=\"param\">\$1</span>" );
224 my $blankline_html5 = $local_lt . "br /" . $local_gt;
226 # XML, docbook format
227 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
228 $type_constant, "<constant>\$1</constant>",
229 $type_func, "<function>\$1</function>",
230 $type_struct_xml, "<structname>\$1</structname>",
231 $type_env, "<envar>\$1</envar>",
232 $type_param, "<parameter>\$1</parameter>" );
233 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
235 # gnome, docbook format
236 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
237 $type_func, "<function>\$1</function>",
238 $type_struct, "<structname>\$1</structname>",
239 $type_env, "<envar>\$1</envar>",
240 $type_param, "<parameter>\$1</parameter>" );
241 my $blankline_gnome = "</para><para>\n";
243 # these are pretty rough
244 my %highlights_man = ( $type_constant, "\$1",
245 $type_func, "\\\\fB\$1\\\\fP",
246 $type_struct, "\\\\fI\$1\\\\fP",
247 $type_param, "\\\\fI\$1\\\\fP" );
248 my $blankline_man = "";
251 my %highlights_text = ( $type_constant, "\$1",
254 $type_param, "\$1" );
255 my $blankline_text = "";
258 my %highlights_list = ( $type_constant, "\$1",
261 $type_param, "\$1" );
262 my $blankline_list = "";
270 my $dohighlight = "";
273 my $output_mode = "man";
274 my $output_preformatted = 0;
275 my $no_doc_sections = 0;
276 my %highlights = %highlights_man;
277 my $blankline = $blankline_man;
278 my $modulename = "Kernel API";
279 my $function_only = 0;
280 my $show_not_found = 0;
283 if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
284 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
285 @build_time = gmtime($seconds);
287 @build_time = localtime;
290 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
291 'July', 'August', 'September', 'October',
292 'November', 'December')[$build_time[4]] .
293 " " . ($build_time[5]+1900);
295 # Essentially these are globals.
296 # They probably want to be tidied up, made more localised or something.
297 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
298 # could cause "use of undefined value" or other bugs.
299 my ($function, %function_table, %parametertypes, $declaration_purpose);
300 my ($type, $declaration_name, $return_type);
301 my ($newsection, $newcontents, $prototype, $brcount, %source_map);
303 if (defined($ENV{'KBUILD_VERBOSE'})) {
304 $verbose = "$ENV{'KBUILD_VERBOSE'}";
307 # Generated docbook code is inserted in a template at a point where
308 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
309 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
310 # We keep track of number of generated entries and generate a dummy
311 # if needs be to ensure the expanded template can be postprocessed
313 my $section_counter = 0;
319 # 1 - looking for function name
320 # 2 - scanning field start.
321 # 3 - scanning prototype.
322 # 4 - documentation block
323 # 5 - gathering documentation outside main block
328 # 0 - Invalid (Before start or after finish)
329 # 1 - Is started (the /** was found inside a struct)
330 # 2 - The @parameter header was found, start accepting multi paragraph text.
331 # 3 - Finished (the */ was found)
332 # 4 - Error - Comment without header was found. Spit a warning as it's not
333 # proper kernel-doc and ignore the rest.
336 #declaration types: can be
337 # 'function', 'struct', 'union', 'enum', 'typedef'
340 my $doc_special = "\@\%\$\&";
342 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
344 my $doc_com = '\s*\*\s*';
345 my $doc_com_body = '\s*\* ?';
346 my $doc_decl = $doc_com . '(\w+)';
347 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
348 my $doc_content = $doc_com_body . '(.*)';
349 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
350 my $doc_split_start = '^\s*/\*\*\s*$';
351 my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
352 my $doc_split_end = '^\s*\*/\s*$';
363 my $section_default = "Description"; # default section
364 my $section_intro = "Introduction";
365 my $section = $section_default;
366 my $section_context = "Context";
367 my $section_return = "Return";
369 my $undescribed = "-- undescribed --";
373 while ($ARGV[0] =~ m/^-(.*)/) {
374 my $cmd = shift @ARGV;
375 if ($cmd eq "-html") {
376 $output_mode = "html";
377 %highlights = %highlights_html;
378 $blankline = $blankline_html;
379 } elsif ($cmd eq "-html5") {
380 $output_mode = "html5";
381 %highlights = %highlights_html5;
382 $blankline = $blankline_html5;
383 } elsif ($cmd eq "-man") {
384 $output_mode = "man";
385 %highlights = %highlights_man;
386 $blankline = $blankline_man;
387 } elsif ($cmd eq "-text") {
388 $output_mode = "text";
389 %highlights = %highlights_text;
390 $blankline = $blankline_text;
391 } elsif ($cmd eq "-docbook") {
392 $output_mode = "xml";
393 %highlights = %highlights_xml;
394 $blankline = $blankline_xml;
395 } elsif ($cmd eq "-list") {
396 $output_mode = "list";
397 %highlights = %highlights_list;
398 $blankline = $blankline_list;
399 } elsif ($cmd eq "-gnome") {
400 $output_mode = "gnome";
401 %highlights = %highlights_gnome;
402 $blankline = $blankline_gnome;
403 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
404 $modulename = shift @ARGV;
405 } elsif ($cmd eq "-function") { # to only output specific functions
407 $function = shift @ARGV;
408 $function_table{$function} = 1;
409 } elsif ($cmd eq "-nofunction") { # to only output specific functions
411 $function = shift @ARGV;
412 $function_table{$function} = 1;
413 } elsif ($cmd eq "-v") {
415 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
417 } elsif ($cmd eq '-no-doc-sections') {
418 $no_doc_sections = 1;
419 } elsif ($cmd eq '-show-not-found') {
424 # continue execution near EOF;
427 print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n";
428 print " [ -no-doc-sections ]\n";
429 print " [ -function funcname [ -function funcname ...] ]\n";
430 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
432 print " c source file(s) > outputfile\n";
433 print " -v : verbose output, more warnings & other info listed\n";
437 # get kernel version from env
438 sub get_kernel_version
() {
439 my $version = 'unknown kernel version';
441 if (defined($ENV{'KERNELVERSION'})) {
442 $version = $ENV{'KERNELVERSION'};
448 # dumps section contents to arrays/hashes intended for that purpose.
453 my $contents = join "\n", @_;
455 if ($name =~ m/$type_constant/) {
457 # print STDERR "constant section '$1' = '$contents'\n";
458 $constants{$name} = $contents;
459 } elsif ($name =~ m/$type_param/) {
460 # print STDERR "parameter def '$1' = '$contents'\n";
462 $parameterdescs{$name} = $contents;
463 $sectcheck = $sectcheck . $name . " ";
464 } elsif ($name eq "@\.\.\.") {
465 # print STDERR "parameter def '...' = '$contents'\n";
467 $parameterdescs{$name} = $contents;
468 $sectcheck = $sectcheck . $name . " ";
470 # print STDERR "other section '$name' = '$contents'\n";
471 if (defined($sections{$name}) && ($sections{$name} ne "")) {
472 print STDERR
"${file}:$.: error: duplicate section name '$name'\n";
475 $sections{$name} = $contents;
476 push @sectionlist, $name;
481 # dump DOC: section after checking that it should go out
483 sub dump_doc_section
{
486 my $contents = join "\n", @_;
488 if ($no_doc_sections) {
492 if (($function_only == 0) ||
493 ( $function_only == 1 && defined($function_table{$name})) ||
494 ( $function_only == 2 && !defined($function_table{$name})))
496 dump_section
($file, $name, $contents);
497 output_blockhead
({'sectionlist' => \
@sectionlist,
498 'sections' => \
%sections,
499 'module' => $modulename,
500 'content-only' => ($function_only != 0), });
507 # parameterdescs, a hash.
508 # function => "function name"
509 # parameterlist => @list of parameters
510 # parameterdescs => %parameter descriptions
511 # sectionlist => @list of sections
512 # sections => %section descriptions
515 sub output_highlight
{
516 my $contents = join "\n",@_;
520 # if (!defined $contents) {
522 # confess "output_highlight got called with no args?\n";
525 if ($output_mode eq "html" || $output_mode eq "html5" ||
526 $output_mode eq "xml") {
527 $contents = local_unescape
($contents);
528 # convert data read & converted thru xml_escape() into &xyz; format:
529 $contents =~ s/\\\\\\/\&/g;
531 # print STDERR "contents b4:$contents\n";
534 # print STDERR "contents af:$contents\n";
536 # strip whitespaces when generating html5
537 if ($output_mode eq "html5") {
538 $contents =~ s/^\s+//;
539 $contents =~ s/\s+$//;
541 foreach $line (split "\n", $contents) {
542 if (! $output_preformatted) {
546 if (! $output_preformatted) {
547 print $lineprefix, local_unescape
($blankline);
550 $line =~ s/\\\\\\/\&/g;
551 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
554 print $lineprefix, $line;
561 # output sections in html
562 sub output_section_html
(%) {
566 foreach $section (@
{$args{'sectionlist'}}) {
567 print "<h3>$section</h3>\n";
568 print "<blockquote>\n";
569 output_highlight
($args{'sections'}{$section});
570 print "</blockquote>\n";
574 # output enum in html
575 sub output_enum_html
(%) {
579 print "<h2>enum " . $args{'enum'} . "</h2>\n";
581 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
583 foreach $parameter (@
{$args{'parameterlist'}}) {
584 print " <b>" . $parameter . "</b>";
585 if ($count != $#{$args{'parameterlist'}}) {
593 print "<h3>Constants</h3>\n";
595 foreach $parameter (@
{$args{'parameterlist'}}) {
596 print "<dt><b>" . $parameter . "</b>\n";
598 output_highlight
($args{'parameterdescs'}{$parameter});
601 output_section_html
(@_);
605 # output typedef in html
606 sub output_typedef_html
(%) {
610 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
612 print "<b>typedef " . $args{'typedef'} . "</b>\n";
613 output_section_html
(@_);
617 # output struct in html
618 sub output_struct_html
(%) {
622 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
623 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
624 foreach $parameter (@
{$args{'parameterlist'}}) {
625 if ($parameter =~ /^#/) {
626 print "$parameter<br>\n";
629 my $parameter_name = $parameter;
630 $parameter_name =~ s/\[.*//;
632 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
633 $type = $args{'parametertypes'}{$parameter};
634 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
635 # pointer-to-function
636 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
637 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
639 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
641 print " <i>$type</i> <b>$parameter</b>;<br>\n";
646 print "<h3>Members</h3>\n";
648 foreach $parameter (@
{$args{'parameterlist'}}) {
649 ($parameter =~ /^#/) && next;
651 my $parameter_name = $parameter;
652 $parameter_name =~ s/\[.*//;
654 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
655 print "<dt><b>" . $parameter . "</b>\n";
657 output_highlight
($args{'parameterdescs'}{$parameter_name});
660 output_section_html
(@_);
664 # output function in html
665 sub output_function_html
(%) {
667 my ($parameter, $section);
670 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
671 print "<i>" . $args{'functiontype'} . "</i>\n";
672 print "<b>" . $args{'function'} . "</b>\n";
675 foreach $parameter (@
{$args{'parameterlist'}}) {
676 $type = $args{'parametertypes'}{$parameter};
677 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
678 # pointer-to-function
679 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
681 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
683 if ($count != $#{$args{'parameterlist'}}) {
690 print "<h3>Arguments</h3>\n";
692 foreach $parameter (@
{$args{'parameterlist'}}) {
693 my $parameter_name = $parameter;
694 $parameter_name =~ s/\[.*//;
696 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
697 print "<dt><b>" . $parameter . "</b>\n";
699 output_highlight
($args{'parameterdescs'}{$parameter_name});
702 output_section_html
(@_);
706 # output DOC: block header in html
707 sub output_blockhead_html
(%) {
709 my ($parameter, $section);
712 foreach $section (@
{$args{'sectionlist'}}) {
713 print "<h3>$section</h3>\n";
715 output_highlight
($args{'sections'}{$section});
721 # output sections in html5
722 sub output_section_html5
(%) {
726 foreach $section (@
{$args{'sectionlist'}}) {
728 print "<h1>$section</h1>\n";
730 output_highlight
($args{'sections'}{$section});
732 print "</section>\n";
736 # output enum in html5
737 sub output_enum_html5
(%) {
743 $html5id = $args{'enum'};
744 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
745 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
746 print "<h1>enum " . $args{'enum'} . "</h1>\n";
747 print "<ol class=\"code\">\n";
749 print "<span class=\"keyword\">enum</span> ";
750 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
753 foreach $parameter (@
{$args{'parameterlist'}}) {
754 print "<li class=\"indent\">";
755 print "<span class=\"param\">" . $parameter . "</span>";
756 if ($count != $#{$args{'parameterlist'}}) {
762 print "<li>};</li>\n";
766 print "<h1>Constants</h1>\n";
768 foreach $parameter (@
{$args{'parameterlist'}}) {
769 print "<dt>" . $parameter . "</dt>\n";
771 output_highlight
($args{'parameterdescs'}{$parameter});
775 print "</section>\n";
776 output_section_html5
(@_);
777 print "</article>\n";
780 # output typedef in html5
781 sub output_typedef_html5
(%) {
787 $html5id = $args{'typedef'};
788 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
789 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
790 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
792 print "<ol class=\"code\">\n";
794 print "<span class=\"keyword\">typedef</span> ";
795 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
798 output_section_html5
(@_);
799 print "</article>\n";
802 # output struct in html5
803 sub output_struct_html5
(%) {
808 $html5id = $args{'struct'};
809 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
810 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
812 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
813 print "<h2>". $args{'purpose'} . "</h2>\n";
815 print "<ol class=\"code\">\n";
817 print "<span class=\"type\">" . $args{'type'} . "</span> ";
818 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
820 foreach $parameter (@
{$args{'parameterlist'}}) {
821 print "<li class=\"indent\">";
822 if ($parameter =~ /^#/) {
823 print "<span class=\"param\">" . $parameter ."</span>\n";
827 my $parameter_name = $parameter;
828 $parameter_name =~ s/\[.*//;
830 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
831 $type = $args{'parametertypes'}{$parameter};
832 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
833 # pointer-to-function
834 print "<span class=\"type\">$1</span> ";
835 print "<span class=\"param\">$parameter</span>";
836 print "<span class=\"type\">)</span> ";
837 print "(<span class=\"args\">$2</span>);";
838 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
840 print "<span class=\"type\">$1</span> ";
841 print "<span class=\"param\">$parameter</span>";
842 print "<span class=\"bits\">$2</span>;";
844 print "<span class=\"type\">$type</span> ";
845 print "<span class=\"param\">$parameter</span>;";
849 print "<li>};</li>\n";
853 print "<h1>Members</h1>\n";
855 foreach $parameter (@
{$args{'parameterlist'}}) {
856 ($parameter =~ /^#/) && next;
858 my $parameter_name = $parameter;
859 $parameter_name =~ s/\[.*//;
861 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
862 print "<dt>" . $parameter . "</dt>\n";
864 output_highlight
($args{'parameterdescs'}{$parameter_name});
868 print "</section>\n";
869 output_section_html5
(@_);
870 print "</article>\n";
873 # output function in html5
874 sub output_function_html5
(%) {
876 my ($parameter, $section);
880 $html5id = $args{'function'};
881 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
882 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
884 print "<h1>" . $args{'function'} . "</h1>";
885 print "<h2>" . $args{'purpose'} . "</h2>\n";
887 print "<ol class=\"code\">\n";
889 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
890 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
893 foreach $parameter (@
{$args{'parameterlist'}}) {
894 print "<li class=\"indent\">";
895 $type = $args{'parametertypes'}{$parameter};
896 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
897 # pointer-to-function
898 print "<span class=\"type\">$1</span> ";
899 print "<span class=\"param\">$parameter</span>";
900 print "<span class=\"type\">)</span> ";
901 print "(<span class=\"args\">$2</span>)";
903 print "<span class=\"type\">$type</span> ";
904 print "<span class=\"param\">$parameter</span>";
906 if ($count != $#{$args{'parameterlist'}}) {
912 print "<li>)</li>\n";
916 print "<h1>Arguments</h1>\n";
919 foreach $parameter (@
{$args{'parameterlist'}}) {
920 my $parameter_name = $parameter;
921 $parameter_name =~ s/\[.*//;
923 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
924 print "<dt>" . $parameter . "</dt>\n";
926 output_highlight
($args{'parameterdescs'}{$parameter_name});
930 print "</section>\n";
931 output_section_html5
(@_);
932 print "</article>\n";
935 # output DOC: block header in html5
936 sub output_blockhead_html5
(%) {
938 my ($parameter, $section);
942 foreach $section (@
{$args{'sectionlist'}}) {
944 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
945 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
946 print "<h1>$section</h1>\n";
948 output_highlight
($args{'sections'}{$section});
951 print "</article>\n";
954 sub output_section_xml
(%) {
957 # print out each section
959 foreach $section (@
{$args{'sectionlist'}}) {
960 print "<refsect1>\n";
961 print "<title>$section</title>\n";
962 if ($section =~ m/EXAMPLE/i) {
963 print "<informalexample><programlisting>\n";
964 $output_preformatted = 1;
968 output_highlight
($args{'sections'}{$section});
969 $output_preformatted = 0;
970 if ($section =~ m/EXAMPLE/i) {
971 print "</programlisting></informalexample>\n";
975 print "</refsect1>\n";
979 # output function in XML DocBook
980 sub output_function_xml
(%) {
982 my ($parameter, $section);
986 $id = "API-" . $args{'function'};
987 $id =~ s/[^A-Za-z0-9]/-/g;
989 print "<refentry id=\"$id\">\n";
990 print "<refentryinfo>\n";
991 print " <title>LINUX</title>\n";
992 print " <productname>Kernel Hackers Manual</productname>\n";
993 print " <date>$man_date</date>\n";
994 print "</refentryinfo>\n";
996 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
997 print " <manvolnum>9</manvolnum>\n";
998 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
999 print "</refmeta>\n";
1000 print "<refnamediv>\n";
1001 print " <refname>" . $args{'function'} . "</refname>\n";
1002 print " <refpurpose>\n";
1004 output_highlight
($args{'purpose'});
1005 print " </refpurpose>\n";
1006 print "</refnamediv>\n";
1008 print "<refsynopsisdiv>\n";
1009 print " <title>Synopsis</title>\n";
1010 print " <funcsynopsis><funcprototype>\n";
1011 print " <funcdef>" . $args{'functiontype'} . " ";
1012 print "<function>" . $args{'function'} . " </function></funcdef>\n";
1015 if ($#{$args{'parameterlist'}} >= 0) {
1016 foreach $parameter (@
{$args{'parameterlist'}}) {
1017 $type = $args{'parametertypes'}{$parameter};
1018 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1019 # pointer-to-function
1020 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1021 print " <funcparams>$2</funcparams></paramdef>\n";
1023 print " <paramdef>" . $type;
1024 print " <parameter>$parameter</parameter></paramdef>\n";
1030 print " </funcprototype></funcsynopsis>\n";
1031 print "</refsynopsisdiv>\n";
1034 print "<refsect1>\n <title>Arguments</title>\n";
1035 if ($#{$args{'parameterlist'}} >= 0) {
1036 print " <variablelist>\n";
1037 foreach $parameter (@
{$args{'parameterlist'}}) {
1038 my $parameter_name = $parameter;
1039 $parameter_name =~ s/\[.*//;
1041 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1042 print " <listitem>\n <para>\n";
1044 output_highlight
($args{'parameterdescs'}{$parameter_name});
1045 print " </para>\n </listitem>\n </varlistentry>\n";
1047 print " </variablelist>\n";
1049 print " <para>\n None\n </para>\n";
1051 print "</refsect1>\n";
1053 output_section_xml
(@_);
1054 print "</refentry>\n\n";
1057 # output struct in XML DocBook
1058 sub output_struct_xml
(%) {
1059 my %args = %{$_[0]};
1060 my ($parameter, $section);
1063 $id = "API-struct-" . $args{'struct'};
1064 $id =~ s/[^A-Za-z0-9]/-/g;
1066 print "<refentry id=\"$id\">\n";
1067 print "<refentryinfo>\n";
1068 print " <title>LINUX</title>\n";
1069 print " <productname>Kernel Hackers Manual</productname>\n";
1070 print " <date>$man_date</date>\n";
1071 print "</refentryinfo>\n";
1072 print "<refmeta>\n";
1073 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
1074 print " <manvolnum>9</manvolnum>\n";
1075 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1076 print "</refmeta>\n";
1077 print "<refnamediv>\n";
1078 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
1079 print " <refpurpose>\n";
1081 output_highlight
($args{'purpose'});
1082 print " </refpurpose>\n";
1083 print "</refnamediv>\n";
1085 print "<refsynopsisdiv>\n";
1086 print " <title>Synopsis</title>\n";
1087 print " <programlisting>\n";
1088 print $args{'type'} . " " . $args{'struct'} . " {\n";
1089 foreach $parameter (@
{$args{'parameterlist'}}) {
1090 if ($parameter =~ /^#/) {
1091 my $prm = $parameter;
1092 # convert data read & converted thru xml_escape() into &xyz; format:
1093 # This allows us to have #define macros interspersed in a struct.
1094 $prm =~ s/\\\\\\/\&/g;
1099 my $parameter_name = $parameter;
1100 $parameter_name =~ s/\[.*//;
1102 defined($args{'parameterdescs'}{$parameter_name}) || next;
1103 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1104 $type = $args{'parametertypes'}{$parameter};
1105 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1106 # pointer-to-function
1107 print " $1 $parameter) ($2);\n";
1108 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1110 print " $1 $parameter$2;\n";
1112 print " " . $type . " " . $parameter . ";\n";
1116 print " </programlisting>\n";
1117 print "</refsynopsisdiv>\n";
1119 print " <refsect1>\n";
1120 print " <title>Members</title>\n";
1122 if ($#{$args{'parameterlist'}} >= 0) {
1123 print " <variablelist>\n";
1124 foreach $parameter (@
{$args{'parameterlist'}}) {
1125 ($parameter =~ /^#/) && next;
1127 my $parameter_name = $parameter;
1128 $parameter_name =~ s/\[.*//;
1130 defined($args{'parameterdescs'}{$parameter_name}) || next;
1131 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1132 print " <varlistentry>";
1133 print " <term>$parameter</term>\n";
1134 print " <listitem><para>\n";
1135 output_highlight
($args{'parameterdescs'}{$parameter_name});
1136 print " </para></listitem>\n";
1137 print " </varlistentry>\n";
1139 print " </variablelist>\n";
1141 print " <para>\n None\n </para>\n";
1143 print " </refsect1>\n";
1145 output_section_xml
(@_);
1147 print "</refentry>\n\n";
1150 # output enum in XML DocBook
1151 sub output_enum_xml
(%) {
1152 my %args = %{$_[0]};
1153 my ($parameter, $section);
1157 $id = "API-enum-" . $args{'enum'};
1158 $id =~ s/[^A-Za-z0-9]/-/g;
1160 print "<refentry id=\"$id\">\n";
1161 print "<refentryinfo>\n";
1162 print " <title>LINUX</title>\n";
1163 print " <productname>Kernel Hackers Manual</productname>\n";
1164 print " <date>$man_date</date>\n";
1165 print "</refentryinfo>\n";
1166 print "<refmeta>\n";
1167 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
1168 print " <manvolnum>9</manvolnum>\n";
1169 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1170 print "</refmeta>\n";
1171 print "<refnamediv>\n";
1172 print " <refname>enum " . $args{'enum'} . "</refname>\n";
1173 print " <refpurpose>\n";
1175 output_highlight
($args{'purpose'});
1176 print " </refpurpose>\n";
1177 print "</refnamediv>\n";
1179 print "<refsynopsisdiv>\n";
1180 print " <title>Synopsis</title>\n";
1181 print " <programlisting>\n";
1182 print "enum " . $args{'enum'} . " {\n";
1184 foreach $parameter (@
{$args{'parameterlist'}}) {
1185 print " $parameter";
1186 if ($count != $#{$args{'parameterlist'}}) {
1193 print " </programlisting>\n";
1194 print "</refsynopsisdiv>\n";
1196 print "<refsect1>\n";
1197 print " <title>Constants</title>\n";
1198 print " <variablelist>\n";
1199 foreach $parameter (@
{$args{'parameterlist'}}) {
1200 my $parameter_name = $parameter;
1201 $parameter_name =~ s/\[.*//;
1203 print " <varlistentry>";
1204 print " <term>$parameter</term>\n";
1205 print " <listitem><para>\n";
1206 output_highlight
($args{'parameterdescs'}{$parameter_name});
1207 print " </para></listitem>\n";
1208 print " </varlistentry>\n";
1210 print " </variablelist>\n";
1211 print "</refsect1>\n";
1213 output_section_xml
(@_);
1215 print "</refentry>\n\n";
1218 # output typedef in XML DocBook
1219 sub output_typedef_xml
(%) {
1220 my %args = %{$_[0]};
1221 my ($parameter, $section);
1224 $id = "API-typedef-" . $args{'typedef'};
1225 $id =~ s/[^A-Za-z0-9]/-/g;
1227 print "<refentry id=\"$id\">\n";
1228 print "<refentryinfo>\n";
1229 print " <title>LINUX</title>\n";
1230 print " <productname>Kernel Hackers Manual</productname>\n";
1231 print " <date>$man_date</date>\n";
1232 print "</refentryinfo>\n";
1233 print "<refmeta>\n";
1234 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
1235 print " <manvolnum>9</manvolnum>\n";
1236 print "</refmeta>\n";
1237 print "<refnamediv>\n";
1238 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
1239 print " <refpurpose>\n";
1241 output_highlight
($args{'purpose'});
1242 print " </refpurpose>\n";
1243 print "</refnamediv>\n";
1245 print "<refsynopsisdiv>\n";
1246 print " <title>Synopsis</title>\n";
1247 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
1248 print "</refsynopsisdiv>\n";
1250 output_section_xml
(@_);
1252 print "</refentry>\n\n";
1255 # output in XML DocBook
1256 sub output_blockhead_xml
(%) {
1257 my %args = %{$_[0]};
1258 my ($parameter, $section);
1261 my $id = $args{'module'};
1262 $id =~ s/[^A-Za-z0-9]/-/g;
1264 # print out each section
1266 foreach $section (@
{$args{'sectionlist'}}) {
1267 if (!$args{'content-only'}) {
1268 print "<refsect1>\n <title>$section</title>\n";
1270 if ($section =~ m/EXAMPLE/i) {
1271 print "<example><para>\n";
1272 $output_preformatted = 1;
1276 output_highlight
($args{'sections'}{$section});
1277 $output_preformatted = 0;
1278 if ($section =~ m/EXAMPLE/i) {
1279 print "</para></example>\n";
1283 if (!$args{'content-only'}) {
1284 print "\n</refsect1>\n";
1291 # output in XML DocBook
1292 sub output_function_gnome
{
1293 my %args = %{$_[0]};
1294 my ($parameter, $section);
1298 $id = $args{'module'} . "-" . $args{'function'};
1299 $id =~ s/[^A-Za-z0-9]/-/g;
1302 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
1304 print " <funcsynopsis>\n";
1305 print " <funcdef>" . $args{'functiontype'} . " ";
1306 print "<function>" . $args{'function'} . " ";
1307 print "</function></funcdef>\n";
1310 if ($#{$args{'parameterlist'}} >= 0) {
1311 foreach $parameter (@
{$args{'parameterlist'}}) {
1312 $type = $args{'parametertypes'}{$parameter};
1313 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1314 # pointer-to-function
1315 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1316 print " <funcparams>$2</funcparams></paramdef>\n";
1318 print " <paramdef>" . $type;
1319 print " <parameter>$parameter</parameter></paramdef>\n";
1325 print " </funcsynopsis>\n";
1326 if ($#{$args{'parameterlist'}} >= 0) {
1327 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1328 print "<tgroup cols=\"2\">\n";
1329 print "<colspec colwidth=\"2*\">\n";
1330 print "<colspec colwidth=\"8*\">\n";
1332 foreach $parameter (@
{$args{'parameterlist'}}) {
1333 my $parameter_name = $parameter;
1334 $parameter_name =~ s/\[.*//;
1336 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1339 output_highlight
($args{'parameterdescs'}{$parameter_name});
1340 print " </entry></row>\n";
1342 print " </tbody></tgroup></informaltable>\n";
1344 print " <para>\n None\n </para>\n";
1347 # print out each section
1349 foreach $section (@
{$args{'sectionlist'}}) {
1350 print "<simplesect>\n <title>$section</title>\n";
1351 if ($section =~ m/EXAMPLE/i) {
1352 print "<example><programlisting>\n";
1353 $output_preformatted = 1;
1357 output_highlight
($args{'sections'}{$section});
1358 $output_preformatted = 0;
1360 if ($section =~ m/EXAMPLE/i) {
1361 print "</programlisting></example>\n";
1364 print " </simplesect>\n";
1367 print "</sect2>\n\n";
1371 # output function in man
1372 sub output_function_man
(%) {
1373 my %args = %{$_[0]};
1374 my ($parameter, $section);
1377 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1380 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1382 print ".SH SYNOPSIS\n";
1383 if ($args{'functiontype'} ne "") {
1384 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1386 print ".B \"" . $args{'function'} . "\n";
1391 foreach my $parameter (@
{$args{'parameterlist'}}) {
1392 if ($count == $#{$args{'parameterlist'}}) {
1395 $type = $args{'parametertypes'}{$parameter};
1396 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1397 # pointer-to-function
1398 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1400 $type =~ s/([^\*])$/$1 /;
1401 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1407 print ".SH ARGUMENTS\n";
1408 foreach $parameter (@
{$args{'parameterlist'}}) {
1409 my $parameter_name = $parameter;
1410 $parameter_name =~ s/\[.*//;
1412 print ".IP \"" . $parameter . "\" 12\n";
1413 output_highlight
($args{'parameterdescs'}{$parameter_name});
1415 foreach $section (@
{$args{'sectionlist'}}) {
1416 print ".SH \"", uc $section, "\"\n";
1417 output_highlight
($args{'sections'}{$section});
1422 # output enum in man
1423 sub output_enum_man
(%) {
1424 my %args = %{$_[0]};
1425 my ($parameter, $section);
1428 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1431 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1433 print ".SH SYNOPSIS\n";
1434 print "enum " . $args{'enum'} . " {\n";
1436 foreach my $parameter (@
{$args{'parameterlist'}}) {
1437 print ".br\n.BI \" $parameter\"\n";
1438 if ($count == $#{$args{'parameterlist'}}) {
1448 print ".SH Constants\n";
1449 foreach $parameter (@
{$args{'parameterlist'}}) {
1450 my $parameter_name = $parameter;
1451 $parameter_name =~ s/\[.*//;
1453 print ".IP \"" . $parameter . "\" 12\n";
1454 output_highlight
($args{'parameterdescs'}{$parameter_name});
1456 foreach $section (@
{$args{'sectionlist'}}) {
1457 print ".SH \"$section\"\n";
1458 output_highlight
($args{'sections'}{$section});
1463 # output struct in man
1464 sub output_struct_man
(%) {
1465 my %args = %{$_[0]};
1466 my ($parameter, $section);
1468 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1471 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1473 print ".SH SYNOPSIS\n";
1474 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1476 foreach my $parameter (@
{$args{'parameterlist'}}) {
1477 if ($parameter =~ /^#/) {
1478 print ".BI \"$parameter\"\n.br\n";
1481 my $parameter_name = $parameter;
1482 $parameter_name =~ s/\[.*//;
1484 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1485 $type = $args{'parametertypes'}{$parameter};
1486 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1487 # pointer-to-function
1488 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1489 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1491 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1493 $type =~ s/([^\*])$/$1 /;
1494 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1500 print ".SH Members\n";
1501 foreach $parameter (@
{$args{'parameterlist'}}) {
1502 ($parameter =~ /^#/) && next;
1504 my $parameter_name = $parameter;
1505 $parameter_name =~ s/\[.*//;
1507 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1508 print ".IP \"" . $parameter . "\" 12\n";
1509 output_highlight
($args{'parameterdescs'}{$parameter_name});
1511 foreach $section (@
{$args{'sectionlist'}}) {
1512 print ".SH \"$section\"\n";
1513 output_highlight
($args{'sections'}{$section});
1518 # output typedef in man
1519 sub output_typedef_man
(%) {
1520 my %args = %{$_[0]};
1521 my ($parameter, $section);
1523 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1526 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1528 foreach $section (@
{$args{'sectionlist'}}) {
1529 print ".SH \"$section\"\n";
1530 output_highlight
($args{'sections'}{$section});
1534 sub output_blockhead_man
(%) {
1535 my %args = %{$_[0]};
1536 my ($parameter, $section);
1539 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1541 foreach $section (@
{$args{'sectionlist'}}) {
1542 print ".SH \"$section\"\n";
1543 output_highlight
($args{'sections'}{$section});
1549 sub output_function_text
(%) {
1550 my %args = %{$_[0]};
1551 my ($parameter, $section);
1555 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1557 print "\nSynopsis:\n\n";
1558 if ($args{'functiontype'} ne "") {
1559 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1561 $start = $args{'function'} . " (";
1566 foreach my $parameter (@
{$args{'parameterlist'}}) {
1567 $type = $args{'parametertypes'}{$parameter};
1568 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1569 # pointer-to-function
1570 print $1 . $parameter . ") (" . $2;
1572 print $type . " " . $parameter;
1574 if ($count != $#{$args{'parameterlist'}}) {
1577 print " " x
length($start);
1583 print "Arguments:\n\n";
1584 foreach $parameter (@
{$args{'parameterlist'}}) {
1585 my $parameter_name = $parameter;
1586 $parameter_name =~ s/\[.*//;
1588 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1590 output_section_text
(@_);
1593 #output sections in text
1594 sub output_section_text
(%) {
1595 my %args = %{$_[0]};
1599 foreach $section (@
{$args{'sectionlist'}}) {
1600 print "$section:\n\n";
1601 output_highlight
($args{'sections'}{$section});
1606 # output enum in text
1607 sub output_enum_text
(%) {
1608 my %args = %{$_[0]};
1613 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1614 print "enum " . $args{'enum'} . " {\n";
1616 foreach $parameter (@
{$args{'parameterlist'}}) {
1617 print "\t$parameter";
1618 if ($count != $#{$args{'parameterlist'}}) {
1626 print "Constants:\n\n";
1627 foreach $parameter (@
{$args{'parameterlist'}}) {
1628 print "$parameter\n\t";
1629 print $args{'parameterdescs'}{$parameter} . "\n";
1632 output_section_text
(@_);
1635 # output typedef in text
1636 sub output_typedef_text
(%) {
1637 my %args = %{$_[0]};
1640 print "Typedef:\n\n";
1642 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1643 output_section_text
(@_);
1646 # output struct as text
1647 sub output_struct_text
(%) {
1648 my %args = %{$_[0]};
1651 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1652 print $args{'type'} . " " . $args{'struct'} . " {\n";
1653 foreach $parameter (@
{$args{'parameterlist'}}) {
1654 if ($parameter =~ /^#/) {
1655 print "$parameter\n";
1659 my $parameter_name = $parameter;
1660 $parameter_name =~ s/\[.*//;
1662 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1663 $type = $args{'parametertypes'}{$parameter};
1664 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1665 # pointer-to-function
1666 print "\t$1 $parameter) ($2);\n";
1667 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1669 print "\t$1 $parameter$2;\n";
1671 print "\t" . $type . " " . $parameter . ";\n";
1676 print "Members:\n\n";
1677 foreach $parameter (@
{$args{'parameterlist'}}) {
1678 ($parameter =~ /^#/) && next;
1680 my $parameter_name = $parameter;
1681 $parameter_name =~ s/\[.*//;
1683 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1684 print "$parameter\n\t";
1685 print $args{'parameterdescs'}{$parameter_name} . "\n";
1688 output_section_text
(@_);
1691 sub output_blockhead_text
(%) {
1692 my %args = %{$_[0]};
1693 my ($parameter, $section);
1695 foreach $section (@
{$args{'sectionlist'}}) {
1696 print " $section:\n";
1698 output_highlight
($args{'sections'}{$section});
1702 ## list mode output functions
1704 sub output_function_list
(%) {
1705 my %args = %{$_[0]};
1707 print $args{'function'} . "\n";
1710 # output enum in list
1711 sub output_enum_list
(%) {
1712 my %args = %{$_[0]};
1713 print $args{'enum'} . "\n";
1716 # output typedef in list
1717 sub output_typedef_list
(%) {
1718 my %args = %{$_[0]};
1719 print $args{'typedef'} . "\n";
1722 # output struct as list
1723 sub output_struct_list
(%) {
1724 my %args = %{$_[0]};
1726 print $args{'struct'} . "\n";
1729 sub output_blockhead_list
(%) {
1730 my %args = %{$_[0]};
1731 my ($parameter, $section);
1733 foreach $section (@
{$args{'sectionlist'}}) {
1734 print "DOC: $section\n";
1739 # generic output function for all types (function, struct/union, typedef, enum);
1740 # calls the generated, variable output_ function name based on
1741 # functype and output_mode
1742 sub output_declaration
{
1745 my $functype = shift;
1746 my $func = "output_${functype}_$output_mode";
1747 if (($function_only==0) ||
1748 ( $function_only == 1 && defined($function_table{$name})) ||
1749 ( $function_only == 2 && !defined($function_table{$name})))
1757 # generic output function - calls the right one based on current output mode.
1758 sub output_blockhead
{
1760 my $func = "output_blockhead_" . $output_mode;
1766 # takes a declaration (struct, union, enum, typedef) and
1767 # invokes the right handler. NOT called for functions.
1768 sub dump_declaration
($$) {
1770 my ($prototype, $file) = @_;
1771 my $func = "dump_" . $decl_type;
1775 sub dump_union
($$) {
1779 sub dump_struct
($$) {
1784 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1785 #my $decl_type = $1;
1786 $declaration_name = $2;
1789 # ignore embedded structs or unions
1790 $members =~ s/({.*})//g;
1793 # ignore members marked private:
1794 $members =~ s/\/\*\s*private:.*?\/\
*\s
*public
:.*?\
*\
///gos
;
1795 $members =~ s/\/\*\s*private:.*//gos
;
1797 $members =~ s/\/\*.*?\*\///gos;
1798 $nested =~ s/\/\*.*?\*\///gos;
1799 # strip kmemcheck_bitfield_{begin,end}.*;
1800 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1802 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1803 $members =~ s/__aligned\s*\([^;]*\)//gos;
1804 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
1806 create_parameterlist
($members, ';', $file);
1807 check_sections
($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1809 output_declaration
($declaration_name,
1811 {'struct' => $declaration_name,
1812 'module' => $modulename,
1813 'parameterlist' => \
@parameterlist,
1814 'parameterdescs' => \
%parameterdescs,
1815 'parametertypes' => \
%parametertypes,
1816 'sectionlist' => \
@sectionlist,
1817 'sections' => \
%sections,
1818 'purpose' => $declaration_purpose,
1819 'type' => $decl_type
1823 print STDERR
"${file}:$.: error: Cannot parse struct or union!\n";
1832 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1833 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1835 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1836 $declaration_name = $1;
1839 foreach my $arg (split ',', $members) {
1840 $arg =~ s/^\s*(\w+).*/$1/;
1841 push @parameterlist, $arg;
1842 if (!$parameterdescs{$arg}) {
1843 $parameterdescs{$arg} = $undescribed;
1844 print STDERR
"${file}:$.: warning: Enum value '$arg' ".
1845 "not described in enum '$declaration_name'\n";
1850 output_declaration
($declaration_name,
1852 {'enum' => $declaration_name,
1853 'module' => $modulename,
1854 'parameterlist' => \
@parameterlist,
1855 'parameterdescs' => \
%parameterdescs,
1856 'sectionlist' => \
@sectionlist,
1857 'sections' => \
%sections,
1858 'purpose' => $declaration_purpose
1862 print STDERR
"${file}:$.: error: Cannot parse enum!\n";
1867 sub dump_typedef
($$) {
1871 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1872 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1873 $x =~ s/\(*.\)\s*;$/;/;
1874 $x =~ s/\[*.\]\s*;$/;/;
1877 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1878 $declaration_name = $1;
1880 output_declaration
($declaration_name,
1882 {'typedef' => $declaration_name,
1883 'module' => $modulename,
1884 'sectionlist' => \
@sectionlist,
1885 'sections' => \
%sections,
1886 'purpose' => $declaration_purpose
1890 print STDERR
"${file}:$.: error: Cannot parse typedef!\n";
1895 sub save_struct_actual
($) {
1898 # strip all spaces from the actual param so that it looks like one string item
1899 $actual =~ s/\s*//g;
1900 $struct_actual = $struct_actual . $actual . " ";
1903 sub create_parameterlist
($$$) {
1905 my $splitter = shift;
1910 # temporarily replace commas inside function pointer definition
1911 while ($args =~ /(\([^\),]+),/) {
1912 $args =~ s/(\([^\),]+),/$1#/g;
1915 foreach my $arg (split($splitter, $args)) {
1917 $arg =~ s/\/\*.*\*\///;
1918 # strip leading/trailing spaces
1924 # Treat preprocessor directive as a typeless variable just to fill
1925 # corresponding data structures "correctly". Catch it later in
1927 push_parameter
($arg, "", $file);
1928 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1929 # pointer-to-function
1931 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1934 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1935 save_struct_actual
($param);
1936 push_parameter
($param, $type, $file);
1938 $arg =~ s/\s*:\s*/:/g;
1939 $arg =~ s/\s*\[/\[/g;
1941 my @args = split('\s*,\s*', $arg);
1942 if ($args[0] =~ m/\*/) {
1943 $args[0] =~ s/(\*+)\s*/ $1/;
1947 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1949 push(@first_arg, split('\s+', $1));
1950 push(@first_arg, $2);
1952 @first_arg = split('\s+', shift @args);
1955 unshift(@args, pop @first_arg);
1956 $type = join " ", @first_arg;
1958 foreach $param (@args) {
1959 if ($param =~ m/^(\*+)\s*(.*)/) {
1960 save_struct_actual
($2);
1961 push_parameter
($2, "$type $1", $file);
1963 elsif ($param =~ m/(.*?):(\d+)/) {
1964 if ($type ne "") { # skip unnamed bit-fields
1965 save_struct_actual
($1);
1966 push_parameter
($1, "$type:$2", $file)
1970 save_struct_actual
($param);
1971 push_parameter
($param, $type, $file);
1978 sub push_parameter
($$$) {
1983 if (($anon_struct_union == 1) && ($type eq "") &&
1985 return; # ignore the ending }; from anon. struct/union
1988 $anon_struct_union = 0;
1989 my $param_name = $param;
1990 $param_name =~ s/\[.*//;
1992 if ($type eq "" && $param =~ /\.\.\.$/)
1994 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1995 $parameterdescs{$param} = "variable arguments";
1998 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2001 $parameterdescs{void
} = "no arguments";
2003 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2004 # handle unnamed (anonymous) union or struct:
2007 $param = "{unnamed_" . $param . "}";
2008 $parameterdescs{$param} = "anonymous\n";
2009 $anon_struct_union = 1;
2012 # warn if parameter has no description
2013 # (but ignore ones starting with # as these are not parameters
2014 # but inline preprocessor statements);
2015 # also ignore unnamed structs/unions;
2016 if (!$anon_struct_union) {
2017 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2019 $parameterdescs{$param_name} = $undescribed;
2021 if (($type eq 'function') || ($type eq 'enum')) {
2022 print STDERR
"${file}:$.: warning: Function parameter ".
2023 "or member '$param' not " .
2024 "described in '$declaration_name'\n";
2026 print STDERR
"${file}:$.: warning:" .
2027 " No description found for parameter '$param'\n";
2032 $param = xml_escape
($param);
2034 # strip spaces from $param so that it is one continuous string
2035 # on @parameterlist;
2036 # this fixes a problem where check_sections() cannot find
2037 # a parameter like "addr[6 + 2]" because it actually appears
2038 # as "addr[6", "+", "2]" on the parameter list;
2039 # but it's better to maintain the param string unchanged for output,
2040 # so just weaken the string compare in check_sections() to ignore
2041 # "[blah" in a parameter string;
2042 ###$param =~ s/\s*//g;
2043 push @parameterlist, $param;
2044 $parametertypes{$param} = $type;
2047 sub check_sections
($$$$$$) {
2048 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2049 my @sects = split ' ', $sectcheck;
2050 my @prms = split ' ', $prmscheck;
2053 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2055 foreach $sx (0 .. $#sects) {
2057 foreach $px (0 .. $#prms) {
2058 $prm_clean = $prms[$px];
2059 $prm_clean =~ s/\[.*\]//;
2060 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
2061 # ignore array size in a parameter string;
2062 # however, the original param string may contain
2063 # spaces, e.g.: addr[6 + 2]
2064 # and this appears in @prms as "addr[6" since the
2065 # parameter list is split at spaces;
2066 # hence just ignore "[..." for the sections check;
2067 $prm_clean =~ s/\[.*//;
2069 ##$prm_clean =~ s/^\**//;
2070 if ($prm_clean eq $sects[$sx]) {
2076 if ($decl_type eq "function") {
2077 print STDERR
"${file}:$.: warning: " .
2078 "Excess function parameter " .
2080 "description in '$decl_name'\n";
2083 if ($nested !~ m/\Q$sects[$sx]\E/) {
2084 print STDERR
"${file}:$.: warning: " .
2085 "Excess struct/union/enum/typedef member " .
2087 "description in '$decl_name'\n";
2096 # Checks the section describing the return value of a function.
2097 sub check_return_section
{
2099 my $declaration_name = shift;
2100 my $return_type = shift;
2102 # Ignore an empty return type (It's a macro)
2103 # Ignore functions with a "void" return type. (But don't ignore "void *")
2104 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2108 if (!defined($sections{$section_return}) ||
2109 $sections{$section_return} eq "") {
2110 print STDERR
"${file}:$.: warning: " .
2111 "No description found for return value of " .
2112 "'$declaration_name'\n";
2118 # takes a function prototype and the name of the current file being
2119 # processed and spits out all the details stored in the global
2121 sub dump_function
($$) {
2122 my $prototype = shift;
2126 $prototype =~ s/^static +//;
2127 $prototype =~ s/^extern +//;
2128 $prototype =~ s/^asmlinkage +//;
2129 $prototype =~ s/^inline +//;
2130 $prototype =~ s/^__inline__ +//;
2131 $prototype =~ s/^__inline +//;
2132 $prototype =~ s/^__always_inline +//;
2133 $prototype =~ s/^noinline +//;
2134 $prototype =~ s/__init +//;
2135 $prototype =~ s/__init_or_module +//;
2136 $prototype =~ s/__meminit +//;
2137 $prototype =~ s/__must_check +//;
2138 $prototype =~ s/__weak +//;
2139 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
2140 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
2142 # Yes, this truly is vile. We are looking for:
2143 # 1. Return type (may be nothing if we're looking at a macro)
2145 # 3. Function parameters.
2147 # All the while we have to watch out for function pointer parameters
2148 # (which IIRC is what the two sections are for), C types (these
2149 # regexps don't even start to express all the possibilities), and
2152 # If you mess with these regexps, it's a good idea to check that
2153 # the following functions' documentation still comes out right:
2154 # - parport_register_device (function pointer parameters)
2155 # - atomic_set (macro)
2156 # - pci_match_device, __copy_to_user (long return type)
2158 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2159 # This is an object-like macro, it has no return type and no parameter
2161 # Function-like macros are not allowed to have spaces between
2162 # declaration_name and opening parenthesis (notice the \s+).
2164 $declaration_name = $2;
2166 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2167 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2168 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2169 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2170 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2171 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2172 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2173 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2174 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2175 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2176 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2177 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2178 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2179 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2180 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2181 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2182 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
2184 $declaration_name = $2;
2187 create_parameterlist
($args, ',', $file);
2189 print STDERR
"${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
2193 my $prms = join " ", @parameterlist;
2194 check_sections
($file, $declaration_name, "function", $sectcheck, $prms, "");
2196 # This check emits a lot of warnings at the moment, because many
2197 # functions don't have a 'Return' doc section. So until the number
2198 # of warnings goes sufficiently down, the check is only performed in
2200 # TODO: always perform the check.
2201 if ($verbose && !$noret) {
2202 check_return_section
($file, $declaration_name, $return_type);
2205 output_declaration
($declaration_name,
2207 {'function' => $declaration_name,
2208 'module' => $modulename,
2209 'functiontype' => $return_type,
2210 'parameterlist' => \
@parameterlist,
2211 'parameterdescs' => \
%parameterdescs,
2212 'parametertypes' => \
%parametertypes,
2213 'sectionlist' => \
@sectionlist,
2214 'sections' => \
%sections,
2215 'purpose' => $declaration_purpose
2222 %parameterdescs = ();
2223 %parametertypes = ();
2224 @parameterlist = ();
2228 $struct_actual = "";
2232 $split_doc_state = 0;
2235 sub tracepoint_munge
($) {
2237 my $tracepointname = 0;
2238 my $tracepointargs = 0;
2240 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
2241 $tracepointname = $1;
2243 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2244 $tracepointname = $1;
2246 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2247 $tracepointname = $2;
2249 $tracepointname =~ s/^\s+//; #strip leading whitespace
2250 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
2251 $tracepointargs = $1;
2253 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
2254 print STDERR
"${file}:$.: warning: Unrecognized tracepoint format: \n".
2257 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2261 sub syscall_munge
() {
2264 $prototype =~ s@
[\r\n\t]+@
@gos; # strip newlines/CR's/tabs
2265 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2266 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2268 ## $prototype = "long sys_$1(void)";
2271 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2272 if ($prototype =~ m/long (sys_.*?),/) {
2273 $prototype =~ s/,/\(/;
2275 $prototype =~ s/\)/\(void\)/;
2278 # now delete all of the odd-number commas in $prototype
2279 # so that arg types & arg names don't have a comma between them
2281 my $len = length($prototype);
2283 $len = 0; # skip the for-loop
2285 for (my $ix = 0; $ix < $len; $ix++) {
2286 if (substr($prototype, $ix, 1) eq ',') {
2288 if ($count % 2 == 1) {
2289 substr($prototype, $ix, 1) = ' ';
2295 sub process_state3_function
($$) {
2299 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
2301 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
2304 elsif ($x =~ /([^\{]*)/) {
2308 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
2309 $prototype =~ s@
/\*.*?\*/@
@gos; # strip comments.
2310 $prototype =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
2311 $prototype =~ s@
^\s
+@
@gos; # strip leading spaces
2312 if ($prototype =~ /SYSCALL_DEFINE/) {
2315 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2316 $prototype =~ /DEFINE_SINGLE_EVENT/)
2318 tracepoint_munge
($file);
2320 dump_function
($prototype, $file);
2325 sub process_state3_type
($$) {
2329 $x =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
2330 $x =~ s@
^\s
+@
@gos; # strip leading spaces
2331 $x =~ s@\s
+$@
@gos; # strip trailing spaces
2332 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
2335 # To distinguish preprocessor directive from regular declaration later.
2340 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
2341 $prototype .= $1 . $2;
2342 ($2 eq '{') && $brcount++;
2343 ($2 eq '}') && $brcount--;
2344 if (($2 eq ';') && ($brcount == 0)) {
2345 dump_declaration
($prototype, $file);
2357 # xml_escape: replace <, >, and & in the text stream;
2359 # however, formatting controls that are generated internally/locally in the
2360 # kernel-doc script are not escaped here; instead, they begin life like
2361 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2362 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2363 # just before actual output; (this is done by local_unescape())
2366 if (($output_mode eq "text") || ($output_mode eq "man")) {
2369 $text =~ s/\&/\\\\\\amp;/g;
2370 $text =~ s/\</\\\\\\lt;/g;
2371 $text =~ s/\>/\\\\\\gt;/g;
2375 # convert local escape strings to html
2376 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2377 sub local_unescape
($) {
2379 if (($output_mode eq "text") || ($output_mode eq "man")) {
2382 $text =~ s/\\\\\\\\lt:/</g;
2383 $text =~ s/\\\\\\\\gt:/>/g;
2387 sub process_file
($) {
2393 my $initial_section_counter = $section_counter;
2395 if (defined($ENV{'SRCTREE'})) {
2396 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2401 if (defined($source_map{$file})) {
2402 $file = $source_map{$file};
2405 if (!open(IN
,"<$file")) {
2406 print STDERR
"Error: Cannot open file $file\n";
2413 $section_counter = 0;
2415 while (s/\\\s*$//) {
2419 if (/$doc_start/o) {
2420 $state = 1; # next line is always the function name
2423 } elsif ($state == 1) { # this line is the function name (always)
2424 if (/$doc_block/o) {
2428 $section = $section_intro;
2433 elsif (/$doc_decl/o) {
2435 if (/\s*([\w\s]+?)\s*-/) {
2441 # strip leading/trailing/multiple spaces
2445 $descr =~ s/\s+/ /g;
2446 $declaration_purpose = xml_escape
($descr);
2449 $declaration_purpose = "";
2452 if (($declaration_purpose eq "") && $verbose) {
2453 print STDERR
"${file}:$.: warning: missing initial short description on line:\n";
2458 if ($identifier =~ m/^struct/) {
2459 $decl_type = 'struct';
2460 } elsif ($identifier =~ m/^union/) {
2461 $decl_type = 'union';
2462 } elsif ($identifier =~ m/^enum/) {
2463 $decl_type = 'enum';
2464 } elsif ($identifier =~ m/^typedef/) {
2465 $decl_type = 'typedef';
2467 $decl_type = 'function';
2471 print STDERR
"${file}:$.: info: Scanning doc for $identifier\n";
2474 print STDERR
"${file}:$.: warning: Cannot understand $_ on line $.",
2475 " - I thought it was a doc line\n";
2479 } elsif ($state == 2) { # look for head: lines, and include content
2484 if (($contents ne "") && ($contents ne "\n")) {
2485 if (!$in_doc_sect && $verbose) {
2486 print STDERR
"${file}:$.: warning: contents before sections\n";
2489 dump_section
($file, $section, xml_escape
($contents));
2490 $section = $section_default;
2495 $contents = $newcontents;
2496 if ($contents ne "") {
2497 while ((substr($contents, 0, 1) eq " ") ||
2498 substr($contents, 0, 1) eq "\t") {
2499 $contents = substr($contents, 1);
2503 $section = $newsection;
2504 } elsif (/$doc_end/) {
2505 if (($contents ne "") && ($contents ne "\n")) {
2506 dump_section
($file, $section, xml_escape
($contents));
2507 $section = $section_default;
2510 # look for doc_com + <text> + doc_end:
2511 if ($_ =~ m
'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2512 print STDERR
"${file}:$.: warning: suspicious ending line: $_";
2519 # print STDERR "end of doc comment, looking for prototype\n";
2520 } elsif (/$doc_content/) {
2521 # miguel-style comment kludge, look for blank lines after
2522 # @parameter line to signify start of description
2524 if ($section =~ m/^@/ || $section eq $section_context) {
2525 dump_section
($file, $section, xml_escape
($contents));
2526 $section = $section_default;
2532 } elsif ($in_purpose == 1) {
2533 # Continued declaration purpose
2534 chomp($declaration_purpose);
2535 $declaration_purpose .= " " . xml_escape
($1);
2536 $declaration_purpose =~ s/\s+/ /g;
2538 $contents .= $1 . "\n";
2541 # i dont know - bad line? ignore.
2542 print STDERR
"${file}:$.: warning: bad line: $_";
2545 } elsif ($state == 5) { # scanning for split parameters
2546 # First line (state 1) needs to be a @parameter
2547 if ($split_doc_state == 1 && /$doc_split_sect/o) {
2550 if ($contents ne "") {
2551 while ((substr($contents, 0, 1) eq " ") ||
2552 substr($contents, 0, 1) eq "\t") {
2553 $contents = substr($contents, 1);
2557 $split_doc_state = 2;
2558 # Documentation block end */
2559 } elsif (/$doc_split_end/) {
2560 if (($contents ne "") && ($contents ne "\n")) {
2561 dump_section
($file, $section, xml_escape
($contents));
2562 $section = $section_default;
2566 $split_doc_state = 0;
2568 } elsif (/$doc_content/) {
2569 if ($split_doc_state == 2) {
2570 $contents .= $1 . "\n";
2571 } elsif ($split_doc_state == 1) {
2572 $split_doc_state = 4;
2573 print STDERR
"Warning(${file}:$.): ";
2574 print STDERR
"Incorrect use of kernel-doc format: $_";
2578 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2579 if (/$doc_split_start/) {
2581 $split_doc_state = 1;
2582 } elsif ($decl_type eq 'function') {
2583 process_state3_function
($_, $file);
2585 process_state3_type
($_, $file);
2587 } elsif ($state == 4) {
2588 # Documentation block
2590 dump_doc_section
($file, $section, xml_escape
($contents));
2594 %parameterdescs = ();
2595 %parametertypes = ();
2596 @parameterlist = ();
2601 $section = $section_intro;
2608 dump_doc_section
($file, $section, xml_escape
($contents));
2612 %parameterdescs = ();
2613 %parametertypes = ();
2614 @parameterlist = ();
2620 elsif (/$doc_content/)
2624 $contents .= $blankline;
2628 $contents .= $1 . "\n";
2633 if ($initial_section_counter == $section_counter) {
2634 print STDERR
"${file}:1: warning: no structured comments found\n";
2635 if (($function_only == 1) && ($show_not_found == 1)) {
2636 print STDERR
" Was looking for '$_'.\n" for keys %function_table;
2638 if ($output_mode eq "xml") {
2639 # The template wants at least one RefEntry here; make one.
2640 print "<refentry>\n";
2641 print " <refnamediv>\n";
2642 print " <refname>\n";
2644 print " </refname>\n";
2645 print " <refpurpose>\n";
2646 print " Document generation inconsistency\n";
2647 print " </refpurpose>\n";
2648 print " </refnamediv>\n";
2649 print " <refsect1>\n";
2652 print " </title>\n";
2653 print " <warning>\n";
2655 print " The template for this document tried to insert\n";
2656 print " the structured comment from the file\n";
2657 print " <filename>${file}</filename> at this point,\n";
2658 print " but none was found.\n";
2659 print " This dummy section is inserted to allow\n";
2660 print " generation to continue.\n";
2662 print " </warning>\n";
2663 print " </refsect1>\n";
2664 print "</refentry>\n";
2670 $kernelversion = get_kernel_version
();
2672 # generate a sequence of code that will splice in highlighting information
2673 # using the s// operator.
2674 foreach my $pattern (sort keys %highlights) {
2675 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2676 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2679 # Read the file that maps relative names to absolute names for
2680 # separate source and object directories and for shadow trees.
2681 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
2682 my ($relname, $absname);
2683 while(<SOURCE_MAP
>) {
2685 ($relname, $absname) = (split())[0..1];
2686 $relname =~ s
:^/+::;
2687 $source_map{$relname} = $absname;
2696 if ($verbose && $errors) {
2697 print STDERR
"$errors errors\n";
2699 if ($verbose && $warnings) {
2700 print STDERR
"$warnings warnings\n";