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 ##
9 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
10 ## Copyright (c) 2000 MontaVista Software, Inc. ##
12 ## This software falls under the GNU General Public License. ##
13 ## Please read the COPYING file for more information ##
15 # w.o. 03-11-2000: added the '-filelist' option.
17 # 18/01/2001 - Cleanups
18 # Functions prototyped as foo(void) same as foo()
19 # Stop eval'ing where we don't need to.
22 # 27/06/2001 - Allowed whitespace after initial "/**" and
23 # allowed comments before function declarations.
24 # -- Christian Kreibich <ck@whoop.org>
27 # - add perldoc documentation
28 # - Look more closely at some of the scarier bits :)
30 # 26/05/2001 - Support for separate source and object trees.
32 # Keith Owens <kaos@ocs.com.au>
34 # 23/09/2001 - Added support for typedefs, structs, enums and unions
35 # Support for Context section; can be terminated using empty line
36 # Small fixes (like spaces vs. \s in regex)
37 # -- Tim Jansen <tim@tjansen.de>
41 # This will read a 'c' file and scan for embedded comments in the
42 # style of gnome comments (+minor extensions - see below).
45 # Note: This only supports 'c'.
48 # kernel-doc [ -docbook | -html | -text | -man ]
49 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
51 # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
53 # Set output format using one of -docbook -html -text or -man. Default is man.
56 # If set, then only generate documentation for the given function(s). All
57 # other functions are ignored.
59 # -nofunction funcname
60 # If set, then only generate documentation for the other function(s). All
61 # other functions are ignored. Cannot be used with -function together
62 # (yes, that's a bug -- perl hackers can fix it 8))
64 # c files - list of 'c' files to process
66 # All output goes to stdout, with errors to stderr.
70 # In the following table, (...)? signifies optional structure.
71 # (...)* signifies 0 or more structure elements
73 # * function_name(:)? (- short description)?
74 # (* @parameterx: (description of parameter x)?)*
76 # * (Description:)? (Description of function)?
77 # * (section header: (section description)? )*
80 # So .. the trivial example would be:
86 # If the Description: header tag is ommitted, then there must be a blank line
87 # after the last parameter specification.
90 # * my_function - does my stuff
91 # * @my_arg: its mine damnit
93 # * Does my stuff explained.
98 # * my_function - does my stuff
99 # * @my_arg: its mine damnit
100 # * Description: Does my stuff explained.
104 # Beside functions you can also write documentation for structs, unions,
105 # enums and typedefs. Instead of the function name you must write the name
106 # of the declaration; the struct/union/enum/typedef must always precede
107 # the name. Nesting of declarations is not supported.
108 # Use the argument mechanism to document members or constants.
111 # * struct my_struct - short description
113 # * @b: second member
115 # * Longer description
124 # All descriptions can be multiline, except the short function description.
126 # You can also add additional sections. When documenting kernel functions you
127 # should document the "Context:" of the function, e.g. whether the functions
128 # can be called form interrupts. Unlike other sections you can end it with an
130 # Example-sections should contain the string EXAMPLE so that they are marked
131 # appropriately in DocBook.
135 # * user_function - function that can only be called in user context
136 # * @a: some argument
137 # * Context: !in_interrupt()
141 # * user_function(22);
146 # All descriptive text is further processed, scanning for the following special
147 # patterns, which are highlighted appropriately.
149 # 'funcname()' - function
150 # '$ENVVAR' - environmental variable
151 # '&struct_name' - name of a structure (up to two words including 'struct')
152 # '@parameter' - name of a parameter
153 # '%CONST' - name of a constant.
158 # match expressions used to find embedded type information
159 my $type_constant = '\%([-_\w]+)';
160 my $type_func = '(\w+)\(\)';
161 my $type_param = '\@(\w+)';
162 my $type_struct = '\&((struct\s*)?[_\w]+)';
163 my $type_env = '(\$\w+)';
165 # Output conversion substitutions.
166 # One for each output format
168 # these work fairly well
169 my %highlights_html = ( $type_constant, "<i>\$1</i>",
170 $type_func, "<b>\$1</b>",
171 $type_struct, "<i>\$1</i>",
172 $type_param, "<tt><b>\$1</b></tt>" );
173 my $blankline_html = "<p>";
175 # XML, docbook format
176 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
177 $type_constant, "<constant>\$1</constant>",
178 $type_func, "<function>\$1</function>",
179 $type_struct, "<structname>\$1</structname>",
180 $type_env, "<envar>\$1</envar>",
181 $type_param, "<parameter>\$1</parameter>" );
182 my $blankline_xml = "</para><para>\n";
184 # gnome, docbook format
185 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
186 $type_func, "<function>\$1</function>",
187 $type_struct, "<structname>\$1</structname>",
188 $type_env, "<envar>\$1</envar>",
189 $type_param, "<parameter>\$1</parameter>" );
190 my $blankline_gnome = "</para><para>\n";
192 # these are pretty rough
193 my %highlights_man = ( $type_constant, "\$1",
194 $type_func, "\\\\fB\$1\\\\fP",
195 $type_struct, "\\\\fI\$1\\\\fP",
196 $type_param, "\\\\fI\$1\\\\fP" );
197 my $blankline_man = "";
200 my %highlights_text = ( $type_constant, "\$1",
203 $type_param, "\$1" );
204 my $blankline_text = "";
208 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n";
209 print " [ -function funcname [ -function funcname ...] ]\n";
210 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
211 print " c source file(s) > outputfile\n";
221 my $output_mode = "man";
222 my %highlights = %highlights_man;
223 my $blankline = $blankline_man;
224 my $modulename = "Kernel API";
225 my $function_only = 0;
226 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
227 'July', 'August', 'September', 'October',
228 'November', 'December')[(localtime)[4]] .
229 " " . ((localtime)[5]+1900);
231 # Essentially these are globals
232 # They probably want to be tidied up made more localised or summat.
233 # CAVEAT EMPTOR! Some of the others I localised may not want to be which
234 # could cause "use of undefined value" or other bugs.
235 my ($function, %function_table,%parametertypes,$declaration_purpose);
236 my ($type,$declaration_name,$return_type);
237 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
239 # Generated docbook code is inserted in a template at a point where
240 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
241 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
242 # We keep track of number of generated entries and generate a dummy
243 # if needs be to ensure the expanded template can be postprocessed
245 my $section_counter = 0;
251 # 1 - looking for function name
252 # 2 - scanning field start.
253 # 3 - scanning prototype.
254 # 4 - documentation block
258 #declaration types: can be
259 # 'function', 'struct', 'union', 'enum', 'typedef'
262 my $doc_special = "\@\%\$\&";
264 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
266 my $doc_com = '\s*\*\s*';
267 my $doc_decl = $doc_com.'(\w+)';
268 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w ]+):(.*)';
269 my $doc_content = $doc_com.'(.*)';
270 my $doc_block = $doc_com.'DOC:\s*(.*)?';
279 my $section_default = "Description"; # default section
280 my $section_intro = "Introduction";
281 my $section = $section_default;
282 my $section_context = "Context";
284 my $undescribed = "-- undescribed --";
288 while ($ARGV[0] =~ m/^-(.*)/) {
289 my $cmd = shift @ARGV;
290 if ($cmd eq "-html") {
291 $output_mode = "html";
292 %highlights = %highlights_html;
293 $blankline = $blankline_html;
294 } elsif ($cmd eq "-man") {
295 $output_mode = "man";
296 %highlights = %highlights_man;
297 $blankline = $blankline_man;
298 } elsif ($cmd eq "-text") {
299 $output_mode = "text";
300 %highlights = %highlights_text;
301 $blankline = $blankline_text;
302 } elsif ($cmd eq "-docbook") {
303 $output_mode = "xml";
304 %highlights = %highlights_xml;
305 $blankline = $blankline_xml;
306 } elsif ($cmd eq "-gnome") {
307 $output_mode = "gnome";
308 %highlights = %highlights_gnome;
309 $blankline = $blankline_gnome;
310 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
311 $modulename = shift @ARGV;
312 } elsif ($cmd eq "-function") { # to only output specific functions
314 $function = shift @ARGV;
315 $function_table{$function} = 1;
316 } elsif ($cmd eq "-nofunction") { # to only output specific functions
318 $function = shift @ARGV;
319 $function_table{$function} = 1;
320 } elsif ($cmd eq "-v") {
322 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
324 } elsif ($cmd eq '-filelist') {
325 $filelist = shift @ARGV;
330 # generate a sequence of code that will splice in highlighting information
331 # using the s// operator.
332 my $dohighlight = "";
333 foreach my $pattern (keys %highlights) {
334 # print "scanning pattern $pattern ($highlights{$pattern})\n";
335 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
339 # dumps section contents to arrays/hashes intended for that purpose.
343 my $contents = join "\n", @_;
345 if ($name =~ m/$type_constant/) {
347 # print STDERR "constant section '$1' = '$contents'\n";
348 $constants{$name} = $contents;
349 } elsif ($name =~ m/$type_param/) {
350 # print STDERR "parameter def '$1' = '$contents'\n";
352 $parameterdescs{$name} = $contents;
354 # print STDERR "other section '$name' = '$contents'\n";
355 $sections{$name} = $contents;
356 push @sectionlist, $name;
363 # parameterdescs, a hash.
364 # function => "function name"
365 # parameterlist => @list of parameters
366 # parameterdescs => %parameter descriptions
367 # sectionlist => @list of sections
368 # sections => %descriont descriptions
371 sub output_highlight {
372 my $contents = join "\n",@_;
376 # if (!defined $contents) {
378 # confess "output_highlight got called with no args?\n";
383 foreach $line (split "\n", $contents) {
385 print $lineprefix, $blankline;
387 $line =~ s/\\\\\\/\&/g;
388 print $lineprefix, $line;
394 #output sections in html
395 sub output_section_html(%) {
399 foreach $section (@{$args{'sectionlist'}}) {
400 print "<h3>$section</h3>\n";
401 print "<blockquote>\n";
402 output_highlight($args{'sections'}{$section});
403 print "</blockquote>\n";
407 # output enum in html
408 sub output_enum_html(%) {
412 print "<h2>enum ".$args{'enum'}."</h2>\n";
414 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
416 foreach $parameter (@{$args{'parameterlist'}}) {
417 print " <b>".$parameter."</b>";
418 if ($count != $#{$args{'parameterlist'}}) {
426 print "<h3>Constants</h3>\n";
428 foreach $parameter (@{$args{'parameterlist'}}) {
429 print "<dt><b>".$parameter."</b>\n";
431 output_highlight($args{'parameterdescs'}{$parameter});
434 output_section_html(@_);
438 # output typedef in html
439 sub output_typedef_html(%) {
443 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
445 print "<b>typedef ".$args{'typedef'}."</b>\n";
446 output_section_html(@_);
450 # output struct in html
451 sub output_struct_html(%) {
455 print "<h2>".$args{'type'}." ".$args{'struct'}."</h2>\n";
456 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
457 foreach $parameter (@{$args{'parameterlist'}}) {
458 if ($parameter =~ /^#/) {
459 print "$parameter<br>\n";
462 my $parameter_name = $parameter;
463 $parameter_name =~ s/\[.*//;
465 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
466 $type = $args{'parametertypes'}{$parameter};
467 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
468 # pointer-to-function
469 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
470 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
471 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
473 print " <i>$type</i> <b>$parameter</b>;<br>\n";
478 print "<h3>Members</h3>\n";
480 foreach $parameter (@{$args{'parameterlist'}}) {
481 ($parameter =~ /^#/) && next;
483 my $parameter_name = $parameter;
484 $parameter_name =~ s/\[.*//;
486 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
487 print "<dt><b>".$parameter."</b>\n";
489 output_highlight($args{'parameterdescs'}{$parameter_name});
492 output_section_html(@_);
496 # output function in html
497 sub output_function_html(%) {
499 my ($parameter, $section);
501 print "<h2>Function</h2>\n";
503 print "<i>".$args{'functiontype'}."</i>\n";
504 print "<b>".$args{'function'}."</b>\n";
507 foreach $parameter (@{$args{'parameterlist'}}) {
508 $type = $args{'parametertypes'}{$parameter};
509 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
510 # pointer-to-function
511 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
513 print "<i>".$type."</i> <b>".$parameter."</b>";
515 if ($count != $#{$args{'parameterlist'}}) {
522 print "<h3>Arguments</h3>\n";
524 foreach $parameter (@{$args{'parameterlist'}}) {
525 my $parameter_name = $parameter;
526 $parameter_name =~ s/\[.*//;
528 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
529 print "<dt><b>".$parameter."</b>\n";
531 output_highlight($args{'parameterdescs'}{$parameter_name});
534 output_section_html(@_);
538 # output intro in html
539 sub output_intro_html(%) {
541 my ($parameter, $section);
544 foreach $section (@{$args{'sectionlist'}}) {
545 print "<h3>$section</h3>\n";
547 output_highlight($args{'sections'}{$section});
553 sub output_section_xml(%) {
556 # print out each section
558 foreach $section (@{$args{'sectionlist'}}) {
559 print "<refsect1>\n";
560 print "<title>$section</title>\n";
561 if ($section =~ m/EXAMPLE/i) {
562 print "<informalexample><programlisting>\n";
566 output_highlight($args{'sections'}{$section});
567 if ($section =~ m/EXAMPLE/i) {
568 print "</programlisting></informalexample>\n";
572 print "</refsect1>\n";
576 # output function in XML DocBook
577 sub output_function_xml(%) {
579 my ($parameter, $section);
583 $id = "API-".$args{'function'};
584 $id =~ s/[^A-Za-z0-9]/-/g;
586 print "<refentry>\n";
587 print "<refentryinfo>\n";
588 print " <title>LINUX</title>\n";
589 print " <productname>Kernel Hackers Manual</productname>\n";
590 print " <date>$man_date</date>\n";
591 print "</refentryinfo>\n";
593 print " <refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
594 print " <manvolnum>9</manvolnum>\n";
595 print "</refmeta>\n";
596 print "<refnamediv>\n";
597 print " <refname>".$args{'function'}."</refname>\n";
598 print " <refpurpose>\n";
600 output_highlight ($args{'purpose'});
601 print " </refpurpose>\n";
602 print "</refnamediv>\n";
604 print "<refsynopsisdiv>\n";
605 print " <title>Synopsis</title>\n";
606 print " <funcsynopsis><funcprototype>\n";
607 print " <funcdef>".$args{'functiontype'}." ";
608 print "<function>".$args{'function'}." </function></funcdef>\n";
611 if ($#{$args{'parameterlist'}} >= 0) {
612 foreach $parameter (@{$args{'parameterlist'}}) {
613 $type = $args{'parametertypes'}{$parameter};
614 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
615 # pointer-to-function
616 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
617 print " <funcparams>$2</funcparams></paramdef>\n";
619 print " <paramdef>".$type;
620 print " <parameter>$parameter</parameter></paramdef>\n";
626 print " </funcprototype></funcsynopsis>\n";
627 print "</refsynopsisdiv>\n";
630 print "<refsect1>\n <title>Arguments</title>\n";
631 if ($#{$args{'parameterlist'}} >= 0) {
632 print " <variablelist>\n";
633 foreach $parameter (@{$args{'parameterlist'}}) {
634 my $parameter_name = $parameter;
635 $parameter_name =~ s/\[.*//;
637 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
638 print " <listitem>\n <para>\n";
640 output_highlight($args{'parameterdescs'}{$parameter_name});
641 print " </para>\n </listitem>\n </varlistentry>\n";
643 print " </variablelist>\n";
645 print " <para>\n None\n </para>\n";
647 print "</refsect1>\n";
649 output_section_xml(@_);
650 print "</refentry>\n\n";
653 # output struct in XML DocBook
654 sub output_struct_xml(%) {
656 my ($parameter, $section);
659 $id = "API-struct-".$args{'struct'};
660 $id =~ s/[^A-Za-z0-9]/-/g;
662 print "<refentry>\n";
663 print "<refentryinfo>\n";
664 print " <title>LINUX</title>\n";
665 print " <productname>Kernel Hackers Manual</productname>\n";
666 print " <date>$man_date</date>\n";
667 print "</refentryinfo>\n";
669 print " <refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
670 print " <manvolnum>9</manvolnum>\n";
671 print "</refmeta>\n";
672 print "<refnamediv>\n";
673 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
674 print " <refpurpose>\n";
676 output_highlight ($args{'purpose'});
677 print " </refpurpose>\n";
678 print "</refnamediv>\n";
680 print "<refsynopsisdiv>\n";
681 print " <title>Synopsis</title>\n";
682 print " <programlisting>\n";
683 print $args{'type'}." ".$args{'struct'}." {\n";
684 foreach $parameter (@{$args{'parameterlist'}}) {
685 if ($parameter =~ /^#/) {
686 print "$parameter\n";
690 my $parameter_name = $parameter;
691 $parameter_name =~ s/\[.*//;
693 defined($args{'parameterdescs'}{$parameter_name}) || next;
694 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
695 $type = $args{'parametertypes'}{$parameter};
696 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
697 # pointer-to-function
698 print " $1 $parameter) ($2);\n";
699 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
700 print " $1 $parameter$2;\n";
702 print " ".$type." ".$parameter.";\n";
706 print " </programlisting>\n";
707 print "</refsynopsisdiv>\n";
709 print " <refsect1>\n";
710 print " <title>Members</title>\n";
712 print " <variablelist>\n";
713 foreach $parameter (@{$args{'parameterlist'}}) {
714 ($parameter =~ /^#/) && next;
716 my $parameter_name = $parameter;
717 $parameter_name =~ s/\[.*//;
719 defined($args{'parameterdescs'}{$parameter_name}) || next;
720 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
721 print " <varlistentry>";
722 print " <term>$parameter</term>\n";
723 print " <listitem><para>\n";
724 output_highlight($args{'parameterdescs'}{$parameter_name});
725 print " </para></listitem>\n";
726 print " </varlistentry>\n";
728 print " </variablelist>\n";
729 print " </refsect1>\n";
731 output_section_xml(@_);
733 print "</refentry>\n\n";
736 # output enum in XML DocBook
737 sub output_enum_xml(%) {
739 my ($parameter, $section);
743 $id = "API-enum-".$args{'enum'};
744 $id =~ s/[^A-Za-z0-9]/-/g;
746 print "<refentry>\n";
747 print "<refentryinfo>\n";
748 print " <title>LINUX</title>\n";
749 print " <productname>Kernel Hackers Manual</productname>\n";
750 print " <date>$man_date</date>\n";
751 print "</refentryinfo>\n";
753 print " <refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n";
754 print " <manvolnum>9</manvolnum>\n";
755 print "</refmeta>\n";
756 print "<refnamediv>\n";
757 print " <refname>enum ".$args{'enum'}."</refname>\n";
758 print " <refpurpose>\n";
760 output_highlight ($args{'purpose'});
761 print " </refpurpose>\n";
762 print "</refnamediv>\n";
764 print "<refsynopsisdiv>\n";
765 print " <title>Synopsis</title>\n";
766 print " <programlisting>\n";
767 print "enum ".$args{'enum'}." {\n";
769 foreach $parameter (@{$args{'parameterlist'}}) {
771 if ($count != $#{$args{'parameterlist'}}) {
778 print " </programlisting>\n";
779 print "</refsynopsisdiv>\n";
781 print "<refsect1>\n";
782 print " <title>Constants</title>\n";
783 print " <variablelist>\n";
784 foreach $parameter (@{$args{'parameterlist'}}) {
785 my $parameter_name = $parameter;
786 $parameter_name =~ s/\[.*//;
788 print " <varlistentry>";
789 print " <term>$parameter</term>\n";
790 print " <listitem><para>\n";
791 output_highlight($args{'parameterdescs'}{$parameter_name});
792 print " </para></listitem>\n";
793 print " </varlistentry>\n";
795 print " </variablelist>\n";
796 print "</refsect1>\n";
798 output_section_xml(@_);
800 print "</refentry>\n\n";
803 # output typedef in XML DocBook
804 sub output_typedef_xml(%) {
806 my ($parameter, $section);
809 $id = "API-typedef-".$args{'typedef'};
810 $id =~ s/[^A-Za-z0-9]/-/g;
812 print "<refentry>\n";
813 print "<refentryinfo>\n";
814 print " <title>LINUX</title>\n";
815 print " <productname>Kernel Hackers Manual</productname>\n";
816 print " <date>$man_date</date>\n";
817 print "</refentryinfo>\n";
819 print " <refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
820 print " <manvolnum>9</manvolnum>\n";
821 print "</refmeta>\n";
822 print "<refnamediv>\n";
823 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
824 print " <refpurpose>\n";
826 output_highlight ($args{'purpose'});
827 print " </refpurpose>\n";
828 print "</refnamediv>\n";
830 print "<refsynopsisdiv>\n";
831 print " <title>Synopsis</title>\n";
832 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
833 print "</refsynopsisdiv>\n";
835 output_section_xml(@_);
837 print "</refentry>\n\n";
840 # output in XML DocBook
841 sub output_intro_xml(%) {
843 my ($parameter, $section);
846 my $id = $args{'module'};
847 $id =~ s/[^A-Za-z0-9]/-/g;
849 # print out each section
851 foreach $section (@{$args{'sectionlist'}}) {
852 print "<refsect1>\n <title>$section</title>\n <para>\n";
853 if ($section =~ m/EXAMPLE/i) {
854 print "<example><para>\n";
856 output_highlight($args{'sections'}{$section});
857 if ($section =~ m/EXAMPLE/i) {
858 print "</para></example>\n";
860 print " </para>\n</refsect1>\n";
866 # output in XML DocBook
867 sub output_function_gnome {
869 my ($parameter, $section);
873 $id = $args{'module'}."-".$args{'function'};
874 $id =~ s/[^A-Za-z0-9]/-/g;
877 print " <title id=\"$id\">".$args{'function'}."</title>\n";
879 print " <funcsynopsis>\n";
880 print " <funcdef>".$args{'functiontype'}." ";
881 print "<function>".$args{'function'}." ";
882 print "</function></funcdef>\n";
885 if ($#{$args{'parameterlist'}} >= 0) {
886 foreach $parameter (@{$args{'parameterlist'}}) {
887 $type = $args{'parametertypes'}{$parameter};
888 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
889 # pointer-to-function
890 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
891 print " <funcparams>$2</funcparams></paramdef>\n";
893 print " <paramdef>".$type;
894 print " <parameter>$parameter</parameter></paramdef>\n";
900 print " </funcsynopsis>\n";
901 if ($#{$args{'parameterlist'}} >= 0) {
902 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
903 print "<tgroup cols=\"2\">\n";
904 print "<colspec colwidth=\"2*\">\n";
905 print "<colspec colwidth=\"8*\">\n";
907 foreach $parameter (@{$args{'parameterlist'}}) {
908 my $parameter_name = $parameter;
909 $parameter_name =~ s/\[.*//;
911 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
914 output_highlight($args{'parameterdescs'}{$parameter_name});
915 print " </entry></row>\n";
917 print " </tbody></tgroup></informaltable>\n";
919 print " <para>\n None\n </para>\n";
922 # print out each section
924 foreach $section (@{$args{'sectionlist'}}) {
925 print "<simplesect>\n <title>$section</title>\n";
926 if ($section =~ m/EXAMPLE/i) {
927 print "<example><programlisting>\n";
931 output_highlight($args{'sections'}{$section});
933 if ($section =~ m/EXAMPLE/i) {
934 print "</programlisting></example>\n";
937 print " </simplesect>\n";
940 print "</sect2>\n\n";
944 # output function in man
945 sub output_function_man(%) {
947 my ($parameter, $section);
950 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
953 print $args{'function'}." \\- ".$args{'purpose'}."\n";
955 print ".SH SYNOPSIS\n";
956 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
960 foreach my $parameter (@{$args{'parameterlist'}}) {
961 if ($count == $#{$args{'parameterlist'}}) {
964 $type = $args{'parametertypes'}{$parameter};
965 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
966 # pointer-to-function
967 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
969 $type =~ s/([^\*])$/$1 /;
970 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
976 print ".SH ARGUMENTS\n";
977 foreach $parameter (@{$args{'parameterlist'}}) {
978 my $parameter_name = $parameter;
979 $parameter_name =~ s/\[.*//;
981 print ".IP \"".$parameter."\" 12\n";
982 output_highlight($args{'parameterdescs'}{$parameter_name});
984 foreach $section (@{$args{'sectionlist'}}) {
985 print ".SH \"", uc $section, "\"\n";
986 output_highlight($args{'sections'}{$section});
992 sub output_enum_man(%) {
994 my ($parameter, $section);
997 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1000 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1002 print ".SH SYNOPSIS\n";
1003 print "enum ".$args{'enum'}." {\n";
1005 foreach my $parameter (@{$args{'parameterlist'}}) {
1006 print ".br\n.BI \" $parameter\"\n";
1007 if ($count == $#{$args{'parameterlist'}}) {
1017 print ".SH Constants\n";
1018 foreach $parameter (@{$args{'parameterlist'}}) {
1019 my $parameter_name = $parameter;
1020 $parameter_name =~ s/\[.*//;
1022 print ".IP \"".$parameter."\" 12\n";
1023 output_highlight($args{'parameterdescs'}{$parameter_name});
1025 foreach $section (@{$args{'sectionlist'}}) {
1026 print ".SH \"$section\"\n";
1027 output_highlight($args{'sections'}{$section});
1032 # output struct in man
1033 sub output_struct_man(%) {
1034 my %args = %{$_[0]};
1035 my ($parameter, $section);
1037 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1040 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1042 print ".SH SYNOPSIS\n";
1043 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1045 foreach my $parameter (@{$args{'parameterlist'}}) {
1046 if ($parameter =~ /^#/) {
1047 print ".BI \"$parameter\"\n.br\n";
1050 my $parameter_name = $parameter;
1051 $parameter_name =~ s/\[.*//;
1053 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1054 $type = $args{'parametertypes'}{$parameter};
1055 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1056 # pointer-to-function
1057 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1058 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1059 print ".BI \" ".$1."\" ".$parameter.$2." \""."\"\n;\n";
1061 $type =~ s/([^\*])$/$1 /;
1062 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1068 print ".SH Members\n";
1069 foreach $parameter (@{$args{'parameterlist'}}) {
1070 ($parameter =~ /^#/) && next;
1072 my $parameter_name = $parameter;
1073 $parameter_name =~ s/\[.*//;
1075 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1076 print ".IP \"".$parameter."\" 12\n";
1077 output_highlight($args{'parameterdescs'}{$parameter_name});
1079 foreach $section (@{$args{'sectionlist'}}) {
1080 print ".SH \"$section\"\n";
1081 output_highlight($args{'sections'}{$section});
1086 # output typedef in man
1087 sub output_typedef_man(%) {
1088 my %args = %{$_[0]};
1089 my ($parameter, $section);
1091 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1094 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1096 foreach $section (@{$args{'sectionlist'}}) {
1097 print ".SH \"$section\"\n";
1098 output_highlight($args{'sections'}{$section});
1102 sub output_intro_man(%) {
1103 my %args = %{$_[0]};
1104 my ($parameter, $section);
1107 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1109 foreach $section (@{$args{'sectionlist'}}) {
1110 print ".SH \"$section\"\n";
1111 output_highlight($args{'sections'}{$section});
1117 sub output_function_text(%) {
1118 my %args = %{$_[0]};
1119 my ($parameter, $section);
1121 print "Function:\n\n";
1122 my $start=$args{'functiontype'}." ".$args{'function'}." (";
1125 foreach my $parameter (@{$args{'parameterlist'}}) {
1126 $type = $args{'parametertypes'}{$parameter};
1127 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1128 # pointer-to-function
1129 print $1.$parameter.") (".$2;
1131 print $type." ".$parameter;
1133 if ($count != $#{$args{'parameterlist'}}) {
1136 print " " x length($start);
1142 print "Arguments:\n\n";
1143 foreach $parameter (@{$args{'parameterlist'}}) {
1144 my $parameter_name = $parameter;
1145 $parameter_name =~ s/\[.*//;
1147 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1149 output_section_text(@_);
1152 #output sections in text
1153 sub output_section_text(%) {
1154 my %args = %{$_[0]};
1158 foreach $section (@{$args{'sectionlist'}}) {
1159 print "$section:\n\n";
1160 output_highlight($args{'sections'}{$section});
1165 # output enum in text
1166 sub output_enum_text(%) {
1167 my %args = %{$_[0]};
1172 print "enum ".$args{'enum'}." {\n";
1174 foreach $parameter (@{$args{'parameterlist'}}) {
1175 print "\t$parameter";
1176 if ($count != $#{$args{'parameterlist'}}) {
1184 print "Constants:\n\n";
1185 foreach $parameter (@{$args{'parameterlist'}}) {
1186 print "$parameter\n\t";
1187 print $args{'parameterdescs'}{$parameter}."\n";
1190 output_section_text(@_);
1193 # output typedef in text
1194 sub output_typedef_text(%) {
1195 my %args = %{$_[0]};
1198 print "Typedef:\n\n";
1200 print "typedef ".$args{'typedef'}."\n";
1201 output_section_text(@_);
1204 # output struct as text
1205 sub output_struct_text(%) {
1206 my %args = %{$_[0]};
1209 print $args{'type'}." ".$args{'struct'}.":\n\n";
1210 print $args{'type'}." ".$args{'struct'}." {\n";
1211 foreach $parameter (@{$args{'parameterlist'}}) {
1212 if ($parameter =~ /^#/) {
1213 print "$parameter\n";
1217 my $parameter_name = $parameter;
1218 $parameter_name =~ s/\[.*//;
1220 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1221 $type = $args{'parametertypes'}{$parameter};
1222 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1223 # pointer-to-function
1224 print "\t$1 $parameter) ($2);\n";
1225 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1226 print "\t$1 $parameter$2;\n";
1228 print "\t".$type." ".$parameter.";\n";
1233 print "Members:\n\n";
1234 foreach $parameter (@{$args{'parameterlist'}}) {
1235 ($parameter =~ /^#/) && next;
1237 my $parameter_name = $parameter;
1238 $parameter_name =~ s/\[.*//;
1240 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1241 print "$parameter\n\t";
1242 print $args{'parameterdescs'}{$parameter_name}."\n";
1245 output_section_text(@_);
1248 sub output_intro_text(%) {
1249 my %args = %{$_[0]};
1250 my ($parameter, $section);
1252 foreach $section (@{$args{'sectionlist'}}) {
1253 print " $section:\n";
1255 output_highlight($args{'sections'}{$section});
1260 # generic output function for typedefs
1261 sub output_declaration {
1264 my $functype = shift;
1265 my $func = "output_${functype}_$output_mode";
1266 if (($function_only==0) ||
1267 ( $function_only == 1 && defined($function_table{$name})) ||
1268 ( $function_only == 2 && !defined($function_table{$name})))
1276 # generic output function - calls the right one based
1277 # on current output mode.
1280 my $func = "output_intro_".$output_mode;
1286 # takes a declaration (struct, union, enum, typedef) and
1287 # invokes the right handler. NOT called for functions.
1288 sub dump_declaration($$) {
1290 my ($prototype, $file) = @_;
1291 my $func = "dump_".$decl_type;
1295 sub dump_union($$) {
1299 sub dump_struct($$) {
1303 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1304 $declaration_name = $2;
1307 # ignore embedded structs or unions
1308 $members =~ s/{.*?}//g;
1310 # ignore members marked private:
1311 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1312 $members =~ s/\/\*.*?private:.*//gos;
1314 $members =~ s/\/\*.*?\*\///gos;
1316 create_parameterlist($members, ';', $file);
1318 output_declaration($declaration_name,
1320 {'struct' => $declaration_name,
1321 'module' => $modulename,
1322 'parameterlist' => \@parameterlist,
1323 'parameterdescs' => \%parameterdescs,
1324 'parametertypes' => \%parametertypes,
1325 'sectionlist' => \@sectionlist,
1326 'sections' => \%sections,
1327 'purpose' => $declaration_purpose,
1328 'type' => $decl_type
1332 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1341 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1342 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1343 $declaration_name = $1;
1346 foreach my $arg (split ',', $members) {
1347 $arg =~ s/^\s*(\w+).*/$1/;
1348 push @parameterlist, $arg;
1349 if (!$parameterdescs{$arg}) {
1350 $parameterdescs{$arg} = $undescribed;
1351 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1352 "not described in enum '$declaration_name'\n";
1357 output_declaration($declaration_name,
1359 {'enum' => $declaration_name,
1360 'module' => $modulename,
1361 'parameterlist' => \@parameterlist,
1362 'parameterdescs' => \%parameterdescs,
1363 'sectionlist' => \@sectionlist,
1364 'sections' => \%sections,
1365 'purpose' => $declaration_purpose
1369 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1374 sub dump_typedef($$) {
1378 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1379 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1380 $x =~ s/\(*.\)\s*;$/;/;
1381 $x =~ s/\[*.\]\s*;$/;/;
1384 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1385 $declaration_name = $1;
1387 output_declaration($declaration_name,
1389 {'typedef' => $declaration_name,
1390 'module' => $modulename,
1391 'sectionlist' => \@sectionlist,
1392 'sections' => \%sections,
1393 'purpose' => $declaration_purpose
1397 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1402 sub create_parameterlist($$$) {
1404 my $splitter = shift;
1409 # temporarily replace commas inside function pointer definition
1410 while ($args =~ /(\([^\),]+),/) {
1411 $args =~ s/(\([^\),]+),/$1#/g;
1414 foreach my $arg (split($splitter, $args)) {
1416 $arg =~ s/\/\*.*\*\///;
1417 # strip leading/trailing spaces
1423 # Treat preprocessor directive as a typeless variable just to fill
1424 # corresponding data structures "correctly". Catch it later in
1426 push_parameter($arg, "", $file);
1427 } elsif ($arg =~ m/\(/) {
1428 # pointer-to-function
1430 $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
1433 $type =~ s/([^\(]+\(\*)$param/$1/;
1434 push_parameter($param, $type, $file);
1436 $arg =~ s/\s*:\s*/:/g;
1437 $arg =~ s/\s*\[/\[/g;
1439 my @args = split('\s*,\s*', $arg);
1440 if ($args[0] =~ m/\*/) {
1441 $args[0] =~ s/(\*+)\s*/ $1/;
1443 my @first_arg = split('\s+', shift @args);
1444 unshift(@args, pop @first_arg);
1445 $type = join " ", @first_arg;
1447 foreach $param (@args) {
1448 if ($param =~ m/^(\*+)\s*(.*)/) {
1449 push_parameter($2, "$type $1", $file);
1451 elsif ($param =~ m/(.*?):(\d+)/) {
1452 push_parameter($1, "$type:$2", $file)
1455 push_parameter($param, $type, $file);
1462 sub push_parameter($$$) {
1467 my $param_name = $param;
1468 $param_name =~ s/\[.*//;
1470 if ($type eq "" && $param =~ /\.\.\.$/)
1473 $parameterdescs{$param} = "variable arguments";
1475 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1479 $parameterdescs{void} = "no arguments";
1481 # warn if parameter has no description
1482 # (but ignore ones starting with # as these are no parameters
1483 # but inline preprocessor statements
1484 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1486 $parameterdescs{$param_name} = $undescribed;
1488 if (($type eq 'function') || ($type eq 'enum')) {
1489 print STDERR "Warning(${file}:$.): Function parameter ".
1490 "or member '$param' not " .
1491 "described in '$declaration_name'\n";
1493 print STDERR "Warning(${file}:$.):".
1494 " No description found for parameter '$param'\n";
1498 push @parameterlist, $param;
1499 $parametertypes{$param} = $type;
1503 # takes a function prototype and the name of the current file being
1504 # processed and spits out all the details stored in the global
1506 sub dump_function($$) {
1507 my $prototype = shift;
1510 $prototype =~ s/^static +//;
1511 $prototype =~ s/^extern +//;
1512 $prototype =~ s/^fastcall +//;
1513 $prototype =~ s/^asmlinkage +//;
1514 $prototype =~ s/^inline +//;
1515 $prototype =~ s/^__inline__ +//;
1516 $prototype =~ s/^#define +//; #ak added
1517 $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//;
1519 # Yes, this truly is vile. We are looking for:
1520 # 1. Return type (may be nothing if we're looking at a macro)
1522 # 3. Function parameters.
1524 # All the while we have to watch out for function pointer parameters
1525 # (which IIRC is what the two sections are for), C types (these
1526 # regexps don't even start to express all the possibilities), and
1529 # If you mess with these regexps, it's a good idea to check that
1530 # the following functions' documentation still comes out right:
1531 # - parport_register_device (function pointer parameters)
1532 # - atomic_set (macro)
1533 # - pci_match_device, __copy_to_user (long return type)
1535 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1536 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1537 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1538 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1539 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1540 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1541 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1542 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1543 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1544 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1545 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1546 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1547 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1548 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1549 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1550 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1552 $declaration_name = $2;
1555 create_parameterlist($args, ',', $file);
1557 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1562 output_declaration($declaration_name,
1564 {'function' => $declaration_name,
1565 'module' => $modulename,
1566 'functiontype' => $return_type,
1567 'parameterlist' => \@parameterlist,
1568 'parameterdescs' => \%parameterdescs,
1569 'parametertypes' => \%parametertypes,
1570 'sectionlist' => \@sectionlist,
1571 'sections' => \%sections,
1572 'purpose' => $declaration_purpose
1576 sub process_file($);
1578 # Read the file that maps relative names to absolute names for
1579 # separate source and object directories and for shadow trees.
1580 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1581 my ($relname, $absname);
1582 while(<SOURCE_MAP>) {
1584 ($relname, $absname) = (split())[0..1];
1585 $relname =~ s:^/+::;
1586 $source_map{$relname} = $absname;
1592 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1603 if ($verbose && $errors) {
1604 print STDERR "$errors errors\n";
1606 if ($verbose && $warnings) {
1607 print STDERR "$warnings warnings\n";
1615 %parameterdescs = ();
1616 %parametertypes = ();
1617 @parameterlist = ();
1625 sub process_state3_function($$) {
1629 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1632 elsif ($x =~ /([^\{]*)/) {
1635 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1636 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1637 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1638 $prototype =~ s@^\s+@@gos; # strip leading spaces
1639 dump_function($prototype,$file);
1644 sub process_state3_type($$) {
1648 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1649 $x =~ s@^\s+@@gos; # strip leading spaces
1650 $x =~ s@\s+$@@gos; # strip trailing spaces
1652 # To distinguish preprocessor directive from regular declaration later.
1657 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1658 $prototype .= $1 . $2;
1659 ($2 eq '{') && $brcount++;
1660 ($2 eq '}') && $brcount--;
1661 if (($2 eq ';') && ($brcount == 0)) {
1662 dump_declaration($prototype,$file);
1674 # replace <, >, and &
1677 if (($output_mode eq "text") || ($output_mode eq "man")) {
1680 $text =~ s/\&/\\\\\\amp;/g;
1681 $text =~ s/\</\\\\\\lt;/g;
1682 $text =~ s/\>/\\\\\\gt;/g;
1686 sub process_file($) {
1690 my $initial_section_counter = $section_counter;
1692 if (defined($ENV{'SRCTREE'})) {
1693 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1698 if (defined($source_map{$file})) {
1699 $file = $source_map{$file};
1702 if (!open(IN,"<$file")) {
1703 print STDERR "Error: Cannot open file $file\n";
1708 $section_counter = 0;
1711 if (/$doc_start/o) {
1712 $state = 1; # next line is always the function name
1715 } elsif ($state == 1) { # this line is the function name (always)
1716 if (/$doc_block/o) {
1720 $section = $section_intro;
1725 elsif (/$doc_decl/o) {
1727 if (/\s*([\w\s]+?)\s*-/) {
1733 $declaration_purpose = xml_escape($1);
1735 $declaration_purpose = "";
1737 if ($identifier =~ m/^struct/) {
1738 $decl_type = 'struct';
1739 } elsif ($identifier =~ m/^union/) {
1740 $decl_type = 'union';
1741 } elsif ($identifier =~ m/^enum/) {
1742 $decl_type = 'enum';
1743 } elsif ($identifier =~ m/^typedef/) {
1744 $decl_type = 'typedef';
1746 $decl_type = 'function';
1750 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1753 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1754 " - I thought it was a doc line\n";
1758 } elsif ($state == 2) { # look for head: lines, and include content
1763 if ($contents ne "") {
1764 if (!$in_doc_sect && $verbose) {
1765 print STDERR "Warning(${file}:$.): contents before sections\n";
1768 dump_section($section, xml_escape($contents));
1769 $section = $section_default;
1773 $contents = $newcontents;
1774 if ($contents ne "") {
1775 if (substr($contents, 0, 1) eq " ") {
1776 $contents = substr($contents, 1);
1780 $section = $newsection;
1781 } elsif (/$doc_end/) {
1783 if ($contents ne "") {
1784 dump_section($section, xml_escape($contents));
1785 $section = $section_default;
1792 # print STDERR "end of doc comment, looking for prototype\n";
1793 } elsif (/$doc_content/) {
1794 # miguel-style comment kludge, look for blank lines after
1795 # @parameter line to signify start of description
1797 ($section =~ m/^@/ || $section eq $section_context)) {
1798 dump_section($section, xml_escape($contents));
1799 $section = $section_default;
1802 $contents .= $1."\n";
1805 # i dont know - bad line? ignore.
1806 print STDERR "Warning(${file}:$.): bad line: $_";
1809 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1810 if ($decl_type eq 'function') {
1811 process_state3_function($_, $file);
1813 process_state3_type($_, $file);
1815 } elsif ($state == 4) {
1816 # Documentation block
1818 dump_section($section, $contents);
1819 output_intro({'sectionlist' => \@sectionlist,
1820 'sections' => \%sections });
1824 %parameterdescs = ();
1825 %parametertypes = ();
1826 @parameterlist = ();
1831 $section = $section_intro;
1838 dump_section($section, $contents);
1839 output_intro({'sectionlist' => \@sectionlist,
1840 'sections' => \%sections });
1844 %parameterdescs = ();
1845 %parametertypes = ();
1846 @parameterlist = ();
1852 elsif (/$doc_content/)
1856 $contents .= $blankline;
1860 $contents .= $1 . "\n";
1865 if ($initial_section_counter == $section_counter) {
1866 print STDERR "Warning(${file}): no structured comments found\n";
1867 if ($output_mode eq "xml") {
1868 # The template wants at least one RefEntry here; make one.
1869 print "<refentry>\n";
1870 print " <refnamediv>\n";
1871 print " <refname>\n";
1873 print " </refname>\n";
1874 print " <refpurpose>\n";
1875 print " Document generation inconsistency\n";
1876 print " </refpurpose>\n";
1877 print " </refnamediv>\n";
1878 print " <refsect1>\n";
1881 print " </title>\n";
1882 print " <warning>\n";
1884 print " The template for this document tried to insert\n";
1885 print " the structured comment from the file\n";
1886 print " <filename>${file}</filename> at this point,\n";
1887 print " but none was found.\n";
1888 print " This dummy section is inserted to allow\n";
1889 print " generation to continue.\n";
1891 print " </warning>\n";
1892 print " </refsect1>\n";
1893 print "</refentry>\n";