[PATCH] freepgt: mpnt to vma cleanup
[linux-2.6.22.y-op.git] / scripts / kernel-doc
blob8b1dab63f11cafb2467b2f430e68964b198371d3
1 #!/usr/bin/perl -w
3 use strict;
5 ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
6 ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7 ## Copyright (C) 2001 Simon Huggins ##
8 ## ##
9 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
10 ## Copyright (c) 2000 MontaVista Software, Inc. ##
11 ## ##
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.
20 # -- huggie@earth.li
22 # 27/06/2001 - Allowed whitespace after initial "/**" and
23 # allowed comments before function declarations.
24 # -- Christian Kreibich <ck@whoop.org>
26 # Still to do:
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.
31 # Return error code.
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'.
47 # usage:
48 # kerneldoc [ -docbook | -html | -text | -man ]
49 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
50 # or
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.
55 # -function funcname
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.
69 # format of comments.
70 # In the following table, (...)? signifies optional structure.
71 # (...)* signifies 0 or more structure elements
72 # /**
73 # * function_name(:)? (- short description)?
74 # (* @parameterx: (description of parameter x)?)*
75 # (* a blank line)?
76 # * (Description:)? (Description of function)?
77 # * (section header: (section description)? )*
78 # (*)?*/
80 # So .. the trivial example would be:
82 # /**
83 # * my_function
84 # **/
86 # If the Description: header tag is ommitted, then there must be a blank line
87 # after the last parameter specification.
88 # e.g.
89 # /**
90 # * my_function - does my stuff
91 # * @my_arg: its mine damnit
92 # *
93 # * Does my stuff explained.
94 # */
96 # or, could also use:
97 # /**
98 # * my_function - does my stuff
99 # * @my_arg: its mine damnit
100 # * Description: Does my stuff explained.
101 # */
102 # etc.
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.
109 # e.g.
110 # /**
111 # * struct my_struct - short description
112 # * @a: first member
113 # * @b: second member
114 # *
115 # * Longer description
116 # */
117 # struct my_struct {
118 # int a;
119 # int b;
120 # };
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
127 # empty line.
128 # Example-sections should contain the string EXAMPLE so that they are marked
129 # appropriately in DocBook.
131 # Example:
132 # /**
133 # * user_function - function that can only be called in user context
134 # * @a: some argument
135 # * Context: !in_interrupt()
136 # *
137 # * Some description
138 # * Example:
139 # * user_function(22);
140 # */
141 # ...
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.
153 my $errors = 0;
154 my $warnings = 0;
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 = "";
197 # text-mode
198 my %highlights_text = ( $type_constant, "\$1",
199 $type_func, "\$1",
200 $type_struct, "\$1",
201 $type_param, "\$1" );
202 my $blankline_text = "";
205 sub usage {
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";
210 exit 1;
213 # read arguments
214 if ($#ARGV==-1) {
215 usage();
218 my $verbose = 0;
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
242 # into html.
243 my $section_counter = 0;
245 my $lineprefix="";
247 # states
248 # 0 - normal code
249 # 1 - looking for function name
250 # 2 - scanning field start.
251 # 3 - scanning prototype.
252 # 4 - documentation block
253 my $state;
255 #declaration types: can be
256 # 'function', 'struct', 'union', 'enum', 'typedef'
257 my $decl_type;
259 my $doc_special = "\@\%\$\&";
261 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
262 my $doc_end = '\*/';
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*(.*)?';
269 my %constants;
270 my %parameterdescs;
271 my @parameterlist;
272 my %sections;
273 my @sectionlist;
275 my $contents = "";
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 --";
283 reset_state();
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
310 $function_only = 1;
311 $function = shift @ARGV;
312 $function_table{$function} = 1;
313 } elsif ($cmd eq "-nofunction") { # to only output specific functions
314 $function_only = 2;
315 $function = shift @ARGV;
316 $function_table{$function} = 1;
317 } elsif ($cmd eq "-v") {
318 $verbose = 1;
319 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
320 usage();
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.
338 sub dump_section {
339 my $name = shift;
340 my $contents = join "\n", @_;
342 if ($name =~ m/$type_constant/) {
343 $name = $1;
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";
348 $name = $1;
349 $parameterdescs{$name} = $contents;
350 } else {
351 # print STDERR "other section '$name' = '$contents'\n";
352 $sections{$name} = $contents;
353 push @sectionlist, $name;
358 # output function
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",@_;
370 my $line;
372 # DEBUG
373 # if (!defined $contents) {
374 # use Carp;
375 # confess "output_highlight got called with no args?\n";
378 eval $dohighlight;
379 die $@ if $@;
380 foreach $line (split "\n", $contents) {
381 if ($line eq ""){
382 print $lineprefix, $blankline;
383 } else {
384 $line =~ s/\\\\\\/\&/g;
385 print $lineprefix, $line;
387 print "\n";
391 #output sections in html
392 sub output_section_html(%) {
393 my %args = %{$_[0]};
394 my $section;
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(%) {
406 my %args = %{$_[0]};
407 my ($parameter);
408 my $count;
409 print "<h2>enum ".$args{'enum'}."</h2>\n";
411 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
412 $count = 0;
413 foreach $parameter (@{$args{'parameterlist'}}) {
414 print " <b>".$parameter."</b>";
415 if ($count != $#{$args{'parameterlist'}}) {
416 $count++;
417 print ",\n";
419 print "<br>";
421 print "};<br>\n";
423 print "<h3>Constants</h3>\n";
424 print "<dl>\n";
425 foreach $parameter (@{$args{'parameterlist'}}) {
426 print "<dt><b>".$parameter."</b>\n";
427 print "<dd>";
428 output_highlight($args{'parameterdescs'}{$parameter});
430 print "</dl>\n";
431 output_section_html(@_);
432 print "<hr>\n";
435 # output tyepdef in html
436 sub output_typedef_html(%) {
437 my %args = %{$_[0]};
438 my ($parameter);
439 my $count;
440 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
442 print "<b>typedef ".$args{'typedef'}."</b>\n";
443 output_section_html(@_);
444 print "<hr>\n";
447 # output struct in html
448 sub output_struct_html(%) {
449 my %args = %{$_[0]};
450 my ($parameter);
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";
457 next;
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";
469 } else {
470 print " <i>$type</i> <b>$parameter</b>;<br>\n";
473 print "};<br>\n";
475 print "<h3>Members</h3>\n";
476 print "<dl>\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";
485 print "<dd>";
486 output_highlight($args{'parameterdescs'}{$parameter_name});
488 print "</dl>\n";
489 output_section_html(@_);
490 print "<hr>\n";
493 # output function in html
494 sub output_function_html(%) {
495 my %args = %{$_[0]};
496 my ($parameter, $section);
497 my $count;
498 print "<h2>Function</h2>\n";
500 print "<i>".$args{'functiontype'}."</i>\n";
501 print "<b>".$args{'function'}."</b>\n";
502 print "(";
503 $count = 0;
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>";
509 } else {
510 print "<i>".$type."</i> <b>".$parameter."</b>";
512 if ($count != $#{$args{'parameterlist'}}) {
513 $count++;
514 print ",\n";
517 print ")\n";
519 print "<h3>Arguments</h3>\n";
520 print "<dl>\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";
527 print "<dd>";
528 output_highlight($args{'parameterdescs'}{$parameter_name});
530 print "</dl>\n";
531 output_section_html(@_);
532 print "<hr>\n";
535 # output intro in html
536 sub output_intro_html(%) {
537 my %args = %{$_[0]};
538 my ($parameter, $section);
539 my $count;
541 foreach $section (@{$args{'sectionlist'}}) {
542 print "<h3>$section</h3>\n";
543 print "<ul>\n";
544 output_highlight($args{'sections'}{$section});
545 print "</ul>\n";
547 print "<hr>\n";
550 sub output_section_xml(%) {
551 my %args = %{$_[0]};
552 my $section;
553 # print out each section
554 $lineprefix=" ";
555 foreach $section (@{$args{'sectionlist'}}) {
556 print "<refsect1>\n <title>$section</title>\n <para>\n";
557 if ($section =~ m/EXAMPLE/i) {
558 print "<example><para>\n";
560 output_highlight($args{'sections'}{$section});
561 if ($section =~ m/EXAMPLE/i) {
562 print "</para></example>\n";
564 print " </para>\n</refsect1>\n";
568 # output function in XML DocBook
569 sub output_function_xml(%) {
570 my %args = %{$_[0]};
571 my ($parameter, $section);
572 my $count;
573 my $id;
575 $id = "API-".$args{'function'};
576 $id =~ s/[^A-Za-z0-9]/-/g;
578 print "<refentry>\n";
579 print "<refmeta>\n";
580 print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
581 print "</refmeta>\n";
582 print "<refnamediv>\n";
583 print " <refname>".$args{'function'}."</refname>\n";
584 print " <refpurpose>\n";
585 print " ";
586 output_highlight ($args{'purpose'});
587 print " </refpurpose>\n";
588 print "</refnamediv>\n";
590 print "<refsynopsisdiv>\n";
591 print " <title>Synopsis</title>\n";
592 print " <funcsynopsis><funcprototype>\n";
593 print " <funcdef>".$args{'functiontype'}." ";
594 print "<function>".$args{'function'}." </function></funcdef>\n";
596 $count = 0;
597 if ($#{$args{'parameterlist'}} >= 0) {
598 foreach $parameter (@{$args{'parameterlist'}}) {
599 $type = $args{'parametertypes'}{$parameter};
600 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
601 # pointer-to-function
602 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
603 print " <funcparams>$2</funcparams></paramdef>\n";
604 } else {
605 print " <paramdef>".$type;
606 print " <parameter>$parameter</parameter></paramdef>\n";
609 } else {
610 print " <void>\n";
612 print " </funcprototype></funcsynopsis>\n";
613 print "</refsynopsisdiv>\n";
615 # print parameters
616 print "<refsect1>\n <title>Arguments</title>\n";
617 if ($#{$args{'parameterlist'}} >= 0) {
618 print " <variablelist>\n";
619 foreach $parameter (@{$args{'parameterlist'}}) {
620 my $parameter_name = $parameter;
621 $parameter_name =~ s/\[.*//;
623 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
624 print " <listitem>\n <para>\n";
625 $lineprefix=" ";
626 output_highlight($args{'parameterdescs'}{$parameter_name});
627 print " </para>\n </listitem>\n </varlistentry>\n";
629 print " </variablelist>\n";
630 } else {
631 print " <para>\n None\n </para>\n";
633 print "</refsect1>\n";
635 output_section_xml(@_);
636 print "</refentry>\n\n";
639 # output struct in XML DocBook
640 sub output_struct_xml(%) {
641 my %args = %{$_[0]};
642 my ($parameter, $section);
643 my $id;
645 $id = "API-struct-".$args{'struct'};
646 $id =~ s/[^A-Za-z0-9]/-/g;
648 print "<refentry>\n";
649 print "<refmeta>\n";
650 print "<refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
651 print "</refmeta>\n";
652 print "<refnamediv>\n";
653 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
654 print " <refpurpose>\n";
655 print " ";
656 output_highlight ($args{'purpose'});
657 print " </refpurpose>\n";
658 print "</refnamediv>\n";
660 print "<refsynopsisdiv>\n";
661 print " <title>Synopsis</title>\n";
662 print " <programlisting>\n";
663 print $args{'type'}." ".$args{'struct'}." {\n";
664 foreach $parameter (@{$args{'parameterlist'}}) {
665 if ($parameter =~ /^#/) {
666 print "$parameter\n";
667 next;
670 my $parameter_name = $parameter;
671 $parameter_name =~ s/\[.*//;
673 defined($args{'parameterdescs'}{$parameter_name}) || next;
674 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
675 $type = $args{'parametertypes'}{$parameter};
676 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
677 # pointer-to-function
678 print " $1 $parameter) ($2);\n";
679 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
680 print " $1 $parameter$2;\n";
681 } else {
682 print " ".$type." ".$parameter.";\n";
685 print "};";
686 print " </programlisting>\n";
687 print "</refsynopsisdiv>\n";
689 print " <refsect1>\n";
690 print " <title>Members</title>\n";
692 print " <variablelist>\n";
693 foreach $parameter (@{$args{'parameterlist'}}) {
694 ($parameter =~ /^#/) && next;
696 my $parameter_name = $parameter;
697 $parameter_name =~ s/\[.*//;
699 defined($args{'parameterdescs'}{$parameter_name}) || next;
700 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
701 print " <varlistentry>";
702 print " <term>$parameter</term>\n";
703 print " <listitem><para>\n";
704 output_highlight($args{'parameterdescs'}{$parameter_name});
705 print " </para></listitem>\n";
706 print " </varlistentry>\n";
708 print " </variablelist>\n";
709 print " </refsect1>\n";
711 output_section_xml(@_);
713 print "</refentry>\n\n";
716 # output enum in XML DocBook
717 sub output_enum_xml(%) {
718 my %args = %{$_[0]};
719 my ($parameter, $section);
720 my $count;
721 my $id;
723 $id = "API-enum-".$args{'enum'};
724 $id =~ s/[^A-Za-z0-9]/-/g;
726 print "<refentry>\n";
727 print "<refmeta>\n";
728 print "<refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n";
729 print "</refmeta>\n";
730 print "<refnamediv>\n";
731 print " <refname>enum ".$args{'enum'}."</refname>\n";
732 print " <refpurpose>\n";
733 print " ";
734 output_highlight ($args{'purpose'});
735 print " </refpurpose>\n";
736 print "</refnamediv>\n";
738 print "<refsynopsisdiv>\n";
739 print " <title>Synopsis</title>\n";
740 print " <programlisting>\n";
741 print "enum ".$args{'enum'}." {\n";
742 $count = 0;
743 foreach $parameter (@{$args{'parameterlist'}}) {
744 print " $parameter";
745 if ($count != $#{$args{'parameterlist'}}) {
746 $count++;
747 print ",";
749 print "\n";
751 print "};";
752 print " </programlisting>\n";
753 print "</refsynopsisdiv>\n";
755 print "<refsect1>\n";
756 print " <title>Constants</title>\n";
757 print " <variablelist>\n";
758 foreach $parameter (@{$args{'parameterlist'}}) {
759 my $parameter_name = $parameter;
760 $parameter_name =~ s/\[.*//;
762 print " <varlistentry>";
763 print " <term>$parameter</term>\n";
764 print " <listitem><para>\n";
765 output_highlight($args{'parameterdescs'}{$parameter_name});
766 print " </para></listitem>\n";
767 print " </varlistentry>\n";
769 print " </variablelist>\n";
770 print "</refsect1>\n";
772 output_section_xml(@_);
774 print "</refentry>\n\n";
777 # output typedef in XML DocBook
778 sub output_typedef_xml(%) {
779 my %args = %{$_[0]};
780 my ($parameter, $section);
781 my $id;
783 $id = "API-typedef-".$args{'typedef'};
784 $id =~ s/[^A-Za-z0-9]/-/g;
786 print "<refentry>\n";
787 print "<refmeta>\n";
788 print "<refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
789 print "</refmeta>\n";
790 print "<refnamediv>\n";
791 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
792 print " <refpurpose>\n";
793 print " ";
794 output_highlight ($args{'purpose'});
795 print " </refpurpose>\n";
796 print "</refnamediv>\n";
798 print "<refsynopsisdiv>\n";
799 print " <title>Synopsis</title>\n";
800 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
801 print "</refsynopsisdiv>\n";
803 output_section_xml(@_);
805 print "</refentry>\n\n";
808 # output in XML DocBook
809 sub output_intro_xml(%) {
810 my %args = %{$_[0]};
811 my ($parameter, $section);
812 my $count;
814 my $id = $args{'module'};
815 $id =~ s/[^A-Za-z0-9]/-/g;
817 # print out each section
818 $lineprefix=" ";
819 foreach $section (@{$args{'sectionlist'}}) {
820 print "<refsect1>\n <title>$section</title>\n <para>\n";
821 if ($section =~ m/EXAMPLE/i) {
822 print "<example><para>\n";
824 output_highlight($args{'sections'}{$section});
825 if ($section =~ m/EXAMPLE/i) {
826 print "</para></example>\n";
828 print " </para>\n</refsect1>\n";
831 print "\n\n";
834 # output in XML DocBook
835 sub output_function_gnome {
836 my %args = %{$_[0]};
837 my ($parameter, $section);
838 my $count;
839 my $id;
841 $id = $args{'module'}."-".$args{'function'};
842 $id =~ s/[^A-Za-z0-9]/-/g;
844 print "<sect2>\n";
845 print " <title id=\"$id\">".$args{'function'}."</title>\n";
847 print " <funcsynopsis>\n";
848 print " <funcdef>".$args{'functiontype'}." ";
849 print "<function>".$args{'function'}." ";
850 print "</function></funcdef>\n";
852 $count = 0;
853 if ($#{$args{'parameterlist'}} >= 0) {
854 foreach $parameter (@{$args{'parameterlist'}}) {
855 $type = $args{'parametertypes'}{$parameter};
856 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
857 # pointer-to-function
858 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
859 print " <funcparams>$2</funcparams></paramdef>\n";
860 } else {
861 print " <paramdef>".$type;
862 print " <parameter>$parameter</parameter></paramdef>\n";
865 } else {
866 print " <void>\n";
868 print " </funcsynopsis>\n";
869 if ($#{$args{'parameterlist'}} >= 0) {
870 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
871 print "<tgroup cols=\"2\">\n";
872 print "<colspec colwidth=\"2*\">\n";
873 print "<colspec colwidth=\"8*\">\n";
874 print "<tbody>\n";
875 foreach $parameter (@{$args{'parameterlist'}}) {
876 my $parameter_name = $parameter;
877 $parameter_name =~ s/\[.*//;
879 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
880 print " <entry>\n";
881 $lineprefix=" ";
882 output_highlight($args{'parameterdescs'}{$parameter_name});
883 print " </entry></row>\n";
885 print " </tbody></tgroup></informaltable>\n";
886 } else {
887 print " <para>\n None\n </para>\n";
890 # print out each section
891 $lineprefix=" ";
892 foreach $section (@{$args{'sectionlist'}}) {
893 print "<simplesect>\n <title>$section</title>\n";
894 if ($section =~ m/EXAMPLE/i) {
895 print "<example><programlisting>\n";
896 } else {
898 print "<para>\n";
899 output_highlight($args{'sections'}{$section});
900 print "</para>\n";
901 if ($section =~ m/EXAMPLE/i) {
902 print "</programlisting></example>\n";
903 } else {
905 print " </simplesect>\n";
908 print "</sect2>\n\n";
912 # output function in man
913 sub output_function_man(%) {
914 my %args = %{$_[0]};
915 my ($parameter, $section);
916 my $count;
918 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
920 print ".SH NAME\n";
921 print $args{'function'}." \\- ".$args{'purpose'}."\n";
923 print ".SH SYNOPSIS\n";
924 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
925 $count = 0;
926 my $parenth = "(";
927 my $post = ",";
928 foreach my $parameter (@{$args{'parameterlist'}}) {
929 if ($count == $#{$args{'parameterlist'}}) {
930 $post = ");";
932 $type = $args{'parametertypes'}{$parameter};
933 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
934 # pointer-to-function
935 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
936 } else {
937 $type =~ s/([^\*])$/$1 /;
938 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
940 $count++;
941 $parenth = "";
944 print ".SH ARGUMENTS\n";
945 foreach $parameter (@{$args{'parameterlist'}}) {
946 my $parameter_name = $parameter;
947 $parameter_name =~ s/\[.*//;
949 print ".IP \"".$parameter."\" 12\n";
950 output_highlight($args{'parameterdescs'}{$parameter_name});
952 foreach $section (@{$args{'sectionlist'}}) {
953 print ".SH \"", uc $section, "\"\n";
954 output_highlight($args{'sections'}{$section});
959 # output enum in man
960 sub output_enum_man(%) {
961 my %args = %{$_[0]};
962 my ($parameter, $section);
963 my $count;
965 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
967 print ".SH NAME\n";
968 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
970 print ".SH SYNOPSIS\n";
971 print "enum ".$args{'enum'}." {\n";
972 $count = 0;
973 foreach my $parameter (@{$args{'parameterlist'}}) {
974 print ".br\n.BI \" $parameter\"\n";
975 if ($count == $#{$args{'parameterlist'}}) {
976 print "\n};\n";
977 last;
979 else {
980 print ", \n.br\n";
982 $count++;
985 print ".SH Constants\n";
986 foreach $parameter (@{$args{'parameterlist'}}) {
987 my $parameter_name = $parameter;
988 $parameter_name =~ s/\[.*//;
990 print ".IP \"".$parameter."\" 12\n";
991 output_highlight($args{'parameterdescs'}{$parameter_name});
993 foreach $section (@{$args{'sectionlist'}}) {
994 print ".SH \"$section\"\n";
995 output_highlight($args{'sections'}{$section});
1000 # output struct in man
1001 sub output_struct_man(%) {
1002 my %args = %{$_[0]};
1003 my ($parameter, $section);
1005 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1007 print ".SH NAME\n";
1008 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1010 print ".SH SYNOPSIS\n";
1011 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1013 foreach my $parameter (@{$args{'parameterlist'}}) {
1014 if ($parameter =~ /^#/) {
1015 print ".BI \"$parameter\"\n.br\n";
1016 next;
1018 my $parameter_name = $parameter;
1019 $parameter_name =~ s/\[.*//;
1021 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1022 $type = $args{'parametertypes'}{$parameter};
1023 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1024 # pointer-to-function
1025 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1026 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1027 print ".BI \" ".$1."\" ".$parameter.$2." \""."\"\n;\n";
1028 } else {
1029 $type =~ s/([^\*])$/$1 /;
1030 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1032 print "\n.br\n";
1034 print "};\n.br\n";
1036 print ".SH Arguments\n";
1037 foreach $parameter (@{$args{'parameterlist'}}) {
1038 ($parameter =~ /^#/) && next;
1040 my $parameter_name = $parameter;
1041 $parameter_name =~ s/\[.*//;
1043 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1044 print ".IP \"".$parameter."\" 12\n";
1045 output_highlight($args{'parameterdescs'}{$parameter_name});
1047 foreach $section (@{$args{'sectionlist'}}) {
1048 print ".SH \"$section\"\n";
1049 output_highlight($args{'sections'}{$section});
1054 # output typedef in man
1055 sub output_typedef_man(%) {
1056 my %args = %{$_[0]};
1057 my ($parameter, $section);
1059 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1061 print ".SH NAME\n";
1062 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1064 foreach $section (@{$args{'sectionlist'}}) {
1065 print ".SH \"$section\"\n";
1066 output_highlight($args{'sections'}{$section});
1070 sub output_intro_man(%) {
1071 my %args = %{$_[0]};
1072 my ($parameter, $section);
1073 my $count;
1075 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1077 foreach $section (@{$args{'sectionlist'}}) {
1078 print ".SH \"$section\"\n";
1079 output_highlight($args{'sections'}{$section});
1084 # output in text
1085 sub output_function_text(%) {
1086 my %args = %{$_[0]};
1087 my ($parameter, $section);
1089 print "Function:\n\n";
1090 my $start=$args{'functiontype'}." ".$args{'function'}." (";
1091 print $start;
1092 my $count = 0;
1093 foreach my $parameter (@{$args{'parameterlist'}}) {
1094 $type = $args{'parametertypes'}{$parameter};
1095 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1096 # pointer-to-function
1097 print $1.$parameter.") (".$2;
1098 } else {
1099 print $type." ".$parameter;
1101 if ($count != $#{$args{'parameterlist'}}) {
1102 $count++;
1103 print ",\n";
1104 print " " x length($start);
1105 } else {
1106 print ");\n\n";
1110 print "Arguments:\n\n";
1111 foreach $parameter (@{$args{'parameterlist'}}) {
1112 my $parameter_name = $parameter;
1113 $parameter_name =~ s/\[.*//;
1115 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1117 output_section_text(@_);
1120 #output sections in text
1121 sub output_section_text(%) {
1122 my %args = %{$_[0]};
1123 my $section;
1125 print "\n";
1126 foreach $section (@{$args{'sectionlist'}}) {
1127 print "$section:\n\n";
1128 output_highlight($args{'sections'}{$section});
1130 print "\n\n";
1133 # output enum in text
1134 sub output_enum_text(%) {
1135 my %args = %{$_[0]};
1136 my ($parameter);
1137 my $count;
1138 print "Enum:\n\n";
1140 print "enum ".$args{'enum'}." {\n";
1141 $count = 0;
1142 foreach $parameter (@{$args{'parameterlist'}}) {
1143 print "\t$parameter";
1144 if ($count != $#{$args{'parameterlist'}}) {
1145 $count++;
1146 print ",";
1148 print "\n";
1150 print "};\n\n";
1152 print "Constants:\n\n";
1153 foreach $parameter (@{$args{'parameterlist'}}) {
1154 print "$parameter\n\t";
1155 print $args{'parameterdescs'}{$parameter}."\n";
1158 output_section_text(@_);
1161 # output typedef in text
1162 sub output_typedef_text(%) {
1163 my %args = %{$_[0]};
1164 my ($parameter);
1165 my $count;
1166 print "Typedef:\n\n";
1168 print "typedef ".$args{'typedef'}."\n";
1169 output_section_text(@_);
1172 # output struct as text
1173 sub output_struct_text(%) {
1174 my %args = %{$_[0]};
1175 my ($parameter);
1177 print $args{'type'}." ".$args{'struct'}.":\n\n";
1178 print $args{'type'}." ".$args{'struct'}." {\n";
1179 foreach $parameter (@{$args{'parameterlist'}}) {
1180 if ($parameter =~ /^#/) {
1181 print "$parameter\n";
1182 next;
1185 my $parameter_name = $parameter;
1186 $parameter_name =~ s/\[.*//;
1188 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1189 $type = $args{'parametertypes'}{$parameter};
1190 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1191 # pointer-to-function
1192 print "\t$1 $parameter) ($2);\n";
1193 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1194 print "\t$1 $parameter$2;\n";
1195 } else {
1196 print "\t".$type." ".$parameter.";\n";
1199 print "};\n\n";
1201 print "Members:\n\n";
1202 foreach $parameter (@{$args{'parameterlist'}}) {
1203 ($parameter =~ /^#/) && next;
1205 my $parameter_name = $parameter;
1206 $parameter_name =~ s/\[.*//;
1208 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1209 print "$parameter\n\t";
1210 print $args{'parameterdescs'}{$parameter_name}."\n";
1212 print "\n";
1213 output_section_text(@_);
1216 sub output_intro_text(%) {
1217 my %args = %{$_[0]};
1218 my ($parameter, $section);
1220 foreach $section (@{$args{'sectionlist'}}) {
1221 print " $section:\n";
1222 print " -> ";
1223 output_highlight($args{'sections'}{$section});
1228 # generic output function for typedefs
1229 sub output_declaration {
1230 no strict 'refs';
1231 my $name = shift;
1232 my $functype = shift;
1233 my $func = "output_${functype}_$output_mode";
1234 if (($function_only==0) ||
1235 ( $function_only == 1 && defined($function_table{$name})) ||
1236 ( $function_only == 2 && !defined($function_table{$name})))
1238 &$func(@_);
1239 $section_counter++;
1244 # generic output function - calls the right one based
1245 # on current output mode.
1246 sub output_intro {
1247 no strict 'refs';
1248 my $func = "output_intro_".$output_mode;
1249 &$func(@_);
1250 $section_counter++;
1254 # takes a declaration (struct, union, enum, typedef) and
1255 # invokes the right handler. NOT called for functions.
1256 sub dump_declaration($$) {
1257 no strict 'refs';
1258 my ($prototype, $file) = @_;
1259 my $func = "dump_".$decl_type;
1260 &$func(@_);
1263 sub dump_union($$) {
1264 dump_struct(@_);
1267 sub dump_struct($$) {
1268 my $x = shift;
1269 my $file = shift;
1271 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1272 $declaration_name = $2;
1273 my $members = $3;
1275 # ignore embedded structs or unions
1276 $members =~ s/{.*?}//g;
1278 create_parameterlist($members, ';', $file);
1280 output_declaration($declaration_name,
1281 'struct',
1282 {'struct' => $declaration_name,
1283 'module' => $modulename,
1284 'parameterlist' => \@parameterlist,
1285 'parameterdescs' => \%parameterdescs,
1286 'parametertypes' => \%parametertypes,
1287 'sectionlist' => \@sectionlist,
1288 'sections' => \%sections,
1289 'purpose' => $declaration_purpose,
1290 'type' => $decl_type
1293 else {
1294 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1295 ++$errors;
1299 sub dump_enum($$) {
1300 my $x = shift;
1301 my $file = shift;
1303 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1304 $declaration_name = $1;
1305 my $members = $2;
1307 foreach my $arg (split ',', $members) {
1308 $arg =~ s/^\s*(\w+).*/$1/;
1309 push @parameterlist, $arg;
1310 if (!$parameterdescs{$arg}) {
1311 $parameterdescs{$arg} = $undescribed;
1312 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1313 "not described in enum '$declaration_name'\n";
1318 output_declaration($declaration_name,
1319 'enum',
1320 {'enum' => $declaration_name,
1321 'module' => $modulename,
1322 'parameterlist' => \@parameterlist,
1323 'parameterdescs' => \%parameterdescs,
1324 'sectionlist' => \@sectionlist,
1325 'sections' => \%sections,
1326 'purpose' => $declaration_purpose
1329 else {
1330 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1331 ++$errors;
1335 sub dump_typedef($$) {
1336 my $x = shift;
1337 my $file = shift;
1339 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1340 $x =~ s/\(*.\)\s*;$/;/;
1341 $x =~ s/\[*.\]\s*;$/;/;
1344 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1345 $declaration_name = $1;
1347 output_declaration($declaration_name,
1348 'typedef',
1349 {'typedef' => $declaration_name,
1350 'module' => $modulename,
1351 'sectionlist' => \@sectionlist,
1352 'sections' => \%sections,
1353 'purpose' => $declaration_purpose
1356 else {
1357 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1358 ++$errors;
1362 sub create_parameterlist($$$) {
1363 my $args = shift;
1364 my $splitter = shift;
1365 my $file = shift;
1366 my $type;
1367 my $param;
1369 while ($args =~ /(\([^\),]+),/) {
1370 $args =~ s/(\([^\),]+),/$1#/g;
1373 foreach my $arg (split($splitter, $args)) {
1374 # strip comments
1375 $arg =~ s/\/\*.*\*\///;
1376 # strip leading/trailing spaces
1377 $arg =~ s/^\s*//;
1378 $arg =~ s/\s*$//;
1379 $arg =~ s/\s+/ /;
1381 if ($arg =~ /^#/) {
1382 # Treat preprocessor directive as a typeless variable just to fill
1383 # corresponding data structures "correctly". Catch it later in
1384 # output_* subs.
1385 push_parameter($arg, "", $file);
1386 } elsif ($arg =~ m/\(/) {
1387 # pointer-to-function
1388 $arg =~ tr/#/,/;
1389 $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
1390 $param = $1;
1391 $type = $arg;
1392 $type =~ s/([^\(]+\(\*)$param/$1/;
1393 push_parameter($param, $type, $file);
1394 } else {
1395 $arg =~ s/\s*:\s*/:/g;
1396 $arg =~ s/\s*\[/\[/g;
1398 my @args = split('\s*,\s*', $arg);
1399 if ($args[0] =~ m/\*/) {
1400 $args[0] =~ s/(\*+)\s*/ $1/;
1402 my @first_arg = split('\s+', shift @args);
1403 unshift(@args, pop @first_arg);
1404 $type = join " ", @first_arg;
1406 foreach $param (@args) {
1407 if ($param =~ m/^(\*+)\s*(.*)/) {
1408 push_parameter($2, "$type $1", $file);
1410 elsif ($param =~ m/(.*?):(\d+)/) {
1411 push_parameter($1, "$type:$2", $file)
1413 else {
1414 push_parameter($param, $type, $file);
1421 sub push_parameter($$$) {
1422 my $param = shift;
1423 my $type = shift;
1424 my $file = shift;
1426 my $param_name = $param;
1427 $param_name =~ s/\[.*//;
1429 if ($type eq "" && $param eq "...")
1431 $type="";
1432 $param="...";
1433 $parameterdescs{"..."} = "variable arguments";
1435 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1437 $type="";
1438 $param="void";
1439 $parameterdescs{void} = "no arguments";
1441 if (defined $type && $type && !defined $parameterdescs{$param_name}) {
1442 $parameterdescs{$param_name} = $undescribed;
1444 if (($type eq 'function') || ($type eq 'enum')) {
1445 print STDERR "Warning(${file}:$.): Function parameter ".
1446 "or member '$param' not " .
1447 "described in '$declaration_name'\n";
1449 print STDERR "Warning(${file}:$.):".
1450 " No description found for parameter '$param'\n";
1451 ++$warnings;
1454 push @parameterlist, $param;
1455 $parametertypes{$param} = $type;
1459 # takes a function prototype and the name of the current file being
1460 # processed and spits out all the details stored in the global
1461 # arrays/hashes.
1462 sub dump_function($$) {
1463 my $prototype = shift;
1464 my $file = shift;
1466 $prototype =~ s/^static +//;
1467 $prototype =~ s/^extern +//;
1468 $prototype =~ s/^inline +//;
1469 $prototype =~ s/^__inline__ +//;
1470 $prototype =~ s/^#define +//; #ak added
1471 $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//;
1473 # Yes, this truly is vile. We are looking for:
1474 # 1. Return type (may be nothing if we're looking at a macro)
1475 # 2. Function name
1476 # 3. Function parameters.
1478 # All the while we have to watch out for function pointer parameters
1479 # (which IIRC is what the two sections are for), C types (these
1480 # regexps don't even start to express all the possibilities), and
1481 # so on.
1483 # If you mess with these regexps, it's a good idea to check that
1484 # the following functions' documentation still comes out right:
1485 # - parport_register_device (function pointer parameters)
1486 # - atomic_set (macro)
1487 # - pci_match_device (long return type)
1489 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1490 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1491 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1492 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1493 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1494 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1495 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1496 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1497 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1498 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1499 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1500 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1501 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1502 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1503 $return_type = $1;
1504 $declaration_name = $2;
1505 my $args = $3;
1507 create_parameterlist($args, ',', $file);
1508 } else {
1509 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1510 ++$errors;
1511 return;
1514 output_declaration($declaration_name,
1515 'function',
1516 {'function' => $declaration_name,
1517 'module' => $modulename,
1518 'functiontype' => $return_type,
1519 'parameterlist' => \@parameterlist,
1520 'parameterdescs' => \%parameterdescs,
1521 'parametertypes' => \%parametertypes,
1522 'sectionlist' => \@sectionlist,
1523 'sections' => \%sections,
1524 'purpose' => $declaration_purpose
1528 sub process_file($);
1530 # Read the file that maps relative names to absolute names for
1531 # separate source and object directories and for shadow trees.
1532 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1533 my ($relname, $absname);
1534 while(<SOURCE_MAP>) {
1535 chop();
1536 ($relname, $absname) = (split())[0..1];
1537 $relname =~ s:^/+::;
1538 $source_map{$relname} = $absname;
1540 close(SOURCE_MAP);
1543 if ($filelist) {
1544 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1545 while(<FLIST>) {
1546 chop;
1547 process_file($_);
1551 foreach (@ARGV) {
1552 chomp;
1553 process_file($_);
1555 if ($verbose && $errors) {
1556 print STDERR "$errors errors\n";
1558 if ($verbose && $warnings) {
1559 print STDERR "$warnings warnings\n";
1562 exit($errors);
1564 sub reset_state {
1565 $function = "";
1566 %constants = ();
1567 %parameterdescs = ();
1568 %parametertypes = ();
1569 @parameterlist = ();
1570 %sections = ();
1571 @sectionlist = ();
1572 $prototype = "";
1574 $state = 0;
1577 sub process_state3_function($$) {
1578 my $x = shift;
1579 my $file = shift;
1581 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1582 # do nothing
1584 elsif ($x =~ /([^\{]*)/) {
1585 $prototype .= $1;
1587 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1588 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1589 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1590 $prototype =~ s@^\s+@@gos; # strip leading spaces
1591 dump_function($prototype,$file);
1592 reset_state();
1596 sub process_state3_type($$) {
1597 my $x = shift;
1598 my $file = shift;
1600 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1601 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1602 $x =~ s@^\s+@@gos; # strip leading spaces
1603 $x =~ s@\s+$@@gos; # strip trailing spaces
1604 if ($x =~ /^#/) {
1605 # To distinguish preprocessor directive from regular declaration later.
1606 $x .= ";";
1609 while (1) {
1610 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1611 $prototype .= $1 . $2;
1612 ($2 eq '{') && $brcount++;
1613 ($2 eq '}') && $brcount--;
1614 if (($2 eq ';') && ($brcount == 0)) {
1615 dump_declaration($prototype,$file);
1616 reset_state();
1617 last;
1619 $x = $3;
1620 } else {
1621 $prototype .= $x;
1622 last;
1627 # replace <, >, and &
1628 sub xml_escape($) {
1629 my $text = shift;
1630 $text =~ s/\&/\\\\\\amp;/g;
1631 $text =~ s/\</\\\\\\lt;/g;
1632 $text =~ s/\>/\\\\\\gt;/g;
1633 return $text;
1636 sub process_file($) {
1637 my ($file) = "$ENV{'SRCTREE'}@_";
1638 my $identifier;
1639 my $func;
1640 my $initial_section_counter = $section_counter;
1642 if (defined($source_map{$file})) {
1643 $file = $source_map{$file};
1646 if (!open(IN,"<$file")) {
1647 print STDERR "Error: Cannot open file $file\n";
1648 ++$errors;
1649 return;
1652 $section_counter = 0;
1653 while (<IN>) {
1654 if ($state == 0) {
1655 if (/$doc_start/o) {
1656 $state = 1; # next line is always the function name
1658 } elsif ($state == 1) { # this line is the function name (always)
1659 if (/$doc_block/o) {
1660 $state = 4;
1661 $contents = "";
1662 if ( $1 eq "" ) {
1663 $section = $section_intro;
1664 } else {
1665 $section = $1;
1668 elsif (/$doc_decl/o) {
1669 $identifier = $1;
1670 if (/\s*([\w\s]+?)\s*-/) {
1671 $identifier = $1;
1674 $state = 2;
1675 if (/-(.*)/) {
1676 $declaration_purpose = xml_escape($1);
1677 } else {
1678 $declaration_purpose = "";
1680 if ($identifier =~ m/^struct/) {
1681 $decl_type = 'struct';
1682 } elsif ($identifier =~ m/^union/) {
1683 $decl_type = 'union';
1684 } elsif ($identifier =~ m/^enum/) {
1685 $decl_type = 'enum';
1686 } elsif ($identifier =~ m/^typedef/) {
1687 $decl_type = 'typedef';
1688 } else {
1689 $decl_type = 'function';
1692 if ($verbose) {
1693 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1695 } else {
1696 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1697 " - I thought it was a doc line\n";
1698 ++$warnings;
1699 $state = 0;
1701 } elsif ($state == 2) { # look for head: lines, and include content
1702 if (/$doc_sect/o) {
1703 $newsection = $1;
1704 $newcontents = $2;
1706 if ($contents ne "") {
1707 dump_section($section, xml_escape($contents));
1708 $section = $section_default;
1711 $contents = $newcontents;
1712 if ($contents ne "") {
1713 $contents .= "\n";
1715 $section = $newsection;
1716 } elsif (/$doc_end/) {
1718 if ($contents ne "") {
1719 dump_section($section, xml_escape($contents));
1720 $section = $section_default;
1721 $contents = "";
1724 $prototype = "";
1725 $state = 3;
1726 $brcount = 0;
1727 # print STDERR "end of doc comment, looking for prototype\n";
1728 } elsif (/$doc_content/) {
1729 # miguel-style comment kludge, look for blank lines after
1730 # @parameter line to signify start of description
1731 if ($1 eq "" &&
1732 ($section =~ m/^@/ || $section eq $section_context)) {
1733 dump_section($section, xml_escape($contents));
1734 $section = $section_default;
1735 $contents = "";
1736 } else {
1737 $contents .= $1."\n";
1739 } else {
1740 # i dont know - bad line? ignore.
1741 print STDERR "Warning(${file}:$.): bad line: $_";
1742 ++$warnings;
1744 } elsif ($state == 3) { # scanning for function { (end of prototype)
1745 if ($decl_type eq 'function') {
1746 process_state3_function($_, $file);
1747 } else {
1748 process_state3_type($_, $file);
1750 } elsif ($state == 4) {
1751 # Documentation block
1752 if (/$doc_block/) {
1753 dump_section($section, $contents);
1754 output_intro({'sectionlist' => \@sectionlist,
1755 'sections' => \%sections });
1756 $contents = "";
1757 $function = "";
1758 %constants = ();
1759 %parameterdescs = ();
1760 %parametertypes = ();
1761 @parameterlist = ();
1762 %sections = ();
1763 @sectionlist = ();
1764 $prototype = "";
1765 if ( $1 eq "" ) {
1766 $section = $section_intro;
1767 } else {
1768 $section = $1;
1771 elsif (/$doc_end/)
1773 dump_section($section, $contents);
1774 output_intro({'sectionlist' => \@sectionlist,
1775 'sections' => \%sections });
1776 $contents = "";
1777 $function = "";
1778 %constants = ();
1779 %parameterdescs = ();
1780 %parametertypes = ();
1781 @parameterlist = ();
1782 %sections = ();
1783 @sectionlist = ();
1784 $prototype = "";
1785 $state = 0;
1787 elsif (/$doc_content/)
1789 if ( $1 eq "" )
1791 $contents .= $blankline;
1793 else
1795 $contents .= $1 . "\n";
1800 if ($initial_section_counter == $section_counter) {
1801 print STDERR "Warning(${file}): no structured comments found\n";
1802 if ($output_mode eq "xml") {
1803 # The template wants at least one RefEntry here; make one.
1804 print "<refentry>\n";
1805 print " <refnamediv>\n";
1806 print " <refname>\n";
1807 print " ${file}\n";
1808 print " </refname>\n";
1809 print " <refpurpose>\n";
1810 print " Document generation inconsistency\n";
1811 print " </refpurpose>\n";
1812 print " </refnamediv>\n";
1813 print " <refsect1>\n";
1814 print " <title>\n";
1815 print " Oops\n";
1816 print " </title>\n";
1817 print " <warning>\n";
1818 print " <para>\n";
1819 print " The template for this document tried to insert\n";
1820 print " the structured comment from the file\n";
1821 print " <filename>${file}</filename> at this point,\n";
1822 print " but none was found.\n";
1823 print " This dummy section is inserted to allow\n";
1824 print " generation to continue.\n";
1825 print " </para>\n";
1826 print " </warning>\n";
1827 print " </refsect1>\n";
1828 print "</refentry>\n";