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-2007 Randy Dunlap ##
10 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11 ## Copyright (c) 2000 MontaVista Software, Inc. ##
13 ## This software falls under the GNU General Public License. ##
14 ## Please read the COPYING file for more information ##
16 # w.o. 03-11-2000: added the '-filelist' option.
18 # 18/01/2001 - Cleanups
19 # Functions prototyped as foo(void) same as foo()
20 # Stop eval'ing where we don't need to.
23 # 27/06/2001 - Allowed whitespace after initial "/**" and
24 # allowed comments before function declarations.
25 # -- Christian Kreibich <ck@whoop.org>
28 # - add perldoc documentation
29 # - Look more closely at some of the scarier bits :)
31 # 26/05/2001 - Support for separate source and object trees.
33 # Keith Owens <kaos@ocs.com.au>
35 # 23/09/2001 - Added support for typedefs, structs, enums and unions
36 # Support for Context section; can be terminated using empty line
37 # Small fixes (like spaces vs. \s in regex)
38 # -- Tim Jansen <tim@tjansen.de>
42 # This will read a 'c' file and scan for embedded comments in the
43 # style of gnome comments (+minor extensions - see below).
46 # Note: This only supports 'c'.
49 # kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ]
50 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
52 # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
54 # Set output format using one of -docbook -html -text or -man. Default is man.
57 # Do not output DOC: sections
60 # If set, then only generate documentation for the given function(s) or
61 # DOC: section titles. All other functions and DOC: sections are ignored.
63 # -nofunction funcname
64 # If set, then only generate documentation for the other function(s)/DOC:
65 # sections. Cannot be used together with -function (yes, that's a bug --
66 # perl hackers can fix it 8))
68 # c files - list of 'c' files to process
70 # All output goes to stdout, with errors to stderr.
74 # In the following table, (...)? signifies optional structure.
75 # (...)* signifies 0 or more structure elements
77 # * function_name(:)? (- short description)?
78 # (* @parameterx: (description of parameter x)?)*
80 # * (Description:)? (Description of function)?
81 # * (section header: (section description)? )*
84 # So .. the trivial example would be:
90 # If the Description: header tag is omitted, then there must be a blank line
91 # after the last parameter specification.
94 # * my_function - does my stuff
95 # * @my_arg: its mine damnit
97 # * Does my stuff explained.
100 # or, could also use:
102 # * my_function - does my stuff
103 # * @my_arg: its mine damnit
104 # * Description: Does my stuff explained.
108 # Beside functions you can also write documentation for structs, unions,
109 # enums and typedefs. Instead of the function name you must write the name
110 # of the declaration; the struct/union/enum/typedef must always precede
111 # the name. Nesting of declarations is not supported.
112 # Use the argument mechanism to document members or constants.
115 # * struct my_struct - short description
117 # * @b: second member
119 # * Longer description
128 # All descriptions can be multiline, except the short function description.
130 # You can also add additional sections. When documenting kernel functions you
131 # should document the "Context:" of the function, e.g. whether the functions
132 # can be called form interrupts. Unlike other sections you can end it with an
134 # Example-sections should contain the string EXAMPLE so that they are marked
135 # appropriately in DocBook.
139 # * user_function - function that can only be called in user context
140 # * @a: some argument
141 # * Context: !in_interrupt()
145 # * user_function(22);
150 # All descriptive text is further processed, scanning for the following special
151 # patterns, which are highlighted appropriately.
153 # 'funcname()' - function
154 # '$ENVVAR' - environmental variable
155 # '&struct_name' - name of a structure (up to two words including 'struct')
156 # '@parameter' - name of a parameter
157 # '%CONST' - name of a constant.
161 my $anon_struct_union = 0;
163 # match expressions used to find embedded type information
164 my $type_constant = '\%([-_\w]+)';
165 my $type_func = '(\w+)\(\)';
166 my $type_param = '\@(\w+)';
167 my $type_struct = '\&((struct\s*)*[_\w]+)';
168 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
169 my $type_env = '(\$\w+)';
171 # Output conversion substitutions.
172 # One for each output format
174 # these work fairly well
175 my %highlights_html = ( $type_constant, "<i>\$1</i>",
176 $type_func, "<b>\$1</b>",
177 $type_struct_xml, "<i>\$1</i>",
178 $type_env, "<b><i>\$1</i></b>",
179 $type_param, "<tt><b>\$1</b></tt>" );
180 my $local_lt = "\\\\\\\\lt:";
181 my $local_gt = "\\\\\\\\gt:";
182 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
184 # XML, docbook format
185 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
186 $type_constant, "<constant>\$1</constant>",
187 $type_func, "<function>\$1</function>",
188 $type_struct_xml, "<structname>\$1</structname>",
189 $type_env, "<envar>\$1</envar>",
190 $type_param, "<parameter>\$1</parameter>" );
191 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
193 # gnome, docbook format
194 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
195 $type_func, "<function>\$1</function>",
196 $type_struct, "<structname>\$1</structname>",
197 $type_env, "<envar>\$1</envar>",
198 $type_param, "<parameter>\$1</parameter>" );
199 my $blankline_gnome = "</para><para>\n";
201 # these are pretty rough
202 my %highlights_man = ( $type_constant, "\$1",
203 $type_func, "\\\\fB\$1\\\\fP",
204 $type_struct, "\\\\fI\$1\\\\fP",
205 $type_param, "\\\\fI\$1\\\\fP" );
206 my $blankline_man = "";
209 my %highlights_text = ( $type_constant, "\$1",
212 $type_param, "\$1" );
213 my $blankline_text = "";
217 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n";
218 print " [ -function funcname [ -function funcname ...] ]\n";
219 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
220 print " c source file(s) > outputfile\n";
221 print " -v : verbose output, more warnings & other info listed\n";
231 my $output_mode = "man";
232 my $no_doc_sections = 0;
233 my %highlights = %highlights_man;
234 my $blankline = $blankline_man;
235 my $modulename = "Kernel API";
236 my $function_only = 0;
237 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
238 'July', 'August', 'September', 'October',
239 'November', 'December')[(localtime)[4]] .
240 " " . ((localtime)[5]+1900);
242 # Essentially these are globals
243 # They probably want to be tidied up made more localised or summat.
244 # CAVEAT EMPTOR! Some of the others I localised may not want to be which
245 # could cause "use of undefined value" or other bugs.
246 my ($function, %function_table,%parametertypes,$declaration_purpose);
247 my ($type,$declaration_name,$return_type);
248 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
250 <<<<<<< HEAD
:scripts
/kernel
-doc
252 if (defined($ENV{'KBUILD_VERBOSE'})) {
253 $verbose = "$ENV{'KBUILD_VERBOSE'}";
256 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/kernel
-doc
257 # Generated docbook code is inserted in a template at a point where
258 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
259 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
260 # We keep track of number of generated entries and generate a dummy
261 # if needs be to ensure the expanded template can be postprocessed
263 my $section_counter = 0;
269 # 1 - looking for function name
270 # 2 - scanning field start.
271 # 3 - scanning prototype.
272 # 4 - documentation block
276 #declaration types: can be
277 # 'function', 'struct', 'union', 'enum', 'typedef'
280 my $doc_special = "\@\%\$\&";
282 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
284 my $doc_com = '\s*\*\s*';
285 my $doc_decl = $doc_com.'(\w+)';
286 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)';
287 my $doc_content = $doc_com.'(.*)';
288 my $doc_block = $doc_com.'DOC:\s*(.*)?';
297 my $section_default = "Description"; # default section
298 my $section_intro = "Introduction";
299 my $section = $section_default;
300 my $section_context = "Context";
302 my $undescribed = "-- undescribed --";
306 while ($ARGV[0] =~ m/^-(.*)/) {
307 my $cmd = shift @ARGV;
308 if ($cmd eq "-html") {
309 $output_mode = "html";
310 %highlights = %highlights_html;
311 $blankline = $blankline_html;
312 } elsif ($cmd eq "-man") {
313 $output_mode = "man";
314 %highlights = %highlights_man;
315 $blankline = $blankline_man;
316 } elsif ($cmd eq "-text") {
317 $output_mode = "text";
318 %highlights = %highlights_text;
319 $blankline = $blankline_text;
320 } elsif ($cmd eq "-docbook") {
321 $output_mode = "xml";
322 %highlights = %highlights_xml;
323 $blankline = $blankline_xml;
324 } elsif ($cmd eq "-gnome") {
325 $output_mode = "gnome";
326 %highlights = %highlights_gnome;
327 $blankline = $blankline_gnome;
328 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
329 $modulename = shift @ARGV;
330 } elsif ($cmd eq "-function") { # to only output specific functions
332 $function = shift @ARGV;
333 $function_table{$function} = 1;
334 } elsif ($cmd eq "-nofunction") { # to only output specific functions
336 $function = shift @ARGV;
337 $function_table{$function} = 1;
338 } elsif ($cmd eq "-v") {
340 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
342 } elsif ($cmd eq '-filelist') {
343 $filelist = shift @ARGV;
344 } elsif ($cmd eq '-no-doc-sections') {
345 $no_doc_sections = 1;
349 # get kernel version from env
350 sub get_kernel_version
() {
351 my $version = 'unknown kernel version';
353 if (defined($ENV{'KERNELVERSION'})) {
354 $version = $ENV{'KERNELVERSION'};
358 my $kernelversion = get_kernel_version
();
360 # generate a sequence of code that will splice in highlighting information
361 # using the s// operator.
362 my $dohighlight = "";
363 foreach my $pattern (keys %highlights) {
364 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
365 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
369 # dumps section contents to arrays/hashes intended for that purpose.
373 my $contents = join "\n", @_;
375 if ($name =~ m/$type_constant/) {
377 # print STDERR "constant section '$1' = '$contents'\n";
378 $constants{$name} = $contents;
379 } elsif ($name =~ m/$type_param/) {
380 # print STDERR "parameter def '$1' = '$contents'\n";
382 $parameterdescs{$name} = $contents;
384 # print STDERR "other section '$name' = '$contents'\n";
385 $sections{$name} = $contents;
386 push @sectionlist, $name;
391 # dump DOC: section after checking that it should go out
393 sub dump_doc_section
{
395 my $contents = join "\n", @_;
397 if ($no_doc_sections) {
401 if (($function_only == 0) ||
402 ( $function_only == 1 && defined($function_table{$name})) ||
403 ( $function_only == 2 && !defined($function_table{$name})))
405 dump_section
$name, $contents;
406 output_blockhead
({'sectionlist' => \
@sectionlist,
407 'sections' => \
%sections,
408 'module' => $modulename,
409 'content-only' => ($function_only != 0), });
416 # parameterdescs, a hash.
417 # function => "function name"
418 # parameterlist => @list of parameters
419 # parameterdescs => %parameter descriptions
420 # sectionlist => @list of sections
421 # sections => %section descriptions
424 sub output_highlight
{
425 my $contents = join "\n",@_;
429 # if (!defined $contents) {
431 # confess "output_highlight got called with no args?\n";
434 if ($output_mode eq "html" || $output_mode eq "xml") {
435 $contents = local_unescape
($contents);
436 # convert data read & converted thru xml_escape() into &xyz; format:
437 $contents =~ s/\\\\\\/&/g;
439 # print STDERR "contents b4:$contents\n";
442 # print STDERR "contents af:$contents\n";
444 foreach $line (split "\n", $contents) {
446 print $lineprefix, local_unescape
($blankline);
448 $line =~ s/\\\\\\/\&/g;
449 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
452 print $lineprefix, $line;
459 #output sections in html
460 sub output_section_html
(%) {
464 foreach $section (@
{$args{'sectionlist'}}) {
465 print "<h3>$section</h3>\n";
466 print "<blockquote>\n";
467 output_highlight
($args{'sections'}{$section});
468 print "</blockquote>\n";
472 # output enum in html
473 sub output_enum_html
(%) {
477 print "<h2>enum ".$args{'enum'}."</h2>\n";
479 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
481 foreach $parameter (@
{$args{'parameterlist'}}) {
482 print " <b>".$parameter."</b>";
483 if ($count != $#{$args{'parameterlist'}}) {
491 print "<h3>Constants</h3>\n";
493 foreach $parameter (@
{$args{'parameterlist'}}) {
494 print "<dt><b>".$parameter."</b>\n";
496 output_highlight
($args{'parameterdescs'}{$parameter});
499 output_section_html
(@_);
503 # output typedef in html
504 sub output_typedef_html
(%) {
508 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
510 print "<b>typedef ".$args{'typedef'}."</b>\n";
511 output_section_html
(@_);
515 # output struct in html
516 sub output_struct_html
(%) {
520 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
521 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
522 foreach $parameter (@
{$args{'parameterlist'}}) {
523 if ($parameter =~ /^#/) {
524 print "$parameter<br>\n";
527 my $parameter_name = $parameter;
528 $parameter_name =~ s/\[.*//;
530 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
531 $type = $args{'parametertypes'}{$parameter};
532 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
533 # pointer-to-function
534 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
535 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
537 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
539 print " <i>$type</i> <b>$parameter</b>;<br>\n";
544 print "<h3>Members</h3>\n";
546 foreach $parameter (@
{$args{'parameterlist'}}) {
547 ($parameter =~ /^#/) && next;
549 my $parameter_name = $parameter;
550 $parameter_name =~ s/\[.*//;
552 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
553 print "<dt><b>".$parameter."</b>\n";
555 output_highlight
($args{'parameterdescs'}{$parameter_name});
558 output_section_html
(@_);
562 # output function in html
563 sub output_function_html
(%) {
565 my ($parameter, $section);
568 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
569 print "<i>".$args{'functiontype'}."</i>\n";
570 print "<b>".$args{'function'}."</b>\n";
573 foreach $parameter (@
{$args{'parameterlist'}}) {
574 $type = $args{'parametertypes'}{$parameter};
575 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
576 # pointer-to-function
577 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
579 print "<i>".$type."</i> <b>".$parameter."</b>";
581 if ($count != $#{$args{'parameterlist'}}) {
588 print "<h3>Arguments</h3>\n";
590 foreach $parameter (@
{$args{'parameterlist'}}) {
591 my $parameter_name = $parameter;
592 $parameter_name =~ s/\[.*//;
594 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
595 print "<dt><b>".$parameter."</b>\n";
597 output_highlight
($args{'parameterdescs'}{$parameter_name});
600 output_section_html
(@_);
604 # output DOC: block header in html
605 sub output_blockhead_html
(%) {
607 my ($parameter, $section);
610 foreach $section (@
{$args{'sectionlist'}}) {
611 print "<h3>$section</h3>\n";
613 output_highlight
($args{'sections'}{$section});
619 sub output_section_xml
(%) {
622 # print out each section
624 foreach $section (@
{$args{'sectionlist'}}) {
625 print "<refsect1>\n";
626 print "<title>$section</title>\n";
627 if ($section =~ m/EXAMPLE/i) {
628 print "<informalexample><programlisting>\n";
632 output_highlight
($args{'sections'}{$section});
633 if ($section =~ m/EXAMPLE/i) {
634 print "</programlisting></informalexample>\n";
638 print "</refsect1>\n";
642 # output function in XML DocBook
643 sub output_function_xml
(%) {
645 my ($parameter, $section);
649 $id = "API-".$args{'function'};
650 $id =~ s/[^A-Za-z0-9]/-/g;
652 print "<refentry id=\"$id\">\n";
653 print "<refentryinfo>\n";
654 print " <title>LINUX</title>\n";
655 print " <productname>Kernel Hackers Manual</productname>\n";
656 print " <date>$man_date</date>\n";
657 print "</refentryinfo>\n";
659 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
660 print " <manvolnum>9</manvolnum>\n";
661 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
662 print "</refmeta>\n";
663 print "<refnamediv>\n";
664 print " <refname>".$args{'function'}."</refname>\n";
665 print " <refpurpose>\n";
667 output_highlight
($args{'purpose'});
668 print " </refpurpose>\n";
669 print "</refnamediv>\n";
671 print "<refsynopsisdiv>\n";
672 print " <title>Synopsis</title>\n";
673 print " <funcsynopsis><funcprototype>\n";
674 print " <funcdef>".$args{'functiontype'}." ";
675 print "<function>".$args{'function'}." </function></funcdef>\n";
678 if ($#{$args{'parameterlist'}} >= 0) {
679 foreach $parameter (@
{$args{'parameterlist'}}) {
680 $type = $args{'parametertypes'}{$parameter};
681 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
682 # pointer-to-function
683 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
684 print " <funcparams>$2</funcparams></paramdef>\n";
686 print " <paramdef>".$type;
687 print " <parameter>$parameter</parameter></paramdef>\n";
693 print " </funcprototype></funcsynopsis>\n";
694 print "</refsynopsisdiv>\n";
697 print "<refsect1>\n <title>Arguments</title>\n";
698 if ($#{$args{'parameterlist'}} >= 0) {
699 print " <variablelist>\n";
700 foreach $parameter (@
{$args{'parameterlist'}}) {
701 my $parameter_name = $parameter;
702 $parameter_name =~ s/\[.*//;
704 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
705 print " <listitem>\n <para>\n";
707 output_highlight
($args{'parameterdescs'}{$parameter_name});
708 print " </para>\n </listitem>\n </varlistentry>\n";
710 print " </variablelist>\n";
712 print " <para>\n None\n </para>\n";
714 print "</refsect1>\n";
716 output_section_xml
(@_);
717 print "</refentry>\n\n";
720 # output struct in XML DocBook
721 sub output_struct_xml
(%) {
723 my ($parameter, $section);
726 $id = "API-struct-".$args{'struct'};
727 $id =~ s/[^A-Za-z0-9]/-/g;
729 print "<refentry id=\"$id\">\n";
730 print "<refentryinfo>\n";
731 print " <title>LINUX</title>\n";
732 print " <productname>Kernel Hackers Manual</productname>\n";
733 print " <date>$man_date</date>\n";
734 print "</refentryinfo>\n";
736 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
737 print " <manvolnum>9</manvolnum>\n";
738 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
739 print "</refmeta>\n";
740 print "<refnamediv>\n";
741 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
742 print " <refpurpose>\n";
744 output_highlight
($args{'purpose'});
745 print " </refpurpose>\n";
746 print "</refnamediv>\n";
748 print "<refsynopsisdiv>\n";
749 print " <title>Synopsis</title>\n";
750 print " <programlisting>\n";
751 print $args{'type'}." ".$args{'struct'}." {\n";
752 foreach $parameter (@
{$args{'parameterlist'}}) {
753 if ($parameter =~ /^#/) {
754 print "$parameter\n";
758 my $parameter_name = $parameter;
759 $parameter_name =~ s/\[.*//;
761 defined($args{'parameterdescs'}{$parameter_name}) || next;
762 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
763 $type = $args{'parametertypes'}{$parameter};
764 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
765 # pointer-to-function
766 print " $1 $parameter) ($2);\n";
767 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
769 print " $1 $parameter$2;\n";
771 print " ".$type." ".$parameter.";\n";
775 print " </programlisting>\n";
776 print "</refsynopsisdiv>\n";
778 print " <refsect1>\n";
779 print " <title>Members</title>\n";
781 print " <variablelist>\n";
782 foreach $parameter (@
{$args{'parameterlist'}}) {
783 ($parameter =~ /^#/) && next;
785 my $parameter_name = $parameter;
786 $parameter_name =~ s/\[.*//;
788 defined($args{'parameterdescs'}{$parameter_name}) || next;
789 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
790 print " <varlistentry>";
791 print " <term>$parameter</term>\n";
792 print " <listitem><para>\n";
793 output_highlight
($args{'parameterdescs'}{$parameter_name});
794 print " </para></listitem>\n";
795 print " </varlistentry>\n";
797 print " </variablelist>\n";
798 print " </refsect1>\n";
800 output_section_xml
(@_);
802 print "</refentry>\n\n";
805 # output enum in XML DocBook
806 sub output_enum_xml
(%) {
808 my ($parameter, $section);
812 $id = "API-enum-".$args{'enum'};
813 $id =~ s/[^A-Za-z0-9]/-/g;
815 print "<refentry id=\"$id\">\n";
816 print "<refentryinfo>\n";
817 print " <title>LINUX</title>\n";
818 print " <productname>Kernel Hackers Manual</productname>\n";
819 print " <date>$man_date</date>\n";
820 print "</refentryinfo>\n";
822 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
823 print " <manvolnum>9</manvolnum>\n";
824 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
825 print "</refmeta>\n";
826 print "<refnamediv>\n";
827 print " <refname>enum ".$args{'enum'}."</refname>\n";
828 print " <refpurpose>\n";
830 output_highlight
($args{'purpose'});
831 print " </refpurpose>\n";
832 print "</refnamediv>\n";
834 print "<refsynopsisdiv>\n";
835 print " <title>Synopsis</title>\n";
836 print " <programlisting>\n";
837 print "enum ".$args{'enum'}." {\n";
839 foreach $parameter (@
{$args{'parameterlist'}}) {
841 if ($count != $#{$args{'parameterlist'}}) {
848 print " </programlisting>\n";
849 print "</refsynopsisdiv>\n";
851 print "<refsect1>\n";
852 print " <title>Constants</title>\n";
853 print " <variablelist>\n";
854 foreach $parameter (@
{$args{'parameterlist'}}) {
855 my $parameter_name = $parameter;
856 $parameter_name =~ s/\[.*//;
858 print " <varlistentry>";
859 print " <term>$parameter</term>\n";
860 print " <listitem><para>\n";
861 output_highlight
($args{'parameterdescs'}{$parameter_name});
862 print " </para></listitem>\n";
863 print " </varlistentry>\n";
865 print " </variablelist>\n";
866 print "</refsect1>\n";
868 output_section_xml
(@_);
870 print "</refentry>\n\n";
873 # output typedef in XML DocBook
874 sub output_typedef_xml
(%) {
876 my ($parameter, $section);
879 $id = "API-typedef-".$args{'typedef'};
880 $id =~ s/[^A-Za-z0-9]/-/g;
882 print "<refentry id=\"$id\">\n";
883 print "<refentryinfo>\n";
884 print " <title>LINUX</title>\n";
885 print " <productname>Kernel Hackers Manual</productname>\n";
886 print " <date>$man_date</date>\n";
887 print "</refentryinfo>\n";
889 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
890 print " <manvolnum>9</manvolnum>\n";
891 print "</refmeta>\n";
892 print "<refnamediv>\n";
893 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
894 print " <refpurpose>\n";
896 output_highlight
($args{'purpose'});
897 print " </refpurpose>\n";
898 print "</refnamediv>\n";
900 print "<refsynopsisdiv>\n";
901 print " <title>Synopsis</title>\n";
902 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
903 print "</refsynopsisdiv>\n";
905 output_section_xml
(@_);
907 print "</refentry>\n\n";
910 # output in XML DocBook
911 sub output_blockhead_xml
(%) {
913 my ($parameter, $section);
916 my $id = $args{'module'};
917 $id =~ s/[^A-Za-z0-9]/-/g;
919 # print out each section
921 foreach $section (@
{$args{'sectionlist'}}) {
922 if (!$args{'content-only'}) {
923 print "<refsect1>\n <title>$section</title>\n";
925 if ($section =~ m/EXAMPLE/i) {
926 print "<example><para>\n";
930 output_highlight
($args{'sections'}{$section});
931 if ($section =~ m/EXAMPLE/i) {
932 print "</para></example>\n";
936 if (!$args{'content-only'}) {
937 print "\n</refsect1>\n";
944 # output in XML DocBook
945 sub output_function_gnome
{
947 my ($parameter, $section);
951 $id = $args{'module'}."-".$args{'function'};
952 $id =~ s/[^A-Za-z0-9]/-/g;
955 print " <title id=\"$id\">".$args{'function'}."</title>\n";
957 print " <funcsynopsis>\n";
958 print " <funcdef>".$args{'functiontype'}." ";
959 print "<function>".$args{'function'}." ";
960 print "</function></funcdef>\n";
963 if ($#{$args{'parameterlist'}} >= 0) {
964 foreach $parameter (@
{$args{'parameterlist'}}) {
965 $type = $args{'parametertypes'}{$parameter};
966 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
967 # pointer-to-function
968 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
969 print " <funcparams>$2</funcparams></paramdef>\n";
971 print " <paramdef>".$type;
972 print " <parameter>$parameter</parameter></paramdef>\n";
978 print " </funcsynopsis>\n";
979 if ($#{$args{'parameterlist'}} >= 0) {
980 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
981 print "<tgroup cols=\"2\">\n";
982 print "<colspec colwidth=\"2*\">\n";
983 print "<colspec colwidth=\"8*\">\n";
985 foreach $parameter (@
{$args{'parameterlist'}}) {
986 my $parameter_name = $parameter;
987 $parameter_name =~ s/\[.*//;
989 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
992 output_highlight
($args{'parameterdescs'}{$parameter_name});
993 print " </entry></row>\n";
995 print " </tbody></tgroup></informaltable>\n";
997 print " <para>\n None\n </para>\n";
1000 # print out each section
1002 foreach $section (@
{$args{'sectionlist'}}) {
1003 print "<simplesect>\n <title>$section</title>\n";
1004 if ($section =~ m/EXAMPLE/i) {
1005 print "<example><programlisting>\n";
1009 output_highlight
($args{'sections'}{$section});
1011 if ($section =~ m/EXAMPLE/i) {
1012 print "</programlisting></example>\n";
1015 print " </simplesect>\n";
1018 print "</sect2>\n\n";
1022 # output function in man
1023 sub output_function_man
(%) {
1024 my %args = %{$_[0]};
1025 my ($parameter, $section);
1028 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1031 print $args{'function'}." \\- ".$args{'purpose'}."\n";
1033 print ".SH SYNOPSIS\n";
1034 if ($args{'functiontype'} ne "") {
1035 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
1037 print ".B \"".$args{'function'}."\n";
1042 foreach my $parameter (@
{$args{'parameterlist'}}) {
1043 if ($count == $#{$args{'parameterlist'}}) {
1046 $type = $args{'parametertypes'}{$parameter};
1047 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1048 # pointer-to-function
1049 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
1051 $type =~ s/([^\*])$/$1 /;
1052 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1058 print ".SH ARGUMENTS\n";
1059 foreach $parameter (@
{$args{'parameterlist'}}) {
1060 my $parameter_name = $parameter;
1061 $parameter_name =~ s/\[.*//;
1063 print ".IP \"".$parameter."\" 12\n";
1064 output_highlight
($args{'parameterdescs'}{$parameter_name});
1066 foreach $section (@
{$args{'sectionlist'}}) {
1067 print ".SH \"", uc $section, "\"\n";
1068 output_highlight
($args{'sections'}{$section});
1073 # output enum in man
1074 sub output_enum_man
(%) {
1075 my %args = %{$_[0]};
1076 my ($parameter, $section);
1079 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1082 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1084 print ".SH SYNOPSIS\n";
1085 print "enum ".$args{'enum'}." {\n";
1087 foreach my $parameter (@
{$args{'parameterlist'}}) {
1088 print ".br\n.BI \" $parameter\"\n";
1089 if ($count == $#{$args{'parameterlist'}}) {
1099 print ".SH Constants\n";
1100 foreach $parameter (@
{$args{'parameterlist'}}) {
1101 my $parameter_name = $parameter;
1102 $parameter_name =~ s/\[.*//;
1104 print ".IP \"".$parameter."\" 12\n";
1105 output_highlight
($args{'parameterdescs'}{$parameter_name});
1107 foreach $section (@
{$args{'sectionlist'}}) {
1108 print ".SH \"$section\"\n";
1109 output_highlight
($args{'sections'}{$section});
1114 # output struct in man
1115 sub output_struct_man
(%) {
1116 my %args = %{$_[0]};
1117 my ($parameter, $section);
1119 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1122 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1124 print ".SH SYNOPSIS\n";
1125 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1127 foreach my $parameter (@
{$args{'parameterlist'}}) {
1128 if ($parameter =~ /^#/) {
1129 print ".BI \"$parameter\"\n.br\n";
1132 my $parameter_name = $parameter;
1133 $parameter_name =~ s/\[.*//;
1135 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1136 $type = $args{'parametertypes'}{$parameter};
1137 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1138 # pointer-to-function
1139 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1140 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1142 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1144 $type =~ s/([^\*])$/$1 /;
1145 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1151 print ".SH Members\n";
1152 foreach $parameter (@
{$args{'parameterlist'}}) {
1153 ($parameter =~ /^#/) && next;
1155 my $parameter_name = $parameter;
1156 $parameter_name =~ s/\[.*//;
1158 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1159 print ".IP \"".$parameter."\" 12\n";
1160 output_highlight
($args{'parameterdescs'}{$parameter_name});
1162 foreach $section (@
{$args{'sectionlist'}}) {
1163 print ".SH \"$section\"\n";
1164 output_highlight
($args{'sections'}{$section});
1169 # output typedef in man
1170 sub output_typedef_man
(%) {
1171 my %args = %{$_[0]};
1172 my ($parameter, $section);
1174 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1177 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1179 foreach $section (@
{$args{'sectionlist'}}) {
1180 print ".SH \"$section\"\n";
1181 output_highlight
($args{'sections'}{$section});
1185 sub output_blockhead_man
(%) {
1186 my %args = %{$_[0]};
1187 my ($parameter, $section);
1190 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1192 foreach $section (@
{$args{'sectionlist'}}) {
1193 print ".SH \"$section\"\n";
1194 output_highlight
($args{'sections'}{$section});
1200 sub output_function_text
(%) {
1201 my %args = %{$_[0]};
1202 my ($parameter, $section);
1206 print $args{'function'}." - ".$args{'purpose'}."\n";
1208 print "\nSynopsis:\n\n";
1209 if ($args{'functiontype'} ne "") {
1210 $start = $args{'functiontype'}." ".$args{'function'}." (";
1212 $start = $args{'function'}." (";
1217 foreach my $parameter (@
{$args{'parameterlist'}}) {
1218 $type = $args{'parametertypes'}{$parameter};
1219 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1220 # pointer-to-function
1221 print $1.$parameter.") (".$2;
1223 print $type." ".$parameter;
1225 if ($count != $#{$args{'parameterlist'}}) {
1228 print " " x
length($start);
1234 print "Arguments:\n\n";
1235 foreach $parameter (@
{$args{'parameterlist'}}) {
1236 my $parameter_name = $parameter;
1237 $parameter_name =~ s/\[.*//;
1239 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1241 output_section_text
(@_);
1244 #output sections in text
1245 sub output_section_text
(%) {
1246 my %args = %{$_[0]};
1250 foreach $section (@
{$args{'sectionlist'}}) {
1251 print "$section:\n\n";
1252 output_highlight
($args{'sections'}{$section});
1257 # output enum in text
1258 sub output_enum_text
(%) {
1259 my %args = %{$_[0]};
1264 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1265 print "enum ".$args{'enum'}." {\n";
1267 foreach $parameter (@
{$args{'parameterlist'}}) {
1268 print "\t$parameter";
1269 if ($count != $#{$args{'parameterlist'}}) {
1277 print "Constants:\n\n";
1278 foreach $parameter (@
{$args{'parameterlist'}}) {
1279 print "$parameter\n\t";
1280 print $args{'parameterdescs'}{$parameter}."\n";
1283 output_section_text
(@_);
1286 # output typedef in text
1287 sub output_typedef_text
(%) {
1288 my %args = %{$_[0]};
1291 print "Typedef:\n\n";
1293 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1294 output_section_text
(@_);
1297 # output struct as text
1298 sub output_struct_text
(%) {
1299 my %args = %{$_[0]};
1302 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1303 print $args{'type'}." ".$args{'struct'}." {\n";
1304 foreach $parameter (@
{$args{'parameterlist'}}) {
1305 if ($parameter =~ /^#/) {
1306 print "$parameter\n";
1310 my $parameter_name = $parameter;
1311 $parameter_name =~ s/\[.*//;
1313 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1314 $type = $args{'parametertypes'}{$parameter};
1315 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1316 # pointer-to-function
1317 print "\t$1 $parameter) ($2);\n";
1318 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1320 print "\t$1 $parameter$2;\n";
1322 print "\t".$type." ".$parameter.";\n";
1327 print "Members:\n\n";
1328 foreach $parameter (@
{$args{'parameterlist'}}) {
1329 ($parameter =~ /^#/) && next;
1331 my $parameter_name = $parameter;
1332 $parameter_name =~ s/\[.*//;
1334 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1335 print "$parameter\n\t";
1336 print $args{'parameterdescs'}{$parameter_name}."\n";
1339 output_section_text
(@_);
1342 sub output_blockhead_text
(%) {
1343 my %args = %{$_[0]};
1344 my ($parameter, $section);
1346 foreach $section (@
{$args{'sectionlist'}}) {
1347 print " $section:\n";
1349 output_highlight
($args{'sections'}{$section});
1354 # generic output function for all types (function, struct/union, typedef, enum);
1355 # calls the generated, variable output_ function name based on
1356 # functype and output_mode
1357 sub output_declaration
{
1360 my $functype = shift;
1361 my $func = "output_${functype}_$output_mode";
1362 if (($function_only==0) ||
1363 ( $function_only == 1 && defined($function_table{$name})) ||
1364 ( $function_only == 2 && !defined($function_table{$name})))
1372 # generic output function - calls the right one based on current output mode.
1373 sub output_blockhead
{
1375 my $func = "output_blockhead_".$output_mode;
1381 # takes a declaration (struct, union, enum, typedef) and
1382 # invokes the right handler. NOT called for functions.
1383 sub dump_declaration
($$) {
1385 my ($prototype, $file) = @_;
1386 my $func = "dump_".$decl_type;
1390 sub dump_union
($$) {
1394 sub dump_struct
($$) {
1398 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1399 $declaration_name = $2;
1402 # ignore embedded structs or unions
1403 $members =~ s/{.*?}//g;
1405 # ignore members marked private:
1406 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1407 $members =~ s/\/\*.*?private:.*//gos
;
1409 $members =~ s/\/\*.*?\*\///gos;
1411 create_parameterlist
($members, ';', $file);
1413 output_declaration
($declaration_name,
1415 {'struct' => $declaration_name,
1416 'module' => $modulename,
1417 'parameterlist' => \
@parameterlist,
1418 'parameterdescs' => \
%parameterdescs,
1419 'parametertypes' => \
%parametertypes,
1420 'sectionlist' => \
@sectionlist,
1421 'sections' => \
%sections,
1422 'purpose' => $declaration_purpose,
1423 'type' => $decl_type
1427 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1436 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1437 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1438 $declaration_name = $1;
1441 foreach my $arg (split ',', $members) {
1442 $arg =~ s/^\s*(\w+).*/$1/;
1443 push @parameterlist, $arg;
1444 if (!$parameterdescs{$arg}) {
1445 $parameterdescs{$arg} = $undescribed;
1446 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1447 "not described in enum '$declaration_name'\n";
1452 output_declaration
($declaration_name,
1454 {'enum' => $declaration_name,
1455 'module' => $modulename,
1456 'parameterlist' => \
@parameterlist,
1457 'parameterdescs' => \
%parameterdescs,
1458 'sectionlist' => \
@sectionlist,
1459 'sections' => \
%sections,
1460 'purpose' => $declaration_purpose
1464 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1469 sub dump_typedef
($$) {
1473 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1474 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1475 $x =~ s/\(*.\)\s*;$/;/;
1476 $x =~ s/\[*.\]\s*;$/;/;
1479 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1480 $declaration_name = $1;
1482 output_declaration
($declaration_name,
1484 {'typedef' => $declaration_name,
1485 'module' => $modulename,
1486 'sectionlist' => \
@sectionlist,
1487 'sections' => \
%sections,
1488 'purpose' => $declaration_purpose
1492 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1497 sub create_parameterlist
($$$) {
1499 my $splitter = shift;
1504 # temporarily replace commas inside function pointer definition
1505 while ($args =~ /(\([^\),]+),/) {
1506 $args =~ s/(\([^\),]+),/$1#/g;
1509 foreach my $arg (split($splitter, $args)) {
1511 $arg =~ s/\/\*.*\*\///;
1512 # strip leading/trailing spaces
1518 # Treat preprocessor directive as a typeless variable just to fill
1519 # corresponding data structures "correctly". Catch it later in
1521 push_parameter
($arg, "", $file);
1522 <<<<<<< HEAD
:scripts
/kernel
-doc
1523 } elsif ($arg =~ m/\(.*\*/) {
1525 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1526 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/kernel
-doc
1527 # pointer-to-function
1529 <<<<<<< HEAD
:scripts
/kernel
-doc
1530 $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/;
1532 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1533 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/kernel
-doc
1536 <<<<<<< HEAD
:scripts
/kernel
-doc
1537 $type =~ s/([^\(]+\(\*)$param/$1/;
1539 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1540 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/kernel
-doc
1541 push_parameter
($param, $type, $file);
1543 $arg =~ s/\s*:\s*/:/g;
1544 $arg =~ s/\s*\[/\[/g;
1546 my @args = split('\s*,\s*', $arg);
1547 if ($args[0] =~ m/\*/) {
1548 $args[0] =~ s/(\*+)\s*/ $1/;
1552 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1554 push(@first_arg, split('\s+', $1));
1555 push(@first_arg, $2);
1557 @first_arg = split('\s+', shift @args);
1560 unshift(@args, pop @first_arg);
1561 $type = join " ", @first_arg;
1563 foreach $param (@args) {
1564 if ($param =~ m/^(\*+)\s*(.*)/) {
1565 push_parameter
($2, "$type $1", $file);
1567 elsif ($param =~ m/(.*?):(\d+)/) {
1568 push_parameter
($1, "$type:$2", $file)
1571 push_parameter
($param, $type, $file);
1578 sub push_parameter
($$$) {
1583 if (($anon_struct_union == 1) && ($type eq "") &&
1585 return; # ignore the ending }; from anon. struct/union
1588 $anon_struct_union = 0;
1589 my $param_name = $param;
1590 $param_name =~ s/\[.*//;
1592 if ($type eq "" && $param =~ /\.\.\.$/)
1595 $parameterdescs{$param} = "variable arguments";
1597 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1601 $parameterdescs{void
} = "no arguments";
1603 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1604 # handle unnamed (anonymous) union or struct:
1607 $param = "{unnamed_" . $param . "}";
1608 $parameterdescs{$param} = "anonymous\n";
1609 $anon_struct_union = 1;
1612 # warn if parameter has no description
1613 # (but ignore ones starting with # as these are not parameters
1614 # but inline preprocessor statements);
1615 # also ignore unnamed structs/unions;
1616 if (!$anon_struct_union) {
1617 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1619 $parameterdescs{$param_name} = $undescribed;
1621 if (($type eq 'function') || ($type eq 'enum')) {
1622 print STDERR
"Warning(${file}:$.): Function parameter ".
1623 "or member '$param' not " .
1624 "described in '$declaration_name'\n";
1626 print STDERR
"Warning(${file}:$.):".
1627 " No description found for parameter '$param'\n";
1632 push @parameterlist, $param;
1633 $parametertypes{$param} = $type;
1637 # takes a function prototype and the name of the current file being
1638 # processed and spits out all the details stored in the global
1640 sub dump_function
($$) {
1641 my $prototype = shift;
1644 $prototype =~ s/^static +//;
1645 $prototype =~ s/^extern +//;
1646 $prototype =~ s/^asmlinkage +//;
1647 $prototype =~ s/^inline +//;
1648 $prototype =~ s/^__inline__ +//;
1649 $prototype =~ s/^__inline +//;
1650 $prototype =~ s/^__always_inline +//;
1651 $prototype =~ s/^noinline +//;
1652 $prototype =~ s/__devinit +//;
1653 $prototype =~ s/^#define\s+//; #ak added
1654 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1656 # Yes, this truly is vile. We are looking for:
1657 # 1. Return type (may be nothing if we're looking at a macro)
1659 # 3. Function parameters.
1661 # All the while we have to watch out for function pointer parameters
1662 # (which IIRC is what the two sections are for), C types (these
1663 # regexps don't even start to express all the possibilities), and
1666 # If you mess with these regexps, it's a good idea to check that
1667 # the following functions' documentation still comes out right:
1668 # - parport_register_device (function pointer parameters)
1669 # - atomic_set (macro)
1670 # - pci_match_device, __copy_to_user (long return type)
1672 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1673 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1674 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1675 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1676 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1677 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1678 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1679 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1680 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1681 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1682 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1683 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1684 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1685 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1686 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1687 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1688 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1690 $declaration_name = $2;
1693 create_parameterlist
($args, ',', $file);
1695 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1700 output_declaration
($declaration_name,
1702 {'function' => $declaration_name,
1703 'module' => $modulename,
1704 'functiontype' => $return_type,
1705 'parameterlist' => \
@parameterlist,
1706 'parameterdescs' => \
%parameterdescs,
1707 'parametertypes' => \
%parametertypes,
1708 'sectionlist' => \
@sectionlist,
1709 'sections' => \
%sections,
1710 'purpose' => $declaration_purpose
1714 sub process_file
($);
1716 # Read the file that maps relative names to absolute names for
1717 # separate source and object directories and for shadow trees.
1718 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
1719 my ($relname, $absname);
1720 while(<SOURCE_MAP
>) {
1722 ($relname, $absname) = (split())[0..1];
1723 $relname =~ s
:^/+::;
1724 $source_map{$relname} = $absname;
1730 open(FLIST
,"<$filelist") or die "Can't open file list $filelist";
1741 if ($verbose && $errors) {
1742 print STDERR
"$errors errors\n";
1744 if ($verbose && $warnings) {
1745 print STDERR
"$warnings warnings\n";
1753 %parameterdescs = ();
1754 %parametertypes = ();
1755 @parameterlist = ();
1763 sub process_state3_function
($$) {
1767 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
1769 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1772 elsif ($x =~ /([^\{]*)/) {
1775 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1776 $prototype =~ s@
/\*.*?\*/@
@gos; # strip comments.
1777 $prototype =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1778 $prototype =~ s@
^\s
+@
@gos; # strip leading spaces
1779 dump_function
($prototype,$file);
1784 sub process_state3_type
($$) {
1788 $x =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1789 $x =~ s@
^\s
+@
@gos; # strip leading spaces
1790 $x =~ s@\s
+$@
@gos; # strip trailing spaces
1791 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
1794 # To distinguish preprocessor directive from regular declaration later.
1799 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1800 $prototype .= $1 . $2;
1801 ($2 eq '{') && $brcount++;
1802 ($2 eq '}') && $brcount--;
1803 if (($2 eq ';') && ($brcount == 0)) {
1804 dump_declaration
($prototype,$file);
1816 # xml_escape: replace <, >, and & in the text stream;
1818 # however, formatting controls that are generated internally/locally in the
1819 # kernel-doc script are not escaped here; instead, they begin life like
1820 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1821 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1822 # just before actual output; (this is done by local_unescape())
1825 if (($output_mode eq "text") || ($output_mode eq "man")) {
1828 $text =~ s/\&/\\\\\\amp;/g;
1829 $text =~ s/\</\\\\\\lt;/g;
1830 $text =~ s/\>/\\\\\\gt;/g;
1834 # convert local escape strings to html
1835 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1836 sub local_unescape
($) {
1838 if (($output_mode eq "text") || ($output_mode eq "man")) {
1841 $text =~ s/\\\\\\\\lt:/</g;
1842 $text =~ s/\\\\\\\\gt:/>/g;
1846 sub process_file
($) {
1851 my $initial_section_counter = $section_counter;
1853 if (defined($ENV{'SRCTREE'})) {
1854 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1859 if (defined($source_map{$file})) {
1860 $file = $source_map{$file};
1863 if (!open(IN
,"<$file")) {
1864 print STDERR
"Error: Cannot open file $file\n";
1869 $section_counter = 0;
1872 if (/$doc_start/o) {
1873 $state = 1; # next line is always the function name
1876 } elsif ($state == 1) { # this line is the function name (always)
1877 if (/$doc_block/o) {
1881 $section = $section_intro;
1886 elsif (/$doc_decl/o) {
1888 if (/\s*([\w\s]+?)\s*-/) {
1894 # strip leading/trailing/multiple spaces
1899 $declaration_purpose = xml_escape
($descr);
1901 $declaration_purpose = "";
1904 if (($declaration_purpose eq "") && $verbose) {
1905 print STDERR
"Warning(${file}:$.): missing initial short description on line:\n";
1910 if ($identifier =~ m/^struct/) {
1911 $decl_type = 'struct';
1912 } elsif ($identifier =~ m/^union/) {
1913 $decl_type = 'union';
1914 } elsif ($identifier =~ m/^enum/) {
1915 $decl_type = 'enum';
1916 } elsif ($identifier =~ m/^typedef/) {
1917 $decl_type = 'typedef';
1919 $decl_type = 'function';
1923 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
1926 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
1927 " - I thought it was a doc line\n";
1931 } elsif ($state == 2) { # look for head: lines, and include content
1936 if (($contents ne "") && ($contents ne "\n")) {
1937 if (!$in_doc_sect && $verbose) {
1938 print STDERR
"Warning(${file}:$.): contents before sections\n";
1941 dump_section
($section, xml_escape
($contents));
1942 $section = $section_default;
1946 $contents = $newcontents;
1947 if ($contents ne "") {
1948 while ((substr($contents, 0, 1) eq " ") ||
1949 substr($contents, 0, 1) eq "\t") {
1950 $contents = substr($contents, 1);
1954 $section = $newsection;
1955 } elsif (/$doc_end/) {
1957 if ($contents ne "") {
1958 dump_section
($section, xml_escape
($contents));
1959 $section = $section_default;
1966 # print STDERR "end of doc comment, looking for prototype\n";
1967 } elsif (/$doc_content/) {
1968 # miguel-style comment kludge, look for blank lines after
1969 # @parameter line to signify start of description
1971 ($section =~ m/^@/ || $section eq $section_context)) {
1972 dump_section
($section, xml_escape
($contents));
1973 $section = $section_default;
1976 $contents .= $1."\n";
1979 # i dont know - bad line? ignore.
1980 print STDERR
"Warning(${file}:$.): bad line: $_";
1983 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1984 if ($decl_type eq 'function') {
1985 process_state3_function
($_, $file);
1987 process_state3_type
($_, $file);
1989 } elsif ($state == 4) {
1990 # Documentation block
1992 dump_doc_section
($section, xml_escape
($contents));
1996 %parameterdescs = ();
1997 %parametertypes = ();
1998 @parameterlist = ();
2003 $section = $section_intro;
2010 dump_doc_section
($section, xml_escape
($contents));
2014 %parameterdescs = ();
2015 %parametertypes = ();
2016 @parameterlist = ();
2022 elsif (/$doc_content/)
2026 $contents .= $blankline;
2030 $contents .= $1 . "\n";
2035 if ($initial_section_counter == $section_counter) {
2036 print STDERR
"Warning(${file}): no structured comments found\n";
2037 if ($output_mode eq "xml") {
2038 # The template wants at least one RefEntry here; make one.
2039 print "<refentry>\n";
2040 print " <refnamediv>\n";
2041 print " <refname>\n";
2043 print " </refname>\n";
2044 print " <refpurpose>\n";
2045 print " Document generation inconsistency\n";
2046 print " </refpurpose>\n";
2047 print " </refnamediv>\n";
2048 print " <refsect1>\n";
2051 print " </title>\n";
2052 print " <warning>\n";
2054 print " The template for this document tried to insert\n";
2055 print " the structured comment from the file\n";
2056 print " <filename>${file}</filename> at this point,\n";
2057 print " but none was found.\n";
2058 print " This dummy section is inserted to allow\n";
2059 print " generation to continue.\n";
2061 print " </warning>\n";
2062 print " </refsect1>\n";
2063 print "</refentry>\n";