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
122 # All descriptions can be multiline, except the short function description.
124 # You can also add additional sections. When documenting kernel functions you
125 # should document the "Context:" of the function, e.g. whether the functions
126 # can be called form interrupts. Unlike other sections you can end it with an
128 # Example-sections should contain the string EXAMPLE so that they are marked
129 # appropriately in DocBook.
133 # * user_function - function that can only be called in user context
134 # * @a: some argument
135 # * Context: !in_interrupt()
139 # * user_function(22);
144 # All descriptive text is further processed, scanning for the following special
145 # patterns, which are highlighted appropriately.
147 # 'funcname()' - function
148 # '$ENVVAR' - environmental variable
149 # '&struct_name' - name of a structure (up to two words including 'struct')
150 # '@parameter' - name of a parameter
151 # '%CONST' - name of a constant.
156 # match expressions used to find embedded type information
157 my $type_constant = '\%([-_\w]+)';
158 my $type_func = '(\w+)\(\)';
159 my $type_param = '\@(\w+)';
160 my $type_struct = '\&((struct\s*)?[_\w]+)';
161 my $type_env = '(\$\w+)';
163 # Output conversion substitutions.
164 # One for each output format
166 # these work fairly well
167 my %highlights_html = ( $type_constant, "<i>\$1</i>",
168 $type_func, "<b>\$1</b>",
169 $type_struct, "<i>\$1</i>",
170 $type_param, "<tt><b>\$1</b></tt>" );
171 my $blankline_html = "<p>";
173 # XML, docbook format
174 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
175 $type_constant, "<constant>\$1</constant>",
176 $type_func, "<function>\$1</function>",
177 $type_struct, "<structname>\$1</structname>",
178 $type_env, "<envar>\$1</envar>",
179 $type_param, "<parameter>\$1</parameter>" );
180 my $blankline_xml = "</para><para>\n";
182 # gnome, docbook format
183 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
184 $type_func, "<function>\$1</function>",
185 $type_struct, "<structname>\$1</structname>",
186 $type_env, "<envar>\$1</envar>",
187 $type_param, "<parameter>\$1</parameter>" );
188 my $blankline_gnome = "</para><para>\n";
190 # these are pretty rough
191 my %highlights_man = ( $type_constant, "\$1",
192 $type_func, "\\\\fB\$1\\\\fP",
193 $type_struct, "\\\\fI\$1\\\\fP",
194 $type_param, "\\\\fI\$1\\\\fP" );
195 my $blankline_man = "";
198 my %highlights_text = ( $type_constant, "\$1",
201 $type_param, "\$1" );
202 my $blankline_text = "";
206 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n";
207 print " [ -function funcname [ -function funcname ...] ]\n";
208 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
209 print " c source file(s) > outputfile\n";
219 my $output_mode = "man";
220 my %highlights = %highlights_man;
221 my $blankline = $blankline_man;
222 my $modulename = "Kernel API";
223 my $function_only = 0;
224 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
225 'July', 'August', 'September', 'October',
226 'November', 'December')[(localtime)[4]] .
227 " " . ((localtime)[5]+1900);
229 # Essentially these are globals
230 # They probably want to be tidied up made more localised or summat.
231 # CAVEAT EMPTOR! Some of the others I localised may not want to be which
232 # could cause "use of undefined value" or other bugs.
233 my ($function, %function_table,%parametertypes,$declaration_purpose);
234 my ($type,$declaration_name,$return_type);
235 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
237 # Generated docbook code is inserted in a template at a point where
238 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
239 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
240 # We keep track of number of generated entries and generate a dummy
241 # if needs be to ensure the expanded template can be postprocessed
243 my $section_counter = 0;
249 # 1 - looking for function name
250 # 2 - scanning field start.
251 # 3 - scanning prototype.
252 # 4 - documentation block
255 #declaration types: can be
256 # 'function', 'struct', 'union', 'enum', 'typedef'
259 my $doc_special = "\@\%\$\&";
261 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
263 my $doc_com = '\s*\*\s*';
264 my $doc_decl = $doc_com.'(\w+)';
265 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w ]+):(.*)';
266 my $doc_content = $doc_com.'(.*)';
267 my $doc_block = $doc_com.'DOC:\s*(.*)?';
276 my $section_default = "Description"; # default section
277 my $section_intro = "Introduction";
278 my $section = $section_default;
279 my $section_context = "Context";
281 my $undescribed = "-- undescribed --";
285 while ($ARGV[0] =~ m/^-(.*)/) {
286 my $cmd = shift @ARGV;
287 if ($cmd eq "-html") {
288 $output_mode = "html";
289 %highlights = %highlights_html;
290 $blankline = $blankline_html;
291 } elsif ($cmd eq "-man") {
292 $output_mode = "man";
293 %highlights = %highlights_man;
294 $blankline = $blankline_man;
295 } elsif ($cmd eq "-text") {
296 $output_mode = "text";
297 %highlights = %highlights_text;
298 $blankline = $blankline_text;
299 } elsif ($cmd eq "-docbook") {
300 $output_mode = "xml";
301 %highlights = %highlights_xml;
302 $blankline = $blankline_xml;
303 } elsif ($cmd eq "-gnome") {
304 $output_mode = "gnome";
305 %highlights = %highlights_gnome;
306 $blankline = $blankline_gnome;
307 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
308 $modulename = shift @ARGV;
309 } elsif ($cmd eq "-function") { # to only output specific functions
311 $function = shift @ARGV;
312 $function_table{$function} = 1;
313 } elsif ($cmd eq "-nofunction") { # to only output specific functions
315 $function = shift @ARGV;
316 $function_table{$function} = 1;
317 } elsif ($cmd eq "-v") {
319 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
321 } elsif ($cmd eq '-filelist') {
322 $filelist = shift @ARGV;
327 # generate a sequence of code that will splice in highlighting information
328 # using the s// operator.
329 my $dohighlight = "";
330 foreach my $pattern (keys %highlights) {
331 # print "scanning pattern $pattern ($highlights{$pattern})\n";
332 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
336 # dumps section contents to arrays/hashes intended for that purpose.
340 my $contents = join "\n", @_;
342 if ($name =~ m/$type_constant/) {
344 # print STDERR "constant section '$1' = '$contents'\n";
345 $constants{$name} = $contents;
346 } elsif ($name =~ m/$type_param/) {
347 # print STDERR "parameter def '$1' = '$contents'\n";
349 $parameterdescs{$name} = $contents;
351 # print STDERR "other section '$name' = '$contents'\n";
352 $sections{$name} = $contents;
353 push @sectionlist, $name;
360 # parameterdescs, a hash.
361 # function => "function name"
362 # parameterlist => @list of parameters
363 # parameterdescs => %parameter descriptions
364 # sectionlist => @list of sections
365 # sections => %descriont descriptions
368 sub output_highlight
{
369 my $contents = join "\n",@_;
373 # if (!defined $contents) {
375 # confess "output_highlight got called with no args?\n";
380 foreach $line (split "\n", $contents) {
382 print $lineprefix, $blankline;
384 $line =~ s/\\\\\\/\&/g;
385 print $lineprefix, $line;
391 #output sections in html
392 sub output_section_html
(%) {
396 foreach $section (@
{$args{'sectionlist'}}) {
397 print "<h3>$section</h3>\n";
398 print "<blockquote>\n";
399 output_highlight
($args{'sections'}{$section});
400 print "</blockquote>\n";
404 # output enum in html
405 sub output_enum_html
(%) {
409 print "<h2>enum ".$args{'enum'}."</h2>\n";
411 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
413 foreach $parameter (@
{$args{'parameterlist'}}) {
414 print " <b>".$parameter."</b>";
415 if ($count != $#{$args{'parameterlist'}}) {
423 print "<h3>Constants</h3>\n";
425 foreach $parameter (@
{$args{'parameterlist'}}) {
426 print "<dt><b>".$parameter."</b>\n";
428 output_highlight
($args{'parameterdescs'}{$parameter});
431 output_section_html
(@_);
435 # output tyepdef in html
436 sub output_typedef_html
(%) {
440 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
442 print "<b>typedef ".$args{'typedef'}."</b>\n";
443 output_section_html
(@_);
447 # output struct in html
448 sub output_struct_html
(%) {
452 print "<h2>".$args{'type'}." ".$args{'struct'}."</h2>\n";
453 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
454 foreach $parameter (@
{$args{'parameterlist'}}) {
455 if ($parameter =~ /^#/) {
456 print "$parameter<br>\n";
459 my $parameter_name = $parameter;
460 $parameter_name =~ s/\[.*//;
462 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
463 $type = $args{'parametertypes'}{$parameter};
464 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
465 # pointer-to-function
466 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
467 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
468 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
470 print " <i>$type</i> <b>$parameter</b>;<br>\n";
475 print "<h3>Members</h3>\n";
477 foreach $parameter (@
{$args{'parameterlist'}}) {
478 ($parameter =~ /^#/) && next;
480 my $parameter_name = $parameter;
481 $parameter_name =~ s/\[.*//;
483 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
484 print "<dt><b>".$parameter."</b>\n";
486 output_highlight
($args{'parameterdescs'}{$parameter_name});
489 output_section_html
(@_);
493 # output function in html
494 sub output_function_html
(%) {
496 my ($parameter, $section);
498 print "<h2>Function</h2>\n";
500 print "<i>".$args{'functiontype'}."</i>\n";
501 print "<b>".$args{'function'}."</b>\n";
504 foreach $parameter (@
{$args{'parameterlist'}}) {
505 $type = $args{'parametertypes'}{$parameter};
506 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
507 # pointer-to-function
508 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
510 print "<i>".$type."</i> <b>".$parameter."</b>";
512 if ($count != $#{$args{'parameterlist'}}) {
519 print "<h3>Arguments</h3>\n";
521 foreach $parameter (@
{$args{'parameterlist'}}) {
522 my $parameter_name = $parameter;
523 $parameter_name =~ s/\[.*//;
525 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
526 print "<dt><b>".$parameter."</b>\n";
528 output_highlight
($args{'parameterdescs'}{$parameter_name});
531 output_section_html
(@_);
535 # output intro in html
536 sub output_intro_html
(%) {
538 my ($parameter, $section);
541 foreach $section (@
{$args{'sectionlist'}}) {
542 print "<h3>$section</h3>\n";
544 output_highlight
($args{'sections'}{$section});
550 sub output_section_xml
(%) {
553 # print out each section
555 foreach $section (@
{$args{'sectionlist'}}) {
556 print "<refsect1>\n";
557 print "<title>$section</title>\n";
558 if ($section =~ m/EXAMPLE/i) {
559 print "<informalexample><programlisting>\n";
563 output_highlight
($args{'sections'}{$section});
564 if ($section =~ m/EXAMPLE/i) {
565 print "</programlisting></informalexample>\n";
569 print "</refsect1>\n";
573 # output function in XML DocBook
574 sub output_function_xml
(%) {
576 my ($parameter, $section);
580 $id = "API-".$args{'function'};
581 $id =~ s/[^A-Za-z0-9]/-/g;
583 print "<refentry>\n";
584 print "<refentryinfo>\n";
585 print " <title>LINUX</title>\n";
586 print " <productname>Kernel Hackers Manual</productname>\n";
587 print " <date>$man_date</date>\n";
588 print "</refentryinfo>\n";
590 print " <refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
591 print " <manvolnum>9</manvolnum>\n";
592 print "</refmeta>\n";
593 print "<refnamediv>\n";
594 print " <refname>".$args{'function'}."</refname>\n";
595 print " <refpurpose>\n";
597 output_highlight
($args{'purpose'});
598 print " </refpurpose>\n";
599 print "</refnamediv>\n";
601 print "<refsynopsisdiv>\n";
602 print " <title>Synopsis</title>\n";
603 print " <funcsynopsis><funcprototype>\n";
604 print " <funcdef>".$args{'functiontype'}." ";
605 print "<function>".$args{'function'}." </function></funcdef>\n";
608 if ($#{$args{'parameterlist'}} >= 0) {
609 foreach $parameter (@
{$args{'parameterlist'}}) {
610 $type = $args{'parametertypes'}{$parameter};
611 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
612 # pointer-to-function
613 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
614 print " <funcparams>$2</funcparams></paramdef>\n";
616 print " <paramdef>".$type;
617 print " <parameter>$parameter</parameter></paramdef>\n";
623 print " </funcprototype></funcsynopsis>\n";
624 print "</refsynopsisdiv>\n";
627 print "<refsect1>\n <title>Arguments</title>\n";
628 if ($#{$args{'parameterlist'}} >= 0) {
629 print " <variablelist>\n";
630 foreach $parameter (@
{$args{'parameterlist'}}) {
631 my $parameter_name = $parameter;
632 $parameter_name =~ s/\[.*//;
634 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
635 print " <listitem>\n <para>\n";
637 output_highlight
($args{'parameterdescs'}{$parameter_name});
638 print " </para>\n </listitem>\n </varlistentry>\n";
640 print " </variablelist>\n";
642 print " <para>\n None\n </para>\n";
644 print "</refsect1>\n";
646 output_section_xml
(@_);
647 print "</refentry>\n\n";
650 # output struct in XML DocBook
651 sub output_struct_xml
(%) {
653 my ($parameter, $section);
656 $id = "API-struct-".$args{'struct'};
657 $id =~ s/[^A-Za-z0-9]/-/g;
659 print "<refentry>\n";
660 print "<refentryinfo>\n";
661 print " <title>LINUX</title>\n";
662 print " <productname>Kernel Hackers Manual</productname>\n";
663 print " <date>$man_date</date>\n";
664 print "</refentryinfo>\n";
666 print " <refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
667 print " <manvolnum>9</manvolnum>\n";
668 print "</refmeta>\n";
669 print "<refnamediv>\n";
670 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
671 print " <refpurpose>\n";
673 output_highlight
($args{'purpose'});
674 print " </refpurpose>\n";
675 print "</refnamediv>\n";
677 print "<refsynopsisdiv>\n";
678 print " <title>Synopsis</title>\n";
679 print " <programlisting>\n";
680 print $args{'type'}." ".$args{'struct'}." {\n";
681 foreach $parameter (@
{$args{'parameterlist'}}) {
682 if ($parameter =~ /^#/) {
683 print "$parameter\n";
687 my $parameter_name = $parameter;
688 $parameter_name =~ s/\[.*//;
690 defined($args{'parameterdescs'}{$parameter_name}) || next;
691 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
692 $type = $args{'parametertypes'}{$parameter};
693 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
694 # pointer-to-function
695 print " $1 $parameter) ($2);\n";
696 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
697 print " $1 $parameter$2;\n";
699 print " ".$type." ".$parameter.";\n";
703 print " </programlisting>\n";
704 print "</refsynopsisdiv>\n";
706 print " <refsect1>\n";
707 print " <title>Members</title>\n";
709 print " <variablelist>\n";
710 foreach $parameter (@
{$args{'parameterlist'}}) {
711 ($parameter =~ /^#/) && next;
713 my $parameter_name = $parameter;
714 $parameter_name =~ s/\[.*//;
716 defined($args{'parameterdescs'}{$parameter_name}) || next;
717 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
718 print " <varlistentry>";
719 print " <term>$parameter</term>\n";
720 print " <listitem><para>\n";
721 output_highlight
($args{'parameterdescs'}{$parameter_name});
722 print " </para></listitem>\n";
723 print " </varlistentry>\n";
725 print " </variablelist>\n";
726 print " </refsect1>\n";
728 output_section_xml
(@_);
730 print "</refentry>\n\n";
733 # output enum in XML DocBook
734 sub output_enum_xml
(%) {
736 my ($parameter, $section);
740 $id = "API-enum-".$args{'enum'};
741 $id =~ s/[^A-Za-z0-9]/-/g;
743 print "<refentry>\n";
744 print "<refentryinfo>\n";
745 print " <title>LINUX</title>\n";
746 print " <productname>Kernel Hackers Manual</productname>\n";
747 print " <date>$man_date</date>\n";
748 print "</refentryinfo>\n";
750 print " <refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n";
751 print " <manvolnum>9</manvolnum>\n";
752 print "</refmeta>\n";
753 print "<refnamediv>\n";
754 print " <refname>enum ".$args{'enum'}."</refname>\n";
755 print " <refpurpose>\n";
757 output_highlight
($args{'purpose'});
758 print " </refpurpose>\n";
759 print "</refnamediv>\n";
761 print "<refsynopsisdiv>\n";
762 print " <title>Synopsis</title>\n";
763 print " <programlisting>\n";
764 print "enum ".$args{'enum'}." {\n";
766 foreach $parameter (@
{$args{'parameterlist'}}) {
768 if ($count != $#{$args{'parameterlist'}}) {
775 print " </programlisting>\n";
776 print "</refsynopsisdiv>\n";
778 print "<refsect1>\n";
779 print " <title>Constants</title>\n";
780 print " <variablelist>\n";
781 foreach $parameter (@
{$args{'parameterlist'}}) {
782 my $parameter_name = $parameter;
783 $parameter_name =~ s/\[.*//;
785 print " <varlistentry>";
786 print " <term>$parameter</term>\n";
787 print " <listitem><para>\n";
788 output_highlight
($args{'parameterdescs'}{$parameter_name});
789 print " </para></listitem>\n";
790 print " </varlistentry>\n";
792 print " </variablelist>\n";
793 print "</refsect1>\n";
795 output_section_xml
(@_);
797 print "</refentry>\n\n";
800 # output typedef in XML DocBook
801 sub output_typedef_xml
(%) {
803 my ($parameter, $section);
806 $id = "API-typedef-".$args{'typedef'};
807 $id =~ s/[^A-Za-z0-9]/-/g;
809 print "<refentry>\n";
810 print "<refentryinfo>\n";
811 print " <title>LINUX</title>\n";
812 print " <productname>Kernel Hackers Manual</productname>\n";
813 print " <date>$man_date</date>\n";
814 print "</refentryinfo>\n";
816 print " <refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
817 print " <manvolnum>9</manvolnum>\n";
818 print "</refmeta>\n";
819 print "<refnamediv>\n";
820 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
821 print " <refpurpose>\n";
823 output_highlight
($args{'purpose'});
824 print " </refpurpose>\n";
825 print "</refnamediv>\n";
827 print "<refsynopsisdiv>\n";
828 print " <title>Synopsis</title>\n";
829 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
830 print "</refsynopsisdiv>\n";
832 output_section_xml
(@_);
834 print "</refentry>\n\n";
837 # output in XML DocBook
838 sub output_intro_xml
(%) {
840 my ($parameter, $section);
843 my $id = $args{'module'};
844 $id =~ s/[^A-Za-z0-9]/-/g;
846 # print out each section
848 foreach $section (@
{$args{'sectionlist'}}) {
849 print "<refsect1>\n <title>$section</title>\n <para>\n";
850 if ($section =~ m/EXAMPLE/i) {
851 print "<example><para>\n";
853 output_highlight
($args{'sections'}{$section});
854 if ($section =~ m/EXAMPLE/i) {
855 print "</para></example>\n";
857 print " </para>\n</refsect1>\n";
863 # output in XML DocBook
864 sub output_function_gnome
{
866 my ($parameter, $section);
870 $id = $args{'module'}."-".$args{'function'};
871 $id =~ s/[^A-Za-z0-9]/-/g;
874 print " <title id=\"$id\">".$args{'function'}."</title>\n";
876 print " <funcsynopsis>\n";
877 print " <funcdef>".$args{'functiontype'}." ";
878 print "<function>".$args{'function'}." ";
879 print "</function></funcdef>\n";
882 if ($#{$args{'parameterlist'}} >= 0) {
883 foreach $parameter (@
{$args{'parameterlist'}}) {
884 $type = $args{'parametertypes'}{$parameter};
885 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
886 # pointer-to-function
887 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
888 print " <funcparams>$2</funcparams></paramdef>\n";
890 print " <paramdef>".$type;
891 print " <parameter>$parameter</parameter></paramdef>\n";
897 print " </funcsynopsis>\n";
898 if ($#{$args{'parameterlist'}} >= 0) {
899 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
900 print "<tgroup cols=\"2\">\n";
901 print "<colspec colwidth=\"2*\">\n";
902 print "<colspec colwidth=\"8*\">\n";
904 foreach $parameter (@
{$args{'parameterlist'}}) {
905 my $parameter_name = $parameter;
906 $parameter_name =~ s/\[.*//;
908 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
911 output_highlight
($args{'parameterdescs'}{$parameter_name});
912 print " </entry></row>\n";
914 print " </tbody></tgroup></informaltable>\n";
916 print " <para>\n None\n </para>\n";
919 # print out each section
921 foreach $section (@
{$args{'sectionlist'}}) {
922 print "<simplesect>\n <title>$section</title>\n";
923 if ($section =~ m/EXAMPLE/i) {
924 print "<example><programlisting>\n";
928 output_highlight
($args{'sections'}{$section});
930 if ($section =~ m/EXAMPLE/i) {
931 print "</programlisting></example>\n";
934 print " </simplesect>\n";
937 print "</sect2>\n\n";
941 # output function in man
942 sub output_function_man
(%) {
944 my ($parameter, $section);
947 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
950 print $args{'function'}." \\- ".$args{'purpose'}."\n";
952 print ".SH SYNOPSIS\n";
953 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
957 foreach my $parameter (@
{$args{'parameterlist'}}) {
958 if ($count == $#{$args{'parameterlist'}}) {
961 $type = $args{'parametertypes'}{$parameter};
962 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
963 # pointer-to-function
964 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
966 $type =~ s/([^\*])$/$1 /;
967 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
973 print ".SH ARGUMENTS\n";
974 foreach $parameter (@
{$args{'parameterlist'}}) {
975 my $parameter_name = $parameter;
976 $parameter_name =~ s/\[.*//;
978 print ".IP \"".$parameter."\" 12\n";
979 output_highlight
($args{'parameterdescs'}{$parameter_name});
981 foreach $section (@
{$args{'sectionlist'}}) {
982 print ".SH \"", uc $section, "\"\n";
983 output_highlight
($args{'sections'}{$section});
989 sub output_enum_man
(%) {
991 my ($parameter, $section);
994 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
997 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
999 print ".SH SYNOPSIS\n";
1000 print "enum ".$args{'enum'}." {\n";
1002 foreach my $parameter (@
{$args{'parameterlist'}}) {
1003 print ".br\n.BI \" $parameter\"\n";
1004 if ($count == $#{$args{'parameterlist'}}) {
1014 print ".SH Constants\n";
1015 foreach $parameter (@
{$args{'parameterlist'}}) {
1016 my $parameter_name = $parameter;
1017 $parameter_name =~ s/\[.*//;
1019 print ".IP \"".$parameter."\" 12\n";
1020 output_highlight
($args{'parameterdescs'}{$parameter_name});
1022 foreach $section (@
{$args{'sectionlist'}}) {
1023 print ".SH \"$section\"\n";
1024 output_highlight
($args{'sections'}{$section});
1029 # output struct in man
1030 sub output_struct_man
(%) {
1031 my %args = %{$_[0]};
1032 my ($parameter, $section);
1034 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1037 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1039 print ".SH SYNOPSIS\n";
1040 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1042 foreach my $parameter (@
{$args{'parameterlist'}}) {
1043 if ($parameter =~ /^#/) {
1044 print ".BI \"$parameter\"\n.br\n";
1047 my $parameter_name = $parameter;
1048 $parameter_name =~ s/\[.*//;
1050 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1051 $type = $args{'parametertypes'}{$parameter};
1052 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1053 # pointer-to-function
1054 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1055 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1056 print ".BI \" ".$1."\" ".$parameter.$2." \""."\"\n;\n";
1058 $type =~ s/([^\*])$/$1 /;
1059 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1065 print ".SH Arguments\n";
1066 foreach $parameter (@
{$args{'parameterlist'}}) {
1067 ($parameter =~ /^#/) && next;
1069 my $parameter_name = $parameter;
1070 $parameter_name =~ s/\[.*//;
1072 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1073 print ".IP \"".$parameter."\" 12\n";
1074 output_highlight
($args{'parameterdescs'}{$parameter_name});
1076 foreach $section (@
{$args{'sectionlist'}}) {
1077 print ".SH \"$section\"\n";
1078 output_highlight
($args{'sections'}{$section});
1083 # output typedef in man
1084 sub output_typedef_man
(%) {
1085 my %args = %{$_[0]};
1086 my ($parameter, $section);
1088 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1091 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1093 foreach $section (@
{$args{'sectionlist'}}) {
1094 print ".SH \"$section\"\n";
1095 output_highlight
($args{'sections'}{$section});
1099 sub output_intro_man
(%) {
1100 my %args = %{$_[0]};
1101 my ($parameter, $section);
1104 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1106 foreach $section (@
{$args{'sectionlist'}}) {
1107 print ".SH \"$section\"\n";
1108 output_highlight
($args{'sections'}{$section});
1114 sub output_function_text
(%) {
1115 my %args = %{$_[0]};
1116 my ($parameter, $section);
1118 print "Function:\n\n";
1119 my $start=$args{'functiontype'}." ".$args{'function'}." (";
1122 foreach my $parameter (@
{$args{'parameterlist'}}) {
1123 $type = $args{'parametertypes'}{$parameter};
1124 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1125 # pointer-to-function
1126 print $1.$parameter.") (".$2;
1128 print $type." ".$parameter;
1130 if ($count != $#{$args{'parameterlist'}}) {
1133 print " " x
length($start);
1139 print "Arguments:\n\n";
1140 foreach $parameter (@
{$args{'parameterlist'}}) {
1141 my $parameter_name = $parameter;
1142 $parameter_name =~ s/\[.*//;
1144 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1146 output_section_text
(@_);
1149 #output sections in text
1150 sub output_section_text
(%) {
1151 my %args = %{$_[0]};
1155 foreach $section (@
{$args{'sectionlist'}}) {
1156 print "$section:\n\n";
1157 output_highlight
($args{'sections'}{$section});
1162 # output enum in text
1163 sub output_enum_text
(%) {
1164 my %args = %{$_[0]};
1169 print "enum ".$args{'enum'}." {\n";
1171 foreach $parameter (@
{$args{'parameterlist'}}) {
1172 print "\t$parameter";
1173 if ($count != $#{$args{'parameterlist'}}) {
1181 print "Constants:\n\n";
1182 foreach $parameter (@
{$args{'parameterlist'}}) {
1183 print "$parameter\n\t";
1184 print $args{'parameterdescs'}{$parameter}."\n";
1187 output_section_text
(@_);
1190 # output typedef in text
1191 sub output_typedef_text
(%) {
1192 my %args = %{$_[0]};
1195 print "Typedef:\n\n";
1197 print "typedef ".$args{'typedef'}."\n";
1198 output_section_text
(@_);
1201 # output struct as text
1202 sub output_struct_text
(%) {
1203 my %args = %{$_[0]};
1206 print $args{'type'}." ".$args{'struct'}.":\n\n";
1207 print $args{'type'}." ".$args{'struct'}." {\n";
1208 foreach $parameter (@
{$args{'parameterlist'}}) {
1209 if ($parameter =~ /^#/) {
1210 print "$parameter\n";
1214 my $parameter_name = $parameter;
1215 $parameter_name =~ s/\[.*//;
1217 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1218 $type = $args{'parametertypes'}{$parameter};
1219 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1220 # pointer-to-function
1221 print "\t$1 $parameter) ($2);\n";
1222 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1223 print "\t$1 $parameter$2;\n";
1225 print "\t".$type." ".$parameter.";\n";
1230 print "Members:\n\n";
1231 foreach $parameter (@
{$args{'parameterlist'}}) {
1232 ($parameter =~ /^#/) && next;
1234 my $parameter_name = $parameter;
1235 $parameter_name =~ s/\[.*//;
1237 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1238 print "$parameter\n\t";
1239 print $args{'parameterdescs'}{$parameter_name}."\n";
1242 output_section_text
(@_);
1245 sub output_intro_text
(%) {
1246 my %args = %{$_[0]};
1247 my ($parameter, $section);
1249 foreach $section (@
{$args{'sectionlist'}}) {
1250 print " $section:\n";
1252 output_highlight
($args{'sections'}{$section});
1257 # generic output function for typedefs
1258 sub output_declaration
{
1261 my $functype = shift;
1262 my $func = "output_${functype}_$output_mode";
1263 if (($function_only==0) ||
1264 ( $function_only == 1 && defined($function_table{$name})) ||
1265 ( $function_only == 2 && !defined($function_table{$name})))
1273 # generic output function - calls the right one based
1274 # on current output mode.
1277 my $func = "output_intro_".$output_mode;
1283 # takes a declaration (struct, union, enum, typedef) and
1284 # invokes the right handler. NOT called for functions.
1285 sub dump_declaration
($$) {
1287 my ($prototype, $file) = @_;
1288 my $func = "dump_".$decl_type;
1292 sub dump_union
($$) {
1296 sub dump_struct
($$) {
1300 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1301 $declaration_name = $2;
1304 # ignore embedded structs or unions
1305 $members =~ s/{.*?}//g;
1307 create_parameterlist
($members, ';', $file);
1309 output_declaration
($declaration_name,
1311 {'struct' => $declaration_name,
1312 'module' => $modulename,
1313 'parameterlist' => \
@parameterlist,
1314 'parameterdescs' => \
%parameterdescs,
1315 'parametertypes' => \
%parametertypes,
1316 'sectionlist' => \
@sectionlist,
1317 'sections' => \
%sections,
1318 'purpose' => $declaration_purpose,
1319 'type' => $decl_type
1323 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1332 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1333 $declaration_name = $1;
1336 foreach my $arg (split ',', $members) {
1337 $arg =~ s/^\s*(\w+).*/$1/;
1338 push @parameterlist, $arg;
1339 if (!$parameterdescs{$arg}) {
1340 $parameterdescs{$arg} = $undescribed;
1341 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1342 "not described in enum '$declaration_name'\n";
1347 output_declaration
($declaration_name,
1349 {'enum' => $declaration_name,
1350 'module' => $modulename,
1351 'parameterlist' => \
@parameterlist,
1352 'parameterdescs' => \
%parameterdescs,
1353 'sectionlist' => \
@sectionlist,
1354 'sections' => \
%sections,
1355 'purpose' => $declaration_purpose
1359 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1364 sub dump_typedef
($$) {
1368 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1369 $x =~ s/\(*.\)\s*;$/;/;
1370 $x =~ s/\[*.\]\s*;$/;/;
1373 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1374 $declaration_name = $1;
1376 output_declaration
($declaration_name,
1378 {'typedef' => $declaration_name,
1379 'module' => $modulename,
1380 'sectionlist' => \
@sectionlist,
1381 'sections' => \
%sections,
1382 'purpose' => $declaration_purpose
1386 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1391 sub create_parameterlist
($$$) {
1393 my $splitter = shift;
1398 while ($args =~ /(\([^\),]+),/) {
1399 $args =~ s/(\([^\),]+),/$1#/g;
1402 foreach my $arg (split($splitter, $args)) {
1404 $arg =~ s/\/\*.*\*\///;
1405 # strip leading/trailing spaces
1411 # Treat preprocessor directive as a typeless variable just to fill
1412 # corresponding data structures "correctly". Catch it later in
1414 push_parameter
($arg, "", $file);
1415 } elsif ($arg =~ m/\(/) {
1416 # pointer-to-function
1418 $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
1421 $type =~ s/([^\(]+\(\*)$param/$1/;
1422 push_parameter
($param, $type, $file);
1424 $arg =~ s/\s*:\s*/:/g;
1425 $arg =~ s/\s*\[/\[/g;
1427 my @args = split('\s*,\s*', $arg);
1428 if ($args[0] =~ m/\*/) {
1429 $args[0] =~ s/(\*+)\s*/ $1/;
1431 my @first_arg = split('\s+', shift @args);
1432 unshift(@args, pop @first_arg);
1433 $type = join " ", @first_arg;
1435 foreach $param (@args) {
1436 if ($param =~ m/^(\*+)\s*(.*)/) {
1437 push_parameter
($2, "$type $1", $file);
1439 elsif ($param =~ m/(.*?):(\d+)/) {
1440 push_parameter
($1, "$type:$2", $file)
1443 push_parameter
($param, $type, $file);
1450 sub push_parameter
($$$) {
1455 my $param_name = $param;
1456 $param_name =~ s/\[.*//;
1458 if ($type eq "" && $param eq "...")
1462 $parameterdescs{"..."} = "variable arguments";
1464 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1468 $parameterdescs{void
} = "no arguments";
1470 if (defined $type && $type && !defined $parameterdescs{$param_name}) {
1471 $parameterdescs{$param_name} = $undescribed;
1473 if (($type eq 'function') || ($type eq 'enum')) {
1474 print STDERR
"Warning(${file}:$.): Function parameter ".
1475 "or member '$param' not " .
1476 "described in '$declaration_name'\n";
1478 print STDERR
"Warning(${file}:$.):".
1479 " No description found for parameter '$param'\n";
1483 push @parameterlist, $param;
1484 $parametertypes{$param} = $type;
1488 # takes a function prototype and the name of the current file being
1489 # processed and spits out all the details stored in the global
1491 sub dump_function
($$) {
1492 my $prototype = shift;
1495 $prototype =~ s/^static +//;
1496 $prototype =~ s/^extern +//;
1497 $prototype =~ s/^fastcall +//;
1498 $prototype =~ s/^asmlinkage +//;
1499 $prototype =~ s/^inline +//;
1500 $prototype =~ s/^__inline__ +//;
1501 $prototype =~ s/^#define +//; #ak added
1502 $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//;
1504 # Yes, this truly is vile. We are looking for:
1505 # 1. Return type (may be nothing if we're looking at a macro)
1507 # 3. Function parameters.
1509 # All the while we have to watch out for function pointer parameters
1510 # (which IIRC is what the two sections are for), C types (these
1511 # regexps don't even start to express all the possibilities), and
1514 # If you mess with these regexps, it's a good idea to check that
1515 # the following functions' documentation still comes out right:
1516 # - parport_register_device (function pointer parameters)
1517 # - atomic_set (macro)
1518 # - pci_match_device (long return type)
1520 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1521 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1522 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1523 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1524 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1525 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1526 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1527 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1528 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1529 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1530 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1531 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1532 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1533 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1535 $declaration_name = $2;
1538 create_parameterlist
($args, ',', $file);
1540 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1545 output_declaration
($declaration_name,
1547 {'function' => $declaration_name,
1548 'module' => $modulename,
1549 'functiontype' => $return_type,
1550 'parameterlist' => \
@parameterlist,
1551 'parameterdescs' => \
%parameterdescs,
1552 'parametertypes' => \
%parametertypes,
1553 'sectionlist' => \
@sectionlist,
1554 'sections' => \
%sections,
1555 'purpose' => $declaration_purpose
1559 sub process_file
($);
1561 # Read the file that maps relative names to absolute names for
1562 # separate source and object directories and for shadow trees.
1563 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
1564 my ($relname, $absname);
1565 while(<SOURCE_MAP
>) {
1567 ($relname, $absname) = (split())[0..1];
1568 $relname =~ s
:^/+::;
1569 $source_map{$relname} = $absname;
1575 open(FLIST
,"<$filelist") or die "Can't open file list $filelist";
1586 if ($verbose && $errors) {
1587 print STDERR
"$errors errors\n";
1589 if ($verbose && $warnings) {
1590 print STDERR
"$warnings warnings\n";
1598 %parameterdescs = ();
1599 %parametertypes = ();
1600 @parameterlist = ();
1608 sub process_state3_function
($$) {
1612 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1615 elsif ($x =~ /([^\{]*)/) {
1618 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1619 $prototype =~ s@
/\*.*?\*/@
@gos; # strip comments.
1620 $prototype =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1621 $prototype =~ s@
^\s
+@
@gos; # strip leading spaces
1622 dump_function
($prototype,$file);
1627 sub process_state3_type
($$) {
1631 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1632 $x =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1633 $x =~ s@
^\s
+@
@gos; # strip leading spaces
1634 $x =~ s@\s
+$@
@gos; # strip trailing spaces
1636 # To distinguish preprocessor directive from regular declaration later.
1641 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1642 $prototype .= $1 . $2;
1643 ($2 eq '{') && $brcount++;
1644 ($2 eq '}') && $brcount--;
1645 if (($2 eq ';') && ($brcount == 0)) {
1646 dump_declaration
($prototype,$file);
1658 # replace <, >, and &
1661 $text =~ s/\&/\\\\\\amp;/g;
1662 $text =~ s/\</\\\\\\lt;/g;
1663 $text =~ s/\>/\\\\\\gt;/g;
1667 sub process_file
($) {
1671 my $initial_section_counter = $section_counter;
1673 if (defined($ENV{'SRCTREE'})) {
1674 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1679 if (defined($source_map{$file})) {
1680 $file = $source_map{$file};
1683 if (!open(IN
,"<$file")) {
1684 print STDERR
"Error: Cannot open file $file\n";
1689 $section_counter = 0;
1692 if (/$doc_start/o) {
1693 $state = 1; # next line is always the function name
1695 } elsif ($state == 1) { # this line is the function name (always)
1696 if (/$doc_block/o) {
1700 $section = $section_intro;
1705 elsif (/$doc_decl/o) {
1707 if (/\s*([\w\s]+?)\s*-/) {
1713 $declaration_purpose = xml_escape
($1);
1715 $declaration_purpose = "";
1717 if ($identifier =~ m/^struct/) {
1718 $decl_type = 'struct';
1719 } elsif ($identifier =~ m/^union/) {
1720 $decl_type = 'union';
1721 } elsif ($identifier =~ m/^enum/) {
1722 $decl_type = 'enum';
1723 } elsif ($identifier =~ m/^typedef/) {
1724 $decl_type = 'typedef';
1726 $decl_type = 'function';
1730 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
1733 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
1734 " - I thought it was a doc line\n";
1738 } elsif ($state == 2) { # look for head: lines, and include content
1743 if ($contents ne "") {
1744 dump_section
($section, xml_escape
($contents));
1745 $section = $section_default;
1748 $contents = $newcontents;
1749 if ($contents ne "") {
1752 $section = $newsection;
1753 } elsif (/$doc_end/) {
1755 if ($contents ne "") {
1756 dump_section
($section, xml_escape
($contents));
1757 $section = $section_default;
1764 # print STDERR "end of doc comment, looking for prototype\n";
1765 } elsif (/$doc_content/) {
1766 # miguel-style comment kludge, look for blank lines after
1767 # @parameter line to signify start of description
1769 ($section =~ m/^@/ || $section eq $section_context)) {
1770 dump_section
($section, xml_escape
($contents));
1771 $section = $section_default;
1774 $contents .= $1."\n";
1777 # i dont know - bad line? ignore.
1778 print STDERR
"Warning(${file}:$.): bad line: $_";
1781 } elsif ($state == 3) { # scanning for function { (end of prototype)
1782 if ($decl_type eq 'function') {
1783 process_state3_function
($_, $file);
1785 process_state3_type
($_, $file);
1787 } elsif ($state == 4) {
1788 # Documentation block
1790 dump_section
($section, $contents);
1791 output_intro
({'sectionlist' => \
@sectionlist,
1792 'sections' => \
%sections });
1796 %parameterdescs = ();
1797 %parametertypes = ();
1798 @parameterlist = ();
1803 $section = $section_intro;
1810 dump_section
($section, $contents);
1811 output_intro
({'sectionlist' => \
@sectionlist,
1812 'sections' => \
%sections });
1816 %parameterdescs = ();
1817 %parametertypes = ();
1818 @parameterlist = ();
1824 elsif (/$doc_content/)
1828 $contents .= $blankline;
1832 $contents .= $1 . "\n";
1837 if ($initial_section_counter == $section_counter) {
1838 print STDERR
"Warning(${file}): no structured comments found\n";
1839 if ($output_mode eq "xml") {
1840 # The template wants at least one RefEntry here; make one.
1841 print "<refentry>\n";
1842 print " <refnamediv>\n";
1843 print " <refname>\n";
1845 print " </refname>\n";
1846 print " <refpurpose>\n";
1847 print " Document generation inconsistency\n";
1848 print " </refpurpose>\n";
1849 print " </refnamediv>\n";
1850 print " <refsect1>\n";
1853 print " </title>\n";
1854 print " <warning>\n";
1856 print " The template for this document tried to insert\n";
1857 print " the structured comment from the file\n";
1858 print " <filename>${file}</filename> at this point,\n";
1859 print " but none was found.\n";
1860 print " This dummy section is inserted to allow\n";
1861 print " generation to continue.\n";
1863 print " </warning>\n";
1864 print " </refsect1>\n";
1865 print "</refentry>\n";