]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - scripts/kernel-doc
5 ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
6 ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7 ## Copyright (C) 2001 Simon Huggins ##
8 ## Copyright (C) 2005-2012 Randy Dunlap ##
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.
162 my $anon_struct_union = 0;
164 # match expressions used to find embedded type information
165 my $type_constant = '\%([-_\w]+)';
166 my $type_func = '(\w+)\(\)';
167 my $type_param = '\@(\w+)';
168 my $type_struct = '\&((struct\s*)*[_\w]+)';
169 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
170 my $type_env = '(\$\w+)';
172 # Output conversion substitutions.
173 # One for each output format
175 # these work fairly well
176 my %highlights_html = ( $type_constant, "<i>\$1</i>",
177 $type_func, "<b>\$1</b>",
178 $type_struct_xml, "<i>\$1</i>",
179 $type_env, "<b><i>\$1</i></b>",
180 $type_param, "<tt><b>\$1</b></tt>" );
181 my $local_lt = "\\\\\\\\lt:";
182 my $local_gt = "\\\\\\\\gt:";
183 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
185 # XML, docbook format
186 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
187 $type_constant, "<constant>\$1</constant>",
188 $type_func, "<function>\$1</function>",
189 $type_struct_xml, "<structname>\$1</structname>",
190 $type_env, "<envar>\$1</envar>",
191 $type_param, "<parameter>\$1</parameter>" );
192 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
194 # gnome, docbook format
195 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
196 $type_func, "<function>\$1</function>",
197 $type_struct, "<structname>\$1</structname>",
198 $type_env, "<envar>\$1</envar>",
199 $type_param, "<parameter>\$1</parameter>" );
200 my $blankline_gnome = "</para><para>\n";
202 # these are pretty rough
203 my %highlights_man = ( $type_constant, "\$1",
204 $type_func, "\\\\fB\$1\\\\fP",
205 $type_struct, "\\\\fI\$1\\\\fP",
206 $type_param, "\\\\fI\$1\\\\fP" );
207 my $blankline_man = "";
210 my %highlights_text = ( $type_constant, "\$1",
213 $type_param, "\$1" );
214 my $blankline_text = "";
217 my %highlights_list = ( $type_constant, "\$1",
220 $type_param, "\$1" );
221 my $blankline_list = "";
229 my $dohighlight = "";
232 my $output_mode = "man";
233 my $output_preformatted = 0;
234 my $no_doc_sections = 0;
235 my %highlights = %highlights_man;
236 my $blankline = $blankline_man;
237 my $modulename = "Kernel API";
238 my $function_only = 0;
239 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
240 'July', 'August', 'September', 'October',
241 'November', 'December')[(localtime)[4]] .
242 " " . ((localtime)[5]+1900);
244 # Essentially these are globals.
245 # They probably want to be tidied up, made more localised or something.
246 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
247 # could cause "use of undefined value" or other bugs.
248 my ($function, %function_table, %parametertypes, $declaration_purpose);
249 my ($type, $declaration_name, $return_type);
250 my ($newsection, $newcontents, $prototype, $brcount, %source_map);
252 if (defined($ENV{'KBUILD_VERBOSE'})) {
253 $verbose = "$ENV{'KBUILD_VERBOSE'}";
256 # Generated docbook code is inserted in a template at a point where
257 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
258 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
259 # We keep track of number of generated entries and generate a dummy
260 # if needs be to ensure the expanded template can be postprocessed
262 my $section_counter = 0;
268 # 1 - looking for function name
269 # 2 - scanning field start.
270 # 3 - scanning prototype.
271 # 4 - documentation block
275 #declaration types: can be
276 # 'function', 'struct', 'union', 'enum', 'typedef'
279 my $doc_special = "\@\%\$\&";
281 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
283 my $doc_com = '\s*\*\s*';
284 my $doc_decl = $doc_com . '(\w+)';
285 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
286 my $doc_content = $doc_com . '(.*)';
287 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
298 my $section_default = "Description"; # default section
299 my $section_intro = "Introduction";
300 my $section = $section_default;
301 my $section_context = "Context";
303 my $undescribed = "-- undescribed --";
307 while ($ARGV[0] =~ m/^-(.*)/) {
308 my $cmd = shift @ARGV;
309 if ($cmd eq "-html") {
310 $output_mode = "html";
311 %highlights = %highlights_html;
312 $blankline = $blankline_html;
313 } elsif ($cmd eq "-man") {
314 $output_mode = "man";
315 %highlights = %highlights_man;
316 $blankline = $blankline_man;
317 } elsif ($cmd eq "-text") {
318 $output_mode = "text";
319 %highlights = %highlights_text;
320 $blankline = $blankline_text;
321 } elsif ($cmd eq "-docbook") {
322 $output_mode = "xml";
323 %highlights = %highlights_xml;
324 $blankline = $blankline_xml;
325 } elsif ($cmd eq "-list") {
326 $output_mode = "list";
327 %highlights = %highlights_list;
328 $blankline = $blankline_list;
329 } elsif ($cmd eq "-gnome") {
330 $output_mode = "gnome";
331 %highlights = %highlights_gnome;
332 $blankline = $blankline_gnome;
333 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
334 $modulename = shift @ARGV;
335 } elsif ($cmd eq "-function") { # to only output specific functions
337 $function = shift @ARGV;
338 $function_table{$function} = 1;
339 } elsif ($cmd eq "-nofunction") { # to only output specific functions
341 $function = shift @ARGV;
342 $function_table{$function} = 1;
343 } elsif ($cmd eq "-v") {
345 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
347 } elsif ($cmd eq '-no-doc-sections') {
348 $no_doc_sections = 1;
352 # continue execution near EOF;
355 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n";
356 print " [ -no-doc-sections ]\n";
357 print " [ -function funcname [ -function funcname ...] ]\n";
358 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
359 print " c source file(s) > outputfile\n";
360 print " -v : verbose output, more warnings & other info listed\n";
364 # get kernel version from env
365 sub get_kernel_version
() {
366 my $version = 'unknown kernel version';
368 if (defined($ENV{'KERNELVERSION'})) {
369 $version = $ENV{'KERNELVERSION'};
375 # dumps section contents to arrays/hashes intended for that purpose.
380 my $contents = join "\n", @_;
382 if ($name =~ m/$type_constant/) {
384 # print STDERR "constant section '$1' = '$contents'\n";
385 $constants{$name} = $contents;
386 } elsif ($name =~ m/$type_param/) {
387 # print STDERR "parameter def '$1' = '$contents'\n";
389 $parameterdescs{$name} = $contents;
390 $sectcheck = $sectcheck . $name . " ";
391 } elsif ($name eq "@\.\.\.") {
392 # print STDERR "parameter def '...' = '$contents'\n";
394 $parameterdescs{$name} = $contents;
395 $sectcheck = $sectcheck . $name . " ";
397 # print STDERR "other section '$name' = '$contents'\n";
398 if (defined($sections{$name}) && ($sections{$name} ne "")) {
399 print STDERR
"Error(${file}:$.): duplicate section name '$name'\n";
402 $sections{$name} = $contents;
403 push @sectionlist, $name;
408 # dump DOC: section after checking that it should go out
410 sub dump_doc_section
{
413 my $contents = join "\n", @_;
415 if ($no_doc_sections) {
419 if (($function_only == 0) ||
420 ( $function_only == 1 && defined($function_table{$name})) ||
421 ( $function_only == 2 && !defined($function_table{$name})))
423 dump_section
($file, $name, $contents);
424 output_blockhead
({'sectionlist' => \
@sectionlist,
425 'sections' => \
%sections,
426 'module' => $modulename,
427 'content-only' => ($function_only != 0), });
434 # parameterdescs, a hash.
435 # function => "function name"
436 # parameterlist => @list of parameters
437 # parameterdescs => %parameter descriptions
438 # sectionlist => @list of sections
439 # sections => %section descriptions
442 sub output_highlight
{
443 my $contents = join "\n",@_;
447 # if (!defined $contents) {
449 # confess "output_highlight got called with no args?\n";
452 if ($output_mode eq "html" || $output_mode eq "xml") {
453 $contents = local_unescape
($contents);
454 # convert data read & converted thru xml_escape() into &xyz; format:
455 $contents =~ s/\\\\\\/\&/g;
457 # print STDERR "contents b4:$contents\n";
460 # print STDERR "contents af:$contents\n";
462 foreach $line (split "\n", $contents) {
464 if (! $output_preformatted) {
465 print $lineprefix, local_unescape
($blankline);
468 $line =~ s/\\\\\\/\&/g;
469 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
472 print $lineprefix, $line;
479 #output sections in html
480 sub output_section_html
(%) {
484 foreach $section (@{$args{'sectionlist'}}) {
485 print "<h3>$section</h3>\n";
486 print "<blockquote>\n";
487 output_highlight
($args{'sections'}{$section});
488 print "</blockquote>\n";
492 # output enum in html
493 sub output_enum_html
(%) {
497 print "<h2>enum " . $args{'enum'} . "</h2>\n";
499 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
501 foreach $parameter (@{$args{'parameterlist'}}) {
502 print " <b>" . $parameter . "</b>";
503 if ($count != $#{$args{'parameterlist'}}) {
511 print "<h3>Constants</h3>\n";
513 foreach $parameter (@{$args{'parameterlist'}}) {
514 print "<dt><b>" . $parameter . "</b>\n";
516 output_highlight
($args{'parameterdescs'}{$parameter});
519 output_section_html
(@_);
523 # output typedef in html
524 sub output_typedef_html
(%) {
528 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
530 print "<b>typedef " . $args{'typedef'} . "</b>\n";
531 output_section_html
(@_);
535 # output struct in html
536 sub output_struct_html
(%) {
540 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
541 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
542 foreach $parameter (@{$args{'parameterlist'}}) {
543 if ($parameter =~ /^#/) {
544 print "$parameter<br>\n";
547 my $parameter_name = $parameter;
548 $parameter_name =~ s/\[.*//;
550 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
551 $type = $args{'parametertypes'}{$parameter};
552 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
553 # pointer-to-function
554 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
555 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
557 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
559 print " <i>$type</i> <b>$parameter</b>;<br>\n";
564 print "<h3>Members</h3>\n";
566 foreach $parameter (@{$args{'parameterlist'}}) {
567 ($parameter =~ /^#/) && next;
569 my $parameter_name = $parameter;
570 $parameter_name =~ s/\[.*//;
572 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
573 print "<dt><b>" . $parameter . "</b>\n";
575 output_highlight
($args{'parameterdescs'}{$parameter_name});
578 output_section_html
(@_);
582 # output function in html
583 sub output_function_html
(%) {
585 my ($parameter, $section);
588 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
589 print "<i>" . $args{'functiontype'} . "</i>\n";
590 print "<b>" . $args{'function'} . "</b>\n";
593 foreach $parameter (@{$args{'parameterlist'}}) {
594 $type = $args{'parametertypes'}{$parameter};
595 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
596 # pointer-to-function
597 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
599 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
601 if ($count != $#{$args{'parameterlist'}}) {
608 print "<h3>Arguments</h3>\n";
610 foreach $parameter (@{$args{'parameterlist'}}) {
611 my $parameter_name = $parameter;
612 $parameter_name =~ s/\[.*//;
614 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
615 print "<dt><b>" . $parameter . "</b>\n";
617 output_highlight
($args{'parameterdescs'}{$parameter_name});
620 output_section_html
(@_);
624 # output DOC: block header in html
625 sub output_blockhead_html
(%) {
627 my ($parameter, $section);
630 foreach $section (@{$args{'sectionlist'}}) {
631 print "<h3>$section</h3>\n";
633 output_highlight
($args{'sections'}{$section});
639 sub output_section_xml
(%) {
642 # print out each section
644 foreach $section (@{$args{'sectionlist'}}) {
645 print "<refsect1>\n";
646 print "<title>$section</title>\n";
647 if ($section =~ m/EXAMPLE/i) {
648 print "<informalexample><programlisting>\n";
649 $output_preformatted = 1;
653 output_highlight
($args{'sections'}{$section});
654 $output_preformatted = 0;
655 if ($section =~ m/EXAMPLE/i) {
656 print "</programlisting></informalexample>\n";
660 print "</refsect1>\n";
664 # output function in XML DocBook
665 sub output_function_xml
(%) {
667 my ($parameter, $section);
671 $id = "API-" . $args{'function'};
672 $id =~ s/[^A-Za-z0-9]/-/g;
674 print "<refentry id=\"$id\">\n";
675 print "<refentryinfo
>\n";
676 print " <title
>LINUX
</title
>\n";
677 print " <productname
>Kernel Hackers Manual
</productname
>\n";
678 print " <date
>$man_date</date
>\n";
679 print "</refentryinfo
>\n";
681 print " <refentrytitle
><phrase
>" . $args{'function'} . "</phrase></refentrytitle
>\n";
682 print " <manvolnum
>9</manvolnum
>\n";
683 print " <refmiscinfo
class=\"version
\">" . $kernelversion . "</refmiscinfo
>\n";
684 print "</refmeta
>\n";
685 print "<refnamediv
>\n";
686 print " <refname
>" . $args{'function'} . "</refname
>\n";
687 print " <refpurpose
>\n";
689 output_highlight ($args{'purpose'});
690 print " </refpurpose
>\n";
691 print "</refnamediv
>\n";
693 print "<refsynopsisdiv
>\n";
694 print " <title
>Synopsis
</title
>\n";
695 print " <funcsynopsis
><funcprototype
>\n";
696 print " <funcdef
>" . $args{'functiontype'} . " ";
697 print "<function
>" . $args{'function'} . " </function></funcdef
>\n";
700 if ($#{$args{'parameterlist'}} >= 0) {
701 foreach $parameter (@{$args{'parameterlist'}}) {
702 $type = $args{'parametertypes'}{$parameter};
703 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
704 # pointer-to-function
705 print " <paramdef
>$1<parameter
>$parameter</parameter
>)\n";
706 print " <funcparams
>$2</funcparams></paramdef
>\n";
708 print " <paramdef
>" . $type;
709 print " <parameter
>$parameter</parameter></paramdef
>\n";
715 print " </funcprototype></funcsynopsis
>\n";
716 print "</refsynopsisdiv
>\n";
719 print "<refsect1
>\n <title
>Arguments
</title
>\n";
720 if ($#{$args{'parameterlist'}} >= 0) {
721 print " <variablelist
>\n";
722 foreach $parameter (@{$args{'parameterlist'}}) {
723 my $parameter_name = $parameter;
724 $parameter_name =~ s/\[.*//;
726 print " <varlistentry
>\n <term
><parameter
>$parameter</parameter></term
>\n";
727 print " <listitem
>\n <para
>\n";
729 output_highlight($args{'parameterdescs'}{$parameter_name});
730 print " </para>\n </listitem
>\n </varlistentry
>\n";
732 print " </variablelist
>\n";
734 print " <para
>\n None
\n </para
>\n";
736 print "</refsect1
>\n";
738 output_section_xml(@_);
739 print "</refentry
>\n\n";
742 # output struct in XML DocBook
743 sub output_struct_xml(%) {
745 my ($parameter, $section);
748 $id = "API-struct-
" . $args{'struct'};
749 $id =~ s/[^A-Za-z0-9]/-/g;
751 print "<refentry id
=\"$id\">\n";
752 print "<refentryinfo>\n";
753 print " <title>LINUX</title>\n";
754 print " <productname>Kernel Hackers Manual</productname>\n";
755 print " <date>$man_date</date>\n";
756 print "</refentryinfo>\n";
758 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
759 print " <manvolnum>9</manvolnum>\n";
760 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
761 print "</refmeta>\n";
762 print "<refnamediv>\n";
763 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
764 print " <refpurpose>\n";
766 output_highlight
($args{'purpose'});
767 print " </refpurpose>\n";
768 print "</refnamediv>\n";
770 print "<refsynopsisdiv>\n";
771 print " <title>Synopsis</title>\n";
772 print " <programlisting>\n";
773 print $args{'type'} . " " . $args{'struct'} . " {\n";
774 foreach $parameter (@{$args{'parameterlist'}}) {
775 if ($parameter =~ /^#/) {
776 my $prm = $parameter;
777 # convert data read & converted thru xml_escape() into &xyz; format:
778 # This allows us to have #define macros interspersed in a struct.
779 $prm =~ s/\\\\\\/\&/g;
784 my $parameter_name = $parameter;
785 $parameter_name =~ s/\[.*//;
787 defined($args{'parameterdescs'}{$parameter_name}) || next;
788 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
789 $type = $args{'parametertypes'}{$parameter};
790 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
791 # pointer-to-function
792 print " $1 $parameter) ($2);\n";
793 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
795 print " $1 $parameter$2;\n";
797 print " " . $type . " " . $parameter . ";\n";
801 print " </programlisting>\n";
802 print "</refsynopsisdiv>\n";
804 print " <refsect1>\n";
805 print " <title>Members</title>\n";
807 if ($#{$args{'parameterlist'}} >= 0) {
808 print " <variablelist>\n";
809 foreach $parameter (@{$args{'parameterlist'}}) {
810 ($parameter =~ /^#/) && next;
812 my $parameter_name = $parameter;
813 $parameter_name =~ s/\[.*//;
815 defined($args{'parameterdescs'}{$parameter_name}) || next;
816 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
817 print " <varlistentry>";
818 print " <term>$parameter</term>\n";
819 print " <listitem><para>\n";
820 output_highlight
($args{'parameterdescs'}{$parameter_name});
821 print " </para></listitem>\n";
822 print " </varlistentry>\n";
824 print " </variablelist>\n";
826 print " <para>\n None\n </para>\n";
828 print " </refsect1>\n";
830 output_section_xml
(@_);
832 print "</refentry>\n\n";
835 # output enum in XML DocBook
836 sub output_enum_xml
(%) {
838 my ($parameter, $section);
842 $id = "API-enum-" . $args{'enum'};
843 $id =~ s/[^A-Za-z0-9]/-/g;
845 print "<refentry id=\"$id\">\n";
846 print "<refentryinfo
>\n";
847 print " <title
>LINUX
</title
>\n";
848 print " <productname
>Kernel Hackers Manual
</productname
>\n";
849 print " <date
>$man_date</date
>\n";
850 print "</refentryinfo
>\n";
852 print " <refentrytitle
><phrase
>enum
" . $args{'enum'} . "</phrase></refentrytitle
>\n";
853 print " <manvolnum
>9</manvolnum
>\n";
854 print " <refmiscinfo
class=\"version
\">" . $kernelversion . "</refmiscinfo
>\n";
855 print "</refmeta
>\n";
856 print "<refnamediv
>\n";
857 print " <refname
>enum
" . $args{'enum'} . "</refname
>\n";
858 print " <refpurpose
>\n";
860 output_highlight ($args{'purpose'});
861 print " </refpurpose
>\n";
862 print "</refnamediv
>\n";
864 print "<refsynopsisdiv
>\n";
865 print " <title
>Synopsis
</title
>\n";
866 print " <programlisting
>\n";
867 print "enum
" . $args{'enum'} . " {\n";
869 foreach $parameter (@{$args{'parameterlist'}}) {
871 if ($count != $#{$args{'parameterlist'}}) {
878 print " </programlisting
>\n";
879 print "</refsynopsisdiv
>\n";
881 print "<refsect1
>\n";
882 print " <title
>Constants
</title
>\n";
883 print " <variablelist
>\n";
884 foreach $parameter (@{$args{'parameterlist'}}) {
885 my $parameter_name = $parameter;
886 $parameter_name =~ s/\[.*//;
888 print " <varlistentry
>";
889 print " <term
>$parameter</term
>\n";
890 print " <listitem
><para
>\n";
891 output_highlight($args{'parameterdescs'}{$parameter_name});
892 print " </para></listitem
>\n";
893 print " </varlistentry
>\n";
895 print " </variablelist
>\n";
896 print "</refsect1
>\n";
898 output_section_xml(@_);
900 print "</refentry
>\n\n";
903 # output typedef in XML DocBook
904 sub output_typedef_xml(%) {
906 my ($parameter, $section);
909 $id = "API-typedef-
" . $args{'typedef'};
910 $id =~ s/[^A-Za-z0-9]/-/g;
912 print "<refentry id
=\"$id\">\n";
913 print "<refentryinfo>\n";
914 print " <title>LINUX</title>\n";
915 print " <productname>Kernel Hackers Manual</productname>\n";
916 print " <date>$man_date</date>\n";
917 print "</refentryinfo>\n";
919 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
920 print " <manvolnum>9</manvolnum>\n";
921 print "</refmeta>\n";
922 print "<refnamediv>\n";
923 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
924 print " <refpurpose>\n";
926 output_highlight
($args{'purpose'});
927 print " </refpurpose>\n";
928 print "</refnamediv>\n";
930 print "<refsynopsisdiv>\n";
931 print " <title>Synopsis</title>\n";
932 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
933 print "</refsynopsisdiv>\n";
935 output_section_xml
(@_);
937 print "</refentry>\n\n";
940 # output in XML DocBook
941 sub output_blockhead_xml
(%) {
943 my ($parameter, $section);
946 my $id = $args{'module'};
947 $id =~ s/[^A-Za-z0-9]/-/g;
949 # print out each section
951 foreach $section (@{$args{'sectionlist'}}) {
952 if (!$args{'content-only'}) {
953 print "<refsect1>\n <title>$section</title>\n";
955 if ($section =~ m/EXAMPLE/i) {
956 print "<example><para>\n";
957 $output_preformatted = 1;
961 output_highlight
($args{'sections'}{$section});
962 $output_preformatted = 0;
963 if ($section =~ m/EXAMPLE/i) {
964 print "</para></example>\n";
968 if (!$args{'content-only'}) {
969 print "\n</refsect1>\n";
976 # output in XML DocBook
977 sub output_function_gnome
{
979 my ($parameter, $section);
983 $id = $args{'module'} . "-" . $args{'function'};
984 $id =~ s/[^A-Za-z0-9]/-/g;
987 print " <title id=\"$id\">" . $args{'function'} . "</title
>\n";
989 print " <funcsynopsis
>\n";
990 print " <funcdef
>" . $args{'functiontype'} . " ";
991 print "<function
>" . $args{'function'} . " ";
992 print "</function></funcdef
>\n";
995 if ($#{$args{'parameterlist'}} >= 0) {
996 foreach $parameter (@{$args{'parameterlist'}}) {
997 $type = $args{'parametertypes'}{$parameter};
998 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
999 # pointer-to-function
1000 print " <paramdef
>$1 <parameter
>$parameter</parameter
>)\n";
1001 print " <funcparams
>$2</funcparams></paramdef
>\n";
1003 print " <paramdef
>" . $type;
1004 print " <parameter
>$parameter</parameter></paramdef
>\n";
1010 print " </funcsynopsis
>\n";
1011 if ($#{$args{'parameterlist'}} >= 0) {
1012 print " <informaltable pgwide
=\"1\" frame
=\"none
\" role=\"params
\">\n";
1013 print "<tgroup cols
=\"2\">\n";
1014 print "<colspec colwidth
=\"2*\">\n";
1015 print "<colspec colwidth
=\"8*\">\n";
1017 foreach $parameter (@{$args{'parameterlist'}}) {
1018 my $parameter_name = $parameter;
1019 $parameter_name =~ s/\[.*//;
1021 print " <row
><entry align
=\"right
\"><parameter
>$parameter</parameter></entry
>\n";
1024 output_highlight($args{'parameterdescs'}{$parameter_name});
1025 print " </entry></row
>\n";
1027 print " </tbody></tgroup
></informaltable
>\n";
1029 print " <para
>\n None
\n </para
>\n";
1032 # print out each section
1034 foreach $section (@{$args{'sectionlist'}}) {
1035 print "<simplesect
>\n <title
>$section</title
>\n";
1036 if ($section =~ m/EXAMPLE/i) {
1037 print "<example
><programlisting
>\n";
1038 $output_preformatted = 1;
1042 output_highlight($args{'sections'}{$section});
1043 $output_preformatted = 0;
1045 if ($section =~ m/EXAMPLE/i) {
1046 print "</programlisting></example
>\n";
1049 print " </simplesect
>\n";
1052 print "</sect2
>\n\n";
1056 # output function in man
1057 sub output_function_man(%) {
1058 my %args = %{$_[0]};
1059 my ($parameter, $section);
1062 print ".TH
\"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1065 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1067 print ".SH SYNOPSIS\n";
1068 if ($args{'functiontype'} ne "") {
1069 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1071 print ".B \"" . $args{'function'} . "\n";
1076 foreach my $parameter (@{$args{'parameterlist'}}) {
1077 if ($count == $#{$args{'parameterlist'}}) {
1080 $type = $args{'parametertypes'}{$parameter};
1081 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1082 # pointer-to-function
1083 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1085 $type =~ s/([^\*])$/$1 /;
1086 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1092 print ".SH ARGUMENTS\n";
1093 foreach $parameter (@{$args{'parameterlist'}}) {
1094 my $parameter_name = $parameter;
1095 $parameter_name =~ s/\[.*//;
1097 print ".IP \"" . $parameter . "\" 12\n";
1098 output_highlight
($args{'parameterdescs'}{$parameter_name});
1100 foreach $section (@{$args{'sectionlist'}}) {
1101 print ".SH \"", uc $section, "\"\n";
1102 output_highlight
($args{'sections'}{$section});
1107 # output enum in man
1108 sub output_enum_man
(%) {
1109 my %args = %{$_[0]};
1110 my ($parameter, $section);
1113 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual
\" LINUX
\n";
1116 print "enum
" . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1118 print ".SH SYNOPSIS
\n";
1119 print "enum
" . $args{'enum'} . " {\n";
1121 foreach my $parameter (@{$args{'parameterlist'}}) {
1122 print ".br
\n.BI
\" $parameter\"\n";
1123 if ($count == $#{$args{'parameterlist'}}) {
1133 print ".SH Constants\n";
1134 foreach $parameter (@{$args{'parameterlist'}}) {
1135 my $parameter_name = $parameter;
1136 $parameter_name =~ s/\[.*//;
1138 print ".IP \"" . $parameter . "\" 12\n";
1139 output_highlight
($args{'parameterdescs'}{$parameter_name});
1141 foreach $section (@{$args{'sectionlist'}}) {
1142 print ".SH \"$section\"\n";
1143 output_highlight($args{'sections'}{$section});
1148 # output struct in man
1149 sub output_struct_man(%) {
1150 my %args = %{$_[0]};
1151 my ($parameter, $section);
1153 print ".TH
\"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1156 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1158 print ".SH SYNOPSIS\n";
1159 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1161 foreach my $parameter (@{$args{'parameterlist'}}) {
1162 if ($parameter =~ /^#/) {
1163 print ".BI \"$parameter\"\n.br
\n";
1166 my $parameter_name = $parameter;
1167 $parameter_name =~ s/\[.*//;
1169 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1170 $type = $args{'parametertypes'}{$parameter};
1171 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1172 # pointer-to-function
1173 print ".BI
\" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1174 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1176 print ".BI
\" " . $1 . "\
\" " . $parameter . $2 . " \"" . "\"\n;\n";
1178 $type =~ s/([^\*])$/$1 /;
1179 print ".BI
\" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1185 print ".SH Members
\n";
1186 foreach $parameter (@{$args{'parameterlist'}}) {
1187 ($parameter =~ /^#/) && next;
1189 my $parameter_name = $parameter;
1190 $parameter_name =~ s/\[.*//;
1192 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1193 print ".IP
\"" . $parameter . "\" 12\n";
1194 output_highlight($args{'parameterdescs'}{$parameter_name});
1196 foreach $section (@{$args{'sectionlist'}}) {
1197 print ".SH
\"$section\"\n";
1198 output_highlight
($args{'sections'}{$section});
1203 # output typedef in man
1204 sub output_typedef_man
(%) {
1205 my %args = %{$_[0]};
1206 my ($parameter, $section);
1208 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual
\" LINUX
\n";
1211 print "typedef
" . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1213 foreach $section (@{$args{'sectionlist'}}) {
1214 print ".SH
\"$section\"\n";
1215 output_highlight
($args{'sections'}{$section});
1219 sub output_blockhead_man
(%) {
1220 my %args = %{$_[0]};
1221 my ($parameter, $section);
1224 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual
\" LINUX
\n";
1226 foreach $section (@{$args{'sectionlist'}}) {
1227 print ".SH
\"$section\"\n";
1228 output_highlight
($args{'sections'}{$section});
1234 sub output_function_text
(%) {
1235 my %args = %{$_[0]};
1236 my ($parameter, $section);
1240 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1242 print "\nSynopsis:\n\n";
1243 if ($args{'functiontype'} ne "") {
1244 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1246 $start = $args{'function'} . " (";
1251 foreach my $parameter (@{$args{'parameterlist'}}) {
1252 $type = $args{'parametertypes'}{$parameter};
1253 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1254 # pointer-to-function
1255 print $1 . $parameter . ") (" . $2;
1257 print $type . " " . $parameter;
1259 if ($count != $#{$args{'parameterlist'}}) {
1262 print " " x
length($start);
1268 print "Arguments:\n\n";
1269 foreach $parameter (@{$args{'parameterlist'}}) {
1270 my $parameter_name = $parameter;
1271 $parameter_name =~ s/\[.*//;
1273 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1275 output_section_text
(@_);
1278 #output sections in text
1279 sub output_section_text
(%) {
1280 my %args = %{$_[0]};
1284 foreach $section (@{$args{'sectionlist'}}) {
1285 print "$section:\n\n";
1286 output_highlight
($args{'sections'}{$section});
1291 # output enum in text
1292 sub output_enum_text
(%) {
1293 my %args = %{$_[0]};
1298 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1299 print "enum " . $args{'enum'} . " {\n";
1301 foreach $parameter (@{$args{'parameterlist'}}) {
1302 print "\t$parameter";
1303 if ($count != $#{$args{'parameterlist'}}) {
1311 print "Constants:\n\n";
1312 foreach $parameter (@{$args{'parameterlist'}}) {
1313 print "$parameter\n\t";
1314 print $args{'parameterdescs'}{$parameter} . "\n";
1317 output_section_text
(@_);
1320 # output typedef in text
1321 sub output_typedef_text
(%) {
1322 my %args = %{$_[0]};
1325 print "Typedef:\n\n";
1327 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1328 output_section_text
(@_);
1331 # output struct as text
1332 sub output_struct_text
(%) {
1333 my %args = %{$_[0]};
1336 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1337 print $args{'type'} . " " . $args{'struct'} . " {\n";
1338 foreach $parameter (@{$args{'parameterlist'}}) {
1339 if ($parameter =~ /^#/) {
1340 print "$parameter\n";
1344 my $parameter_name = $parameter;
1345 $parameter_name =~ s/\[.*//;
1347 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1348 $type = $args{'parametertypes'}{$parameter};
1349 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1350 # pointer-to-function
1351 print "\t$1 $parameter) ($2);\n";
1352 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1354 print "\t$1 $parameter$2;\n";
1356 print "\t" . $type . " " . $parameter . ";\n";
1361 print "Members:\n\n";
1362 foreach $parameter (@{$args{'parameterlist'}}) {
1363 ($parameter =~ /^#/) && next;
1365 my $parameter_name = $parameter;
1366 $parameter_name =~ s/\[.*//;
1368 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1369 print "$parameter\n\t";
1370 print $args{'parameterdescs'}{$parameter_name} . "\n";
1373 output_section_text
(@_);
1376 sub output_blockhead_text
(%) {
1377 my %args = %{$_[0]};
1378 my ($parameter, $section);
1380 foreach $section (@{$args{'sectionlist'}}) {
1381 print " $section:\n";
1383 output_highlight
($args{'sections'}{$section});
1387 ## list mode output functions
1389 sub output_function_list
(%) {
1390 my %args = %{$_[0]};
1392 print $args{'function'} . "\n";
1395 # output enum in list
1396 sub output_enum_list
(%) {
1397 my %args = %{$_[0]};
1398 print $args{'enum'} . "\n";
1401 # output typedef in list
1402 sub output_typedef_list
(%) {
1403 my %args = %{$_[0]};
1404 print $args{'typedef'} . "\n";
1407 # output struct as list
1408 sub output_struct_list
(%) {
1409 my %args = %{$_[0]};
1411 print $args{'struct'} . "\n";
1414 sub output_blockhead_list
(%) {
1415 my %args = %{$_[0]};
1416 my ($parameter, $section);
1418 foreach $section (@{$args{'sectionlist'}}) {
1419 print "DOC: $section\n";
1424 # generic output function for all types (function, struct/union, typedef, enum);
1425 # calls the generated, variable output_ function name based on
1426 # functype and output_mode
1427 sub output_declaration
{
1430 my $functype = shift;
1431 my $func = "output_${functype}_$output_mode";
1432 if (($function_only==0) ||
1433 ( $function_only == 1 && defined($function_table{$name})) ||
1434 ( $function_only == 2 && !defined($function_table{$name})))
1442 # generic output function - calls the right one based on current output mode.
1443 sub output_blockhead
{
1445 my $func = "output_blockhead_" . $output_mode;
1451 # takes a declaration (struct, union, enum, typedef) and
1452 # invokes the right handler. NOT called for functions.
1453 sub dump_declaration
($$) {
1455 my ($prototype, $file) = @_;
1456 my $func = "dump_" . $decl_type;
1460 sub dump_union
($$) {
1464 sub dump_struct
($$) {
1469 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1470 #my $decl_type = $1;
1471 $declaration_name = $2;
1474 # ignore embedded structs or unions
1475 $members =~ s/({.*})//g;
1478 # ignore members marked private:
1479 $members =~ s/\/\*\s*private:.*?\/\
*\s
*public
:.*?\
*\
///gos
;
1480 $members =~ s/\/\*\s*private:.*//gos
;
1482 $members =~ s/\/\*.*?\*\///gos;
1483 $nested =~ s/\/\*.*?\*\///gos;
1484 # strip kmemcheck_bitfield_{begin,end}.*;
1485 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1487 $members =~ s/__aligned\s*\(\d+\)//gos;
1489 create_parameterlist
($members, ';', $file);
1490 check_sections
($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1492 output_declaration
($declaration_name,
1494 {'struct' => $declaration_name,
1495 'module' => $modulename,
1496 'parameterlist' => \
@parameterlist,
1497 'parameterdescs' => \
%parameterdescs,
1498 'parametertypes' => \
%parametertypes,
1499 'sectionlist' => \
@sectionlist,
1500 'sections' => \
%sections,
1501 'purpose' => $declaration_purpose,
1502 'type' => $decl_type
1506 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1515 $x =~ s
@/\*.*?\
*/@@gos; # strip comments.
1516 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1518 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1519 $declaration_name = $1;
1522 foreach my $arg (split ',', $members) {
1523 $arg =~ s/^\s*(\w+).*/$1/;
1524 push @parameterlist, $arg;
1525 if (!$parameterdescs{$arg}) {
1526 $parameterdescs{$arg} = $undescribed;
1527 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1528 "not described in enum '$declaration_name'\n";
1533 output_declaration
($declaration_name,
1535 {'enum' => $declaration_name,
1536 'module' => $modulename,
1537 'parameterlist' => \
@parameterlist,
1538 'parameterdescs' => \
%parameterdescs,
1539 'sectionlist' => \
@sectionlist,
1540 'sections' => \
%sections,
1541 'purpose' => $declaration_purpose
1545 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1550 sub dump_typedef
($$) {
1554 $x =~ s
@/\*.*?\
*/@@gos; # strip comments.
1555 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1556 $x =~ s/\(*.\)\s*;$/;/;
1557 $x =~ s/\[*.\]\s*;$/;/;
1560 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1561 $declaration_name = $1;
1563 output_declaration
($declaration_name,
1565 {'typedef' => $declaration_name,
1566 'module' => $modulename,
1567 'sectionlist' => \
@sectionlist,
1568 'sections' => \
%sections,
1569 'purpose' => $declaration_purpose
1573 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1578 sub save_struct_actual
($) {
1581 # strip all spaces from the actual param so that it looks like one string item
1582 $actual =~ s/\s*//g;
1583 $struct_actual = $struct_actual . $actual . " ";
1586 sub create_parameterlist
($$$) {
1588 my $splitter = shift;
1593 # temporarily replace commas inside function pointer definition
1594 while ($args =~ /(\([^\),]+),/) {
1595 $args =~ s/(\([^\),]+),/$1#/g;
1598 foreach my $arg (split($splitter, $args)) {
1600 $arg =~ s/\/\*.*\*\///;
1601 # strip leading/trailing spaces
1607 # Treat preprocessor directive as a typeless variable just to fill
1608 # corresponding data structures "correctly". Catch it later in
1610 push_parameter
($arg, "", $file);
1611 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1612 # pointer-to-function
1614 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1617 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1618 save_struct_actual
($param);
1619 push_parameter
($param, $type, $file);
1621 $arg =~ s/\s*:\s*/:/g;
1622 $arg =~ s/\s*\[/\[/g;
1624 my @args = split('\s*,\s*', $arg);
1625 if ($args[0] =~ m/\*/) {
1626 $args[0] =~ s/(\*+)\s*/ $1/;
1630 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1632 push(@first_arg, split('\s+', $1));
1633 push(@first_arg, $2);
1635 @first_arg = split('\s+', shift @args);
1638 unshift(@args, pop @first_arg);
1639 $type = join " ", @first_arg;
1641 foreach $param (@args) {
1642 if ($param =~ m/^(\*+)\s*(.*)/) {
1643 save_struct_actual
($2);
1644 push_parameter
($2, "$type $1", $file);
1646 elsif ($param =~ m/(.*?):(\d+)/) {
1647 if ($type ne "") { # skip unnamed bit-fields
1648 save_struct_actual
($1);
1649 push_parameter
($1, "$type:$2", $file)
1653 save_struct_actual
($param);
1654 push_parameter
($param, $type, $file);
1661 sub push_parameter
($$$) {
1666 if (($anon_struct_union == 1) && ($type eq "") &&
1668 return; # ignore the ending }; from anon. struct/union
1671 $anon_struct_union = 0;
1672 my $param_name = $param;
1673 $param_name =~ s/\[.*//;
1675 if ($type eq "" && $param =~ /\.\.\.$/)
1677 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1678 $parameterdescs{$param} = "variable arguments";
1681 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1684 $parameterdescs{void
} = "no arguments";
1686 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1687 # handle unnamed (anonymous) union or struct:
1690 $param = "{unnamed_" . $param . "}";
1691 $parameterdescs{$param} = "anonymous\n";
1692 $anon_struct_union = 1;
1695 # warn if parameter has no description
1696 # (but ignore ones starting with # as these are not parameters
1697 # but inline preprocessor statements);
1698 # also ignore unnamed structs/unions;
1699 if (!$anon_struct_union) {
1700 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1702 $parameterdescs{$param_name} = $undescribed;
1704 if (($type eq 'function') || ($type eq 'enum')) {
1705 print STDERR
"Warning(${file}:$.): Function parameter ".
1706 "or member '$param' not " .
1707 "described in '$declaration_name'\n";
1709 print STDERR
"Warning(${file}:$.):" .
1710 " No description found for parameter '$param'\n";
1715 $param = xml_escape
($param);
1717 # strip spaces from $param so that it is one continuous string
1718 # on @parameterlist;
1719 # this fixes a problem where check_sections() cannot find
1720 # a parameter like "addr[6 + 2]" because it actually appears
1721 # as "addr[6", "+", "2]" on the parameter list;
1722 # but it's better to maintain the param string unchanged for output,
1723 # so just weaken the string compare in check_sections() to ignore
1724 # "[blah" in a parameter string;
1725 ###$param =~ s/\s*//g;
1726 push @parameterlist, $param;
1727 $parametertypes{$param} = $type;
1730 sub check_sections
($$$$$$) {
1731 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1732 my @sects = split ' ', $sectcheck;
1733 my @prms = split ' ', $prmscheck;
1736 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1738 foreach $sx (0 .. $#sects) {
1740 foreach $px (0 .. $#prms) {
1741 $prm_clean = $prms[$px];
1742 $prm_clean =~ s/\[.*\]//;
1743 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1744 # ignore array size in a parameter string;
1745 # however, the original param string may contain
1746 # spaces, e.g.: addr[6 + 2]
1747 # and this appears in @prms as "addr[6" since the
1748 # parameter list is split at spaces;
1749 # hence just ignore "[..." for the sections check;
1750 $prm_clean =~ s/\[.*//;
1752 ##$prm_clean =~ s/^\**//;
1753 if ($prm_clean eq $sects[$sx]) {
1759 if ($decl_type eq "function") {
1760 print STDERR
"Warning(${file}:$.): " .
1761 "Excess function parameter " .
1763 "description in '$decl_name'\n";
1766 if ($nested !~ m/\Q$sects[$sx]\E/) {
1767 print STDERR
"Warning(${file}:$.): " .
1768 "Excess struct/union/enum/typedef member " .
1770 "description in '$decl_name'\n";
1779 # takes a function prototype and the name of the current file being
1780 # processed and spits out all the details stored in the global
1782 sub dump_function
($$) {
1783 my $prototype = shift;
1786 $prototype =~ s/^static +//;
1787 $prototype =~ s/^extern +//;
1788 $prototype =~ s/^asmlinkage +//;
1789 $prototype =~ s/^inline +//;
1790 $prototype =~ s/^__inline__ +//;
1791 $prototype =~ s/^__inline +//;
1792 $prototype =~ s/^__always_inline +//;
1793 $prototype =~ s/^noinline +//;
1794 $prototype =~ s/__devinit +//;
1795 $prototype =~ s/__init +//;
1796 $prototype =~ s/__init_or_module +//;
1797 $prototype =~ s/__must_check +//;
1798 $prototype =~ s/__weak +//;
1799 $prototype =~ s/^#\s*define\s+//; #ak added
1800 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1802 # Yes, this truly is vile. We are looking for:
1803 # 1. Return type (may be nothing if we're looking at a macro)
1805 # 3. Function parameters.
1807 # All the while we have to watch out for function pointer parameters
1808 # (which IIRC is what the two sections are for), C types (these
1809 # regexps don't even start to express all the possibilities), and
1812 # If you mess with these regexps, it's a good idea to check that
1813 # the following functions' documentation still comes out right:
1814 # - parport_register_device (function pointer parameters)
1815 # - atomic_set (macro)
1816 # - pci_match_device, __copy_to_user (long return type)
1818 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1819 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1820 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1821 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1822 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1823 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1824 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1825 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1826 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1827 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1828 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1829 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1830 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1831 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1832 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1833 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1834 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1836 $declaration_name = $2;
1839 create_parameterlist
($args, ',', $file);
1841 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1846 my $prms = join " ", @parameterlist;
1847 check_sections
($file, $declaration_name, "function", $sectcheck, $prms, "");
1849 output_declaration
($declaration_name,
1851 {'function' => $declaration_name,
1852 'module' => $modulename,
1853 'functiontype' => $return_type,
1854 'parameterlist' => \
@parameterlist,
1855 'parameterdescs' => \
%parameterdescs,
1856 'parametertypes' => \
%parametertypes,
1857 'sectionlist' => \
@sectionlist,
1858 'sections' => \
%sections,
1859 'purpose' => $declaration_purpose
1866 %parameterdescs = ();
1867 %parametertypes = ();
1868 @parameterlist = ();
1872 $struct_actual = "";
1878 sub tracepoint_munge
($) {
1880 my $tracepointname = 0;
1881 my $tracepointargs = 0;
1883 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
1884 $tracepointname = $1;
1886 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1887 $tracepointname = $1;
1889 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1890 $tracepointname = $2;
1892 $tracepointname =~ s/^\s+//; #strip leading whitespace
1893 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
1894 $tracepointargs = $1;
1896 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
1897 print STDERR
"Warning(${file}:$.): Unrecognized tracepoint format: \n".
1900 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1904 sub syscall_munge
() {
1907 $prototype =~ s
@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
1908 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1909 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1911 ## $prototype = "long sys_$1(void)";
1914 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1915 if ($prototype =~ m/long (sys_.*?),/) {
1916 $prototype =~ s/,/\(/;
1918 $prototype =~ s/\)/\(void\)/;
1921 # now delete all of the odd-number commas in $prototype
1922 # so that arg types & arg names don't have a comma between them
1924 my $len = length($prototype);
1926 $len = 0; # skip the for-loop
1928 for (my $ix = 0; $ix < $len; $ix++) {
1929 if (substr($prototype, $ix, 1) eq ',') {
1931 if ($count % 2 == 1) {
1932 substr($prototype, $ix, 1) = ' ';
1938 sub process_state3_function
($$) {
1942 $x =~ s
@\/\/.*$@@gos; # strip C99-style comments to end of line
1944 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1947 elsif ($x =~ /([^\{]*)/) {
1951 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
1952 $prototype =~ s
@/\*.*?\
*/@@gos; # strip comments.
1953 $prototype =~ s
@[\r\n]+@ @gos; # strip newlines/cr's.
1954 $prototype =~ s
@^\s+@@gos; # strip leading spaces
1955 if ($prototype =~ /SYSCALL_DEFINE/) {
1958 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1959 $prototype =~ /DEFINE_SINGLE_EVENT/)
1961 tracepoint_munge
($file);
1963 dump_function
($prototype, $file);
1968 sub process_state3_type
($$) {
1972 $x =~ s
@[\r\n]+@ @gos; # strip newlines/cr's.
1973 $x =~ s
@^\s+@@gos; # strip leading spaces
1974 $x =~ s
@\s+$@@gos; # strip trailing spaces
1975 $x =~ s
@\/\/.*$@@gos; # strip C99-style comments to end of line
1978 # To distinguish preprocessor directive from regular declaration later.
1983 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1984 $prototype .= $1 . $2;
1985 ($2 eq '{') && $brcount++;
1986 ($2 eq '}') && $brcount--;
1987 if (($2 eq ';') && ($brcount == 0)) {
1988 dump_declaration
($prototype, $file);
2000 # xml_escape: replace <, >, and & in the text stream;
2002 # however, formatting controls that are generated internally/locally in the
2003 # kernel-doc script are not escaped here; instead, they begin life like
2004 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2005 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2006 # just before actual output; (this is done by local_unescape())
2009 if (($output_mode eq "text") || ($output_mode eq "man")) {
2012 $text =~ s/\&/\\\\\\amp;/g;
2013 $text =~ s/\</\\\\\\lt;/g;
2014 $text =~ s/\>/\\\\\\gt;/g;
2018 # convert local escape strings to html
2019 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2020 sub local_unescape
($) {
2022 if (($output_mode eq "text") || ($output_mode eq "man")) {
2025 $text =~ s/\\\\\\\\lt:/</g;
2026 $text =~ s/\\\\\\\\gt:/>/g;
2030 sub process_file
($) {
2036 my $initial_section_counter = $section_counter;
2038 if (defined($ENV{'SRCTREE'})) {
2039 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2044 if (defined($source_map{$file})) {
2045 $file = $source_map{$file};
2048 if (!open(IN
,"<$file")) {
2049 print STDERR
"Error: Cannot open file $file\n";
2056 $section_counter = 0;
2058 while (s/\\\s*$//) {
2062 if (/$doc_start/o) {
2063 $state = 1; # next line is always the function name
2066 } elsif ($state == 1) { # this line is the function name (always)
2067 if (/$doc_block/o) {
2071 $section = $section_intro;
2076 elsif (/$doc_decl/o) {
2078 if (/\s*([\w\s]+?)\s*-/) {
2084 # strip leading/trailing/multiple spaces
2089 $declaration_purpose = xml_escape
($descr);
2092 $declaration_purpose = "";
2095 if (($declaration_purpose eq "") && $verbose) {
2096 print STDERR
"Warning(${file}:$.): missing initial short description on line:\n";
2101 if ($identifier =~ m/^struct/) {
2102 $decl_type = 'struct';
2103 } elsif ($identifier =~ m/^union/) {
2104 $decl_type = 'union';
2105 } elsif ($identifier =~ m/^enum/) {
2106 $decl_type = 'enum';
2107 } elsif ($identifier =~ m/^typedef/) {
2108 $decl_type = 'typedef';
2110 $decl_type = 'function';
2114 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
2117 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
2118 " - I thought it was a doc line\n";
2122 } elsif ($state == 2) { # look for head: lines, and include content
2127 if (($contents ne "") && ($contents ne "\n")) {
2128 if (!$in_doc_sect && $verbose) {
2129 print STDERR
"Warning(${file}:$.): contents before sections\n";
2132 dump_section
($file, $section, xml_escape
($contents));
2133 $section = $section_default;
2138 $contents = $newcontents;
2139 if ($contents ne "") {
2140 while ((substr($contents, 0, 1) eq " ") ||
2141 substr($contents, 0, 1) eq "\t") {
2142 $contents = substr($contents, 1);
2146 $section = $newsection;
2147 } elsif (/$doc_end/) {
2149 if (($contents ne "") && ($contents ne "\n")) {
2150 dump_section
($file, $section, xml_escape
($contents));
2151 $section = $section_default;
2154 # look for doc_com + <text> + doc_end:
2155 if ($_ =~ m
'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2156 print STDERR
"Warning(${file}:$.): suspicious ending line: $_";
2163 # print STDERR "end of doc comment, looking for prototype\n";
2164 } elsif (/$doc_content/) {
2165 # miguel-style comment kludge, look for blank lines after
2166 # @parameter line to signify start of description
2168 if ($section =~ m/^@/ || $section eq $section_context) {
2169 dump_section
($file, $section, xml_escape
($contents));
2170 $section = $section_default;
2176 } elsif ($in_purpose == 1) {
2177 # Continued declaration purpose
2178 chomp($declaration_purpose);
2179 $declaration_purpose .= " " . xml_escape
($1);
2181 $contents .= $1 . "\n";
2184 # i dont know - bad line? ignore.
2185 print STDERR
"Warning(${file}:$.): bad line: $_";
2188 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2189 if ($decl_type eq 'function') {
2190 process_state3_function
($_, $file);
2192 process_state3_type
($_, $file);
2194 } elsif ($state == 4) {
2195 # Documentation block
2197 dump_doc_section
($file, $section, xml_escape
($contents));
2201 %parameterdescs = ();
2202 %parametertypes = ();
2203 @parameterlist = ();
2208 $section = $section_intro;
2215 dump_doc_section
($file, $section, xml_escape
($contents));
2219 %parameterdescs = ();
2220 %parametertypes = ();
2221 @parameterlist = ();
2227 elsif (/$doc_content/)
2231 $contents .= $blankline;
2235 $contents .= $1 . "\n";
2240 if ($initial_section_counter == $section_counter) {
2241 print STDERR
"Warning(${file}): no structured comments found\n";
2242 if ($output_mode eq "xml") {
2243 # The template wants at least one RefEntry here; make one.
2244 print "<refentry>\n";
2245 print " <refnamediv>\n";
2246 print " <refname>\n";
2248 print " </refname>\n";
2249 print " <refpurpose>\n";
2250 print " Document generation inconsistency\n";
2251 print " </refpurpose>\n";
2252 print " </refnamediv>\n";
2253 print " <refsect1>\n";
2256 print " </title>\n";
2257 print " <warning>\n";
2259 print " The template for this document tried to insert\n";
2260 print " the structured comment from the file\n";
2261 print " <filename>${file}</filename> at this point,\n";
2262 print " but none was found.\n";
2263 print " This dummy section is inserted to allow\n";
2264 print " generation to continue.\n";
2266 print " </warning>\n";
2267 print " </refsect1>\n";
2268 print "</refentry>\n";
2274 $kernelversion = get_kernel_version
();
2276 # generate a sequence of code that will splice in highlighting information
2277 # using the s// operator.
2278 foreach my $pattern (keys %highlights) {
2279 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2280 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2283 # Read the file that maps relative names to absolute names for
2284 # separate source and object directories and for shadow trees.
2285 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
2286 my ($relname, $absname);
2287 while(<SOURCE_MAP
>) {
2289 ($relname, $absname) = (split())[0..1];
2290 $relname =~ s
:^/+::;
2291 $source_map{$relname} = $absname;
2300 if ($verbose && $errors) {
2301 print STDERR
"$errors errors\n";
2303 if ($verbose && $warnings) {
2304 print STDERR
"$warnings warnings\n";