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 # kerneldoc [ -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 thats 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
257 #declaration types: can be
258 # 'function', 'struct', 'union', 'enum', 'typedef'
261 my $doc_special = "\@\%\$\&";
263 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
265 my $doc_com = '\s*\*\s*';
266 my $doc_decl = $doc_com.'(\w+)';
267 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w ]+):(.*)';
268 my $doc_content = $doc_com.'(.*)';
269 my $doc_block = $doc_com.'DOC:\s*(.*)?';
278 my $section_default = "Description"; # default section
279 my $section_intro = "Introduction";
280 my $section = $section_default;
281 my $section_context = "Context";
283 my $undescribed = "-- undescribed --";
287 while ($ARGV[0] =~ m/^-(.*)/) {
288 my $cmd = shift @ARGV;
289 if ($cmd eq "-html") {
290 $output_mode = "html";
291 %highlights = %highlights_html;
292 $blankline = $blankline_html;
293 } elsif ($cmd eq "-man") {
294 $output_mode = "man";
295 %highlights = %highlights_man;
296 $blankline = $blankline_man;
297 } elsif ($cmd eq "-text") {
298 $output_mode = "text";
299 %highlights = %highlights_text;
300 $blankline = $blankline_text;
301 } elsif ($cmd eq "-docbook") {
302 $output_mode = "xml";
303 %highlights = %highlights_xml;
304 $blankline = $blankline_xml;
305 } elsif ($cmd eq "-gnome") {
306 $output_mode = "gnome";
307 %highlights = %highlights_gnome;
308 $blankline = $blankline_gnome;
309 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
310 $modulename = shift @ARGV;
311 } elsif ($cmd eq "-function") { # to only output specific functions
313 $function = shift @ARGV;
314 $function_table{$function} = 1;
315 } elsif ($cmd eq "-nofunction") { # to only output specific functions
317 $function = shift @ARGV;
318 $function_table{$function} = 1;
319 } elsif ($cmd eq "-v") {
321 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
323 } elsif ($cmd eq '-filelist') {
324 $filelist = shift @ARGV;
329 # generate a sequence of code that will splice in highlighting information
330 # using the s// operator.
331 my $dohighlight = "";
332 foreach my $pattern (keys %highlights) {
333 # print "scanning pattern $pattern ($highlights{$pattern})\n";
334 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
338 # dumps section contents to arrays/hashes intended for that purpose.
342 my $contents = join "\n", @_;
344 if ($name =~ m/$type_constant/) {
346 # print STDERR "constant section '$1' = '$contents'\n";
347 $constants{$name} = $contents;
348 } elsif ($name =~ m/$type_param/) {
349 # print STDERR "parameter def '$1' = '$contents'\n";
351 $parameterdescs{$name} = $contents;
353 # print STDERR "other section '$name' = '$contents'\n";
354 $sections{$name} = $contents;
355 push @sectionlist, $name;
362 # parameterdescs, a hash.
363 # function => "function name"
364 # parameterlist => @list of parameters
365 # parameterdescs => %parameter descriptions
366 # sectionlist => @list of sections
367 # sections => %descriont descriptions
370 sub output_highlight {
371 my $contents = join "\n",@_;
375 # if (!defined $contents) {
377 # confess "output_highlight got called with no args?\n";
382 foreach $line (split "\n", $contents) {
384 print $lineprefix, $blankline;
386 $line =~ s/\\\\\\/\&/g;
387 print $lineprefix, $line;
393 #output sections in html
394 sub output_section_html(%) {
398 foreach $section (@{$args{'sectionlist'}}) {
399 print "<h3>$section</h3>\n";
400 print "<blockquote>\n";
401 output_highlight($args{'sections'}{$section});
402 print "</blockquote>\n";
406 # output enum in html
407 sub output_enum_html(%) {
411 print "<h2>enum ".$args{'enum'}."</h2>\n";
413 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
415 foreach $parameter (@{$args{'parameterlist'}}) {
416 print " <b>".$parameter."</b>";
417 if ($count != $#{$args{'parameterlist'}}) {
425 print "<h3>Constants</h3>\n";
427 foreach $parameter (@{$args{'parameterlist'}}) {
428 print "<dt><b>".$parameter."</b>\n";
430 output_highlight($args{'parameterdescs'}{$parameter});
433 output_section_html(@_);
437 # output tyepdef in html
438 sub output_typedef_html(%) {
442 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
444 print "<b>typedef ".$args{'typedef'}."</b>\n";
445 output_section_html(@_);
449 # output struct in html
450 sub output_struct_html(%) {
454 print "<h2>".$args{'type'}." ".$args{'struct'}."</h2>\n";
455 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
456 foreach $parameter (@{$args{'parameterlist'}}) {
457 if ($parameter =~ /^#/) {
458 print "$parameter<br>\n";
461 my $parameter_name = $parameter;
462 $parameter_name =~ s/\[.*//;
464 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
465 $type = $args{'parametertypes'}{$parameter};
466 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
467 # pointer-to-function
468 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
469 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
470 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
472 print " <i>$type</i> <b>$parameter</b>;<br>\n";
477 print "<h3>Members</h3>\n";
479 foreach $parameter (@{$args{'parameterlist'}}) {
480 ($parameter =~ /^#/) && next;
482 my $parameter_name = $parameter;
483 $parameter_name =~ s/\[.*//;
485 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
486 print "<dt><b>".$parameter."</b>\n";
488 output_highlight($args{'parameterdescs'}{$parameter_name});
491 output_section_html(@_);
495 # output function in html
496 sub output_function_html(%) {
498 my ($parameter, $section);
500 print "<h2>Function</h2>\n";
502 print "<i>".$args{'functiontype'}."</i>\n";
503 print "<b>".$args{'function'}."</b>\n";
506 foreach $parameter (@{$args{'parameterlist'}}) {
507 $type = $args{'parametertypes'}{$parameter};
508 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
509 # pointer-to-function
510 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
512 print "<i>".$type."</i> <b>".$parameter."</b>";
514 if ($count != $#{$args{'parameterlist'}}) {
521 print "<h3>Arguments</h3>\n";
523 foreach $parameter (@{$args{'parameterlist'}}) {
524 my $parameter_name = $parameter;
525 $parameter_name =~ s/\[.*//;
527 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
528 print "<dt><b>".$parameter."</b>\n";
530 output_highlight($args{'parameterdescs'}{$parameter_name});
533 output_section_html(@_);
537 # output intro in html
538 sub output_intro_html(%) {
540 my ($parameter, $section);
543 foreach $section (@{$args{'sectionlist'}}) {
544 print "<h3>$section</h3>\n";
546 output_highlight($args{'sections'}{$section});
552 sub output_section_xml(%) {
555 # print out each section
557 foreach $section (@{$args{'sectionlist'}}) {
558 print "<refsect1>\n";
559 print "<title>$section</title>\n";
560 if ($section =~ m/EXAMPLE/i) {
561 print "<informalexample><programlisting>\n";
565 output_highlight($args{'sections'}{$section});
566 if ($section =~ m/EXAMPLE/i) {
567 print "</programlisting></informalexample>\n";
571 print "</refsect1>\n";
575 # output function in XML DocBook
576 sub output_function_xml(%) {
578 my ($parameter, $section);
582 $id = "API-".$args{'function'};
583 $id =~ s/[^A-Za-z0-9]/-/g;
585 print "<refentry>\n";
586 print "<refentryinfo>\n";
587 print " <title>LINUX</title>\n";
588 print " <productname>Kernel Hackers Manual</productname>\n";
589 print " <date>$man_date</date>\n";
590 print "</refentryinfo>\n";
592 print " <refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
593 print " <manvolnum>9</manvolnum>\n";
594 print "</refmeta>\n";
595 print "<refnamediv>\n";
596 print " <refname>".$args{'function'}."</refname>\n";
597 print " <refpurpose>\n";
599 output_highlight ($args{'purpose'});
600 print " </refpurpose>\n";
601 print "</refnamediv>\n";
603 print "<refsynopsisdiv>\n";
604 print " <title>Synopsis</title>\n";
605 print " <funcsynopsis><funcprototype>\n";
606 print " <funcdef>".$args{'functiontype'}." ";
607 print "<function>".$args{'function'}." </function></funcdef>\n";
610 if ($#{$args{'parameterlist'}} >= 0) {
611 foreach $parameter (@{$args{'parameterlist'}}) {
612 $type = $args{'parametertypes'}{$parameter};
613 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
614 # pointer-to-function
615 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
616 print " <funcparams>$2</funcparams></paramdef>\n";
618 print " <paramdef>".$type;
619 print " <parameter>$parameter</parameter></paramdef>\n";
625 print " </funcprototype></funcsynopsis>\n";
626 print "</refsynopsisdiv>\n";
629 print "<refsect1>\n <title>Arguments</title>\n";
630 if ($#{$args{'parameterlist'}} >= 0) {
631 print " <variablelist>\n";
632 foreach $parameter (@{$args{'parameterlist'}}) {
633 my $parameter_name = $parameter;
634 $parameter_name =~ s/\[.*//;
636 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
637 print " <listitem>\n <para>\n";
639 output_highlight($args{'parameterdescs'}{$parameter_name});
640 print " </para>\n </listitem>\n </varlistentry>\n";
642 print " </variablelist>\n";
644 print " <para>\n None\n </para>\n";
646 print "</refsect1>\n";
648 output_section_xml(@_);
649 print "</refentry>\n\n";
652 # output struct in XML DocBook
653 sub output_struct_xml(%) {
655 my ($parameter, $section);
658 $id = "API-struct-".$args{'struct'};
659 $id =~ s/[^A-Za-z0-9]/-/g;
661 print "<refentry>\n";
662 print "<refentryinfo>\n";
663 print " <title>LINUX</title>\n";
664 print " <productname>Kernel Hackers Manual</productname>\n";
665 print " <date>$man_date</date>\n";
666 print "</refentryinfo>\n";
668 print " <refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
669 print " <manvolnum>9</manvolnum>\n";
670 print "</refmeta>\n";
671 print "<refnamediv>\n";
672 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
673 print " <refpurpose>\n";
675 output_highlight ($args{'purpose'});
676 print " </refpurpose>\n";
677 print "</refnamediv>\n";
679 print "<refsynopsisdiv>\n";
680 print " <title>Synopsis</title>\n";
681 print " <programlisting>\n";
682 print $args{'type'}." ".$args{'struct'}." {\n";
683 foreach $parameter (@{$args{'parameterlist'}}) {
684 if ($parameter =~ /^#/) {
685 print "$parameter\n";
689 my $parameter_name = $parameter;
690 $parameter_name =~ s/\[.*//;
692 defined($args{'parameterdescs'}{$parameter_name}) || next;
693 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
694 $type = $args{'parametertypes'}{$parameter};
695 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
696 # pointer-to-function
697 print " $1 $parameter) ($2);\n";
698 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
699 print " $1 $parameter$2;\n";
701 print " ".$type." ".$parameter.";\n";
705 print " </programlisting>\n";
706 print "</refsynopsisdiv>\n";
708 print " <refsect1>\n";
709 print " <title>Members</title>\n";
711 print " <variablelist>\n";
712 foreach $parameter (@{$args{'parameterlist'}}) {
713 ($parameter =~ /^#/) && next;
715 my $parameter_name = $parameter;
716 $parameter_name =~ s/\[.*//;
718 defined($args{'parameterdescs'}{$parameter_name}) || next;
719 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
720 print " <varlistentry>";
721 print " <term>$parameter</term>\n";
722 print " <listitem><para>\n";
723 output_highlight($args{'parameterdescs'}{$parameter_name});
724 print " </para></listitem>\n";
725 print " </varlistentry>\n";
727 print " </variablelist>\n";
728 print " </refsect1>\n";
730 output_section_xml(@_);
732 print "</refentry>\n\n";
735 # output enum in XML DocBook
736 sub output_enum_xml(%) {
738 my ($parameter, $section);
742 $id = "API-enum-".$args{'enum'};
743 $id =~ s/[^A-Za-z0-9]/-/g;
745 print "<refentry>\n";
746 print "<refentryinfo>\n";
747 print " <title>LINUX</title>\n";
748 print " <productname>Kernel Hackers Manual</productname>\n";
749 print " <date>$man_date</date>\n";
750 print "</refentryinfo>\n";
752 print " <refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n";
753 print " <manvolnum>9</manvolnum>\n";
754 print "</refmeta>\n";
755 print "<refnamediv>\n";
756 print " <refname>enum ".$args{'enum'}."</refname>\n";
757 print " <refpurpose>\n";
759 output_highlight ($args{'purpose'});
760 print " </refpurpose>\n";
761 print "</refnamediv>\n";
763 print "<refsynopsisdiv>\n";
764 print " <title>Synopsis</title>\n";
765 print " <programlisting>\n";
766 print "enum ".$args{'enum'}." {\n";
768 foreach $parameter (@{$args{'parameterlist'}}) {
770 if ($count != $#{$args{'parameterlist'}}) {
777 print " </programlisting>\n";
778 print "</refsynopsisdiv>\n";
780 print "<refsect1>\n";
781 print " <title>Constants</title>\n";
782 print " <variablelist>\n";
783 foreach $parameter (@{$args{'parameterlist'}}) {
784 my $parameter_name = $parameter;
785 $parameter_name =~ s/\[.*//;
787 print " <varlistentry>";
788 print " <term>$parameter</term>\n";
789 print " <listitem><para>\n";
790 output_highlight($args{'parameterdescs'}{$parameter_name});
791 print " </para></listitem>\n";
792 print " </varlistentry>\n";
794 print " </variablelist>\n";
795 print "</refsect1>\n";
797 output_section_xml(@_);
799 print "</refentry>\n\n";
802 # output typedef in XML DocBook
803 sub output_typedef_xml(%) {
805 my ($parameter, $section);
808 $id = "API-typedef-".$args{'typedef'};
809 $id =~ s/[^A-Za-z0-9]/-/g;
811 print "<refentry>\n";
812 print "<refentryinfo>\n";
813 print " <title>LINUX</title>\n";
814 print " <productname>Kernel Hackers Manual</productname>\n";
815 print " <date>$man_date</date>\n";
816 print "</refentryinfo>\n";
818 print " <refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
819 print " <manvolnum>9</manvolnum>\n";
820 print "</refmeta>\n";
821 print "<refnamediv>\n";
822 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
823 print " <refpurpose>\n";
825 output_highlight ($args{'purpose'});
826 print " </refpurpose>\n";
827 print "</refnamediv>\n";
829 print "<refsynopsisdiv>\n";
830 print " <title>Synopsis</title>\n";
831 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
832 print "</refsynopsisdiv>\n";
834 output_section_xml(@_);
836 print "</refentry>\n\n";
839 # output in XML DocBook
840 sub output_intro_xml(%) {
842 my ($parameter, $section);
845 my $id = $args{'module'};
846 $id =~ s/[^A-Za-z0-9]/-/g;
848 # print out each section
850 foreach $section (@{$args{'sectionlist'}}) {
851 print "<refsect1>\n <title>$section</title>\n <para>\n";
852 if ($section =~ m/EXAMPLE/i) {
853 print "<example><para>\n";
855 output_highlight($args{'sections'}{$section});
856 if ($section =~ m/EXAMPLE/i) {
857 print "</para></example>\n";
859 print " </para>\n</refsect1>\n";
865 # output in XML DocBook
866 sub output_function_gnome {
868 my ($parameter, $section);
872 $id = $args{'module'}."-".$args{'function'};
873 $id =~ s/[^A-Za-z0-9]/-/g;
876 print " <title id=\"$id\">".$args{'function'}."</title>\n";
878 print " <funcsynopsis>\n";
879 print " <funcdef>".$args{'functiontype'}." ";
880 print "<function>".$args{'function'}." ";
881 print "</function></funcdef>\n";
884 if ($#{$args{'parameterlist'}} >= 0) {
885 foreach $parameter (@{$args{'parameterlist'}}) {
886 $type = $args{'parametertypes'}{$parameter};
887 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
888 # pointer-to-function
889 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
890 print " <funcparams>$2</funcparams></paramdef>\n";
892 print " <paramdef>".$type;
893 print " <parameter>$parameter</parameter></paramdef>\n";
899 print " </funcsynopsis>\n";
900 if ($#{$args{'parameterlist'}} >= 0) {
901 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
902 print "<tgroup cols=\"2\">\n";
903 print "<colspec colwidth=\"2*\">\n";
904 print "<colspec colwidth=\"8*\">\n";
906 foreach $parameter (@{$args{'parameterlist'}}) {
907 my $parameter_name = $parameter;
908 $parameter_name =~ s/\[.*//;
910 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
913 output_highlight($args{'parameterdescs'}{$parameter_name});
914 print " </entry></row>\n";
916 print " </tbody></tgroup></informaltable>\n";
918 print " <para>\n None\n </para>\n";
921 # print out each section
923 foreach $section (@{$args{'sectionlist'}}) {
924 print "<simplesect>\n <title>$section</title>\n";
925 if ($section =~ m/EXAMPLE/i) {
926 print "<example><programlisting>\n";
930 output_highlight($args{'sections'}{$section});
932 if ($section =~ m/EXAMPLE/i) {
933 print "</programlisting></example>\n";
936 print " </simplesect>\n";
939 print "</sect2>\n\n";
943 # output function in man
944 sub output_function_man(%) {
946 my ($parameter, $section);
949 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
952 print $args{'function'}." \\- ".$args{'purpose'}."\n";
954 print ".SH SYNOPSIS\n";
955 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
959 foreach my $parameter (@{$args{'parameterlist'}}) {
960 if ($count == $#{$args{'parameterlist'}}) {
963 $type = $args{'parametertypes'}{$parameter};
964 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
965 # pointer-to-function
966 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
968 $type =~ s/([^\*])$/$1 /;
969 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
975 print ".SH ARGUMENTS\n";
976 foreach $parameter (@{$args{'parameterlist'}}) {
977 my $parameter_name = $parameter;
978 $parameter_name =~ s/\[.*//;
980 print ".IP \"".$parameter."\" 12\n";
981 output_highlight($args{'parameterdescs'}{$parameter_name});
983 foreach $section (@{$args{'sectionlist'}}) {
984 print ".SH \"", uc $section, "\"\n";
985 output_highlight($args{'sections'}{$section});
991 sub output_enum_man(%) {
993 my ($parameter, $section);
996 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
999 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1001 print ".SH SYNOPSIS\n";
1002 print "enum ".$args{'enum'}." {\n";
1004 foreach my $parameter (@{$args{'parameterlist'}}) {
1005 print ".br\n.BI \" $parameter\"\n";
1006 if ($count == $#{$args{'parameterlist'}}) {
1016 print ".SH Constants\n";
1017 foreach $parameter (@{$args{'parameterlist'}}) {
1018 my $parameter_name = $parameter;
1019 $parameter_name =~ s/\[.*//;
1021 print ".IP \"".$parameter."\" 12\n";
1022 output_highlight($args{'parameterdescs'}{$parameter_name});
1024 foreach $section (@{$args{'sectionlist'}}) {
1025 print ".SH \"$section\"\n";
1026 output_highlight($args{'sections'}{$section});
1031 # output struct in man
1032 sub output_struct_man(%) {
1033 my %args = %{$_[0]};
1034 my ($parameter, $section);
1036 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1039 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1041 print ".SH SYNOPSIS\n";
1042 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1044 foreach my $parameter (@{$args{'parameterlist'}}) {
1045 if ($parameter =~ /^#/) {
1046 print ".BI \"$parameter\"\n.br\n";
1049 my $parameter_name = $parameter;
1050 $parameter_name =~ s/\[.*//;
1052 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1053 $type = $args{'parametertypes'}{$parameter};
1054 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1055 # pointer-to-function
1056 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1057 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1058 print ".BI \" ".$1."\" ".$parameter.$2." \""."\"\n;\n";
1060 $type =~ s/([^\*])$/$1 /;
1061 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1067 print ".SH Arguments\n";
1068 foreach $parameter (@{$args{'parameterlist'}}) {
1069 ($parameter =~ /^#/) && next;
1071 my $parameter_name = $parameter;
1072 $parameter_name =~ s/\[.*//;
1074 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1075 print ".IP \"".$parameter."\" 12\n";
1076 output_highlight($args{'parameterdescs'}{$parameter_name});
1078 foreach $section (@{$args{'sectionlist'}}) {
1079 print ".SH \"$section\"\n";
1080 output_highlight($args{'sections'}{$section});
1085 # output typedef in man
1086 sub output_typedef_man(%) {
1087 my %args = %{$_[0]};
1088 my ($parameter, $section);
1090 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1093 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1095 foreach $section (@{$args{'sectionlist'}}) {
1096 print ".SH \"$section\"\n";
1097 output_highlight($args{'sections'}{$section});
1101 sub output_intro_man(%) {
1102 my %args = %{$_[0]};
1103 my ($parameter, $section);
1106 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1108 foreach $section (@{$args{'sectionlist'}}) {
1109 print ".SH \"$section\"\n";
1110 output_highlight($args{'sections'}{$section});
1116 sub output_function_text(%) {
1117 my %args = %{$_[0]};
1118 my ($parameter, $section);
1120 print "Function:\n\n";
1121 my $start=$args{'functiontype'}." ".$args{'function'}." (";
1124 foreach my $parameter (@{$args{'parameterlist'}}) {
1125 $type = $args{'parametertypes'}{$parameter};
1126 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1127 # pointer-to-function
1128 print $1.$parameter.") (".$2;
1130 print $type." ".$parameter;
1132 if ($count != $#{$args{'parameterlist'}}) {
1135 print " " x length($start);
1141 print "Arguments:\n\n";
1142 foreach $parameter (@{$args{'parameterlist'}}) {
1143 my $parameter_name = $parameter;
1144 $parameter_name =~ s/\[.*//;
1146 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1148 output_section_text(@_);
1151 #output sections in text
1152 sub output_section_text(%) {
1153 my %args = %{$_[0]};
1157 foreach $section (@{$args{'sectionlist'}}) {
1158 print "$section:\n\n";
1159 output_highlight($args{'sections'}{$section});
1164 # output enum in text
1165 sub output_enum_text(%) {
1166 my %args = %{$_[0]};
1171 print "enum ".$args{'enum'}." {\n";
1173 foreach $parameter (@{$args{'parameterlist'}}) {
1174 print "\t$parameter";
1175 if ($count != $#{$args{'parameterlist'}}) {
1183 print "Constants:\n\n";
1184 foreach $parameter (@{$args{'parameterlist'}}) {
1185 print "$parameter\n\t";
1186 print $args{'parameterdescs'}{$parameter}."\n";
1189 output_section_text(@_);
1192 # output typedef in text
1193 sub output_typedef_text(%) {
1194 my %args = %{$_[0]};
1197 print "Typedef:\n\n";
1199 print "typedef ".$args{'typedef'}."\n";
1200 output_section_text(@_);
1203 # output struct as text
1204 sub output_struct_text(%) {
1205 my %args = %{$_[0]};
1208 print $args{'type'}." ".$args{'struct'}.":\n\n";
1209 print $args{'type'}." ".$args{'struct'}." {\n";
1210 foreach $parameter (@{$args{'parameterlist'}}) {
1211 if ($parameter =~ /^#/) {
1212 print "$parameter\n";
1216 my $parameter_name = $parameter;
1217 $parameter_name =~ s/\[.*//;
1219 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1220 $type = $args{'parametertypes'}{$parameter};
1221 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1222 # pointer-to-function
1223 print "\t$1 $parameter) ($2);\n";
1224 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1225 print "\t$1 $parameter$2;\n";
1227 print "\t".$type." ".$parameter.";\n";
1232 print "Members:\n\n";
1233 foreach $parameter (@{$args{'parameterlist'}}) {
1234 ($parameter =~ /^#/) && next;
1236 my $parameter_name = $parameter;
1237 $parameter_name =~ s/\[.*//;
1239 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1240 print "$parameter\n\t";
1241 print $args{'parameterdescs'}{$parameter_name}."\n";
1244 output_section_text(@_);
1247 sub output_intro_text(%) {
1248 my %args = %{$_[0]};
1249 my ($parameter, $section);
1251 foreach $section (@{$args{'sectionlist'}}) {
1252 print " $section:\n";
1254 output_highlight($args{'sections'}{$section});
1259 # generic output function for typedefs
1260 sub output_declaration {
1263 my $functype = shift;
1264 my $func = "output_${functype}_$output_mode";
1265 if (($function_only==0) ||
1266 ( $function_only == 1 && defined($function_table{$name})) ||
1267 ( $function_only == 2 && !defined($function_table{$name})))
1275 # generic output function - calls the right one based
1276 # on current output mode.
1279 my $func = "output_intro_".$output_mode;
1285 # takes a declaration (struct, union, enum, typedef) and
1286 # invokes the right handler. NOT called for functions.
1287 sub dump_declaration($$) {
1289 my ($prototype, $file) = @_;
1290 my $func = "dump_".$decl_type;
1294 sub dump_union($$) {
1298 sub dump_struct($$) {
1302 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1303 $declaration_name = $2;
1306 # ignore embedded structs or unions
1307 $members =~ s/{.*?}//g;
1309 # ignore members marked private:
1310 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1311 $members =~ s/\/\*.*?private:.*//gos;
1313 $members =~ s/\/\*.*?\*\///gos;
1315 create_parameterlist($members, ';', $file);
1317 output_declaration($declaration_name,
1319 {'struct' => $declaration_name,
1320 'module' => $modulename,
1321 'parameterlist' => \@parameterlist,
1322 'parameterdescs' => \%parameterdescs,
1323 'parametertypes' => \%parametertypes,
1324 'sectionlist' => \@sectionlist,
1325 'sections' => \%sections,
1326 'purpose' => $declaration_purpose,
1327 'type' => $decl_type
1331 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1340 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1341 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1342 $declaration_name = $1;
1345 foreach my $arg (split ',', $members) {
1346 $arg =~ s/^\s*(\w+).*/$1/;
1347 push @parameterlist, $arg;
1348 if (!$parameterdescs{$arg}) {
1349 $parameterdescs{$arg} = $undescribed;
1350 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1351 "not described in enum '$declaration_name'\n";
1356 output_declaration($declaration_name,
1358 {'enum' => $declaration_name,
1359 'module' => $modulename,
1360 'parameterlist' => \@parameterlist,
1361 'parameterdescs' => \%parameterdescs,
1362 'sectionlist' => \@sectionlist,
1363 'sections' => \%sections,
1364 'purpose' => $declaration_purpose
1368 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1373 sub dump_typedef($$) {
1377 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1378 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1379 $x =~ s/\(*.\)\s*;$/;/;
1380 $x =~ s/\[*.\]\s*;$/;/;
1383 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1384 $declaration_name = $1;
1386 output_declaration($declaration_name,
1388 {'typedef' => $declaration_name,
1389 'module' => $modulename,
1390 'sectionlist' => \@sectionlist,
1391 'sections' => \%sections,
1392 'purpose' => $declaration_purpose
1396 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1401 sub create_parameterlist($$$) {
1403 my $splitter = shift;
1408 # temporarily replace commas inside function pointer definition
1409 while ($args =~ /(\([^\),]+),/) {
1410 $args =~ s/(\([^\),]+),/$1#/g;
1413 foreach my $arg (split($splitter, $args)) {
1415 $arg =~ s/\/\*.*\*\///;
1416 # strip leading/trailing spaces
1422 # Treat preprocessor directive as a typeless variable just to fill
1423 # corresponding data structures "correctly". Catch it later in
1425 push_parameter($arg, "", $file);
1426 } elsif ($arg =~ m/\(/) {
1427 # pointer-to-function
1429 $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
1432 $type =~ s/([^\(]+\(\*)$param/$1/;
1433 push_parameter($param, $type, $file);
1435 $arg =~ s/\s*:\s*/:/g;
1436 $arg =~ s/\s*\[/\[/g;
1438 my @args = split('\s*,\s*', $arg);
1439 if ($args[0] =~ m/\*/) {
1440 $args[0] =~ s/(\*+)\s*/ $1/;
1442 my @first_arg = split('\s+', shift @args);
1443 unshift(@args, pop @first_arg);
1444 $type = join " ", @first_arg;
1446 foreach $param (@args) {
1447 if ($param =~ m/^(\*+)\s*(.*)/) {
1448 push_parameter($2, "$type $1", $file);
1450 elsif ($param =~ m/(.*?):(\d+)/) {
1451 push_parameter($1, "$type:$2", $file)
1454 push_parameter($param, $type, $file);
1461 sub push_parameter($$$) {
1466 my $param_name = $param;
1467 $param_name =~ s/\[.*//;
1469 if ($type eq "" && $param =~ /\.\.\.$/)
1472 $parameterdescs{$param} = "variable arguments";
1474 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1478 $parameterdescs{void} = "no arguments";
1480 # warn if parameter has no description
1481 # (but ignore ones starting with # as these are no parameters
1482 # but inline preprocessor statements
1483 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1485 $parameterdescs{$param_name} = $undescribed;
1487 if (($type eq 'function') || ($type eq 'enum')) {
1488 print STDERR "Warning(${file}:$.): Function parameter ".
1489 "or member '$param' not " .
1490 "described in '$declaration_name'\n";
1492 print STDERR "Warning(${file}:$.):".
1493 " No description found for parameter '$param'\n";
1497 push @parameterlist, $param;
1498 $parametertypes{$param} = $type;
1502 # takes a function prototype and the name of the current file being
1503 # processed and spits out all the details stored in the global
1505 sub dump_function($$) {
1506 my $prototype = shift;
1509 $prototype =~ s/^static +//;
1510 $prototype =~ s/^extern +//;
1511 $prototype =~ s/^fastcall +//;
1512 $prototype =~ s/^asmlinkage +//;
1513 $prototype =~ s/^inline +//;
1514 $prototype =~ s/^__inline__ +//;
1515 $prototype =~ s/^#define +//; #ak added
1516 $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//;
1518 # Yes, this truly is vile. We are looking for:
1519 # 1. Return type (may be nothing if we're looking at a macro)
1521 # 3. Function parameters.
1523 # All the while we have to watch out for function pointer parameters
1524 # (which IIRC is what the two sections are for), C types (these
1525 # regexps don't even start to express all the possibilities), and
1528 # If you mess with these regexps, it's a good idea to check that
1529 # the following functions' documentation still comes out right:
1530 # - parport_register_device (function pointer parameters)
1531 # - atomic_set (macro)
1532 # - pci_match_device (long return type)
1534 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1535 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1536 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1537 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1538 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1539 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1540 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1541 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1542 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1543 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1544 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1545 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1546 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1547 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1549 $declaration_name = $2;
1552 create_parameterlist($args, ',', $file);
1554 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1559 output_declaration($declaration_name,
1561 {'function' => $declaration_name,
1562 'module' => $modulename,
1563 'functiontype' => $return_type,
1564 'parameterlist' => \@parameterlist,
1565 'parameterdescs' => \%parameterdescs,
1566 'parametertypes' => \%parametertypes,
1567 'sectionlist' => \@sectionlist,
1568 'sections' => \%sections,
1569 'purpose' => $declaration_purpose
1573 sub process_file($);
1575 # Read the file that maps relative names to absolute names for
1576 # separate source and object directories and for shadow trees.
1577 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1578 my ($relname, $absname);
1579 while(<SOURCE_MAP>) {
1581 ($relname, $absname) = (split())[0..1];
1582 $relname =~ s:^/+::;
1583 $source_map{$relname} = $absname;
1589 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1600 if ($verbose && $errors) {
1601 print STDERR "$errors errors\n";
1603 if ($verbose && $warnings) {
1604 print STDERR "$warnings warnings\n";
1612 %parameterdescs = ();
1613 %parametertypes = ();
1614 @parameterlist = ();
1622 sub process_state3_function($$) {
1626 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1629 elsif ($x =~ /([^\{]*)/) {
1632 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1633 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1634 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1635 $prototype =~ s@^\s+@@gos; # strip leading spaces
1636 dump_function($prototype,$file);
1641 sub process_state3_type($$) {
1645 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1646 $x =~ s@^\s+@@gos; # strip leading spaces
1647 $x =~ s@\s+$@@gos; # strip trailing spaces
1649 # To distinguish preprocessor directive from regular declaration later.
1654 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1655 $prototype .= $1 . $2;
1656 ($2 eq '{') && $brcount++;
1657 ($2 eq '}') && $brcount--;
1658 if (($2 eq ';') && ($brcount == 0)) {
1659 dump_declaration($prototype,$file);
1671 # replace <, >, and &
1674 $text =~ s/\&/\\\\\\amp;/g;
1675 $text =~ s/\</\\\\\\lt;/g;
1676 $text =~ s/\>/\\\\\\gt;/g;
1680 sub process_file($) {
1684 my $initial_section_counter = $section_counter;
1686 if (defined($ENV{'SRCTREE'})) {
1687 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1692 if (defined($source_map{$file})) {
1693 $file = $source_map{$file};
1696 if (!open(IN,"<$file")) {
1697 print STDERR "Error: Cannot open file $file\n";
1702 $section_counter = 0;
1705 if (/$doc_start/o) {
1706 $state = 1; # next line is always the function name
1708 } elsif ($state == 1) { # this line is the function name (always)
1709 if (/$doc_block/o) {
1713 $section = $section_intro;
1718 elsif (/$doc_decl/o) {
1720 if (/\s*([\w\s]+?)\s*-/) {
1726 $declaration_purpose = xml_escape($1);
1728 $declaration_purpose = "";
1730 if ($identifier =~ m/^struct/) {
1731 $decl_type = 'struct';
1732 } elsif ($identifier =~ m/^union/) {
1733 $decl_type = 'union';
1734 } elsif ($identifier =~ m/^enum/) {
1735 $decl_type = 'enum';
1736 } elsif ($identifier =~ m/^typedef/) {
1737 $decl_type = 'typedef';
1739 $decl_type = 'function';
1743 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1746 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1747 " - I thought it was a doc line\n";
1751 } elsif ($state == 2) { # look for head: lines, and include content
1756 if ($contents ne "") {
1757 dump_section($section, xml_escape($contents));
1758 $section = $section_default;
1761 $contents = $newcontents;
1762 if ($contents ne "") {
1765 $section = $newsection;
1766 } elsif (/$doc_end/) {
1768 if ($contents ne "") {
1769 dump_section($section, xml_escape($contents));
1770 $section = $section_default;
1777 # print STDERR "end of doc comment, looking for prototype\n";
1778 } elsif (/$doc_content/) {
1779 # miguel-style comment kludge, look for blank lines after
1780 # @parameter line to signify start of description
1782 ($section =~ m/^@/ || $section eq $section_context)) {
1783 dump_section($section, xml_escape($contents));
1784 $section = $section_default;
1787 $contents .= $1."\n";
1790 # i dont know - bad line? ignore.
1791 print STDERR "Warning(${file}:$.): bad line: $_";
1794 } elsif ($state == 3) { # scanning for function { (end of prototype)
1795 if ($decl_type eq 'function') {
1796 process_state3_function($_, $file);
1798 process_state3_type($_, $file);
1800 } elsif ($state == 4) {
1801 # Documentation block
1803 dump_section($section, $contents);
1804 output_intro({'sectionlist' => \@sectionlist,
1805 'sections' => \%sections });
1809 %parameterdescs = ();
1810 %parametertypes = ();
1811 @parameterlist = ();
1816 $section = $section_intro;
1823 dump_section($section, $contents);
1824 output_intro({'sectionlist' => \@sectionlist,
1825 'sections' => \%sections });
1829 %parameterdescs = ();
1830 %parametertypes = ();
1831 @parameterlist = ();
1837 elsif (/$doc_content/)
1841 $contents .= $blankline;
1845 $contents .= $1 . "\n";
1850 if ($initial_section_counter == $section_counter) {
1851 print STDERR "Warning(${file}): no structured comments found\n";
1852 if ($output_mode eq "xml") {
1853 # The template wants at least one RefEntry here; make one.
1854 print "<refentry>\n";
1855 print " <refnamediv>\n";
1856 print " <refname>\n";
1858 print " </refname>\n";
1859 print " <refpurpose>\n";
1860 print " Document generation inconsistency\n";
1861 print " </refpurpose>\n";
1862 print " </refnamediv>\n";
1863 print " <refsect1>\n";
1866 print " </title>\n";
1867 print " <warning>\n";
1869 print " The template for this document tried to insert\n";
1870 print " the structured comment from the file\n";
1871 print " <filename>${file}</filename> at this point,\n";
1872 print " but none was found.\n";
1873 print " This dummy section is inserted to allow\n";
1874 print " generation to continue.\n";
1876 print " </warning>\n";
1877 print " </refsect1>\n";
1878 print "</refentry>\n";