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-2009 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 ] [ -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.
55 # Do not output DOC: sections
58 # If set, then only generate documentation for the given function(s) or
59 # DOC: section titles. All other functions and DOC: sections are ignored.
61 # -nofunction funcname
62 # If set, then only generate documentation for the other function(s)/DOC:
63 # sections. Cannot be used together with -function (yes, that's a bug --
64 # perl hackers can fix it 8))
66 # c files - list of 'c' files to process
68 # All output goes to stdout, with errors to stderr.
72 # In the following table, (...)? signifies optional structure.
73 # (...)* signifies 0 or more structure elements
75 # * function_name(:)? (- short description)?
76 # (* @parameterx: (description of parameter x)?)*
78 # * (Description:)? (Description of function)?
79 # * (section header: (section description)? )*
82 # So .. the trivial example would be:
88 # If the Description: header tag is omitted, then there must be a blank line
89 # after the last parameter specification.
92 # * my_function - does my stuff
93 # * @my_arg: its mine damnit
95 # * Does my stuff explained.
100 # * my_function - does my stuff
101 # * @my_arg: its mine damnit
102 # * Description: Does my stuff explained.
106 # Besides functions you can also write documentation for structs, unions,
107 # enums and typedefs. Instead of the function name you must write the name
108 # of the declaration; the struct/union/enum/typedef must always precede
109 # the name. Nesting of declarations is not supported.
110 # Use the argument mechanism to document members or constants.
113 # * struct my_struct - short description
115 # * @b: second member
117 # * Longer description
126 # All descriptions can be multiline, except the short function description.
128 # You can also add additional sections. When documenting kernel functions you
129 # should document the "Context:" of the function, e.g. whether the functions
130 # can be called form interrupts. Unlike other sections you can end it with an
132 # Example-sections should contain the string EXAMPLE so that they are marked
133 # appropriately in DocBook.
137 # * user_function - function that can only be called in user context
138 # * @a: some argument
139 # * Context: !in_interrupt()
143 # * user_function(22);
148 # All descriptive text is further processed, scanning for the following special
149 # patterns, which are highlighted appropriately.
151 # 'funcname()' - function
152 # '$ENVVAR' - environmental variable
153 # '&struct_name' - name of a structure (up to two words including 'struct')
154 # '@parameter' - name of a parameter
155 # '%CONST' - name of a constant.
159 my $anon_struct_union = 0;
161 # match expressions used to find embedded type information
162 my $type_constant = '\%([-_\w]+)';
163 my $type_func = '(\w+)\(\)';
164 my $type_param = '\@(\w+)';
165 my $type_struct = '\&((struct\s*)*[_\w]+)';
166 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
167 my $type_env = '(\$\w+)';
169 # Output conversion substitutions.
170 # One for each output format
172 # these work fairly well
173 my %highlights_html = ( $type_constant, "<i>\$1</i>",
174 $type_func, "<b>\$1</b>",
175 $type_struct_xml, "<i>\$1</i>",
176 $type_env, "<b><i>\$1</i></b>",
177 $type_param, "<tt><b>\$1</b></tt>" );
178 my $local_lt = "\\\\\\\\lt:";
179 my $local_gt = "\\\\\\\\gt:";
180 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
182 # XML, docbook format
183 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
184 $type_constant, "<constant>\$1</constant>",
185 $type_func, "<function>\$1</function>",
186 $type_struct_xml, "<structname>\$1</structname>",
187 $type_env, "<envar>\$1</envar>",
188 $type_param, "<parameter>\$1</parameter>" );
189 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
191 # gnome, docbook format
192 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
193 $type_func, "<function>\$1</function>",
194 $type_struct, "<structname>\$1</structname>",
195 $type_env, "<envar>\$1</envar>",
196 $type_param, "<parameter>\$1</parameter>" );
197 my $blankline_gnome = "</para><para>\n";
199 # these are pretty rough
200 my %highlights_man = ( $type_constant, "\$1",
201 $type_func, "\\\\fB\$1\\\\fP",
202 $type_struct, "\\\\fI\$1\\\\fP",
203 $type_param, "\\\\fI\$1\\\\fP" );
204 my $blankline_man = "";
207 my %highlights_text = ( $type_constant, "\$1",
210 $type_param, "\$1" );
211 my $blankline_text = "";
215 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n";
216 print " [ -function funcname [ -function funcname ...] ]\n";
217 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
218 print " c source file(s) > outputfile\n";
219 print " -v : verbose output, more warnings & other info listed\n";
229 my $output_mode = "man";
230 my $no_doc_sections = 0;
231 my %highlights = %highlights_man;
232 my $blankline = $blankline_man;
233 my $modulename = "Kernel API";
234 my $function_only = 0;
235 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
236 'July', 'August', 'September', 'October',
237 'November', 'December')[(localtime)[4]] .
238 " " . ((localtime)[5]+1900);
240 # Essentially these are globals
241 # They probably want to be tidied up, made more localised or something.
242 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
243 # could cause "use of undefined value" or other bugs.
244 my ($function, %function_table, %parametertypes, $declaration_purpose);
245 my ($type, $declaration_name, $return_type);
246 my ($newsection, $newcontents, $prototype, $brcount, %source_map);
248 if (defined($ENV{'KBUILD_VERBOSE'})) {
249 $verbose = "$ENV{'KBUILD_VERBOSE'}";
252 # Generated docbook code is inserted in a template at a point where
253 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
254 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
255 # We keep track of number of generated entries and generate a dummy
256 # if needs be to ensure the expanded template can be postprocessed
258 my $section_counter = 0;
264 # 1 - looking for function name
265 # 2 - scanning field start.
266 # 3 - scanning prototype.
267 # 4 - documentation block
271 #declaration types: can be
272 # 'function', 'struct', 'union', 'enum', 'typedef'
275 my $doc_special = "\@\%\$\&";
277 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
279 my $doc_com = '\s*\*\s*';
280 my $doc_decl = $doc_com . '(\w+)';
281 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
282 my $doc_content = $doc_com . '(.*)';
283 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
294 my $section_default = "Description"; # default section
295 my $section_intro = "Introduction";
296 my $section = $section_default;
297 my $section_context = "Context";
299 my $undescribed = "-- undescribed --";
303 while ($ARGV[0] =~ m/^-(.*)/) {
304 my $cmd = shift @ARGV;
305 if ($cmd eq "-html") {
306 $output_mode = "html";
307 %highlights = %highlights_html;
308 $blankline = $blankline_html;
309 } elsif ($cmd eq "-man") {
310 $output_mode = "man";
311 %highlights = %highlights_man;
312 $blankline = $blankline_man;
313 } elsif ($cmd eq "-text") {
314 $output_mode = "text";
315 %highlights = %highlights_text;
316 $blankline = $blankline_text;
317 } elsif ($cmd eq "-docbook") {
318 $output_mode = "xml";
319 %highlights = %highlights_xml;
320 $blankline = $blankline_xml;
321 } elsif ($cmd eq "-gnome") {
322 $output_mode = "gnome";
323 %highlights = %highlights_gnome;
324 $blankline = $blankline_gnome;
325 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
326 $modulename = shift @ARGV;
327 } elsif ($cmd eq "-function") { # to only output specific functions
329 $function = shift @ARGV;
330 $function_table{$function} = 1;
331 } elsif ($cmd eq "-nofunction") { # to only output specific functions
333 $function = shift @ARGV;
334 $function_table{$function} = 1;
335 } elsif ($cmd eq "-v") {
337 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
339 } elsif ($cmd eq '-no-doc-sections') {
340 $no_doc_sections = 1;
344 # get kernel version from env
345 sub get_kernel_version
() {
346 my $version = 'unknown kernel version';
348 if (defined($ENV{'KERNELVERSION'})) {
349 $version = $ENV{'KERNELVERSION'};
353 my $kernelversion = get_kernel_version
();
355 # generate a sequence of code that will splice in highlighting information
356 # using the s// operator.
357 my $dohighlight = "";
358 foreach my $pattern (keys %highlights) {
359 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
360 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
364 # dumps section contents to arrays/hashes intended for that purpose.
369 my $contents = join "\n", @_;
371 if ($name =~ m/$type_constant/) {
373 # print STDERR "constant section '$1' = '$contents'\n";
374 $constants{$name} = $contents;
375 } elsif ($name =~ m/$type_param/) {
376 # print STDERR "parameter def '$1' = '$contents'\n";
378 $parameterdescs{$name} = $contents;
379 $sectcheck = $sectcheck . $name . " ";
380 } elsif ($name eq "@\.\.\.") {
381 # print STDERR "parameter def '...' = '$contents'\n";
383 $parameterdescs{$name} = $contents;
384 $sectcheck = $sectcheck . $name . " ";
386 # print STDERR "other section '$name' = '$contents'\n";
387 if (defined($sections{$name}) && ($sections{$name} ne "")) {
388 print STDERR
"Error(${file}:$.): duplicate section name '$name'\n";
391 $sections{$name} = $contents;
392 push @sectionlist, $name;
397 # dump DOC: section after checking that it should go out
399 sub dump_doc_section
{
402 my $contents = join "\n", @_;
404 if ($no_doc_sections) {
408 if (($function_only == 0) ||
409 ( $function_only == 1 && defined($function_table{$name})) ||
410 ( $function_only == 2 && !defined($function_table{$name})))
412 dump_section
($file, $name, $contents);
413 output_blockhead
({'sectionlist' => \
@sectionlist,
414 'sections' => \
%sections,
415 'module' => $modulename,
416 'content-only' => ($function_only != 0), });
423 # parameterdescs, a hash.
424 # function => "function name"
425 # parameterlist => @list of parameters
426 # parameterdescs => %parameter descriptions
427 # sectionlist => @list of sections
428 # sections => %section descriptions
431 sub output_highlight
{
432 my $contents = join "\n",@_;
436 # if (!defined $contents) {
438 # confess "output_highlight got called with no args?\n";
441 if ($output_mode eq "html" || $output_mode eq "xml") {
442 $contents = local_unescape
($contents);
443 # convert data read & converted thru xml_escape() into &xyz; format:
444 $contents =~ s/\\\\\\/&/g;
446 # print STDERR "contents b4:$contents\n";
449 # print STDERR "contents af:$contents\n";
451 foreach $line (split "\n", $contents) {
453 print $lineprefix, local_unescape
($blankline);
455 $line =~ s/\\\\\\/\&/g;
456 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
459 print $lineprefix, $line;
466 #output sections in html
467 sub output_section_html
(%) {
471 foreach $section (@
{$args{'sectionlist'}}) {
472 print "<h3>$section</h3>\n";
473 print "<blockquote>\n";
474 output_highlight
($args{'sections'}{$section});
475 print "</blockquote>\n";
479 # output enum in html
480 sub output_enum_html
(%) {
484 print "<h2>enum " . $args{'enum'} . "</h2>\n";
486 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
488 foreach $parameter (@
{$args{'parameterlist'}}) {
489 print " <b>" . $parameter . "</b>";
490 if ($count != $#{$args{'parameterlist'}}) {
498 print "<h3>Constants</h3>\n";
500 foreach $parameter (@
{$args{'parameterlist'}}) {
501 print "<dt><b>" . $parameter . "</b>\n";
503 output_highlight
($args{'parameterdescs'}{$parameter});
506 output_section_html
(@_);
510 # output typedef in html
511 sub output_typedef_html
(%) {
515 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
517 print "<b>typedef " . $args{'typedef'} . "</b>\n";
518 output_section_html
(@_);
522 # output struct in html
523 sub output_struct_html
(%) {
527 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
528 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
529 foreach $parameter (@
{$args{'parameterlist'}}) {
530 if ($parameter =~ /^#/) {
531 print "$parameter<br>\n";
534 my $parameter_name = $parameter;
535 $parameter_name =~ s/\[.*//;
537 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
538 $type = $args{'parametertypes'}{$parameter};
539 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
540 # pointer-to-function
541 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
542 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
544 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
546 print " <i>$type</i> <b>$parameter</b>;<br>\n";
551 print "<h3>Members</h3>\n";
553 foreach $parameter (@
{$args{'parameterlist'}}) {
554 ($parameter =~ /^#/) && next;
556 my $parameter_name = $parameter;
557 $parameter_name =~ s/\[.*//;
559 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
560 print "<dt><b>" . $parameter . "</b>\n";
562 output_highlight
($args{'parameterdescs'}{$parameter_name});
565 output_section_html
(@_);
569 # output function in html
570 sub output_function_html
(%) {
572 my ($parameter, $section);
575 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
576 print "<i>" . $args{'functiontype'} . "</i>\n";
577 print "<b>" . $args{'function'} . "</b>\n";
580 foreach $parameter (@
{$args{'parameterlist'}}) {
581 $type = $args{'parametertypes'}{$parameter};
582 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
583 # pointer-to-function
584 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
586 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
588 if ($count != $#{$args{'parameterlist'}}) {
595 print "<h3>Arguments</h3>\n";
597 foreach $parameter (@
{$args{'parameterlist'}}) {
598 my $parameter_name = $parameter;
599 $parameter_name =~ s/\[.*//;
601 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
602 print "<dt><b>" . $parameter . "</b>\n";
604 output_highlight
($args{'parameterdescs'}{$parameter_name});
607 output_section_html
(@_);
611 # output DOC: block header in html
612 sub output_blockhead_html
(%) {
614 my ($parameter, $section);
617 foreach $section (@
{$args{'sectionlist'}}) {
618 print "<h3>$section</h3>\n";
620 output_highlight
($args{'sections'}{$section});
626 sub output_section_xml
(%) {
629 # print out each section
631 foreach $section (@
{$args{'sectionlist'}}) {
632 print "<refsect1>\n";
633 print "<title>$section</title>\n";
634 if ($section =~ m/EXAMPLE/i) {
635 print "<informalexample><programlisting>\n";
639 output_highlight
($args{'sections'}{$section});
640 if ($section =~ m/EXAMPLE/i) {
641 print "</programlisting></informalexample>\n";
645 print "</refsect1>\n";
649 # output function in XML DocBook
650 sub output_function_xml
(%) {
652 my ($parameter, $section);
656 $id = "API-" . $args{'function'};
657 $id =~ s/[^A-Za-z0-9]/-/g;
659 print "<refentry id=\"$id\">\n";
660 print "<refentryinfo>\n";
661 print " <title>LINUX</title>\n";
662 print " <productname>Kernel Hackers Manual</productname>\n";
663 print " <date>$man_date</date>\n";
664 print "</refentryinfo>\n";
666 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
667 print " <manvolnum>9</manvolnum>\n";
668 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
669 print "</refmeta>\n";
670 print "<refnamediv>\n";
671 print " <refname>" . $args{'function'} . "</refname>\n";
672 print " <refpurpose>\n";
674 output_highlight
($args{'purpose'});
675 print " </refpurpose>\n";
676 print "</refnamediv>\n";
678 print "<refsynopsisdiv>\n";
679 print " <title>Synopsis</title>\n";
680 print " <funcsynopsis><funcprototype>\n";
681 print " <funcdef>" . $args{'functiontype'} . " ";
682 print "<function>" . $args{'function'} . " </function></funcdef>\n";
685 if ($#{$args{'parameterlist'}} >= 0) {
686 foreach $parameter (@
{$args{'parameterlist'}}) {
687 $type = $args{'parametertypes'}{$parameter};
688 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
689 # pointer-to-function
690 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
691 print " <funcparams>$2</funcparams></paramdef>\n";
693 print " <paramdef>" . $type;
694 print " <parameter>$parameter</parameter></paramdef>\n";
700 print " </funcprototype></funcsynopsis>\n";
701 print "</refsynopsisdiv>\n";
704 print "<refsect1>\n <title>Arguments</title>\n";
705 if ($#{$args{'parameterlist'}} >= 0) {
706 print " <variablelist>\n";
707 foreach $parameter (@
{$args{'parameterlist'}}) {
708 my $parameter_name = $parameter;
709 $parameter_name =~ s/\[.*//;
711 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
712 print " <listitem>\n <para>\n";
714 output_highlight
($args{'parameterdescs'}{$parameter_name});
715 print " </para>\n </listitem>\n </varlistentry>\n";
717 print " </variablelist>\n";
719 print " <para>\n None\n </para>\n";
721 print "</refsect1>\n";
723 output_section_xml
(@_);
724 print "</refentry>\n\n";
727 # output struct in XML DocBook
728 sub output_struct_xml
(%) {
730 my ($parameter, $section);
733 $id = "API-struct-" . $args{'struct'};
734 $id =~ s/[^A-Za-z0-9]/-/g;
736 print "<refentry id=\"$id\">\n";
737 print "<refentryinfo>\n";
738 print " <title>LINUX</title>\n";
739 print " <productname>Kernel Hackers Manual</productname>\n";
740 print " <date>$man_date</date>\n";
741 print "</refentryinfo>\n";
743 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
744 print " <manvolnum>9</manvolnum>\n";
745 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
746 print "</refmeta>\n";
747 print "<refnamediv>\n";
748 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
749 print " <refpurpose>\n";
751 output_highlight
($args{'purpose'});
752 print " </refpurpose>\n";
753 print "</refnamediv>\n";
755 print "<refsynopsisdiv>\n";
756 print " <title>Synopsis</title>\n";
757 print " <programlisting>\n";
758 print $args{'type'} . " " . $args{'struct'} . " {\n";
759 foreach $parameter (@
{$args{'parameterlist'}}) {
760 if ($parameter =~ /^#/) {
761 print "$parameter\n";
765 my $parameter_name = $parameter;
766 $parameter_name =~ s/\[.*//;
768 defined($args{'parameterdescs'}{$parameter_name}) || next;
769 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
770 $type = $args{'parametertypes'}{$parameter};
771 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
772 # pointer-to-function
773 print " $1 $parameter) ($2);\n";
774 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
776 print " $1 $parameter$2;\n";
778 print " " . $type . " " . $parameter . ";\n";
782 print " </programlisting>\n";
783 print "</refsynopsisdiv>\n";
785 print " <refsect1>\n";
786 print " <title>Members</title>\n";
788 if ($#{$args{'parameterlist'}} >= 0) {
789 print " <variablelist>\n";
790 foreach $parameter (@
{$args{'parameterlist'}}) {
791 ($parameter =~ /^#/) && next;
793 my $parameter_name = $parameter;
794 $parameter_name =~ s/\[.*//;
796 defined($args{'parameterdescs'}{$parameter_name}) || next;
797 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
798 print " <varlistentry>";
799 print " <term>$parameter</term>\n";
800 print " <listitem><para>\n";
801 output_highlight
($args{'parameterdescs'}{$parameter_name});
802 print " </para></listitem>\n";
803 print " </varlistentry>\n";
805 print " </variablelist>\n";
807 print " <para>\n None\n </para>\n";
809 print " </refsect1>\n";
811 output_section_xml
(@_);
813 print "</refentry>\n\n";
816 # output enum in XML DocBook
817 sub output_enum_xml
(%) {
819 my ($parameter, $section);
823 $id = "API-enum-" . $args{'enum'};
824 $id =~ s/[^A-Za-z0-9]/-/g;
826 print "<refentry id=\"$id\">\n";
827 print "<refentryinfo>\n";
828 print " <title>LINUX</title>\n";
829 print " <productname>Kernel Hackers Manual</productname>\n";
830 print " <date>$man_date</date>\n";
831 print "</refentryinfo>\n";
833 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
834 print " <manvolnum>9</manvolnum>\n";
835 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
836 print "</refmeta>\n";
837 print "<refnamediv>\n";
838 print " <refname>enum " . $args{'enum'} . "</refname>\n";
839 print " <refpurpose>\n";
841 output_highlight
($args{'purpose'});
842 print " </refpurpose>\n";
843 print "</refnamediv>\n";
845 print "<refsynopsisdiv>\n";
846 print " <title>Synopsis</title>\n";
847 print " <programlisting>\n";
848 print "enum " . $args{'enum'} . " {\n";
850 foreach $parameter (@
{$args{'parameterlist'}}) {
852 if ($count != $#{$args{'parameterlist'}}) {
859 print " </programlisting>\n";
860 print "</refsynopsisdiv>\n";
862 print "<refsect1>\n";
863 print " <title>Constants</title>\n";
864 print " <variablelist>\n";
865 foreach $parameter (@
{$args{'parameterlist'}}) {
866 my $parameter_name = $parameter;
867 $parameter_name =~ s/\[.*//;
869 print " <varlistentry>";
870 print " <term>$parameter</term>\n";
871 print " <listitem><para>\n";
872 output_highlight
($args{'parameterdescs'}{$parameter_name});
873 print " </para></listitem>\n";
874 print " </varlistentry>\n";
876 print " </variablelist>\n";
877 print "</refsect1>\n";
879 output_section_xml
(@_);
881 print "</refentry>\n\n";
884 # output typedef in XML DocBook
885 sub output_typedef_xml
(%) {
887 my ($parameter, $section);
890 $id = "API-typedef-" . $args{'typedef'};
891 $id =~ s/[^A-Za-z0-9]/-/g;
893 print "<refentry id=\"$id\">\n";
894 print "<refentryinfo>\n";
895 print " <title>LINUX</title>\n";
896 print " <productname>Kernel Hackers Manual</productname>\n";
897 print " <date>$man_date</date>\n";
898 print "</refentryinfo>\n";
900 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
901 print " <manvolnum>9</manvolnum>\n";
902 print "</refmeta>\n";
903 print "<refnamediv>\n";
904 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
905 print " <refpurpose>\n";
907 output_highlight
($args{'purpose'});
908 print " </refpurpose>\n";
909 print "</refnamediv>\n";
911 print "<refsynopsisdiv>\n";
912 print " <title>Synopsis</title>\n";
913 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
914 print "</refsynopsisdiv>\n";
916 output_section_xml
(@_);
918 print "</refentry>\n\n";
921 # output in XML DocBook
922 sub output_blockhead_xml
(%) {
924 my ($parameter, $section);
927 my $id = $args{'module'};
928 $id =~ s/[^A-Za-z0-9]/-/g;
930 # print out each section
932 foreach $section (@
{$args{'sectionlist'}}) {
933 if (!$args{'content-only'}) {
934 print "<refsect1>\n <title>$section</title>\n";
936 if ($section =~ m/EXAMPLE/i) {
937 print "<example><para>\n";
941 output_highlight
($args{'sections'}{$section});
942 if ($section =~ m/EXAMPLE/i) {
943 print "</para></example>\n";
947 if (!$args{'content-only'}) {
948 print "\n</refsect1>\n";
955 # output in XML DocBook
956 sub output_function_gnome
{
958 my ($parameter, $section);
962 $id = $args{'module'} . "-" . $args{'function'};
963 $id =~ s/[^A-Za-z0-9]/-/g;
966 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
968 print " <funcsynopsis>\n";
969 print " <funcdef>" . $args{'functiontype'} . " ";
970 print "<function>" . $args{'function'} . " ";
971 print "</function></funcdef>\n";
974 if ($#{$args{'parameterlist'}} >= 0) {
975 foreach $parameter (@
{$args{'parameterlist'}}) {
976 $type = $args{'parametertypes'}{$parameter};
977 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
978 # pointer-to-function
979 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
980 print " <funcparams>$2</funcparams></paramdef>\n";
982 print " <paramdef>" . $type;
983 print " <parameter>$parameter</parameter></paramdef>\n";
989 print " </funcsynopsis>\n";
990 if ($#{$args{'parameterlist'}} >= 0) {
991 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
992 print "<tgroup cols=\"2\">\n";
993 print "<colspec colwidth=\"2*\">\n";
994 print "<colspec colwidth=\"8*\">\n";
996 foreach $parameter (@
{$args{'parameterlist'}}) {
997 my $parameter_name = $parameter;
998 $parameter_name =~ s/\[.*//;
1000 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1003 output_highlight
($args{'parameterdescs'}{$parameter_name});
1004 print " </entry></row>\n";
1006 print " </tbody></tgroup></informaltable>\n";
1008 print " <para>\n None\n </para>\n";
1011 # print out each section
1013 foreach $section (@
{$args{'sectionlist'}}) {
1014 print "<simplesect>\n <title>$section</title>\n";
1015 if ($section =~ m/EXAMPLE/i) {
1016 print "<example><programlisting>\n";
1020 output_highlight
($args{'sections'}{$section});
1022 if ($section =~ m/EXAMPLE/i) {
1023 print "</programlisting></example>\n";
1026 print " </simplesect>\n";
1029 print "</sect2>\n\n";
1033 # output function in man
1034 sub output_function_man
(%) {
1035 my %args = %{$_[0]};
1036 my ($parameter, $section);
1039 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1042 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1044 print ".SH SYNOPSIS\n";
1045 if ($args{'functiontype'} ne "") {
1046 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1048 print ".B \"" . $args{'function'} . "\n";
1053 foreach my $parameter (@
{$args{'parameterlist'}}) {
1054 if ($count == $#{$args{'parameterlist'}}) {
1057 $type = $args{'parametertypes'}{$parameter};
1058 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1059 # pointer-to-function
1060 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1062 $type =~ s/([^\*])$/$1 /;
1063 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1069 print ".SH ARGUMENTS\n";
1070 foreach $parameter (@
{$args{'parameterlist'}}) {
1071 my $parameter_name = $parameter;
1072 $parameter_name =~ s/\[.*//;
1074 print ".IP \"" . $parameter . "\" 12\n";
1075 output_highlight
($args{'parameterdescs'}{$parameter_name});
1077 foreach $section (@
{$args{'sectionlist'}}) {
1078 print ".SH \"", uc $section, "\"\n";
1079 output_highlight
($args{'sections'}{$section});
1084 # output enum in man
1085 sub output_enum_man
(%) {
1086 my %args = %{$_[0]};
1087 my ($parameter, $section);
1090 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1093 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1095 print ".SH SYNOPSIS\n";
1096 print "enum " . $args{'enum'} . " {\n";
1098 foreach my $parameter (@
{$args{'parameterlist'}}) {
1099 print ".br\n.BI \" $parameter\"\n";
1100 if ($count == $#{$args{'parameterlist'}}) {
1110 print ".SH Constants\n";
1111 foreach $parameter (@
{$args{'parameterlist'}}) {
1112 my $parameter_name = $parameter;
1113 $parameter_name =~ s/\[.*//;
1115 print ".IP \"" . $parameter . "\" 12\n";
1116 output_highlight
($args{'parameterdescs'}{$parameter_name});
1118 foreach $section (@
{$args{'sectionlist'}}) {
1119 print ".SH \"$section\"\n";
1120 output_highlight
($args{'sections'}{$section});
1125 # output struct in man
1126 sub output_struct_man
(%) {
1127 my %args = %{$_[0]};
1128 my ($parameter, $section);
1130 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1133 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1135 print ".SH SYNOPSIS\n";
1136 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1138 foreach my $parameter (@
{$args{'parameterlist'}}) {
1139 if ($parameter =~ /^#/) {
1140 print ".BI \"$parameter\"\n.br\n";
1143 my $parameter_name = $parameter;
1144 $parameter_name =~ s/\[.*//;
1146 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1147 $type = $args{'parametertypes'}{$parameter};
1148 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1149 # pointer-to-function
1150 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1151 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1153 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1155 $type =~ s/([^\*])$/$1 /;
1156 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1162 print ".SH Members\n";
1163 foreach $parameter (@
{$args{'parameterlist'}}) {
1164 ($parameter =~ /^#/) && next;
1166 my $parameter_name = $parameter;
1167 $parameter_name =~ s/\[.*//;
1169 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1170 print ".IP \"" . $parameter . "\" 12\n";
1171 output_highlight
($args{'parameterdescs'}{$parameter_name});
1173 foreach $section (@
{$args{'sectionlist'}}) {
1174 print ".SH \"$section\"\n";
1175 output_highlight
($args{'sections'}{$section});
1180 # output typedef in man
1181 sub output_typedef_man
(%) {
1182 my %args = %{$_[0]};
1183 my ($parameter, $section);
1185 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1188 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1190 foreach $section (@
{$args{'sectionlist'}}) {
1191 print ".SH \"$section\"\n";
1192 output_highlight
($args{'sections'}{$section});
1196 sub output_blockhead_man
(%) {
1197 my %args = %{$_[0]};
1198 my ($parameter, $section);
1201 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1203 foreach $section (@
{$args{'sectionlist'}}) {
1204 print ".SH \"$section\"\n";
1205 output_highlight
($args{'sections'}{$section});
1211 sub output_function_text
(%) {
1212 my %args = %{$_[0]};
1213 my ($parameter, $section);
1217 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1219 print "\nSynopsis:\n\n";
1220 if ($args{'functiontype'} ne "") {
1221 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1223 $start = $args{'function'} . " (";
1228 foreach my $parameter (@
{$args{'parameterlist'}}) {
1229 $type = $args{'parametertypes'}{$parameter};
1230 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1231 # pointer-to-function
1232 print $1 . $parameter . ") (" . $2;
1234 print $type . " " . $parameter;
1236 if ($count != $#{$args{'parameterlist'}}) {
1239 print " " x
length($start);
1245 print "Arguments:\n\n";
1246 foreach $parameter (@
{$args{'parameterlist'}}) {
1247 my $parameter_name = $parameter;
1248 $parameter_name =~ s/\[.*//;
1250 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1252 output_section_text
(@_);
1255 #output sections in text
1256 sub output_section_text
(%) {
1257 my %args = %{$_[0]};
1261 foreach $section (@
{$args{'sectionlist'}}) {
1262 print "$section:\n\n";
1263 output_highlight
($args{'sections'}{$section});
1268 # output enum in text
1269 sub output_enum_text
(%) {
1270 my %args = %{$_[0]};
1275 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1276 print "enum " . $args{'enum'} . " {\n";
1278 foreach $parameter (@
{$args{'parameterlist'}}) {
1279 print "\t$parameter";
1280 if ($count != $#{$args{'parameterlist'}}) {
1288 print "Constants:\n\n";
1289 foreach $parameter (@
{$args{'parameterlist'}}) {
1290 print "$parameter\n\t";
1291 print $args{'parameterdescs'}{$parameter} . "\n";
1294 output_section_text
(@_);
1297 # output typedef in text
1298 sub output_typedef_text
(%) {
1299 my %args = %{$_[0]};
1302 print "Typedef:\n\n";
1304 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1305 output_section_text
(@_);
1308 # output struct as text
1309 sub output_struct_text
(%) {
1310 my %args = %{$_[0]};
1313 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1314 print $args{'type'} . " " . $args{'struct'} . " {\n";
1315 foreach $parameter (@
{$args{'parameterlist'}}) {
1316 if ($parameter =~ /^#/) {
1317 print "$parameter\n";
1321 my $parameter_name = $parameter;
1322 $parameter_name =~ s/\[.*//;
1324 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1325 $type = $args{'parametertypes'}{$parameter};
1326 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1327 # pointer-to-function
1328 print "\t$1 $parameter) ($2);\n";
1329 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1331 print "\t$1 $parameter$2;\n";
1333 print "\t" . $type . " " . $parameter . ";\n";
1338 print "Members:\n\n";
1339 foreach $parameter (@
{$args{'parameterlist'}}) {
1340 ($parameter =~ /^#/) && next;
1342 my $parameter_name = $parameter;
1343 $parameter_name =~ s/\[.*//;
1345 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1346 print "$parameter\n\t";
1347 print $args{'parameterdescs'}{$parameter_name} . "\n";
1350 output_section_text
(@_);
1353 sub output_blockhead_text
(%) {
1354 my %args = %{$_[0]};
1355 my ($parameter, $section);
1357 foreach $section (@
{$args{'sectionlist'}}) {
1358 print " $section:\n";
1360 output_highlight
($args{'sections'}{$section});
1365 # generic output function for all types (function, struct/union, typedef, enum);
1366 # calls the generated, variable output_ function name based on
1367 # functype and output_mode
1368 sub output_declaration
{
1371 my $functype = shift;
1372 my $func = "output_${functype}_$output_mode";
1373 if (($function_only==0) ||
1374 ( $function_only == 1 && defined($function_table{$name})) ||
1375 ( $function_only == 2 && !defined($function_table{$name})))
1383 # generic output function - calls the right one based on current output mode.
1384 sub output_blockhead
{
1386 my $func = "output_blockhead_" . $output_mode;
1392 # takes a declaration (struct, union, enum, typedef) and
1393 # invokes the right handler. NOT called for functions.
1394 sub dump_declaration
($$) {
1396 my ($prototype, $file) = @_;
1397 my $func = "dump_" . $decl_type;
1401 sub dump_union
($$) {
1405 sub dump_struct
($$) {
1410 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1411 #my $decl_type = $1;
1412 $declaration_name = $2;
1415 # ignore embedded structs or unions
1416 $members =~ s/({.*})//g;
1419 # ignore members marked private:
1420 $members =~ s/\/\*\s*private:.*?\/\
*\s
*public
:.*?\
*\
///gos
;
1421 $members =~ s/\/\*\s*private:.*//gos
;
1423 $members =~ s/\/\*.*?\*\///gos;
1424 $nested =~ s/\/\*.*?\*\///gos;
1425 # strip kmemcheck_bitfield_{begin,end}.*;
1426 $members =~ s/kmemcheck_bitfield_.*?;//gos;
1428 $members =~ s/__aligned\s*\(\d+\)//gos;
1430 create_parameterlist
($members, ';', $file);
1431 check_sections
($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1433 output_declaration
($declaration_name,
1435 {'struct' => $declaration_name,
1436 'module' => $modulename,
1437 'parameterlist' => \
@parameterlist,
1438 'parameterdescs' => \
%parameterdescs,
1439 'parametertypes' => \
%parametertypes,
1440 'sectionlist' => \
@sectionlist,
1441 'sections' => \
%sections,
1442 'purpose' => $declaration_purpose,
1443 'type' => $decl_type
1447 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1456 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1457 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1459 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1460 $declaration_name = $1;
1463 foreach my $arg (split ',', $members) {
1464 $arg =~ s/^\s*(\w+).*/$1/;
1465 push @parameterlist, $arg;
1466 if (!$parameterdescs{$arg}) {
1467 $parameterdescs{$arg} = $undescribed;
1468 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1469 "not described in enum '$declaration_name'\n";
1474 output_declaration
($declaration_name,
1476 {'enum' => $declaration_name,
1477 'module' => $modulename,
1478 'parameterlist' => \
@parameterlist,
1479 'parameterdescs' => \
%parameterdescs,
1480 'sectionlist' => \
@sectionlist,
1481 'sections' => \
%sections,
1482 'purpose' => $declaration_purpose
1486 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1491 sub dump_typedef
($$) {
1495 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1496 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1497 $x =~ s/\(*.\)\s*;$/;/;
1498 $x =~ s/\[*.\]\s*;$/;/;
1501 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1502 $declaration_name = $1;
1504 output_declaration
($declaration_name,
1506 {'typedef' => $declaration_name,
1507 'module' => $modulename,
1508 'sectionlist' => \
@sectionlist,
1509 'sections' => \
%sections,
1510 'purpose' => $declaration_purpose
1514 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1519 sub save_struct_actual
($) {
1522 # strip all spaces from the actual param so that it looks like one string item
1523 $actual =~ s/\s*//g;
1524 $struct_actual = $struct_actual . $actual . " ";
1527 sub create_parameterlist
($$$) {
1529 my $splitter = shift;
1534 # temporarily replace commas inside function pointer definition
1535 while ($args =~ /(\([^\),]+),/) {
1536 $args =~ s/(\([^\),]+),/$1#/g;
1539 foreach my $arg (split($splitter, $args)) {
1541 $arg =~ s/\/\*.*\*\///;
1542 # strip leading/trailing spaces
1548 # Treat preprocessor directive as a typeless variable just to fill
1549 # corresponding data structures "correctly". Catch it later in
1551 push_parameter
($arg, "", $file);
1552 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1553 # pointer-to-function
1555 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1558 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1559 save_struct_actual
($param);
1560 push_parameter
($param, $type, $file);
1562 $arg =~ s/\s*:\s*/:/g;
1563 $arg =~ s/\s*\[/\[/g;
1565 my @args = split('\s*,\s*', $arg);
1566 if ($args[0] =~ m/\*/) {
1567 $args[0] =~ s/(\*+)\s*/ $1/;
1571 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1573 push(@first_arg, split('\s+', $1));
1574 push(@first_arg, $2);
1576 @first_arg = split('\s+', shift @args);
1579 unshift(@args, pop @first_arg);
1580 $type = join " ", @first_arg;
1582 foreach $param (@args) {
1583 if ($param =~ m/^(\*+)\s*(.*)/) {
1584 save_struct_actual
($2);
1585 push_parameter
($2, "$type $1", $file);
1587 elsif ($param =~ m/(.*?):(\d+)/) {
1588 if ($type ne "") { # skip unnamed bit-fields
1589 save_struct_actual
($1);
1590 push_parameter
($1, "$type:$2", $file)
1594 save_struct_actual
($param);
1595 push_parameter
($param, $type, $file);
1602 sub push_parameter
($$$) {
1607 if (($anon_struct_union == 1) && ($type eq "") &&
1609 return; # ignore the ending }; from anon. struct/union
1612 $anon_struct_union = 0;
1613 my $param_name = $param;
1614 $param_name =~ s/\[.*//;
1616 if ($type eq "" && $param =~ /\.\.\.$/)
1618 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1619 $parameterdescs{$param} = "variable arguments";
1622 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1625 $parameterdescs{void
} = "no arguments";
1627 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1628 # handle unnamed (anonymous) union or struct:
1631 $param = "{unnamed_" . $param . "}";
1632 $parameterdescs{$param} = "anonymous\n";
1633 $anon_struct_union = 1;
1636 # warn if parameter has no description
1637 # (but ignore ones starting with # as these are not parameters
1638 # but inline preprocessor statements);
1639 # also ignore unnamed structs/unions;
1640 if (!$anon_struct_union) {
1641 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1643 $parameterdescs{$param_name} = $undescribed;
1645 if (($type eq 'function') || ($type eq 'enum')) {
1646 print STDERR
"Warning(${file}:$.): Function parameter ".
1647 "or member '$param' not " .
1648 "described in '$declaration_name'\n";
1650 print STDERR
"Warning(${file}:$.):" .
1651 " No description found for parameter '$param'\n";
1656 # strip spaces from $param so that it is one continous string
1657 # on @parameterlist;
1658 # this fixes a problem where check_sections() cannot find
1659 # a parameter like "addr[6 + 2]" because it actually appears
1660 # as "addr[6", "+", "2]" on the parameter list;
1661 # but it's better to maintain the param string unchanged for output,
1662 # so just weaken the string compare in check_sections() to ignore
1663 # "[blah" in a parameter string;
1664 ###$param =~ s/\s*//g;
1665 push @parameterlist, $param;
1666 $parametertypes{$param} = $type;
1669 sub check_sections
($$$$$$) {
1670 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1671 my @sects = split ' ', $sectcheck;
1672 my @prms = split ' ', $prmscheck;
1675 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1677 foreach $sx (0 .. $#sects) {
1679 foreach $px (0 .. $#prms) {
1680 $prm_clean = $prms[$px];
1681 $prm_clean =~ s/\[.*\]//;
1682 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//;
1683 # ignore array size in a parameter string;
1684 # however, the original param string may contain
1685 # spaces, e.g.: addr[6 + 2]
1686 # and this appears in @prms as "addr[6" since the
1687 # parameter list is split at spaces;
1688 # hence just ignore "[..." for the sections check;
1689 $prm_clean =~ s/\[.*//;
1691 ##$prm_clean =~ s/^\**//;
1692 if ($prm_clean eq $sects[$sx]) {
1698 if ($decl_type eq "function") {
1699 print STDERR
"Warning(${file}:$.): " .
1700 "Excess function parameter " .
1702 "description in '$decl_name'\n";
1705 if ($nested !~ m/\Q$sects[$sx]\E/) {
1706 print STDERR
"Warning(${file}:$.): " .
1707 "Excess struct/union/enum/typedef member " .
1709 "description in '$decl_name'\n";
1718 # takes a function prototype and the name of the current file being
1719 # processed and spits out all the details stored in the global
1721 sub dump_function
($$) {
1722 my $prototype = shift;
1725 $prototype =~ s/^static +//;
1726 $prototype =~ s/^extern +//;
1727 $prototype =~ s/^asmlinkage +//;
1728 $prototype =~ s/^inline +//;
1729 $prototype =~ s/^__inline__ +//;
1730 $prototype =~ s/^__inline +//;
1731 $prototype =~ s/^__always_inline +//;
1732 $prototype =~ s/^noinline +//;
1733 $prototype =~ s/__devinit +//;
1734 $prototype =~ s/__init +//;
1735 $prototype =~ s/__init_or_module +//;
1736 $prototype =~ s/^#\s*define\s+//; #ak added
1737 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1739 # Yes, this truly is vile. We are looking for:
1740 # 1. Return type (may be nothing if we're looking at a macro)
1742 # 3. Function parameters.
1744 # All the while we have to watch out for function pointer parameters
1745 # (which IIRC is what the two sections are for), C types (these
1746 # regexps don't even start to express all the possibilities), and
1749 # If you mess with these regexps, it's a good idea to check that
1750 # the following functions' documentation still comes out right:
1751 # - parport_register_device (function pointer parameters)
1752 # - atomic_set (macro)
1753 # - pci_match_device, __copy_to_user (long return type)
1755 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1756 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1757 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1758 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1759 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1760 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1761 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1762 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1763 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1764 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1765 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1766 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1767 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1768 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1769 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1770 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1771 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1773 $declaration_name = $2;
1776 create_parameterlist
($args, ',', $file);
1778 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1783 my $prms = join " ", @parameterlist;
1784 check_sections
($file, $declaration_name, "function", $sectcheck, $prms, "");
1786 output_declaration
($declaration_name,
1788 {'function' => $declaration_name,
1789 'module' => $modulename,
1790 'functiontype' => $return_type,
1791 'parameterlist' => \
@parameterlist,
1792 'parameterdescs' => \
%parameterdescs,
1793 'parametertypes' => \
%parametertypes,
1794 'sectionlist' => \
@sectionlist,
1795 'sections' => \
%sections,
1796 'purpose' => $declaration_purpose
1800 sub process_file
($);
1802 # Read the file that maps relative names to absolute names for
1803 # separate source and object directories and for shadow trees.
1804 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
1805 my ($relname, $absname);
1806 while(<SOURCE_MAP
>) {
1808 ($relname, $absname) = (split())[0..1];
1809 $relname =~ s
:^/+::;
1810 $source_map{$relname} = $absname;
1819 if ($verbose && $errors) {
1820 print STDERR
"$errors errors\n";
1822 if ($verbose && $warnings) {
1823 print STDERR
"$warnings warnings\n";
1831 %parameterdescs = ();
1832 %parametertypes = ();
1833 @parameterlist = ();
1837 $struct_actual = "";
1843 sub tracepoint_munge
($) {
1845 my $tracepointname = 0;
1846 my $tracepointargs = 0;
1848 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
1849 $tracepointname = $1;
1851 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1852 $tracepointname = $1;
1854 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1855 $tracepointname = $2;
1857 $tracepointname =~ s/^\s+//; #strip leading whitespace
1858 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
1859 $tracepointargs = $1;
1861 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
1862 print STDERR
"Warning(${file}:$.): Unrecognized tracepoint format: \n".
1865 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1869 sub syscall_munge
() {
1872 $prototype =~ s@
[\r\n\t]+@
@gos; # strip newlines/CR's/tabs
1873 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1874 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1876 ## $prototype = "long sys_$1(void)";
1879 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1880 if ($prototype =~ m/long (sys_.*?),/) {
1881 $prototype =~ s/,/\(/;
1883 $prototype =~ s/\)/\(void\)/;
1886 # now delete all of the odd-number commas in $prototype
1887 # so that arg types & arg names don't have a comma between them
1889 my $len = length($prototype);
1891 $len = 0; # skip the for-loop
1893 for (my $ix = 0; $ix < $len; $ix++) {
1894 if (substr($prototype, $ix, 1) eq ',') {
1896 if ($count % 2 == 1) {
1897 substr($prototype, $ix, 1) = ' ';
1903 sub process_state3_function
($$) {
1907 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
1909 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1912 elsif ($x =~ /([^\{]*)/) {
1916 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
1917 $prototype =~ s@
/\*.*?\*/@
@gos; # strip comments.
1918 $prototype =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1919 $prototype =~ s@
^\s
+@
@gos; # strip leading spaces
1920 if ($prototype =~ /SYSCALL_DEFINE/) {
1923 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1924 $prototype =~ /DEFINE_SINGLE_EVENT/)
1926 tracepoint_munge
($file);
1928 dump_function
($prototype, $file);
1933 sub process_state3_type
($$) {
1937 $x =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1938 $x =~ s@
^\s
+@
@gos; # strip leading spaces
1939 $x =~ s@\s
+$@
@gos; # strip trailing spaces
1940 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
1943 # To distinguish preprocessor directive from regular declaration later.
1948 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1949 $prototype .= $1 . $2;
1950 ($2 eq '{') && $brcount++;
1951 ($2 eq '}') && $brcount--;
1952 if (($2 eq ';') && ($brcount == 0)) {
1953 dump_declaration
($prototype, $file);
1965 # xml_escape: replace <, >, and & in the text stream;
1967 # however, formatting controls that are generated internally/locally in the
1968 # kernel-doc script are not escaped here; instead, they begin life like
1969 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1970 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1971 # just before actual output; (this is done by local_unescape())
1974 if (($output_mode eq "text") || ($output_mode eq "man")) {
1977 $text =~ s/\&/\\\\\\amp;/g;
1978 $text =~ s/\</\\\\\\lt;/g;
1979 $text =~ s/\>/\\\\\\gt;/g;
1983 # convert local escape strings to html
1984 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1985 sub local_unescape
($) {
1987 if (($output_mode eq "text") || ($output_mode eq "man")) {
1990 $text =~ s/\\\\\\\\lt:/</g;
1991 $text =~ s/\\\\\\\\gt:/>/g;
1995 sub process_file
($) {
2001 my $initial_section_counter = $section_counter;
2003 if (defined($ENV{'SRCTREE'})) {
2004 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2009 if (defined($source_map{$file})) {
2010 $file = $source_map{$file};
2013 if (!open(IN
,"<$file")) {
2014 print STDERR
"Error: Cannot open file $file\n";
2021 $section_counter = 0;
2024 if (/$doc_start/o) {
2025 $state = 1; # next line is always the function name
2028 } elsif ($state == 1) { # this line is the function name (always)
2029 if (/$doc_block/o) {
2033 $section = $section_intro;
2038 elsif (/$doc_decl/o) {
2040 if (/\s*([\w\s]+?)\s*-/) {
2046 # strip leading/trailing/multiple spaces
2051 $declaration_purpose = xml_escape
($descr);
2054 $declaration_purpose = "";
2057 if (($declaration_purpose eq "") && $verbose) {
2058 print STDERR
"Warning(${file}:$.): missing initial short description on line:\n";
2063 if ($identifier =~ m/^struct/) {
2064 $decl_type = 'struct';
2065 } elsif ($identifier =~ m/^union/) {
2066 $decl_type = 'union';
2067 } elsif ($identifier =~ m/^enum/) {
2068 $decl_type = 'enum';
2069 } elsif ($identifier =~ m/^typedef/) {
2070 $decl_type = 'typedef';
2072 $decl_type = 'function';
2076 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
2079 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
2080 " - I thought it was a doc line\n";
2084 } elsif ($state == 2) { # look for head: lines, and include content
2089 if (($contents ne "") && ($contents ne "\n")) {
2090 if (!$in_doc_sect && $verbose) {
2091 print STDERR
"Warning(${file}:$.): contents before sections\n";
2094 dump_section
($file, $section, xml_escape
($contents));
2095 $section = $section_default;
2100 $contents = $newcontents;
2101 if ($contents ne "") {
2102 while ((substr($contents, 0, 1) eq " ") ||
2103 substr($contents, 0, 1) eq "\t") {
2104 $contents = substr($contents, 1);
2108 $section = $newsection;
2109 } elsif (/$doc_end/) {
2111 if (($contents ne "") && ($contents ne "\n")) {
2112 dump_section
($file, $section, xml_escape
($contents));
2113 $section = $section_default;
2116 # look for doc_com + <text> + doc_end:
2117 if ($_ =~ m
'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2118 print STDERR
"Warning(${file}:$.): suspicious ending line: $_";
2125 # print STDERR "end of doc comment, looking for prototype\n";
2126 } elsif (/$doc_content/) {
2127 # miguel-style comment kludge, look for blank lines after
2128 # @parameter line to signify start of description
2130 if ($section =~ m/^@/ || $section eq $section_context) {
2131 dump_section
($file, $section, xml_escape
($contents));
2132 $section = $section_default;
2138 } elsif ($in_purpose == 1) {
2139 # Continued declaration purpose
2140 chomp($declaration_purpose);
2141 $declaration_purpose .= " " . xml_escape
($1);
2143 $contents .= $1 . "\n";
2146 # i dont know - bad line? ignore.
2147 print STDERR
"Warning(${file}:$.): bad line: $_";
2150 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2151 if ($decl_type eq 'function') {
2152 process_state3_function
($_, $file);
2154 process_state3_type
($_, $file);
2156 } elsif ($state == 4) {
2157 # Documentation block
2159 dump_doc_section
($file, $section, xml_escape
($contents));
2163 %parameterdescs = ();
2164 %parametertypes = ();
2165 @parameterlist = ();
2170 $section = $section_intro;
2177 dump_doc_section
($file, $section, xml_escape
($contents));
2181 %parameterdescs = ();
2182 %parametertypes = ();
2183 @parameterlist = ();
2189 elsif (/$doc_content/)
2193 $contents .= $blankline;
2197 $contents .= $1 . "\n";
2202 if ($initial_section_counter == $section_counter) {
2203 print STDERR
"Warning(${file}): no structured comments found\n";
2204 if ($output_mode eq "xml") {
2205 # The template wants at least one RefEntry here; make one.
2206 print "<refentry>\n";
2207 print " <refnamediv>\n";
2208 print " <refname>\n";
2210 print " </refname>\n";
2211 print " <refpurpose>\n";
2212 print " Document generation inconsistency\n";
2213 print " </refpurpose>\n";
2214 print " </refnamediv>\n";
2215 print " <refsect1>\n";
2218 print " </title>\n";
2219 print " <warning>\n";
2221 print " The template for this document tried to insert\n";
2222 print " the structured comment from the file\n";
2223 print " <filename>${file}</filename> at this point,\n";
2224 print " but none was found.\n";
2225 print " This dummy section is inserted to allow\n";
2226 print " generation to continue.\n";
2228 print " </warning>\n";
2229 print " </refsect1>\n";
2230 print "</refentry>\n";