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_com_body = '\s*\* ?';
285 my $doc_decl = $doc_com . '(\w+)';
286 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
287 my $doc_content = $doc_com_body . '(.*)';
288 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
299 my $section_default = "Description"; # default section
300 my $section_intro = "Introduction";
301 my $section = $section_default;
302 my $section_context = "Context";
304 my $undescribed = "-- undescribed --";
308 while ($ARGV[0] =~ m/^-(.*)/) {
309 my $cmd = shift @ARGV;
310 if ($cmd eq "-html") {
311 $output_mode = "html";
312 %highlights = %highlights_html;
313 $blankline = $blankline_html;
314 } elsif ($cmd eq "-man") {
315 $output_mode = "man";
316 %highlights = %highlights_man;
317 $blankline = $blankline_man;
318 } elsif ($cmd eq "-text") {
319 $output_mode = "text";
320 %highlights = %highlights_text;
321 $blankline = $blankline_text;
322 } elsif ($cmd eq "-docbook") {
323 $output_mode = "xml";
324 %highlights = %highlights_xml;
325 $blankline = $blankline_xml;
326 } elsif ($cmd eq "-list") {
327 $output_mode = "list";
328 %highlights = %highlights_list;
329 $blankline = $blankline_list;
330 } elsif ($cmd eq "-gnome") {
331 $output_mode = "gnome";
332 %highlights = %highlights_gnome;
333 $blankline = $blankline_gnome;
334 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
335 $modulename = shift @ARGV;
336 } elsif ($cmd eq "-function") { # to only output specific functions
338 $function = shift @ARGV;
339 $function_table{$function} = 1;
340 } elsif ($cmd eq "-nofunction") { # to only output specific functions
342 $function = shift @ARGV;
343 $function_table{$function} = 1;
344 } elsif ($cmd eq "-v") {
346 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
348 } elsif ($cmd eq '-no-doc-sections') {
349 $no_doc_sections = 1;
353 # continue execution near EOF;
356 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n";
357 print " [ -no-doc-sections ]\n";
358 print " [ -function funcname [ -function funcname ...] ]\n";
359 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
360 print " c source file(s) > outputfile\n";
361 print " -v : verbose output, more warnings & other info listed\n";
365 # get kernel version from env
366 sub get_kernel_version() {
367 my $version = 'unknown kernel version';
369 if (defined($ENV{'KERNELVERSION'})) {
370 $version = $ENV{'KERNELVERSION'};
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) {
464 if (! $output_preformatted) {
468 if (! $output_preformatted) {
469 print $lineprefix, local_unescape($blankline);
472 $line =~ s/\\\\\\/\&/g;
473 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
476 print $lineprefix, $line;
483 #output sections in html
484 sub output_section_html(%) {
488 foreach $section (@{$args{'sectionlist'}}) {
489 print "<h3>$section</h3>\n";
490 print "<blockquote>\n";
491 output_highlight($args{'sections'}{$section});
492 print "</blockquote>\n";
496 # output enum in html
497 sub output_enum_html(%) {
501 print "<h2>enum " . $args{'enum'} . "</h2>\n";
503 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
505 foreach $parameter (@{$args{'parameterlist'}}) {
506 print " <b>" . $parameter . "</b>";
507 if ($count != $#{$args{'parameterlist'}}) {
515 print "<h3>Constants</h3>\n";
517 foreach $parameter (@{$args{'parameterlist'}}) {
518 print "<dt><b>" . $parameter . "</b>\n";
520 output_highlight($args{'parameterdescs'}{$parameter});
523 output_section_html(@_);
527 # output typedef in html
528 sub output_typedef_html(%) {
532 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
534 print "<b>typedef " . $args{'typedef'} . "</b>\n";
535 output_section_html(@_);
539 # output struct in html
540 sub output_struct_html(%) {
544 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
545 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
546 foreach $parameter (@{$args{'parameterlist'}}) {
547 if ($parameter =~ /^#/) {
548 print "$parameter<br>\n";
551 my $parameter_name = $parameter;
552 $parameter_name =~ s/\[.*//;
554 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
555 $type = $args{'parametertypes'}{$parameter};
556 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
557 # pointer-to-function
558 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
559 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
561 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
563 print " <i>$type</i> <b>$parameter</b>;<br>\n";
568 print "<h3>Members</h3>\n";
570 foreach $parameter (@{$args{'parameterlist'}}) {
571 ($parameter =~ /^#/) && next;
573 my $parameter_name = $parameter;
574 $parameter_name =~ s/\[.*//;
576 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
577 print "<dt><b>" . $parameter . "</b>\n";
579 output_highlight($args{'parameterdescs'}{$parameter_name});
582 output_section_html(@_);
586 # output function in html
587 sub output_function_html(%) {
589 my ($parameter, $section);
592 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
593 print "<i>" . $args{'functiontype'} . "</i>\n";
594 print "<b>" . $args{'function'} . "</b>\n";
597 foreach $parameter (@{$args{'parameterlist'}}) {
598 $type = $args{'parametertypes'}{$parameter};
599 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
600 # pointer-to-function
601 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
603 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
605 if ($count != $#{$args{'parameterlist'}}) {
612 print "<h3>Arguments</h3>\n";
614 foreach $parameter (@{$args{'parameterlist'}}) {
615 my $parameter_name = $parameter;
616 $parameter_name =~ s/\[.*//;
618 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
619 print "<dt><b>" . $parameter . "</b>\n";
621 output_highlight($args{'parameterdescs'}{$parameter_name});
624 output_section_html(@_);
628 # output DOC: block header in html
629 sub output_blockhead_html(%) {
631 my ($parameter, $section);
634 foreach $section (@{$args{'sectionlist'}}) {
635 print "<h3>$section</h3>\n";
637 output_highlight($args{'sections'}{$section});
643 sub output_section_xml(%) {
646 # print out each section
648 foreach $section (@{$args{'sectionlist'}}) {
649 print "<refsect1>\n";
650 print "<title>$section</title>\n";
651 if ($section =~ m/EXAMPLE/i) {
652 print "<informalexample><programlisting>\n";
653 $output_preformatted = 1;
657 output_highlight($args{'sections'}{$section});
658 $output_preformatted = 0;
659 if ($section =~ m/EXAMPLE/i) {
660 print "</programlisting></informalexample>\n";
664 print "</refsect1>\n";
668 # output function in XML DocBook
669 sub output_function_xml(%) {
671 my ($parameter, $section);
675 $id = "API-" . $args{'function'};
676 $id =~ s/[^A-Za-z0-9]/-/g;
678 print "<refentry id=\"$id\">\n";
679 print "<refentryinfo>\n";
680 print " <title>LINUX</title>\n";
681 print " <productname>Kernel Hackers Manual</productname>\n";
682 print " <date>$man_date</date>\n";
683 print "</refentryinfo>\n";
685 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
686 print " <manvolnum>9</manvolnum>\n";
687 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
688 print "</refmeta>\n";
689 print "<refnamediv>\n";
690 print " <refname>" . $args{'function'} . "</refname>\n";
691 print " <refpurpose>\n";
693 output_highlight ($args{'purpose'});
694 print " </refpurpose>\n";
695 print "</refnamediv>\n";
697 print "<refsynopsisdiv>\n";
698 print " <title>Synopsis</title>\n";
699 print " <funcsynopsis><funcprototype>\n";
700 print " <funcdef>" . $args{'functiontype'} . " ";
701 print "<function>" . $args{'function'} . " </function></funcdef>\n";
704 if ($#{$args{'parameterlist'}} >= 0) {
705 foreach $parameter (@{$args{'parameterlist'}}) {
706 $type = $args{'parametertypes'}{$parameter};
707 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
708 # pointer-to-function
709 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
710 print " <funcparams>$2</funcparams></paramdef>\n";
712 print " <paramdef>" . $type;
713 print " <parameter>$parameter</parameter></paramdef>\n";
719 print " </funcprototype></funcsynopsis>\n";
720 print "</refsynopsisdiv>\n";
723 print "<refsect1>\n <title>Arguments</title>\n";
724 if ($#{$args{'parameterlist'}} >= 0) {
725 print " <variablelist>\n";
726 foreach $parameter (@{$args{'parameterlist'}}) {
727 my $parameter_name = $parameter;
728 $parameter_name =~ s/\[.*//;
730 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
731 print " <listitem>\n <para>\n";
733 output_highlight($args{'parameterdescs'}{$parameter_name});
734 print " </para>\n </listitem>\n </varlistentry>\n";
736 print " </variablelist>\n";
738 print " <para>\n None\n </para>\n";
740 print "</refsect1>\n";
742 output_section_xml(@_);
743 print "</refentry>\n\n";
746 # output struct in XML DocBook
747 sub output_struct_xml(%) {
749 my ($parameter, $section);
752 $id = "API-struct-" . $args{'struct'};
753 $id =~ s/[^A-Za-z0-9]/-/g;
755 print "<refentry id=\"$id\">\n";
756 print "<refentryinfo>\n";
757 print " <title>LINUX</title>\n";
758 print " <productname>Kernel Hackers Manual</productname>\n";
759 print " <date>$man_date</date>\n";
760 print "</refentryinfo>\n";
762 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
763 print " <manvolnum>9</manvolnum>\n";
764 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
765 print "</refmeta>\n";
766 print "<refnamediv>\n";
767 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
768 print " <refpurpose>\n";
770 output_highlight ($args{'purpose'});
771 print " </refpurpose>\n";
772 print "</refnamediv>\n";
774 print "<refsynopsisdiv>\n";
775 print " <title>Synopsis</title>\n";
776 print " <programlisting>\n";
777 print $args{'type'} . " " . $args{'struct'} . " {\n";
778 foreach $parameter (@{$args{'parameterlist'}}) {
779 if ($parameter =~ /^#/) {
780 my $prm = $parameter;
781 # convert data read & converted thru xml_escape() into &xyz; format:
782 # This allows us to have #define macros interspersed in a struct.
783 $prm =~ s/\\\\\\/\&/g;
788 my $parameter_name = $parameter;
789 $parameter_name =~ s/\[.*//;
791 defined($args{'parameterdescs'}{$parameter_name}) || next;
792 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
793 $type = $args{'parametertypes'}{$parameter};
794 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
795 # pointer-to-function
796 print " $1 $parameter) ($2);\n";
797 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
799 print " $1 $parameter$2;\n";
801 print " " . $type . " " . $parameter . ";\n";
805 print " </programlisting>\n";
806 print "</refsynopsisdiv>\n";
808 print " <refsect1>\n";
809 print " <title>Members</title>\n";
811 if ($#{$args{'parameterlist'}} >= 0) {
812 print " <variablelist>\n";
813 foreach $parameter (@{$args{'parameterlist'}}) {
814 ($parameter =~ /^#/) && next;
816 my $parameter_name = $parameter;
817 $parameter_name =~ s/\[.*//;
819 defined($args{'parameterdescs'}{$parameter_name}) || next;
820 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
821 print " <varlistentry>";
822 print " <term>$parameter</term>\n";
823 print " <listitem><para>\n";
824 output_highlight($args{'parameterdescs'}{$parameter_name});
825 print " </para></listitem>\n";
826 print " </varlistentry>\n";
828 print " </variablelist>\n";
830 print " <para>\n None\n </para>\n";
832 print " </refsect1>\n";
834 output_section_xml(@_);
836 print "</refentry>\n\n";
839 # output enum in XML DocBook
840 sub output_enum_xml(%) {
842 my ($parameter, $section);
846 $id = "API-enum-" . $args{'enum'};
847 $id =~ s/[^A-Za-z0-9]/-/g;
849 print "<refentry id=\"$id\">\n";
850 print "<refentryinfo>\n";
851 print " <title>LINUX</title>\n";
852 print " <productname>Kernel Hackers Manual</productname>\n";
853 print " <date>$man_date</date>\n";
854 print "</refentryinfo>\n";
856 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
857 print " <manvolnum>9</manvolnum>\n";
858 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
859 print "</refmeta>\n";
860 print "<refnamediv>\n";
861 print " <refname>enum " . $args{'enum'} . "</refname>\n";
862 print " <refpurpose>\n";
864 output_highlight ($args{'purpose'});
865 print " </refpurpose>\n";
866 print "</refnamediv>\n";
868 print "<refsynopsisdiv>\n";
869 print " <title>Synopsis</title>\n";
870 print " <programlisting>\n";
871 print "enum " . $args{'enum'} . " {\n";
873 foreach $parameter (@{$args{'parameterlist'}}) {
875 if ($count != $#{$args{'parameterlist'}}) {
882 print " </programlisting>\n";
883 print "</refsynopsisdiv>\n";
885 print "<refsect1>\n";
886 print " <title>Constants</title>\n";
887 print " <variablelist>\n";
888 foreach $parameter (@{$args{'parameterlist'}}) {
889 my $parameter_name = $parameter;
890 $parameter_name =~ s/\[.*//;
892 print " <varlistentry>";
893 print " <term>$parameter</term>\n";
894 print " <listitem><para>\n";
895 output_highlight($args{'parameterdescs'}{$parameter_name});
896 print " </para></listitem>\n";
897 print " </varlistentry>\n";
899 print " </variablelist>\n";
900 print "</refsect1>\n";
902 output_section_xml(@_);
904 print "</refentry>\n\n";
907 # output typedef in XML DocBook
908 sub output_typedef_xml(%) {
910 my ($parameter, $section);
913 $id = "API-typedef-" . $args{'typedef'};
914 $id =~ s/[^A-Za-z0-9]/-/g;
916 print "<refentry id=\"$id\">\n";
917 print "<refentryinfo>\n";
918 print " <title>LINUX</title>\n";
919 print " <productname>Kernel Hackers Manual</productname>\n";
920 print " <date>$man_date</date>\n";
921 print "</refentryinfo>\n";
923 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
924 print " <manvolnum>9</manvolnum>\n";
925 print "</refmeta>\n";
926 print "<refnamediv>\n";
927 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
928 print " <refpurpose>\n";
930 output_highlight ($args{'purpose'});
931 print " </refpurpose>\n";
932 print "</refnamediv>\n";
934 print "<refsynopsisdiv>\n";
935 print " <title>Synopsis</title>\n";
936 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
937 print "</refsynopsisdiv>\n";
939 output_section_xml(@_);
941 print "</refentry>\n\n";
944 # output in XML DocBook
945 sub output_blockhead_xml(%) {
947 my ($parameter, $section);
950 my $id = $args{'module'};
951 $id =~ s/[^A-Za-z0-9]/-/g;
953 # print out each section
955 foreach $section (@{$args{'sectionlist'}}) {
956 if (!$args{'content-only'}) {
957 print "<refsect1>\n <title>$section</title>\n";
959 if ($section =~ m/EXAMPLE/i) {
960 print "<example><para>\n";
961 $output_preformatted = 1;
965 output_highlight($args{'sections'}{$section});
966 $output_preformatted = 0;
967 if ($section =~ m/EXAMPLE/i) {
968 print "</para></example>\n";
972 if (!$args{'content-only'}) {
973 print "\n</refsect1>\n";
980 # output in XML DocBook
981 sub output_function_gnome {
983 my ($parameter, $section);
987 $id = $args{'module'} . "-" . $args{'function'};
988 $id =~ s/[^A-Za-z0-9]/-/g;
991 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
993 print " <funcsynopsis>\n";
994 print " <funcdef>" . $args{'functiontype'} . " ";
995 print "<function>" . $args{'function'} . " ";
996 print "</function></funcdef>\n";
999 if ($#{$args{'parameterlist'}} >= 0) {
1000 foreach $parameter (@{$args{'parameterlist'}}) {
1001 $type = $args{'parametertypes'}{$parameter};
1002 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1003 # pointer-to-function
1004 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1005 print " <funcparams>$2</funcparams></paramdef>\n";
1007 print " <paramdef>" . $type;
1008 print " <parameter>$parameter</parameter></paramdef>\n";
1014 print " </funcsynopsis>\n";
1015 if ($#{$args{'parameterlist'}} >= 0) {
1016 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1017 print "<tgroup cols=\"2\">\n";
1018 print "<colspec colwidth=\"2*\">\n";
1019 print "<colspec colwidth=\"8*\">\n";
1021 foreach $parameter (@{$args{'parameterlist'}}) {
1022 my $parameter_name = $parameter;
1023 $parameter_name =~ s/\[.*//;
1025 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1028 output_highlight($args{'parameterdescs'}{$parameter_name});
1029 print " </entry></row>\n";
1031 print " </tbody></tgroup></informaltable>\n";
1033 print " <para>\n None\n </para>\n";
1036 # print out each section
1038 foreach $section (@{$args{'sectionlist'}}) {
1039 print "<simplesect>\n <title>$section</title>\n";
1040 if ($section =~ m/EXAMPLE/i) {
1041 print "<example><programlisting>\n";
1042 $output_preformatted = 1;
1046 output_highlight($args{'sections'}{$section});
1047 $output_preformatted = 0;
1049 if ($section =~ m/EXAMPLE/i) {
1050 print "</programlisting></example>\n";
1053 print " </simplesect>\n";
1056 print "</sect2>\n\n";
1060 # output function in man
1061 sub output_function_man(%) {
1062 my %args = %{$_[0]};
1063 my ($parameter, $section);
1066 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1069 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1071 print ".SH SYNOPSIS\n";
1072 if ($args{'functiontype'} ne "") {
1073 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1075 print ".B \"" . $args{'function'} . "\n";
1080 foreach my $parameter (@{$args{'parameterlist'}}) {
1081 if ($count == $#{$args{'parameterlist'}}) {
1084 $type = $args{'parametertypes'}{$parameter};
1085 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1086 # pointer-to-function
1087 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1089 $type =~ s/([^\*])$/$1 /;
1090 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1096 print ".SH ARGUMENTS\n";
1097 foreach $parameter (@{$args{'parameterlist'}}) {
1098 my $parameter_name = $parameter;
1099 $parameter_name =~ s/\[.*//;
1101 print ".IP \"" . $parameter . "\" 12\n";
1102 output_highlight($args{'parameterdescs'}{$parameter_name});
1104 foreach $section (@{$args{'sectionlist'}}) {
1105 print ".SH \"", uc $section, "\"\n";
1106 output_highlight($args{'sections'}{$section});
1111 # output enum in man
1112 sub output_enum_man(%) {
1113 my %args = %{$_[0]};
1114 my ($parameter, $section);
1117 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1120 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1122 print ".SH SYNOPSIS\n";
1123 print "enum " . $args{'enum'} . " {\n";
1125 foreach my $parameter (@{$args{'parameterlist'}}) {
1126 print ".br\n.BI \" $parameter\"\n";
1127 if ($count == $#{$args{'parameterlist'}}) {
1137 print ".SH Constants\n";
1138 foreach $parameter (@{$args{'parameterlist'}}) {
1139 my $parameter_name = $parameter;
1140 $parameter_name =~ s/\[.*//;
1142 print ".IP \"" . $parameter . "\" 12\n";
1143 output_highlight($args{'parameterdescs'}{$parameter_name});
1145 foreach $section (@{$args{'sectionlist'}}) {
1146 print ".SH \"$section\"\n";
1147 output_highlight($args{'sections'}{$section});
1152 # output struct in man
1153 sub output_struct_man(%) {
1154 my %args = %{$_[0]};
1155 my ($parameter, $section);
1157 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1160 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1162 print ".SH SYNOPSIS\n";
1163 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1165 foreach my $parameter (@{$args{'parameterlist'}}) {
1166 if ($parameter =~ /^#/) {
1167 print ".BI \"$parameter\"\n.br\n";
1170 my $parameter_name = $parameter;
1171 $parameter_name =~ s/\[.*//;
1173 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1174 $type = $args{'parametertypes'}{$parameter};
1175 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1176 # pointer-to-function
1177 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1178 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1180 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1182 $type =~ s/([^\*])$/$1 /;
1183 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1189 print ".SH Members\n";
1190 foreach $parameter (@{$args{'parameterlist'}}) {
1191 ($parameter =~ /^#/) && next;
1193 my $parameter_name = $parameter;
1194 $parameter_name =~ s/\[.*//;
1196 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1197 print ".IP \"" . $parameter . "\" 12\n";
1198 output_highlight($args{'parameterdescs'}{$parameter_name});
1200 foreach $section (@{$args{'sectionlist'}}) {
1201 print ".SH \"$section\"\n";
1202 output_highlight($args{'sections'}{$section});
1207 # output typedef in man
1208 sub output_typedef_man(%) {
1209 my %args = %{$_[0]};
1210 my ($parameter, $section);
1212 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1215 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1217 foreach $section (@{$args{'sectionlist'}}) {
1218 print ".SH \"$section\"\n";
1219 output_highlight($args{'sections'}{$section});
1223 sub output_blockhead_man(%) {
1224 my %args = %{$_[0]};
1225 my ($parameter, $section);
1228 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1230 foreach $section (@{$args{'sectionlist'}}) {
1231 print ".SH \"$section\"\n";
1232 output_highlight($args{'sections'}{$section});
1238 sub output_function_text(%) {
1239 my %args = %{$_[0]};
1240 my ($parameter, $section);
1244 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1246 print "\nSynopsis:\n\n";
1247 if ($args{'functiontype'} ne "") {
1248 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1250 $start = $args{'function'} . " (";
1255 foreach my $parameter (@{$args{'parameterlist'}}) {
1256 $type = $args{'parametertypes'}{$parameter};
1257 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1258 # pointer-to-function
1259 print $1 . $parameter . ") (" . $2;
1261 print $type . " " . $parameter;
1263 if ($count != $#{$args{'parameterlist'}}) {
1266 print " " x length($start);
1272 print "Arguments:\n\n";
1273 foreach $parameter (@{$args{'parameterlist'}}) {
1274 my $parameter_name = $parameter;
1275 $parameter_name =~ s/\[.*//;
1277 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1279 output_section_text(@_);
1282 #output sections in text
1283 sub output_section_text(%) {
1284 my %args = %{$_[0]};
1288 foreach $section (@{$args{'sectionlist'}}) {
1289 print "$section:\n\n";
1290 output_highlight($args{'sections'}{$section});
1295 # output enum in text
1296 sub output_enum_text(%) {
1297 my %args = %{$_[0]};
1302 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1303 print "enum " . $args{'enum'} . " {\n";
1305 foreach $parameter (@{$args{'parameterlist'}}) {
1306 print "\t$parameter";
1307 if ($count != $#{$args{'parameterlist'}}) {
1315 print "Constants:\n\n";
1316 foreach $parameter (@{$args{'parameterlist'}}) {
1317 print "$parameter\n\t";
1318 print $args{'parameterdescs'}{$parameter} . "\n";
1321 output_section_text(@_);
1324 # output typedef in text
1325 sub output_typedef_text(%) {
1326 my %args = %{$_[0]};
1329 print "Typedef:\n\n";
1331 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1332 output_section_text(@_);
1335 # output struct as text
1336 sub output_struct_text(%) {
1337 my %args = %{$_[0]};
1340 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1341 print $args{'type'} . " " . $args{'struct'} . " {\n";
1342 foreach $parameter (@{$args{'parameterlist'}}) {
1343 if ($parameter =~ /^#/) {
1344 print "$parameter\n";
1348 my $parameter_name = $parameter;
1349 $parameter_name =~ s/\[.*//;
1351 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1352 $type = $args{'parametertypes'}{$parameter};
1353 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1354 # pointer-to-function
1355 print "\t$1 $parameter) ($2);\n";
1356 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1358 print "\t$1 $parameter$2;\n";
1360 print "\t" . $type . " " . $parameter . ";\n";
1365 print "Members:\n\n";
1366 foreach $parameter (@{$args{'parameterlist'}}) {
1367 ($parameter =~ /^#/) && next;
1369 my $parameter_name = $parameter;
1370 $parameter_name =~ s/\[.*//;
1372 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1373 print "$parameter\n\t";
1374 print $args{'parameterdescs'}{$parameter_name} . "\n";
1377 output_section_text(@_);
1380 sub output_blockhead_text(%) {
1381 my %args = %{$_[0]};
1382 my ($parameter, $section);
1384 foreach $section (@{$args{'sectionlist'}}) {
1385 print " $section:\n";
1387 output_highlight($args{'sections'}{$section});
1391 ## list mode output functions
1393 sub output_function_list(%) {
1394 my %args = %{$_[0]};
1396 print $args{'function'} . "\n";
1399 # output enum in list
1400 sub output_enum_list(%) {
1401 my %args = %{$_[0]};
1402 print $args{'enum'} . "\n";
1405 # output typedef in list
1406 sub output_typedef_list(%) {
1407 my %args = %{$_[0]};
1408 print $args{'typedef'} . "\n";
1411 # output struct as list
1412 sub output_struct_list(%) {
1413 my %args = %{$_[0]};
1415 print $args{'struct'} . "\n";
1418 sub output_blockhead_list(%) {
1419 my %args = %{$_[0]};
1420 my ($parameter, $section);
1422 foreach $section (@{$args{'sectionlist'}}) {
1423 print "DOC: $section\n";
1428 # generic output function for all types (function, struct/union, typedef, enum);
1429 # calls the generated, variable output_ function name based on
1430 # functype and output_mode
1431 sub output_declaration {
1434 my $functype = shift;
1435 my $func = "output_${functype}_$output_mode";
1436 if (($function_only==0) ||
1437 ( $function_only == 1 && defined($function_table{$name})) ||
1438 ( $function_only == 2 && !defined($function_table{$name})))
1446 # generic output function - calls the right one based on current output mode.
1447 sub output_blockhead {
1449 my $func = "output_blockhead_" . $output_mode;
1455 # takes a declaration (struct, union, enum, typedef) and
1456 # invokes the right handler. NOT called for functions.
1457 sub dump_declaration($$) {
1459 my ($prototype, $file) = @_;
1460 my $func = "dump_" . $decl_type;
1464 sub dump_union($$) {
1468 sub dump_struct($$) {
1473 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1474 #my $decl_type = $1;
1475 $declaration_name = $2;
1478 # ignore embedded structs or unions
1479 $members =~ s/({.*})//g;
1482 # ignore members marked private:
1483 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
1484 $members =~ s/\/\*\s*private:.*//gos;
1486 $members =~ s/\/\*.*?\*\///gos;
1487 $nested =~ s/\/\*.*?\*\///gos;
1488 # strip kmemcheck_bitfield_{begin,end}.*;
1489 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1491 $members =~ s/__aligned\s*\(\d+\)//gos;
1493 create_parameterlist($members, ';', $file);
1494 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1496 output_declaration($declaration_name,
1498 {'struct' => $declaration_name,
1499 'module' => $modulename,
1500 'parameterlist' => \@parameterlist,
1501 'parameterdescs' => \%parameterdescs,
1502 'parametertypes' => \%parametertypes,
1503 'sectionlist' => \@sectionlist,
1504 'sections' => \%sections,
1505 'purpose' => $declaration_purpose,
1506 'type' => $decl_type
1510 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1519 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1520 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1522 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1523 $declaration_name = $1;
1526 foreach my $arg (split ',', $members) {
1527 $arg =~ s/^\s*(\w+).*/$1/;
1528 push @parameterlist, $arg;
1529 if (!$parameterdescs{$arg}) {
1530 $parameterdescs{$arg} = $undescribed;
1531 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1532 "not described in enum '$declaration_name'\n";
1537 output_declaration($declaration_name,
1539 {'enum' => $declaration_name,
1540 'module' => $modulename,
1541 'parameterlist' => \@parameterlist,
1542 'parameterdescs' => \%parameterdescs,
1543 'sectionlist' => \@sectionlist,
1544 'sections' => \%sections,
1545 'purpose' => $declaration_purpose
1549 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1554 sub dump_typedef($$) {
1558 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1559 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1560 $x =~ s/\(*.\)\s*;$/;/;
1561 $x =~ s/\[*.\]\s*;$/;/;
1564 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1565 $declaration_name = $1;
1567 output_declaration($declaration_name,
1569 {'typedef' => $declaration_name,
1570 'module' => $modulename,
1571 'sectionlist' => \@sectionlist,
1572 'sections' => \%sections,
1573 'purpose' => $declaration_purpose
1577 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1582 sub save_struct_actual($) {
1585 # strip all spaces from the actual param so that it looks like one string item
1586 $actual =~ s/\s*//g;
1587 $struct_actual = $struct_actual . $actual . " ";
1590 sub create_parameterlist($$$) {
1592 my $splitter = shift;
1597 # temporarily replace commas inside function pointer definition
1598 while ($args =~ /(\([^\),]+),/) {
1599 $args =~ s/(\([^\),]+),/$1#/g;
1602 foreach my $arg (split($splitter, $args)) {
1604 $arg =~ s/\/\*.*\*\///;
1605 # strip leading/trailing spaces
1611 # Treat preprocessor directive as a typeless variable just to fill
1612 # corresponding data structures "correctly". Catch it later in
1614 push_parameter($arg, "", $file);
1615 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1616 # pointer-to-function
1618 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1621 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1622 save_struct_actual($param);
1623 push_parameter($param, $type, $file);
1625 $arg =~ s/\s*:\s*/:/g;
1626 $arg =~ s/\s*\[/\[/g;
1628 my @args = split('\s*,\s*', $arg);
1629 if ($args[0] =~ m/\*/) {
1630 $args[0] =~ s/(\*+)\s*/ $1/;
1634 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1636 push(@first_arg, split('\s+', $1));
1637 push(@first_arg, $2);
1639 @first_arg = split('\s+', shift @args);
1642 unshift(@args, pop @first_arg);
1643 $type = join " ", @first_arg;
1645 foreach $param (@args) {
1646 if ($param =~ m/^(\*+)\s*(.*)/) {
1647 save_struct_actual($2);
1648 push_parameter($2, "$type $1", $file);
1650 elsif ($param =~ m/(.*?):(\d+)/) {
1651 if ($type ne "") { # skip unnamed bit-fields
1652 save_struct_actual($1);
1653 push_parameter($1, "$type:$2", $file)
1657 save_struct_actual($param);
1658 push_parameter($param, $type, $file);
1665 sub push_parameter($$$) {
1670 if (($anon_struct_union == 1) && ($type eq "") &&
1672 return; # ignore the ending }; from anon. struct/union
1675 $anon_struct_union = 0;
1676 my $param_name = $param;
1677 $param_name =~ s/\[.*//;
1679 if ($type eq "" && $param =~ /\.\.\.$/)
1681 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1682 $parameterdescs{$param} = "variable arguments";
1685 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1688 $parameterdescs{void} = "no arguments";
1690 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1691 # handle unnamed (anonymous) union or struct:
1694 $param = "{unnamed_" . $param . "}";
1695 $parameterdescs{$param} = "anonymous\n";
1696 $anon_struct_union = 1;
1699 # warn if parameter has no description
1700 # (but ignore ones starting with # as these are not parameters
1701 # but inline preprocessor statements);
1702 # also ignore unnamed structs/unions;
1703 if (!$anon_struct_union) {
1704 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1706 $parameterdescs{$param_name} = $undescribed;
1708 if (($type eq 'function') || ($type eq 'enum')) {
1709 print STDERR "Warning(${file}:$.): Function parameter ".
1710 "or member '$param' not " .
1711 "described in '$declaration_name'\n";
1713 print STDERR "Warning(${file}:$.):" .
1714 " No description found for parameter '$param'\n";
1719 $param = xml_escape($param);
1721 # strip spaces from $param so that it is one continuous string
1722 # on @parameterlist;
1723 # this fixes a problem where check_sections() cannot find
1724 # a parameter like "addr[6 + 2]" because it actually appears
1725 # as "addr[6", "+", "2]" on the parameter list;
1726 # but it's better to maintain the param string unchanged for output,
1727 # so just weaken the string compare in check_sections() to ignore
1728 # "[blah" in a parameter string;
1729 ###$param =~ s/\s*//g;
1730 push @parameterlist, $param;
1731 $parametertypes{$param} = $type;
1734 sub check_sections($$$$$$) {
1735 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1736 my @sects = split ' ', $sectcheck;
1737 my @prms = split ' ', $prmscheck;
1740 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1742 foreach $sx (0 .. $#sects) {
1744 foreach $px (0 .. $#prms) {
1745 $prm_clean = $prms[$px];
1746 $prm_clean =~ s/\[.*\]//;
1747 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1748 # ignore array size in a parameter string;
1749 # however, the original param string may contain
1750 # spaces, e.g.: addr[6 + 2]
1751 # and this appears in @prms as "addr[6" since the
1752 # parameter list is split at spaces;
1753 # hence just ignore "[..." for the sections check;
1754 $prm_clean =~ s/\[.*//;
1756 ##$prm_clean =~ s/^\**//;
1757 if ($prm_clean eq $sects[$sx]) {
1763 if ($decl_type eq "function") {
1764 print STDERR "Warning(${file}:$.): " .
1765 "Excess function parameter " .
1767 "description in '$decl_name'\n";
1770 if ($nested !~ m/\Q$sects[$sx]\E/) {
1771 print STDERR "Warning(${file}:$.): " .
1772 "Excess struct/union/enum/typedef member " .
1774 "description in '$decl_name'\n";
1783 # takes a function prototype and the name of the current file being
1784 # processed and spits out all the details stored in the global
1786 sub dump_function($$) {
1787 my $prototype = shift;
1790 $prototype =~ s/^static +//;
1791 $prototype =~ s/^extern +//;
1792 $prototype =~ s/^asmlinkage +//;
1793 $prototype =~ s/^inline +//;
1794 $prototype =~ s/^__inline__ +//;
1795 $prototype =~ s/^__inline +//;
1796 $prototype =~ s/^__always_inline +//;
1797 $prototype =~ s/^noinline +//;
1798 $prototype =~ s/__devinit +//;
1799 $prototype =~ s/__init +//;
1800 $prototype =~ s/__init_or_module +//;
1801 $prototype =~ s/__must_check +//;
1802 $prototype =~ s/__weak +//;
1803 $prototype =~ s/^#\s*define\s+//; #ak added
1804 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1806 # Yes, this truly is vile. We are looking for:
1807 # 1. Return type (may be nothing if we're looking at a macro)
1809 # 3. Function parameters.
1811 # All the while we have to watch out for function pointer parameters
1812 # (which IIRC is what the two sections are for), C types (these
1813 # regexps don't even start to express all the possibilities), and
1816 # If you mess with these regexps, it's a good idea to check that
1817 # the following functions' documentation still comes out right:
1818 # - parport_register_device (function pointer parameters)
1819 # - atomic_set (macro)
1820 # - pci_match_device, __copy_to_user (long return type)
1822 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1823 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1824 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1825 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1826 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1827 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1828 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1829 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1830 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1831 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1832 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1833 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1834 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1835 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1836 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1837 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1838 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1840 $declaration_name = $2;
1843 create_parameterlist($args, ',', $file);
1845 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1850 my $prms = join " ", @parameterlist;
1851 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
1853 output_declaration($declaration_name,
1855 {'function' => $declaration_name,
1856 'module' => $modulename,
1857 'functiontype' => $return_type,
1858 'parameterlist' => \@parameterlist,
1859 'parameterdescs' => \%parameterdescs,
1860 'parametertypes' => \%parametertypes,
1861 'sectionlist' => \@sectionlist,
1862 'sections' => \%sections,
1863 'purpose' => $declaration_purpose
1870 %parameterdescs = ();
1871 %parametertypes = ();
1872 @parameterlist = ();
1876 $struct_actual = "";
1882 sub tracepoint_munge($) {
1884 my $tracepointname = 0;
1885 my $tracepointargs = 0;
1887 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
1888 $tracepointname = $1;
1890 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1891 $tracepointname = $1;
1893 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1894 $tracepointname = $2;
1896 $tracepointname =~ s/^\s+//; #strip leading whitespace
1897 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
1898 $tracepointargs = $1;
1900 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
1901 print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
1904 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1908 sub syscall_munge() {
1911 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
1912 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1913 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1915 ## $prototype = "long sys_$1(void)";
1918 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1919 if ($prototype =~ m/long (sys_.*?),/) {
1920 $prototype =~ s/,/\(/;
1922 $prototype =~ s/\)/\(void\)/;
1925 # now delete all of the odd-number commas in $prototype
1926 # so that arg types & arg names don't have a comma between them
1928 my $len = length($prototype);
1930 $len = 0; # skip the for-loop
1932 for (my $ix = 0; $ix < $len; $ix++) {
1933 if (substr($prototype, $ix, 1) eq ',') {
1935 if ($count % 2 == 1) {
1936 substr($prototype, $ix, 1) = ' ';
1942 sub process_state3_function($$) {
1946 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1948 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1951 elsif ($x =~ /([^\{]*)/) {
1955 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
1956 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1957 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1958 $prototype =~ s@^\s+@@gos; # strip leading spaces
1959 if ($prototype =~ /SYSCALL_DEFINE/) {
1962 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1963 $prototype =~ /DEFINE_SINGLE_EVENT/)
1965 tracepoint_munge($file);
1967 dump_function($prototype, $file);
1972 sub process_state3_type($$) {
1976 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1977 $x =~ s@^\s+@@gos; # strip leading spaces
1978 $x =~ s@\s+$@@gos; # strip trailing spaces
1979 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1982 # To distinguish preprocessor directive from regular declaration later.
1987 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1988 $prototype .= $1 . $2;
1989 ($2 eq '{') && $brcount++;
1990 ($2 eq '}') && $brcount--;
1991 if (($2 eq ';') && ($brcount == 0)) {
1992 dump_declaration($prototype, $file);
2004 # xml_escape: replace <, >, and & in the text stream;
2006 # however, formatting controls that are generated internally/locally in the
2007 # kernel-doc script are not escaped here; instead, they begin life like
2008 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2009 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2010 # just before actual output; (this is done by local_unescape())
2013 if (($output_mode eq "text") || ($output_mode eq "man")) {
2016 $text =~ s/\&/\\\\\\amp;/g;
2017 $text =~ s/\</\\\\\\lt;/g;
2018 $text =~ s/\>/\\\\\\gt;/g;
2022 # convert local escape strings to html
2023 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2024 sub local_unescape($) {
2026 if (($output_mode eq "text") || ($output_mode eq "man")) {
2029 $text =~ s/\\\\\\\\lt:/</g;
2030 $text =~ s/\\\\\\\\gt:/>/g;
2034 sub process_file($) {
2040 my $initial_section_counter = $section_counter;
2042 if (defined($ENV{'SRCTREE'})) {
2043 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2048 if (defined($source_map{$file})) {
2049 $file = $source_map{$file};
2052 if (!open(IN,"<$file")) {
2053 print STDERR "Error: Cannot open file $file\n";
2060 $section_counter = 0;
2062 while (s/\\\s*$//) {
2066 if (/$doc_start/o) {
2067 $state = 1; # next line is always the function name
2070 } elsif ($state == 1) { # this line is the function name (always)
2071 if (/$doc_block/o) {
2075 $section = $section_intro;
2080 elsif (/$doc_decl/o) {
2082 if (/\s*([\w\s]+?)\s*-/) {
2088 # strip leading/trailing/multiple spaces
2092 $descr =~ s/\s+/ /g;
2093 $declaration_purpose = xml_escape($descr);
2096 $declaration_purpose = "";
2099 if (($declaration_purpose eq "") && $verbose) {
2100 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
2105 if ($identifier =~ m/^struct/) {
2106 $decl_type = 'struct';
2107 } elsif ($identifier =~ m/^union/) {
2108 $decl_type = 'union';
2109 } elsif ($identifier =~ m/^enum/) {
2110 $decl_type = 'enum';
2111 } elsif ($identifier =~ m/^typedef/) {
2112 $decl_type = 'typedef';
2114 $decl_type = 'function';
2118 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
2121 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
2122 " - I thought it was a doc line\n";
2126 } elsif ($state == 2) { # look for head: lines, and include content
2131 if (($contents ne "") && ($contents ne "\n")) {
2132 if (!$in_doc_sect && $verbose) {
2133 print STDERR "Warning(${file}:$.): contents before sections\n";
2136 dump_section($file, $section, xml_escape($contents));
2137 $section = $section_default;
2142 $contents = $newcontents;
2143 if ($contents ne "") {
2144 while ((substr($contents, 0, 1) eq " ") ||
2145 substr($contents, 0, 1) eq "\t") {
2146 $contents = substr($contents, 1);
2150 $section = $newsection;
2151 } elsif (/$doc_end/) {
2153 if (($contents ne "") && ($contents ne "\n")) {
2154 dump_section($file, $section, xml_escape($contents));
2155 $section = $section_default;
2158 # look for doc_com + <text> + doc_end:
2159 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2160 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
2167 # print STDERR "end of doc comment, looking for prototype\n";
2168 } elsif (/$doc_content/) {
2169 # miguel-style comment kludge, look for blank lines after
2170 # @parameter line to signify start of description
2172 if ($section =~ m/^@/ || $section eq $section_context) {
2173 dump_section($file, $section, xml_escape($contents));
2174 $section = $section_default;
2180 } elsif ($in_purpose == 1) {
2181 # Continued declaration purpose
2182 chomp($declaration_purpose);
2183 $declaration_purpose .= " " . xml_escape($1);
2184 $declaration_purpose =~ s/\s+/ /g;
2186 $contents .= $1 . "\n";
2189 # i dont know - bad line? ignore.
2190 print STDERR "Warning(${file}:$.): bad line: $_";
2193 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2194 if ($decl_type eq 'function') {
2195 process_state3_function($_, $file);
2197 process_state3_type($_, $file);
2199 } elsif ($state == 4) {
2200 # Documentation block
2202 dump_doc_section($file, $section, xml_escape($contents));
2206 %parameterdescs = ();
2207 %parametertypes = ();
2208 @parameterlist = ();
2213 $section = $section_intro;
2220 dump_doc_section($file, $section, xml_escape($contents));
2224 %parameterdescs = ();
2225 %parametertypes = ();
2226 @parameterlist = ();
2232 elsif (/$doc_content/)
2236 $contents .= $blankline;
2240 $contents .= $1 . "\n";
2245 if ($initial_section_counter == $section_counter) {
2246 print STDERR "Warning(${file}): no structured comments found\n";
2247 if ($output_mode eq "xml") {
2248 # The template wants at least one RefEntry here; make one.
2249 print "<refentry>\n";
2250 print " <refnamediv>\n";
2251 print " <refname>\n";
2253 print " </refname>\n";
2254 print " <refpurpose>\n";
2255 print " Document generation inconsistency\n";
2256 print " </refpurpose>\n";
2257 print " </refnamediv>\n";
2258 print " <refsect1>\n";
2261 print " </title>\n";
2262 print " <warning>\n";
2264 print " The template for this document tried to insert\n";
2265 print " the structured comment from the file\n";
2266 print " <filename>${file}</filename> at this point,\n";
2267 print " but none was found.\n";
2268 print " This dummy section is inserted to allow\n";
2269 print " generation to continue.\n";
2271 print " </warning>\n";
2272 print " </refsect1>\n";
2273 print "</refentry>\n";
2279 $kernelversion = get_kernel_version();
2281 # generate a sequence of code that will splice in highlighting information
2282 # using the s// operator.
2283 foreach my $pattern (keys %highlights) {
2284 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2285 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2288 # Read the file that maps relative names to absolute names for
2289 # separate source and object directories and for shadow trees.
2290 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2291 my ($relname, $absname);
2292 while(<SOURCE_MAP>) {
2294 ($relname, $absname) = (split())[0..1];
2295 $relname =~ s:^/+::;
2296 $source_map{$relname} = $absname;
2305 if ($verbose && $errors) {
2306 print STDERR "$errors errors\n";
2308 if ($verbose && $warnings) {
2309 print STDERR "$warnings warnings\n";