udf: support files larger than 1G
[linux-2.6/pdupreez.git] / scripts / kernel-doc
bloba325a0c890dc8e0a49ce4992ca4735ba5b5d1530
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 # kernel-doc [ -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).
61 # Cannot be used together with -function
62 # (yes, that's a bug -- perl hackers can fix it 8))
64 # c files - list of 'c' files to process
66 # All output goes to stdout, with errors to stderr.
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 omitted, 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
115 # * Longer description
116 # */
117 # struct my_struct {
118 # int a;
119 # int b;
120 # /* private: */
121 # int c;
122 # };
124 # All descriptions can be multiline, except the short function description.
126 # You can also add additional sections. When documenting kernel functions you
127 # should document the "Context:" of the function, e.g. whether the functions
128 # can be called form interrupts. Unlike other sections you can end it with an
129 # empty line.
130 # Example-sections should contain the string EXAMPLE so that they are marked
131 # appropriately in DocBook.
133 # Example:
134 # /**
135 # * user_function - function that can only be called in user context
136 # * @a: some argument
137 # * Context: !in_interrupt()
139 # * Some description
140 # * Example:
141 # * user_function(22);
142 # */
143 # ...
146 # All descriptive text is further processed, scanning for the following special
147 # patterns, which are highlighted appropriately.
149 # 'funcname()' - function
150 # '$ENVVAR' - environmental variable
151 # '&struct_name' - name of a structure (up to two words including 'struct')
152 # '@parameter' - name of a parameter
153 # '%CONST' - name of a constant.
155 my $errors = 0;
156 my $warnings = 0;
158 # match expressions used to find embedded type information
159 my $type_constant = '\%([-_\w]+)';
160 my $type_func = '(\w+)\(\)';
161 my $type_param = '\@(\w+)';
162 my $type_struct = '\&((struct\s*)*[_\w]+)';
163 my $type_struct_xml = '\\\amp;((struct\s*)*[_\w]+)';
164 my $type_env = '(\$\w+)';
166 # Output conversion substitutions.
167 # One for each output format
169 # these work fairly well
170 my %highlights_html = ( $type_constant, "<i>\$1</i>",
171 $type_func, "<b>\$1</b>",
172 $type_struct_xml, "<i>\$1</i>",
173 $type_env, "<b><i>\$1</i></b>",
174 $type_param, "<tt><b>\$1</b></tt>" );
175 my $blankline_html = "<p>";
177 # XML, docbook format
178 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
179 $type_constant, "<constant>\$1</constant>",
180 $type_func, "<function>\$1</function>",
181 $type_struct, "<structname>\$1</structname>",
182 $type_env, "<envar>\$1</envar>",
183 $type_param, "<parameter>\$1</parameter>" );
184 my $blankline_xml = "</para><para>\n";
186 # gnome, docbook format
187 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
188 $type_func, "<function>\$1</function>",
189 $type_struct, "<structname>\$1</structname>",
190 $type_env, "<envar>\$1</envar>",
191 $type_param, "<parameter>\$1</parameter>" );
192 my $blankline_gnome = "</para><para>\n";
194 # these are pretty rough
195 my %highlights_man = ( $type_constant, "\$1",
196 $type_func, "\\\\fB\$1\\\\fP",
197 $type_struct, "\\\\fI\$1\\\\fP",
198 $type_param, "\\\\fI\$1\\\\fP" );
199 my $blankline_man = "";
201 # text-mode
202 my %highlights_text = ( $type_constant, "\$1",
203 $type_func, "\$1",
204 $type_struct, "\$1",
205 $type_param, "\$1" );
206 my $blankline_text = "";
209 sub usage {
210 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n";
211 print " [ -function funcname [ -function funcname ...] ]\n";
212 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
213 print " c source file(s) > outputfile\n";
214 exit 1;
217 # read arguments
218 if ($#ARGV==-1) {
219 usage();
222 my $verbose = 0;
223 my $output_mode = "man";
224 my %highlights = %highlights_man;
225 my $blankline = $blankline_man;
226 my $modulename = "Kernel API";
227 my $function_only = 0;
228 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
229 'July', 'August', 'September', 'October',
230 'November', 'December')[(localtime)[4]] .
231 " " . ((localtime)[5]+1900);
233 # Essentially these are globals
234 # They probably want to be tidied up made more localised or summat.
235 # CAVEAT EMPTOR! Some of the others I localised may not want to be which
236 # could cause "use of undefined value" or other bugs.
237 my ($function, %function_table,%parametertypes,$declaration_purpose);
238 my ($type,$declaration_name,$return_type);
239 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
241 # Generated docbook code is inserted in a template at a point where
242 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
243 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
244 # We keep track of number of generated entries and generate a dummy
245 # if needs be to ensure the expanded template can be postprocessed
246 # into html.
247 my $section_counter = 0;
249 my $lineprefix="";
251 # states
252 # 0 - normal code
253 # 1 - looking for function name
254 # 2 - scanning field start.
255 # 3 - scanning prototype.
256 # 4 - documentation block
257 my $state;
258 my $in_doc_sect;
260 #declaration types: can be
261 # 'function', 'struct', 'union', 'enum', 'typedef'
262 my $decl_type;
264 my $doc_special = "\@\%\$\&";
266 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
267 my $doc_end = '\*/';
268 my $doc_com = '\s*\*\s*';
269 my $doc_decl = $doc_com.'(\w+)';
270 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)';
271 my $doc_content = $doc_com.'(.*)';
272 my $doc_block = $doc_com.'DOC:\s*(.*)?';
274 my %constants;
275 my %parameterdescs;
276 my @parameterlist;
277 my %sections;
278 my @sectionlist;
280 my $contents = "";
281 my $section_default = "Description"; # default section
282 my $section_intro = "Introduction";
283 my $section = $section_default;
284 my $section_context = "Context";
286 my $undescribed = "-- undescribed --";
288 reset_state();
290 while ($ARGV[0] =~ m/^-(.*)/) {
291 my $cmd = shift @ARGV;
292 if ($cmd eq "-html") {
293 $output_mode = "html";
294 %highlights = %highlights_html;
295 $blankline = $blankline_html;
296 } elsif ($cmd eq "-man") {
297 $output_mode = "man";
298 %highlights = %highlights_man;
299 $blankline = $blankline_man;
300 } elsif ($cmd eq "-text") {
301 $output_mode = "text";
302 %highlights = %highlights_text;
303 $blankline = $blankline_text;
304 } elsif ($cmd eq "-docbook") {
305 $output_mode = "xml";
306 %highlights = %highlights_xml;
307 $blankline = $blankline_xml;
308 } elsif ($cmd eq "-gnome") {
309 $output_mode = "gnome";
310 %highlights = %highlights_gnome;
311 $blankline = $blankline_gnome;
312 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
313 $modulename = shift @ARGV;
314 } elsif ($cmd eq "-function") { # to only output specific functions
315 $function_only = 1;
316 $function = shift @ARGV;
317 $function_table{$function} = 1;
318 } elsif ($cmd eq "-nofunction") { # to only output specific functions
319 $function_only = 2;
320 $function = shift @ARGV;
321 $function_table{$function} = 1;
322 } elsif ($cmd eq "-v") {
323 $verbose = 1;
324 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
325 usage();
326 } elsif ($cmd eq '-filelist') {
327 $filelist = shift @ARGV;
331 # get kernel version from env
332 sub get_kernel_version() {
333 my $version;
335 if (defined($ENV{'KERNELVERSION'})) {
336 $version = $ENV{'KERNELVERSION'};
338 return $version;
341 # generate a sequence of code that will splice in highlighting information
342 # using the s// operator.
343 my $dohighlight = "";
344 foreach my $pattern (keys %highlights) {
345 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
346 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
350 # dumps section contents to arrays/hashes intended for that purpose.
352 sub dump_section {
353 my $name = shift;
354 my $contents = join "\n", @_;
356 if ($name =~ m/$type_constant/) {
357 $name = $1;
358 # print STDERR "constant section '$1' = '$contents'\n";
359 $constants{$name} = $contents;
360 } elsif ($name =~ m/$type_param/) {
361 # print STDERR "parameter def '$1' = '$contents'\n";
362 $name = $1;
363 $parameterdescs{$name} = $contents;
364 } else {
365 # print STDERR "other section '$name' = '$contents'\n";
366 $sections{$name} = $contents;
367 push @sectionlist, $name;
372 # output function
374 # parameterdescs, a hash.
375 # function => "function name"
376 # parameterlist => @list of parameters
377 # parameterdescs => %parameter descriptions
378 # sectionlist => @list of sections
379 # sections => %section descriptions
382 sub output_highlight {
383 my $contents = join "\n",@_;
384 my $line;
386 # DEBUG
387 # if (!defined $contents) {
388 # use Carp;
389 # confess "output_highlight got called with no args?\n";
392 # print STDERR "contents b4:$contents\n";
393 eval $dohighlight;
394 die $@ if $@;
395 if ($output_mode eq "html") {
396 $contents =~ s/\\\\//;
398 # print STDERR "contents af:$contents\n";
400 foreach $line (split "\n", $contents) {
401 if ($line eq ""){
402 print $lineprefix, $blankline;
403 } else {
404 $line =~ s/\\\\\\/\&/g;
405 print $lineprefix, $line;
407 print "\n";
411 #output sections in html
412 sub output_section_html(%) {
413 my %args = %{$_[0]};
414 my $section;
416 foreach $section (@{$args{'sectionlist'}}) {
417 print "<h3>$section</h3>\n";
418 print "<blockquote>\n";
419 output_highlight($args{'sections'}{$section});
420 print "</blockquote>\n";
424 # output enum in html
425 sub output_enum_html(%) {
426 my %args = %{$_[0]};
427 my ($parameter);
428 my $count;
429 print "<h2>enum ".$args{'enum'}."</h2>\n";
431 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
432 $count = 0;
433 foreach $parameter (@{$args{'parameterlist'}}) {
434 print " <b>".$parameter."</b>";
435 if ($count != $#{$args{'parameterlist'}}) {
436 $count++;
437 print ",\n";
439 print "<br>";
441 print "};<br>\n";
443 print "<h3>Constants</h3>\n";
444 print "<dl>\n";
445 foreach $parameter (@{$args{'parameterlist'}}) {
446 print "<dt><b>".$parameter."</b>\n";
447 print "<dd>";
448 output_highlight($args{'parameterdescs'}{$parameter});
450 print "</dl>\n";
451 output_section_html(@_);
452 print "<hr>\n";
455 # output typedef in html
456 sub output_typedef_html(%) {
457 my %args = %{$_[0]};
458 my ($parameter);
459 my $count;
460 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
462 print "<b>typedef ".$args{'typedef'}."</b>\n";
463 output_section_html(@_);
464 print "<hr>\n";
467 # output struct in html
468 sub output_struct_html(%) {
469 my %args = %{$_[0]};
470 my ($parameter);
472 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
473 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
474 foreach $parameter (@{$args{'parameterlist'}}) {
475 if ($parameter =~ /^#/) {
476 print "$parameter<br>\n";
477 next;
479 my $parameter_name = $parameter;
480 $parameter_name =~ s/\[.*//;
482 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
483 $type = $args{'parametertypes'}{$parameter};
484 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
485 # pointer-to-function
486 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
487 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
488 # bitfield
489 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
490 } else {
491 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
494 print "};<br>\n";
496 print "<h3>Members</h3>\n";
497 print "<dl>\n";
498 foreach $parameter (@{$args{'parameterlist'}}) {
499 ($parameter =~ /^#/) && next;
501 my $parameter_name = $parameter;
502 $parameter_name =~ s/\[.*//;
504 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
505 print "<dt><b>".$parameter."</b>\n";
506 print "<dd>";
507 output_highlight($args{'parameterdescs'}{$parameter_name});
509 print "</dl>\n";
510 output_section_html(@_);
511 print "<hr>\n";
514 # output function in html
515 sub output_function_html(%) {
516 my %args = %{$_[0]};
517 my ($parameter, $section);
518 my $count;
520 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
521 print "<i>".$args{'functiontype'}."</i>\n";
522 print "<b>".$args{'function'}."</b>\n";
523 print "(";
524 $count = 0;
525 foreach $parameter (@{$args{'parameterlist'}}) {
526 $type = $args{'parametertypes'}{$parameter};
527 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
528 # pointer-to-function
529 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
530 } else {
531 print "<i>".$type."</i> <b>".$parameter."</b>";
533 if ($count != $#{$args{'parameterlist'}}) {
534 $count++;
535 print ",\n";
538 print ")\n";
540 print "<h3>Arguments</h3>\n";
541 print "<dl>\n";
542 foreach $parameter (@{$args{'parameterlist'}}) {
543 my $parameter_name = $parameter;
544 $parameter_name =~ s/\[.*//;
546 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
547 print "<dt><b>".$parameter."</b>\n";
548 print "<dd>";
549 output_highlight($args{'parameterdescs'}{$parameter_name});
551 print "</dl>\n";
552 output_section_html(@_);
553 print "<hr>\n";
556 # output intro in html
557 sub output_intro_html(%) {
558 my %args = %{$_[0]};
559 my ($parameter, $section);
560 my $count;
562 foreach $section (@{$args{'sectionlist'}}) {
563 print "<h3>$section</h3>\n";
564 print "<ul>\n";
565 output_highlight($args{'sections'}{$section});
566 print "</ul>\n";
568 print "<hr>\n";
571 sub output_section_xml(%) {
572 my %args = %{$_[0]};
573 my $section;
574 # print out each section
575 $lineprefix=" ";
576 foreach $section (@{$args{'sectionlist'}}) {
577 print "<refsect1>\n";
578 print "<title>$section</title>\n";
579 if ($section =~ m/EXAMPLE/i) {
580 print "<informalexample><programlisting>\n";
581 } else {
582 print "<para>\n";
584 output_highlight($args{'sections'}{$section});
585 if ($section =~ m/EXAMPLE/i) {
586 print "</programlisting></informalexample>\n";
587 } else {
588 print "</para>\n";
590 print "</refsect1>\n";
594 # output function in XML DocBook
595 sub output_function_xml(%) {
596 my %args = %{$_[0]};
597 my ($parameter, $section);
598 my $count;
599 my $id;
601 $id = "API-".$args{'function'};
602 $id =~ s/[^A-Za-z0-9]/-/g;
604 print "<refentry id=\"$id\">\n";
605 print "<refentryinfo>\n";
606 print " <title>LINUX</title>\n";
607 print " <productname>Kernel Hackers Manual</productname>\n";
608 print " <date>$man_date</date>\n";
609 print "</refentryinfo>\n";
610 print "<refmeta>\n";
611 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
612 print " <manvolnum>9</manvolnum>\n";
613 print " <refmiscinfo class=\"version\">" . get_kernel_version() . "</refmiscinfo>\n";
614 print "</refmeta>\n";
615 print "<refnamediv>\n";
616 print " <refname>".$args{'function'}."</refname>\n";
617 print " <refpurpose>\n";
618 print " ";
619 output_highlight ($args{'purpose'});
620 print " </refpurpose>\n";
621 print "</refnamediv>\n";
623 print "<refsynopsisdiv>\n";
624 print " <title>Synopsis</title>\n";
625 print " <funcsynopsis><funcprototype>\n";
626 print " <funcdef>".$args{'functiontype'}." ";
627 print "<function>".$args{'function'}." </function></funcdef>\n";
629 $count = 0;
630 if ($#{$args{'parameterlist'}} >= 0) {
631 foreach $parameter (@{$args{'parameterlist'}}) {
632 $type = $args{'parametertypes'}{$parameter};
633 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
634 # pointer-to-function
635 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
636 print " <funcparams>$2</funcparams></paramdef>\n";
637 } else {
638 print " <paramdef>".$type;
639 print " <parameter>$parameter</parameter></paramdef>\n";
642 } else {
643 print " <void/>\n";
645 print " </funcprototype></funcsynopsis>\n";
646 print "</refsynopsisdiv>\n";
648 # print parameters
649 print "<refsect1>\n <title>Arguments</title>\n";
650 if ($#{$args{'parameterlist'}} >= 0) {
651 print " <variablelist>\n";
652 foreach $parameter (@{$args{'parameterlist'}}) {
653 my $parameter_name = $parameter;
654 $parameter_name =~ s/\[.*//;
656 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
657 print " <listitem>\n <para>\n";
658 $lineprefix=" ";
659 output_highlight($args{'parameterdescs'}{$parameter_name});
660 print " </para>\n </listitem>\n </varlistentry>\n";
662 print " </variablelist>\n";
663 } else {
664 print " <para>\n None\n </para>\n";
666 print "</refsect1>\n";
668 output_section_xml(@_);
669 print "</refentry>\n\n";
672 # output struct in XML DocBook
673 sub output_struct_xml(%) {
674 my %args = %{$_[0]};
675 my ($parameter, $section);
676 my $id;
678 $id = "API-struct-".$args{'struct'};
679 $id =~ s/[^A-Za-z0-9]/-/g;
681 print "<refentry id=\"$id\">\n";
682 print "<refentryinfo>\n";
683 print " <title>LINUX</title>\n";
684 print " <productname>Kernel Hackers Manual</productname>\n";
685 print " <date>$man_date</date>\n";
686 print "</refentryinfo>\n";
687 print "<refmeta>\n";
688 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
689 print " <manvolnum>9</manvolnum>\n";
690 print " <refmiscinfo class=\"version\">" . get_kernel_version() . "</refmiscinfo>\n";
691 print "</refmeta>\n";
692 print "<refnamediv>\n";
693 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
694 print " <refpurpose>\n";
695 print " ";
696 output_highlight ($args{'purpose'});
697 print " </refpurpose>\n";
698 print "</refnamediv>\n";
700 print "<refsynopsisdiv>\n";
701 print " <title>Synopsis</title>\n";
702 print " <programlisting>\n";
703 print $args{'type'}." ".$args{'struct'}." {\n";
704 foreach $parameter (@{$args{'parameterlist'}}) {
705 if ($parameter =~ /^#/) {
706 print "$parameter\n";
707 next;
710 my $parameter_name = $parameter;
711 $parameter_name =~ s/\[.*//;
713 defined($args{'parameterdescs'}{$parameter_name}) || next;
714 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
715 $type = $args{'parametertypes'}{$parameter};
716 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
717 # pointer-to-function
718 print " $1 $parameter) ($2);\n";
719 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
720 print " $1 $parameter$2;\n";
721 } else {
722 print " ".$type." ".$parameter.";\n";
725 print "};";
726 print " </programlisting>\n";
727 print "</refsynopsisdiv>\n";
729 print " <refsect1>\n";
730 print " <title>Members</title>\n";
732 print " <variablelist>\n";
733 foreach $parameter (@{$args{'parameterlist'}}) {
734 ($parameter =~ /^#/) && next;
736 my $parameter_name = $parameter;
737 $parameter_name =~ s/\[.*//;
739 defined($args{'parameterdescs'}{$parameter_name}) || next;
740 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
741 print " <varlistentry>";
742 print " <term>$parameter</term>\n";
743 print " <listitem><para>\n";
744 output_highlight($args{'parameterdescs'}{$parameter_name});
745 print " </para></listitem>\n";
746 print " </varlistentry>\n";
748 print " </variablelist>\n";
749 print " </refsect1>\n";
751 output_section_xml(@_);
753 print "</refentry>\n\n";
756 # output enum in XML DocBook
757 sub output_enum_xml(%) {
758 my %args = %{$_[0]};
759 my ($parameter, $section);
760 my $count;
761 my $id;
763 $id = "API-enum-".$args{'enum'};
764 $id =~ s/[^A-Za-z0-9]/-/g;
766 print "<refentry id=\"$id\">\n";
767 print "<refentryinfo>\n";
768 print " <title>LINUX</title>\n";
769 print " <productname>Kernel Hackers Manual</productname>\n";
770 print " <date>$man_date</date>\n";
771 print "</refentryinfo>\n";
772 print "<refmeta>\n";
773 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
774 print " <manvolnum>9</manvolnum>\n";
775 print " <refmiscinfo class=\"version\">" . get_kernel_version() . "</refmiscinfo>\n";
776 print "</refmeta>\n";
777 print "<refnamediv>\n";
778 print " <refname>enum ".$args{'enum'}."</refname>\n";
779 print " <refpurpose>\n";
780 print " ";
781 output_highlight ($args{'purpose'});
782 print " </refpurpose>\n";
783 print "</refnamediv>\n";
785 print "<refsynopsisdiv>\n";
786 print " <title>Synopsis</title>\n";
787 print " <programlisting>\n";
788 print "enum ".$args{'enum'}." {\n";
789 $count = 0;
790 foreach $parameter (@{$args{'parameterlist'}}) {
791 print " $parameter";
792 if ($count != $#{$args{'parameterlist'}}) {
793 $count++;
794 print ",";
796 print "\n";
798 print "};";
799 print " </programlisting>\n";
800 print "</refsynopsisdiv>\n";
802 print "<refsect1>\n";
803 print " <title>Constants</title>\n";
804 print " <variablelist>\n";
805 foreach $parameter (@{$args{'parameterlist'}}) {
806 my $parameter_name = $parameter;
807 $parameter_name =~ s/\[.*//;
809 print " <varlistentry>";
810 print " <term>$parameter</term>\n";
811 print " <listitem><para>\n";
812 output_highlight($args{'parameterdescs'}{$parameter_name});
813 print " </para></listitem>\n";
814 print " </varlistentry>\n";
816 print " </variablelist>\n";
817 print "</refsect1>\n";
819 output_section_xml(@_);
821 print "</refentry>\n\n";
824 # output typedef in XML DocBook
825 sub output_typedef_xml(%) {
826 my %args = %{$_[0]};
827 my ($parameter, $section);
828 my $id;
830 $id = "API-typedef-".$args{'typedef'};
831 $id =~ s/[^A-Za-z0-9]/-/g;
833 print "<refentry id=\"$id\">\n";
834 print "<refentryinfo>\n";
835 print " <title>LINUX</title>\n";
836 print " <productname>Kernel Hackers Manual</productname>\n";
837 print " <date>$man_date</date>\n";
838 print "</refentryinfo>\n";
839 print "<refmeta>\n";
840 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
841 print " <manvolnum>9</manvolnum>\n";
842 print "</refmeta>\n";
843 print "<refnamediv>\n";
844 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
845 print " <refpurpose>\n";
846 print " ";
847 output_highlight ($args{'purpose'});
848 print " </refpurpose>\n";
849 print "</refnamediv>\n";
851 print "<refsynopsisdiv>\n";
852 print " <title>Synopsis</title>\n";
853 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
854 print "</refsynopsisdiv>\n";
856 output_section_xml(@_);
858 print "</refentry>\n\n";
861 # output in XML DocBook
862 sub output_intro_xml(%) {
863 my %args = %{$_[0]};
864 my ($parameter, $section);
865 my $count;
867 my $id = $args{'module'};
868 $id =~ s/[^A-Za-z0-9]/-/g;
870 # print out each section
871 $lineprefix=" ";
872 foreach $section (@{$args{'sectionlist'}}) {
873 print "<refsect1>\n <title>$section</title>\n <para>\n";
874 if ($section =~ m/EXAMPLE/i) {
875 print "<example><para>\n";
877 output_highlight($args{'sections'}{$section});
878 if ($section =~ m/EXAMPLE/i) {
879 print "</para></example>\n";
881 print " </para>\n</refsect1>\n";
884 print "\n\n";
887 # output in XML DocBook
888 sub output_function_gnome {
889 my %args = %{$_[0]};
890 my ($parameter, $section);
891 my $count;
892 my $id;
894 $id = $args{'module'}."-".$args{'function'};
895 $id =~ s/[^A-Za-z0-9]/-/g;
897 print "<sect2>\n";
898 print " <title id=\"$id\">".$args{'function'}."</title>\n";
900 print " <funcsynopsis>\n";
901 print " <funcdef>".$args{'functiontype'}." ";
902 print "<function>".$args{'function'}." ";
903 print "</function></funcdef>\n";
905 $count = 0;
906 if ($#{$args{'parameterlist'}} >= 0) {
907 foreach $parameter (@{$args{'parameterlist'}}) {
908 $type = $args{'parametertypes'}{$parameter};
909 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
910 # pointer-to-function
911 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
912 print " <funcparams>$2</funcparams></paramdef>\n";
913 } else {
914 print " <paramdef>".$type;
915 print " <parameter>$parameter</parameter></paramdef>\n";
918 } else {
919 print " <void>\n";
921 print " </funcsynopsis>\n";
922 if ($#{$args{'parameterlist'}} >= 0) {
923 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
924 print "<tgroup cols=\"2\">\n";
925 print "<colspec colwidth=\"2*\">\n";
926 print "<colspec colwidth=\"8*\">\n";
927 print "<tbody>\n";
928 foreach $parameter (@{$args{'parameterlist'}}) {
929 my $parameter_name = $parameter;
930 $parameter_name =~ s/\[.*//;
932 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
933 print " <entry>\n";
934 $lineprefix=" ";
935 output_highlight($args{'parameterdescs'}{$parameter_name});
936 print " </entry></row>\n";
938 print " </tbody></tgroup></informaltable>\n";
939 } else {
940 print " <para>\n None\n </para>\n";
943 # print out each section
944 $lineprefix=" ";
945 foreach $section (@{$args{'sectionlist'}}) {
946 print "<simplesect>\n <title>$section</title>\n";
947 if ($section =~ m/EXAMPLE/i) {
948 print "<example><programlisting>\n";
949 } else {
951 print "<para>\n";
952 output_highlight($args{'sections'}{$section});
953 print "</para>\n";
954 if ($section =~ m/EXAMPLE/i) {
955 print "</programlisting></example>\n";
956 } else {
958 print " </simplesect>\n";
961 print "</sect2>\n\n";
965 # output function in man
966 sub output_function_man(%) {
967 my %args = %{$_[0]};
968 my ($parameter, $section);
969 my $count;
971 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
973 print ".SH NAME\n";
974 print $args{'function'}." \\- ".$args{'purpose'}."\n";
976 print ".SH SYNOPSIS\n";
977 if ($args{'functiontype'} ne "") {
978 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
979 } else {
980 print ".B \"".$args{'function'}."\n";
982 $count = 0;
983 my $parenth = "(";
984 my $post = ",";
985 foreach my $parameter (@{$args{'parameterlist'}}) {
986 if ($count == $#{$args{'parameterlist'}}) {
987 $post = ");";
989 $type = $args{'parametertypes'}{$parameter};
990 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
991 # pointer-to-function
992 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
993 } else {
994 $type =~ s/([^\*])$/$1 /;
995 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
997 $count++;
998 $parenth = "";
1001 print ".SH ARGUMENTS\n";
1002 foreach $parameter (@{$args{'parameterlist'}}) {
1003 my $parameter_name = $parameter;
1004 $parameter_name =~ s/\[.*//;
1006 print ".IP \"".$parameter."\" 12\n";
1007 output_highlight($args{'parameterdescs'}{$parameter_name});
1009 foreach $section (@{$args{'sectionlist'}}) {
1010 print ".SH \"", uc $section, "\"\n";
1011 output_highlight($args{'sections'}{$section});
1016 # output enum in man
1017 sub output_enum_man(%) {
1018 my %args = %{$_[0]};
1019 my ($parameter, $section);
1020 my $count;
1022 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1024 print ".SH NAME\n";
1025 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1027 print ".SH SYNOPSIS\n";
1028 print "enum ".$args{'enum'}." {\n";
1029 $count = 0;
1030 foreach my $parameter (@{$args{'parameterlist'}}) {
1031 print ".br\n.BI \" $parameter\"\n";
1032 if ($count == $#{$args{'parameterlist'}}) {
1033 print "\n};\n";
1034 last;
1036 else {
1037 print ", \n.br\n";
1039 $count++;
1042 print ".SH Constants\n";
1043 foreach $parameter (@{$args{'parameterlist'}}) {
1044 my $parameter_name = $parameter;
1045 $parameter_name =~ s/\[.*//;
1047 print ".IP \"".$parameter."\" 12\n";
1048 output_highlight($args{'parameterdescs'}{$parameter_name});
1050 foreach $section (@{$args{'sectionlist'}}) {
1051 print ".SH \"$section\"\n";
1052 output_highlight($args{'sections'}{$section});
1057 # output struct in man
1058 sub output_struct_man(%) {
1059 my %args = %{$_[0]};
1060 my ($parameter, $section);
1062 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1064 print ".SH NAME\n";
1065 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1067 print ".SH SYNOPSIS\n";
1068 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1070 foreach my $parameter (@{$args{'parameterlist'}}) {
1071 if ($parameter =~ /^#/) {
1072 print ".BI \"$parameter\"\n.br\n";
1073 next;
1075 my $parameter_name = $parameter;
1076 $parameter_name =~ s/\[.*//;
1078 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1079 $type = $args{'parametertypes'}{$parameter};
1080 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1081 # pointer-to-function
1082 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1083 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1084 # bitfield
1085 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1086 } else {
1087 $type =~ s/([^\*])$/$1 /;
1088 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1090 print "\n.br\n";
1092 print "};\n.br\n";
1094 print ".SH Members\n";
1095 foreach $parameter (@{$args{'parameterlist'}}) {
1096 ($parameter =~ /^#/) && next;
1098 my $parameter_name = $parameter;
1099 $parameter_name =~ s/\[.*//;
1101 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1102 print ".IP \"".$parameter."\" 12\n";
1103 output_highlight($args{'parameterdescs'}{$parameter_name});
1105 foreach $section (@{$args{'sectionlist'}}) {
1106 print ".SH \"$section\"\n";
1107 output_highlight($args{'sections'}{$section});
1112 # output typedef in man
1113 sub output_typedef_man(%) {
1114 my %args = %{$_[0]};
1115 my ($parameter, $section);
1117 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1119 print ".SH NAME\n";
1120 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1122 foreach $section (@{$args{'sectionlist'}}) {
1123 print ".SH \"$section\"\n";
1124 output_highlight($args{'sections'}{$section});
1128 sub output_intro_man(%) {
1129 my %args = %{$_[0]};
1130 my ($parameter, $section);
1131 my $count;
1133 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1135 foreach $section (@{$args{'sectionlist'}}) {
1136 print ".SH \"$section\"\n";
1137 output_highlight($args{'sections'}{$section});
1142 # output in text
1143 sub output_function_text(%) {
1144 my %args = %{$_[0]};
1145 my ($parameter, $section);
1146 my $start;
1148 print "Name:\n\n";
1149 print $args{'function'}." - ".$args{'purpose'}."\n";
1151 print "\nSynopsis:\n\n";
1152 if ($args{'functiontype'} ne "") {
1153 $start = $args{'functiontype'}." ".$args{'function'}." (";
1154 } else {
1155 $start = $args{'function'}." (";
1157 print $start;
1159 my $count = 0;
1160 foreach my $parameter (@{$args{'parameterlist'}}) {
1161 $type = $args{'parametertypes'}{$parameter};
1162 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1163 # pointer-to-function
1164 print $1.$parameter.") (".$2;
1165 } else {
1166 print $type." ".$parameter;
1168 if ($count != $#{$args{'parameterlist'}}) {
1169 $count++;
1170 print ",\n";
1171 print " " x length($start);
1172 } else {
1173 print ");\n\n";
1177 print "Arguments:\n\n";
1178 foreach $parameter (@{$args{'parameterlist'}}) {
1179 my $parameter_name = $parameter;
1180 $parameter_name =~ s/\[.*//;
1182 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1184 output_section_text(@_);
1187 #output sections in text
1188 sub output_section_text(%) {
1189 my %args = %{$_[0]};
1190 my $section;
1192 print "\n";
1193 foreach $section (@{$args{'sectionlist'}}) {
1194 print "$section:\n\n";
1195 output_highlight($args{'sections'}{$section});
1197 print "\n\n";
1200 # output enum in text
1201 sub output_enum_text(%) {
1202 my %args = %{$_[0]};
1203 my ($parameter);
1204 my $count;
1205 print "Enum:\n\n";
1207 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1208 print "enum ".$args{'enum'}." {\n";
1209 $count = 0;
1210 foreach $parameter (@{$args{'parameterlist'}}) {
1211 print "\t$parameter";
1212 if ($count != $#{$args{'parameterlist'}}) {
1213 $count++;
1214 print ",";
1216 print "\n";
1218 print "};\n\n";
1220 print "Constants:\n\n";
1221 foreach $parameter (@{$args{'parameterlist'}}) {
1222 print "$parameter\n\t";
1223 print $args{'parameterdescs'}{$parameter}."\n";
1226 output_section_text(@_);
1229 # output typedef in text
1230 sub output_typedef_text(%) {
1231 my %args = %{$_[0]};
1232 my ($parameter);
1233 my $count;
1234 print "Typedef:\n\n";
1236 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1237 output_section_text(@_);
1240 # output struct as text
1241 sub output_struct_text(%) {
1242 my %args = %{$_[0]};
1243 my ($parameter);
1245 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1246 print $args{'type'}." ".$args{'struct'}." {\n";
1247 foreach $parameter (@{$args{'parameterlist'}}) {
1248 if ($parameter =~ /^#/) {
1249 print "$parameter\n";
1250 next;
1253 my $parameter_name = $parameter;
1254 $parameter_name =~ s/\[.*//;
1256 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1257 $type = $args{'parametertypes'}{$parameter};
1258 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1259 # pointer-to-function
1260 print "\t$1 $parameter) ($2);\n";
1261 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1262 print "\t$1 $parameter$2;\n";
1263 } else {
1264 print "\t".$type." ".$parameter.";\n";
1267 print "};\n\n";
1269 print "Members:\n\n";
1270 foreach $parameter (@{$args{'parameterlist'}}) {
1271 ($parameter =~ /^#/) && next;
1273 my $parameter_name = $parameter;
1274 $parameter_name =~ s/\[.*//;
1276 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1277 print "$parameter\n\t";
1278 print $args{'parameterdescs'}{$parameter_name}."\n";
1280 print "\n";
1281 output_section_text(@_);
1284 sub output_intro_text(%) {
1285 my %args = %{$_[0]};
1286 my ($parameter, $section);
1288 foreach $section (@{$args{'sectionlist'}}) {
1289 print " $section:\n";
1290 print " -> ";
1291 output_highlight($args{'sections'}{$section});
1296 # generic output function for all types (function, struct/union, typedef, enum);
1297 # calls the generated, variable output_ function name based on
1298 # functype and output_mode
1299 sub output_declaration {
1300 no strict 'refs';
1301 my $name = shift;
1302 my $functype = shift;
1303 my $func = "output_${functype}_$output_mode";
1304 if (($function_only==0) ||
1305 ( $function_only == 1 && defined($function_table{$name})) ||
1306 ( $function_only == 2 && !defined($function_table{$name})))
1308 &$func(@_);
1309 $section_counter++;
1314 # generic output function - calls the right one based on current output mode.
1315 sub output_intro {
1316 no strict 'refs';
1317 my $func = "output_intro_".$output_mode;
1318 &$func(@_);
1319 $section_counter++;
1323 # takes a declaration (struct, union, enum, typedef) and
1324 # invokes the right handler. NOT called for functions.
1325 sub dump_declaration($$) {
1326 no strict 'refs';
1327 my ($prototype, $file) = @_;
1328 my $func = "dump_".$decl_type;
1329 &$func(@_);
1332 sub dump_union($$) {
1333 dump_struct(@_);
1336 sub dump_struct($$) {
1337 my $x = shift;
1338 my $file = shift;
1340 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1341 $declaration_name = $2;
1342 my $members = $3;
1344 # ignore embedded structs or unions
1345 $members =~ s/{.*?}//g;
1347 # ignore members marked private:
1348 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1349 $members =~ s/\/\*.*?private:.*//gos;
1350 # strip comments:
1351 $members =~ s/\/\*.*?\*\///gos;
1353 create_parameterlist($members, ';', $file);
1355 output_declaration($declaration_name,
1356 'struct',
1357 {'struct' => $declaration_name,
1358 'module' => $modulename,
1359 'parameterlist' => \@parameterlist,
1360 'parameterdescs' => \%parameterdescs,
1361 'parametertypes' => \%parametertypes,
1362 'sectionlist' => \@sectionlist,
1363 'sections' => \%sections,
1364 'purpose' => $declaration_purpose,
1365 'type' => $decl_type
1368 else {
1369 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1370 ++$errors;
1374 sub dump_enum($$) {
1375 my $x = shift;
1376 my $file = shift;
1378 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1379 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1380 $declaration_name = $1;
1381 my $members = $2;
1383 foreach my $arg (split ',', $members) {
1384 $arg =~ s/^\s*(\w+).*/$1/;
1385 push @parameterlist, $arg;
1386 if (!$parameterdescs{$arg}) {
1387 $parameterdescs{$arg} = $undescribed;
1388 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1389 "not described in enum '$declaration_name'\n";
1394 output_declaration($declaration_name,
1395 'enum',
1396 {'enum' => $declaration_name,
1397 'module' => $modulename,
1398 'parameterlist' => \@parameterlist,
1399 'parameterdescs' => \%parameterdescs,
1400 'sectionlist' => \@sectionlist,
1401 'sections' => \%sections,
1402 'purpose' => $declaration_purpose
1405 else {
1406 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1407 ++$errors;
1411 sub dump_typedef($$) {
1412 my $x = shift;
1413 my $file = shift;
1415 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1416 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1417 $x =~ s/\(*.\)\s*;$/;/;
1418 $x =~ s/\[*.\]\s*;$/;/;
1421 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1422 $declaration_name = $1;
1424 output_declaration($declaration_name,
1425 'typedef',
1426 {'typedef' => $declaration_name,
1427 'module' => $modulename,
1428 'sectionlist' => \@sectionlist,
1429 'sections' => \%sections,
1430 'purpose' => $declaration_purpose
1433 else {
1434 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1435 ++$errors;
1439 sub create_parameterlist($$$) {
1440 my $args = shift;
1441 my $splitter = shift;
1442 my $file = shift;
1443 my $type;
1444 my $param;
1446 # temporarily replace commas inside function pointer definition
1447 while ($args =~ /(\([^\),]+),/) {
1448 $args =~ s/(\([^\),]+),/$1#/g;
1451 foreach my $arg (split($splitter, $args)) {
1452 # strip comments
1453 $arg =~ s/\/\*.*\*\///;
1454 # strip leading/trailing spaces
1455 $arg =~ s/^\s*//;
1456 $arg =~ s/\s*$//;
1457 $arg =~ s/\s+/ /;
1459 if ($arg =~ /^#/) {
1460 # Treat preprocessor directive as a typeless variable just to fill
1461 # corresponding data structures "correctly". Catch it later in
1462 # output_* subs.
1463 push_parameter($arg, "", $file);
1464 } elsif ($arg =~ m/\(.*\*/) {
1465 # pointer-to-function
1466 $arg =~ tr/#/,/;
1467 $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/;
1468 $param = $1;
1469 $type = $arg;
1470 $type =~ s/([^\(]+\(\*)$param/$1/;
1471 push_parameter($param, $type, $file);
1472 } elsif ($arg) {
1473 $arg =~ s/\s*:\s*/:/g;
1474 $arg =~ s/\s*\[/\[/g;
1476 my @args = split('\s*,\s*', $arg);
1477 if ($args[0] =~ m/\*/) {
1478 $args[0] =~ s/(\*+)\s*/ $1/;
1481 my @first_arg;
1482 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1483 shift @args;
1484 push(@first_arg, split('\s+', $1));
1485 push(@first_arg, $2);
1486 } else {
1487 @first_arg = split('\s+', shift @args);
1490 unshift(@args, pop @first_arg);
1491 $type = join " ", @first_arg;
1493 foreach $param (@args) {
1494 if ($param =~ m/^(\*+)\s*(.*)/) {
1495 push_parameter($2, "$type $1", $file);
1497 elsif ($param =~ m/(.*?):(\d+)/) {
1498 push_parameter($1, "$type:$2", $file)
1500 else {
1501 push_parameter($param, $type, $file);
1508 sub push_parameter($$$) {
1509 my $param = shift;
1510 my $type = shift;
1511 my $file = shift;
1512 my $anon = 0;
1514 my $param_name = $param;
1515 $param_name =~ s/\[.*//;
1517 if ($type eq "" && $param =~ /\.\.\.$/)
1519 $type="";
1520 $parameterdescs{$param} = "variable arguments";
1522 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1524 $type="";
1525 $param="void";
1526 $parameterdescs{void} = "no arguments";
1528 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1529 # handle unnamed (anonymous) union or struct:
1531 $type = $param;
1532 $param = "{unnamed_" . $param. "}";
1533 $parameterdescs{$param} = "anonymous\n";
1534 $anon = 1;
1537 # warn if parameter has no description
1538 # (but ignore ones starting with # as these are not parameters
1539 # but inline preprocessor statements);
1540 # also ignore unnamed structs/unions;
1541 if (!$anon) {
1542 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1544 $parameterdescs{$param_name} = $undescribed;
1546 if (($type eq 'function') || ($type eq 'enum')) {
1547 print STDERR "Warning(${file}:$.): Function parameter ".
1548 "or member '$param' not " .
1549 "described in '$declaration_name'\n";
1551 print STDERR "Warning(${file}:$.):".
1552 " No description found for parameter '$param'\n";
1553 ++$warnings;
1557 push @parameterlist, $param;
1558 $parametertypes{$param} = $type;
1562 # takes a function prototype and the name of the current file being
1563 # processed and spits out all the details stored in the global
1564 # arrays/hashes.
1565 sub dump_function($$) {
1566 my $prototype = shift;
1567 my $file = shift;
1569 $prototype =~ s/^static +//;
1570 $prototype =~ s/^extern +//;
1571 $prototype =~ s/^fastcall +//;
1572 $prototype =~ s/^asmlinkage +//;
1573 $prototype =~ s/^inline +//;
1574 $prototype =~ s/^__inline__ +//;
1575 $prototype =~ s/^__inline +//;
1576 $prototype =~ s/^__always_inline +//;
1577 $prototype =~ s/^noinline +//;
1578 $prototype =~ s/__devinit +//;
1579 $prototype =~ s/^#define\s+//; #ak added
1580 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1582 # Yes, this truly is vile. We are looking for:
1583 # 1. Return type (may be nothing if we're looking at a macro)
1584 # 2. Function name
1585 # 3. Function parameters.
1587 # All the while we have to watch out for function pointer parameters
1588 # (which IIRC is what the two sections are for), C types (these
1589 # regexps don't even start to express all the possibilities), and
1590 # so on.
1592 # If you mess with these regexps, it's a good idea to check that
1593 # the following functions' documentation still comes out right:
1594 # - parport_register_device (function pointer parameters)
1595 # - atomic_set (macro)
1596 # - pci_match_device, __copy_to_user (long return type)
1598 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1599 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1600 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1601 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1602 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1603 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1604 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1605 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1606 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1607 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1608 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1609 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1610 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1611 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1612 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1613 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1614 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1615 $return_type = $1;
1616 $declaration_name = $2;
1617 my $args = $3;
1619 create_parameterlist($args, ',', $file);
1620 } else {
1621 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1622 ++$errors;
1623 return;
1626 output_declaration($declaration_name,
1627 'function',
1628 {'function' => $declaration_name,
1629 'module' => $modulename,
1630 'functiontype' => $return_type,
1631 'parameterlist' => \@parameterlist,
1632 'parameterdescs' => \%parameterdescs,
1633 'parametertypes' => \%parametertypes,
1634 'sectionlist' => \@sectionlist,
1635 'sections' => \%sections,
1636 'purpose' => $declaration_purpose
1640 sub process_file($);
1642 # Read the file that maps relative names to absolute names for
1643 # separate source and object directories and for shadow trees.
1644 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1645 my ($relname, $absname);
1646 while(<SOURCE_MAP>) {
1647 chop();
1648 ($relname, $absname) = (split())[0..1];
1649 $relname =~ s:^/+::;
1650 $source_map{$relname} = $absname;
1652 close(SOURCE_MAP);
1655 if ($filelist) {
1656 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1657 while(<FLIST>) {
1658 chop;
1659 process_file($_);
1663 foreach (@ARGV) {
1664 chomp;
1665 process_file($_);
1667 if ($verbose && $errors) {
1668 print STDERR "$errors errors\n";
1670 if ($verbose && $warnings) {
1671 print STDERR "$warnings warnings\n";
1674 exit($errors);
1676 sub reset_state {
1677 $function = "";
1678 %constants = ();
1679 %parameterdescs = ();
1680 %parametertypes = ();
1681 @parameterlist = ();
1682 %sections = ();
1683 @sectionlist = ();
1684 $prototype = "";
1686 $state = 0;
1689 sub process_state3_function($$) {
1690 my $x = shift;
1691 my $file = shift;
1693 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1694 # do nothing
1696 elsif ($x =~ /([^\{]*)/) {
1697 $prototype .= $1;
1699 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1700 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1701 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1702 $prototype =~ s@^\s+@@gos; # strip leading spaces
1703 dump_function($prototype,$file);
1704 reset_state();
1708 sub process_state3_type($$) {
1709 my $x = shift;
1710 my $file = shift;
1712 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1713 $x =~ s@^\s+@@gos; # strip leading spaces
1714 $x =~ s@\s+$@@gos; # strip trailing spaces
1715 if ($x =~ /^#/) {
1716 # To distinguish preprocessor directive from regular declaration later.
1717 $x .= ";";
1720 while (1) {
1721 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1722 $prototype .= $1 . $2;
1723 ($2 eq '{') && $brcount++;
1724 ($2 eq '}') && $brcount--;
1725 if (($2 eq ';') && ($brcount == 0)) {
1726 dump_declaration($prototype,$file);
1727 reset_state();
1728 last;
1730 $x = $3;
1731 } else {
1732 $prototype .= $x;
1733 last;
1738 # replace <, >, and &
1739 sub xml_escape($) {
1740 my $text = shift;
1741 if (($output_mode eq "text") || ($output_mode eq "man")) {
1742 return $text;
1744 $text =~ s/\&/\\\\\\amp;/g;
1745 $text =~ s/\</\\\\\\lt;/g;
1746 $text =~ s/\>/\\\\\\gt;/g;
1747 return $text;
1750 sub process_file($) {
1751 my $file;
1752 my $identifier;
1753 my $func;
1754 my $descr;
1755 my $initial_section_counter = $section_counter;
1757 if (defined($ENV{'SRCTREE'})) {
1758 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1760 else {
1761 $file = "@_";
1763 if (defined($source_map{$file})) {
1764 $file = $source_map{$file};
1767 if (!open(IN,"<$file")) {
1768 print STDERR "Error: Cannot open file $file\n";
1769 ++$errors;
1770 return;
1773 $section_counter = 0;
1774 while (<IN>) {
1775 if ($state == 0) {
1776 if (/$doc_start/o) {
1777 $state = 1; # next line is always the function name
1778 $in_doc_sect = 0;
1780 } elsif ($state == 1) { # this line is the function name (always)
1781 if (/$doc_block/o) {
1782 $state = 4;
1783 $contents = "";
1784 if ( $1 eq "" ) {
1785 $section = $section_intro;
1786 } else {
1787 $section = $1;
1790 elsif (/$doc_decl/o) {
1791 $identifier = $1;
1792 if (/\s*([\w\s]+?)\s*-/) {
1793 $identifier = $1;
1796 $state = 2;
1797 if (/-(.*)/) {
1798 # strip leading/trailing/multiple spaces #RDD:T:
1799 $descr= $1;
1800 $descr =~ s/^\s*//;
1801 $descr =~ s/\s*$//;
1802 $descr =~ s/\s+/ /;
1803 $declaration_purpose = xml_escape($descr);
1804 } else {
1805 $declaration_purpose = "";
1807 if ($identifier =~ m/^struct/) {
1808 $decl_type = 'struct';
1809 } elsif ($identifier =~ m/^union/) {
1810 $decl_type = 'union';
1811 } elsif ($identifier =~ m/^enum/) {
1812 $decl_type = 'enum';
1813 } elsif ($identifier =~ m/^typedef/) {
1814 $decl_type = 'typedef';
1815 } else {
1816 $decl_type = 'function';
1819 if ($verbose) {
1820 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1822 } else {
1823 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1824 " - I thought it was a doc line\n";
1825 ++$warnings;
1826 $state = 0;
1828 } elsif ($state == 2) { # look for head: lines, and include content
1829 if (/$doc_sect/o) {
1830 $newsection = $1;
1831 $newcontents = $2;
1833 if ($contents ne "") {
1834 if (!$in_doc_sect && $verbose) {
1835 print STDERR "Warning(${file}:$.): contents before sections\n";
1836 ++$warnings;
1838 dump_section($section, xml_escape($contents));
1839 $section = $section_default;
1842 $in_doc_sect = 1;
1843 $contents = $newcontents;
1844 if ($contents ne "") {
1845 while ((substr($contents, 0, 1) eq " ") ||
1846 substr($contents, 0, 1) eq "\t") {
1847 $contents = substr($contents, 1);
1849 $contents .= "\n";
1851 $section = $newsection;
1852 } elsif (/$doc_end/) {
1854 if ($contents ne "") {
1855 dump_section($section, xml_escape($contents));
1856 $section = $section_default;
1857 $contents = "";
1860 $prototype = "";
1861 $state = 3;
1862 $brcount = 0;
1863 # print STDERR "end of doc comment, looking for prototype\n";
1864 } elsif (/$doc_content/) {
1865 # miguel-style comment kludge, look for blank lines after
1866 # @parameter line to signify start of description
1867 if ($1 eq "" &&
1868 ($section =~ m/^@/ || $section eq $section_context)) {
1869 dump_section($section, xml_escape($contents));
1870 $section = $section_default;
1871 $contents = "";
1872 } else {
1873 $contents .= $1."\n";
1875 } else {
1876 # i dont know - bad line? ignore.
1877 print STDERR "Warning(${file}:$.): bad line: $_";
1878 ++$warnings;
1880 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1881 if ($decl_type eq 'function') {
1882 process_state3_function($_, $file);
1883 } else {
1884 process_state3_type($_, $file);
1886 } elsif ($state == 4) {
1887 # Documentation block
1888 if (/$doc_block/) {
1889 dump_section($section, $contents);
1890 output_intro({'sectionlist' => \@sectionlist,
1891 'sections' => \%sections });
1892 $contents = "";
1893 $function = "";
1894 %constants = ();
1895 %parameterdescs = ();
1896 %parametertypes = ();
1897 @parameterlist = ();
1898 %sections = ();
1899 @sectionlist = ();
1900 $prototype = "";
1901 if ( $1 eq "" ) {
1902 $section = $section_intro;
1903 } else {
1904 $section = $1;
1907 elsif (/$doc_end/)
1909 dump_section($section, $contents);
1910 output_intro({'sectionlist' => \@sectionlist,
1911 'sections' => \%sections });
1912 $contents = "";
1913 $function = "";
1914 %constants = ();
1915 %parameterdescs = ();
1916 %parametertypes = ();
1917 @parameterlist = ();
1918 %sections = ();
1919 @sectionlist = ();
1920 $prototype = "";
1921 $state = 0;
1923 elsif (/$doc_content/)
1925 if ( $1 eq "" )
1927 $contents .= $blankline;
1929 else
1931 $contents .= $1 . "\n";
1936 if ($initial_section_counter == $section_counter) {
1937 print STDERR "Warning(${file}): no structured comments found\n";
1938 if ($output_mode eq "xml") {
1939 # The template wants at least one RefEntry here; make one.
1940 print "<refentry>\n";
1941 print " <refnamediv>\n";
1942 print " <refname>\n";
1943 print " ${file}\n";
1944 print " </refname>\n";
1945 print " <refpurpose>\n";
1946 print " Document generation inconsistency\n";
1947 print " </refpurpose>\n";
1948 print " </refnamediv>\n";
1949 print " <refsect1>\n";
1950 print " <title>\n";
1951 print " Oops\n";
1952 print " </title>\n";
1953 print " <warning>\n";
1954 print " <para>\n";
1955 print " The template for this document tried to insert\n";
1956 print " the structured comment from the file\n";
1957 print " <filename>${file}</filename> at this point,\n";
1958 print " but none was found.\n";
1959 print " This dummy section is inserted to allow\n";
1960 print " generation to continue.\n";
1961 print " </para>\n";
1962 print " </warning>\n";
1963 print " </refsect1>\n";
1964 print "</refentry>\n";