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-2008 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 # Beside 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 summat.
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*(.*)?';
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 '-filelist') {
340 $filelist = shift @ARGV;
341 } elsif ($cmd eq '-no-doc-sections') {
342 $no_doc_sections = 1;
346 # get kernel version from env
347 sub get_kernel_version
() {
348 my $version = 'unknown kernel version';
350 if (defined($ENV{'KERNELVERSION'})) {
351 $version = $ENV{'KERNELVERSION'};
355 my $kernelversion = get_kernel_version
();
357 # generate a sequence of code that will splice in highlighting information
358 # using the s// operator.
359 my $dohighlight = "";
360 foreach my $pattern (keys %highlights) {
361 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
362 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
366 # dumps section contents to arrays/hashes intended for that purpose.
371 my $contents = join "\n", @_;
373 if ($name =~ m/$type_constant/) {
375 # print STDERR "constant section '$1' = '$contents'\n";
376 $constants{$name} = $contents;
377 } elsif ($name =~ m/$type_param/) {
378 # print STDERR "parameter def '$1' = '$contents'\n";
380 $parameterdescs{$name} = $contents;
382 # print STDERR "other section '$name' = '$contents'\n";
383 if (defined($sections{$name}) && ($sections{$name} ne "")) {
384 print STDERR
"Error(${file}:$.): duplicate section name '$name'\n";
387 $sections{$name} = $contents;
388 push @sectionlist, $name;
393 # dump DOC: section after checking that it should go out
395 sub dump_doc_section
{
398 my $contents = join "\n", @_;
400 if ($no_doc_sections) {
404 if (($function_only == 0) ||
405 ( $function_only == 1 && defined($function_table{$name})) ||
406 ( $function_only == 2 && !defined($function_table{$name})))
408 dump_section
($file, $name, $contents);
409 output_blockhead
({'sectionlist' => \
@sectionlist,
410 'sections' => \
%sections,
411 'module' => $modulename,
412 'content-only' => ($function_only != 0), });
419 # parameterdescs, a hash.
420 # function => "function name"
421 # parameterlist => @list of parameters
422 # parameterdescs => %parameter descriptions
423 # sectionlist => @list of sections
424 # sections => %section descriptions
427 sub output_highlight
{
428 my $contents = join "\n",@_;
432 # if (!defined $contents) {
434 # confess "output_highlight got called with no args?\n";
437 if ($output_mode eq "html" || $output_mode eq "xml") {
438 $contents = local_unescape
($contents);
439 # convert data read & converted thru xml_escape() into &xyz; format:
440 $contents =~ s/\\\\\\/&/g;
442 # print STDERR "contents b4:$contents\n";
445 # print STDERR "contents af:$contents\n";
447 foreach $line (split "\n", $contents) {
449 print $lineprefix, local_unescape
($blankline);
451 $line =~ s/\\\\\\/\&/g;
452 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
455 print $lineprefix, $line;
462 #output sections in html
463 sub output_section_html
(%) {
467 foreach $section (@
{$args{'sectionlist'}}) {
468 print "<h3>$section</h3>\n";
469 print "<blockquote>\n";
470 output_highlight
($args{'sections'}{$section});
471 print "</blockquote>\n";
475 # output enum in html
476 sub output_enum_html
(%) {
480 print "<h2>enum ".$args{'enum'}."</h2>\n";
482 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
484 foreach $parameter (@
{$args{'parameterlist'}}) {
485 print " <b>".$parameter."</b>";
486 if ($count != $#{$args{'parameterlist'}}) {
494 print "<h3>Constants</h3>\n";
496 foreach $parameter (@
{$args{'parameterlist'}}) {
497 print "<dt><b>".$parameter."</b>\n";
499 output_highlight
($args{'parameterdescs'}{$parameter});
502 output_section_html
(@_);
506 # output typedef in html
507 sub output_typedef_html
(%) {
511 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
513 print "<b>typedef ".$args{'typedef'}."</b>\n";
514 output_section_html
(@_);
518 # output struct in html
519 sub output_struct_html
(%) {
523 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
524 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
525 foreach $parameter (@
{$args{'parameterlist'}}) {
526 if ($parameter =~ /^#/) {
527 print "$parameter<br>\n";
530 my $parameter_name = $parameter;
531 $parameter_name =~ s/\[.*//;
533 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
534 $type = $args{'parametertypes'}{$parameter};
535 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
536 # pointer-to-function
537 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
538 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
540 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
542 print " <i>$type</i> <b>$parameter</b>;<br>\n";
547 print "<h3>Members</h3>\n";
549 foreach $parameter (@
{$args{'parameterlist'}}) {
550 ($parameter =~ /^#/) && next;
552 my $parameter_name = $parameter;
553 $parameter_name =~ s/\[.*//;
555 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
556 print "<dt><b>".$parameter."</b>\n";
558 output_highlight
($args{'parameterdescs'}{$parameter_name});
561 output_section_html
(@_);
565 # output function in html
566 sub output_function_html
(%) {
568 my ($parameter, $section);
571 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
572 print "<i>".$args{'functiontype'}."</i>\n";
573 print "<b>".$args{'function'}."</b>\n";
576 foreach $parameter (@
{$args{'parameterlist'}}) {
577 $type = $args{'parametertypes'}{$parameter};
578 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
579 # pointer-to-function
580 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
582 print "<i>".$type."</i> <b>".$parameter."</b>";
584 if ($count != $#{$args{'parameterlist'}}) {
591 print "<h3>Arguments</h3>\n";
593 foreach $parameter (@
{$args{'parameterlist'}}) {
594 my $parameter_name = $parameter;
595 $parameter_name =~ s/\[.*//;
597 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
598 print "<dt><b>".$parameter."</b>\n";
600 output_highlight
($args{'parameterdescs'}{$parameter_name});
603 output_section_html
(@_);
607 # output DOC: block header in html
608 sub output_blockhead_html
(%) {
610 my ($parameter, $section);
613 foreach $section (@
{$args{'sectionlist'}}) {
614 print "<h3>$section</h3>\n";
616 output_highlight
($args{'sections'}{$section});
622 sub output_section_xml
(%) {
625 # print out each section
627 foreach $section (@
{$args{'sectionlist'}}) {
628 print "<refsect1>\n";
629 print "<title>$section</title>\n";
630 if ($section =~ m/EXAMPLE/i) {
631 print "<informalexample><programlisting>\n";
635 output_highlight
($args{'sections'}{$section});
636 if ($section =~ m/EXAMPLE/i) {
637 print "</programlisting></informalexample>\n";
641 print "</refsect1>\n";
645 # output function in XML DocBook
646 sub output_function_xml
(%) {
648 my ($parameter, $section);
652 $id = "API-".$args{'function'};
653 $id =~ s/[^A-Za-z0-9]/-/g;
655 print "<refentry id=\"$id\">\n";
656 print "<refentryinfo>\n";
657 print " <title>LINUX</title>\n";
658 print " <productname>Kernel Hackers Manual</productname>\n";
659 print " <date>$man_date</date>\n";
660 print "</refentryinfo>\n";
662 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
663 print " <manvolnum>9</manvolnum>\n";
664 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
665 print "</refmeta>\n";
666 print "<refnamediv>\n";
667 print " <refname>".$args{'function'}."</refname>\n";
668 print " <refpurpose>\n";
670 output_highlight
($args{'purpose'});
671 print " </refpurpose>\n";
672 print "</refnamediv>\n";
674 print "<refsynopsisdiv>\n";
675 print " <title>Synopsis</title>\n";
676 print " <funcsynopsis><funcprototype>\n";
677 print " <funcdef>".$args{'functiontype'}." ";
678 print "<function>".$args{'function'}." </function></funcdef>\n";
681 if ($#{$args{'parameterlist'}} >= 0) {
682 foreach $parameter (@
{$args{'parameterlist'}}) {
683 $type = $args{'parametertypes'}{$parameter};
684 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
685 # pointer-to-function
686 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
687 print " <funcparams>$2</funcparams></paramdef>\n";
689 print " <paramdef>".$type;
690 print " <parameter>$parameter</parameter></paramdef>\n";
696 print " </funcprototype></funcsynopsis>\n";
697 print "</refsynopsisdiv>\n";
700 print "<refsect1>\n <title>Arguments</title>\n";
701 if ($#{$args{'parameterlist'}} >= 0) {
702 print " <variablelist>\n";
703 foreach $parameter (@
{$args{'parameterlist'}}) {
704 my $parameter_name = $parameter;
705 $parameter_name =~ s/\[.*//;
707 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
708 print " <listitem>\n <para>\n";
710 output_highlight
($args{'parameterdescs'}{$parameter_name});
711 print " </para>\n </listitem>\n </varlistentry>\n";
713 print " </variablelist>\n";
715 print " <para>\n None\n </para>\n";
717 print "</refsect1>\n";
719 output_section_xml
(@_);
720 print "</refentry>\n\n";
723 # output struct in XML DocBook
724 sub output_struct_xml
(%) {
726 my ($parameter, $section);
729 $id = "API-struct-".$args{'struct'};
730 $id =~ s/[^A-Za-z0-9]/-/g;
732 print "<refentry id=\"$id\">\n";
733 print "<refentryinfo>\n";
734 print " <title>LINUX</title>\n";
735 print " <productname>Kernel Hackers Manual</productname>\n";
736 print " <date>$man_date</date>\n";
737 print "</refentryinfo>\n";
739 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
740 print " <manvolnum>9</manvolnum>\n";
741 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
742 print "</refmeta>\n";
743 print "<refnamediv>\n";
744 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
745 print " <refpurpose>\n";
747 output_highlight
($args{'purpose'});
748 print " </refpurpose>\n";
749 print "</refnamediv>\n";
751 print "<refsynopsisdiv>\n";
752 print " <title>Synopsis</title>\n";
753 print " <programlisting>\n";
754 print $args{'type'}." ".$args{'struct'}." {\n";
755 foreach $parameter (@
{$args{'parameterlist'}}) {
756 if ($parameter =~ /^#/) {
757 print "$parameter\n";
761 my $parameter_name = $parameter;
762 $parameter_name =~ s/\[.*//;
764 defined($args{'parameterdescs'}{$parameter_name}) || next;
765 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
766 $type = $args{'parametertypes'}{$parameter};
767 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
768 # pointer-to-function
769 print " $1 $parameter) ($2);\n";
770 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
772 print " $1 $parameter$2;\n";
774 print " ".$type." ".$parameter.";\n";
778 print " </programlisting>\n";
779 print "</refsynopsisdiv>\n";
781 print " <refsect1>\n";
782 print " <title>Members</title>\n";
784 print " <variablelist>\n";
785 foreach $parameter (@
{$args{'parameterlist'}}) {
786 ($parameter =~ /^#/) && next;
788 my $parameter_name = $parameter;
789 $parameter_name =~ s/\[.*//;
791 defined($args{'parameterdescs'}{$parameter_name}) || next;
792 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
793 print " <varlistentry>";
794 print " <term>$parameter</term>\n";
795 print " <listitem><para>\n";
796 output_highlight
($args{'parameterdescs'}{$parameter_name});
797 print " </para></listitem>\n";
798 print " </varlistentry>\n";
800 print " </variablelist>\n";
801 print " </refsect1>\n";
803 output_section_xml
(@_);
805 print "</refentry>\n\n";
808 # output enum in XML DocBook
809 sub output_enum_xml
(%) {
811 my ($parameter, $section);
815 $id = "API-enum-".$args{'enum'};
816 $id =~ s/[^A-Za-z0-9]/-/g;
818 print "<refentry id=\"$id\">\n";
819 print "<refentryinfo>\n";
820 print " <title>LINUX</title>\n";
821 print " <productname>Kernel Hackers Manual</productname>\n";
822 print " <date>$man_date</date>\n";
823 print "</refentryinfo>\n";
825 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
826 print " <manvolnum>9</manvolnum>\n";
827 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
828 print "</refmeta>\n";
829 print "<refnamediv>\n";
830 print " <refname>enum ".$args{'enum'}."</refname>\n";
831 print " <refpurpose>\n";
833 output_highlight
($args{'purpose'});
834 print " </refpurpose>\n";
835 print "</refnamediv>\n";
837 print "<refsynopsisdiv>\n";
838 print " <title>Synopsis</title>\n";
839 print " <programlisting>\n";
840 print "enum ".$args{'enum'}." {\n";
842 foreach $parameter (@
{$args{'parameterlist'}}) {
844 if ($count != $#{$args{'parameterlist'}}) {
851 print " </programlisting>\n";
852 print "</refsynopsisdiv>\n";
854 print "<refsect1>\n";
855 print " <title>Constants</title>\n";
856 print " <variablelist>\n";
857 foreach $parameter (@
{$args{'parameterlist'}}) {
858 my $parameter_name = $parameter;
859 $parameter_name =~ s/\[.*//;
861 print " <varlistentry>";
862 print " <term>$parameter</term>\n";
863 print " <listitem><para>\n";
864 output_highlight
($args{'parameterdescs'}{$parameter_name});
865 print " </para></listitem>\n";
866 print " </varlistentry>\n";
868 print " </variablelist>\n";
869 print "</refsect1>\n";
871 output_section_xml
(@_);
873 print "</refentry>\n\n";
876 # output typedef in XML DocBook
877 sub output_typedef_xml
(%) {
879 my ($parameter, $section);
882 $id = "API-typedef-".$args{'typedef'};
883 $id =~ s/[^A-Za-z0-9]/-/g;
885 print "<refentry id=\"$id\">\n";
886 print "<refentryinfo>\n";
887 print " <title>LINUX</title>\n";
888 print " <productname>Kernel Hackers Manual</productname>\n";
889 print " <date>$man_date</date>\n";
890 print "</refentryinfo>\n";
892 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
893 print " <manvolnum>9</manvolnum>\n";
894 print "</refmeta>\n";
895 print "<refnamediv>\n";
896 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
897 print " <refpurpose>\n";
899 output_highlight
($args{'purpose'});
900 print " </refpurpose>\n";
901 print "</refnamediv>\n";
903 print "<refsynopsisdiv>\n";
904 print " <title>Synopsis</title>\n";
905 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
906 print "</refsynopsisdiv>\n";
908 output_section_xml
(@_);
910 print "</refentry>\n\n";
913 # output in XML DocBook
914 sub output_blockhead_xml
(%) {
916 my ($parameter, $section);
919 my $id = $args{'module'};
920 $id =~ s/[^A-Za-z0-9]/-/g;
922 # print out each section
924 foreach $section (@
{$args{'sectionlist'}}) {
925 if (!$args{'content-only'}) {
926 print "<refsect1>\n <title>$section</title>\n";
928 if ($section =~ m/EXAMPLE/i) {
929 print "<example><para>\n";
933 output_highlight
($args{'sections'}{$section});
934 if ($section =~ m/EXAMPLE/i) {
935 print "</para></example>\n";
939 if (!$args{'content-only'}) {
940 print "\n</refsect1>\n";
947 # output in XML DocBook
948 sub output_function_gnome
{
950 my ($parameter, $section);
954 $id = $args{'module'}."-".$args{'function'};
955 $id =~ s/[^A-Za-z0-9]/-/g;
958 print " <title id=\"$id\">".$args{'function'}."</title>\n";
960 print " <funcsynopsis>\n";
961 print " <funcdef>".$args{'functiontype'}." ";
962 print "<function>".$args{'function'}." ";
963 print "</function></funcdef>\n";
966 if ($#{$args{'parameterlist'}} >= 0) {
967 foreach $parameter (@
{$args{'parameterlist'}}) {
968 $type = $args{'parametertypes'}{$parameter};
969 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
970 # pointer-to-function
971 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
972 print " <funcparams>$2</funcparams></paramdef>\n";
974 print " <paramdef>".$type;
975 print " <parameter>$parameter</parameter></paramdef>\n";
981 print " </funcsynopsis>\n";
982 if ($#{$args{'parameterlist'}} >= 0) {
983 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
984 print "<tgroup cols=\"2\">\n";
985 print "<colspec colwidth=\"2*\">\n";
986 print "<colspec colwidth=\"8*\">\n";
988 foreach $parameter (@
{$args{'parameterlist'}}) {
989 my $parameter_name = $parameter;
990 $parameter_name =~ s/\[.*//;
992 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
995 output_highlight
($args{'parameterdescs'}{$parameter_name});
996 print " </entry></row>\n";
998 print " </tbody></tgroup></informaltable>\n";
1000 print " <para>\n None\n </para>\n";
1003 # print out each section
1005 foreach $section (@
{$args{'sectionlist'}}) {
1006 print "<simplesect>\n <title>$section</title>\n";
1007 if ($section =~ m/EXAMPLE/i) {
1008 print "<example><programlisting>\n";
1012 output_highlight
($args{'sections'}{$section});
1014 if ($section =~ m/EXAMPLE/i) {
1015 print "</programlisting></example>\n";
1018 print " </simplesect>\n";
1021 print "</sect2>\n\n";
1025 # output function in man
1026 sub output_function_man
(%) {
1027 my %args = %{$_[0]};
1028 my ($parameter, $section);
1031 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1034 print $args{'function'}." \\- ".$args{'purpose'}."\n";
1036 print ".SH SYNOPSIS\n";
1037 if ($args{'functiontype'} ne "") {
1038 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
1040 print ".B \"".$args{'function'}."\n";
1045 foreach my $parameter (@
{$args{'parameterlist'}}) {
1046 if ($count == $#{$args{'parameterlist'}}) {
1049 $type = $args{'parametertypes'}{$parameter};
1050 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1051 # pointer-to-function
1052 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
1054 $type =~ s/([^\*])$/$1 /;
1055 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1061 print ".SH ARGUMENTS\n";
1062 foreach $parameter (@
{$args{'parameterlist'}}) {
1063 my $parameter_name = $parameter;
1064 $parameter_name =~ s/\[.*//;
1066 print ".IP \"".$parameter."\" 12\n";
1067 output_highlight
($args{'parameterdescs'}{$parameter_name});
1069 foreach $section (@
{$args{'sectionlist'}}) {
1070 print ".SH \"", uc $section, "\"\n";
1071 output_highlight
($args{'sections'}{$section});
1076 # output enum in man
1077 sub output_enum_man
(%) {
1078 my %args = %{$_[0]};
1079 my ($parameter, $section);
1082 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1085 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1087 print ".SH SYNOPSIS\n";
1088 print "enum ".$args{'enum'}." {\n";
1090 foreach my $parameter (@
{$args{'parameterlist'}}) {
1091 print ".br\n.BI \" $parameter\"\n";
1092 if ($count == $#{$args{'parameterlist'}}) {
1102 print ".SH Constants\n";
1103 foreach $parameter (@
{$args{'parameterlist'}}) {
1104 my $parameter_name = $parameter;
1105 $parameter_name =~ s/\[.*//;
1107 print ".IP \"".$parameter."\" 12\n";
1108 output_highlight
($args{'parameterdescs'}{$parameter_name});
1110 foreach $section (@
{$args{'sectionlist'}}) {
1111 print ".SH \"$section\"\n";
1112 output_highlight
($args{'sections'}{$section});
1117 # output struct in man
1118 sub output_struct_man
(%) {
1119 my %args = %{$_[0]};
1120 my ($parameter, $section);
1122 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1125 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1127 print ".SH SYNOPSIS\n";
1128 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1130 foreach my $parameter (@
{$args{'parameterlist'}}) {
1131 if ($parameter =~ /^#/) {
1132 print ".BI \"$parameter\"\n.br\n";
1135 my $parameter_name = $parameter;
1136 $parameter_name =~ s/\[.*//;
1138 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1139 $type = $args{'parametertypes'}{$parameter};
1140 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1141 # pointer-to-function
1142 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1143 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1145 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1147 $type =~ s/([^\*])$/$1 /;
1148 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1154 print ".SH Members\n";
1155 foreach $parameter (@
{$args{'parameterlist'}}) {
1156 ($parameter =~ /^#/) && next;
1158 my $parameter_name = $parameter;
1159 $parameter_name =~ s/\[.*//;
1161 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1162 print ".IP \"".$parameter."\" 12\n";
1163 output_highlight
($args{'parameterdescs'}{$parameter_name});
1165 foreach $section (@
{$args{'sectionlist'}}) {
1166 print ".SH \"$section\"\n";
1167 output_highlight
($args{'sections'}{$section});
1172 # output typedef in man
1173 sub output_typedef_man
(%) {
1174 my %args = %{$_[0]};
1175 my ($parameter, $section);
1177 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1180 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1182 foreach $section (@
{$args{'sectionlist'}}) {
1183 print ".SH \"$section\"\n";
1184 output_highlight
($args{'sections'}{$section});
1188 sub output_blockhead_man
(%) {
1189 my %args = %{$_[0]};
1190 my ($parameter, $section);
1193 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1195 foreach $section (@
{$args{'sectionlist'}}) {
1196 print ".SH \"$section\"\n";
1197 output_highlight
($args{'sections'}{$section});
1203 sub output_function_text
(%) {
1204 my %args = %{$_[0]};
1205 my ($parameter, $section);
1209 print $args{'function'}." - ".$args{'purpose'}."\n";
1211 print "\nSynopsis:\n\n";
1212 if ($args{'functiontype'} ne "") {
1213 $start = $args{'functiontype'}." ".$args{'function'}." (";
1215 $start = $args{'function'}." (";
1220 foreach my $parameter (@
{$args{'parameterlist'}}) {
1221 $type = $args{'parametertypes'}{$parameter};
1222 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1223 # pointer-to-function
1224 print $1.$parameter.") (".$2;
1226 print $type." ".$parameter;
1228 if ($count != $#{$args{'parameterlist'}}) {
1231 print " " x
length($start);
1237 print "Arguments:\n\n";
1238 foreach $parameter (@
{$args{'parameterlist'}}) {
1239 my $parameter_name = $parameter;
1240 $parameter_name =~ s/\[.*//;
1242 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1244 output_section_text
(@_);
1247 #output sections in text
1248 sub output_section_text
(%) {
1249 my %args = %{$_[0]};
1253 foreach $section (@
{$args{'sectionlist'}}) {
1254 print "$section:\n\n";
1255 output_highlight
($args{'sections'}{$section});
1260 # output enum in text
1261 sub output_enum_text
(%) {
1262 my %args = %{$_[0]};
1267 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1268 print "enum ".$args{'enum'}." {\n";
1270 foreach $parameter (@
{$args{'parameterlist'}}) {
1271 print "\t$parameter";
1272 if ($count != $#{$args{'parameterlist'}}) {
1280 print "Constants:\n\n";
1281 foreach $parameter (@
{$args{'parameterlist'}}) {
1282 print "$parameter\n\t";
1283 print $args{'parameterdescs'}{$parameter}."\n";
1286 output_section_text
(@_);
1289 # output typedef in text
1290 sub output_typedef_text
(%) {
1291 my %args = %{$_[0]};
1294 print "Typedef:\n\n";
1296 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1297 output_section_text
(@_);
1300 # output struct as text
1301 sub output_struct_text
(%) {
1302 my %args = %{$_[0]};
1305 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1306 print $args{'type'}." ".$args{'struct'}." {\n";
1307 foreach $parameter (@
{$args{'parameterlist'}}) {
1308 if ($parameter =~ /^#/) {
1309 print "$parameter\n";
1313 my $parameter_name = $parameter;
1314 $parameter_name =~ s/\[.*//;
1316 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1317 $type = $args{'parametertypes'}{$parameter};
1318 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1319 # pointer-to-function
1320 print "\t$1 $parameter) ($2);\n";
1321 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1323 print "\t$1 $parameter$2;\n";
1325 print "\t".$type." ".$parameter.";\n";
1330 print "Members:\n\n";
1331 foreach $parameter (@
{$args{'parameterlist'}}) {
1332 ($parameter =~ /^#/) && next;
1334 my $parameter_name = $parameter;
1335 $parameter_name =~ s/\[.*//;
1337 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1338 print "$parameter\n\t";
1339 print $args{'parameterdescs'}{$parameter_name}."\n";
1342 output_section_text
(@_);
1345 sub output_blockhead_text
(%) {
1346 my %args = %{$_[0]};
1347 my ($parameter, $section);
1349 foreach $section (@
{$args{'sectionlist'}}) {
1350 print " $section:\n";
1352 output_highlight
($args{'sections'}{$section});
1357 # generic output function for all types (function, struct/union, typedef, enum);
1358 # calls the generated, variable output_ function name based on
1359 # functype and output_mode
1360 sub output_declaration
{
1363 my $functype = shift;
1364 my $func = "output_${functype}_$output_mode";
1365 if (($function_only==0) ||
1366 ( $function_only == 1 && defined($function_table{$name})) ||
1367 ( $function_only == 2 && !defined($function_table{$name})))
1375 # generic output function - calls the right one based on current output mode.
1376 sub output_blockhead
{
1378 my $func = "output_blockhead_".$output_mode;
1384 # takes a declaration (struct, union, enum, typedef) and
1385 # invokes the right handler. NOT called for functions.
1386 sub dump_declaration
($$) {
1388 my ($prototype, $file) = @_;
1389 my $func = "dump_".$decl_type;
1393 sub dump_union
($$) {
1397 sub dump_struct
($$) {
1401 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1402 $declaration_name = $2;
1405 # ignore embedded structs or unions
1406 $members =~ s/{.*}//g;
1408 # ignore members marked private:
1409 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1410 $members =~ s/\/\*.*?private:.*//gos
;
1412 $members =~ s/\/\*.*?\*\///gos;
1414 create_parameterlist
($members, ';', $file);
1416 output_declaration
($declaration_name,
1418 {'struct' => $declaration_name,
1419 'module' => $modulename,
1420 'parameterlist' => \
@parameterlist,
1421 'parameterdescs' => \
%parameterdescs,
1422 'parametertypes' => \
%parametertypes,
1423 'sectionlist' => \
@sectionlist,
1424 'sections' => \
%sections,
1425 'purpose' => $declaration_purpose,
1426 'type' => $decl_type
1430 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1439 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1440 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1441 $declaration_name = $1;
1444 foreach my $arg (split ',', $members) {
1445 $arg =~ s/^\s*(\w+).*/$1/;
1446 push @parameterlist, $arg;
1447 if (!$parameterdescs{$arg}) {
1448 $parameterdescs{$arg} = $undescribed;
1449 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1450 "not described in enum '$declaration_name'\n";
1455 output_declaration
($declaration_name,
1457 {'enum' => $declaration_name,
1458 'module' => $modulename,
1459 'parameterlist' => \
@parameterlist,
1460 'parameterdescs' => \
%parameterdescs,
1461 'sectionlist' => \
@sectionlist,
1462 'sections' => \
%sections,
1463 'purpose' => $declaration_purpose
1467 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1472 sub dump_typedef
($$) {
1476 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1477 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1478 $x =~ s/\(*.\)\s*;$/;/;
1479 $x =~ s/\[*.\]\s*;$/;/;
1482 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1483 $declaration_name = $1;
1485 output_declaration
($declaration_name,
1487 {'typedef' => $declaration_name,
1488 'module' => $modulename,
1489 'sectionlist' => \
@sectionlist,
1490 'sections' => \
%sections,
1491 'purpose' => $declaration_purpose
1495 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1500 sub create_parameterlist
($$$) {
1502 my $splitter = shift;
1507 # temporarily replace commas inside function pointer definition
1508 while ($args =~ /(\([^\),]+),/) {
1509 $args =~ s/(\([^\),]+),/$1#/g;
1512 foreach my $arg (split($splitter, $args)) {
1514 $arg =~ s/\/\*.*\*\///;
1515 # strip leading/trailing spaces
1521 # Treat preprocessor directive as a typeless variable just to fill
1522 # corresponding data structures "correctly". Catch it later in
1524 push_parameter
($arg, "", $file);
1525 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1526 # pointer-to-function
1528 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1531 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1532 push_parameter
($param, $type, $file);
1534 $arg =~ s/\s*:\s*/:/g;
1535 $arg =~ s/\s*\[/\[/g;
1537 my @args = split('\s*,\s*', $arg);
1538 if ($args[0] =~ m/\*/) {
1539 $args[0] =~ s/(\*+)\s*/ $1/;
1543 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1545 push(@first_arg, split('\s+', $1));
1546 push(@first_arg, $2);
1548 @first_arg = split('\s+', shift @args);
1551 unshift(@args, pop @first_arg);
1552 $type = join " ", @first_arg;
1554 foreach $param (@args) {
1555 if ($param =~ m/^(\*+)\s*(.*)/) {
1556 push_parameter
($2, "$type $1", $file);
1558 elsif ($param =~ m/(.*?):(\d+)/) {
1559 if ($type ne "") { # skip unnamed bit-fields
1560 push_parameter
($1, "$type:$2", $file)
1564 push_parameter
($param, $type, $file);
1571 sub push_parameter
($$$) {
1576 if (($anon_struct_union == 1) && ($type eq "") &&
1578 return; # ignore the ending }; from anon. struct/union
1581 $anon_struct_union = 0;
1582 my $param_name = $param;
1583 $param_name =~ s/\[.*//;
1585 if ($type eq "" && $param =~ /\.\.\.$/)
1588 $parameterdescs{$param} = "variable arguments";
1590 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1594 $parameterdescs{void
} = "no arguments";
1596 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1597 # handle unnamed (anonymous) union or struct:
1600 $param = "{unnamed_" . $param . "}";
1601 $parameterdescs{$param} = "anonymous\n";
1602 $anon_struct_union = 1;
1605 # warn if parameter has no description
1606 # (but ignore ones starting with # as these are not parameters
1607 # but inline preprocessor statements);
1608 # also ignore unnamed structs/unions;
1609 if (!$anon_struct_union) {
1610 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1612 $parameterdescs{$param_name} = $undescribed;
1614 if (($type eq 'function') || ($type eq 'enum')) {
1615 print STDERR
"Warning(${file}:$.): Function parameter ".
1616 "or member '$param' not " .
1617 "described in '$declaration_name'\n";
1619 print STDERR
"Warning(${file}:$.):".
1620 " No description found for parameter '$param'\n";
1625 push @parameterlist, $param;
1626 $parametertypes{$param} = $type;
1630 # takes a function prototype and the name of the current file being
1631 # processed and spits out all the details stored in the global
1633 sub dump_function
($$) {
1634 my $prototype = shift;
1637 $prototype =~ s/^static +//;
1638 $prototype =~ s/^extern +//;
1639 $prototype =~ s/^asmlinkage +//;
1640 $prototype =~ s/^inline +//;
1641 $prototype =~ s/^__inline__ +//;
1642 $prototype =~ s/^__inline +//;
1643 $prototype =~ s/^__always_inline +//;
1644 $prototype =~ s/^noinline +//;
1645 $prototype =~ s/__devinit +//;
1646 $prototype =~ s/__init +//;
1647 $prototype =~ s/^#define\s+//; #ak added
1648 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1650 # Yes, this truly is vile. We are looking for:
1651 # 1. Return type (may be nothing if we're looking at a macro)
1653 # 3. Function parameters.
1655 # All the while we have to watch out for function pointer parameters
1656 # (which IIRC is what the two sections are for), C types (these
1657 # regexps don't even start to express all the possibilities), and
1660 # If you mess with these regexps, it's a good idea to check that
1661 # the following functions' documentation still comes out right:
1662 # - parport_register_device (function pointer parameters)
1663 # - atomic_set (macro)
1664 # - pci_match_device, __copy_to_user (long return type)
1666 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1667 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1668 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1669 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1670 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1671 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1672 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1673 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1674 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1675 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1676 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1677 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1678 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1679 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1680 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1681 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1682 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1684 $declaration_name = $2;
1687 create_parameterlist
($args, ',', $file);
1689 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1694 output_declaration
($declaration_name,
1696 {'function' => $declaration_name,
1697 'module' => $modulename,
1698 'functiontype' => $return_type,
1699 'parameterlist' => \
@parameterlist,
1700 'parameterdescs' => \
%parameterdescs,
1701 'parametertypes' => \
%parametertypes,
1702 'sectionlist' => \
@sectionlist,
1703 'sections' => \
%sections,
1704 'purpose' => $declaration_purpose
1708 sub process_file
($);
1710 # Read the file that maps relative names to absolute names for
1711 # separate source and object directories and for shadow trees.
1712 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
1713 my ($relname, $absname);
1714 while(<SOURCE_MAP
>) {
1716 ($relname, $absname) = (split())[0..1];
1717 $relname =~ s
:^/+::;
1718 $source_map{$relname} = $absname;
1724 open(FLIST
,"<$filelist") or die "Can't open file list $filelist";
1735 if ($verbose && $errors) {
1736 print STDERR
"$errors errors\n";
1738 if ($verbose && $warnings) {
1739 print STDERR
"$warnings warnings\n";
1747 %parameterdescs = ();
1748 %parametertypes = ();
1749 @parameterlist = ();
1757 sub process_state3_function
($$) {
1761 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
1763 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1766 elsif ($x =~ /([^\{]*)/) {
1769 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1770 $prototype =~ s@
/\*.*?\*/@
@gos; # strip comments.
1771 $prototype =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1772 $prototype =~ s@
^\s
+@
@gos; # strip leading spaces
1773 dump_function
($prototype,$file);
1778 sub process_state3_type
($$) {
1782 $x =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1783 $x =~ s@
^\s
+@
@gos; # strip leading spaces
1784 $x =~ s@\s
+$@
@gos; # strip trailing spaces
1785 $x =~ s@\
/\/.*$@
@gos; # strip C99-style comments to end of line
1788 # To distinguish preprocessor directive from regular declaration later.
1793 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1794 $prototype .= $1 . $2;
1795 ($2 eq '{') && $brcount++;
1796 ($2 eq '}') && $brcount--;
1797 if (($2 eq ';') && ($brcount == 0)) {
1798 dump_declaration
($prototype,$file);
1810 # xml_escape: replace <, >, and & in the text stream;
1812 # however, formatting controls that are generated internally/locally in the
1813 # kernel-doc script are not escaped here; instead, they begin life like
1814 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1815 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1816 # just before actual output; (this is done by local_unescape())
1819 if (($output_mode eq "text") || ($output_mode eq "man")) {
1822 $text =~ s/\&/\\\\\\amp;/g;
1823 $text =~ s/\</\\\\\\lt;/g;
1824 $text =~ s/\>/\\\\\\gt;/g;
1828 # convert local escape strings to html
1829 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1830 sub local_unescape
($) {
1832 if (($output_mode eq "text") || ($output_mode eq "man")) {
1835 $text =~ s/\\\\\\\\lt:/</g;
1836 $text =~ s/\\\\\\\\gt:/>/g;
1840 sub process_file
($) {
1845 my $initial_section_counter = $section_counter;
1847 if (defined($ENV{'SRCTREE'})) {
1848 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1853 if (defined($source_map{$file})) {
1854 $file = $source_map{$file};
1857 if (!open(IN
,"<$file")) {
1858 print STDERR
"Error: Cannot open file $file\n";
1863 $section_counter = 0;
1866 if (/$doc_start/o) {
1867 $state = 1; # next line is always the function name
1870 } elsif ($state == 1) { # this line is the function name (always)
1871 if (/$doc_block/o) {
1875 $section = $section_intro;
1880 elsif (/$doc_decl/o) {
1882 if (/\s*([\w\s]+?)\s*-/) {
1888 # strip leading/trailing/multiple spaces
1893 $declaration_purpose = xml_escape
($descr);
1895 $declaration_purpose = "";
1898 if (($declaration_purpose eq "") && $verbose) {
1899 print STDERR
"Warning(${file}:$.): missing initial short description on line:\n";
1904 if ($identifier =~ m/^struct/) {
1905 $decl_type = 'struct';
1906 } elsif ($identifier =~ m/^union/) {
1907 $decl_type = 'union';
1908 } elsif ($identifier =~ m/^enum/) {
1909 $decl_type = 'enum';
1910 } elsif ($identifier =~ m/^typedef/) {
1911 $decl_type = 'typedef';
1913 $decl_type = 'function';
1917 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
1920 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
1921 " - I thought it was a doc line\n";
1925 } elsif ($state == 2) { # look for head: lines, and include content
1930 if (($contents ne "") && ($contents ne "\n")) {
1931 if (!$in_doc_sect && $verbose) {
1932 print STDERR
"Warning(${file}:$.): contents before sections\n";
1935 dump_section
($file, $section, xml_escape
($contents));
1936 $section = $section_default;
1940 $contents = $newcontents;
1941 if ($contents ne "") {
1942 while ((substr($contents, 0, 1) eq " ") ||
1943 substr($contents, 0, 1) eq "\t") {
1944 $contents = substr($contents, 1);
1948 $section = $newsection;
1949 } elsif (/$doc_end/) {
1951 if ($contents ne "") {
1952 dump_section
($file, $section, xml_escape
($contents));
1953 $section = $section_default;
1956 # look for doc_com + <text> + doc_end:
1957 if ($_ =~ m
'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
1958 print STDERR
"Warning(${file}:$.): suspicious ending line: $_";
1965 # print STDERR "end of doc comment, looking for prototype\n";
1966 } elsif (/$doc_content/) {
1967 # miguel-style comment kludge, look for blank lines after
1968 # @parameter line to signify start of description
1970 ($section =~ m/^@/ || $section eq $section_context)) {
1971 dump_section
($file, $section, xml_escape
($contents));
1972 $section = $section_default;
1975 $contents .= $1."\n";
1978 # i dont know - bad line? ignore.
1979 print STDERR
"Warning(${file}:$.): bad line: $_";
1982 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1983 if ($decl_type eq 'function') {
1984 process_state3_function
($_, $file);
1986 process_state3_type
($_, $file);
1988 } elsif ($state == 4) {
1989 # Documentation block
1991 dump_doc_section
($file, $section, xml_escape
($contents));
1995 %parameterdescs = ();
1996 %parametertypes = ();
1997 @parameterlist = ();
2002 $section = $section_intro;
2009 dump_doc_section
($file, $section, xml_escape
($contents));
2013 %parameterdescs = ();
2014 %parametertypes = ();
2015 @parameterlist = ();
2021 elsif (/$doc_content/)
2025 $contents .= $blankline;
2029 $contents .= $1 . "\n";
2034 if ($initial_section_counter == $section_counter) {
2035 print STDERR
"Warning(${file}): no structured comments found\n";
2036 if ($output_mode eq "xml") {
2037 # The template wants at least one RefEntry here; make one.
2038 print "<refentry>\n";
2039 print " <refnamediv>\n";
2040 print " <refname>\n";
2042 print " </refname>\n";
2043 print " <refpurpose>\n";
2044 print " Document generation inconsistency\n";
2045 print " </refpurpose>\n";
2046 print " </refnamediv>\n";
2047 print " <refsect1>\n";
2050 print " </title>\n";
2051 print " <warning>\n";
2053 print " The template for this document tried to insert\n";
2054 print " the structured comment from the file\n";
2055 print " <filename>${file}</filename> at this point,\n";
2056 print " but none was found.\n";
2057 print " This dummy section is inserted to allow\n";
2058 print " generation to continue.\n";
2060 print " </warning>\n";
2061 print " </refsect1>\n";
2062 print "</refentry>\n";