]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - scripts/kernel-doc
5 ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
6 ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7 ## Copyright (C) 2001 Simon Huggins ##
8 ## Copyright (C) 2005-2010 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 # 18/01/2001 - Cleanups
17 # Functions prototyped as foo(void) same as foo()
18 # Stop eval'ing where we don't need to.
21 # 27/06/2001 - Allowed whitespace after initial "/**" and
22 # allowed comments before function declarations.
23 # -- Christian Kreibich <ck@whoop.org>
26 # - add perldoc documentation
27 # - Look more closely at some of the scarier bits :)
29 # 26/05/2001 - Support for separate source and object trees.
31 # Keith Owens <kaos@ocs.com.au>
33 # 23/09/2001 - Added support for typedefs, structs, enums and unions
34 # Support for Context section; can be terminated using empty line
35 # Small fixes (like spaces vs. \s in regex)
36 # -- Tim Jansen <tim@tjansen.de>
40 # This will read a 'c' file and scan for embedded comments in the
41 # style of gnome comments (+minor extensions - see below).
44 # Note: This only supports 'c'.
47 # kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ]
48 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
50 # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
52 # Set output format using one of -docbook -html -text or -man. Default is man.
53 # The -list format is for internal use by docproc.
56 # Do not output DOC: sections
59 # If set, then only generate documentation for the given function(s) or
60 # DOC: section titles. All other functions and DOC: sections are ignored.
62 # -nofunction funcname
63 # If set, then only generate documentation for the other function(s)/DOC:
64 # sections. Cannot be used together with -function (yes, that's a bug --
65 # perl hackers can fix it 8))
67 # c files - list of 'c' files to process
69 # All output goes to stdout, with errors to stderr.
73 # In the following table, (...)? signifies optional structure.
74 # (...)* signifies 0 or more structure elements
76 # * function_name(:)? (- short description)?
77 # (* @parameterx: (description of parameter x)?)*
79 # * (Description:)? (Description of function)?
80 # * (section header: (section description)? )*
83 # So .. the trivial example would be:
89 # If the Description: header tag is omitted, then there must be a blank line
90 # after the last parameter specification.
93 # * my_function - does my stuff
94 # * @my_arg: its mine damnit
96 # * Does my stuff explained.
101 # * my_function - does my stuff
102 # * @my_arg: its mine damnit
103 # * Description: Does my stuff explained.
107 # Besides functions you can also write documentation for structs, unions,
108 # enums and typedefs. Instead of the function name you must write the name
109 # of the declaration; the struct/union/enum/typedef must always precede
110 # the name. Nesting of declarations is not supported.
111 # Use the argument mechanism to document members or constants.
114 # * struct my_struct - short description
116 # * @b: second member
118 # * Longer description
127 # All descriptions can be multiline, except the short function description.
129 # You can also add additional sections. When documenting kernel functions you
130 # should document the "Context:" of the function, e.g. whether the functions
131 # can be called form interrupts. Unlike other sections you can end it with an
133 # Example-sections should contain the string EXAMPLE so that they are marked
134 # appropriately in DocBook.
138 # * user_function - function that can only be called in user context
139 # * @a: some argument
140 # * Context: !in_interrupt()
144 # * user_function(22);
149 # All descriptive text is further processed, scanning for the following special
150 # patterns, which are highlighted appropriately.
152 # 'funcname()' - function
153 # '$ENVVAR' - environmental variable
154 # '&struct_name' - name of a structure (up to two words including 'struct')
155 # '@parameter' - name of a parameter
156 # '%CONST' - name of a constant.
160 my $anon_struct_union = 0;
162 # match expressions used to find embedded type information
163 my $type_constant = '\%([-_\w]+)';
164 my $type_func = '(\w+)\(\)';
165 my $type_param = '\@(\w+)';
166 my $type_struct = '\&((struct\s*)*[_\w]+)';
167 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
168 my $type_env = '(\$\w+)';
170 # Output conversion substitutions.
171 # One for each output format
173 # these work fairly well
174 my %highlights_html = ( $type_constant, "<i>\$1</i>",
175 $type_func, "<b>\$1</b>",
176 $type_struct_xml, "<i>\$1</i>",
177 $type_env, "<b><i>\$1</i></b>",
178 $type_param, "<tt><b>\$1</b></tt>" );
179 my $local_lt = "\\\\\\\\lt:";
180 my $local_gt = "\\\\\\\\gt:";
181 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
183 # XML, docbook format
184 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
185 $type_constant, "<constant>\$1</constant>",
186 $type_func, "<function>\$1</function>",
187 $type_struct_xml, "<structname>\$1</structname>",
188 $type_env, "<envar>\$1</envar>",
189 $type_param, "<parameter>\$1</parameter>" );
190 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
192 # gnome, docbook format
193 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
194 $type_func, "<function>\$1</function>",
195 $type_struct, "<structname>\$1</structname>",
196 $type_env, "<envar>\$1</envar>",
197 $type_param, "<parameter>\$1</parameter>" );
198 my $blankline_gnome = "</para><para>\n";
200 # these are pretty rough
201 my %highlights_man = ( $type_constant, "\$1",
202 $type_func, "\\\\fB\$1\\\\fP",
203 $type_struct, "\\\\fI\$1\\\\fP",
204 $type_param, "\\\\fI\$1\\\\fP" );
205 my $blankline_man = "";
208 my %highlights_text = ( $type_constant, "\$1",
211 $type_param, "\$1" );
212 my $blankline_text = "";
215 my %highlights_list = ( $type_constant, "\$1",
218 $type_param, "\$1" );
219 my $blankline_list = "";
222 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n";
223 print " [ -no-doc-sections ]\n";
224 print " [ -function funcname [ -function funcname ...] ]\n";
225 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
226 print " c source file(s) > outputfile\n";
227 print " -v : verbose output, more warnings & other info listed\n";
237 my $output_mode = "man";
238 my $no_doc_sections = 0;
239 my %highlights = %highlights_man;
240 my $blankline = $blankline_man;
241 my $modulename = "Kernel API";
242 my $function_only = 0;
243 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
244 'July', 'August', 'September', 'October',
245 'November', 'December')[(localtime)[4]] .
246 " " . ((localtime)[5]+1900);
248 # Essentially these are globals
249 # They probably want to be tidied up, made more localised or something.
250 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
251 # could cause "use of undefined value" or other bugs.
252 my ($function, %function_table, %parametertypes, $declaration_purpose);
253 my ($type, $declaration_name, $return_type);
254 my ($newsection, $newcontents, $prototype, $brcount, %source_map);
256 if (defined($ENV{'KBUILD_VERBOSE'})) {
257 $verbose = "$ENV{'KBUILD_VERBOSE'}";
260 # Generated docbook code is inserted in a template at a point where
261 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
262 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
263 # We keep track of number of generated entries and generate a dummy
264 # if needs be to ensure the expanded template can be postprocessed
266 my $section_counter = 0;
272 # 1 - looking for function name
273 # 2 - scanning field start.
274 # 3 - scanning prototype.
275 # 4 - documentation block
279 #declaration types: can be
280 # 'function', 'struct', 'union', 'enum', 'typedef'
283 my $doc_special = "\@\%\$\&";
285 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
287 my $doc_com = '\s*\*\s*';
288 my $doc_decl = $doc_com . '(\w+)';
289 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
290 my $doc_content = $doc_com . '(.*)';
291 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
302 my $section_default = "Description"; # default section
303 my $section_intro = "Introduction";
304 my $section = $section_default;
305 my $section_context = "Context";
307 my $undescribed = "-- undescribed --";
311 while ($ARGV[0] =~ m/^-(.*)/) {
312 my $cmd = shift @ARGV;
313 if ($cmd eq "-html") {
314 $output_mode = "html";
315 %highlights = %highlights_html;
316 $blankline = $blankline_html;
317 } elsif ($cmd eq "-man") {
318 $output_mode = "man";
319 %highlights = %highlights_man;
320 $blankline = $blankline_man;
321 } elsif ($cmd eq "-text") {
322 $output_mode = "text";
323 %highlights = %highlights_text;
324 $blankline = $blankline_text;
325 } elsif ($cmd eq "-docbook") {
326 $output_mode = "xml";
327 %highlights = %highlights_xml;
328 $blankline = $blankline_xml;
329 } elsif ($cmd eq "-list") {
330 $output_mode = "list";
331 %highlights = %highlights_list;
332 $blankline = $blankline_list;
333 } elsif ($cmd eq "-gnome") {
334 $output_mode = "gnome";
335 %highlights = %highlights_gnome;
336 $blankline = $blankline_gnome;
337 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
338 $modulename = shift @ARGV;
339 } elsif ($cmd eq "-function") { # to only output specific functions
341 $function = shift @ARGV;
342 $function_table{$function} = 1;
343 } elsif ($cmd eq "-nofunction") { # to only output specific functions
345 $function = shift @ARGV;
346 $function_table{$function} = 1;
347 } elsif ($cmd eq "-v") {
349 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
351 } elsif ($cmd eq '-no-doc-sections') {
352 $no_doc_sections = 1;
356 # get kernel version from env
357 sub get_kernel_version
() {
358 my $version = 'unknown kernel version';
360 if (defined($ENV{'KERNELVERSION'})) {
361 $version = $ENV{'KERNELVERSION'};
365 my $kernelversion = get_kernel_version
();
367 # generate a sequence of code that will splice in highlighting information
368 # using the s// operator.
369 my $dohighlight = "";
370 foreach my $pattern (keys %highlights) {
371 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
372 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
376 # dumps section contents to arrays/hashes intended for that purpose.
381 my $contents = join "\n", @_;
383 if ($name =~ m/$type_constant/) {
385 # print STDERR "constant section '$1' = '$contents'\n";
386 $constants{$name} = $contents;
387 } elsif ($name =~ m/$type_param/) {
388 # print STDERR "parameter def '$1' = '$contents'\n";
390 $parameterdescs{$name} = $contents;
391 $sectcheck = $sectcheck . $name . " ";
392 } elsif ($name eq "@\.\.\.") {
393 # print STDERR "parameter def '...' = '$contents'\n";
395 $parameterdescs{$name} = $contents;
396 $sectcheck = $sectcheck . $name . " ";
398 # print STDERR "other section '$name' = '$contents'\n";
399 if (defined($sections{$name}) && ($sections{$name} ne "")) {
400 print STDERR
"Error(${file}:$.): duplicate section name '$name'\n";
403 $sections{$name} = $contents;
404 push @sectionlist, $name;
409 # dump DOC: section after checking that it should go out
411 sub dump_doc_section
{
414 my $contents = join "\n", @_;
416 if ($no_doc_sections) {
420 if (($function_only == 0) ||
421 ( $function_only == 1 && defined($function_table{$name})) ||
422 ( $function_only == 2 && !defined($function_table{$name})))
424 dump_section
($file, $name, $contents);
425 output_blockhead
({'sectionlist' => \
@sectionlist,
426 'sections' => \
%sections,
427 'module' => $modulename,
428 'content-only' => ($function_only != 0), });
435 # parameterdescs, a hash.
436 # function => "function name"
437 # parameterlist => @list of parameters
438 # parameterdescs => %parameter descriptions
439 # sectionlist => @list of sections
440 # sections => %section descriptions
443 sub output_highlight
{
444 my $contents = join "\n",@_;
448 # if (!defined $contents) {
450 # confess "output_highlight got called with no args?\n";
453 if ($output_mode eq "html" || $output_mode eq "xml") {
454 $contents = local_unescape
($contents);
455 # convert data read & converted thru xml_escape() into &xyz; format:
456 $contents =~ s/\\\\\\/\&/g;
458 # print STDERR "contents b4:$contents\n";
461 # print STDERR "contents af:$contents\n";
463 foreach $line (split "\n", $contents) {
465 print $lineprefix, local_unescape
($blankline);
467 $line =~ s/\\\\\\/\&/g;
468 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
471 print $lineprefix, $line;
478 #output sections in html
479 sub output_section_html
(%) {
483 foreach $section (@{$args{'sectionlist'}}) {
484 print "<h3>$section</h3>\n";
485 print "<blockquote>\n";
486 output_highlight
($args{'sections'}{$section});
487 print "</blockquote>\n";
491 # output enum in html
492 sub output_enum_html
(%) {
496 print "<h2>enum " . $args{'enum'} . "</h2>\n";
498 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
500 foreach $parameter (@{$args{'parameterlist'}}) {
501 print " <b>" . $parameter . "</b>";
502 if ($count != $#{$args{'parameterlist'}}) {
510 print "<h3>Constants</h3>\n";
512 foreach $parameter (@{$args{'parameterlist'}}) {
513 print "<dt><b>" . $parameter . "</b>\n";
515 output_highlight
($args{'parameterdescs'}{$parameter});
518 output_section_html
(@_);
522 # output typedef in html
523 sub output_typedef_html
(%) {
527 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
529 print "<b>typedef " . $args{'typedef'} . "</b>\n";
530 output_section_html
(@_);
534 # output struct in html
535 sub output_struct_html
(%) {
539 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
540 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
541 foreach $parameter (@{$args{'parameterlist'}}) {
542 if ($parameter =~ /^#/) {
543 print "$parameter<br>\n";
546 my $parameter_name = $parameter;
547 $parameter_name =~ s/\[.*//;
549 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
550 $type = $args{'parametertypes'}{$parameter};
551 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
552 # pointer-to-function
553 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
554 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
556 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
558 print " <i>$type</i> <b>$parameter</b>;<br>\n";
563 print "<h3>Members</h3>\n";
565 foreach $parameter (@{$args{'parameterlist'}}) {
566 ($parameter =~ /^#/) && next;
568 my $parameter_name = $parameter;
569 $parameter_name =~ s/\[.*//;
571 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
572 print "<dt><b>" . $parameter . "</b>\n";
574 output_highlight
($args{'parameterdescs'}{$parameter_name});
577 output_section_html
(@_);
581 # output function in html
582 sub output_function_html
(%) {
584 my ($parameter, $section);
587 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
588 print "<i>" . $args{'functiontype'} . "</i>\n";
589 print "<b>" . $args{'function'} . "</b>\n";
592 foreach $parameter (@{$args{'parameterlist'}}) {
593 $type = $args{'parametertypes'}{$parameter};
594 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
595 # pointer-to-function
596 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
598 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
600 if ($count != $#{$args{'parameterlist'}}) {
607 print "<h3>Arguments</h3>\n";
609 foreach $parameter (@{$args{'parameterlist'}}) {
610 my $parameter_name = $parameter;
611 $parameter_name =~ s/\[.*//;
613 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
614 print "<dt><b>" . $parameter . "</b>\n";
616 output_highlight
($args{'parameterdescs'}{$parameter_name});
619 output_section_html
(@_);
623 # output DOC: block header in html
624 sub output_blockhead_html
(%) {
626 my ($parameter, $section);
629 foreach $section (@{$args{'sectionlist'}}) {
630 print "<h3>$section</h3>\n";
632 output_highlight
($args{'sections'}{$section});
638 sub output_section_xml
(%) {
641 # print out each section
643 foreach $section (@{$args{'sectionlist'}}) {
644 print "<refsect1>\n";
645 print "<title>$section</title>\n";
646 if ($section =~ m/EXAMPLE/i) {
647 print "<informalexample><programlisting>\n";
651 output_highlight
($args{'sections'}{$section});
652 if ($section =~ m/EXAMPLE/i) {
653 print "</programlisting></informalexample>\n";
657 print "</refsect1>\n";
661 # output function in XML DocBook
662 sub output_function_xml
(%) {
664 my ($parameter, $section);
668 $id = "API-" . $args{'function'};
669 $id =~ s/[^A-Za-z0-9]/-/g;
671 print "<refentry id=\"$id\">\n";
672 print "<refentryinfo
>\n";
673 print " <title
>LINUX
</title
>\n";
674 print " <productname
>Kernel Hackers Manual
</productname
>\n";
675 print " <date
>$man_date</date
>\n";
676 print "</refentryinfo
>\n";
678 print " <refentrytitle
><phrase
>" . $args{'function'} . "</phrase></refentrytitle
>\n";
679 print " <manvolnum
>9</manvolnum
>\n";
680 print " <refmiscinfo
class=\"version
\">" . $kernelversion . "</refmiscinfo
>\n";
681 print "</refmeta
>\n";
682 print "<refnamediv
>\n";
683 print " <refname
>" . $args{'function'} . "</refname
>\n";
684 print " <refpurpose
>\n";
686 output_highlight ($args{'purpose'});
687 print " </refpurpose
>\n";
688 print "</refnamediv
>\n";
690 print "<refsynopsisdiv
>\n";
691 print " <title
>Synopsis
</title
>\n";
692 print " <funcsynopsis
><funcprototype
>\n";
693 print " <funcdef
>" . $args{'functiontype'} . " ";
694 print "<function
>" . $args{'function'} . " </function></funcdef
>\n";
697 if ($#{$args{'parameterlist'}} >= 0) {
698 foreach $parameter (@{$args{'parameterlist'}}) {
699 $type = $args{'parametertypes'}{$parameter};
700 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
701 # pointer-to-function
702 print " <paramdef
>$1<parameter
>$parameter</parameter
>)\n";
703 print " <funcparams
>$2</funcparams></paramdef
>\n";
705 print " <paramdef
>" . $type;
706 print " <parameter
>$parameter</parameter></paramdef
>\n";
712 print " </funcprototype></funcsynopsis
>\n";
713 print "</refsynopsisdiv
>\n";
716 print "<refsect1
>\n <title
>Arguments
</title
>\n";
717 if ($#{$args{'parameterlist'}} >= 0) {
718 print " <variablelist
>\n";
719 foreach $parameter (@{$args{'parameterlist'}}) {
720 my $parameter_name = $parameter;
721 $parameter_name =~ s/\[.*//;
723 print " <varlistentry
>\n <term
><parameter
>$parameter</parameter></term
>\n";
724 print " <listitem
>\n <para
>\n";
726 output_highlight($args{'parameterdescs'}{$parameter_name});
727 print " </para>\n </listitem
>\n </varlistentry
>\n";
729 print " </variablelist
>\n";
731 print " <para
>\n None
\n </para
>\n";
733 print "</refsect1
>\n";
735 output_section_xml(@_);
736 print "</refentry
>\n\n";
739 # output struct in XML DocBook
740 sub output_struct_xml(%) {
742 my ($parameter, $section);
745 $id = "API-struct-
" . $args{'struct'};
746 $id =~ s/[^A-Za-z0-9]/-/g;
748 print "<refentry id
=\"$id\">\n";
749 print "<refentryinfo>\n";
750 print " <title>LINUX</title>\n";
751 print " <productname>Kernel Hackers Manual</productname>\n";
752 print " <date>$man_date</date>\n";
753 print "</refentryinfo>\n";
755 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
756 print " <manvolnum>9</manvolnum>\n";
757 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
758 print "</refmeta>\n";
759 print "<refnamediv>\n";
760 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
761 print " <refpurpose>\n";
763 output_highlight
($args{'purpose'});
764 print " </refpurpose>\n";
765 print "</refnamediv>\n";
767 print "<refsynopsisdiv>\n";
768 print " <title>Synopsis</title>\n";
769 print " <programlisting>\n";
770 print $args{'type'} . " " . $args{'struct'} . " {\n";
771 foreach $parameter (@{$args{'parameterlist'}}) {
772 if ($parameter =~ /^#/) {
773 my $prm = $parameter;
774 # convert data read & converted thru xml_escape() into &xyz; format:
775 # This allows us to have #define macros interspersed in a struct.
776 $prm =~ s/\\\\\\/\&/g;
781 my $parameter_name = $parameter;
782 $parameter_name =~ s/\[.*//;
784 defined($args{'parameterdescs'}{$parameter_name}) || next;
785 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
786 $type = $args{'parametertypes'}{$parameter};
787 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
788 # pointer-to-function
789 print " $1 $parameter) ($2);\n";
790 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
792 print " $1 $parameter$2;\n";
794 print " " . $type . " " . $parameter . ";\n";
798 print " </programlisting>\n";
799 print "</refsynopsisdiv>\n";
801 print " <refsect1>\n";
802 print " <title>Members</title>\n";
804 if ($#{$args{'parameterlist'}} >= 0) {
805 print " <variablelist>\n";
806 foreach $parameter (@{$args{'parameterlist'}}) {
807 ($parameter =~ /^#/) && next;
809 my $parameter_name = $parameter;
810 $parameter_name =~ s/\[.*//;
812 defined($args{'parameterdescs'}{$parameter_name}) || next;
813 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
814 print " <varlistentry>";
815 print " <term>$parameter</term>\n";
816 print " <listitem><para>\n";
817 output_highlight
($args{'parameterdescs'}{$parameter_name});
818 print " </para></listitem>\n";
819 print " </varlistentry>\n";
821 print " </variablelist>\n";
823 print " <para>\n None\n </para>\n";
825 print " </refsect1>\n";
827 output_section_xml
(@_);
829 print "</refentry>\n\n";
832 # output enum in XML DocBook
833 sub output_enum_xml
(%) {
835 my ($parameter, $section);
839 $id = "API-enum-" . $args{'enum'};
840 $id =~ s/[^A-Za-z0-9]/-/g;
842 print "<refentry id=\"$id\">\n";
843 print "<refentryinfo
>\n";
844 print " <title
>LINUX
</title
>\n";
845 print " <productname
>Kernel Hackers Manual
</productname
>\n";
846 print " <date
>$man_date</date
>\n";
847 print "</refentryinfo
>\n";
849 print " <refentrytitle
><phrase
>enum
" . $args{'enum'} . "</phrase></refentrytitle
>\n";
850 print " <manvolnum
>9</manvolnum
>\n";
851 print " <refmiscinfo
class=\"version
\">" . $kernelversion . "</refmiscinfo
>\n";
852 print "</refmeta
>\n";
853 print "<refnamediv
>\n";
854 print " <refname
>enum
" . $args{'enum'} . "</refname
>\n";
855 print " <refpurpose
>\n";
857 output_highlight ($args{'purpose'});
858 print " </refpurpose
>\n";
859 print "</refnamediv
>\n";
861 print "<refsynopsisdiv
>\n";
862 print " <title
>Synopsis
</title
>\n";
863 print " <programlisting
>\n";
864 print "enum
" . $args{'enum'} . " {\n";
866 foreach $parameter (@{$args{'parameterlist'}}) {
868 if ($count != $#{$args{'parameterlist'}}) {
875 print " </programlisting
>\n";
876 print "</refsynopsisdiv
>\n";
878 print "<refsect1
>\n";
879 print " <title
>Constants
</title
>\n";
880 print " <variablelist
>\n";
881 foreach $parameter (@{$args{'parameterlist'}}) {
882 my $parameter_name = $parameter;
883 $parameter_name =~ s/\[.*//;
885 print " <varlistentry
>";
886 print " <term
>$parameter</term
>\n";
887 print " <listitem
><para
>\n";
888 output_highlight($args{'parameterdescs'}{$parameter_name});
889 print " </para></listitem
>\n";
890 print " </varlistentry
>\n";
892 print " </variablelist
>\n";
893 print "</refsect1
>\n";
895 output_section_xml(@_);
897 print "</refentry
>\n\n";
900 # output typedef in XML DocBook
901 sub output_typedef_xml(%) {
903 my ($parameter, $section);
906 $id = "API-typedef-
" . $args{'typedef'};
907 $id =~ s/[^A-Za-z0-9]/-/g;
909 print "<refentry id
=\"$id\">\n";
910 print "<refentryinfo>\n";
911 print " <title>LINUX</title>\n";
912 print " <productname>Kernel Hackers Manual</productname>\n";
913 print " <date>$man_date</date>\n";
914 print "</refentryinfo>\n";
916 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
917 print " <manvolnum>9</manvolnum>\n";
918 print "</refmeta>\n";
919 print "<refnamediv>\n";
920 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
921 print " <refpurpose>\n";
923 output_highlight
($args{'purpose'});
924 print " </refpurpose>\n";
925 print "</refnamediv>\n";
927 print "<refsynopsisdiv>\n";
928 print " <title>Synopsis</title>\n";
929 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
930 print "</refsynopsisdiv>\n";
932 output_section_xml
(@_);
934 print "</refentry>\n\n";
937 # output in XML DocBook
938 sub output_blockhead_xml
(%) {
940 my ($parameter, $section);
943 my $id = $args{'module'};
944 $id =~ s/[^A-Za-z0-9]/-/g;
946 # print out each section
948 foreach $section (@{$args{'sectionlist'}}) {
949 if (!$args{'content-only'}) {
950 print "<refsect1>\n <title>$section</title>\n";
952 if ($section =~ m/EXAMPLE/i) {
953 print "<example><para>\n";
957 output_highlight
($args{'sections'}{$section});
958 if ($section =~ m/EXAMPLE/i) {
959 print "</para></example>\n";
963 if (!$args{'content-only'}) {
964 print "\n</refsect1>\n";
971 # output in XML DocBook
972 sub output_function_gnome
{
974 my ($parameter, $section);
978 $id = $args{'module'} . "-" . $args{'function'};
979 $id =~ s/[^A-Za-z0-9]/-/g;
982 print " <title id=\"$id\">" . $args{'function'} . "</title
>\n";
984 print " <funcsynopsis
>\n";
985 print " <funcdef
>" . $args{'functiontype'} . " ";
986 print "<function
>" . $args{'function'} . " ";
987 print "</function></funcdef
>\n";
990 if ($#{$args{'parameterlist'}} >= 0) {
991 foreach $parameter (@{$args{'parameterlist'}}) {
992 $type = $args{'parametertypes'}{$parameter};
993 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
994 # pointer-to-function
995 print " <paramdef
>$1 <parameter
>$parameter</parameter
>)\n";
996 print " <funcparams
>$2</funcparams></paramdef
>\n";
998 print " <paramdef
>" . $type;
999 print " <parameter
>$parameter</parameter></paramdef
>\n";
1005 print " </funcsynopsis
>\n";
1006 if ($#{$args{'parameterlist'}} >= 0) {
1007 print " <informaltable pgwide
=\"1\" frame
=\"none
\" role=\"params
\">\n";
1008 print "<tgroup cols
=\"2\">\n";
1009 print "<colspec colwidth
=\"2*\">\n";
1010 print "<colspec colwidth
=\"8*\">\n";
1012 foreach $parameter (@{$args{'parameterlist'}}) {
1013 my $parameter_name = $parameter;
1014 $parameter_name =~ s/\[.*//;
1016 print " <row
><entry align
=\"right
\"><parameter
>$parameter</parameter></entry
>\n";
1019 output_highlight($args{'parameterdescs'}{$parameter_name});
1020 print " </entry></row
>\n";
1022 print " </tbody></tgroup
></informaltable
>\n";
1024 print " <para
>\n None
\n </para
>\n";
1027 # print out each section
1029 foreach $section (@{$args{'sectionlist'}}) {
1030 print "<simplesect
>\n <title
>$section</title
>\n";
1031 if ($section =~ m/EXAMPLE/i) {
1032 print "<example
><programlisting
>\n";
1036 output_highlight($args{'sections'}{$section});
1038 if ($section =~ m/EXAMPLE/i) {
1039 print "</programlisting></example
>\n";
1042 print " </simplesect
>\n";
1045 print "</sect2
>\n\n";
1049 # output function in man
1050 sub output_function_man(%) {
1051 my %args = %{$_[0]};
1052 my ($parameter, $section);
1055 print ".TH
\"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1058 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1060 print ".SH SYNOPSIS\n";
1061 if ($args{'functiontype'} ne "") {
1062 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1064 print ".B \"" . $args{'function'} . "\n";
1069 foreach my $parameter (@{$args{'parameterlist'}}) {
1070 if ($count == $#{$args{'parameterlist'}}) {
1073 $type = $args{'parametertypes'}{$parameter};
1074 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1075 # pointer-to-function
1076 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1078 $type =~ s/([^\*])$/$1 /;
1079 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1085 print ".SH ARGUMENTS\n";
1086 foreach $parameter (@{$args{'parameterlist'}}) {
1087 my $parameter_name = $parameter;
1088 $parameter_name =~ s/\[.*//;
1090 print ".IP \"" . $parameter . "\" 12\n";
1091 output_highlight
($args{'parameterdescs'}{$parameter_name});
1093 foreach $section (@{$args{'sectionlist'}}) {
1094 print ".SH \"", uc $section, "\"\n";
1095 output_highlight
($args{'sections'}{$section});
1100 # output enum in man
1101 sub output_enum_man
(%) {
1102 my %args = %{$_[0]};
1103 my ($parameter, $section);
1106 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual
\" LINUX
\n";
1109 print "enum
" . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1111 print ".SH SYNOPSIS
\n";
1112 print "enum
" . $args{'enum'} . " {\n";
1114 foreach my $parameter (@{$args{'parameterlist'}}) {
1115 print ".br
\n.BI
\" $parameter\"\n";
1116 if ($count == $#{$args{'parameterlist'}}) {
1126 print ".SH Constants\n";
1127 foreach $parameter (@{$args{'parameterlist'}}) {
1128 my $parameter_name = $parameter;
1129 $parameter_name =~ s/\[.*//;
1131 print ".IP \"" . $parameter . "\" 12\n";
1132 output_highlight
($args{'parameterdescs'}{$parameter_name});
1134 foreach $section (@{$args{'sectionlist'}}) {
1135 print ".SH \"$section\"\n";
1136 output_highlight($args{'sections'}{$section});
1141 # output struct in man
1142 sub output_struct_man(%) {
1143 my %args = %{$_[0]};
1144 my ($parameter, $section);
1146 print ".TH
\"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1149 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1151 print ".SH SYNOPSIS\n";
1152 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1154 foreach my $parameter (@{$args{'parameterlist'}}) {
1155 if ($parameter =~ /^#/) {
1156 print ".BI \"$parameter\"\n.br
\n";
1159 my $parameter_name = $parameter;
1160 $parameter_name =~ s/\[.*//;
1162 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1163 $type = $args{'parametertypes'}{$parameter};
1164 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1165 # pointer-to-function
1166 print ".BI
\" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1167 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1169 print ".BI
\" " . $1 . "\
\" " . $parameter . $2 . " \"" . "\"\n;\n";
1171 $type =~ s/([^\*])$/$1 /;
1172 print ".BI
\" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1178 print ".SH Members
\n";
1179 foreach $parameter (@{$args{'parameterlist'}}) {
1180 ($parameter =~ /^#/) && next;
1182 my $parameter_name = $parameter;
1183 $parameter_name =~ s/\[.*//;
1185 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1186 print ".IP
\"" . $parameter . "\" 12\n";
1187 output_highlight($args{'parameterdescs'}{$parameter_name});
1189 foreach $section (@{$args{'sectionlist'}}) {
1190 print ".SH
\"$section\"\n";
1191 output_highlight
($args{'sections'}{$section});
1196 # output typedef in man
1197 sub output_typedef_man
(%) {
1198 my %args = %{$_[0]};
1199 my ($parameter, $section);
1201 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual
\" LINUX
\n";
1204 print "typedef
" . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1206 foreach $section (@{$args{'sectionlist'}}) {
1207 print ".SH
\"$section\"\n";
1208 output_highlight
($args{'sections'}{$section});
1212 sub output_blockhead_man
(%) {
1213 my %args = %{$_[0]};
1214 my ($parameter, $section);
1217 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual
\" LINUX
\n";
1219 foreach $section (@{$args{'sectionlist'}}) {
1220 print ".SH
\"$section\"\n";
1221 output_highlight
($args{'sections'}{$section});
1227 sub output_function_text
(%) {
1228 my %args = %{$_[0]};
1229 my ($parameter, $section);
1233 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1235 print "\nSynopsis:\n\n";
1236 if ($args{'functiontype'} ne "") {
1237 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1239 $start = $args{'function'} . " (";
1244 foreach my $parameter (@{$args{'parameterlist'}}) {
1245 $type = $args{'parametertypes'}{$parameter};
1246 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1247 # pointer-to-function
1248 print $1 . $parameter . ") (" . $2;
1250 print $type . " " . $parameter;
1252 if ($count != $#{$args{'parameterlist'}}) {
1255 print " " x
length($start);
1261 print "Arguments:\n\n";
1262 foreach $parameter (@{$args{'parameterlist'}}) {
1263 my $parameter_name = $parameter;
1264 $parameter_name =~ s/\[.*//;
1266 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1268 output_section_text
(@_);
1271 #output sections in text
1272 sub output_section_text
(%) {
1273 my %args = %{$_[0]};
1277 foreach $section (@{$args{'sectionlist'}}) {
1278 print "$section:\n\n";
1279 output_highlight
($args{'sections'}{$section});
1284 # output enum in text
1285 sub output_enum_text
(%) {
1286 my %args = %{$_[0]};
1291 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1292 print "enum " . $args{'enum'} . " {\n";
1294 foreach $parameter (@{$args{'parameterlist'}}) {
1295 print "\t$parameter";
1296 if ($count != $#{$args{'parameterlist'}}) {
1304 print "Constants:\n\n";
1305 foreach $parameter (@{$args{'parameterlist'}}) {
1306 print "$parameter\n\t";
1307 print $args{'parameterdescs'}{$parameter} . "\n";
1310 output_section_text
(@_);
1313 # output typedef in text
1314 sub output_typedef_text
(%) {
1315 my %args = %{$_[0]};
1318 print "Typedef:\n\n";
1320 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1321 output_section_text
(@_);
1324 # output struct as text
1325 sub output_struct_text
(%) {
1326 my %args = %{$_[0]};
1329 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1330 print $args{'type'} . " " . $args{'struct'} . " {\n";
1331 foreach $parameter (@{$args{'parameterlist'}}) {
1332 if ($parameter =~ /^#/) {
1333 print "$parameter\n";
1337 my $parameter_name = $parameter;
1338 $parameter_name =~ s/\[.*//;
1340 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1341 $type = $args{'parametertypes'}{$parameter};
1342 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1343 # pointer-to-function
1344 print "\t$1 $parameter) ($2);\n";
1345 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1347 print "\t$1 $parameter$2;\n";
1349 print "\t" . $type . " " . $parameter . ";\n";
1354 print "Members:\n\n";
1355 foreach $parameter (@{$args{'parameterlist'}}) {
1356 ($parameter =~ /^#/) && next;
1358 my $parameter_name = $parameter;
1359 $parameter_name =~ s/\[.*//;
1361 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1362 print "$parameter\n\t";
1363 print $args{'parameterdescs'}{$parameter_name} . "\n";
1366 output_section_text
(@_);
1369 sub output_blockhead_text
(%) {
1370 my %args = %{$_[0]};
1371 my ($parameter, $section);
1373 foreach $section (@{$args{'sectionlist'}}) {
1374 print " $section:\n";
1376 output_highlight
($args{'sections'}{$section});
1380 ## list mode output functions
1382 sub output_function_list
(%) {
1383 my %args = %{$_[0]};
1385 print $args{'function'} . "\n";
1388 # output enum in list
1389 sub output_enum_list
(%) {
1390 my %args = %{$_[0]};
1391 print $args{'enum'} . "\n";
1394 # output typedef in list
1395 sub output_typedef_list
(%) {
1396 my %args = %{$_[0]};
1397 print $args{'typedef'} . "\n";
1400 # output struct as list
1401 sub output_struct_list
(%) {
1402 my %args = %{$_[0]};
1404 print $args{'struct'} . "\n";
1407 sub output_blockhead_list
(%) {
1408 my %args = %{$_[0]};
1409 my ($parameter, $section);
1411 foreach $section (@{$args{'sectionlist'}}) {
1412 print "DOC: $section\n";
1417 # generic output function for all types (function, struct/union, typedef, enum);
1418 # calls the generated, variable output_ function name based on
1419 # functype and output_mode
1420 sub output_declaration
{
1423 my $functype = shift;
1424 my $func = "output_${functype}_$output_mode";
1425 if (($function_only==0) ||
1426 ( $function_only == 1 && defined($function_table{$name})) ||
1427 ( $function_only == 2 && !defined($function_table{$name})))
1435 # generic output function - calls the right one based on current output mode.
1436 sub output_blockhead
{
1438 my $func = "output_blockhead_" . $output_mode;
1444 # takes a declaration (struct, union, enum, typedef) and
1445 # invokes the right handler. NOT called for functions.
1446 sub dump_declaration
($$) {
1448 my ($prototype, $file) = @_;
1449 my $func = "dump_" . $decl_type;
1453 sub dump_union
($$) {
1457 sub dump_struct
($$) {
1462 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1463 #my $decl_type = $1;
1464 $declaration_name = $2;
1467 # ignore embedded structs or unions
1468 $members =~ s/({.*})//g;
1471 # ignore members marked private:
1472 $members =~ s/\/\*\s*private:.*?\/\
*\s
*public
:.*?\
*\
///gos
;
1473 $members =~ s/\/\*\s*private:.*//gos
;
1475 $members =~ s/\/\*.*?\*\///gos;
1476 $nested =~ s/\/\*.*?\*\///gos;
1477 # strip kmemcheck_bitfield_{begin,end}.*;
1478 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1480 $members =~ s/__aligned\s*\(\d+\)//gos;
1482 create_parameterlist
($members, ';', $file);
1483 check_sections
($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1485 output_declaration
($declaration_name,
1487 {'struct' => $declaration_name,
1488 'module' => $modulename,
1489 'parameterlist' => \
@parameterlist,
1490 'parameterdescs' => \
%parameterdescs,
1491 'parametertypes' => \
%parametertypes,
1492 'sectionlist' => \
@sectionlist,
1493 'sections' => \
%sections,
1494 'purpose' => $declaration_purpose,
1495 'type' => $decl_type
1499 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1508 $x =~ s
@/\*.*?\
*/@@gos; # strip comments.
1509 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1511 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1512 $declaration_name = $1;
1515 foreach my $arg (split ',', $members) {
1516 $arg =~ s/^\s*(\w+).*/$1/;
1517 push @parameterlist, $arg;
1518 if (!$parameterdescs{$arg}) {
1519 $parameterdescs{$arg} = $undescribed;
1520 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1521 "not described in enum '$declaration_name'\n";
1526 output_declaration
($declaration_name,
1528 {'enum' => $declaration_name,
1529 'module' => $modulename,
1530 'parameterlist' => \
@parameterlist,
1531 'parameterdescs' => \
%parameterdescs,
1532 'sectionlist' => \
@sectionlist,
1533 'sections' => \
%sections,
1534 'purpose' => $declaration_purpose
1538 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1543 sub dump_typedef
($$) {
1547 $x =~ s
@/\*.*?\
*/@@gos; # strip comments.
1548 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1549 $x =~ s/\(*.\)\s*;$/;/;
1550 $x =~ s/\[*.\]\s*;$/;/;
1553 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1554 $declaration_name = $1;
1556 output_declaration
($declaration_name,
1558 {'typedef' => $declaration_name,
1559 'module' => $modulename,
1560 'sectionlist' => \
@sectionlist,
1561 'sections' => \
%sections,
1562 'purpose' => $declaration_purpose
1566 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1571 sub save_struct_actual
($) {
1574 # strip all spaces from the actual param so that it looks like one string item
1575 $actual =~ s/\s*//g;
1576 $struct_actual = $struct_actual . $actual . " ";
1579 sub create_parameterlist
($$$) {
1581 my $splitter = shift;
1586 # temporarily replace commas inside function pointer definition
1587 while ($args =~ /(\([^\),]+),/) {
1588 $args =~ s/(\([^\),]+),/$1#/g;
1591 foreach my $arg (split($splitter, $args)) {
1593 $arg =~ s/\/\*.*\*\///;
1594 # strip leading/trailing spaces
1600 # Treat preprocessor directive as a typeless variable just to fill
1601 # corresponding data structures "correctly". Catch it later in
1603 push_parameter
($arg, "", $file);
1604 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1605 # pointer-to-function
1607 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1610 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1611 save_struct_actual
($param);
1612 push_parameter
($param, $type, $file);
1614 $arg =~ s/\s*:\s*/:/g;
1615 $arg =~ s/\s*\[/\[/g;
1617 my @args = split('\s*,\s*', $arg);
1618 if ($args[0] =~ m/\*/) {
1619 $args[0] =~ s/(\*+)\s*/ $1/;
1623 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1625 push(@first_arg, split('\s+', $1));
1626 push(@first_arg, $2);
1628 @first_arg = split('\s+', shift @args);
1631 unshift(@args, pop @first_arg);
1632 $type = join " ", @first_arg;
1634 foreach $param (@args) {
1635 if ($param =~ m/^(\*+)\s*(.*)/) {
1636 save_struct_actual
($2);
1637 push_parameter
($2, "$type $1", $file);
1639 elsif ($param =~ m/(.*?):(\d+)/) {
1640 if ($type ne "") { # skip unnamed bit-fields
1641 save_struct_actual
($1);
1642 push_parameter
($1, "$type:$2", $file)
1646 save_struct_actual
($param);
1647 push_parameter
($param, $type, $file);
1654 sub push_parameter
($$$) {
1659 if (($anon_struct_union == 1) && ($type eq "") &&
1661 return; # ignore the ending }; from anon. struct/union
1664 $anon_struct_union = 0;
1665 my $param_name = $param;
1666 $param_name =~ s/\[.*//;
1668 if ($type eq "" && $param =~ /\.\.\.$/)
1670 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1671 $parameterdescs{$param} = "variable arguments";
1674 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1677 $parameterdescs{void
} = "no arguments";
1679 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1680 # handle unnamed (anonymous) union or struct:
1683 $param = "{unnamed_" . $param . "}";
1684 $parameterdescs{$param} = "anonymous\n";
1685 $anon_struct_union = 1;
1688 # warn if parameter has no description
1689 # (but ignore ones starting with # as these are not parameters
1690 # but inline preprocessor statements);
1691 # also ignore unnamed structs/unions;
1692 if (!$anon_struct_union) {
1693 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1695 $parameterdescs{$param_name} = $undescribed;
1697 if (($type eq 'function') || ($type eq 'enum')) {
1698 print STDERR
"Warning(${file}:$.): Function parameter ".
1699 "or member '$param' not " .
1700 "described in '$declaration_name'\n";
1702 print STDERR
"Warning(${file}:$.):" .
1703 " No description found for parameter '$param'\n";
1708 $param = xml_escape
($param);
1710 # strip spaces from $param so that it is one continous string
1711 # on @parameterlist;
1712 # this fixes a problem where check_sections() cannot find
1713 # a parameter like "addr[6 + 2]" because it actually appears
1714 # as "addr[6", "+", "2]" on the parameter list;
1715 # but it's better to maintain the param string unchanged for output,
1716 # so just weaken the string compare in check_sections() to ignore
1717 # "[blah" in a parameter string;
1718 ###$param =~ s/\s*//g;
1719 push @parameterlist, $param;
1720 $parametertypes{$param} = $type;
1723 sub check_sections
($$$$$$) {
1724 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1725 my @sects = split ' ', $sectcheck;
1726 my @prms = split ' ', $prmscheck;
1729 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1731 foreach $sx (0 .. $#sects) {
1733 foreach $px (0 .. $#prms) {
1734 $prm_clean = $prms[$px];
1735 $prm_clean =~ s/\[.*\]//;
1736 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1737 # ignore array size in a parameter string;
1738 # however, the original param string may contain
1739 # spaces, e.g.: addr[6 + 2]
1740 # and this appears in @prms as "addr[6" since the
1741 # parameter list is split at spaces;
1742 # hence just ignore "[..." for the sections check;
1743 $prm_clean =~ s/\[.*//;
1745 ##$prm_clean =~ s/^\**//;
1746 if ($prm_clean eq $sects[$sx]) {
1752 if ($decl_type eq "function") {
1753 print STDERR
"Warning(${file}:$.): " .
1754 "Excess function parameter " .
1756 "description in '$decl_name'\n";
1759 if ($nested !~ m/\Q$sects[$sx]\E/) {
1760 print STDERR
"Warning(${file}:$.): " .
1761 "Excess struct/union/enum/typedef member " .
1763 "description in '$decl_name'\n";
1772 # takes a function prototype and the name of the current file being
1773 # processed and spits out all the details stored in the global
1775 sub dump_function
($$) {
1776 my $prototype = shift;
1779 $prototype =~ s/^static +//;
1780 $prototype =~ s/^extern +//;
1781 $prototype =~ s/^asmlinkage +//;
1782 $prototype =~ s/^inline +//;
1783 $prototype =~ s/^__inline__ +//;
1784 $prototype =~ s/^__inline +//;
1785 $prototype =~ s/^__always_inline +//;
1786 $prototype =~ s/^noinline +//;
1787 $prototype =~ s/__devinit +//;
1788 $prototype =~ s/__init +//;
1789 $prototype =~ s/__init_or_module +//;
1790 $prototype =~ s/^#\s*define\s+//; #ak added
1791 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1793 # Yes, this truly is vile. We are looking for:
1794 # 1. Return type (may be nothing if we're looking at a macro)
1796 # 3. Function parameters.
1798 # All the while we have to watch out for function pointer parameters
1799 # (which IIRC is what the two sections are for), C types (these
1800 # regexps don't even start to express all the possibilities), and
1803 # If you mess with these regexps, it's a good idea to check that
1804 # the following functions' documentation still comes out right:
1805 # - parport_register_device (function pointer parameters)
1806 # - atomic_set (macro)
1807 # - pci_match_device, __copy_to_user (long return type)
1809 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1810 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1811 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1812 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1813 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1814 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1815 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1816 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1817 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1818 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1819 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1820 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1821 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1822 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1823 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1824 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1825 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1827 $declaration_name = $2;
1830 create_parameterlist
($args, ',', $file);
1832 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1837 my $prms = join " ", @parameterlist;
1838 check_sections
($file, $declaration_name, "function", $sectcheck, $prms, "");
1840 output_declaration
($declaration_name,
1842 {'function' => $declaration_name,
1843 'module' => $modulename,
1844 'functiontype' => $return_type,
1845 'parameterlist' => \
@parameterlist,
1846 'parameterdescs' => \
%parameterdescs,
1847 'parametertypes' => \
%parametertypes,
1848 'sectionlist' => \
@sectionlist,
1849 'sections' => \
%sections,
1850 'purpose' => $declaration_purpose
1854 sub process_file
($);
1856 # Read the file that maps relative names to absolute names for
1857 # separate source and object directories and for shadow trees.
1858 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
1859 my ($relname, $absname);
1860 while(<SOURCE_MAP
>) {
1862 ($relname, $absname) = (split())[0..1];
1863 $relname =~ s
:^/+::;
1864 $source_map{$relname} = $absname;
1873 if ($verbose && $errors) {
1874 print STDERR
"$errors errors\n";
1876 if ($verbose && $warnings) {
1877 print STDERR
"$warnings warnings\n";
1885 %parameterdescs = ();
1886 %parametertypes = ();
1887 @parameterlist = ();
1891 $struct_actual = "";
1897 sub tracepoint_munge
($) {
1899 my $tracepointname = 0;
1900 my $tracepointargs = 0;
1902 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
1903 $tracepointname = $1;
1905 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1906 $tracepointname = $1;
1908 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1909 $tracepointname = $2;
1911 $tracepointname =~ s/^\s+//; #strip leading whitespace
1912 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
1913 $tracepointargs = $1;
1915 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
1916 print STDERR
"Warning(${file}:$.): Unrecognized tracepoint format: \n".
1919 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1923 sub syscall_munge
() {
1926 $prototype =~ s
@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
1927 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1928 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1930 ## $prototype = "long sys_$1(void)";
1933 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1934 if ($prototype =~ m/long (sys_.*?),/) {
1935 $prototype =~ s/,/\(/;
1937 $prototype =~ s/\)/\(void\)/;
1940 # now delete all of the odd-number commas in $prototype
1941 # so that arg types & arg names don't have a comma between them
1943 my $len = length($prototype);
1945 $len = 0; # skip the for-loop
1947 for (my $ix = 0; $ix < $len; $ix++) {
1948 if (substr($prototype, $ix, 1) eq ',') {
1950 if ($count % 2 == 1) {
1951 substr($prototype, $ix, 1) = ' ';
1957 sub process_state3_function
($$) {
1961 $x =~ s
@\/\/.*$@@gos; # strip C99-style comments to end of line
1963 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1966 elsif ($x =~ /([^\{]*)/) {
1970 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
1971 $prototype =~ s
@/\*.*?\
*/@@gos; # strip comments.
1972 $prototype =~ s
@[\r\n]+@ @gos; # strip newlines/cr's.
1973 $prototype =~ s
@^\s+@@gos; # strip leading spaces
1974 if ($prototype =~ /SYSCALL_DEFINE/) {
1977 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1978 $prototype =~ /DEFINE_SINGLE_EVENT/)
1980 tracepoint_munge
($file);
1982 dump_function
($prototype, $file);
1987 sub process_state3_type
($$) {
1991 $x =~ s
@[\r\n]+@ @gos; # strip newlines/cr's.
1992 $x =~ s
@^\s+@@gos; # strip leading spaces
1993 $x =~ s
@\s+$@@gos; # strip trailing spaces
1994 $x =~ s
@\/\/.*$@@gos; # strip C99-style comments to end of line
1997 # To distinguish preprocessor directive from regular declaration later.
2002 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
2003 $prototype .= $1 . $2;
2004 ($2 eq '{') && $brcount++;
2005 ($2 eq '}') && $brcount--;
2006 if (($2 eq ';') && ($brcount == 0)) {
2007 dump_declaration
($prototype, $file);
2019 # xml_escape: replace <, >, and & in the text stream;
2021 # however, formatting controls that are generated internally/locally in the
2022 # kernel-doc script are not escaped here; instead, they begin life like
2023 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2024 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2025 # just before actual output; (this is done by local_unescape())
2028 if (($output_mode eq "text") || ($output_mode eq "man")) {
2031 $text =~ s/\&/\\\\\\amp;/g;
2032 $text =~ s/\</\\\\\\lt;/g;
2033 $text =~ s/\>/\\\\\\gt;/g;
2037 # convert local escape strings to html
2038 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2039 sub local_unescape
($) {
2041 if (($output_mode eq "text") || ($output_mode eq "man")) {
2044 $text =~ s/\\\\\\\\lt:/</g;
2045 $text =~ s/\\\\\\\\gt:/>/g;
2049 sub process_file
($) {
2055 my $initial_section_counter = $section_counter;
2057 if (defined($ENV{'SRCTREE'})) {
2058 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2063 if (defined($source_map{$file})) {
2064 $file = $source_map{$file};
2067 if (!open(IN
,"<$file")) {
2068 print STDERR
"Error: Cannot open file $file\n";
2075 $section_counter = 0;
2078 if (/$doc_start/o) {
2079 $state = 1; # next line is always the function name
2082 } elsif ($state == 1) { # this line is the function name (always)
2083 if (/$doc_block/o) {
2087 $section = $section_intro;
2092 elsif (/$doc_decl/o) {
2094 if (/\s*([\w\s]+?)\s*-/) {
2100 # strip leading/trailing/multiple spaces
2105 $declaration_purpose = xml_escape
($descr);
2108 $declaration_purpose = "";
2111 if (($declaration_purpose eq "") && $verbose) {
2112 print STDERR
"Warning(${file}:$.): missing initial short description on line:\n";
2117 if ($identifier =~ m/^struct/) {
2118 $decl_type = 'struct';
2119 } elsif ($identifier =~ m/^union/) {
2120 $decl_type = 'union';
2121 } elsif ($identifier =~ m/^enum/) {
2122 $decl_type = 'enum';
2123 } elsif ($identifier =~ m/^typedef/) {
2124 $decl_type = 'typedef';
2126 $decl_type = 'function';
2130 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
2133 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
2134 " - I thought it was a doc line\n";
2138 } elsif ($state == 2) { # look for head: lines, and include content
2143 if (($contents ne "") && ($contents ne "\n")) {
2144 if (!$in_doc_sect && $verbose) {
2145 print STDERR
"Warning(${file}:$.): contents before sections\n";
2148 dump_section
($file, $section, xml_escape
($contents));
2149 $section = $section_default;
2154 $contents = $newcontents;
2155 if ($contents ne "") {
2156 while ((substr($contents, 0, 1) eq " ") ||
2157 substr($contents, 0, 1) eq "\t") {
2158 $contents = substr($contents, 1);
2162 $section = $newsection;
2163 } elsif (/$doc_end/) {
2165 if (($contents ne "") && ($contents ne "\n")) {
2166 dump_section
($file, $section, xml_escape
($contents));
2167 $section = $section_default;
2170 # look for doc_com + <text> + doc_end:
2171 if ($_ =~ m
'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2172 print STDERR
"Warning(${file}:$.): suspicious ending line: $_";
2179 # print STDERR "end of doc comment, looking for prototype\n";
2180 } elsif (/$doc_content/) {
2181 # miguel-style comment kludge, look for blank lines after
2182 # @parameter line to signify start of description
2184 if ($section =~ m/^@/ || $section eq $section_context) {
2185 dump_section
($file, $section, xml_escape
($contents));
2186 $section = $section_default;
2192 } elsif ($in_purpose == 1) {
2193 # Continued declaration purpose
2194 chomp($declaration_purpose);
2195 $declaration_purpose .= " " . xml_escape
($1);
2197 $contents .= $1 . "\n";
2200 # i dont know - bad line? ignore.
2201 print STDERR
"Warning(${file}:$.): bad line: $_";
2204 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2205 if ($decl_type eq 'function') {
2206 process_state3_function
($_, $file);
2208 process_state3_type
($_, $file);
2210 } elsif ($state == 4) {
2211 # Documentation block
2213 dump_doc_section
($file, $section, xml_escape
($contents));
2217 %parameterdescs = ();
2218 %parametertypes = ();
2219 @parameterlist = ();
2224 $section = $section_intro;
2231 dump_doc_section
($file, $section, xml_escape
($contents));
2235 %parameterdescs = ();
2236 %parametertypes = ();
2237 @parameterlist = ();
2243 elsif (/$doc_content/)
2247 $contents .= $blankline;
2251 $contents .= $1 . "\n";
2256 if ($initial_section_counter == $section_counter) {
2257 print STDERR
"Warning(${file}): no structured comments found\n";
2258 if ($output_mode eq "xml") {
2259 # The template wants at least one RefEntry here; make one.
2260 print "<refentry>\n";
2261 print " <refnamediv>\n";
2262 print " <refname>\n";
2264 print " </refname>\n";
2265 print " <refpurpose>\n";
2266 print " Document generation inconsistency\n";
2267 print " </refpurpose>\n";
2268 print " </refnamediv>\n";
2269 print " <refsect1>\n";
2272 print " </title>\n";
2273 print " <warning>\n";
2275 print " The template for this document tried to insert\n";
2276 print " the structured comment from the file\n";
2277 print " <filename>${file}</filename> at this point,\n";
2278 print " but none was found.\n";
2279 print " This dummy section is inserted to allow\n";
2280 print " generation to continue.\n";
2282 print " </warning>\n";
2283 print " </refsect1>\n";
2284 print "</refentry>\n";