Merge tag 'firewire-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[deliverable/linux.git] / scripts / kernel-doc
CommitLineData
1da177e4
LT
1#!/usr/bin/perl -w
2
3use strict;
4
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 ##
70c95b00 8## Copyright (C) 2005-2012 Randy Dunlap ##
1da177e4
LT
9## ##
10## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11## Copyright (c) 2000 MontaVista Software, Inc. ##
12## ##
13## This software falls under the GNU General Public License. ##
14## Please read the COPYING file for more information ##
15
1da177e4
LT
16# 18/01/2001 - Cleanups
17# Functions prototyped as foo(void) same as foo()
18# Stop eval'ing where we don't need to.
19# -- huggie@earth.li
20
21# 27/06/2001 - Allowed whitespace after initial "/**" and
22# allowed comments before function declarations.
23# -- Christian Kreibich <ck@whoop.org>
24
25# Still to do:
26# - add perldoc documentation
27# - Look more closely at some of the scarier bits :)
28
29# 26/05/2001 - Support for separate source and object trees.
30# Return error code.
31# Keith Owens <kaos@ocs.com.au>
32
33# 23/09/2001 - Added support for typedefs, structs, enums and unions
34# Support for Context section; can be terminated using empty line
35# Small fixes (like spaces vs. \s in regex)
36# -- Tim Jansen <tim@tjansen.de>
37
38
39#
40# This will read a 'c' file and scan for embedded comments in the
41# style of gnome comments (+minor extensions - see below).
42#
43
44# Note: This only supports 'c'.
45
46# usage:
eda603f6 47# kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ]
1da177e4
LT
48# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
49# or
50# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
51#
52# Set output format using one of -docbook -html -text or -man. Default is man.
eda603f6 53# The -list format is for internal use by docproc.
1da177e4 54#
4b44595a
JB
55# -no-doc-sections
56# Do not output DOC: sections
57#
1da177e4 58# -function funcname
b112e0f7
JB
59# If set, then only generate documentation for the given function(s) or
60# DOC: section titles. All other functions and DOC: sections are ignored.
1da177e4
LT
61#
62# -nofunction funcname
b112e0f7
JB
63# If set, then only generate documentation for the other function(s)/DOC:
64# sections. Cannot be used together with -function (yes, that's a bug --
65# perl hackers can fix it 8))
1da177e4
LT
66#
67# c files - list of 'c' files to process
68#
69# All output goes to stdout, with errors to stderr.
70
71#
72# format of comments.
73# In the following table, (...)? signifies optional structure.
74# (...)* signifies 0 or more structure elements
75# /**
76# * function_name(:)? (- short description)?
77# (* @parameterx: (description of parameter x)?)*
78# (* a blank line)?
79# * (Description:)? (Description of function)?
80# * (section header: (section description)? )*
81# (*)?*/
82#
83# So .. the trivial example would be:
84#
85# /**
86# * my_function
b9d97328 87# */
1da177e4 88#
891dcd2f 89# If the Description: header tag is omitted, then there must be a blank line
1da177e4
LT
90# after the last parameter specification.
91# e.g.
92# /**
93# * my_function - does my stuff
94# * @my_arg: its mine damnit
95# *
3c3b809e 96# * Does my stuff explained.
1da177e4
LT
97# */
98#
99# or, could also use:
100# /**
101# * my_function - does my stuff
102# * @my_arg: its mine damnit
3c3b809e 103# * Description: Does my stuff explained.
1da177e4
LT
104# */
105# etc.
106#
b9d97328 107# Besides functions you can also write documentation for structs, unions,
3c3b809e
RD
108# enums and typedefs. Instead of the function name you must write the name
109# of the declaration; the struct/union/enum/typedef must always precede
110# the name. Nesting of declarations is not supported.
1da177e4
LT
111# Use the argument mechanism to document members or constants.
112# e.g.
113# /**
114# * struct my_struct - short description
115# * @a: first member
116# * @b: second member
3c3b809e 117# *
1da177e4
LT
118# * Longer description
119# */
120# struct my_struct {
121# int a;
122# int b;
aeec46b9
MW
123# /* private: */
124# int c;
1da177e4
LT
125# };
126#
127# All descriptions can be multiline, except the short function description.
3c3b809e
RD
128#
129# You can also add additional sections. When documenting kernel functions you
130# should document the "Context:" of the function, e.g. whether the functions
1da177e4 131# can be called form interrupts. Unlike other sections you can end it with an
3c3b809e
RD
132# empty line.
133# Example-sections should contain the string EXAMPLE so that they are marked
1da177e4
LT
134# appropriately in DocBook.
135#
136# Example:
137# /**
138# * user_function - function that can only be called in user context
139# * @a: some argument
140# * Context: !in_interrupt()
3c3b809e 141# *
1da177e4
LT
142# * Some description
143# * Example:
144# * user_function(22);
145# */
146# ...
147#
148#
149# All descriptive text is further processed, scanning for the following special
150# patterns, which are highlighted appropriately.
151#
152# 'funcname()' - function
153# '$ENVVAR' - environmental variable
154# '&struct_name' - name of a structure (up to two words including 'struct')
155# '@parameter' - name of a parameter
156# '%CONST' - name of a constant.
157
8484baaa
RD
158## init lots of data
159
1da177e4
LT
160my $errors = 0;
161my $warnings = 0;
5f8c7c98 162my $anon_struct_union = 0;
1da177e4
LT
163
164# match expressions used to find embedded type information
165my $type_constant = '\%([-_\w]+)';
166my $type_func = '(\w+)\(\)';
167my $type_param = '\@(\w+)';
3eb014a1 168my $type_struct = '\&((struct\s*)*[_\w]+)';
6b5b55f6 169my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
1da177e4
LT
170my $type_env = '(\$\w+)';
171
172# Output conversion substitutions.
173# One for each output format
174
175# these work fairly well
176my %highlights_html = ( $type_constant, "<i>\$1</i>",
177 $type_func, "<b>\$1</b>",
3eb014a1
RD
178 $type_struct_xml, "<i>\$1</i>",
179 $type_env, "<b><i>\$1</i></b>",
1da177e4 180 $type_param, "<tt><b>\$1</b></tt>" );
6b5b55f6
RD
181my $local_lt = "\\\\\\\\lt:";
182my $local_gt = "\\\\\\\\gt:";
183my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
1da177e4
LT
184
185# XML, docbook format
186my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
187 $type_constant, "<constant>\$1</constant>",
188 $type_func, "<function>\$1</function>",
5c98fc03 189 $type_struct_xml, "<structname>\$1</structname>",
1da177e4
LT
190 $type_env, "<envar>\$1</envar>",
191 $type_param, "<parameter>\$1</parameter>" );
5c98fc03 192my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
1da177e4
LT
193
194# gnome, docbook format
195my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
196 $type_func, "<function>\$1</function>",
197 $type_struct, "<structname>\$1</structname>",
198 $type_env, "<envar>\$1</envar>",
199 $type_param, "<parameter>\$1</parameter>" );
200my $blankline_gnome = "</para><para>\n";
201
202# these are pretty rough
203my %highlights_man = ( $type_constant, "\$1",
204 $type_func, "\\\\fB\$1\\\\fP",
205 $type_struct, "\\\\fI\$1\\\\fP",
206 $type_param, "\\\\fI\$1\\\\fP" );
207my $blankline_man = "";
208
209# text-mode
210my %highlights_text = ( $type_constant, "\$1",
211 $type_func, "\$1",
212 $type_struct, "\$1",
213 $type_param, "\$1" );
214my $blankline_text = "";
215
eda603f6
JB
216# list mode
217my %highlights_list = ( $type_constant, "\$1",
218 $type_func, "\$1",
219 $type_struct, "\$1",
220 $type_param, "\$1" );
221my $blankline_list = "";
1da177e4 222
1da177e4 223# read arguments
b9d97328 224if ($#ARGV == -1) {
1da177e4
LT
225 usage();
226}
227
8484baaa
RD
228my $kernelversion;
229my $dohighlight = "";
230
1da177e4
LT
231my $verbose = 0;
232my $output_mode = "man";
e314ba31 233my $output_preformatted = 0;
4b44595a 234my $no_doc_sections = 0;
1da177e4
LT
235my %highlights = %highlights_man;
236my $blankline = $blankline_man;
237my $modulename = "Kernel API";
238my $function_only = 0;
3c3b809e
RD
239my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
240 'July', 'August', 'September', 'October',
241 'November', 'December')[(localtime)[4]] .
1da177e4
LT
242 " " . ((localtime)[5]+1900);
243
8484baaa 244# Essentially these are globals.
b9d97328
RD
245# They probably want to be tidied up, made more localised or something.
246# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
1da177e4 247# could cause "use of undefined value" or other bugs.
b9d97328
RD
248my ($function, %function_table, %parametertypes, $declaration_purpose);
249my ($type, $declaration_name, $return_type);
1c32fd0c 250my ($newsection, $newcontents, $prototype, $brcount, %source_map);
1da177e4 251
bd0e88e5
RD
252if (defined($ENV{'KBUILD_VERBOSE'})) {
253 $verbose = "$ENV{'KBUILD_VERBOSE'}";
254}
255
3c3b809e 256# Generated docbook code is inserted in a template at a point where
1da177e4
LT
257# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
258# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
259# We keep track of number of generated entries and generate a dummy
260# if needs be to ensure the expanded template can be postprocessed
261# into html.
262my $section_counter = 0;
263
264my $lineprefix="";
265
266# states
267# 0 - normal code
268# 1 - looking for function name
269# 2 - scanning field start.
270# 3 - scanning prototype.
271# 4 - documentation block
272my $state;
850622df 273my $in_doc_sect;
1da177e4
LT
274
275#declaration types: can be
276# 'function', 'struct', 'union', 'enum', 'typedef'
277my $decl_type;
278
279my $doc_special = "\@\%\$\&";
280
281my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
282my $doc_end = '\*/';
283my $doc_com = '\s*\*\s*';
12ae6779 284my $doc_com_body = '\s*\* ?';
b9d97328
RD
285my $doc_decl = $doc_com . '(\w+)';
286my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
12ae6779 287my $doc_content = $doc_com_body . '(.*)';
b9d97328 288my $doc_block = $doc_com . 'DOC:\s*(.*)?';
1da177e4
LT
289
290my %constants;
291my %parameterdescs;
292my @parameterlist;
293my %sections;
294my @sectionlist;
a1d94aa5
RD
295my $sectcheck;
296my $struct_actual;
1da177e4
LT
297
298my $contents = "";
299my $section_default = "Description"; # default section
300my $section_intro = "Introduction";
301my $section = $section_default;
302my $section_context = "Context";
303
304my $undescribed = "-- undescribed --";
305
306reset_state();
307
308while ($ARGV[0] =~ m/^-(.*)/) {
309 my $cmd = shift @ARGV;
310 if ($cmd eq "-html") {
311 $output_mode = "html";
312 %highlights = %highlights_html;
313 $blankline = $blankline_html;
314 } elsif ($cmd eq "-man") {
315 $output_mode = "man";
316 %highlights = %highlights_man;
317 $blankline = $blankline_man;
318 } elsif ($cmd eq "-text") {
319 $output_mode = "text";
320 %highlights = %highlights_text;
321 $blankline = $blankline_text;
322 } elsif ($cmd eq "-docbook") {
323 $output_mode = "xml";
324 %highlights = %highlights_xml;
325 $blankline = $blankline_xml;
eda603f6
JB
326 } elsif ($cmd eq "-list") {
327 $output_mode = "list";
328 %highlights = %highlights_list;
329 $blankline = $blankline_list;
1da177e4
LT
330 } elsif ($cmd eq "-gnome") {
331 $output_mode = "gnome";
332 %highlights = %highlights_gnome;
333 $blankline = $blankline_gnome;
334 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
335 $modulename = shift @ARGV;
336 } elsif ($cmd eq "-function") { # to only output specific functions
337 $function_only = 1;
338 $function = shift @ARGV;
339 $function_table{$function} = 1;
340 } elsif ($cmd eq "-nofunction") { # to only output specific functions
341 $function_only = 2;
342 $function = shift @ARGV;
343 $function_table{$function} = 1;
344 } elsif ($cmd eq "-v") {
345 $verbose = 1;
346 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
347 usage();
4b44595a
JB
348 } elsif ($cmd eq '-no-doc-sections') {
349 $no_doc_sections = 1;
1da177e4
LT
350 }
351}
352
8484baaa
RD
353# continue execution near EOF;
354
355sub usage {
356 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n";
357 print " [ -no-doc-sections ]\n";
358 print " [ -function funcname [ -function funcname ...] ]\n";
359 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
360 print " c source file(s) > outputfile\n";
361 print " -v : verbose output, more warnings & other info listed\n";
362 exit 1;
363}
364
53f049fa
BP
365# get kernel version from env
366sub get_kernel_version() {
1b9bc22d 367 my $version = 'unknown kernel version';
53f049fa
BP
368
369 if (defined($ENV{'KERNELVERSION'})) {
370 $version = $ENV{'KERNELVERSION'};
371 }
372 return $version;
373}
1da177e4
LT
374
375##
376# dumps section contents to arrays/hashes intended for that purpose.
377#
378sub dump_section {
94dc7ad5 379 my $file = shift;
1da177e4
LT
380 my $name = shift;
381 my $contents = join "\n", @_;
382
383 if ($name =~ m/$type_constant/) {
384 $name = $1;
385# print STDERR "constant section '$1' = '$contents'\n";
386 $constants{$name} = $contents;
387 } elsif ($name =~ m/$type_param/) {
388# print STDERR "parameter def '$1' = '$contents'\n";
389 $name = $1;
390 $parameterdescs{$name} = $contents;
a1d94aa5 391 $sectcheck = $sectcheck . $name . " ";
ced69090
RD
392 } elsif ($name eq "@\.\.\.") {
393# print STDERR "parameter def '...' = '$contents'\n";
394 $name = "...";
395 $parameterdescs{$name} = $contents;
a1d94aa5 396 $sectcheck = $sectcheck . $name . " ";
1da177e4
LT
397 } else {
398# print STDERR "other section '$name' = '$contents'\n";
94dc7ad5
RD
399 if (defined($sections{$name}) && ($sections{$name} ne "")) {
400 print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
401 ++$errors;
402 }
1da177e4
LT
403 $sections{$name} = $contents;
404 push @sectionlist, $name;
405 }
406}
407
b112e0f7
JB
408##
409# dump DOC: section after checking that it should go out
410#
411sub dump_doc_section {
94dc7ad5 412 my $file = shift;
b112e0f7
JB
413 my $name = shift;
414 my $contents = join "\n", @_;
415
4b44595a
JB
416 if ($no_doc_sections) {
417 return;
418 }
419
b112e0f7
JB
420 if (($function_only == 0) ||
421 ( $function_only == 1 && defined($function_table{$name})) ||
422 ( $function_only == 2 && !defined($function_table{$name})))
423 {
94dc7ad5 424 dump_section($file, $name, $contents);
b112e0f7
JB
425 output_blockhead({'sectionlist' => \@sectionlist,
426 'sections' => \%sections,
427 'module' => $modulename,
428 'content-only' => ($function_only != 0), });
429 }
430}
431
1da177e4
LT
432##
433# output function
434#
435# parameterdescs, a hash.
436# function => "function name"
437# parameterlist => @list of parameters
438# parameterdescs => %parameter descriptions
439# sectionlist => @list of sections
a21217da 440# sections => %section descriptions
3c3b809e 441#
1da177e4
LT
442
443sub output_highlight {
444 my $contents = join "\n",@_;
445 my $line;
446
447# DEBUG
448# if (!defined $contents) {
449# use Carp;
450# confess "output_highlight got called with no args?\n";
451# }
452
5c98fc03 453 if ($output_mode eq "html" || $output_mode eq "xml") {
6b5b55f6
RD
454 $contents = local_unescape($contents);
455 # convert data read & converted thru xml_escape() into &xyz; format:
2b35f4d9 456 $contents =~ s/\\\\\\/\&/g;
6b5b55f6 457 }
3eb014a1 458# print STDERR "contents b4:$contents\n";
1da177e4
LT
459 eval $dohighlight;
460 die $@ if $@;
3eb014a1
RD
461# print STDERR "contents af:$contents\n";
462
1da177e4 463 foreach $line (split "\n", $contents) {
12ae6779
DS
464 if (! $output_preformatted) {
465 $line =~ s/^\s*//;
466 }
3c308798 467 if ($line eq ""){
e314ba31
DS
468 if (! $output_preformatted) {
469 print $lineprefix, local_unescape($blankline);
470 }
1da177e4 471 } else {
3c308798 472 $line =~ s/\\\\\\/\&/g;
cdccb316
RD
473 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
474 print "\\&$line";
475 } else {
476 print $lineprefix, $line;
477 }
1da177e4
LT
478 }
479 print "\n";
480 }
481}
482
483#output sections in html
484sub output_section_html(%) {
485 my %args = %{$_[0]};
486 my $section;
487
488 foreach $section (@{$args{'sectionlist'}}) {
489 print "<h3>$section</h3>\n";
490 print "<blockquote>\n";
491 output_highlight($args{'sections'}{$section});
492 print "</blockquote>\n";
3c3b809e 493 }
1da177e4
LT
494}
495
496# output enum in html
497sub output_enum_html(%) {
498 my %args = %{$_[0]};
499 my ($parameter);
500 my $count;
b9d97328 501 print "<h2>enum " . $args{'enum'} . "</h2>\n";
1da177e4 502
b9d97328 503 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
1da177e4
LT
504 $count = 0;
505 foreach $parameter (@{$args{'parameterlist'}}) {
b9d97328 506 print " <b>" . $parameter . "</b>";
1da177e4
LT
507 if ($count != $#{$args{'parameterlist'}}) {
508 $count++;
509 print ",\n";
510 }
511 print "<br>";
512 }
513 print "};<br>\n";
514
515 print "<h3>Constants</h3>\n";
516 print "<dl>\n";
517 foreach $parameter (@{$args{'parameterlist'}}) {
b9d97328 518 print "<dt><b>" . $parameter . "</b>\n";
1da177e4
LT
519 print "<dd>";
520 output_highlight($args{'parameterdescs'}{$parameter});
521 }
522 print "</dl>\n";
523 output_section_html(@_);
524 print "<hr>\n";
525}
526
d28bee0c 527# output typedef in html
1da177e4
LT
528sub output_typedef_html(%) {
529 my %args = %{$_[0]};
530 my ($parameter);
531 my $count;
b9d97328 532 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
1da177e4 533
b9d97328 534 print "<b>typedef " . $args{'typedef'} . "</b>\n";
1da177e4
LT
535 output_section_html(@_);
536 print "<hr>\n";
537}
538
539# output struct in html
540sub output_struct_html(%) {
541 my %args = %{$_[0]};
542 my ($parameter);
543
b9d97328
RD
544 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
545 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
1da177e4
LT
546 foreach $parameter (@{$args{'parameterlist'}}) {
547 if ($parameter =~ /^#/) {
548 print "$parameter<br>\n";
549 next;
550 }
551 my $parameter_name = $parameter;
552 $parameter_name =~ s/\[.*//;
553
3c308798 554 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
555 $type = $args{'parametertypes'}{$parameter};
556 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
557 # pointer-to-function
3eb014a1 558 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
1da177e4 559 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
3eb014a1
RD
560 # bitfield
561 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
1da177e4 562 } else {
3eb014a1 563 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
1da177e4
LT
564 }
565 }
566 print "};<br>\n";
567
568 print "<h3>Members</h3>\n";
569 print "<dl>\n";
570 foreach $parameter (@{$args{'parameterlist'}}) {
571 ($parameter =~ /^#/) && next;
572
573 my $parameter_name = $parameter;
574 $parameter_name =~ s/\[.*//;
575
3c308798 576 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 577 print "<dt><b>" . $parameter . "</b>\n";
1da177e4
LT
578 print "<dd>";
579 output_highlight($args{'parameterdescs'}{$parameter_name});
580 }
581 print "</dl>\n";
582 output_section_html(@_);
583 print "<hr>\n";
584}
585
586# output function in html
587sub output_function_html(%) {
588 my %args = %{$_[0]};
589 my ($parameter, $section);
590 my $count;
1da177e4 591
b9d97328
RD
592 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
593 print "<i>" . $args{'functiontype'} . "</i>\n";
594 print "<b>" . $args{'function'} . "</b>\n";
1da177e4
LT
595 print "(";
596 $count = 0;
597 foreach $parameter (@{$args{'parameterlist'}}) {
598 $type = $args{'parametertypes'}{$parameter};
599 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
600 # pointer-to-function
601 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
602 } else {
b9d97328 603 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
1da177e4
LT
604 }
605 if ($count != $#{$args{'parameterlist'}}) {
606 $count++;
607 print ",\n";
608 }
609 }
610 print ")\n";
611
612 print "<h3>Arguments</h3>\n";
613 print "<dl>\n";
614 foreach $parameter (@{$args{'parameterlist'}}) {
615 my $parameter_name = $parameter;
616 $parameter_name =~ s/\[.*//;
617
3c308798 618 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 619 print "<dt><b>" . $parameter . "</b>\n";
1da177e4
LT
620 print "<dd>";
621 output_highlight($args{'parameterdescs'}{$parameter_name});
622 }
623 print "</dl>\n";
624 output_section_html(@_);
625 print "<hr>\n";
626}
627
b112e0f7
JB
628# output DOC: block header in html
629sub output_blockhead_html(%) {
1da177e4
LT
630 my %args = %{$_[0]};
631 my ($parameter, $section);
632 my $count;
633
634 foreach $section (@{$args{'sectionlist'}}) {
635 print "<h3>$section</h3>\n";
636 print "<ul>\n";
637 output_highlight($args{'sections'}{$section});
638 print "</ul>\n";
639 }
640 print "<hr>\n";
641}
642
643sub output_section_xml(%) {
644 my %args = %{$_[0]};
3c3b809e 645 my $section;
1da177e4
LT
646 # print out each section
647 $lineprefix=" ";
648 foreach $section (@{$args{'sectionlist'}}) {
c73894c1
RW
649 print "<refsect1>\n";
650 print "<title>$section</title>\n";
1da177e4 651 if ($section =~ m/EXAMPLE/i) {
c73894c1 652 print "<informalexample><programlisting>\n";
e314ba31 653 $output_preformatted = 1;
c73894c1
RW
654 } else {
655 print "<para>\n";
1da177e4
LT
656 }
657 output_highlight($args{'sections'}{$section});
e314ba31 658 $output_preformatted = 0;
1da177e4 659 if ($section =~ m/EXAMPLE/i) {
c73894c1
RW
660 print "</programlisting></informalexample>\n";
661 } else {
662 print "</para>\n";
1da177e4 663 }
c73894c1 664 print "</refsect1>\n";
1da177e4
LT
665 }
666}
667
668# output function in XML DocBook
669sub output_function_xml(%) {
670 my %args = %{$_[0]};
671 my ($parameter, $section);
672 my $count;
673 my $id;
674
b9d97328 675 $id = "API-" . $args{'function'};
1da177e4
LT
676 $id =~ s/[^A-Za-z0-9]/-/g;
677
5449bc94 678 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
679 print "<refentryinfo>\n";
680 print " <title>LINUX</title>\n";
681 print " <productname>Kernel Hackers Manual</productname>\n";
682 print " <date>$man_date</date>\n";
683 print "</refentryinfo>\n";
1da177e4 684 print "<refmeta>\n";
b9d97328 685 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
8b0c2d98 686 print " <manvolnum>9</manvolnum>\n";
0366299b 687 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1da177e4
LT
688 print "</refmeta>\n";
689 print "<refnamediv>\n";
b9d97328 690 print " <refname>" . $args{'function'} . "</refname>\n";
1da177e4
LT
691 print " <refpurpose>\n";
692 print " ";
693 output_highlight ($args{'purpose'});
694 print " </refpurpose>\n";
695 print "</refnamediv>\n";
696
697 print "<refsynopsisdiv>\n";
698 print " <title>Synopsis</title>\n";
699 print " <funcsynopsis><funcprototype>\n";
b9d97328
RD
700 print " <funcdef>" . $args{'functiontype'} . " ";
701 print "<function>" . $args{'function'} . " </function></funcdef>\n";
1da177e4
LT
702
703 $count = 0;
704 if ($#{$args{'parameterlist'}} >= 0) {
705 foreach $parameter (@{$args{'parameterlist'}}) {
706 $type = $args{'parametertypes'}{$parameter};
707 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
708 # pointer-to-function
709 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
710 print " <funcparams>$2</funcparams></paramdef>\n";
711 } else {
b9d97328 712 print " <paramdef>" . $type;
1da177e4
LT
713 print " <parameter>$parameter</parameter></paramdef>\n";
714 }
715 }
716 } else {
6013d544 717 print " <void/>\n";
1da177e4
LT
718 }
719 print " </funcprototype></funcsynopsis>\n";
720 print "</refsynopsisdiv>\n";
721
722 # print parameters
723 print "<refsect1>\n <title>Arguments</title>\n";
724 if ($#{$args{'parameterlist'}} >= 0) {
725 print " <variablelist>\n";
726 foreach $parameter (@{$args{'parameterlist'}}) {
727 my $parameter_name = $parameter;
728 $parameter_name =~ s/\[.*//;
729
730 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
731 print " <listitem>\n <para>\n";
732 $lineprefix=" ";
733 output_highlight($args{'parameterdescs'}{$parameter_name});
734 print " </para>\n </listitem>\n </varlistentry>\n";
735 }
736 print " </variablelist>\n";
737 } else {
738 print " <para>\n None\n </para>\n";
739 }
740 print "</refsect1>\n";
741
742 output_section_xml(@_);
743 print "</refentry>\n\n";
744}
745
746# output struct in XML DocBook
747sub output_struct_xml(%) {
748 my %args = %{$_[0]};
749 my ($parameter, $section);
750 my $id;
751
b9d97328 752 $id = "API-struct-" . $args{'struct'};
1da177e4
LT
753 $id =~ s/[^A-Za-z0-9]/-/g;
754
5449bc94 755 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
756 print "<refentryinfo>\n";
757 print " <title>LINUX</title>\n";
758 print " <productname>Kernel Hackers Manual</productname>\n";
759 print " <date>$man_date</date>\n";
760 print "</refentryinfo>\n";
1da177e4 761 print "<refmeta>\n";
b9d97328 762 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
8b0c2d98 763 print " <manvolnum>9</manvolnum>\n";
0366299b 764 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1da177e4
LT
765 print "</refmeta>\n";
766 print "<refnamediv>\n";
b9d97328 767 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
1da177e4
LT
768 print " <refpurpose>\n";
769 print " ";
770 output_highlight ($args{'purpose'});
771 print " </refpurpose>\n";
772 print "</refnamediv>\n";
773
774 print "<refsynopsisdiv>\n";
775 print " <title>Synopsis</title>\n";
776 print " <programlisting>\n";
b9d97328 777 print $args{'type'} . " " . $args{'struct'} . " {\n";
1da177e4
LT
778 foreach $parameter (@{$args{'parameterlist'}}) {
779 if ($parameter =~ /^#/) {
2b35f4d9
RD
780 my $prm = $parameter;
781 # convert data read & converted thru xml_escape() into &xyz; format:
782 # This allows us to have #define macros interspersed in a struct.
783 $prm =~ s/\\\\\\/\&/g;
784 print "$prm\n";
1da177e4
LT
785 next;
786 }
787
788 my $parameter_name = $parameter;
789 $parameter_name =~ s/\[.*//;
790
791 defined($args{'parameterdescs'}{$parameter_name}) || next;
3c308798 792 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
793 $type = $args{'parametertypes'}{$parameter};
794 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
795 # pointer-to-function
796 print " $1 $parameter) ($2);\n";
797 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
51f5a0c8 798 # bitfield
1da177e4
LT
799 print " $1 $parameter$2;\n";
800 } else {
b9d97328 801 print " " . $type . " " . $parameter . ";\n";
1da177e4
LT
802 }
803 }
804 print "};";
805 print " </programlisting>\n";
806 print "</refsynopsisdiv>\n";
807
808 print " <refsect1>\n";
809 print " <title>Members</title>\n";
810
39f00c08 811 if ($#{$args{'parameterlist'}} >= 0) {
1da177e4
LT
812 print " <variablelist>\n";
813 foreach $parameter (@{$args{'parameterlist'}}) {
814 ($parameter =~ /^#/) && next;
815
816 my $parameter_name = $parameter;
817 $parameter_name =~ s/\[.*//;
818
819 defined($args{'parameterdescs'}{$parameter_name}) || next;
820 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
821 print " <varlistentry>";
822 print " <term>$parameter</term>\n";
823 print " <listitem><para>\n";
824 output_highlight($args{'parameterdescs'}{$parameter_name});
825 print " </para></listitem>\n";
826 print " </varlistentry>\n";
827 }
828 print " </variablelist>\n";
39f00c08
RD
829 } else {
830 print " <para>\n None\n </para>\n";
831 }
1da177e4
LT
832 print " </refsect1>\n";
833
834 output_section_xml(@_);
835
836 print "</refentry>\n\n";
837}
838
839# output enum in XML DocBook
840sub output_enum_xml(%) {
841 my %args = %{$_[0]};
842 my ($parameter, $section);
843 my $count;
844 my $id;
845
b9d97328 846 $id = "API-enum-" . $args{'enum'};
1da177e4
LT
847 $id =~ s/[^A-Za-z0-9]/-/g;
848
5449bc94 849 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
850 print "<refentryinfo>\n";
851 print " <title>LINUX</title>\n";
852 print " <productname>Kernel Hackers Manual</productname>\n";
853 print " <date>$man_date</date>\n";
854 print "</refentryinfo>\n";
1da177e4 855 print "<refmeta>\n";
b9d97328 856 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
8b0c2d98 857 print " <manvolnum>9</manvolnum>\n";
0366299b 858 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1da177e4
LT
859 print "</refmeta>\n";
860 print "<refnamediv>\n";
b9d97328 861 print " <refname>enum " . $args{'enum'} . "</refname>\n";
1da177e4
LT
862 print " <refpurpose>\n";
863 print " ";
864 output_highlight ($args{'purpose'});
865 print " </refpurpose>\n";
866 print "</refnamediv>\n";
867
868 print "<refsynopsisdiv>\n";
869 print " <title>Synopsis</title>\n";
870 print " <programlisting>\n";
b9d97328 871 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
872 $count = 0;
873 foreach $parameter (@{$args{'parameterlist'}}) {
3c308798
RD
874 print " $parameter";
875 if ($count != $#{$args{'parameterlist'}}) {
1da177e4
LT
876 $count++;
877 print ",";
3c308798 878 }
1da177e4
LT
879 print "\n";
880 }
881 print "};";
882 print " </programlisting>\n";
883 print "</refsynopsisdiv>\n";
884
885 print "<refsect1>\n";
3c3b809e 886 print " <title>Constants</title>\n";
1da177e4
LT
887 print " <variablelist>\n";
888 foreach $parameter (@{$args{'parameterlist'}}) {
889 my $parameter_name = $parameter;
890 $parameter_name =~ s/\[.*//;
891
892 print " <varlistentry>";
893 print " <term>$parameter</term>\n";
894 print " <listitem><para>\n";
895 output_highlight($args{'parameterdescs'}{$parameter_name});
896 print " </para></listitem>\n";
897 print " </varlistentry>\n";
898 }
899 print " </variablelist>\n";
900 print "</refsect1>\n";
901
902 output_section_xml(@_);
903
904 print "</refentry>\n\n";
905}
906
907# output typedef in XML DocBook
908sub output_typedef_xml(%) {
909 my %args = %{$_[0]};
910 my ($parameter, $section);
911 my $id;
912
b9d97328 913 $id = "API-typedef-" . $args{'typedef'};
1da177e4
LT
914 $id =~ s/[^A-Za-z0-9]/-/g;
915
5449bc94 916 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
917 print "<refentryinfo>\n";
918 print " <title>LINUX</title>\n";
919 print " <productname>Kernel Hackers Manual</productname>\n";
920 print " <date>$man_date</date>\n";
921 print "</refentryinfo>\n";
1da177e4 922 print "<refmeta>\n";
b9d97328 923 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
8b0c2d98 924 print " <manvolnum>9</manvolnum>\n";
1da177e4
LT
925 print "</refmeta>\n";
926 print "<refnamediv>\n";
b9d97328 927 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
1da177e4
LT
928 print " <refpurpose>\n";
929 print " ";
930 output_highlight ($args{'purpose'});
931 print " </refpurpose>\n";
932 print "</refnamediv>\n";
933
934 print "<refsynopsisdiv>\n";
935 print " <title>Synopsis</title>\n";
b9d97328 936 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
1da177e4
LT
937 print "</refsynopsisdiv>\n";
938
939 output_section_xml(@_);
940
941 print "</refentry>\n\n";
942}
943
944# output in XML DocBook
b112e0f7 945sub output_blockhead_xml(%) {
1da177e4
LT
946 my %args = %{$_[0]};
947 my ($parameter, $section);
948 my $count;
949
950 my $id = $args{'module'};
951 $id =~ s/[^A-Za-z0-9]/-/g;
952
953 # print out each section
954 $lineprefix=" ";
955 foreach $section (@{$args{'sectionlist'}}) {
b112e0f7
JB
956 if (!$args{'content-only'}) {
957 print "<refsect1>\n <title>$section</title>\n";
958 }
1da177e4
LT
959 if ($section =~ m/EXAMPLE/i) {
960 print "<example><para>\n";
e314ba31 961 $output_preformatted = 1;
b112e0f7
JB
962 } else {
963 print "<para>\n";
1da177e4
LT
964 }
965 output_highlight($args{'sections'}{$section});
e314ba31 966 $output_preformatted = 0;
1da177e4
LT
967 if ($section =~ m/EXAMPLE/i) {
968 print "</para></example>\n";
b112e0f7
JB
969 } else {
970 print "</para>";
971 }
972 if (!$args{'content-only'}) {
973 print "\n</refsect1>\n";
1da177e4 974 }
1da177e4
LT
975 }
976
977 print "\n\n";
978}
979
980# output in XML DocBook
981sub output_function_gnome {
982 my %args = %{$_[0]};
983 my ($parameter, $section);
984 my $count;
985 my $id;
986
b9d97328 987 $id = $args{'module'} . "-" . $args{'function'};
1da177e4
LT
988 $id =~ s/[^A-Za-z0-9]/-/g;
989
990 print "<sect2>\n";
b9d97328 991 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
1da177e4
LT
992
993 print " <funcsynopsis>\n";
b9d97328
RD
994 print " <funcdef>" . $args{'functiontype'} . " ";
995 print "<function>" . $args{'function'} . " ";
1da177e4
LT
996 print "</function></funcdef>\n";
997
998 $count = 0;
999 if ($#{$args{'parameterlist'}} >= 0) {
1000 foreach $parameter (@{$args{'parameterlist'}}) {
1001 $type = $args{'parametertypes'}{$parameter};
1002 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1003 # pointer-to-function
1004 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1005 print " <funcparams>$2</funcparams></paramdef>\n";
1006 } else {
b9d97328 1007 print " <paramdef>" . $type;
1da177e4
LT
1008 print " <parameter>$parameter</parameter></paramdef>\n";
1009 }
1010 }
1011 } else {
1012 print " <void>\n";
1013 }
1014 print " </funcsynopsis>\n";
1015 if ($#{$args{'parameterlist'}} >= 0) {
1016 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1017 print "<tgroup cols=\"2\">\n";
1018 print "<colspec colwidth=\"2*\">\n";
1019 print "<colspec colwidth=\"8*\">\n";
1020 print "<tbody>\n";
1021 foreach $parameter (@{$args{'parameterlist'}}) {
1022 my $parameter_name = $parameter;
1023 $parameter_name =~ s/\[.*//;
1024
1025 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1026 print " <entry>\n";
1027 $lineprefix=" ";
1028 output_highlight($args{'parameterdescs'}{$parameter_name});
1029 print " </entry></row>\n";
1030 }
1031 print " </tbody></tgroup></informaltable>\n";
1032 } else {
1033 print " <para>\n None\n </para>\n";
1034 }
1035
1036 # print out each section
1037 $lineprefix=" ";
1038 foreach $section (@{$args{'sectionlist'}}) {
1039 print "<simplesect>\n <title>$section</title>\n";
1040 if ($section =~ m/EXAMPLE/i) {
1041 print "<example><programlisting>\n";
e314ba31 1042 $output_preformatted = 1;
1da177e4
LT
1043 } else {
1044 }
1045 print "<para>\n";
1046 output_highlight($args{'sections'}{$section});
e314ba31 1047 $output_preformatted = 0;
1da177e4
LT
1048 print "</para>\n";
1049 if ($section =~ m/EXAMPLE/i) {
1050 print "</programlisting></example>\n";
1051 } else {
1052 }
1053 print " </simplesect>\n";
1054 }
1055
1056 print "</sect2>\n\n";
1057}
1058
1059##
1060# output function in man
1061sub output_function_man(%) {
1062 my %args = %{$_[0]};
1063 my ($parameter, $section);
1064 my $count;
1065
1066 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1067
1068 print ".SH NAME\n";
b9d97328 1069 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1070
1071 print ".SH SYNOPSIS\n";
a21217da 1072 if ($args{'functiontype'} ne "") {
b9d97328 1073 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
a21217da 1074 } else {
b9d97328 1075 print ".B \"" . $args{'function'} . "\n";
a21217da 1076 }
1da177e4
LT
1077 $count = 0;
1078 my $parenth = "(";
1079 my $post = ",";
1080 foreach my $parameter (@{$args{'parameterlist'}}) {
1081 if ($count == $#{$args{'parameterlist'}}) {
1082 $post = ");";
1083 }
1084 $type = $args{'parametertypes'}{$parameter};
1085 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1086 # pointer-to-function
b9d97328 1087 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1da177e4
LT
1088 } else {
1089 $type =~ s/([^\*])$/$1 /;
b9d97328 1090 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1da177e4
LT
1091 }
1092 $count++;
1093 $parenth = "";
1094 }
1095
1096 print ".SH ARGUMENTS\n";
1097 foreach $parameter (@{$args{'parameterlist'}}) {
1098 my $parameter_name = $parameter;
1099 $parameter_name =~ s/\[.*//;
1100
b9d97328 1101 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
1102 output_highlight($args{'parameterdescs'}{$parameter_name});
1103 }
1104 foreach $section (@{$args{'sectionlist'}}) {
1105 print ".SH \"", uc $section, "\"\n";
1106 output_highlight($args{'sections'}{$section});
1107 }
1108}
1109
1110##
1111# output enum in man
1112sub output_enum_man(%) {
1113 my %args = %{$_[0]};
1114 my ($parameter, $section);
1115 my $count;
1116
1117 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1118
1119 print ".SH NAME\n";
b9d97328 1120 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1121
1122 print ".SH SYNOPSIS\n";
b9d97328 1123 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
1124 $count = 0;
1125 foreach my $parameter (@{$args{'parameterlist'}}) {
3c308798 1126 print ".br\n.BI \" $parameter\"\n";
1da177e4
LT
1127 if ($count == $#{$args{'parameterlist'}}) {
1128 print "\n};\n";
1129 last;
1130 }
1131 else {
1132 print ", \n.br\n";
1133 }
1134 $count++;
1135 }
1136
1137 print ".SH Constants\n";
1138 foreach $parameter (@{$args{'parameterlist'}}) {
1139 my $parameter_name = $parameter;
1140 $parameter_name =~ s/\[.*//;
1141
b9d97328 1142 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
1143 output_highlight($args{'parameterdescs'}{$parameter_name});
1144 }
1145 foreach $section (@{$args{'sectionlist'}}) {
1146 print ".SH \"$section\"\n";
1147 output_highlight($args{'sections'}{$section});
1148 }
1149}
1150
1151##
1152# output struct in man
1153sub output_struct_man(%) {
1154 my %args = %{$_[0]};
1155 my ($parameter, $section);
1156
b9d97328 1157 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1da177e4
LT
1158
1159 print ".SH NAME\n";
b9d97328 1160 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1161
1162 print ".SH SYNOPSIS\n";
b9d97328 1163 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1da177e4
LT
1164
1165 foreach my $parameter (@{$args{'parameterlist'}}) {
1166 if ($parameter =~ /^#/) {
1167 print ".BI \"$parameter\"\n.br\n";
1168 next;
1169 }
1170 my $parameter_name = $parameter;
1171 $parameter_name =~ s/\[.*//;
1172
3c308798 1173 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
1174 $type = $args{'parametertypes'}{$parameter};
1175 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1176 # pointer-to-function
b9d97328 1177 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1da177e4 1178 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1d7e1d45 1179 # bitfield
b9d97328 1180 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1da177e4
LT
1181 } else {
1182 $type =~ s/([^\*])$/$1 /;
b9d97328 1183 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1da177e4
LT
1184 }
1185 print "\n.br\n";
1186 }
1187 print "};\n.br\n";
1188
c51d3dac 1189 print ".SH Members\n";
1da177e4
LT
1190 foreach $parameter (@{$args{'parameterlist'}}) {
1191 ($parameter =~ /^#/) && next;
1192
1193 my $parameter_name = $parameter;
1194 $parameter_name =~ s/\[.*//;
1195
3c308798 1196 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 1197 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
1198 output_highlight($args{'parameterdescs'}{$parameter_name});
1199 }
1200 foreach $section (@{$args{'sectionlist'}}) {
1201 print ".SH \"$section\"\n";
1202 output_highlight($args{'sections'}{$section});
1203 }
1204}
1205
1206##
1207# output typedef in man
1208sub output_typedef_man(%) {
1209 my %args = %{$_[0]};
1210 my ($parameter, $section);
1211
1212 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1213
1214 print ".SH NAME\n";
b9d97328 1215 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1216
1217 foreach $section (@{$args{'sectionlist'}}) {
1218 print ".SH \"$section\"\n";
1219 output_highlight($args{'sections'}{$section});
1220 }
1221}
1222
b112e0f7 1223sub output_blockhead_man(%) {
1da177e4
LT
1224 my %args = %{$_[0]};
1225 my ($parameter, $section);
1226 my $count;
1227
1228 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1229
1230 foreach $section (@{$args{'sectionlist'}}) {
1231 print ".SH \"$section\"\n";
1232 output_highlight($args{'sections'}{$section});
1233 }
1234}
1235
1236##
1237# output in text
1238sub output_function_text(%) {
1239 my %args = %{$_[0]};
1240 my ($parameter, $section);
a21217da 1241 my $start;
1da177e4 1242
f47634b2 1243 print "Name:\n\n";
b9d97328 1244 print $args{'function'} . " - " . $args{'purpose'} . "\n";
f47634b2
RD
1245
1246 print "\nSynopsis:\n\n";
a21217da 1247 if ($args{'functiontype'} ne "") {
b9d97328 1248 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
a21217da 1249 } else {
b9d97328 1250 $start = $args{'function'} . " (";
a21217da 1251 }
1da177e4 1252 print $start;
a21217da 1253
1da177e4
LT
1254 my $count = 0;
1255 foreach my $parameter (@{$args{'parameterlist'}}) {
1256 $type = $args{'parametertypes'}{$parameter};
1257 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1258 # pointer-to-function
b9d97328 1259 print $1 . $parameter . ") (" . $2;
1da177e4 1260 } else {
b9d97328 1261 print $type . " " . $parameter;
1da177e4
LT
1262 }
1263 if ($count != $#{$args{'parameterlist'}}) {
1264 $count++;
1265 print ",\n";
1266 print " " x length($start);
1267 } else {
1268 print ");\n\n";
1269 }
1270 }
1271
1272 print "Arguments:\n\n";
1273 foreach $parameter (@{$args{'parameterlist'}}) {
1274 my $parameter_name = $parameter;
1275 $parameter_name =~ s/\[.*//;
1276
b9d97328 1277 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1da177e4
LT
1278 }
1279 output_section_text(@_);
1280}
1281
1282#output sections in text
1283sub output_section_text(%) {
1284 my %args = %{$_[0]};
1285 my $section;
1286
1287 print "\n";
1288 foreach $section (@{$args{'sectionlist'}}) {
1289 print "$section:\n\n";
1290 output_highlight($args{'sections'}{$section});
3c3b809e 1291 }
1da177e4
LT
1292 print "\n\n";
1293}
1294
1295# output enum in text
1296sub output_enum_text(%) {
1297 my %args = %{$_[0]};
1298 my ($parameter);
1299 my $count;
1300 print "Enum:\n\n";
1301
b9d97328
RD
1302 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1303 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
1304 $count = 0;
1305 foreach $parameter (@{$args{'parameterlist'}}) {
3c308798 1306 print "\t$parameter";
1da177e4
LT
1307 if ($count != $#{$args{'parameterlist'}}) {
1308 $count++;
1309 print ",";
1310 }
1311 print "\n";
1312 }
1313 print "};\n\n";
1314
1315 print "Constants:\n\n";
1316 foreach $parameter (@{$args{'parameterlist'}}) {
1317 print "$parameter\n\t";
b9d97328 1318 print $args{'parameterdescs'}{$parameter} . "\n";
1da177e4
LT
1319 }
1320
1321 output_section_text(@_);
1322}
1323
1324# output typedef in text
1325sub output_typedef_text(%) {
1326 my %args = %{$_[0]};
1327 my ($parameter);
1328 my $count;
1329 print "Typedef:\n\n";
1330
b9d97328 1331 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1da177e4
LT
1332 output_section_text(@_);
1333}
1334
1335# output struct as text
1336sub output_struct_text(%) {
1337 my %args = %{$_[0]};
1338 my ($parameter);
1339
b9d97328
RD
1340 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1341 print $args{'type'} . " " . $args{'struct'} . " {\n";
1da177e4
LT
1342 foreach $parameter (@{$args{'parameterlist'}}) {
1343 if ($parameter =~ /^#/) {
1344 print "$parameter\n";
1345 next;
1346 }
1347
1348 my $parameter_name = $parameter;
1349 $parameter_name =~ s/\[.*//;
1350
3c308798 1351 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
1352 $type = $args{'parametertypes'}{$parameter};
1353 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1354 # pointer-to-function
1355 print "\t$1 $parameter) ($2);\n";
1356 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
51f5a0c8 1357 # bitfield
1da177e4
LT
1358 print "\t$1 $parameter$2;\n";
1359 } else {
b9d97328 1360 print "\t" . $type . " " . $parameter . ";\n";
1da177e4
LT
1361 }
1362 }
1363 print "};\n\n";
1364
1365 print "Members:\n\n";
1366 foreach $parameter (@{$args{'parameterlist'}}) {
1367 ($parameter =~ /^#/) && next;
1368
1369 my $parameter_name = $parameter;
1370 $parameter_name =~ s/\[.*//;
1371
3c308798 1372 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4 1373 print "$parameter\n\t";
b9d97328 1374 print $args{'parameterdescs'}{$parameter_name} . "\n";
1da177e4
LT
1375 }
1376 print "\n";
1377 output_section_text(@_);
1378}
1379
b112e0f7 1380sub output_blockhead_text(%) {
1da177e4
LT
1381 my %args = %{$_[0]};
1382 my ($parameter, $section);
1383
1384 foreach $section (@{$args{'sectionlist'}}) {
1385 print " $section:\n";
1386 print " -> ";
1387 output_highlight($args{'sections'}{$section});
1388 }
1389}
1390
eda603f6
JB
1391## list mode output functions
1392
1393sub output_function_list(%) {
1394 my %args = %{$_[0]};
1395
1396 print $args{'function'} . "\n";
1397}
1398
1399# output enum in list
1400sub output_enum_list(%) {
1401 my %args = %{$_[0]};
1402 print $args{'enum'} . "\n";
1403}
1404
1405# output typedef in list
1406sub output_typedef_list(%) {
1407 my %args = %{$_[0]};
1408 print $args{'typedef'} . "\n";
1409}
1410
1411# output struct as list
1412sub output_struct_list(%) {
1413 my %args = %{$_[0]};
1414
1415 print $args{'struct'} . "\n";
1416}
1417
1418sub output_blockhead_list(%) {
1419 my %args = %{$_[0]};
1420 my ($parameter, $section);
1421
1422 foreach $section (@{$args{'sectionlist'}}) {
1423 print "DOC: $section\n";
1424 }
1425}
1426
1da177e4 1427##
27205744
RD
1428# generic output function for all types (function, struct/union, typedef, enum);
1429# calls the generated, variable output_ function name based on
1430# functype and output_mode
1da177e4
LT
1431sub output_declaration {
1432 no strict 'refs';
1433 my $name = shift;
1434 my $functype = shift;
1435 my $func = "output_${functype}_$output_mode";
3c3b809e
RD
1436 if (($function_only==0) ||
1437 ( $function_only == 1 && defined($function_table{$name})) ||
1da177e4
LT
1438 ( $function_only == 2 && !defined($function_table{$name})))
1439 {
3c308798 1440 &$func(@_);
1da177e4
LT
1441 $section_counter++;
1442 }
1443}
1444
1445##
27205744 1446# generic output function - calls the right one based on current output mode.
b112e0f7 1447sub output_blockhead {
1da177e4 1448 no strict 'refs';
b9d97328 1449 my $func = "output_blockhead_" . $output_mode;
1da177e4
LT
1450 &$func(@_);
1451 $section_counter++;
1452}
1453
1454##
3c3b809e 1455# takes a declaration (struct, union, enum, typedef) and
1da177e4
LT
1456# invokes the right handler. NOT called for functions.
1457sub dump_declaration($$) {
1458 no strict 'refs';
1459 my ($prototype, $file) = @_;
b9d97328 1460 my $func = "dump_" . $decl_type;
1da177e4
LT
1461 &$func(@_);
1462}
1463
1464sub dump_union($$) {
1465 dump_struct(@_);
1466}
1467
1468sub dump_struct($$) {
1469 my $x = shift;
1470 my $file = shift;
a1d94aa5 1471 my $nested;
1da177e4 1472
52dc5aec
RD
1473 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1474 #my $decl_type = $1;
3c308798
RD
1475 $declaration_name = $2;
1476 my $members = $3;
1da177e4
LT
1477
1478 # ignore embedded structs or unions
a1d94aa5
RD
1479 $members =~ s/({.*})//g;
1480 $nested = $1;
1da177e4 1481
aeec46b9 1482 # ignore members marked private:
52dc5aec
RD
1483 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
1484 $members =~ s/\/\*\s*private:.*//gos;
aeec46b9
MW
1485 # strip comments:
1486 $members =~ s/\/\*.*?\*\///gos;
a1d94aa5 1487 $nested =~ s/\/\*.*?\*\///gos;
d960eea9
RD
1488 # strip kmemcheck_bitfield_{begin,end}.*;
1489 $members =~ s/kmemcheck_bitfield_.*?;//gos;
ef5da59f
RD
1490 # strip attributes
1491 $members =~ s/__aligned\s*\(\d+\)//gos;
aeec46b9 1492
1da177e4 1493 create_parameterlist($members, ';', $file);
a1d94aa5 1494 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1da177e4
LT
1495
1496 output_declaration($declaration_name,
1497 'struct',
1498 {'struct' => $declaration_name,
1499 'module' => $modulename,
1500 'parameterlist' => \@parameterlist,
1501 'parameterdescs' => \%parameterdescs,
1502 'parametertypes' => \%parametertypes,
1503 'sectionlist' => \@sectionlist,
1504 'sections' => \%sections,
1505 'purpose' => $declaration_purpose,
1506 'type' => $decl_type
1507 });
1508 }
1509 else {
3c308798 1510 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1da177e4
LT
1511 ++$errors;
1512 }
1513}
1514
1515sub dump_enum($$) {
1516 my $x = shift;
1517 my $file = shift;
1518
aeec46b9 1519 $x =~ s@/\*.*?\*/@@gos; # strip comments.
b6d676db
RD
1520 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1521
1da177e4 1522 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
3c308798
RD
1523 $declaration_name = $1;
1524 my $members = $2;
1da177e4
LT
1525
1526 foreach my $arg (split ',', $members) {
1527 $arg =~ s/^\s*(\w+).*/$1/;
1528 push @parameterlist, $arg;
1529 if (!$parameterdescs{$arg}) {
3c308798
RD
1530 $parameterdescs{$arg} = $undescribed;
1531 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1da177e4
LT
1532 "not described in enum '$declaration_name'\n";
1533 }
1534
1535 }
3c3b809e 1536
1da177e4
LT
1537 output_declaration($declaration_name,
1538 'enum',
1539 {'enum' => $declaration_name,
1540 'module' => $modulename,
1541 'parameterlist' => \@parameterlist,
1542 'parameterdescs' => \%parameterdescs,
1543 'sectionlist' => \@sectionlist,
1544 'sections' => \%sections,
1545 'purpose' => $declaration_purpose
1546 });
1547 }
1548 else {
3c308798 1549 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1da177e4
LT
1550 ++$errors;
1551 }
1552}
1553
1554sub dump_typedef($$) {
1555 my $x = shift;
1556 my $file = shift;
1557
aeec46b9 1558 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1da177e4 1559 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
3c308798 1560 $x =~ s/\(*.\)\s*;$/;/;
1da177e4
LT
1561 $x =~ s/\[*.\]\s*;$/;/;
1562 }
1563
1564 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
3c308798 1565 $declaration_name = $1;
1da177e4
LT
1566
1567 output_declaration($declaration_name,
1568 'typedef',
1569 {'typedef' => $declaration_name,
1570 'module' => $modulename,
1571 'sectionlist' => \@sectionlist,
1572 'sections' => \%sections,
1573 'purpose' => $declaration_purpose
1574 });
1575 }
1576 else {
3c308798 1577 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1da177e4
LT
1578 ++$errors;
1579 }
1580}
1581
a1d94aa5
RD
1582sub save_struct_actual($) {
1583 my $actual = shift;
1584
1585 # strip all spaces from the actual param so that it looks like one string item
1586 $actual =~ s/\s*//g;
1587 $struct_actual = $struct_actual . $actual . " ";
1588}
1589
1da177e4
LT
1590sub create_parameterlist($$$) {
1591 my $args = shift;
1592 my $splitter = shift;
1593 my $file = shift;
1594 my $type;
1595 my $param;
1596
a6d3fe77 1597 # temporarily replace commas inside function pointer definition
1da177e4 1598 while ($args =~ /(\([^\),]+),/) {
3c308798 1599 $args =~ s/(\([^\),]+),/$1#/g;
1da177e4 1600 }
3c3b809e 1601
1da177e4
LT
1602 foreach my $arg (split($splitter, $args)) {
1603 # strip comments
1604 $arg =~ s/\/\*.*\*\///;
3c308798
RD
1605 # strip leading/trailing spaces
1606 $arg =~ s/^\s*//;
1da177e4
LT
1607 $arg =~ s/\s*$//;
1608 $arg =~ s/\s+/ /;
1609
1610 if ($arg =~ /^#/) {
1611 # Treat preprocessor directive as a typeless variable just to fill
1612 # corresponding data structures "correctly". Catch it later in
1613 # output_* subs.
1614 push_parameter($arg, "", $file);
00d62961 1615 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1da177e4
LT
1616 # pointer-to-function
1617 $arg =~ tr/#/,/;
00d62961 1618 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1da177e4
LT
1619 $param = $1;
1620 $type = $arg;
00d62961 1621 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
a1d94aa5 1622 save_struct_actual($param);
1da177e4 1623 push_parameter($param, $type, $file);
aeec46b9 1624 } elsif ($arg) {
1da177e4
LT
1625 $arg =~ s/\s*:\s*/:/g;
1626 $arg =~ s/\s*\[/\[/g;
1627
1628 my @args = split('\s*,\s*', $arg);
1629 if ($args[0] =~ m/\*/) {
1630 $args[0] =~ s/(\*+)\s*/ $1/;
1631 }
884f2810
BP
1632
1633 my @first_arg;
1634 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1635 shift @args;
1636 push(@first_arg, split('\s+', $1));
1637 push(@first_arg, $2);
1638 } else {
1639 @first_arg = split('\s+', shift @args);
1640 }
1641
1da177e4
LT
1642 unshift(@args, pop @first_arg);
1643 $type = join " ", @first_arg;
1644
1645 foreach $param (@args) {
1646 if ($param =~ m/^(\*+)\s*(.*)/) {
a1d94aa5 1647 save_struct_actual($2);
1da177e4
LT
1648 push_parameter($2, "$type $1", $file);
1649 }
1650 elsif ($param =~ m/(.*?):(\d+)/) {
7b97887e 1651 if ($type ne "") { # skip unnamed bit-fields
a1d94aa5 1652 save_struct_actual($1);
7b97887e
RD
1653 push_parameter($1, "$type:$2", $file)
1654 }
1da177e4
LT
1655 }
1656 else {
a1d94aa5 1657 save_struct_actual($param);
1da177e4
LT
1658 push_parameter($param, $type, $file);
1659 }
1660 }
1661 }
1662 }
1663}
1664
1665sub push_parameter($$$) {
1666 my $param = shift;
1667 my $type = shift;
1668 my $file = shift;
1669
5f8c7c98
RD
1670 if (($anon_struct_union == 1) && ($type eq "") &&
1671 ($param eq "}")) {
1672 return; # ignore the ending }; from anon. struct/union
1673 }
1674
1675 $anon_struct_union = 0;
1da177e4
LT
1676 my $param_name = $param;
1677 $param_name =~ s/\[.*//;
1678
a6d3fe77 1679 if ($type eq "" && $param =~ /\.\.\.$/)
1da177e4 1680 {
ced69090
RD
1681 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1682 $parameterdescs{$param} = "variable arguments";
1683 }
1da177e4
LT
1684 }
1685 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1686 {
1da177e4
LT
1687 $param="void";
1688 $parameterdescs{void} = "no arguments";
1689 }
134fe01b
RD
1690 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1691 # handle unnamed (anonymous) union or struct:
1692 {
1693 $type = $param;
5f8c7c98 1694 $param = "{unnamed_" . $param . "}";
134fe01b 1695 $parameterdescs{$param} = "anonymous\n";
5f8c7c98 1696 $anon_struct_union = 1;
134fe01b
RD
1697 }
1698
a6d3fe77 1699 # warn if parameter has no description
134fe01b
RD
1700 # (but ignore ones starting with # as these are not parameters
1701 # but inline preprocessor statements);
1702 # also ignore unnamed structs/unions;
5f8c7c98 1703 if (!$anon_struct_union) {
a6d3fe77
MW
1704 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1705
1da177e4
LT
1706 $parameterdescs{$param_name} = $undescribed;
1707
1708 if (($type eq 'function') || ($type eq 'enum')) {
3c308798 1709 print STDERR "Warning(${file}:$.): Function parameter ".
1da177e4
LT
1710 "or member '$param' not " .
1711 "described in '$declaration_name'\n";
1712 }
b9d97328 1713 print STDERR "Warning(${file}:$.):" .
3c308798 1714 " No description found for parameter '$param'\n";
1da177e4 1715 ++$warnings;
3c308798
RD
1716 }
1717 }
1da177e4 1718
2b35f4d9
RD
1719 $param = xml_escape($param);
1720
25985edc 1721 # strip spaces from $param so that it is one continuous string
e34e7dbb
RD
1722 # on @parameterlist;
1723 # this fixes a problem where check_sections() cannot find
1724 # a parameter like "addr[6 + 2]" because it actually appears
1725 # as "addr[6", "+", "2]" on the parameter list;
1726 # but it's better to maintain the param string unchanged for output,
1727 # so just weaken the string compare in check_sections() to ignore
1728 # "[blah" in a parameter string;
1729 ###$param =~ s/\s*//g;
1da177e4
LT
1730 push @parameterlist, $param;
1731 $parametertypes{$param} = $type;
1732}
1733
a1d94aa5
RD
1734sub check_sections($$$$$$) {
1735 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1736 my @sects = split ' ', $sectcheck;
1737 my @prms = split ' ', $prmscheck;
1738 my $err;
1739 my ($px, $sx);
1740 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1741
1742 foreach $sx (0 .. $#sects) {
1743 $err = 1;
1744 foreach $px (0 .. $#prms) {
1745 $prm_clean = $prms[$px];
1746 $prm_clean =~ s/\[.*\]//;
1f3a6688 1747 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
e34e7dbb
RD
1748 # ignore array size in a parameter string;
1749 # however, the original param string may contain
1750 # spaces, e.g.: addr[6 + 2]
1751 # and this appears in @prms as "addr[6" since the
1752 # parameter list is split at spaces;
1753 # hence just ignore "[..." for the sections check;
1754 $prm_clean =~ s/\[.*//;
1755
a1d94aa5
RD
1756 ##$prm_clean =~ s/^\**//;
1757 if ($prm_clean eq $sects[$sx]) {
1758 $err = 0;
1759 last;
1760 }
1761 }
1762 if ($err) {
1763 if ($decl_type eq "function") {
1764 print STDERR "Warning(${file}:$.): " .
1765 "Excess function parameter " .
1766 "'$sects[$sx]' " .
1767 "description in '$decl_name'\n";
1768 ++$warnings;
1769 } else {
1770 if ($nested !~ m/\Q$sects[$sx]\E/) {
1771 print STDERR "Warning(${file}:$.): " .
1772 "Excess struct/union/enum/typedef member " .
1773 "'$sects[$sx]' " .
1774 "description in '$decl_name'\n";
1775 ++$warnings;
1776 }
1777 }
1778 }
1779 }
1780}
1781
1da177e4
LT
1782##
1783# takes a function prototype and the name of the current file being
1784# processed and spits out all the details stored in the global
1785# arrays/hashes.
1786sub dump_function($$) {
1787 my $prototype = shift;
1788 my $file = shift;
1789
1790 $prototype =~ s/^static +//;
1791 $prototype =~ s/^extern +//;
4dc3b16b 1792 $prototype =~ s/^asmlinkage +//;
1da177e4
LT
1793 $prototype =~ s/^inline +//;
1794 $prototype =~ s/^__inline__ +//;
32e79401
RD
1795 $prototype =~ s/^__inline +//;
1796 $prototype =~ s/^__always_inline +//;
1797 $prototype =~ s/^noinline +//;
0129a057 1798 $prototype =~ s/__devinit +//;
74fc5c65 1799 $prototype =~ s/__init +//;
20072205 1800 $prototype =~ s/__init_or_module +//;
70c95b00 1801 $prototype =~ s/__must_check +//;
0df7c0e3 1802 $prototype =~ s/__weak +//;
890c78c2 1803 $prototype =~ s/^#\s*define\s+//; #ak added
328d2440 1804 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1da177e4
LT
1805
1806 # Yes, this truly is vile. We are looking for:
1807 # 1. Return type (may be nothing if we're looking at a macro)
1808 # 2. Function name
1809 # 3. Function parameters.
1810 #
1811 # All the while we have to watch out for function pointer parameters
1812 # (which IIRC is what the two sections are for), C types (these
1813 # regexps don't even start to express all the possibilities), and
1814 # so on.
1815 #
1816 # If you mess with these regexps, it's a good idea to check that
1817 # the following functions' documentation still comes out right:
1818 # - parport_register_device (function pointer parameters)
1819 # - atomic_set (macro)
9598f91f 1820 # - pci_match_device, __copy_to_user (long return type)
1da177e4
LT
1821
1822 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1823 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1824 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1825 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
94b3e03c 1826 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4
LT
1827 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1828 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1829 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1830 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1831 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1832 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1833 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1834 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
9598f91f
MW
1835 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1836 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
412ecd77
RD
1837 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1838 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1da177e4
LT
1839 $return_type = $1;
1840 $declaration_name = $2;
1841 my $args = $3;
1842
1843 create_parameterlist($args, ',', $file);
1844 } else {
1845 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1846 ++$errors;
1847 return;
1848 }
1849
a1d94aa5
RD
1850 my $prms = join " ", @parameterlist;
1851 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
1852
3c3b809e 1853 output_declaration($declaration_name,
1da177e4
LT
1854 'function',
1855 {'function' => $declaration_name,
1856 'module' => $modulename,
1857 'functiontype' => $return_type,
1858 'parameterlist' => \@parameterlist,
1859 'parameterdescs' => \%parameterdescs,
1860 'parametertypes' => \%parametertypes,
1861 'sectionlist' => \@sectionlist,
1862 'sections' => \%sections,
1863 'purpose' => $declaration_purpose
1864 });
1865}
1866
1da177e4
LT
1867sub reset_state {
1868 $function = "";
1869 %constants = ();
1870 %parameterdescs = ();
1871 %parametertypes = ();
1872 @parameterlist = ();
1873 %sections = ();
1874 @sectionlist = ();
a1d94aa5
RD
1875 $sectcheck = "";
1876 $struct_actual = "";
1da177e4 1877 $prototype = "";
3c3b809e 1878
1da177e4
LT
1879 $state = 0;
1880}
1881
56afb0f8
JB
1882sub tracepoint_munge($) {
1883 my $file = shift;
1884 my $tracepointname = 0;
1885 my $tracepointargs = 0;
1886
3a9089fd 1887 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
56afb0f8
JB
1888 $tracepointname = $1;
1889 }
3a9089fd
JB
1890 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1891 $tracepointname = $1;
1892 }
1893 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1894 $tracepointname = $2;
1895 }
1896 $tracepointname =~ s/^\s+//; #strip leading whitespace
1897 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
56afb0f8
JB
1898 $tracepointargs = $1;
1899 }
1900 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
1901 print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
1902 "$prototype\n";
1903 } else {
1904 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1905 }
1906}
1907
b4870bc5
RD
1908sub syscall_munge() {
1909 my $void = 0;
1910
1911 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
1912## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1913 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1914 $void = 1;
1915## $prototype = "long sys_$1(void)";
1916 }
1917
1918 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1919 if ($prototype =~ m/long (sys_.*?),/) {
1920 $prototype =~ s/,/\(/;
1921 } elsif ($void) {
1922 $prototype =~ s/\)/\(void\)/;
1923 }
1924
1925 # now delete all of the odd-number commas in $prototype
1926 # so that arg types & arg names don't have a comma between them
1927 my $count = 0;
1928 my $len = length($prototype);
1929 if ($void) {
1930 $len = 0; # skip the for-loop
1931 }
1932 for (my $ix = 0; $ix < $len; $ix++) {
1933 if (substr($prototype, $ix, 1) eq ',') {
1934 $count++;
1935 if ($count % 2 == 1) {
1936 substr($prototype, $ix, 1) = ' ';
1937 }
1938 }
1939 }
1940}
1941
3c3b809e 1942sub process_state3_function($$) {
1da177e4
LT
1943 my $x = shift;
1944 my $file = shift;
1945
51f5a0c8
RD
1946 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1947
890c78c2 1948 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1da177e4
LT
1949 # do nothing
1950 }
1951 elsif ($x =~ /([^\{]*)/) {
3c308798 1952 $prototype .= $1;
1da177e4 1953 }
b4870bc5 1954
890c78c2 1955 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
3c308798 1956 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1da177e4
LT
1957 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1958 $prototype =~ s@^\s+@@gos; # strip leading spaces
b4870bc5
RD
1959 if ($prototype =~ /SYSCALL_DEFINE/) {
1960 syscall_munge();
1961 }
3a9089fd
JB
1962 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1963 $prototype =~ /DEFINE_SINGLE_EVENT/)
1964 {
56afb0f8
JB
1965 tracepoint_munge($file);
1966 }
b4870bc5 1967 dump_function($prototype, $file);
1da177e4
LT
1968 reset_state();
1969 }
1970}
1971
3c3b809e 1972sub process_state3_type($$) {
1da177e4
LT
1973 my $x = shift;
1974 my $file = shift;
1975
1da177e4
LT
1976 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1977 $x =~ s@^\s+@@gos; # strip leading spaces
1978 $x =~ s@\s+$@@gos; # strip trailing spaces
51f5a0c8
RD
1979 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1980
1da177e4
LT
1981 if ($x =~ /^#/) {
1982 # To distinguish preprocessor directive from regular declaration later.
1983 $x .= ";";
1984 }
1985
1986 while (1) {
3c308798 1987 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1da177e4
LT
1988 $prototype .= $1 . $2;
1989 ($2 eq '{') && $brcount++;
1990 ($2 eq '}') && $brcount--;
1991 if (($2 eq ';') && ($brcount == 0)) {
b9d97328 1992 dump_declaration($prototype, $file);
1da177e4 1993 reset_state();
3c308798 1994 last;
1da177e4
LT
1995 }
1996 $x = $3;
3c308798 1997 } else {
1da177e4
LT
1998 $prototype .= $x;
1999 last;
2000 }
2001 }
2002}
2003
6b5b55f6
RD
2004# xml_escape: replace <, >, and & in the text stream;
2005#
2006# however, formatting controls that are generated internally/locally in the
2007# kernel-doc script are not escaped here; instead, they begin life like
2008# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2009# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2010# just before actual output; (this is done by local_unescape())
1da177e4
LT
2011sub xml_escape($) {
2012 my $text = shift;
ecfb251a
RD
2013 if (($output_mode eq "text") || ($output_mode eq "man")) {
2014 return $text;
2015 }
1da177e4
LT
2016 $text =~ s/\&/\\\\\\amp;/g;
2017 $text =~ s/\</\\\\\\lt;/g;
2018 $text =~ s/\>/\\\\\\gt;/g;
2019 return $text;
2020}
2021
6b5b55f6
RD
2022# convert local escape strings to html
2023# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2024sub local_unescape($) {
2025 my $text = shift;
2026 if (($output_mode eq "text") || ($output_mode eq "man")) {
2027 return $text;
2028 }
2029 $text =~ s/\\\\\\\\lt:/</g;
2030 $text =~ s/\\\\\\\\gt:/>/g;
2031 return $text;
2032}
2033
1da177e4 2034sub process_file($) {
2283a117 2035 my $file;
1da177e4
LT
2036 my $identifier;
2037 my $func;
a21217da 2038 my $descr;
6423133b 2039 my $in_purpose = 0;
1da177e4
LT
2040 my $initial_section_counter = $section_counter;
2041
2283a117
RD
2042 if (defined($ENV{'SRCTREE'})) {
2043 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2044 }
2045 else {
2046 $file = "@_";
2047 }
1da177e4
LT
2048 if (defined($source_map{$file})) {
2049 $file = $source_map{$file};
2050 }
2051
2052 if (!open(IN,"<$file")) {
2053 print STDERR "Error: Cannot open file $file\n";
2054 ++$errors;
2055 return;
2056 }
2057
a9e7314b
ID
2058 $. = 1;
2059
1da177e4
LT
2060 $section_counter = 0;
2061 while (<IN>) {
65478428
DS
2062 while (s/\\\s*$//) {
2063 $_ .= <IN>;
2064 }
1da177e4
LT
2065 if ($state == 0) {
2066 if (/$doc_start/o) {
2067 $state = 1; # next line is always the function name
850622df 2068 $in_doc_sect = 0;
1da177e4
LT
2069 }
2070 } elsif ($state == 1) { # this line is the function name (always)
2071 if (/$doc_block/o) {
2072 $state = 4;
2073 $contents = "";
2074 if ( $1 eq "" ) {
2075 $section = $section_intro;
2076 } else {
2077 $section = $1;
2078 }
3c308798 2079 }
1da177e4
LT
2080 elsif (/$doc_decl/o) {
2081 $identifier = $1;
2082 if (/\s*([\w\s]+?)\s*-/) {
2083 $identifier = $1;
2084 }
2085
2086 $state = 2;
2087 if (/-(.*)/) {
51f5a0c8 2088 # strip leading/trailing/multiple spaces
a21217da
RD
2089 $descr= $1;
2090 $descr =~ s/^\s*//;
2091 $descr =~ s/\s*$//;
12ae6779 2092 $descr =~ s/\s+/ /g;
a21217da 2093 $declaration_purpose = xml_escape($descr);
6423133b 2094 $in_purpose = 1;
1da177e4
LT
2095 } else {
2096 $declaration_purpose = "";
2097 }
77cc23b8
RD
2098
2099 if (($declaration_purpose eq "") && $verbose) {
2100 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
2101 print STDERR $_;
2102 ++$warnings;
2103 }
2104
1da177e4
LT
2105 if ($identifier =~ m/^struct/) {
2106 $decl_type = 'struct';
2107 } elsif ($identifier =~ m/^union/) {
2108 $decl_type = 'union';
2109 } elsif ($identifier =~ m/^enum/) {
2110 $decl_type = 'enum';
2111 } elsif ($identifier =~ m/^typedef/) {
2112 $decl_type = 'typedef';
2113 } else {
2114 $decl_type = 'function';
2115 }
2116
2117 if ($verbose) {
2118 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
2119 }
2120 } else {
2121 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
2122 " - I thought it was a doc line\n";
2123 ++$warnings;
2124 $state = 0;
2125 }
2126 } elsif ($state == 2) { # look for head: lines, and include content
2127 if (/$doc_sect/o) {
2128 $newsection = $1;
2129 $newcontents = $2;
2130
792aa2f2 2131 if (($contents ne "") && ($contents ne "\n")) {
850622df
RD
2132 if (!$in_doc_sect && $verbose) {
2133 print STDERR "Warning(${file}:$.): contents before sections\n";
2134 ++$warnings;
2135 }
94dc7ad5 2136 dump_section($file, $section, xml_escape($contents));
1da177e4
LT
2137 $section = $section_default;
2138 }
2139
850622df 2140 $in_doc_sect = 1;
6423133b 2141 $in_purpose = 0;
1da177e4
LT
2142 $contents = $newcontents;
2143 if ($contents ne "") {
27205744
RD
2144 while ((substr($contents, 0, 1) eq " ") ||
2145 substr($contents, 0, 1) eq "\t") {
2146 $contents = substr($contents, 1);
05189497 2147 }
1da177e4
LT
2148 $contents .= "\n";
2149 }
2150 $section = $newsection;
2151 } elsif (/$doc_end/) {
2152
4c98ecaf 2153 if (($contents ne "") && ($contents ne "\n")) {
94dc7ad5 2154 dump_section($file, $section, xml_escape($contents));
1da177e4
LT
2155 $section = $section_default;
2156 $contents = "";
2157 }
46b958eb
RD
2158 # look for doc_com + <text> + doc_end:
2159 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2160 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
2161 ++$warnings;
2162 }
1da177e4
LT
2163
2164 $prototype = "";
2165 $state = 3;
2166 $brcount = 0;
232acbcf 2167# print STDERR "end of doc comment, looking for prototype\n";
1da177e4
LT
2168 } elsif (/$doc_content/) {
2169 # miguel-style comment kludge, look for blank lines after
2170 # @parameter line to signify start of description
6423133b
JW
2171 if ($1 eq "") {
2172 if ($section =~ m/^@/ || $section eq $section_context) {
2173 dump_section($file, $section, xml_escape($contents));
2174 $section = $section_default;
2175 $contents = "";
2176 } else {
2177 $contents .= "\n";
2178 }
2179 $in_purpose = 0;
2180 } elsif ($in_purpose == 1) {
2181 # Continued declaration purpose
2182 chomp($declaration_purpose);
2183 $declaration_purpose .= " " . xml_escape($1);
12ae6779 2184 $declaration_purpose =~ s/\s+/ /g;
1da177e4 2185 } else {
b9d97328 2186 $contents .= $1 . "\n";
1da177e4
LT
2187 }
2188 } else {
2189 # i dont know - bad line? ignore.
3c3b809e 2190 print STDERR "Warning(${file}:$.): bad line: $_";
1da177e4
LT
2191 ++$warnings;
2192 }
232acbcf 2193 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1da177e4 2194 if ($decl_type eq 'function') {
3c308798 2195 process_state3_function($_, $file);
1da177e4 2196 } else {
3c308798 2197 process_state3_type($_, $file);
1da177e4
LT
2198 }
2199 } elsif ($state == 4) {
2200 # Documentation block
3c308798 2201 if (/$doc_block/) {
94dc7ad5 2202 dump_doc_section($file, $section, xml_escape($contents));
1da177e4
LT
2203 $contents = "";
2204 $function = "";
2205 %constants = ();
2206 %parameterdescs = ();
2207 %parametertypes = ();
2208 @parameterlist = ();
2209 %sections = ();
2210 @sectionlist = ();
2211 $prototype = "";
2212 if ( $1 eq "" ) {
2213 $section = $section_intro;
2214 } else {
2215 $section = $1;
2216 }
3c308798 2217 }
1da177e4
LT
2218 elsif (/$doc_end/)
2219 {
94dc7ad5 2220 dump_doc_section($file, $section, xml_escape($contents));
1da177e4
LT
2221 $contents = "";
2222 $function = "";
2223 %constants = ();
2224 %parameterdescs = ();
2225 %parametertypes = ();
2226 @parameterlist = ();
2227 %sections = ();
2228 @sectionlist = ();
2229 $prototype = "";
2230 $state = 0;
2231 }
2232 elsif (/$doc_content/)
2233 {
2234 if ( $1 eq "" )
2235 {
2236 $contents .= $blankline;
2237 }
2238 else
2239 {
2240 $contents .= $1 . "\n";
3c3b809e 2241 }
3c308798
RD
2242 }
2243 }
1da177e4
LT
2244 }
2245 if ($initial_section_counter == $section_counter) {
2246 print STDERR "Warning(${file}): no structured comments found\n";
2247 if ($output_mode eq "xml") {
2248 # The template wants at least one RefEntry here; make one.
2249 print "<refentry>\n";
2250 print " <refnamediv>\n";
2251 print " <refname>\n";
2252 print " ${file}\n";
2253 print " </refname>\n";
2254 print " <refpurpose>\n";
2255 print " Document generation inconsistency\n";
2256 print " </refpurpose>\n";
2257 print " </refnamediv>\n";
2258 print " <refsect1>\n";
2259 print " <title>\n";
2260 print " Oops\n";
2261 print " </title>\n";
2262 print " <warning>\n";
2263 print " <para>\n";
2264 print " The template for this document tried to insert\n";
2265 print " the structured comment from the file\n";
2266 print " <filename>${file}</filename> at this point,\n";
2267 print " but none was found.\n";
2268 print " This dummy section is inserted to allow\n";
2269 print " generation to continue.\n";
2270 print " </para>\n";
2271 print " </warning>\n";
2272 print " </refsect1>\n";
2273 print "</refentry>\n";
2274 }
2275 }
2276}
8484baaa
RD
2277
2278
2279$kernelversion = get_kernel_version();
2280
2281# generate a sequence of code that will splice in highlighting information
2282# using the s// operator.
2283foreach my $pattern (keys %highlights) {
2284# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2285 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2286}
2287
2288# Read the file that maps relative names to absolute names for
2289# separate source and object directories and for shadow trees.
2290if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2291 my ($relname, $absname);
2292 while(<SOURCE_MAP>) {
2293 chop();
2294 ($relname, $absname) = (split())[0..1];
2295 $relname =~ s:^/+::;
2296 $source_map{$relname} = $absname;
2297 }
2298 close(SOURCE_MAP);
2299}
2300
2301foreach (@ARGV) {
2302 chomp;
2303 process_file($_);
2304}
2305if ($verbose && $errors) {
2306 print STDERR "$errors errors\n";
2307}
2308if ($verbose && $warnings) {
2309 print STDERR "$warnings warnings\n";
2310}
2311
2312exit($errors);
This page took 0.695322 seconds and 5 git commands to generate.