]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - scripts/kernel-doc
kernel-doc/rst: add support for &union foo and &typedef foo references
[mirror_ubuntu-bionic-kernel.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 ##
1b40c194 9## Copyright (C) 2012 Dan Luedtke ##
1da177e4
LT
10## ##
11## #define enhancements by Armin Kuster <akuster@mvista.com> ##
12## Copyright (c) 2000 MontaVista Software, Inc. ##
13## ##
14## This software falls under the GNU General Public License. ##
15## Please read the COPYING file for more information ##
16
1da177e4
LT
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
21
22# 27/06/2001 - Allowed whitespace after initial "/**" and
23# allowed comments before function declarations.
24# -- Christian Kreibich <ck@whoop.org>
25
26# Still to do:
27# - add perldoc documentation
28# - Look more closely at some of the scarier bits :)
29
30# 26/05/2001 - Support for separate source and object trees.
31# Return error code.
32# Keith Owens <kaos@ocs.com.au>
33
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>
38
1b40c194
DL
39# 25/07/2012 - Added support for HTML5
40# -- Dan Luedtke <mail@danrl.de>
1da177e4 41
fadc0b31
JN
42sub usage {
43 my $message = <<"EOF";
44Usage: $0 [OPTION ...] FILE ...
45
46Read C language source or header FILEs, extract embedded documentation comments,
47and print formatted documentation to standard output.
48
49The documentation comments are identified by "/**" opening comment mark. See
50Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
51
52Output format selection (mutually exclusive):
53 -docbook Output DocBook format.
54 -html Output HTML format.
55 -html5 Output HTML5 format.
56 -list Output symbol list format. This is for use by docproc.
57 -man Output troff manual page format. This is the default.
c0d1b6ee 58 -rst Output reStructuredText format.
fadc0b31
JN
59 -text Output plain text format.
60
61Output selection (mutually exclusive):
86ae2e38
JN
62 -export Only output documentation for symbols that have been
63 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
64 in the same FILE.
65 -internal Only output documentation for symbols that have NOT been
66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
67 in the same FILE.
fadc0b31
JN
68 -function NAME Only output documentation for the given function(s)
69 or DOC: section title(s). All other functions and DOC:
70 sections are ignored. May be specified multiple times.
71 -nofunction NAME Do NOT output documentation for the given function(s);
72 only output documentation for the other functions and
73 DOC: sections. May be specified multiple times.
74
75Output selection modifiers:
76 -no-doc-sections Do not output DOC: sections.
77
78Other parameters:
79 -v Verbose output, more warnings and other information.
80 -h Print this help.
81
82EOF
83 print $message;
84 exit 1;
85}
1da177e4
LT
86
87#
88# format of comments.
89# In the following table, (...)? signifies optional structure.
90# (...)* signifies 0 or more structure elements
91# /**
92# * function_name(:)? (- short description)?
93# (* @parameterx: (description of parameter x)?)*
94# (* a blank line)?
95# * (Description:)? (Description of function)?
96# * (section header: (section description)? )*
97# (*)?*/
98#
99# So .. the trivial example would be:
100#
101# /**
102# * my_function
b9d97328 103# */
1da177e4 104#
891dcd2f 105# If the Description: header tag is omitted, then there must be a blank line
1da177e4
LT
106# after the last parameter specification.
107# e.g.
108# /**
109# * my_function - does my stuff
110# * @my_arg: its mine damnit
111# *
3c3b809e 112# * Does my stuff explained.
1da177e4
LT
113# */
114#
115# or, could also use:
116# /**
117# * my_function - does my stuff
118# * @my_arg: its mine damnit
3c3b809e 119# * Description: Does my stuff explained.
1da177e4
LT
120# */
121# etc.
122#
b9d97328 123# Besides functions you can also write documentation for structs, unions,
3c3b809e
RD
124# enums and typedefs. Instead of the function name you must write the name
125# of the declaration; the struct/union/enum/typedef must always precede
126# the name. Nesting of declarations is not supported.
1da177e4
LT
127# Use the argument mechanism to document members or constants.
128# e.g.
129# /**
130# * struct my_struct - short description
131# * @a: first member
132# * @b: second member
3c3b809e 133# *
1da177e4
LT
134# * Longer description
135# */
136# struct my_struct {
137# int a;
138# int b;
aeec46b9
MW
139# /* private: */
140# int c;
1da177e4
LT
141# };
142#
143# All descriptions can be multiline, except the short function description.
3c3b809e 144#
a4c6ebed
DCLP
145# For really longs structs, you can also describe arguments inside the
146# body of the struct.
147# eg.
148# /**
149# * struct my_struct - short description
150# * @a: first member
151# * @b: second member
152# *
153# * Longer description
154# */
155# struct my_struct {
156# int a;
157# int b;
158# /**
159# * @c: This is longer description of C
160# *
161# * You can use paragraphs to describe arguments
162# * using this method.
163# */
164# int c;
165# };
166#
167# This should be use only for struct/enum members.
168#
3c3b809e
RD
169# You can also add additional sections. When documenting kernel functions you
170# should document the "Context:" of the function, e.g. whether the functions
1da177e4 171# can be called form interrupts. Unlike other sections you can end it with an
3c3b809e 172# empty line.
4092bac7
YB
173# A non-void function should have a "Return:" section describing the return
174# value(s).
3c3b809e 175# Example-sections should contain the string EXAMPLE so that they are marked
1da177e4
LT
176# appropriately in DocBook.
177#
178# Example:
179# /**
180# * user_function - function that can only be called in user context
181# * @a: some argument
182# * Context: !in_interrupt()
3c3b809e 183# *
1da177e4
LT
184# * Some description
185# * Example:
186# * user_function(22);
187# */
188# ...
189#
190#
191# All descriptive text is further processed, scanning for the following special
192# patterns, which are highlighted appropriately.
193#
194# 'funcname()' - function
195# '$ENVVAR' - environmental variable
196# '&struct_name' - name of a structure (up to two words including 'struct')
197# '@parameter' - name of a parameter
198# '%CONST' - name of a constant.
199
8484baaa
RD
200## init lots of data
201
1da177e4
LT
202my $errors = 0;
203my $warnings = 0;
5f8c7c98 204my $anon_struct_union = 0;
1da177e4
LT
205
206# match expressions used to find embedded type information
207my $type_constant = '\%([-_\w]+)';
208my $type_func = '(\w+)\(\)';
209my $type_param = '\@(\w+)';
3eb014a1 210my $type_struct = '\&((struct\s*)*[_\w]+)';
6b5b55f6 211my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
1da177e4 212my $type_env = '(\$\w+)';
c0d1b6ee
JC
213my $type_enum_full = '\&(enum)\s*([_\w]+)';
214my $type_struct_full = '\&(struct)\s*([_\w]+)';
47ae7aed
JN
215my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
216my $type_union_full = '\&(union)\s*([_\w]+)';
1da177e4
LT
217
218# Output conversion substitutions.
219# One for each output format
220
221# these work fairly well
4d732701
DCLP
222my @highlights_html = (
223 [$type_constant, "<i>\$1</i>"],
224 [$type_func, "<b>\$1</b>"],
225 [$type_struct_xml, "<i>\$1</i>"],
226 [$type_env, "<b><i>\$1</i></b>"],
227 [$type_param, "<tt><b>\$1</b></tt>"]
228 );
6b5b55f6
RD
229my $local_lt = "\\\\\\\\lt:";
230my $local_gt = "\\\\\\\\gt:";
231my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
1da177e4 232
1b40c194 233# html version 5
4d732701
DCLP
234my @highlights_html5 = (
235 [$type_constant, "<span class=\"const\">\$1</span>"],
236 [$type_func, "<span class=\"func\">\$1</span>"],
237 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
238 [$type_env, "<span class=\"env\">\$1</span>"],
239 [$type_param, "<span class=\"param\">\$1</span>]"]
240 );
1b40c194
DL
241my $blankline_html5 = $local_lt . "br /" . $local_gt;
242
1da177e4 243# XML, docbook format
4d732701
DCLP
244my @highlights_xml = (
245 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
246 [$type_constant, "<constant>\$1</constant>"],
247 [$type_struct_xml, "<structname>\$1</structname>"],
248 [$type_param, "<parameter>\$1</parameter>"],
249 [$type_func, "<function>\$1</function>"],
250 [$type_env, "<envar>\$1</envar>"]
251 );
5c98fc03 252my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
1da177e4
LT
253
254# gnome, docbook format
4d732701
DCLP
255my @highlights_gnome = (
256 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
257 [$type_func, "<function>\$1</function>"],
258 [$type_struct, "<structname>\$1</structname>"],
259 [$type_env, "<envar>\$1</envar>"],
260 [$type_param, "<parameter>\$1</parameter>" ]
261 );
1da177e4
LT
262my $blankline_gnome = "</para><para>\n";
263
264# these are pretty rough
4d732701
DCLP
265my @highlights_man = (
266 [$type_constant, "\$1"],
267 [$type_func, "\\\\fB\$1\\\\fP"],
268 [$type_struct, "\\\\fI\$1\\\\fP"],
269 [$type_param, "\\\\fI\$1\\\\fP"]
270 );
1da177e4
LT
271my $blankline_man = "";
272
273# text-mode
4d732701
DCLP
274my @highlights_text = (
275 [$type_constant, "\$1"],
276 [$type_func, "\$1"],
277 [$type_struct, "\$1"],
278 [$type_param, "\$1"]
279 );
1da177e4
LT
280my $blankline_text = "";
281
c0d1b6ee
JC
282# rst-mode
283my @highlights_rst = (
284 [$type_constant, "``\$1``"],
a19bce64 285 [$type_func, "\\:c\\:func\\:`\$1()`"],
62850976
JN
286 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
287 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
47ae7aed
JN
288 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
289 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
a7291e7e
JN
290 # in rst this can refer to any type
291 [$type_struct, "\\:c\\:type\\:`\$1`"],
c0d1b6ee
JC
292 [$type_param, "**\$1**"]
293 );
294my $blankline_rst = "\n";
295
eda603f6 296# list mode
4d732701
DCLP
297my @highlights_list = (
298 [$type_constant, "\$1"],
299 [$type_func, "\$1"],
300 [$type_struct, "\$1"],
301 [$type_param, "\$1"]
302 );
eda603f6 303my $blankline_list = "";
1da177e4 304
1da177e4 305# read arguments
b9d97328 306if ($#ARGV == -1) {
1da177e4
LT
307 usage();
308}
309
8484baaa
RD
310my $kernelversion;
311my $dohighlight = "";
312
1da177e4
LT
313my $verbose = 0;
314my $output_mode = "man";
e314ba31 315my $output_preformatted = 0;
4b44595a 316my $no_doc_sections = 0;
4d732701 317my @highlights = @highlights_man;
1da177e4
LT
318my $blankline = $blankline_man;
319my $modulename = "Kernel API";
b6c3f456
JN
320
321use constant {
322 OUTPUT_ALL => 0, # output all symbols and doc sections
323 OUTPUT_INCLUDE => 1, # output only specified symbols
324 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
325 OUTPUT_EXPORTED => 3, # output exported symbols
326 OUTPUT_INTERNAL => 4, # output non-exported symbols
327};
328my $output_selection = OUTPUT_ALL;
b2c4105b
BH
329my $show_not_found = 0;
330
331my @build_time;
332if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
333 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
334 @build_time = gmtime($seconds);
335} else {
336 @build_time = localtime;
337}
338
3c3b809e
RD
339my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
340 'July', 'August', 'September', 'October',
b2c4105b
BH
341 'November', 'December')[$build_time[4]] .
342 " " . ($build_time[5]+1900);
1da177e4 343
8484baaa 344# Essentially these are globals.
b9d97328
RD
345# They probably want to be tidied up, made more localised or something.
346# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
1da177e4 347# could cause "use of undefined value" or other bugs.
b9d97328
RD
348my ($function, %function_table, %parametertypes, $declaration_purpose);
349my ($type, $declaration_name, $return_type);
1c32fd0c 350my ($newsection, $newcontents, $prototype, $brcount, %source_map);
1da177e4 351
bd0e88e5
RD
352if (defined($ENV{'KBUILD_VERBOSE'})) {
353 $verbose = "$ENV{'KBUILD_VERBOSE'}";
354}
355
3c3b809e 356# Generated docbook code is inserted in a template at a point where
1da177e4
LT
357# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
358# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
359# We keep track of number of generated entries and generate a dummy
360# if needs be to ensure the expanded template can be postprocessed
361# into html.
362my $section_counter = 0;
363
364my $lineprefix="";
365
48af606a
JN
366# Parser states
367use constant {
368 STATE_NORMAL => 0, # normal code
369 STATE_NAME => 1, # looking for function name
370 STATE_FIELD => 2, # scanning field start
371 STATE_PROTO => 3, # scanning prototype
372 STATE_DOCBLOCK => 4, # documentation block
373 STATE_INLINE => 5, # gathering documentation outside main block
374};
1da177e4 375my $state;
850622df 376my $in_doc_sect;
1da177e4 377
48af606a
JN
378# Inline documentation state
379use constant {
380 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
381 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
382 STATE_INLINE_TEXT => 2, # looking for member documentation
383 STATE_INLINE_END => 3, # done
384 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
385 # Spit a warning as it's not
386 # proper kernel-doc and ignore the rest.
387};
388my $inline_doc_state;
a4c6ebed 389
1da177e4
LT
390#declaration types: can be
391# 'function', 'struct', 'union', 'enum', 'typedef'
392my $decl_type;
393
394my $doc_special = "\@\%\$\&";
395
396my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
397my $doc_end = '\*/';
398my $doc_com = '\s*\*\s*';
12ae6779 399my $doc_com_body = '\s*\* ?';
b9d97328
RD
400my $doc_decl = $doc_com . '(\w+)';
401my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
12ae6779 402my $doc_content = $doc_com_body . '(.*)';
b9d97328 403my $doc_block = $doc_com . 'DOC:\s*(.*)?';
48af606a
JN
404my $doc_inline_start = '^\s*/\*\*\s*$';
405my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
406my $doc_inline_end = '^\s*\*/\s*$';
86ae2e38 407my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
1da177e4
LT
408
409my %constants;
410my %parameterdescs;
411my @parameterlist;
412my %sections;
413my @sectionlist;
a1d94aa5
RD
414my $sectcheck;
415my $struct_actual;
1da177e4
LT
416
417my $contents = "";
418my $section_default = "Description"; # default section
419my $section_intro = "Introduction";
420my $section = $section_default;
421my $section_context = "Context";
4092bac7 422my $section_return = "Return";
1da177e4
LT
423
424my $undescribed = "-- undescribed --";
425
426reset_state();
427
428while ($ARGV[0] =~ m/^-(.*)/) {
429 my $cmd = shift @ARGV;
430 if ($cmd eq "-html") {
431 $output_mode = "html";
4d732701 432 @highlights = @highlights_html;
1da177e4 433 $blankline = $blankline_html;
1b40c194
DL
434 } elsif ($cmd eq "-html5") {
435 $output_mode = "html5";
4d732701 436 @highlights = @highlights_html5;
1b40c194 437 $blankline = $blankline_html5;
1da177e4
LT
438 } elsif ($cmd eq "-man") {
439 $output_mode = "man";
4d732701 440 @highlights = @highlights_man;
1da177e4
LT
441 $blankline = $blankline_man;
442 } elsif ($cmd eq "-text") {
443 $output_mode = "text";
4d732701 444 @highlights = @highlights_text;
1da177e4 445 $blankline = $blankline_text;
c0d1b6ee
JC
446 } elsif ($cmd eq "-rst") {
447 $output_mode = "rst";
448 @highlights = @highlights_rst;
449 $blankline = $blankline_rst;
1da177e4
LT
450 } elsif ($cmd eq "-docbook") {
451 $output_mode = "xml";
4d732701 452 @highlights = @highlights_xml;
1da177e4 453 $blankline = $blankline_xml;
eda603f6
JB
454 } elsif ($cmd eq "-list") {
455 $output_mode = "list";
4d732701 456 @highlights = @highlights_list;
eda603f6 457 $blankline = $blankline_list;
1da177e4
LT
458 } elsif ($cmd eq "-gnome") {
459 $output_mode = "gnome";
4d732701 460 @highlights = @highlights_gnome;
1da177e4
LT
461 $blankline = $blankline_gnome;
462 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
463 $modulename = shift @ARGV;
464 } elsif ($cmd eq "-function") { # to only output specific functions
b6c3f456 465 $output_selection = OUTPUT_INCLUDE;
1da177e4
LT
466 $function = shift @ARGV;
467 $function_table{$function} = 1;
b6c3f456
JN
468 } elsif ($cmd eq "-nofunction") { # output all except specific functions
469 $output_selection = OUTPUT_EXCLUDE;
1da177e4
LT
470 $function = shift @ARGV;
471 $function_table{$function} = 1;
86ae2e38 472 } elsif ($cmd eq "-export") { # only exported symbols
b6c3f456 473 $output_selection = OUTPUT_EXPORTED;
86ae2e38
JN
474 %function_table = ()
475 } elsif ($cmd eq "-internal") { # only non-exported symbols
b6c3f456 476 $output_selection = OUTPUT_INTERNAL;
86ae2e38 477 %function_table = ()
1da177e4
LT
478 } elsif ($cmd eq "-v") {
479 $verbose = 1;
480 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
481 usage();
4b44595a
JB
482 } elsif ($cmd eq '-no-doc-sections') {
483 $no_doc_sections = 1;
e946c43a
JB
484 } elsif ($cmd eq '-show-not-found') {
485 $show_not_found = 1;
1da177e4
LT
486 }
487}
488
8484baaa
RD
489# continue execution near EOF;
490
53f049fa
BP
491# get kernel version from env
492sub get_kernel_version() {
1b9bc22d 493 my $version = 'unknown kernel version';
53f049fa
BP
494
495 if (defined($ENV{'KERNELVERSION'})) {
496 $version = $ENV{'KERNELVERSION'};
497 }
498 return $version;
499}
1da177e4
LT
500
501##
502# dumps section contents to arrays/hashes intended for that purpose.
503#
504sub dump_section {
94dc7ad5 505 my $file = shift;
1da177e4
LT
506 my $name = shift;
507 my $contents = join "\n", @_;
508
509 if ($name =~ m/$type_constant/) {
510 $name = $1;
511# print STDERR "constant section '$1' = '$contents'\n";
512 $constants{$name} = $contents;
513 } elsif ($name =~ m/$type_param/) {
514# print STDERR "parameter def '$1' = '$contents'\n";
515 $name = $1;
516 $parameterdescs{$name} = $contents;
a1d94aa5 517 $sectcheck = $sectcheck . $name . " ";
ced69090
RD
518 } elsif ($name eq "@\.\.\.") {
519# print STDERR "parameter def '...' = '$contents'\n";
520 $name = "...";
521 $parameterdescs{$name} = $contents;
a1d94aa5 522 $sectcheck = $sectcheck . $name . " ";
1da177e4
LT
523 } else {
524# print STDERR "other section '$name' = '$contents'\n";
94dc7ad5 525 if (defined($sections{$name}) && ($sections{$name} ne "")) {
d40e1e65 526 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
94dc7ad5
RD
527 ++$errors;
528 }
1da177e4
LT
529 $sections{$name} = $contents;
530 push @sectionlist, $name;
531 }
532}
533
b112e0f7
JB
534##
535# dump DOC: section after checking that it should go out
536#
537sub dump_doc_section {
94dc7ad5 538 my $file = shift;
b112e0f7
JB
539 my $name = shift;
540 my $contents = join "\n", @_;
541
4b44595a
JB
542 if ($no_doc_sections) {
543 return;
544 }
545
b6c3f456
JN
546 if (($output_selection == OUTPUT_ALL) ||
547 ($output_selection == OUTPUT_INCLUDE &&
548 defined($function_table{$name})) ||
549 ($output_selection == OUTPUT_EXCLUDE &&
550 !defined($function_table{$name})))
b112e0f7 551 {
94dc7ad5 552 dump_section($file, $name, $contents);
b112e0f7
JB
553 output_blockhead({'sectionlist' => \@sectionlist,
554 'sections' => \%sections,
555 'module' => $modulename,
b6c3f456 556 'content-only' => ($output_selection != OUTPUT_ALL), });
b112e0f7
JB
557 }
558}
559
1da177e4
LT
560##
561# output function
562#
563# parameterdescs, a hash.
564# function => "function name"
565# parameterlist => @list of parameters
566# parameterdescs => %parameter descriptions
567# sectionlist => @list of sections
a21217da 568# sections => %section descriptions
3c3b809e 569#
1da177e4
LT
570
571sub output_highlight {
572 my $contents = join "\n",@_;
573 my $line;
574
575# DEBUG
576# if (!defined $contents) {
577# use Carp;
578# confess "output_highlight got called with no args?\n";
579# }
580
1b40c194
DL
581 if ($output_mode eq "html" || $output_mode eq "html5" ||
582 $output_mode eq "xml") {
6b5b55f6
RD
583 $contents = local_unescape($contents);
584 # convert data read & converted thru xml_escape() into &xyz; format:
2b35f4d9 585 $contents =~ s/\\\\\\/\&/g;
6b5b55f6 586 }
3eb014a1 587# print STDERR "contents b4:$contents\n";
1da177e4
LT
588 eval $dohighlight;
589 die $@ if $@;
3eb014a1
RD
590# print STDERR "contents af:$contents\n";
591
1b40c194
DL
592# strip whitespaces when generating html5
593 if ($output_mode eq "html5") {
594 $contents =~ s/^\s+//;
595 $contents =~ s/\s+$//;
596 }
1da177e4 597 foreach $line (split "\n", $contents) {
12ae6779
DS
598 if (! $output_preformatted) {
599 $line =~ s/^\s*//;
600 }
3c308798 601 if ($line eq ""){
e314ba31
DS
602 if (! $output_preformatted) {
603 print $lineprefix, local_unescape($blankline);
604 }
1da177e4 605 } else {
3c308798 606 $line =~ s/\\\\\\/\&/g;
cdccb316
RD
607 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
608 print "\\&$line";
609 } else {
610 print $lineprefix, $line;
611 }
1da177e4
LT
612 }
613 print "\n";
614 }
615}
616
1b40c194 617# output sections in html
1da177e4
LT
618sub output_section_html(%) {
619 my %args = %{$_[0]};
620 my $section;
621
622 foreach $section (@{$args{'sectionlist'}}) {
623 print "<h3>$section</h3>\n";
624 print "<blockquote>\n";
625 output_highlight($args{'sections'}{$section});
626 print "</blockquote>\n";
3c3b809e 627 }
1da177e4
LT
628}
629
630# output enum in html
631sub output_enum_html(%) {
632 my %args = %{$_[0]};
633 my ($parameter);
634 my $count;
b9d97328 635 print "<h2>enum " . $args{'enum'} . "</h2>\n";
1da177e4 636
b9d97328 637 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
1da177e4
LT
638 $count = 0;
639 foreach $parameter (@{$args{'parameterlist'}}) {
b9d97328 640 print " <b>" . $parameter . "</b>";
1da177e4
LT
641 if ($count != $#{$args{'parameterlist'}}) {
642 $count++;
643 print ",\n";
644 }
645 print "<br>";
646 }
647 print "};<br>\n";
648
649 print "<h3>Constants</h3>\n";
650 print "<dl>\n";
651 foreach $parameter (@{$args{'parameterlist'}}) {
b9d97328 652 print "<dt><b>" . $parameter . "</b>\n";
1da177e4
LT
653 print "<dd>";
654 output_highlight($args{'parameterdescs'}{$parameter});
655 }
656 print "</dl>\n";
657 output_section_html(@_);
658 print "<hr>\n";
659}
660
d28bee0c 661# output typedef in html
1da177e4
LT
662sub output_typedef_html(%) {
663 my %args = %{$_[0]};
664 my ($parameter);
665 my $count;
b9d97328 666 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
1da177e4 667
b9d97328 668 print "<b>typedef " . $args{'typedef'} . "</b>\n";
1da177e4
LT
669 output_section_html(@_);
670 print "<hr>\n";
671}
672
673# output struct in html
674sub output_struct_html(%) {
675 my %args = %{$_[0]};
676 my ($parameter);
677
b9d97328
RD
678 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
679 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
1da177e4
LT
680 foreach $parameter (@{$args{'parameterlist'}}) {
681 if ($parameter =~ /^#/) {
682 print "$parameter<br>\n";
683 next;
684 }
685 my $parameter_name = $parameter;
686 $parameter_name =~ s/\[.*//;
687
3c308798 688 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
689 $type = $args{'parametertypes'}{$parameter};
690 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
691 # pointer-to-function
3eb014a1 692 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
1da177e4 693 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
3eb014a1
RD
694 # bitfield
695 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
1da177e4 696 } else {
3eb014a1 697 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
1da177e4
LT
698 }
699 }
700 print "};<br>\n";
701
702 print "<h3>Members</h3>\n";
703 print "<dl>\n";
704 foreach $parameter (@{$args{'parameterlist'}}) {
705 ($parameter =~ /^#/) && next;
706
707 my $parameter_name = $parameter;
708 $parameter_name =~ s/\[.*//;
709
3c308798 710 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 711 print "<dt><b>" . $parameter . "</b>\n";
1da177e4
LT
712 print "<dd>";
713 output_highlight($args{'parameterdescs'}{$parameter_name});
714 }
715 print "</dl>\n";
716 output_section_html(@_);
717 print "<hr>\n";
718}
719
720# output function in html
721sub output_function_html(%) {
722 my %args = %{$_[0]};
723 my ($parameter, $section);
724 my $count;
1da177e4 725
b9d97328
RD
726 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
727 print "<i>" . $args{'functiontype'} . "</i>\n";
728 print "<b>" . $args{'function'} . "</b>\n";
1da177e4
LT
729 print "(";
730 $count = 0;
731 foreach $parameter (@{$args{'parameterlist'}}) {
732 $type = $args{'parametertypes'}{$parameter};
733 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
734 # pointer-to-function
735 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
736 } else {
b9d97328 737 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
1da177e4
LT
738 }
739 if ($count != $#{$args{'parameterlist'}}) {
740 $count++;
741 print ",\n";
742 }
743 }
744 print ")\n";
745
746 print "<h3>Arguments</h3>\n";
747 print "<dl>\n";
748 foreach $parameter (@{$args{'parameterlist'}}) {
749 my $parameter_name = $parameter;
750 $parameter_name =~ s/\[.*//;
751
3c308798 752 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 753 print "<dt><b>" . $parameter . "</b>\n";
1da177e4
LT
754 print "<dd>";
755 output_highlight($args{'parameterdescs'}{$parameter_name});
756 }
757 print "</dl>\n";
758 output_section_html(@_);
759 print "<hr>\n";
760}
761
b112e0f7
JB
762# output DOC: block header in html
763sub output_blockhead_html(%) {
1da177e4
LT
764 my %args = %{$_[0]};
765 my ($parameter, $section);
766 my $count;
767
768 foreach $section (@{$args{'sectionlist'}}) {
769 print "<h3>$section</h3>\n";
770 print "<ul>\n";
771 output_highlight($args{'sections'}{$section});
772 print "</ul>\n";
773 }
774 print "<hr>\n";
775}
776
1b40c194
DL
777# output sections in html5
778sub output_section_html5(%) {
779 my %args = %{$_[0]};
780 my $section;
781
782 foreach $section (@{$args{'sectionlist'}}) {
783 print "<section>\n";
784 print "<h1>$section</h1>\n";
785 print "<p>\n";
786 output_highlight($args{'sections'}{$section});
787 print "</p>\n";
788 print "</section>\n";
789 }
790}
791
792# output enum in html5
793sub output_enum_html5(%) {
794 my %args = %{$_[0]};
795 my ($parameter);
796 my $count;
797 my $html5id;
798
799 $html5id = $args{'enum'};
800 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
801 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
802 print "<h1>enum " . $args{'enum'} . "</h1>\n";
803 print "<ol class=\"code\">\n";
804 print "<li>";
805 print "<span class=\"keyword\">enum</span> ";
806 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
807 print "</li>\n";
808 $count = 0;
809 foreach $parameter (@{$args{'parameterlist'}}) {
810 print "<li class=\"indent\">";
811 print "<span class=\"param\">" . $parameter . "</span>";
812 if ($count != $#{$args{'parameterlist'}}) {
813 $count++;
814 print ",";
815 }
816 print "</li>\n";
817 }
818 print "<li>};</li>\n";
819 print "</ol>\n";
820
821 print "<section>\n";
822 print "<h1>Constants</h1>\n";
823 print "<dl>\n";
824 foreach $parameter (@{$args{'parameterlist'}}) {
825 print "<dt>" . $parameter . "</dt>\n";
826 print "<dd>";
827 output_highlight($args{'parameterdescs'}{$parameter});
828 print "</dd>\n";
829 }
830 print "</dl>\n";
831 print "</section>\n";
832 output_section_html5(@_);
833 print "</article>\n";
834}
835
836# output typedef in html5
837sub output_typedef_html5(%) {
838 my %args = %{$_[0]};
839 my ($parameter);
840 my $count;
841 my $html5id;
842
843 $html5id = $args{'typedef'};
844 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
845 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
846 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
847
848 print "<ol class=\"code\">\n";
849 print "<li>";
850 print "<span class=\"keyword\">typedef</span> ";
851 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
852 print "</li>\n";
853 print "</ol>\n";
854 output_section_html5(@_);
855 print "</article>\n";
856}
857
858# output struct in html5
859sub output_struct_html5(%) {
860 my %args = %{$_[0]};
861 my ($parameter);
862 my $html5id;
863
864 $html5id = $args{'struct'};
865 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
866 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
867 print "<hgroup>\n";
868 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
869 print "<h2>". $args{'purpose'} . "</h2>\n";
870 print "</hgroup>\n";
871 print "<ol class=\"code\">\n";
872 print "<li>";
873 print "<span class=\"type\">" . $args{'type'} . "</span> ";
874 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
875 print "</li>\n";
876 foreach $parameter (@{$args{'parameterlist'}}) {
877 print "<li class=\"indent\">";
878 if ($parameter =~ /^#/) {
879 print "<span class=\"param\">" . $parameter ."</span>\n";
880 print "</li>\n";
881 next;
882 }
883 my $parameter_name = $parameter;
884 $parameter_name =~ s/\[.*//;
885
886 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
887 $type = $args{'parametertypes'}{$parameter};
888 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
889 # pointer-to-function
890 print "<span class=\"type\">$1</span> ";
891 print "<span class=\"param\">$parameter</span>";
892 print "<span class=\"type\">)</span> ";
893 print "(<span class=\"args\">$2</span>);";
894 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
895 # bitfield
896 print "<span class=\"type\">$1</span> ";
897 print "<span class=\"param\">$parameter</span>";
898 print "<span class=\"bits\">$2</span>;";
899 } else {
900 print "<span class=\"type\">$type</span> ";
901 print "<span class=\"param\">$parameter</span>;";
902 }
903 print "</li>\n";
904 }
905 print "<li>};</li>\n";
906 print "</ol>\n";
907
908 print "<section>\n";
909 print "<h1>Members</h1>\n";
910 print "<dl>\n";
911 foreach $parameter (@{$args{'parameterlist'}}) {
912 ($parameter =~ /^#/) && next;
913
914 my $parameter_name = $parameter;
915 $parameter_name =~ s/\[.*//;
916
917 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
918 print "<dt>" . $parameter . "</dt>\n";
919 print "<dd>";
920 output_highlight($args{'parameterdescs'}{$parameter_name});
921 print "</dd>\n";
922 }
923 print "</dl>\n";
924 print "</section>\n";
925 output_section_html5(@_);
926 print "</article>\n";
927}
928
929# output function in html5
930sub output_function_html5(%) {
931 my %args = %{$_[0]};
932 my ($parameter, $section);
933 my $count;
934 my $html5id;
935
936 $html5id = $args{'function'};
937 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
938 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
939 print "<hgroup>\n";
940 print "<h1>" . $args{'function'} . "</h1>";
941 print "<h2>" . $args{'purpose'} . "</h2>\n";
942 print "</hgroup>\n";
943 print "<ol class=\"code\">\n";
944 print "<li>";
945 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
946 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
947 print "</li>";
948 $count = 0;
949 foreach $parameter (@{$args{'parameterlist'}}) {
950 print "<li class=\"indent\">";
951 $type = $args{'parametertypes'}{$parameter};
952 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
953 # pointer-to-function
954 print "<span class=\"type\">$1</span> ";
955 print "<span class=\"param\">$parameter</span>";
956 print "<span class=\"type\">)</span> ";
957 print "(<span class=\"args\">$2</span>)";
958 } else {
959 print "<span class=\"type\">$type</span> ";
960 print "<span class=\"param\">$parameter</span>";
961 }
962 if ($count != $#{$args{'parameterlist'}}) {
963 $count++;
964 print ",";
965 }
966 print "</li>\n";
967 }
968 print "<li>)</li>\n";
969 print "</ol>\n";
970
971 print "<section>\n";
972 print "<h1>Arguments</h1>\n";
973 print "<p>\n";
974 print "<dl>\n";
975 foreach $parameter (@{$args{'parameterlist'}}) {
976 my $parameter_name = $parameter;
977 $parameter_name =~ s/\[.*//;
978
979 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
980 print "<dt>" . $parameter . "</dt>\n";
981 print "<dd>";
982 output_highlight($args{'parameterdescs'}{$parameter_name});
983 print "</dd>\n";
984 }
985 print "</dl>\n";
986 print "</section>\n";
987 output_section_html5(@_);
988 print "</article>\n";
989}
990
991# output DOC: block header in html5
992sub output_blockhead_html5(%) {
993 my %args = %{$_[0]};
994 my ($parameter, $section);
995 my $count;
996 my $html5id;
997
998 foreach $section (@{$args{'sectionlist'}}) {
999 $html5id = $section;
1000 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1001 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1002 print "<h1>$section</h1>\n";
1003 print "<p>\n";
1004 output_highlight($args{'sections'}{$section});
1005 print "</p>\n";
1006 }
1007 print "</article>\n";
1008}
1009
1da177e4
LT
1010sub output_section_xml(%) {
1011 my %args = %{$_[0]};
3c3b809e 1012 my $section;
1da177e4
LT
1013 # print out each section
1014 $lineprefix=" ";
1015 foreach $section (@{$args{'sectionlist'}}) {
c73894c1
RW
1016 print "<refsect1>\n";
1017 print "<title>$section</title>\n";
1da177e4 1018 if ($section =~ m/EXAMPLE/i) {
c73894c1 1019 print "<informalexample><programlisting>\n";
e314ba31 1020 $output_preformatted = 1;
c73894c1
RW
1021 } else {
1022 print "<para>\n";
1da177e4
LT
1023 }
1024 output_highlight($args{'sections'}{$section});
e314ba31 1025 $output_preformatted = 0;
1da177e4 1026 if ($section =~ m/EXAMPLE/i) {
c73894c1
RW
1027 print "</programlisting></informalexample>\n";
1028 } else {
1029 print "</para>\n";
1da177e4 1030 }
c73894c1 1031 print "</refsect1>\n";
1da177e4
LT
1032 }
1033}
1034
1035# output function in XML DocBook
1036sub output_function_xml(%) {
1037 my %args = %{$_[0]};
1038 my ($parameter, $section);
1039 my $count;
1040 my $id;
1041
b9d97328 1042 $id = "API-" . $args{'function'};
1da177e4
LT
1043 $id =~ s/[^A-Za-z0-9]/-/g;
1044
5449bc94 1045 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
1046 print "<refentryinfo>\n";
1047 print " <title>LINUX</title>\n";
1048 print " <productname>Kernel Hackers Manual</productname>\n";
1049 print " <date>$man_date</date>\n";
1050 print "</refentryinfo>\n";
1da177e4 1051 print "<refmeta>\n";
b9d97328 1052 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
8b0c2d98 1053 print " <manvolnum>9</manvolnum>\n";
0366299b 1054 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1da177e4
LT
1055 print "</refmeta>\n";
1056 print "<refnamediv>\n";
b9d97328 1057 print " <refname>" . $args{'function'} . "</refname>\n";
1da177e4
LT
1058 print " <refpurpose>\n";
1059 print " ";
1060 output_highlight ($args{'purpose'});
1061 print " </refpurpose>\n";
1062 print "</refnamediv>\n";
1063
1064 print "<refsynopsisdiv>\n";
1065 print " <title>Synopsis</title>\n";
1066 print " <funcsynopsis><funcprototype>\n";
b9d97328
RD
1067 print " <funcdef>" . $args{'functiontype'} . " ";
1068 print "<function>" . $args{'function'} . " </function></funcdef>\n";
1da177e4
LT
1069
1070 $count = 0;
1071 if ($#{$args{'parameterlist'}} >= 0) {
1072 foreach $parameter (@{$args{'parameterlist'}}) {
1073 $type = $args{'parametertypes'}{$parameter};
1074 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1075 # pointer-to-function
1076 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1077 print " <funcparams>$2</funcparams></paramdef>\n";
1078 } else {
b9d97328 1079 print " <paramdef>" . $type;
1da177e4
LT
1080 print " <parameter>$parameter</parameter></paramdef>\n";
1081 }
1082 }
1083 } else {
6013d544 1084 print " <void/>\n";
1da177e4
LT
1085 }
1086 print " </funcprototype></funcsynopsis>\n";
1087 print "</refsynopsisdiv>\n";
1088
1089 # print parameters
1090 print "<refsect1>\n <title>Arguments</title>\n";
1091 if ($#{$args{'parameterlist'}} >= 0) {
1092 print " <variablelist>\n";
1093 foreach $parameter (@{$args{'parameterlist'}}) {
1094 my $parameter_name = $parameter;
1095 $parameter_name =~ s/\[.*//;
1096
1097 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1098 print " <listitem>\n <para>\n";
1099 $lineprefix=" ";
1100 output_highlight($args{'parameterdescs'}{$parameter_name});
1101 print " </para>\n </listitem>\n </varlistentry>\n";
1102 }
1103 print " </variablelist>\n";
1104 } else {
1105 print " <para>\n None\n </para>\n";
1106 }
1107 print "</refsect1>\n";
1108
1109 output_section_xml(@_);
1110 print "</refentry>\n\n";
1111}
1112
1113# output struct in XML DocBook
1114sub output_struct_xml(%) {
1115 my %args = %{$_[0]};
1116 my ($parameter, $section);
1117 my $id;
1118
b9d97328 1119 $id = "API-struct-" . $args{'struct'};
1da177e4
LT
1120 $id =~ s/[^A-Za-z0-9]/-/g;
1121
5449bc94 1122 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
1123 print "<refentryinfo>\n";
1124 print " <title>LINUX</title>\n";
1125 print " <productname>Kernel Hackers Manual</productname>\n";
1126 print " <date>$man_date</date>\n";
1127 print "</refentryinfo>\n";
1da177e4 1128 print "<refmeta>\n";
b9d97328 1129 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
8b0c2d98 1130 print " <manvolnum>9</manvolnum>\n";
0366299b 1131 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1da177e4
LT
1132 print "</refmeta>\n";
1133 print "<refnamediv>\n";
b9d97328 1134 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
1da177e4
LT
1135 print " <refpurpose>\n";
1136 print " ";
1137 output_highlight ($args{'purpose'});
1138 print " </refpurpose>\n";
1139 print "</refnamediv>\n";
1140
1141 print "<refsynopsisdiv>\n";
1142 print " <title>Synopsis</title>\n";
1143 print " <programlisting>\n";
b9d97328 1144 print $args{'type'} . " " . $args{'struct'} . " {\n";
1da177e4
LT
1145 foreach $parameter (@{$args{'parameterlist'}}) {
1146 if ($parameter =~ /^#/) {
2b35f4d9
RD
1147 my $prm = $parameter;
1148 # convert data read & converted thru xml_escape() into &xyz; format:
1149 # This allows us to have #define macros interspersed in a struct.
1150 $prm =~ s/\\\\\\/\&/g;
1151 print "$prm\n";
1da177e4
LT
1152 next;
1153 }
1154
1155 my $parameter_name = $parameter;
1156 $parameter_name =~ s/\[.*//;
1157
1158 defined($args{'parameterdescs'}{$parameter_name}) || next;
3c308798 1159 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
1160 $type = $args{'parametertypes'}{$parameter};
1161 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1162 # pointer-to-function
1163 print " $1 $parameter) ($2);\n";
1164 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
51f5a0c8 1165 # bitfield
1da177e4
LT
1166 print " $1 $parameter$2;\n";
1167 } else {
b9d97328 1168 print " " . $type . " " . $parameter . ";\n";
1da177e4
LT
1169 }
1170 }
1171 print "};";
1172 print " </programlisting>\n";
1173 print "</refsynopsisdiv>\n";
1174
1175 print " <refsect1>\n";
1176 print " <title>Members</title>\n";
1177
39f00c08 1178 if ($#{$args{'parameterlist'}} >= 0) {
1da177e4
LT
1179 print " <variablelist>\n";
1180 foreach $parameter (@{$args{'parameterlist'}}) {
1181 ($parameter =~ /^#/) && next;
1182
1183 my $parameter_name = $parameter;
1184 $parameter_name =~ s/\[.*//;
1185
1186 defined($args{'parameterdescs'}{$parameter_name}) || next;
1187 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1188 print " <varlistentry>";
1189 print " <term>$parameter</term>\n";
1190 print " <listitem><para>\n";
1191 output_highlight($args{'parameterdescs'}{$parameter_name});
1192 print " </para></listitem>\n";
1193 print " </varlistentry>\n";
1194 }
1195 print " </variablelist>\n";
39f00c08
RD
1196 } else {
1197 print " <para>\n None\n </para>\n";
1198 }
1da177e4
LT
1199 print " </refsect1>\n";
1200
1201 output_section_xml(@_);
1202
1203 print "</refentry>\n\n";
1204}
1205
1206# output enum in XML DocBook
1207sub output_enum_xml(%) {
1208 my %args = %{$_[0]};
1209 my ($parameter, $section);
1210 my $count;
1211 my $id;
1212
b9d97328 1213 $id = "API-enum-" . $args{'enum'};
1da177e4
LT
1214 $id =~ s/[^A-Za-z0-9]/-/g;
1215
5449bc94 1216 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
1217 print "<refentryinfo>\n";
1218 print " <title>LINUX</title>\n";
1219 print " <productname>Kernel Hackers Manual</productname>\n";
1220 print " <date>$man_date</date>\n";
1221 print "</refentryinfo>\n";
1da177e4 1222 print "<refmeta>\n";
b9d97328 1223 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
8b0c2d98 1224 print " <manvolnum>9</manvolnum>\n";
0366299b 1225 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
1da177e4
LT
1226 print "</refmeta>\n";
1227 print "<refnamediv>\n";
b9d97328 1228 print " <refname>enum " . $args{'enum'} . "</refname>\n";
1da177e4
LT
1229 print " <refpurpose>\n";
1230 print " ";
1231 output_highlight ($args{'purpose'});
1232 print " </refpurpose>\n";
1233 print "</refnamediv>\n";
1234
1235 print "<refsynopsisdiv>\n";
1236 print " <title>Synopsis</title>\n";
1237 print " <programlisting>\n";
b9d97328 1238 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
1239 $count = 0;
1240 foreach $parameter (@{$args{'parameterlist'}}) {
3c308798
RD
1241 print " $parameter";
1242 if ($count != $#{$args{'parameterlist'}}) {
1da177e4
LT
1243 $count++;
1244 print ",";
3c308798 1245 }
1da177e4
LT
1246 print "\n";
1247 }
1248 print "};";
1249 print " </programlisting>\n";
1250 print "</refsynopsisdiv>\n";
1251
1252 print "<refsect1>\n";
3c3b809e 1253 print " <title>Constants</title>\n";
1da177e4
LT
1254 print " <variablelist>\n";
1255 foreach $parameter (@{$args{'parameterlist'}}) {
1256 my $parameter_name = $parameter;
1257 $parameter_name =~ s/\[.*//;
1258
1259 print " <varlistentry>";
1260 print " <term>$parameter</term>\n";
1261 print " <listitem><para>\n";
1262 output_highlight($args{'parameterdescs'}{$parameter_name});
1263 print " </para></listitem>\n";
1264 print " </varlistentry>\n";
1265 }
1266 print " </variablelist>\n";
1267 print "</refsect1>\n";
1268
1269 output_section_xml(@_);
1270
1271 print "</refentry>\n\n";
1272}
1273
1274# output typedef in XML DocBook
1275sub output_typedef_xml(%) {
1276 my %args = %{$_[0]};
1277 my ($parameter, $section);
1278 my $id;
1279
b9d97328 1280 $id = "API-typedef-" . $args{'typedef'};
1da177e4
LT
1281 $id =~ s/[^A-Za-z0-9]/-/g;
1282
5449bc94 1283 print "<refentry id=\"$id\">\n";
8b0c2d98
MW
1284 print "<refentryinfo>\n";
1285 print " <title>LINUX</title>\n";
1286 print " <productname>Kernel Hackers Manual</productname>\n";
1287 print " <date>$man_date</date>\n";
1288 print "</refentryinfo>\n";
1da177e4 1289 print "<refmeta>\n";
b9d97328 1290 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
8b0c2d98 1291 print " <manvolnum>9</manvolnum>\n";
1da177e4
LT
1292 print "</refmeta>\n";
1293 print "<refnamediv>\n";
b9d97328 1294 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
1da177e4
LT
1295 print " <refpurpose>\n";
1296 print " ";
1297 output_highlight ($args{'purpose'});
1298 print " </refpurpose>\n";
1299 print "</refnamediv>\n";
1300
1301 print "<refsynopsisdiv>\n";
1302 print " <title>Synopsis</title>\n";
b9d97328 1303 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
1da177e4
LT
1304 print "</refsynopsisdiv>\n";
1305
1306 output_section_xml(@_);
1307
1308 print "</refentry>\n\n";
1309}
1310
1311# output in XML DocBook
b112e0f7 1312sub output_blockhead_xml(%) {
1da177e4
LT
1313 my %args = %{$_[0]};
1314 my ($parameter, $section);
1315 my $count;
1316
1317 my $id = $args{'module'};
1318 $id =~ s/[^A-Za-z0-9]/-/g;
1319
1320 # print out each section
1321 $lineprefix=" ";
1322 foreach $section (@{$args{'sectionlist'}}) {
b112e0f7
JB
1323 if (!$args{'content-only'}) {
1324 print "<refsect1>\n <title>$section</title>\n";
1325 }
1da177e4
LT
1326 if ($section =~ m/EXAMPLE/i) {
1327 print "<example><para>\n";
e314ba31 1328 $output_preformatted = 1;
b112e0f7
JB
1329 } else {
1330 print "<para>\n";
1da177e4
LT
1331 }
1332 output_highlight($args{'sections'}{$section});
e314ba31 1333 $output_preformatted = 0;
1da177e4
LT
1334 if ($section =~ m/EXAMPLE/i) {
1335 print "</para></example>\n";
b112e0f7
JB
1336 } else {
1337 print "</para>";
1338 }
1339 if (!$args{'content-only'}) {
1340 print "\n</refsect1>\n";
1da177e4 1341 }
1da177e4
LT
1342 }
1343
1344 print "\n\n";
1345}
1346
1347# output in XML DocBook
1348sub output_function_gnome {
1349 my %args = %{$_[0]};
1350 my ($parameter, $section);
1351 my $count;
1352 my $id;
1353
b9d97328 1354 $id = $args{'module'} . "-" . $args{'function'};
1da177e4
LT
1355 $id =~ s/[^A-Za-z0-9]/-/g;
1356
1357 print "<sect2>\n";
b9d97328 1358 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
1da177e4
LT
1359
1360 print " <funcsynopsis>\n";
b9d97328
RD
1361 print " <funcdef>" . $args{'functiontype'} . " ";
1362 print "<function>" . $args{'function'} . " ";
1da177e4
LT
1363 print "</function></funcdef>\n";
1364
1365 $count = 0;
1366 if ($#{$args{'parameterlist'}} >= 0) {
1367 foreach $parameter (@{$args{'parameterlist'}}) {
1368 $type = $args{'parametertypes'}{$parameter};
1369 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1370 # pointer-to-function
1371 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1372 print " <funcparams>$2</funcparams></paramdef>\n";
1373 } else {
b9d97328 1374 print " <paramdef>" . $type;
1da177e4
LT
1375 print " <parameter>$parameter</parameter></paramdef>\n";
1376 }
1377 }
1378 } else {
1379 print " <void>\n";
1380 }
1381 print " </funcsynopsis>\n";
1382 if ($#{$args{'parameterlist'}} >= 0) {
1383 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1384 print "<tgroup cols=\"2\">\n";
1385 print "<colspec colwidth=\"2*\">\n";
1386 print "<colspec colwidth=\"8*\">\n";
1387 print "<tbody>\n";
1388 foreach $parameter (@{$args{'parameterlist'}}) {
1389 my $parameter_name = $parameter;
1390 $parameter_name =~ s/\[.*//;
1391
1392 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1393 print " <entry>\n";
1394 $lineprefix=" ";
1395 output_highlight($args{'parameterdescs'}{$parameter_name});
1396 print " </entry></row>\n";
1397 }
1398 print " </tbody></tgroup></informaltable>\n";
1399 } else {
1400 print " <para>\n None\n </para>\n";
1401 }
1402
1403 # print out each section
1404 $lineprefix=" ";
1405 foreach $section (@{$args{'sectionlist'}}) {
1406 print "<simplesect>\n <title>$section</title>\n";
1407 if ($section =~ m/EXAMPLE/i) {
1408 print "<example><programlisting>\n";
e314ba31 1409 $output_preformatted = 1;
1da177e4
LT
1410 } else {
1411 }
1412 print "<para>\n";
1413 output_highlight($args{'sections'}{$section});
e314ba31 1414 $output_preformatted = 0;
1da177e4
LT
1415 print "</para>\n";
1416 if ($section =~ m/EXAMPLE/i) {
1417 print "</programlisting></example>\n";
1418 } else {
1419 }
1420 print " </simplesect>\n";
1421 }
1422
1423 print "</sect2>\n\n";
1424}
1425
1426##
1427# output function in man
1428sub output_function_man(%) {
1429 my %args = %{$_[0]};
1430 my ($parameter, $section);
1431 my $count;
1432
1433 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1434
1435 print ".SH NAME\n";
b9d97328 1436 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1437
1438 print ".SH SYNOPSIS\n";
a21217da 1439 if ($args{'functiontype'} ne "") {
b9d97328 1440 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
a21217da 1441 } else {
b9d97328 1442 print ".B \"" . $args{'function'} . "\n";
a21217da 1443 }
1da177e4
LT
1444 $count = 0;
1445 my $parenth = "(";
1446 my $post = ",";
1447 foreach my $parameter (@{$args{'parameterlist'}}) {
1448 if ($count == $#{$args{'parameterlist'}}) {
1449 $post = ");";
1450 }
1451 $type = $args{'parametertypes'}{$parameter};
1452 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1453 # pointer-to-function
b9d97328 1454 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1da177e4
LT
1455 } else {
1456 $type =~ s/([^\*])$/$1 /;
b9d97328 1457 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1da177e4
LT
1458 }
1459 $count++;
1460 $parenth = "";
1461 }
1462
1463 print ".SH ARGUMENTS\n";
1464 foreach $parameter (@{$args{'parameterlist'}}) {
1465 my $parameter_name = $parameter;
1466 $parameter_name =~ s/\[.*//;
1467
b9d97328 1468 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
1469 output_highlight($args{'parameterdescs'}{$parameter_name});
1470 }
1471 foreach $section (@{$args{'sectionlist'}}) {
1472 print ".SH \"", uc $section, "\"\n";
1473 output_highlight($args{'sections'}{$section});
1474 }
1475}
1476
1477##
1478# output enum in man
1479sub output_enum_man(%) {
1480 my %args = %{$_[0]};
1481 my ($parameter, $section);
1482 my $count;
1483
1484 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1485
1486 print ".SH NAME\n";
b9d97328 1487 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1488
1489 print ".SH SYNOPSIS\n";
b9d97328 1490 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
1491 $count = 0;
1492 foreach my $parameter (@{$args{'parameterlist'}}) {
3c308798 1493 print ".br\n.BI \" $parameter\"\n";
1da177e4
LT
1494 if ($count == $#{$args{'parameterlist'}}) {
1495 print "\n};\n";
1496 last;
1497 }
1498 else {
1499 print ", \n.br\n";
1500 }
1501 $count++;
1502 }
1503
1504 print ".SH Constants\n";
1505 foreach $parameter (@{$args{'parameterlist'}}) {
1506 my $parameter_name = $parameter;
1507 $parameter_name =~ s/\[.*//;
1508
b9d97328 1509 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
1510 output_highlight($args{'parameterdescs'}{$parameter_name});
1511 }
1512 foreach $section (@{$args{'sectionlist'}}) {
1513 print ".SH \"$section\"\n";
1514 output_highlight($args{'sections'}{$section});
1515 }
1516}
1517
1518##
1519# output struct in man
1520sub output_struct_man(%) {
1521 my %args = %{$_[0]};
1522 my ($parameter, $section);
1523
b9d97328 1524 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1da177e4
LT
1525
1526 print ".SH NAME\n";
b9d97328 1527 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1528
1529 print ".SH SYNOPSIS\n";
b9d97328 1530 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
1da177e4
LT
1531
1532 foreach my $parameter (@{$args{'parameterlist'}}) {
1533 if ($parameter =~ /^#/) {
1534 print ".BI \"$parameter\"\n.br\n";
1535 next;
1536 }
1537 my $parameter_name = $parameter;
1538 $parameter_name =~ s/\[.*//;
1539
3c308798 1540 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
1541 $type = $args{'parametertypes'}{$parameter};
1542 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1543 # pointer-to-function
b9d97328 1544 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
1da177e4 1545 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1d7e1d45 1546 # bitfield
b9d97328 1547 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
1da177e4
LT
1548 } else {
1549 $type =~ s/([^\*])$/$1 /;
b9d97328 1550 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
1da177e4
LT
1551 }
1552 print "\n.br\n";
1553 }
1554 print "};\n.br\n";
1555
c51d3dac 1556 print ".SH Members\n";
1da177e4
LT
1557 foreach $parameter (@{$args{'parameterlist'}}) {
1558 ($parameter =~ /^#/) && next;
1559
1560 my $parameter_name = $parameter;
1561 $parameter_name =~ s/\[.*//;
1562
3c308798 1563 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 1564 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
1565 output_highlight($args{'parameterdescs'}{$parameter_name});
1566 }
1567 foreach $section (@{$args{'sectionlist'}}) {
1568 print ".SH \"$section\"\n";
1569 output_highlight($args{'sections'}{$section});
1570 }
1571}
1572
1573##
1574# output typedef in man
1575sub output_typedef_man(%) {
1576 my %args = %{$_[0]};
1577 my ($parameter, $section);
1578
1579 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1580
1581 print ".SH NAME\n";
b9d97328 1582 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
1583
1584 foreach $section (@{$args{'sectionlist'}}) {
1585 print ".SH \"$section\"\n";
1586 output_highlight($args{'sections'}{$section});
1587 }
1588}
1589
b112e0f7 1590sub output_blockhead_man(%) {
1da177e4
LT
1591 my %args = %{$_[0]};
1592 my ($parameter, $section);
1593 my $count;
1594
1595 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1596
1597 foreach $section (@{$args{'sectionlist'}}) {
1598 print ".SH \"$section\"\n";
1599 output_highlight($args{'sections'}{$section});
1600 }
1601}
1602
1603##
1604# output in text
1605sub output_function_text(%) {
1606 my %args = %{$_[0]};
1607 my ($parameter, $section);
a21217da 1608 my $start;
1da177e4 1609
f47634b2 1610 print "Name:\n\n";
b9d97328 1611 print $args{'function'} . " - " . $args{'purpose'} . "\n";
f47634b2
RD
1612
1613 print "\nSynopsis:\n\n";
a21217da 1614 if ($args{'functiontype'} ne "") {
b9d97328 1615 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
a21217da 1616 } else {
b9d97328 1617 $start = $args{'function'} . " (";
a21217da 1618 }
1da177e4 1619 print $start;
a21217da 1620
1da177e4
LT
1621 my $count = 0;
1622 foreach my $parameter (@{$args{'parameterlist'}}) {
1623 $type = $args{'parametertypes'}{$parameter};
1624 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1625 # pointer-to-function
b9d97328 1626 print $1 . $parameter . ") (" . $2;
1da177e4 1627 } else {
b9d97328 1628 print $type . " " . $parameter;
1da177e4
LT
1629 }
1630 if ($count != $#{$args{'parameterlist'}}) {
1631 $count++;
1632 print ",\n";
1633 print " " x length($start);
1634 } else {
1635 print ");\n\n";
1636 }
1637 }
1638
1639 print "Arguments:\n\n";
1640 foreach $parameter (@{$args{'parameterlist'}}) {
1641 my $parameter_name = $parameter;
1642 $parameter_name =~ s/\[.*//;
1643
b9d97328 1644 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
1da177e4
LT
1645 }
1646 output_section_text(@_);
1647}
1648
1649#output sections in text
1650sub output_section_text(%) {
1651 my %args = %{$_[0]};
1652 my $section;
1653
1654 print "\n";
1655 foreach $section (@{$args{'sectionlist'}}) {
1656 print "$section:\n\n";
1657 output_highlight($args{'sections'}{$section});
3c3b809e 1658 }
1da177e4
LT
1659 print "\n\n";
1660}
1661
1662# output enum in text
1663sub output_enum_text(%) {
1664 my %args = %{$_[0]};
1665 my ($parameter);
1666 my $count;
1667 print "Enum:\n\n";
1668
b9d97328
RD
1669 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1670 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
1671 $count = 0;
1672 foreach $parameter (@{$args{'parameterlist'}}) {
3c308798 1673 print "\t$parameter";
1da177e4
LT
1674 if ($count != $#{$args{'parameterlist'}}) {
1675 $count++;
1676 print ",";
1677 }
1678 print "\n";
1679 }
1680 print "};\n\n";
1681
1682 print "Constants:\n\n";
1683 foreach $parameter (@{$args{'parameterlist'}}) {
1684 print "$parameter\n\t";
b9d97328 1685 print $args{'parameterdescs'}{$parameter} . "\n";
1da177e4
LT
1686 }
1687
1688 output_section_text(@_);
1689}
1690
1691# output typedef in text
1692sub output_typedef_text(%) {
1693 my %args = %{$_[0]};
1694 my ($parameter);
1695 my $count;
1696 print "Typedef:\n\n";
1697
b9d97328 1698 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
1da177e4
LT
1699 output_section_text(@_);
1700}
1701
1702# output struct as text
1703sub output_struct_text(%) {
1704 my %args = %{$_[0]};
1705 my ($parameter);
1706
b9d97328
RD
1707 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1708 print $args{'type'} . " " . $args{'struct'} . " {\n";
1da177e4
LT
1709 foreach $parameter (@{$args{'parameterlist'}}) {
1710 if ($parameter =~ /^#/) {
1711 print "$parameter\n";
1712 next;
1713 }
1714
1715 my $parameter_name = $parameter;
1716 $parameter_name =~ s/\[.*//;
1717
3c308798 1718 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4
LT
1719 $type = $args{'parametertypes'}{$parameter};
1720 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1721 # pointer-to-function
1722 print "\t$1 $parameter) ($2);\n";
1723 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
51f5a0c8 1724 # bitfield
1da177e4
LT
1725 print "\t$1 $parameter$2;\n";
1726 } else {
b9d97328 1727 print "\t" . $type . " " . $parameter . ";\n";
1da177e4
LT
1728 }
1729 }
1730 print "};\n\n";
1731
1732 print "Members:\n\n";
1733 foreach $parameter (@{$args{'parameterlist'}}) {
1734 ($parameter =~ /^#/) && next;
1735
1736 my $parameter_name = $parameter;
1737 $parameter_name =~ s/\[.*//;
1738
3c308798 1739 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1da177e4 1740 print "$parameter\n\t";
b9d97328 1741 print $args{'parameterdescs'}{$parameter_name} . "\n";
1da177e4
LT
1742 }
1743 print "\n";
1744 output_section_text(@_);
1745}
1746
b112e0f7 1747sub output_blockhead_text(%) {
1da177e4
LT
1748 my %args = %{$_[0]};
1749 my ($parameter, $section);
1750
1751 foreach $section (@{$args{'sectionlist'}}) {
1752 print " $section:\n";
1753 print " -> ";
1754 output_highlight($args{'sections'}{$section});
1755 }
1756}
1757
c0d1b6ee
JC
1758##
1759# output in restructured text
1760#
1761
1762#
1763# This could use some work; it's used to output the DOC: sections, and
1764# starts by putting out the name of the doc section itself, but that tends
1765# to duplicate a header already in the template file.
1766#
1767sub output_blockhead_rst(%) {
1768 my %args = %{$_[0]};
1769 my ($parameter, $section);
1770
1771 foreach $section (@{$args{'sectionlist'}}) {
9e72184b
JN
1772 if ($output_selection != OUTPUT_INCLUDE) {
1773 print "**$section**\n\n";
1774 }
c0d1b6ee
JC
1775 output_highlight_rst($args{'sections'}{$section});
1776 print "\n";
1777 }
1778}
1779
1780sub output_highlight_rst {
1781 my $contents = join "\n",@_;
1782 my $line;
1783
1784 # undo the evil effects of xml_escape() earlier
1785 $contents = xml_unescape($contents);
1786
1787 eval $dohighlight;
1788 die $@ if $@;
1789
1790 foreach $line (split "\n", $contents) {
1791 if ($line eq "") {
1792 print $lineprefix, $blankline;
1793 } else {
1794 $line =~ s/\\\\\\/\&/g;
1795 print $lineprefix, $line;
1796 }
1797 print "\n";
1798 }
1799}
1800
1801sub output_function_rst(%) {
1802 my %args = %{$_[0]};
1803 my ($parameter, $section);
1804 my $start;
1805
1806 print ".. c:function:: ";
1807 if ($args{'functiontype'} ne "") {
1808 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1809 } else {
1810 $start = $args{'function'} . " (";
1811 }
1812 print $start;
1813
1814 my $count = 0;
1815 foreach my $parameter (@{$args{'parameterlist'}}) {
1816 if ($count ne 0) {
1817 print ", ";
1818 }
1819 $count++;
1820 $type = $args{'parametertypes'}{$parameter};
1821 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1822 # pointer-to-function
1823 print $1 . $parameter . ") (" . $2;
1824 } else {
1825 print $type . " " . $parameter;
1826 }
1827 }
1828 print ")\n\n " . $args{'purpose'} . "\n\n";
1829
1830 print ":Parameters:\n\n";
1831 foreach $parameter (@{$args{'parameterlist'}}) {
1832 my $parameter_name = $parameter;
1833 #$parameter_name =~ s/\[.*//;
1834 $type = $args{'parametertypes'}{$parameter};
1835
1836 if ($type ne "") {
1837 print " ``$type $parameter``\n";
1838 } else {
1839 print " ``$parameter``\n";
1840 }
5e64fa9c
JN
1841 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1842 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
c0d1b6ee
JC
1843 my $oldprefix = $lineprefix;
1844 $lineprefix = " ";
1845 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1846 $lineprefix = $oldprefix;
1847 } else {
1848 print "\n _undescribed_\n";
1849 }
1850 print "\n";
1851 }
1852 output_section_rst(@_);
1853}
1854
1855sub output_section_rst(%) {
1856 my %args = %{$_[0]};
1857 my $section;
1858 my $oldprefix = $lineprefix;
1859 $lineprefix = " ";
1860
1861 foreach $section (@{$args{'sectionlist'}}) {
1862 print ":$section:\n\n";
1863 output_highlight_rst($args{'sections'}{$section});
1864 print "\n";
1865 }
1866 print "\n";
1867 $lineprefix = $oldprefix;
1868}
1869
1870sub output_enum_rst(%) {
1871 my %args = %{$_[0]};
1872 my ($parameter);
1873 my $count;
c0d1b6ee 1874 my $name = "enum " . $args{'enum'};
62850976
JN
1875
1876 print "\n\n.. c:type:: " . $name . "\n\n";
c0d1b6ee
JC
1877 print " " . $args{'purpose'} . "\n\n";
1878
1879 print "..\n\n:Constants:\n\n";
1880 my $oldprefix = $lineprefix;
1881 $lineprefix = " ";
1882 foreach $parameter (@{$args{'parameterlist'}}) {
1883 print " `$parameter`\n";
1884 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1885 output_highlight_rst($args{'parameterdescs'}{$parameter});
1886 } else {
1887 print " undescribed\n";
1888 }
1889 print "\n";
1890 }
1891 $lineprefix = $oldprefix;
1892 output_section_rst(@_);
1893}
1894
1895sub output_typedef_rst(%) {
1896 my %args = %{$_[0]};
1897 my ($parameter);
1898 my $count;
1899 my $name = "typedef " . $args{'typedef'};
1900
62850976
JN
1901 ### FIXME: should the name below contain "typedef" or not?
1902 print "\n\n.. c:type:: " . $name . "\n\n";
1903 print " " . $args{'purpose'} . "\n\n";
c0d1b6ee
JC
1904
1905 output_section_rst(@_);
1906}
1907
1908sub output_struct_rst(%) {
1909 my %args = %{$_[0]};
1910 my ($parameter);
1911 my $name = $args{'type'} . " " . $args{'struct'};
1912
62850976 1913 print "\n\n.. c:type:: " . $name . "\n\n";
c0d1b6ee
JC
1914 print " " . $args{'purpose'} . "\n\n";
1915
1916 print ":Definition:\n\n";
1917 print " ::\n\n";
1918 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1919 foreach $parameter (@{$args{'parameterlist'}}) {
1920 if ($parameter =~ /^#/) {
1921 print " " . "$parameter\n";
1922 next;
1923 }
1924
1925 my $parameter_name = $parameter;
1926 $parameter_name =~ s/\[.*//;
1927
1928 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1929 $type = $args{'parametertypes'}{$parameter};
1930 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1931 # pointer-to-function
1932 print " $1 $parameter) ($2);\n";
1933 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1934 # bitfield
1935 print " $1 $parameter$2;\n";
1936 } else {
1937 print " " . $type . " " . $parameter . ";\n";
1938 }
1939 }
1940 print " };\n\n";
1941
1942 print ":Members:\n\n";
1943 foreach $parameter (@{$args{'parameterlist'}}) {
1944 ($parameter =~ /^#/) && next;
1945
1946 my $parameter_name = $parameter;
1947 $parameter_name =~ s/\[.*//;
1948
1949 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1950 $type = $args{'parametertypes'}{$parameter};
1951 print " `$type $parameter`" . "\n";
1952 my $oldprefix = $lineprefix;
1953 $lineprefix = " ";
1954 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1955 $lineprefix = $oldprefix;
1956 print "\n";
1957 }
1958 print "\n";
1959 output_section_rst(@_);
1960}
1961
1962
eda603f6
JB
1963## list mode output functions
1964
1965sub output_function_list(%) {
1966 my %args = %{$_[0]};
1967
1968 print $args{'function'} . "\n";
1969}
1970
1971# output enum in list
1972sub output_enum_list(%) {
1973 my %args = %{$_[0]};
1974 print $args{'enum'} . "\n";
1975}
1976
1977# output typedef in list
1978sub output_typedef_list(%) {
1979 my %args = %{$_[0]};
1980 print $args{'typedef'} . "\n";
1981}
1982
1983# output struct as list
1984sub output_struct_list(%) {
1985 my %args = %{$_[0]};
1986
1987 print $args{'struct'} . "\n";
1988}
1989
1990sub output_blockhead_list(%) {
1991 my %args = %{$_[0]};
1992 my ($parameter, $section);
1993
1994 foreach $section (@{$args{'sectionlist'}}) {
1995 print "DOC: $section\n";
1996 }
1997}
1998
1da177e4 1999##
27205744
RD
2000# generic output function for all types (function, struct/union, typedef, enum);
2001# calls the generated, variable output_ function name based on
2002# functype and output_mode
1da177e4
LT
2003sub output_declaration {
2004 no strict 'refs';
2005 my $name = shift;
2006 my $functype = shift;
2007 my $func = "output_${functype}_$output_mode";
b6c3f456
JN
2008 if (($output_selection == OUTPUT_ALL) ||
2009 (($output_selection == OUTPUT_INCLUDE ||
2010 $output_selection == OUTPUT_EXPORTED) &&
2011 defined($function_table{$name})) ||
2012 (($output_selection == OUTPUT_EXCLUDE ||
2013 $output_selection == OUTPUT_INTERNAL) &&
2014 !($functype eq "function" && defined($function_table{$name}))))
1da177e4 2015 {
3c308798 2016 &$func(@_);
1da177e4
LT
2017 $section_counter++;
2018 }
2019}
2020
2021##
27205744 2022# generic output function - calls the right one based on current output mode.
b112e0f7 2023sub output_blockhead {
1da177e4 2024 no strict 'refs';
b9d97328 2025 my $func = "output_blockhead_" . $output_mode;
1da177e4
LT
2026 &$func(@_);
2027 $section_counter++;
2028}
2029
2030##
3c3b809e 2031# takes a declaration (struct, union, enum, typedef) and
1da177e4
LT
2032# invokes the right handler. NOT called for functions.
2033sub dump_declaration($$) {
2034 no strict 'refs';
2035 my ($prototype, $file) = @_;
b9d97328 2036 my $func = "dump_" . $decl_type;
1da177e4
LT
2037 &$func(@_);
2038}
2039
2040sub dump_union($$) {
2041 dump_struct(@_);
2042}
2043
2044sub dump_struct($$) {
2045 my $x = shift;
2046 my $file = shift;
a1d94aa5 2047 my $nested;
1da177e4 2048
52dc5aec
RD
2049 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2050 #my $decl_type = $1;
3c308798
RD
2051 $declaration_name = $2;
2052 my $members = $3;
1da177e4
LT
2053
2054 # ignore embedded structs or unions
a1d94aa5
RD
2055 $members =~ s/({.*})//g;
2056 $nested = $1;
1da177e4 2057
aeec46b9 2058 # ignore members marked private:
0d8c39e6
MCC
2059 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2060 $members =~ s/\/\*\s*private:.*//gosi;
aeec46b9
MW
2061 # strip comments:
2062 $members =~ s/\/\*.*?\*\///gos;
a1d94aa5 2063 $nested =~ s/\/\*.*?\*\///gos;
d960eea9
RD
2064 # strip kmemcheck_bitfield_{begin,end}.*;
2065 $members =~ s/kmemcheck_bitfield_.*?;//gos;
ef5da59f 2066 # strip attributes
f0074929 2067 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
7b990789 2068 $members =~ s/__aligned\s*\([^;]*\)//gos;
f0074929 2069 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
b22b5a9e
CN
2070 # replace DECLARE_BITMAP
2071 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
aeec46b9 2072
1da177e4 2073 create_parameterlist($members, ';', $file);
a1d94aa5 2074 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
1da177e4
LT
2075
2076 output_declaration($declaration_name,
2077 'struct',
2078 {'struct' => $declaration_name,
2079 'module' => $modulename,
2080 'parameterlist' => \@parameterlist,
2081 'parameterdescs' => \%parameterdescs,
2082 'parametertypes' => \%parametertypes,
2083 'sectionlist' => \@sectionlist,
2084 'sections' => \%sections,
2085 'purpose' => $declaration_purpose,
2086 'type' => $decl_type
2087 });
2088 }
2089 else {
d40e1e65 2090 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
1da177e4
LT
2091 ++$errors;
2092 }
2093}
2094
2095sub dump_enum($$) {
2096 my $x = shift;
2097 my $file = shift;
2098
aeec46b9 2099 $x =~ s@/\*.*?\*/@@gos; # strip comments.
4468e21e
CN
2100 # strip #define macros inside enums
2101 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
b6d676db 2102
1da177e4 2103 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
3c308798
RD
2104 $declaration_name = $1;
2105 my $members = $2;
1da177e4
LT
2106
2107 foreach my $arg (split ',', $members) {
2108 $arg =~ s/^\s*(\w+).*/$1/;
2109 push @parameterlist, $arg;
2110 if (!$parameterdescs{$arg}) {
3c308798 2111 $parameterdescs{$arg} = $undescribed;
d40e1e65 2112 print STDERR "${file}:$.: warning: Enum value '$arg' ".
1da177e4
LT
2113 "not described in enum '$declaration_name'\n";
2114 }
2115
2116 }
3c3b809e 2117
1da177e4
LT
2118 output_declaration($declaration_name,
2119 'enum',
2120 {'enum' => $declaration_name,
2121 'module' => $modulename,
2122 'parameterlist' => \@parameterlist,
2123 'parameterdescs' => \%parameterdescs,
2124 'sectionlist' => \@sectionlist,
2125 'sections' => \%sections,
2126 'purpose' => $declaration_purpose
2127 });
2128 }
2129 else {
d40e1e65 2130 print STDERR "${file}:$.: error: Cannot parse enum!\n";
1da177e4
LT
2131 ++$errors;
2132 }
2133}
2134
2135sub dump_typedef($$) {
2136 my $x = shift;
2137 my $file = shift;
2138
aeec46b9 2139 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1da177e4 2140
83766452
MCC
2141 # Parse function prototypes
2142 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2143 # Function typedefs
2144 $return_type = $1;
2145 $declaration_name = $2;
2146 my $args = $3;
2147
2148 create_parameterlist($args, ',', $file);
1da177e4
LT
2149
2150 output_declaration($declaration_name,
83766452
MCC
2151 'function',
2152 {'function' => $declaration_name,
1da177e4 2153 'module' => $modulename,
83766452
MCC
2154 'functiontype' => $return_type,
2155 'parameterlist' => \@parameterlist,
2156 'parameterdescs' => \%parameterdescs,
2157 'parametertypes' => \%parametertypes,
1da177e4
LT
2158 'sectionlist' => \@sectionlist,
2159 'sections' => \%sections,
2160 'purpose' => $declaration_purpose
2161 });
83766452
MCC
2162 return;
2163 }
2164
2165 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
2166 $x =~ s/\(*.\)\s*;$/;/;
2167 $x =~ s/\[*.\]\s*;$/;/;
1da177e4 2168 }
83766452
MCC
2169
2170 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
3a80a766
MCC
2171 $declaration_name = $1;
2172
2173 output_declaration($declaration_name,
2174 'typedef',
2175 {'typedef' => $declaration_name,
2176 'module' => $modulename,
2177 'sectionlist' => \@sectionlist,
2178 'sections' => \%sections,
2179 'purpose' => $declaration_purpose
2180 });
2181 }
1da177e4 2182 else {
d40e1e65 2183 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
1da177e4
LT
2184 ++$errors;
2185 }
2186}
2187
a1d94aa5
RD
2188sub save_struct_actual($) {
2189 my $actual = shift;
2190
2191 # strip all spaces from the actual param so that it looks like one string item
2192 $actual =~ s/\s*//g;
2193 $struct_actual = $struct_actual . $actual . " ";
2194}
2195
1da177e4
LT
2196sub create_parameterlist($$$) {
2197 my $args = shift;
2198 my $splitter = shift;
2199 my $file = shift;
2200 my $type;
2201 my $param;
2202
a6d3fe77 2203 # temporarily replace commas inside function pointer definition
1da177e4 2204 while ($args =~ /(\([^\),]+),/) {
3c308798 2205 $args =~ s/(\([^\),]+),/$1#/g;
1da177e4 2206 }
3c3b809e 2207
1da177e4
LT
2208 foreach my $arg (split($splitter, $args)) {
2209 # strip comments
2210 $arg =~ s/\/\*.*\*\///;
3c308798
RD
2211 # strip leading/trailing spaces
2212 $arg =~ s/^\s*//;
1da177e4
LT
2213 $arg =~ s/\s*$//;
2214 $arg =~ s/\s+/ /;
2215
2216 if ($arg =~ /^#/) {
2217 # Treat preprocessor directive as a typeless variable just to fill
2218 # corresponding data structures "correctly". Catch it later in
2219 # output_* subs.
2220 push_parameter($arg, "", $file);
00d62961 2221 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1da177e4
LT
2222 # pointer-to-function
2223 $arg =~ tr/#/,/;
00d62961 2224 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1da177e4
LT
2225 $param = $1;
2226 $type = $arg;
00d62961 2227 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
a1d94aa5 2228 save_struct_actual($param);
1da177e4 2229 push_parameter($param, $type, $file);
aeec46b9 2230 } elsif ($arg) {
1da177e4
LT
2231 $arg =~ s/\s*:\s*/:/g;
2232 $arg =~ s/\s*\[/\[/g;
2233
2234 my @args = split('\s*,\s*', $arg);
2235 if ($args[0] =~ m/\*/) {
2236 $args[0] =~ s/(\*+)\s*/ $1/;
2237 }
884f2810
BP
2238
2239 my @first_arg;
2240 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2241 shift @args;
2242 push(@first_arg, split('\s+', $1));
2243 push(@first_arg, $2);
2244 } else {
2245 @first_arg = split('\s+', shift @args);
2246 }
2247
1da177e4
LT
2248 unshift(@args, pop @first_arg);
2249 $type = join " ", @first_arg;
2250
2251 foreach $param (@args) {
2252 if ($param =~ m/^(\*+)\s*(.*)/) {
a1d94aa5 2253 save_struct_actual($2);
1da177e4
LT
2254 push_parameter($2, "$type $1", $file);
2255 }
2256 elsif ($param =~ m/(.*?):(\d+)/) {
7b97887e 2257 if ($type ne "") { # skip unnamed bit-fields
a1d94aa5 2258 save_struct_actual($1);
7b97887e
RD
2259 push_parameter($1, "$type:$2", $file)
2260 }
1da177e4
LT
2261 }
2262 else {
a1d94aa5 2263 save_struct_actual($param);
1da177e4
LT
2264 push_parameter($param, $type, $file);
2265 }
2266 }
2267 }
2268 }
2269}
2270
2271sub push_parameter($$$) {
2272 my $param = shift;
2273 my $type = shift;
2274 my $file = shift;
2275
5f8c7c98
RD
2276 if (($anon_struct_union == 1) && ($type eq "") &&
2277 ($param eq "}")) {
2278 return; # ignore the ending }; from anon. struct/union
2279 }
2280
2281 $anon_struct_union = 0;
1da177e4
LT
2282 my $param_name = $param;
2283 $param_name =~ s/\[.*//;
2284
a6d3fe77 2285 if ($type eq "" && $param =~ /\.\.\.$/)
1da177e4 2286 {
ced69090
RD
2287 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2288 $parameterdescs{$param} = "variable arguments";
2289 }
1da177e4
LT
2290 }
2291 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2292 {
1da177e4
LT
2293 $param="void";
2294 $parameterdescs{void} = "no arguments";
2295 }
134fe01b
RD
2296 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2297 # handle unnamed (anonymous) union or struct:
2298 {
2299 $type = $param;
5f8c7c98 2300 $param = "{unnamed_" . $param . "}";
134fe01b 2301 $parameterdescs{$param} = "anonymous\n";
5f8c7c98 2302 $anon_struct_union = 1;
134fe01b
RD
2303 }
2304
a6d3fe77 2305 # warn if parameter has no description
134fe01b
RD
2306 # (but ignore ones starting with # as these are not parameters
2307 # but inline preprocessor statements);
2308 # also ignore unnamed structs/unions;
5f8c7c98 2309 if (!$anon_struct_union) {
a6d3fe77
MW
2310 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2311
1da177e4
LT
2312 $parameterdescs{$param_name} = $undescribed;
2313
2314 if (($type eq 'function') || ($type eq 'enum')) {
d40e1e65 2315 print STDERR "${file}:$.: warning: Function parameter ".
1da177e4
LT
2316 "or member '$param' not " .
2317 "described in '$declaration_name'\n";
2318 }
d40e1e65 2319 print STDERR "${file}:$.: warning:" .
3c308798 2320 " No description found for parameter '$param'\n";
1da177e4 2321 ++$warnings;
3c308798
RD
2322 }
2323 }
1da177e4 2324
2b35f4d9
RD
2325 $param = xml_escape($param);
2326
25985edc 2327 # strip spaces from $param so that it is one continuous string
e34e7dbb
RD
2328 # on @parameterlist;
2329 # this fixes a problem where check_sections() cannot find
2330 # a parameter like "addr[6 + 2]" because it actually appears
2331 # as "addr[6", "+", "2]" on the parameter list;
2332 # but it's better to maintain the param string unchanged for output,
2333 # so just weaken the string compare in check_sections() to ignore
2334 # "[blah" in a parameter string;
2335 ###$param =~ s/\s*//g;
1da177e4
LT
2336 push @parameterlist, $param;
2337 $parametertypes{$param} = $type;
2338}
2339
a1d94aa5
RD
2340sub check_sections($$$$$$) {
2341 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2342 my @sects = split ' ', $sectcheck;
2343 my @prms = split ' ', $prmscheck;
2344 my $err;
2345 my ($px, $sx);
2346 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2347
2348 foreach $sx (0 .. $#sects) {
2349 $err = 1;
2350 foreach $px (0 .. $#prms) {
2351 $prm_clean = $prms[$px];
2352 $prm_clean =~ s/\[.*\]//;
1f3a6688 2353 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
e34e7dbb
RD
2354 # ignore array size in a parameter string;
2355 # however, the original param string may contain
2356 # spaces, e.g.: addr[6 + 2]
2357 # and this appears in @prms as "addr[6" since the
2358 # parameter list is split at spaces;
2359 # hence just ignore "[..." for the sections check;
2360 $prm_clean =~ s/\[.*//;
2361
a1d94aa5
RD
2362 ##$prm_clean =~ s/^\**//;
2363 if ($prm_clean eq $sects[$sx]) {
2364 $err = 0;
2365 last;
2366 }
2367 }
2368 if ($err) {
2369 if ($decl_type eq "function") {
d40e1e65 2370 print STDERR "${file}:$.: warning: " .
a1d94aa5
RD
2371 "Excess function parameter " .
2372 "'$sects[$sx]' " .
2373 "description in '$decl_name'\n";
2374 ++$warnings;
2375 } else {
2376 if ($nested !~ m/\Q$sects[$sx]\E/) {
d40e1e65 2377 print STDERR "${file}:$.: warning: " .
a1d94aa5
RD
2378 "Excess struct/union/enum/typedef member " .
2379 "'$sects[$sx]' " .
2380 "description in '$decl_name'\n";
2381 ++$warnings;
2382 }
2383 }
2384 }
2385 }
2386}
2387
4092bac7
YB
2388##
2389# Checks the section describing the return value of a function.
2390sub check_return_section {
2391 my $file = shift;
2392 my $declaration_name = shift;
2393 my $return_type = shift;
2394
2395 # Ignore an empty return type (It's a macro)
2396 # Ignore functions with a "void" return type. (But don't ignore "void *")
2397 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2398 return;
2399 }
2400
2401 if (!defined($sections{$section_return}) ||
2402 $sections{$section_return} eq "") {
d40e1e65 2403 print STDERR "${file}:$.: warning: " .
4092bac7
YB
2404 "No description found for return value of " .
2405 "'$declaration_name'\n";
2406 ++$warnings;
2407 }
2408}
2409
1da177e4
LT
2410##
2411# takes a function prototype and the name of the current file being
2412# processed and spits out all the details stored in the global
2413# arrays/hashes.
2414sub dump_function($$) {
2415 my $prototype = shift;
2416 my $file = shift;
cbb4d3e6 2417 my $noret = 0;
1da177e4
LT
2418
2419 $prototype =~ s/^static +//;
2420 $prototype =~ s/^extern +//;
4dc3b16b 2421 $prototype =~ s/^asmlinkage +//;
1da177e4
LT
2422 $prototype =~ s/^inline +//;
2423 $prototype =~ s/^__inline__ +//;
32e79401
RD
2424 $prototype =~ s/^__inline +//;
2425 $prototype =~ s/^__always_inline +//;
2426 $prototype =~ s/^noinline +//;
74fc5c65 2427 $prototype =~ s/__init +//;
20072205 2428 $prototype =~ s/__init_or_module +//;
270a0096 2429 $prototype =~ s/__meminit +//;
70c95b00 2430 $prototype =~ s/__must_check +//;
0df7c0e3 2431 $prototype =~ s/__weak +//;
cbb4d3e6 2432 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
328d2440 2433 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1da177e4
LT
2434
2435 # Yes, this truly is vile. We are looking for:
2436 # 1. Return type (may be nothing if we're looking at a macro)
2437 # 2. Function name
2438 # 3. Function parameters.
2439 #
2440 # All the while we have to watch out for function pointer parameters
2441 # (which IIRC is what the two sections are for), C types (these
2442 # regexps don't even start to express all the possibilities), and
2443 # so on.
2444 #
2445 # If you mess with these regexps, it's a good idea to check that
2446 # the following functions' documentation still comes out right:
2447 # - parport_register_device (function pointer parameters)
2448 # - atomic_set (macro)
9598f91f 2449 # - pci_match_device, __copy_to_user (long return type)
1da177e4 2450
cbb4d3e6
HG
2451 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2452 # This is an object-like macro, it has no return type and no parameter
2453 # list.
2454 # Function-like macros are not allowed to have spaces between
2455 # declaration_name and opening parenthesis (notice the \s+).
2456 $return_type = $1;
2457 $declaration_name = $2;
2458 $noret = 1;
2459 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4
LT
2460 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2461 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2462 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
94b3e03c 2463 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4
LT
2464 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2465 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2466 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2467 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2468 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2469 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2470 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2471 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
9598f91f
MW
2472 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2473 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
412ecd77
RD
2474 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2475 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1da177e4
LT
2476 $return_type = $1;
2477 $declaration_name = $2;
2478 my $args = $3;
2479
2480 create_parameterlist($args, ',', $file);
2481 } else {
d40e1e65 2482 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
1da177e4
LT
2483 return;
2484 }
2485
a1d94aa5
RD
2486 my $prms = join " ", @parameterlist;
2487 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2488
4092bac7
YB
2489 # This check emits a lot of warnings at the moment, because many
2490 # functions don't have a 'Return' doc section. So until the number
2491 # of warnings goes sufficiently down, the check is only performed in
2492 # verbose mode.
2493 # TODO: always perform the check.
cbb4d3e6 2494 if ($verbose && !$noret) {
4092bac7
YB
2495 check_return_section($file, $declaration_name, $return_type);
2496 }
2497
3c3b809e 2498 output_declaration($declaration_name,
1da177e4
LT
2499 'function',
2500 {'function' => $declaration_name,
2501 'module' => $modulename,
2502 'functiontype' => $return_type,
2503 'parameterlist' => \@parameterlist,
2504 'parameterdescs' => \%parameterdescs,
2505 'parametertypes' => \%parametertypes,
2506 'sectionlist' => \@sectionlist,
2507 'sections' => \%sections,
2508 'purpose' => $declaration_purpose
2509 });
2510}
2511
1da177e4
LT
2512sub reset_state {
2513 $function = "";
2514 %constants = ();
2515 %parameterdescs = ();
2516 %parametertypes = ();
2517 @parameterlist = ();
2518 %sections = ();
2519 @sectionlist = ();
a1d94aa5
RD
2520 $sectcheck = "";
2521 $struct_actual = "";
1da177e4 2522 $prototype = "";
3c3b809e 2523
48af606a
JN
2524 $state = STATE_NORMAL;
2525 $inline_doc_state = STATE_INLINE_NA;
1da177e4
LT
2526}
2527
56afb0f8
JB
2528sub tracepoint_munge($) {
2529 my $file = shift;
2530 my $tracepointname = 0;
2531 my $tracepointargs = 0;
2532
3a9089fd 2533 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
56afb0f8
JB
2534 $tracepointname = $1;
2535 }
3a9089fd
JB
2536 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2537 $tracepointname = $1;
2538 }
2539 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2540 $tracepointname = $2;
2541 }
2542 $tracepointname =~ s/^\s+//; #strip leading whitespace
2543 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
56afb0f8
JB
2544 $tracepointargs = $1;
2545 }
2546 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
d40e1e65 2547 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
56afb0f8
JB
2548 "$prototype\n";
2549 } else {
2550 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2551 }
2552}
2553
b4870bc5
RD
2554sub syscall_munge() {
2555 my $void = 0;
2556
2557 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2558## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2559 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2560 $void = 1;
2561## $prototype = "long sys_$1(void)";
2562 }
2563
2564 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2565 if ($prototype =~ m/long (sys_.*?),/) {
2566 $prototype =~ s/,/\(/;
2567 } elsif ($void) {
2568 $prototype =~ s/\)/\(void\)/;
2569 }
2570
2571 # now delete all of the odd-number commas in $prototype
2572 # so that arg types & arg names don't have a comma between them
2573 my $count = 0;
2574 my $len = length($prototype);
2575 if ($void) {
2576 $len = 0; # skip the for-loop
2577 }
2578 for (my $ix = 0; $ix < $len; $ix++) {
2579 if (substr($prototype, $ix, 1) eq ',') {
2580 $count++;
2581 if ($count % 2 == 1) {
2582 substr($prototype, $ix, 1) = ' ';
2583 }
2584 }
2585 }
2586}
2587
3c3b809e 2588sub process_state3_function($$) {
1da177e4
LT
2589 my $x = shift;
2590 my $file = shift;
2591
51f5a0c8
RD
2592 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2593
890c78c2 2594 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1da177e4
LT
2595 # do nothing
2596 }
2597 elsif ($x =~ /([^\{]*)/) {
3c308798 2598 $prototype .= $1;
1da177e4 2599 }
b4870bc5 2600
890c78c2 2601 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
3c308798 2602 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1da177e4
LT
2603 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2604 $prototype =~ s@^\s+@@gos; # strip leading spaces
b4870bc5
RD
2605 if ($prototype =~ /SYSCALL_DEFINE/) {
2606 syscall_munge();
2607 }
3a9089fd
JB
2608 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2609 $prototype =~ /DEFINE_SINGLE_EVENT/)
2610 {
56afb0f8
JB
2611 tracepoint_munge($file);
2612 }
b4870bc5 2613 dump_function($prototype, $file);
1da177e4
LT
2614 reset_state();
2615 }
2616}
2617
3c3b809e 2618sub process_state3_type($$) {
1da177e4
LT
2619 my $x = shift;
2620 my $file = shift;
2621
1da177e4
LT
2622 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2623 $x =~ s@^\s+@@gos; # strip leading spaces
2624 $x =~ s@\s+$@@gos; # strip trailing spaces
51f5a0c8
RD
2625 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2626
1da177e4
LT
2627 if ($x =~ /^#/) {
2628 # To distinguish preprocessor directive from regular declaration later.
2629 $x .= ";";
2630 }
2631
2632 while (1) {
3c308798 2633 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1da177e4
LT
2634 $prototype .= $1 . $2;
2635 ($2 eq '{') && $brcount++;
2636 ($2 eq '}') && $brcount--;
2637 if (($2 eq ';') && ($brcount == 0)) {
b9d97328 2638 dump_declaration($prototype, $file);
1da177e4 2639 reset_state();
3c308798 2640 last;
1da177e4
LT
2641 }
2642 $x = $3;
3c308798 2643 } else {
1da177e4
LT
2644 $prototype .= $x;
2645 last;
2646 }
2647 }
2648}
2649
6b5b55f6
RD
2650# xml_escape: replace <, >, and & in the text stream;
2651#
2652# however, formatting controls that are generated internally/locally in the
2653# kernel-doc script are not escaped here; instead, they begin life like
2654# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2655# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2656# just before actual output; (this is done by local_unescape())
1da177e4
LT
2657sub xml_escape($) {
2658 my $text = shift;
ecfb251a
RD
2659 if (($output_mode eq "text") || ($output_mode eq "man")) {
2660 return $text;
2661 }
1da177e4
LT
2662 $text =~ s/\&/\\\\\\amp;/g;
2663 $text =~ s/\</\\\\\\lt;/g;
2664 $text =~ s/\>/\\\\\\gt;/g;
2665 return $text;
2666}
2667
c0d1b6ee
JC
2668# xml_unescape: reverse the effects of xml_escape
2669sub xml_unescape($) {
2670 my $text = shift;
2671 if (($output_mode eq "text") || ($output_mode eq "man")) {
2672 return $text;
2673 }
2674 $text =~ s/\\\\\\amp;/\&/g;
2675 $text =~ s/\\\\\\lt;/</g;
2676 $text =~ s/\\\\\\gt;/>/g;
2677 return $text;
2678}
2679
6b5b55f6
RD
2680# convert local escape strings to html
2681# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2682sub local_unescape($) {
2683 my $text = shift;
2684 if (($output_mode eq "text") || ($output_mode eq "man")) {
2685 return $text;
2686 }
2687 $text =~ s/\\\\\\\\lt:/</g;
2688 $text =~ s/\\\\\\\\gt:/>/g;
2689 return $text;
2690}
2691
1da177e4 2692sub process_file($) {
2283a117 2693 my $file;
1da177e4
LT
2694 my $identifier;
2695 my $func;
a21217da 2696 my $descr;
6423133b 2697 my $in_purpose = 0;
1da177e4 2698 my $initial_section_counter = $section_counter;
68f86662 2699 my ($orig_file) = @_;
1da177e4 2700
2283a117 2701 if (defined($ENV{'SRCTREE'})) {
68f86662 2702 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2283a117
RD
2703 }
2704 else {
68f86662 2705 $file = $orig_file;
2283a117 2706 }
1da177e4
LT
2707 if (defined($source_map{$file})) {
2708 $file = $source_map{$file};
2709 }
2710
2711 if (!open(IN,"<$file")) {
2712 print STDERR "Error: Cannot open file $file\n";
2713 ++$errors;
2714 return;
2715 }
2716
86ae2e38 2717 # two passes for -export and -internal
b6c3f456
JN
2718 if ($output_selection == OUTPUT_EXPORTED ||
2719 $output_selection == OUTPUT_INTERNAL) {
86ae2e38
JN
2720 while (<IN>) {
2721 if (/$export_symbol/o) {
2722 $function_table{$2} = 1;
2723 }
2724 }
2725 seek(IN, 0, 0);
2726 }
2727
a9e7314b
ID
2728 $. = 1;
2729
1da177e4
LT
2730 $section_counter = 0;
2731 while (<IN>) {
65478428
DS
2732 while (s/\\\s*$//) {
2733 $_ .= <IN>;
2734 }
48af606a 2735 if ($state == STATE_NORMAL) {
1da177e4 2736 if (/$doc_start/o) {
48af606a 2737 $state = STATE_NAME; # next line is always the function name
850622df 2738 $in_doc_sect = 0;
1da177e4 2739 }
48af606a 2740 } elsif ($state == STATE_NAME) {# this line is the function name (always)
1da177e4 2741 if (/$doc_block/o) {
48af606a 2742 $state = STATE_DOCBLOCK;
1da177e4
LT
2743 $contents = "";
2744 if ( $1 eq "" ) {
2745 $section = $section_intro;
2746 } else {
2747 $section = $1;
2748 }
3c308798 2749 }
1da177e4
LT
2750 elsif (/$doc_decl/o) {
2751 $identifier = $1;
2752 if (/\s*([\w\s]+?)\s*-/) {
2753 $identifier = $1;
2754 }
2755
48af606a 2756 $state = STATE_FIELD;
1da177e4 2757 if (/-(.*)/) {
51f5a0c8 2758 # strip leading/trailing/multiple spaces
a21217da
RD
2759 $descr= $1;
2760 $descr =~ s/^\s*//;
2761 $descr =~ s/\s*$//;
12ae6779 2762 $descr =~ s/\s+/ /g;
a21217da 2763 $declaration_purpose = xml_escape($descr);
6423133b 2764 $in_purpose = 1;
1da177e4
LT
2765 } else {
2766 $declaration_purpose = "";
2767 }
77cc23b8
RD
2768
2769 if (($declaration_purpose eq "") && $verbose) {
d40e1e65 2770 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
77cc23b8
RD
2771 print STDERR $_;
2772 ++$warnings;
2773 }
2774
1da177e4
LT
2775 if ($identifier =~ m/^struct/) {
2776 $decl_type = 'struct';
2777 } elsif ($identifier =~ m/^union/) {
2778 $decl_type = 'union';
2779 } elsif ($identifier =~ m/^enum/) {
2780 $decl_type = 'enum';
2781 } elsif ($identifier =~ m/^typedef/) {
2782 $decl_type = 'typedef';
2783 } else {
2784 $decl_type = 'function';
2785 }
2786
2787 if ($verbose) {
d40e1e65 2788 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
1da177e4
LT
2789 }
2790 } else {
d40e1e65 2791 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
1da177e4
LT
2792 " - I thought it was a doc line\n";
2793 ++$warnings;
48af606a 2794 $state = STATE_NORMAL;
1da177e4 2795 }
48af606a 2796 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
1da177e4
LT
2797 if (/$doc_sect/o) {
2798 $newsection = $1;
2799 $newcontents = $2;
2800
792aa2f2 2801 if (($contents ne "") && ($contents ne "\n")) {
850622df 2802 if (!$in_doc_sect && $verbose) {
d40e1e65 2803 print STDERR "${file}:$.: warning: contents before sections\n";
850622df
RD
2804 ++$warnings;
2805 }
94dc7ad5 2806 dump_section($file, $section, xml_escape($contents));
1da177e4
LT
2807 $section = $section_default;
2808 }
2809
850622df 2810 $in_doc_sect = 1;
6423133b 2811 $in_purpose = 0;
1da177e4
LT
2812 $contents = $newcontents;
2813 if ($contents ne "") {
27205744
RD
2814 while ((substr($contents, 0, 1) eq " ") ||
2815 substr($contents, 0, 1) eq "\t") {
2816 $contents = substr($contents, 1);
05189497 2817 }
1da177e4
LT
2818 $contents .= "\n";
2819 }
2820 $section = $newsection;
2821 } elsif (/$doc_end/) {
4c98ecaf 2822 if (($contents ne "") && ($contents ne "\n")) {
94dc7ad5 2823 dump_section($file, $section, xml_escape($contents));
1da177e4
LT
2824 $section = $section_default;
2825 $contents = "";
2826 }
46b958eb
RD
2827 # look for doc_com + <text> + doc_end:
2828 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
d40e1e65 2829 print STDERR "${file}:$.: warning: suspicious ending line: $_";
46b958eb
RD
2830 ++$warnings;
2831 }
1da177e4
LT
2832
2833 $prototype = "";
48af606a 2834 $state = STATE_PROTO;
1da177e4 2835 $brcount = 0;
232acbcf 2836# print STDERR "end of doc comment, looking for prototype\n";
1da177e4
LT
2837 } elsif (/$doc_content/) {
2838 # miguel-style comment kludge, look for blank lines after
2839 # @parameter line to signify start of description
6423133b
JW
2840 if ($1 eq "") {
2841 if ($section =~ m/^@/ || $section eq $section_context) {
2842 dump_section($file, $section, xml_escape($contents));
2843 $section = $section_default;
2844 $contents = "";
2845 } else {
2846 $contents .= "\n";
2847 }
2848 $in_purpose = 0;
2849 } elsif ($in_purpose == 1) {
2850 # Continued declaration purpose
2851 chomp($declaration_purpose);
2852 $declaration_purpose .= " " . xml_escape($1);
12ae6779 2853 $declaration_purpose =~ s/\s+/ /g;
1da177e4 2854 } else {
b9d97328 2855 $contents .= $1 . "\n";
1da177e4
LT
2856 }
2857 } else {
2858 # i dont know - bad line? ignore.
d40e1e65 2859 print STDERR "${file}:$.: warning: bad line: $_";
1da177e4
LT
2860 ++$warnings;
2861 }
48af606a 2862 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
a4c6ebed 2863 # First line (state 1) needs to be a @parameter
48af606a 2864 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
a4c6ebed
DCLP
2865 $section = $1;
2866 $contents = $2;
2867 if ($contents ne "") {
2868 while ((substr($contents, 0, 1) eq " ") ||
2869 substr($contents, 0, 1) eq "\t") {
2870 $contents = substr($contents, 1);
2871 }
2872 $contents .= "\n";
2873 }
48af606a 2874 $inline_doc_state = STATE_INLINE_TEXT;
a4c6ebed 2875 # Documentation block end */
48af606a 2876 } elsif (/$doc_inline_end/) {
a4c6ebed
DCLP
2877 if (($contents ne "") && ($contents ne "\n")) {
2878 dump_section($file, $section, xml_escape($contents));
2879 $section = $section_default;
2880 $contents = "";
2881 }
48af606a
JN
2882 $state = STATE_PROTO;
2883 $inline_doc_state = STATE_INLINE_NA;
a4c6ebed
DCLP
2884 # Regular text
2885 } elsif (/$doc_content/) {
48af606a 2886 if ($inline_doc_state == STATE_INLINE_TEXT) {
a4c6ebed 2887 $contents .= $1 . "\n";
48af606a
JN
2888 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2889 $inline_doc_state = STATE_INLINE_ERROR;
a4c6ebed
DCLP
2890 print STDERR "Warning(${file}:$.): ";
2891 print STDERR "Incorrect use of kernel-doc format: $_";
2892 ++$warnings;
2893 }
2894 }
48af606a
JN
2895 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2896 if (/$doc_inline_start/) {
2897 $state = STATE_INLINE;
2898 $inline_doc_state = STATE_INLINE_NAME;
a4c6ebed 2899 } elsif ($decl_type eq 'function') {
3c308798 2900 process_state3_function($_, $file);
1da177e4 2901 } else {
3c308798 2902 process_state3_type($_, $file);
1da177e4 2903 }
48af606a 2904 } elsif ($state == STATE_DOCBLOCK) {
1da177e4 2905 # Documentation block
3c308798 2906 if (/$doc_block/) {
94dc7ad5 2907 dump_doc_section($file, $section, xml_escape($contents));
1da177e4
LT
2908 $contents = "";
2909 $function = "";
2910 %constants = ();
2911 %parameterdescs = ();
2912 %parametertypes = ();
2913 @parameterlist = ();
2914 %sections = ();
2915 @sectionlist = ();
2916 $prototype = "";
2917 if ( $1 eq "" ) {
2918 $section = $section_intro;
2919 } else {
2920 $section = $1;
2921 }
3c308798 2922 }
1da177e4
LT
2923 elsif (/$doc_end/)
2924 {
94dc7ad5 2925 dump_doc_section($file, $section, xml_escape($contents));
1da177e4
LT
2926 $contents = "";
2927 $function = "";
2928 %constants = ();
2929 %parameterdescs = ();
2930 %parametertypes = ();
2931 @parameterlist = ();
2932 %sections = ();
2933 @sectionlist = ();
2934 $prototype = "";
48af606a 2935 $state = STATE_NORMAL;
1da177e4
LT
2936 }
2937 elsif (/$doc_content/)
2938 {
2939 if ( $1 eq "" )
2940 {
2941 $contents .= $blankline;
2942 }
2943 else
2944 {
2945 $contents .= $1 . "\n";
3c3b809e 2946 }
3c308798
RD
2947 }
2948 }
1da177e4
LT
2949 }
2950 if ($initial_section_counter == $section_counter) {
d40e1e65 2951 print STDERR "${file}:1: warning: no structured comments found\n";
b6c3f456 2952 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
e946c43a
JB
2953 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2954 }
1da177e4
LT
2955 if ($output_mode eq "xml") {
2956 # The template wants at least one RefEntry here; make one.
2957 print "<refentry>\n";
2958 print " <refnamediv>\n";
2959 print " <refname>\n";
68f86662 2960 print " ${orig_file}\n";
1da177e4
LT
2961 print " </refname>\n";
2962 print " <refpurpose>\n";
2963 print " Document generation inconsistency\n";
2964 print " </refpurpose>\n";
2965 print " </refnamediv>\n";
2966 print " <refsect1>\n";
2967 print " <title>\n";
2968 print " Oops\n";
2969 print " </title>\n";
2970 print " <warning>\n";
2971 print " <para>\n";
2972 print " The template for this document tried to insert\n";
2973 print " the structured comment from the file\n";
68f86662 2974 print " <filename>${orig_file}</filename> at this point,\n";
1da177e4
LT
2975 print " but none was found.\n";
2976 print " This dummy section is inserted to allow\n";
2977 print " generation to continue.\n";
2978 print " </para>\n";
2979 print " </warning>\n";
2980 print " </refsect1>\n";
2981 print "</refentry>\n";
2982 }
2983 }
2984}
8484baaa
RD
2985
2986
2987$kernelversion = get_kernel_version();
2988
2989# generate a sequence of code that will splice in highlighting information
2990# using the s// operator.
1ef06233 2991for (my $k = 0; $k < @highlights; $k++) {
4d732701
DCLP
2992 my $pattern = $highlights[$k][0];
2993 my $result = $highlights[$k][1];
2994# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2995 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
8484baaa
RD
2996}
2997
2998# Read the file that maps relative names to absolute names for
2999# separate source and object directories and for shadow trees.
3000if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3001 my ($relname, $absname);
3002 while(<SOURCE_MAP>) {
3003 chop();
3004 ($relname, $absname) = (split())[0..1];
3005 $relname =~ s:^/+::;
3006 $source_map{$relname} = $absname;
3007 }
3008 close(SOURCE_MAP);
3009}
3010
3011foreach (@ARGV) {
3012 chomp;
3013 process_file($_);
3014}
3015if ($verbose && $errors) {
3016 print STDERR "$errors errors\n";
3017}
3018if ($verbose && $warnings) {
3019 print STDERR "$warnings warnings\n";
3020}
3021
3022exit($errors);