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 # w.o. 03-11-2000: added the '-filelist' option.
18 # 18/01/2001 - Cleanups
19 # Functions prototyped as foo(void) same as foo()
20 # Stop eval'ing where we don't need to.
23 # 27/06/2001 - Allowed whitespace after initial "/**" and
24 # allowed comments before function declarations.
25 # -- Christian Kreibich <ck@whoop.org>
28 # - add perldoc documentation
29 # - Look more closely at some of the scarier bits :)
31 # 26/05/2001 - Support for separate source and object trees.
33 # Keith Owens <kaos@ocs.com.au>
35 # 23/09/2001 - Added support for typedefs, structs, enums and unions
36 # Support for Context section; can be terminated using empty line
37 # Small fixes (like spaces vs. \s in regex)
38 # -- Tim Jansen <tim@tjansen.de>
42 # This will read a 'c' file and scan for embedded comments in the
43 # style of gnome comments (+minor extensions - see below).
46 # Note: This only supports 'c'.
49 # kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ]
50 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
52 # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
54 # Set output format using one of -docbook -html -text or -man. Default is man.
57 # Do not output DOC: sections
60 # If set, then only generate documentation for the given function(s) or
61 # DOC: section titles. All other functions and DOC: sections are ignored.
63 # -nofunction funcname
64 # If set, then only generate documentation for the other function(s)/DOC:
65 # sections. Cannot be used together with -function (yes, that's a bug --
66 # perl hackers can fix it 8))
68 # c files - list of 'c' files to process
70 # All output goes to stdout, with errors to stderr.
74 # In the following table, (...)? signifies optional structure.
75 # (...)* signifies 0 or more structure elements
77 # * function_name(:)? (- short description)?
78 # (* @parameterx: (description of parameter x)?)*
80 # * (Description:)? (Description of function)?
81 # * (section header: (section description)? )*
84 # So .. the trivial example would be:
90 # If the Description: header tag is omitted, then there must be a blank line
91 # after the last parameter specification.
94 # * my_function - does my stuff
95 # * @my_arg: its mine damnit
97 # * Does my stuff explained.
100 # or, could also use:
102 # * my_function - does my stuff
103 # * @my_arg: its mine damnit
104 # * Description: Does my stuff explained.
108 # Besides functions you can also write documentation for structs, unions,
109 # enums and typedefs. Instead of the function name you must write the name
110 # of the declaration; the struct/union/enum/typedef must always precede
111 # the name. Nesting of declarations is not supported.
112 # Use the argument mechanism to document members or constants.
115 # * struct my_struct - short description
117 # * @b: second member
119 # * Longer description
128 # All descriptions can be multiline, except the short function description.
130 # You can also add additional sections. When documenting kernel functions you
131 # should document the "Context:" of the function, e.g. whether the functions
132 # can be called form interrupts. Unlike other sections you can end it with an
134 # Example-sections should contain the string EXAMPLE so that they are marked
135 # appropriately in DocBook.
139 # * user_function - function that can only be called in user context
140 # * @a: some argument
141 # * Context: !in_interrupt()
145 # * user_function(22);
150 # All descriptive text is further processed, scanning for the following special
151 # patterns, which are highlighted appropriately.
153 # 'funcname()' - function
154 # '$ENVVAR' - environmental variable
155 # '&struct_name' - name of a structure (up to two words including 'struct')
156 # '@parameter' - name of a parameter
157 # '%CONST' - name of a constant.
161 my $anon_struct_union = 0;
163 # match expressions used to find embedded type information
164 my $type_constant = '\%([-_\w]+)';
165 my $type_func = '(\w+)\(\)';
166 my $type_param = '\@(\w+)';
167 my $type_struct = '\&((struct\s*)*[_\w]+)';
168 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)';
169 my $type_env = '(\$\w+)';
171 # Output conversion substitutions.
172 # One for each output format
174 # these work fairly well
175 my %highlights_html = ( $type_constant, "<i>\$1</i>",
176 $type_func, "<b>\$1</b>",
177 $type_struct_xml, "<i>\$1</i>",
178 $type_env, "<b><i>\$1</i></b>",
179 $type_param, "<tt><b>\$1</b></tt>" );
180 my $local_lt = "\\\\\\\\lt:";
181 my $local_gt = "\\\\\\\\gt:";
182 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
184 # XML, docbook format
185 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
186 $type_constant, "<constant>\$1</constant>",
187 $type_func, "<function>\$1</function>",
188 $type_struct_xml, "<structname>\$1</structname>",
189 $type_env, "<envar>\$1</envar>",
190 $type_param, "<parameter>\$1</parameter>" );
191 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
193 # gnome, docbook format
194 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
195 $type_func, "<function>\$1</function>",
196 $type_struct, "<structname>\$1</structname>",
197 $type_env, "<envar>\$1</envar>",
198 $type_param, "<parameter>\$1</parameter>" );
199 my $blankline_gnome = "</para><para>\n";
201 # these are pretty rough
202 my %highlights_man = ( $type_constant, "\$1",
203 $type_func, "\\\\fB\$1\\\\fP",
204 $type_struct, "\\\\fI\$1\\\\fP",
205 $type_param, "\\\\fI\$1\\\\fP" );
206 my $blankline_man = "";
209 my %highlights_text = ( $type_constant, "\$1",
212 $type_param, "\$1" );
213 my $blankline_text = "";
217 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n";
218 print " [ -function funcname [ -function funcname ...] ]\n";
219 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
220 print " c source file(s) > outputfile\n";
221 print " -v : verbose output, more warnings & other info listed\n";
231 my $output_mode = "man";
232 my $no_doc_sections = 0;
233 my %highlights = %highlights_man;
234 my $blankline = $blankline_man;
235 my $modulename = "Kernel API";
236 my $function_only = 0;
237 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
238 'July', 'August', 'September', 'October',
239 'November', 'December')[(localtime)[4]] .
240 " " . ((localtime)[5]+1900);
242 # Essentially these are globals
243 # They probably want to be tidied up, made more localised or something.
244 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
245 # could cause "use of undefined value" or other bugs.
246 my ($function, %function_table, %parametertypes, $declaration_purpose);
247 my ($type, $declaration_name, $return_type);
248 my ($newsection, $newcontents, $prototype, $filelist, $brcount, %source_map);
250 if (defined($ENV{'KBUILD_VERBOSE'})) {
251 $verbose = "$ENV{'KBUILD_VERBOSE'}";
254 # Generated docbook code is inserted in a template at a point where
255 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
256 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
257 # We keep track of number of generated entries and generate a dummy
258 # if needs be to ensure the expanded template can be postprocessed
260 my $section_counter = 0;
266 # 1 - looking for function name
267 # 2 - scanning field start.
268 # 3 - scanning prototype.
269 # 4 - documentation block
273 #declaration types: can be
274 # 'function', 'struct', 'union', 'enum', 'typedef'
277 my $doc_special = "\@\%\$\&";
279 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
281 my $doc_com = '\s*\*\s*';
282 my $doc_decl = $doc_com . '(\w+)';
283 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
284 my $doc_content = $doc_com . '(.*)';
285 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
296 my $section_default = "Description"; # default section
297 my $section_intro = "Introduction";
298 my $section = $section_default;
299 my $section_context = "Context";
301 my $undescribed = "-- undescribed --";
305 while ($ARGV[0] =~ m/^-(.*)/) {
306 my $cmd = shift @ARGV;
307 if ($cmd eq "-html") {
308 $output_mode = "html";
309 %highlights = %highlights_html;
310 $blankline = $blankline_html;
311 } elsif ($cmd eq "-man") {
312 $output_mode = "man";
313 %highlights = %highlights_man;
314 $blankline = $blankline_man;
315 } elsif ($cmd eq "-text") {
316 $output_mode = "text";
317 %highlights = %highlights_text;
318 $blankline = $blankline_text;
319 } elsif ($cmd eq "-docbook") {
320 $output_mode = "xml";
321 %highlights = %highlights_xml;
322 $blankline = $blankline_xml;
323 } elsif ($cmd eq "-gnome") {
324 $output_mode = "gnome";
325 %highlights = %highlights_gnome;
326 $blankline = $blankline_gnome;
327 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
328 $modulename = shift @ARGV;
329 } elsif ($cmd eq "-function") { # to only output specific functions
331 $function = shift @ARGV;
332 $function_table{$function} = 1;
333 } elsif ($cmd eq "-nofunction") { # to only output specific functions
335 $function = shift @ARGV;
336 $function_table{$function} = 1;
337 } elsif ($cmd eq "-v") {
339 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
341 } elsif ($cmd eq '-filelist') {
342 $filelist = shift @ARGV;
343 } elsif ($cmd eq '-no-doc-sections') {
344 $no_doc_sections = 1;
348 # get kernel version from env
349 sub get_kernel_version() {
350 my $version = 'unknown kernel version';
352 if (defined($ENV{'KERNELVERSION'})) {
353 $version = $ENV{'KERNELVERSION'};
357 my $kernelversion = get_kernel_version();
359 # generate a sequence of code that will splice in highlighting information
360 # using the s// operator.
361 my $dohighlight = "";
362 foreach my $pattern (keys %highlights) {
363 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
364 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
368 # dumps section contents to arrays/hashes intended for that purpose.
373 my $contents = join "\n", @_;
375 if ($name =~ m/$type_constant/) {
377 # print STDERR "constant section '$1' = '$contents'\n";
378 $constants{$name} = $contents;
379 } elsif ($name =~ m/$type_param/) {
380 # print STDERR "parameter def '$1' = '$contents'\n";
382 $parameterdescs{$name} = $contents;
383 $sectcheck = $sectcheck . $name . " ";
384 } elsif ($name eq "@\.\.\.") {
385 # print STDERR "parameter def '...' = '$contents'\n";
387 $parameterdescs{$name} = $contents;
388 $sectcheck = $sectcheck . $name . " ";
390 # print STDERR "other section '$name' = '$contents'\n";
391 if (defined($sections{$name}) && ($sections{$name} ne "")) {
392 print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
395 $sections{$name} = $contents;
396 push @sectionlist, $name;
401 # dump DOC: section after checking that it should go out
403 sub dump_doc_section {
406 my $contents = join "\n", @_;
408 if ($no_doc_sections) {
412 if (($function_only == 0) ||
413 ( $function_only == 1 && defined($function_table{$name})) ||
414 ( $function_only == 2 && !defined($function_table{$name})))
416 dump_section($file, $name, $contents);
417 output_blockhead({'sectionlist' => \@sectionlist,
418 'sections' => \%sections,
419 'module' => $modulename,
420 'content-only' => ($function_only != 0), });
427 # parameterdescs, a hash.
428 # function => "function name"
429 # parameterlist => @list of parameters
430 # parameterdescs => %parameter descriptions
431 # sectionlist => @list of sections
432 # sections => %section descriptions
435 sub output_highlight {
436 my $contents = join "\n",@_;
440 # if (!defined $contents) {
442 # confess "output_highlight got called with no args?\n";
445 if ($output_mode eq "html" || $output_mode eq "xml") {
446 $contents = local_unescape($contents);
447 # convert data read & converted thru xml_escape() into &xyz; format:
448 $contents =~ s/\\\\\\/&/g;
450 # print STDERR "contents b4:$contents\n";
453 # print STDERR "contents af:$contents\n";
455 foreach $line (split "\n", $contents) {
457 print $lineprefix, local_unescape($blankline);
459 $line =~ s/\\\\\\/\&/g;
460 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
463 print $lineprefix, $line;
470 #output sections in html
471 sub output_section_html(%) {
475 foreach $section (@{$args{'sectionlist'}}) {
476 print "<h3>$section</h3>\n";
477 print "<blockquote>\n";
478 output_highlight($args{'sections'}{$section});
479 print "</blockquote>\n";
483 # output enum in html
484 sub output_enum_html(%) {
488 print "<h2>enum " . $args{'enum'} . "</h2>\n";
490 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
492 foreach $parameter (@{$args{'parameterlist'}}) {
493 print " <b>" . $parameter . "</b>";
494 if ($count != $#{$args{'parameterlist'}}) {
502 print "<h3>Constants</h3>\n";
504 foreach $parameter (@{$args{'parameterlist'}}) {
505 print "<dt><b>" . $parameter . "</b>\n";
507 output_highlight($args{'parameterdescs'}{$parameter});
510 output_section_html(@_);
514 # output typedef in html
515 sub output_typedef_html(%) {
519 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
521 print "<b>typedef " . $args{'typedef'} . "</b>\n";
522 output_section_html(@_);
526 # output struct in html
527 sub output_struct_html(%) {
531 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
532 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
533 foreach $parameter (@{$args{'parameterlist'}}) {
534 if ($parameter =~ /^#/) {
535 print "$parameter<br>\n";
538 my $parameter_name = $parameter;
539 $parameter_name =~ s/\[.*//;
541 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
542 $type = $args{'parametertypes'}{$parameter};
543 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
544 # pointer-to-function
545 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
546 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
548 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
550 print " <i>$type</i> <b>$parameter</b>;<br>\n";
555 print "<h3>Members</h3>\n";
557 foreach $parameter (@{$args{'parameterlist'}}) {
558 ($parameter =~ /^#/) && next;
560 my $parameter_name = $parameter;
561 $parameter_name =~ s/\[.*//;
563 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
564 print "<dt><b>" . $parameter . "</b>\n";
566 output_highlight($args{'parameterdescs'}{$parameter_name});
569 output_section_html(@_);
573 # output function in html
574 sub output_function_html(%) {
576 my ($parameter, $section);
579 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
580 print "<i>" . $args{'functiontype'} . "</i>\n";
581 print "<b>" . $args{'function'} . "</b>\n";
584 foreach $parameter (@{$args{'parameterlist'}}) {
585 $type = $args{'parametertypes'}{$parameter};
586 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
587 # pointer-to-function
588 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
590 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
592 if ($count != $#{$args{'parameterlist'}}) {
599 print "<h3>Arguments</h3>\n";
601 foreach $parameter (@{$args{'parameterlist'}}) {
602 my $parameter_name = $parameter;
603 $parameter_name =~ s/\[.*//;
605 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
606 print "<dt><b>" . $parameter . "</b>\n";
608 output_highlight($args{'parameterdescs'}{$parameter_name});
611 output_section_html(@_);
615 # output DOC: block header in html
616 sub output_blockhead_html(%) {
618 my ($parameter, $section);
621 foreach $section (@{$args{'sectionlist'}}) {
622 print "<h3>$section</h3>\n";
624 output_highlight($args{'sections'}{$section});
630 sub output_section_xml(%) {
633 # print out each section
635 foreach $section (@{$args{'sectionlist'}}) {
636 print "<refsect1>\n";
637 print "<title>$section</title>\n";
638 if ($section =~ m/EXAMPLE/i) {
639 print "<informalexample><programlisting>\n";
643 output_highlight($args{'sections'}{$section});
644 if ($section =~ m/EXAMPLE/i) {
645 print "</programlisting></informalexample>\n";
649 print "</refsect1>\n";
653 # output function in XML DocBook
654 sub output_function_xml(%) {
656 my ($parameter, $section);
660 $id = "API-" . $args{'function'};
661 $id =~ s/[^A-Za-z0-9]/-/g;
663 print "<refentry id=\"$id\">\n";
664 print "<refentryinfo>\n";
665 print " <title>LINUX</title>\n";
666 print " <productname>Kernel Hackers Manual</productname>\n";
667 print " <date>$man_date</date>\n";
668 print "</refentryinfo>\n";
670 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
671 print " <manvolnum>9</manvolnum>\n";
672 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
673 print "</refmeta>\n";
674 print "<refnamediv>\n";
675 print " <refname>" . $args{'function'} . "</refname>\n";
676 print " <refpurpose>\n";
678 output_highlight ($args{'purpose'});
679 print " </refpurpose>\n";
680 print "</refnamediv>\n";
682 print "<refsynopsisdiv>\n";
683 print " <title>Synopsis</title>\n";
684 print " <funcsynopsis><funcprototype>\n";
685 print " <funcdef>" . $args{'functiontype'} . " ";
686 print "<function>" . $args{'function'} . " </function></funcdef>\n";
689 if ($#{$args{'parameterlist'}} >= 0) {
690 foreach $parameter (@{$args{'parameterlist'}}) {
691 $type = $args{'parametertypes'}{$parameter};
692 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
693 # pointer-to-function
694 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
695 print " <funcparams>$2</funcparams></paramdef>\n";
697 print " <paramdef>" . $type;
698 print " <parameter>$parameter</parameter></paramdef>\n";
704 print " </funcprototype></funcsynopsis>\n";
705 print "</refsynopsisdiv>\n";
708 print "<refsect1>\n <title>Arguments</title>\n";
709 if ($#{$args{'parameterlist'}} >= 0) {
710 print " <variablelist>\n";
711 foreach $parameter (@{$args{'parameterlist'}}) {
712 my $parameter_name = $parameter;
713 $parameter_name =~ s/\[.*//;
715 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
716 print " <listitem>\n <para>\n";
718 output_highlight($args{'parameterdescs'}{$parameter_name});
719 print " </para>\n </listitem>\n </varlistentry>\n";
721 print " </variablelist>\n";
723 print " <para>\n None\n </para>\n";
725 print "</refsect1>\n";
727 output_section_xml(@_);
728 print "</refentry>\n\n";
731 # output struct in XML DocBook
732 sub output_struct_xml(%) {
734 my ($parameter, $section);
737 $id = "API-struct-" . $args{'struct'};
738 $id =~ s/[^A-Za-z0-9]/-/g;
740 print "<refentry id=\"$id\">\n";
741 print "<refentryinfo>\n";
742 print " <title>LINUX</title>\n";
743 print " <productname>Kernel Hackers Manual</productname>\n";
744 print " <date>$man_date</date>\n";
745 print "</refentryinfo>\n";
747 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
748 print " <manvolnum>9</manvolnum>\n";
749 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
750 print "</refmeta>\n";
751 print "<refnamediv>\n";
752 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
753 print " <refpurpose>\n";
755 output_highlight ($args{'purpose'});
756 print " </refpurpose>\n";
757 print "</refnamediv>\n";
759 print "<refsynopsisdiv>\n";
760 print " <title>Synopsis</title>\n";
761 print " <programlisting>\n";
762 print $args{'type'} . " " . $args{'struct'} . " {\n";
763 foreach $parameter (@{$args{'parameterlist'}}) {
764 if ($parameter =~ /^#/) {
765 print "$parameter\n";
769 my $parameter_name = $parameter;
770 $parameter_name =~ s/\[.*//;
772 defined($args{'parameterdescs'}{$parameter_name}) || next;
773 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
774 $type = $args{'parametertypes'}{$parameter};
775 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
776 # pointer-to-function
777 print " $1 $parameter) ($2);\n";
778 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
780 print " $1 $parameter$2;\n";
782 print " " . $type . " " . $parameter . ";\n";
786 print " </programlisting>\n";
787 print "</refsynopsisdiv>\n";
789 print " <refsect1>\n";
790 print " <title>Members</title>\n";
792 if ($#{$args{'parameterlist'}} >= 0) {
793 print " <variablelist>\n";
794 foreach $parameter (@{$args{'parameterlist'}}) {
795 ($parameter =~ /^#/) && next;
797 my $parameter_name = $parameter;
798 $parameter_name =~ s/\[.*//;
800 defined($args{'parameterdescs'}{$parameter_name}) || next;
801 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
802 print " <varlistentry>";
803 print " <term>$parameter</term>\n";
804 print " <listitem><para>\n";
805 output_highlight($args{'parameterdescs'}{$parameter_name});
806 print " </para></listitem>\n";
807 print " </varlistentry>\n";
809 print " </variablelist>\n";
811 print " <para>\n None\n </para>\n";
813 print " </refsect1>\n";
815 output_section_xml(@_);
817 print "</refentry>\n\n";
820 # output enum in XML DocBook
821 sub output_enum_xml(%) {
823 my ($parameter, $section);
827 $id = "API-enum-" . $args{'enum'};
828 $id =~ s/[^A-Za-z0-9]/-/g;
830 print "<refentry id=\"$id\">\n";
831 print "<refentryinfo>\n";
832 print " <title>LINUX</title>\n";
833 print " <productname>Kernel Hackers Manual</productname>\n";
834 print " <date>$man_date</date>\n";
835 print "</refentryinfo>\n";
837 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
838 print " <manvolnum>9</manvolnum>\n";
839 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
840 print "</refmeta>\n";
841 print "<refnamediv>\n";
842 print " <refname>enum " . $args{'enum'} . "</refname>\n";
843 print " <refpurpose>\n";
845 output_highlight ($args{'purpose'});
846 print " </refpurpose>\n";
847 print "</refnamediv>\n";
849 print "<refsynopsisdiv>\n";
850 print " <title>Synopsis</title>\n";
851 print " <programlisting>\n";
852 print "enum " . $args{'enum'} . " {\n";
854 foreach $parameter (@{$args{'parameterlist'}}) {
856 if ($count != $#{$args{'parameterlist'}}) {
863 print " </programlisting>\n";
864 print "</refsynopsisdiv>\n";
866 print "<refsect1>\n";
867 print " <title>Constants</title>\n";
868 print " <variablelist>\n";
869 foreach $parameter (@{$args{'parameterlist'}}) {
870 my $parameter_name = $parameter;
871 $parameter_name =~ s/\[.*//;
873 print " <varlistentry>";
874 print " <term>$parameter</term>\n";
875 print " <listitem><para>\n";
876 output_highlight($args{'parameterdescs'}{$parameter_name});
877 print " </para></listitem>\n";
878 print " </varlistentry>\n";
880 print " </variablelist>\n";
881 print "</refsect1>\n";
883 output_section_xml(@_);
885 print "</refentry>\n\n";
888 # output typedef in XML DocBook
889 sub output_typedef_xml(%) {
891 my ($parameter, $section);
894 $id = "API-typedef-" . $args{'typedef'};
895 $id =~ s/[^A-Za-z0-9]/-/g;
897 print "<refentry id=\"$id\">\n";
898 print "<refentryinfo>\n";
899 print " <title>LINUX</title>\n";
900 print " <productname>Kernel Hackers Manual</productname>\n";
901 print " <date>$man_date</date>\n";
902 print "</refentryinfo>\n";
904 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
905 print " <manvolnum>9</manvolnum>\n";
906 print "</refmeta>\n";
907 print "<refnamediv>\n";
908 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
909 print " <refpurpose>\n";
911 output_highlight ($args{'purpose'});
912 print " </refpurpose>\n";
913 print "</refnamediv>\n";
915 print "<refsynopsisdiv>\n";
916 print " <title>Synopsis</title>\n";
917 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
918 print "</refsynopsisdiv>\n";
920 output_section_xml(@_);
922 print "</refentry>\n\n";
925 # output in XML DocBook
926 sub output_blockhead_xml(%) {
928 my ($parameter, $section);
931 my $id = $args{'module'};
932 $id =~ s/[^A-Za-z0-9]/-/g;
934 # print out each section
936 foreach $section (@{$args{'sectionlist'}}) {
937 if (!$args{'content-only'}) {
938 print "<refsect1>\n <title>$section</title>\n";
940 if ($section =~ m/EXAMPLE/i) {
941 print "<example><para>\n";
945 output_highlight($args{'sections'}{$section});
946 if ($section =~ m/EXAMPLE/i) {
947 print "</para></example>\n";
951 if (!$args{'content-only'}) {
952 print "\n</refsect1>\n";
959 # output in XML DocBook
960 sub output_function_gnome {
962 my ($parameter, $section);
966 $id = $args{'module'} . "-" . $args{'function'};
967 $id =~ s/[^A-Za-z0-9]/-/g;
970 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
972 print " <funcsynopsis>\n";
973 print " <funcdef>" . $args{'functiontype'} . " ";
974 print "<function>" . $args{'function'} . " ";
975 print "</function></funcdef>\n";
978 if ($#{$args{'parameterlist'}} >= 0) {
979 foreach $parameter (@{$args{'parameterlist'}}) {
980 $type = $args{'parametertypes'}{$parameter};
981 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
982 # pointer-to-function
983 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
984 print " <funcparams>$2</funcparams></paramdef>\n";
986 print " <paramdef>" . $type;
987 print " <parameter>$parameter</parameter></paramdef>\n";
993 print " </funcsynopsis>\n";
994 if ($#{$args{'parameterlist'}} >= 0) {
995 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
996 print "<tgroup cols=\"2\">\n";
997 print "<colspec colwidth=\"2*\">\n";
998 print "<colspec colwidth=\"8*\">\n";
1000 foreach $parameter (@{$args{'parameterlist'}}) {
1001 my $parameter_name = $parameter;
1002 $parameter_name =~ s/\[.*//;
1004 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1007 output_highlight($args{'parameterdescs'}{$parameter_name});
1008 print " </entry></row>\n";
1010 print " </tbody></tgroup></informaltable>\n";
1012 print " <para>\n None\n </para>\n";
1015 # print out each section
1017 foreach $section (@{$args{'sectionlist'}}) {
1018 print "<simplesect>\n <title>$section</title>\n";
1019 if ($section =~ m/EXAMPLE/i) {
1020 print "<example><programlisting>\n";
1024 output_highlight($args{'sections'}{$section});
1026 if ($section =~ m/EXAMPLE/i) {
1027 print "</programlisting></example>\n";
1030 print " </simplesect>\n";
1033 print "</sect2>\n\n";
1037 # output function in man
1038 sub output_function_man(%) {
1039 my %args = %{$_[0]};
1040 my ($parameter, $section);
1043 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1046 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1048 print ".SH SYNOPSIS\n";
1049 if ($args{'functiontype'} ne "") {
1050 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1052 print ".B \"" . $args{'function'} . "\n";
1057 foreach my $parameter (@{$args{'parameterlist'}}) {
1058 if ($count == $#{$args{'parameterlist'}}) {
1061 $type = $args{'parametertypes'}{$parameter};
1062 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1063 # pointer-to-function
1064 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1066 $type =~ s/([^\*])$/$1 /;
1067 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1073 print ".SH ARGUMENTS\n";
1074 foreach $parameter (@{$args{'parameterlist'}}) {
1075 my $parameter_name = $parameter;
1076 $parameter_name =~ s/\[.*//;
1078 print ".IP \"" . $parameter . "\" 12\n";
1079 output_highlight($args{'parameterdescs'}{$parameter_name});
1081 foreach $section (@{$args{'sectionlist'}}) {
1082 print ".SH \"", uc $section, "\"\n";
1083 output_highlight($args{'sections'}{$section});
1088 # output enum in man
1089 sub output_enum_man(%) {
1090 my %args = %{$_[0]};
1091 my ($parameter, $section);
1094 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1097 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1099 print ".SH SYNOPSIS\n";
1100 print "enum " . $args{'enum'} . " {\n";
1102 foreach my $parameter (@{$args{'parameterlist'}}) {
1103 print ".br\n.BI \" $parameter\"\n";
1104 if ($count == $#{$args{'parameterlist'}}) {
1114 print ".SH Constants\n";
1115 foreach $parameter (@{$args{'parameterlist'}}) {
1116 my $parameter_name = $parameter;
1117 $parameter_name =~ s/\[.*//;
1119 print ".IP \"" . $parameter . "\" 12\n";
1120 output_highlight($args{'parameterdescs'}{$parameter_name});
1122 foreach $section (@{$args{'sectionlist'}}) {
1123 print ".SH \"$section\"\n";
1124 output_highlight($args{'sections'}{$section});
1129 # output struct in man
1130 sub output_struct_man(%) {
1131 my %args = %{$_[0]};
1132 my ($parameter, $section);
1134 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1137 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1139 print ".SH SYNOPSIS\n";
1140 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1142 foreach my $parameter (@{$args{'parameterlist'}}) {
1143 if ($parameter =~ /^#/) {
1144 print ".BI \"$parameter\"\n.br\n";
1147 my $parameter_name = $parameter;
1148 $parameter_name =~ s/\[.*//;
1150 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1151 $type = $args{'parametertypes'}{$parameter};
1152 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1153 # pointer-to-function
1154 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1155 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1157 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1159 $type =~ s/([^\*])$/$1 /;
1160 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1166 print ".SH Members\n";
1167 foreach $parameter (@{$args{'parameterlist'}}) {
1168 ($parameter =~ /^#/) && next;
1170 my $parameter_name = $parameter;
1171 $parameter_name =~ s/\[.*//;
1173 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1174 print ".IP \"" . $parameter . "\" 12\n";
1175 output_highlight($args{'parameterdescs'}{$parameter_name});
1177 foreach $section (@{$args{'sectionlist'}}) {
1178 print ".SH \"$section\"\n";
1179 output_highlight($args{'sections'}{$section});
1184 # output typedef in man
1185 sub output_typedef_man(%) {
1186 my %args = %{$_[0]};
1187 my ($parameter, $section);
1189 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1192 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1194 foreach $section (@{$args{'sectionlist'}}) {
1195 print ".SH \"$section\"\n";
1196 output_highlight($args{'sections'}{$section});
1200 sub output_blockhead_man(%) {
1201 my %args = %{$_[0]};
1202 my ($parameter, $section);
1205 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1207 foreach $section (@{$args{'sectionlist'}}) {
1208 print ".SH \"$section\"\n";
1209 output_highlight($args{'sections'}{$section});
1215 sub output_function_text(%) {
1216 my %args = %{$_[0]};
1217 my ($parameter, $section);
1221 print $args{'function'} . " - " . $args{'purpose'} . "\n";
1223 print "\nSynopsis:\n\n";
1224 if ($args{'functiontype'} ne "") {
1225 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1227 $start = $args{'function'} . " (";
1232 foreach my $parameter (@{$args{'parameterlist'}}) {
1233 $type = $args{'parametertypes'}{$parameter};
1234 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1235 # pointer-to-function
1236 print $1 . $parameter . ") (" . $2;
1238 print $type . " " . $parameter;
1240 if ($count != $#{$args{'parameterlist'}}) {
1243 print " " x length($start);
1249 print "Arguments:\n\n";
1250 foreach $parameter (@{$args{'parameterlist'}}) {
1251 my $parameter_name = $parameter;
1252 $parameter_name =~ s/\[.*//;
1254 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1256 output_section_text(@_);
1259 #output sections in text
1260 sub output_section_text(%) {
1261 my %args = %{$_[0]};
1265 foreach $section (@{$args{'sectionlist'}}) {
1266 print "$section:\n\n";
1267 output_highlight($args{'sections'}{$section});
1272 # output enum in text
1273 sub output_enum_text(%) {
1274 my %args = %{$_[0]};
1279 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1280 print "enum " . $args{'enum'} . " {\n";
1282 foreach $parameter (@{$args{'parameterlist'}}) {
1283 print "\t$parameter";
1284 if ($count != $#{$args{'parameterlist'}}) {
1292 print "Constants:\n\n";
1293 foreach $parameter (@{$args{'parameterlist'}}) {
1294 print "$parameter\n\t";
1295 print $args{'parameterdescs'}{$parameter} . "\n";
1298 output_section_text(@_);
1301 # output typedef in text
1302 sub output_typedef_text(%) {
1303 my %args = %{$_[0]};
1306 print "Typedef:\n\n";
1308 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1309 output_section_text(@_);
1312 # output struct as text
1313 sub output_struct_text(%) {
1314 my %args = %{$_[0]};
1317 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1318 print $args{'type'} . " " . $args{'struct'} . " {\n";
1319 foreach $parameter (@{$args{'parameterlist'}}) {
1320 if ($parameter =~ /^#/) {
1321 print "$parameter\n";
1325 my $parameter_name = $parameter;
1326 $parameter_name =~ s/\[.*//;
1328 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1329 $type = $args{'parametertypes'}{$parameter};
1330 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1331 # pointer-to-function
1332 print "\t$1 $parameter) ($2);\n";
1333 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1335 print "\t$1 $parameter$2;\n";
1337 print "\t" . $type . " " . $parameter . ";\n";
1342 print "Members:\n\n";
1343 foreach $parameter (@{$args{'parameterlist'}}) {
1344 ($parameter =~ /^#/) && next;
1346 my $parameter_name = $parameter;
1347 $parameter_name =~ s/\[.*//;
1349 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1350 print "$parameter\n\t";
1351 print $args{'parameterdescs'}{$parameter_name} . "\n";
1354 output_section_text(@_);
1357 sub output_blockhead_text(%) {
1358 my %args = %{$_[0]};
1359 my ($parameter, $section);
1361 foreach $section (@{$args{'sectionlist'}}) {
1362 print " $section:\n";
1364 output_highlight($args{'sections'}{$section});
1369 # generic output function for all types (function, struct/union, typedef, enum);
1370 # calls the generated, variable output_ function name based on
1371 # functype and output_mode
1372 sub output_declaration {
1375 my $functype = shift;
1376 my $func = "output_${functype}_$output_mode";
1377 if (($function_only==0) ||
1378 ( $function_only == 1 && defined($function_table{$name})) ||
1379 ( $function_only == 2 && !defined($function_table{$name})))
1387 # generic output function - calls the right one based on current output mode.
1388 sub output_blockhead {
1390 my $func = "output_blockhead_" . $output_mode;
1396 # takes a declaration (struct, union, enum, typedef) and
1397 # invokes the right handler. NOT called for functions.
1398 sub dump_declaration($$) {
1400 my ($prototype, $file) = @_;
1401 my $func = "dump_" . $decl_type;
1405 sub dump_union($$) {
1409 sub dump_struct($$) {
1414 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1415 #my $decl_type = $1;
1416 $declaration_name = $2;
1419 # ignore embedded structs or unions
1420 $members =~ s/({.*})//g;
1423 # ignore members marked private:
1424 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
1425 $members =~ s/\/\*\s*private:.*//gos;
1427 $members =~ s/\/\*.*?\*\///gos;
1428 $nested =~ s/\/\*.*?\*\///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 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1458 $declaration_name = $1;
1461 foreach my $arg (split ',', $members) {
1462 $arg =~ s/^\s*(\w+).*/$1/;
1463 push @parameterlist, $arg;
1464 if (!$parameterdescs{$arg}) {
1465 $parameterdescs{$arg} = $undescribed;
1466 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1467 "not described in enum '$declaration_name'\n";
1472 output_declaration($declaration_name,
1474 {'enum' => $declaration_name,
1475 'module' => $modulename,
1476 'parameterlist' => \@parameterlist,
1477 'parameterdescs' => \%parameterdescs,
1478 'sectionlist' => \@sectionlist,
1479 'sections' => \%sections,
1480 'purpose' => $declaration_purpose
1484 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1489 sub dump_typedef($$) {
1493 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1494 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1495 $x =~ s/\(*.\)\s*;$/;/;
1496 $x =~ s/\[*.\]\s*;$/;/;
1499 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1500 $declaration_name = $1;
1502 output_declaration($declaration_name,
1504 {'typedef' => $declaration_name,
1505 'module' => $modulename,
1506 'sectionlist' => \@sectionlist,
1507 'sections' => \%sections,
1508 'purpose' => $declaration_purpose
1512 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1517 sub save_struct_actual($) {
1520 # strip all spaces from the actual param so that it looks like one string item
1521 $actual =~ s/\s*//g;
1522 $struct_actual = $struct_actual . $actual . " ";
1525 sub create_parameterlist($$$) {
1527 my $splitter = shift;
1532 # temporarily replace commas inside function pointer definition
1533 while ($args =~ /(\([^\),]+),/) {
1534 $args =~ s/(\([^\),]+),/$1#/g;
1537 foreach my $arg (split($splitter, $args)) {
1539 $arg =~ s/\/\*.*\*\///;
1540 # strip leading/trailing spaces
1546 # Treat preprocessor directive as a typeless variable just to fill
1547 # corresponding data structures "correctly". Catch it later in
1549 push_parameter($arg, "", $file);
1550 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1551 # pointer-to-function
1553 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1556 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1557 save_struct_actual($param);
1558 push_parameter($param, $type, $file);
1560 $arg =~ s/\s*:\s*/:/g;
1561 $arg =~ s/\s*\[/\[/g;
1563 my @args = split('\s*,\s*', $arg);
1564 if ($args[0] =~ m/\*/) {
1565 $args[0] =~ s/(\*+)\s*/ $1/;
1569 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1571 push(@first_arg, split('\s+', $1));
1572 push(@first_arg, $2);
1574 @first_arg = split('\s+', shift @args);
1577 unshift(@args, pop @first_arg);
1578 $type = join " ", @first_arg;
1580 foreach $param (@args) {
1581 if ($param =~ m/^(\*+)\s*(.*)/) {
1582 save_struct_actual($2);
1583 push_parameter($2, "$type $1", $file);
1585 elsif ($param =~ m/(.*?):(\d+)/) {
1586 if ($type ne "") { # skip unnamed bit-fields
1587 save_struct_actual($1);
1588 push_parameter($1, "$type:$2", $file)
1592 save_struct_actual($param);
1593 push_parameter($param, $type, $file);
1600 sub push_parameter($$$) {
1605 if (($anon_struct_union == 1) && ($type eq "") &&
1607 return; # ignore the ending }; from anon. struct/union
1610 $anon_struct_union = 0;
1611 my $param_name = $param;
1612 $param_name =~ s/\[.*//;
1614 if ($type eq "" && $param =~ /\.\.\.$/)
1616 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1617 $parameterdescs{$param} = "variable arguments";
1620 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1623 $parameterdescs{void} = "no arguments";
1625 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1626 # handle unnamed (anonymous) union or struct:
1629 $param = "{unnamed_" . $param . "}";
1630 $parameterdescs{$param} = "anonymous\n";
1631 $anon_struct_union = 1;
1634 # warn if parameter has no description
1635 # (but ignore ones starting with # as these are not parameters
1636 # but inline preprocessor statements);
1637 # also ignore unnamed structs/unions;
1638 if (!$anon_struct_union) {
1639 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1641 $parameterdescs{$param_name} = $undescribed;
1643 if (($type eq 'function') || ($type eq 'enum')) {
1644 print STDERR "Warning(${file}:$.): Function parameter ".
1645 "or member '$param' not " .
1646 "described in '$declaration_name'\n";
1648 print STDERR "Warning(${file}:$.):" .
1649 " No description found for parameter '$param'\n";
1654 push @parameterlist, $param;
1655 $parametertypes{$param} = $type;
1658 sub check_sections($$$$$$) {
1659 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1660 my @sects = split ' ', $sectcheck;
1661 my @prms = split ' ', $prmscheck;
1664 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1666 foreach $sx (0 .. $#sects) {
1668 foreach $px (0 .. $#prms) {
1669 $prm_clean = $prms[$px];
1670 $prm_clean =~ s/\[.*\]//;
1671 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//;
1672 ##$prm_clean =~ s/^\**//;
1673 if ($prm_clean eq $sects[$sx]) {
1679 if ($decl_type eq "function") {
1680 print STDERR "Warning(${file}:$.): " .
1681 "Excess function parameter " .
1683 "description in '$decl_name'\n";
1686 if ($nested !~ m/\Q$sects[$sx]\E/) {
1687 print STDERR "Warning(${file}:$.): " .
1688 "Excess struct/union/enum/typedef member " .
1690 "description in '$decl_name'\n";
1699 # takes a function prototype and the name of the current file being
1700 # processed and spits out all the details stored in the global
1702 sub dump_function($$) {
1703 my $prototype = shift;
1706 $prototype =~ s/^static +//;
1707 $prototype =~ s/^extern +//;
1708 $prototype =~ s/^asmlinkage +//;
1709 $prototype =~ s/^inline +//;
1710 $prototype =~ s/^__inline__ +//;
1711 $prototype =~ s/^__inline +//;
1712 $prototype =~ s/^__always_inline +//;
1713 $prototype =~ s/^noinline +//;
1714 $prototype =~ s/__devinit +//;
1715 $prototype =~ s/__init +//;
1716 $prototype =~ s/^#\s*define\s+//; #ak added
1717 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1719 # Yes, this truly is vile. We are looking for:
1720 # 1. Return type (may be nothing if we're looking at a macro)
1722 # 3. Function parameters.
1724 # All the while we have to watch out for function pointer parameters
1725 # (which IIRC is what the two sections are for), C types (these
1726 # regexps don't even start to express all the possibilities), and
1729 # If you mess with these regexps, it's a good idea to check that
1730 # the following functions' documentation still comes out right:
1731 # - parport_register_device (function pointer parameters)
1732 # - atomic_set (macro)
1733 # - pci_match_device, __copy_to_user (long return type)
1735 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1736 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1737 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1738 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1739 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1740 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1741 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1742 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1743 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1744 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1745 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1746 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1747 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1748 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1749 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1750 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1751 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1753 $declaration_name = $2;
1756 create_parameterlist($args, ',', $file);
1758 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1763 my $prms = join " ", @parameterlist;
1764 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
1766 output_declaration($declaration_name,
1768 {'function' => $declaration_name,
1769 'module' => $modulename,
1770 'functiontype' => $return_type,
1771 'parameterlist' => \@parameterlist,
1772 'parameterdescs' => \%parameterdescs,
1773 'parametertypes' => \%parametertypes,
1774 'sectionlist' => \@sectionlist,
1775 'sections' => \%sections,
1776 'purpose' => $declaration_purpose
1780 sub process_file($);
1782 # Read the file that maps relative names to absolute names for
1783 # separate source and object directories and for shadow trees.
1784 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1785 my ($relname, $absname);
1786 while(<SOURCE_MAP>) {
1788 ($relname, $absname) = (split())[0..1];
1789 $relname =~ s:^/+::;
1790 $source_map{$relname} = $absname;
1796 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1807 if ($verbose && $errors) {
1808 print STDERR "$errors errors\n";
1810 if ($verbose && $warnings) {
1811 print STDERR "$warnings warnings\n";
1819 %parameterdescs = ();
1820 %parametertypes = ();
1821 @parameterlist = ();
1825 $struct_actual = "";
1831 sub syscall_munge() {
1834 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
1835 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1836 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1838 ## $prototype = "long sys_$1(void)";
1841 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1842 if ($prototype =~ m/long (sys_.*?),/) {
1843 $prototype =~ s/,/\(/;
1845 $prototype =~ s/\)/\(void\)/;
1848 # now delete all of the odd-number commas in $prototype
1849 # so that arg types & arg names don't have a comma between them
1851 my $len = length($prototype);
1853 $len = 0; # skip the for-loop
1855 for (my $ix = 0; $ix < $len; $ix++) {
1856 if (substr($prototype, $ix, 1) eq ',') {
1858 if ($count % 2 == 1) {
1859 substr($prototype, $ix, 1) = ' ';
1865 sub process_state3_function($$) {
1869 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1871 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1874 elsif ($x =~ /([^\{]*)/) {
1878 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
1879 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1880 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1881 $prototype =~ s@^\s+@@gos; # strip leading spaces
1882 if ($prototype =~ /SYSCALL_DEFINE/) {
1885 dump_function($prototype, $file);
1890 sub process_state3_type($$) {
1894 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1895 $x =~ s@^\s+@@gos; # strip leading spaces
1896 $x =~ s@\s+$@@gos; # strip trailing spaces
1897 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1900 # To distinguish preprocessor directive from regular declaration later.
1905 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1906 $prototype .= $1 . $2;
1907 ($2 eq '{') && $brcount++;
1908 ($2 eq '}') && $brcount--;
1909 if (($2 eq ';') && ($brcount == 0)) {
1910 dump_declaration($prototype, $file);
1922 # xml_escape: replace <, >, and & in the text stream;
1924 # however, formatting controls that are generated internally/locally in the
1925 # kernel-doc script are not escaped here; instead, they begin life like
1926 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1927 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1928 # just before actual output; (this is done by local_unescape())
1931 if (($output_mode eq "text") || ($output_mode eq "man")) {
1934 $text =~ s/\&/\\\\\\amp;/g;
1935 $text =~ s/\</\\\\\\lt;/g;
1936 $text =~ s/\>/\\\\\\gt;/g;
1940 # convert local escape strings to html
1941 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1942 sub local_unescape($) {
1944 if (($output_mode eq "text") || ($output_mode eq "man")) {
1947 $text =~ s/\\\\\\\\lt:/</g;
1948 $text =~ s/\\\\\\\\gt:/>/g;
1952 sub process_file($) {
1957 my $initial_section_counter = $section_counter;
1959 if (defined($ENV{'SRCTREE'})) {
1960 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1965 if (defined($source_map{$file})) {
1966 $file = $source_map{$file};
1969 if (!open(IN,"<$file")) {
1970 print STDERR "Error: Cannot open file $file\n";
1975 $section_counter = 0;
1978 if (/$doc_start/o) {
1979 $state = 1; # next line is always the function name
1982 } elsif ($state == 1) { # this line is the function name (always)
1983 if (/$doc_block/o) {
1987 $section = $section_intro;
1992 elsif (/$doc_decl/o) {
1994 if (/\s*([\w\s]+?)\s*-/) {
2000 # strip leading/trailing/multiple spaces
2005 $declaration_purpose = xml_escape($descr);
2007 $declaration_purpose = "";
2010 if (($declaration_purpose eq "") && $verbose) {
2011 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
2016 if ($identifier =~ m/^struct/) {
2017 $decl_type = 'struct';
2018 } elsif ($identifier =~ m/^union/) {
2019 $decl_type = 'union';
2020 } elsif ($identifier =~ m/^enum/) {
2021 $decl_type = 'enum';
2022 } elsif ($identifier =~ m/^typedef/) {
2023 $decl_type = 'typedef';
2025 $decl_type = 'function';
2029 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
2032 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
2033 " - I thought it was a doc line\n";
2037 } elsif ($state == 2) { # look for head: lines, and include content
2042 if (($contents ne "") && ($contents ne "\n")) {
2043 if (!$in_doc_sect && $verbose) {
2044 print STDERR "Warning(${file}:$.): contents before sections\n";
2047 dump_section($file, $section, xml_escape($contents));
2048 $section = $section_default;
2052 $contents = $newcontents;
2053 if ($contents ne "") {
2054 while ((substr($contents, 0, 1) eq " ") ||
2055 substr($contents, 0, 1) eq "\t") {
2056 $contents = substr($contents, 1);
2060 $section = $newsection;
2061 } elsif (/$doc_end/) {
2063 if ($contents ne "") {
2064 dump_section($file, $section, xml_escape($contents));
2065 $section = $section_default;
2068 # look for doc_com + <text> + doc_end:
2069 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2070 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
2077 # print STDERR "end of doc comment, looking for prototype\n";
2078 } elsif (/$doc_content/) {
2079 # miguel-style comment kludge, look for blank lines after
2080 # @parameter line to signify start of description
2082 ($section =~ m/^@/ || $section eq $section_context)) {
2083 dump_section($file, $section, xml_escape($contents));
2084 $section = $section_default;
2087 $contents .= $1 . "\n";
2090 # i dont know - bad line? ignore.
2091 print STDERR "Warning(${file}:$.): bad line: $_";
2094 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
2095 if ($decl_type eq 'function') {
2096 process_state3_function($_, $file);
2098 process_state3_type($_, $file);
2100 } elsif ($state == 4) {
2101 # Documentation block
2103 dump_doc_section($file, $section, xml_escape($contents));
2107 %parameterdescs = ();
2108 %parametertypes = ();
2109 @parameterlist = ();
2114 $section = $section_intro;
2121 dump_doc_section($file, $section, xml_escape($contents));
2125 %parameterdescs = ();
2126 %parametertypes = ();
2127 @parameterlist = ();
2133 elsif (/$doc_content/)
2137 $contents .= $blankline;
2141 $contents .= $1 . "\n";
2146 if ($initial_section_counter == $section_counter) {
2147 print STDERR "Warning(${file}): no structured comments found\n";
2148 if ($output_mode eq "xml") {
2149 # The template wants at least one RefEntry here; make one.
2150 print "<refentry>\n";
2151 print " <refnamediv>\n";
2152 print " <refname>\n";
2154 print " </refname>\n";
2155 print " <refpurpose>\n";
2156 print " Document generation inconsistency\n";
2157 print " </refpurpose>\n";
2158 print " </refnamediv>\n";
2159 print " <refsect1>\n";
2162 print " </title>\n";
2163 print " <warning>\n";
2165 print " The template for this document tried to insert\n";
2166 print " the structured comment from the file\n";
2167 print " <filename>${file}</filename> at this point,\n";
2168 print " but none was found.\n";
2169 print " This dummy section is inserted to allow\n";
2170 print " generation to continue.\n";
2172 print " </warning>\n";
2173 print " </refsect1>\n";
2174 print "</refentry>\n";