blob: 83cee18a02e922130fae1bf9d8dff87d4f6169d8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/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 ##
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07008## Copyright (C) 2005-2008 Randy Dunlap ##
Linus Torvalds1da177e2005-04-16 15:20:36 -07009## ##
10## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11## Copyright (c) 2000 MontaVista Software, Inc. ##
12## ##
13## This software falls under the GNU General Public License. ##
14## Please read the COPYING file for more information ##
15
16# w.o. 03-11-2000: added the '-filelist' option.
17
18# 18/01/2001 - Cleanups
19# Functions prototyped as foo(void) same as foo()
20# Stop eval'ing where we don't need to.
21# -- huggie@earth.li
22
23# 27/06/2001 - Allowed whitespace after initial "/**" and
24# allowed comments before function declarations.
25# -- Christian Kreibich <ck@whoop.org>
26
27# Still to do:
28# - add perldoc documentation
29# - Look more closely at some of the scarier bits :)
30
31# 26/05/2001 - Support for separate source and object trees.
32# Return error code.
33# Keith Owens <kaos@ocs.com.au>
34
35# 23/09/2001 - Added support for typedefs, structs, enums and unions
36# Support for Context section; can be terminated using empty line
37# Small fixes (like spaces vs. \s in regex)
38# -- Tim Jansen <tim@tjansen.de>
39
40
41#
42# This will read a 'c' file and scan for embedded comments in the
43# style of gnome comments (+minor extensions - see below).
44#
45
46# Note: This only supports 'c'.
47
48# usage:
Johannes Berg4b445952007-10-24 15:08:48 -070049# kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ]
Linus Torvalds1da177e2005-04-16 15:20:36 -070050# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
51# or
52# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
53#
54# Set output format using one of -docbook -html -text or -man. Default is man.
55#
Johannes Berg4b445952007-10-24 15:08:48 -070056# -no-doc-sections
57# Do not output DOC: sections
58#
Linus Torvalds1da177e2005-04-16 15:20:36 -070059# -function funcname
Johannes Bergb112e0f2007-10-24 15:08:48 -070060# If set, then only generate documentation for the given function(s) or
61# DOC: section titles. All other functions and DOC: sections are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#
63# -nofunction funcname
Johannes Bergb112e0f2007-10-24 15:08:48 -070064# If set, then only generate documentation for the other function(s)/DOC:
65# sections. Cannot be used together with -function (yes, that's a bug --
66# perl hackers can fix it 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#
68# c files - list of 'c' files to process
69#
70# All output goes to stdout, with errors to stderr.
71
72#
73# format of comments.
74# In the following table, (...)? signifies optional structure.
75# (...)* signifies 0 or more structure elements
76# /**
77# * function_name(:)? (- short description)?
78# (* @parameterx: (description of parameter x)?)*
79# (* a blank line)?
80# * (Description:)? (Description of function)?
81# * (section header: (section description)? )*
82# (*)?*/
83#
84# So .. the trivial example would be:
85#
86# /**
87# * my_function
88# **/
89#
Randy Dunlap891dcd22007-02-10 01:45:53 -080090# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -070091# after the last parameter specification.
92# e.g.
93# /**
94# * my_function - does my stuff
95# * @my_arg: its mine damnit
96# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -080097# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -070098# */
99#
100# or, could also use:
101# /**
102# * my_function - does my stuff
103# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800104# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105# */
106# etc.
107#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800108# Beside functions you can also write documentation for structs, unions,
109# enums and typedefs. Instead of the function name you must write the name
110# of the declaration; the struct/union/enum/typedef must always precede
111# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112# Use the argument mechanism to document members or constants.
113# e.g.
114# /**
115# * struct my_struct - short description
116# * @a: first member
117# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800118# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119# * Longer description
120# */
121# struct my_struct {
122# int a;
123# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800124# /* private: */
125# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126# };
127#
128# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800129#
130# You can also add additional sections. When documenting kernel functions you
131# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800133# empty line.
134# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135# appropriately in DocBook.
136#
137# Example:
138# /**
139# * user_function - function that can only be called in user context
140# * @a: some argument
141# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800142# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143# * Some description
144# * Example:
145# * user_function(22);
146# */
147# ...
148#
149#
150# All descriptive text is further processed, scanning for the following special
151# patterns, which are highlighted appropriately.
152#
153# 'funcname()' - function
154# '$ENVVAR' - environmental variable
155# '&struct_name' - name of a structure (up to two words including 'struct')
156# '@parameter' - name of a parameter
157# '%CONST' - name of a constant.
158
159my $errors = 0;
160my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700161my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163# match expressions used to find embedded type information
164my $type_constant = '\%([-_\w]+)';
165my $type_func = '(\w+)\(\)';
166my $type_param = '\@(\w+)';
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700167my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700168my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169my $type_env = '(\$\w+)';
170
171# Output conversion substitutions.
172# One for each output format
173
174# these work fairly well
175my %highlights_html = ( $type_constant, "<i>\$1</i>",
176 $type_func, "<b>\$1</b>",
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700177 $type_struct_xml, "<i>\$1</i>",
178 $type_env, "<b><i>\$1</i></b>",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 $type_param, "<tt><b>\$1</b></tt>" );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700180my $local_lt = "\\\\\\\\lt:";
181my $local_gt = "\\\\\\\\gt:";
182my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184# XML, docbook format
185my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
186 $type_constant, "<constant>\$1</constant>",
187 $type_func, "<function>\$1</function>",
Johannes Berg5c98fc02007-10-24 15:08:48 -0700188 $type_struct_xml, "<structname>\$1</structname>",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 $type_env, "<envar>\$1</envar>",
190 $type_param, "<parameter>\$1</parameter>" );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700191my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193# gnome, docbook format
194my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
195 $type_func, "<function>\$1</function>",
196 $type_struct, "<structname>\$1</structname>",
197 $type_env, "<envar>\$1</envar>",
198 $type_param, "<parameter>\$1</parameter>" );
199my $blankline_gnome = "</para><para>\n";
200
201# these are pretty rough
202my %highlights_man = ( $type_constant, "\$1",
203 $type_func, "\\\\fB\$1\\\\fP",
204 $type_struct, "\\\\fI\$1\\\\fP",
205 $type_param, "\\\\fI\$1\\\\fP" );
206my $blankline_man = "";
207
208# text-mode
209my %highlights_text = ( $type_constant, "\$1",
210 $type_func, "\$1",
211 $type_struct, "\$1",
212 $type_param, "\$1" );
213my $blankline_text = "";
214
215
216sub usage {
Johannes Berg4b445952007-10-24 15:08:48 -0700217 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 print " [ -function funcname [ -function funcname ...] ]\n";
219 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
220 print " c source file(s) > outputfile\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -0800221 print " -v : verbose output, more warnings & other info listed\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 exit 1;
223}
224
225# read arguments
226if ($#ARGV==-1) {
227 usage();
228}
229
230my $verbose = 0;
231my $output_mode = "man";
Johannes Berg4b445952007-10-24 15:08:48 -0700232my $no_doc_sections = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233my %highlights = %highlights_man;
234my $blankline = $blankline_man;
235my $modulename = "Kernel API";
236my $function_only = 0;
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800237my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
238 'July', 'August', 'September', 'October',
239 'November', 'December')[(localtime)[4]] .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 " " . ((localtime)[5]+1900);
241
242# Essentially these are globals
243# They probably want to be tidied up made more localised or summat.
244# CAVEAT EMPTOR! Some of the others I localised may not want to be which
245# could cause "use of undefined value" or other bugs.
246my ($function, %function_table,%parametertypes,$declaration_purpose);
247my ($type,$declaration_name,$return_type);
248my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
249
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700250if (defined($ENV{'KBUILD_VERBOSE'})) {
251 $verbose = "$ENV{'KBUILD_VERBOSE'}";
252}
253
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800254# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
256# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
257# We keep track of number of generated entries and generate a dummy
258# if needs be to ensure the expanded template can be postprocessed
259# into html.
260my $section_counter = 0;
261
262my $lineprefix="";
263
264# states
265# 0 - normal code
266# 1 - looking for function name
267# 2 - scanning field start.
268# 3 - scanning prototype.
269# 4 - documentation block
270my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700271my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273#declaration types: can be
274# 'function', 'struct', 'union', 'enum', 'typedef'
275my $decl_type;
276
277my $doc_special = "\@\%\$\&";
278
279my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
280my $doc_end = '\*/';
281my $doc_com = '\s*\*\s*';
282my $doc_decl = $doc_com.'(\w+)';
Randy Dunlap891dcd22007-02-10 01:45:53 -0800283my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284my $doc_content = $doc_com.'(.*)';
285my $doc_block = $doc_com.'DOC:\s*(.*)?';
286
287my %constants;
288my %parameterdescs;
289my @parameterlist;
290my %sections;
291my @sectionlist;
292
293my $contents = "";
294my $section_default = "Description"; # default section
295my $section_intro = "Introduction";
296my $section = $section_default;
297my $section_context = "Context";
298
299my $undescribed = "-- undescribed --";
300
301reset_state();
302
303while ($ARGV[0] =~ m/^-(.*)/) {
304 my $cmd = shift @ARGV;
305 if ($cmd eq "-html") {
306 $output_mode = "html";
307 %highlights = %highlights_html;
308 $blankline = $blankline_html;
309 } elsif ($cmd eq "-man") {
310 $output_mode = "man";
311 %highlights = %highlights_man;
312 $blankline = $blankline_man;
313 } elsif ($cmd eq "-text") {
314 $output_mode = "text";
315 %highlights = %highlights_text;
316 $blankline = $blankline_text;
317 } elsif ($cmd eq "-docbook") {
318 $output_mode = "xml";
319 %highlights = %highlights_xml;
320 $blankline = $blankline_xml;
321 } elsif ($cmd eq "-gnome") {
322 $output_mode = "gnome";
323 %highlights = %highlights_gnome;
324 $blankline = $blankline_gnome;
325 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
326 $modulename = shift @ARGV;
327 } elsif ($cmd eq "-function") { # to only output specific functions
328 $function_only = 1;
329 $function = shift @ARGV;
330 $function_table{$function} = 1;
331 } elsif ($cmd eq "-nofunction") { # to only output specific functions
332 $function_only = 2;
333 $function = shift @ARGV;
334 $function_table{$function} = 1;
335 } elsif ($cmd eq "-v") {
336 $verbose = 1;
337 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
338 usage();
339 } elsif ($cmd eq '-filelist') {
340 $filelist = shift @ARGV;
Johannes Berg4b445952007-10-24 15:08:48 -0700341 } elsif ($cmd eq '-no-doc-sections') {
342 $no_doc_sections = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344}
345
Borislav Petkov53f049f2007-05-08 00:30:54 -0700346# get kernel version from env
347sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700348 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700349
350 if (defined($ENV{'KERNELVERSION'})) {
351 $version = $ENV{'KERNELVERSION'};
352 }
353 return $version;
354}
Borislav Petkov03662992007-05-09 02:33:43 -0700355my $kernelversion = get_kernel_version();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357# generate a sequence of code that will splice in highlighting information
358# using the s// operator.
359my $dohighlight = "";
360foreach my $pattern (keys %highlights) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700361# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
363}
364
365##
366# dumps section contents to arrays/hashes intended for that purpose.
367#
368sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700369 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 my $name = shift;
371 my $contents = join "\n", @_;
372
373 if ($name =~ m/$type_constant/) {
374 $name = $1;
375# print STDERR "constant section '$1' = '$contents'\n";
376 $constants{$name} = $contents;
377 } elsif ($name =~ m/$type_param/) {
378# print STDERR "parameter def '$1' = '$contents'\n";
379 $name = $1;
380 $parameterdescs{$name} = $contents;
381 } else {
382# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700383 if (defined($sections{$name}) && ($sections{$name} ne "")) {
384 print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
385 ++$errors;
386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 $sections{$name} = $contents;
388 push @sectionlist, $name;
389 }
390}
391
392##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700393# dump DOC: section after checking that it should go out
394#
395sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700396 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700397 my $name = shift;
398 my $contents = join "\n", @_;
399
Johannes Berg4b445952007-10-24 15:08:48 -0700400 if ($no_doc_sections) {
401 return;
402 }
403
Johannes Bergb112e0f2007-10-24 15:08:48 -0700404 if (($function_only == 0) ||
405 ( $function_only == 1 && defined($function_table{$name})) ||
406 ( $function_only == 2 && !defined($function_table{$name})))
407 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700408 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700409 output_blockhead({'sectionlist' => \@sectionlist,
410 'sections' => \%sections,
411 'module' => $modulename,
412 'content-only' => ($function_only != 0), });
413 }
414}
415
416##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417# output function
418#
419# parameterdescs, a hash.
420# function => "function name"
421# parameterlist => @list of parameters
422# parameterdescs => %parameter descriptions
423# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800424# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800425#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427sub output_highlight {
428 my $contents = join "\n",@_;
429 my $line;
430
431# DEBUG
432# if (!defined $contents) {
433# use Carp;
434# confess "output_highlight got called with no args?\n";
435# }
436
Johannes Berg5c98fc02007-10-24 15:08:48 -0700437 if ($output_mode eq "html" || $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700438 $contents = local_unescape($contents);
439 # convert data read & converted thru xml_escape() into &xyz; format:
440 $contents =~ s/\\\\\\/&/g;
441 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700442# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 eval $dohighlight;
444 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700445# print STDERR "contents af:$contents\n";
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 foreach $line (split "\n", $contents) {
Randy Dunlap3c308792007-05-08 00:24:39 -0700448 if ($line eq ""){
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700449 print $lineprefix, local_unescape($blankline);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700451 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700452 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
453 print "\\&$line";
454 } else {
455 print $lineprefix, $line;
456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458 print "\n";
459 }
460}
461
462#output sections in html
463sub output_section_html(%) {
464 my %args = %{$_[0]};
465 my $section;
466
467 foreach $section (@{$args{'sectionlist'}}) {
468 print "<h3>$section</h3>\n";
469 print "<blockquote>\n";
470 output_highlight($args{'sections'}{$section});
471 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
475# output enum in html
476sub output_enum_html(%) {
477 my %args = %{$_[0]};
478 my ($parameter);
479 my $count;
480 print "<h2>enum ".$args{'enum'}."</h2>\n";
481
482 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
483 $count = 0;
484 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -0700485 print " <b>".$parameter."</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 if ($count != $#{$args{'parameterlist'}}) {
487 $count++;
488 print ",\n";
489 }
490 print "<br>";
491 }
492 print "};<br>\n";
493
494 print "<h3>Constants</h3>\n";
495 print "<dl>\n";
496 foreach $parameter (@{$args{'parameterlist'}}) {
497 print "<dt><b>".$parameter."</b>\n";
498 print "<dd>";
499 output_highlight($args{'parameterdescs'}{$parameter});
500 }
501 print "</dl>\n";
502 output_section_html(@_);
503 print "<hr>\n";
504}
505
Randy Dunlapd28bee02006-02-01 03:06:57 -0800506# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507sub output_typedef_html(%) {
508 my %args = %{$_[0]};
509 my ($parameter);
510 my $count;
511 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
512
513 print "<b>typedef ".$args{'typedef'}."</b>\n";
514 output_section_html(@_);
515 print "<hr>\n";
516}
517
518# output struct in html
519sub output_struct_html(%) {
520 my %args = %{$_[0]};
521 my ($parameter);
522
Randy Dunlap262d9b02007-02-20 13:58:04 -0800523 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
525 foreach $parameter (@{$args{'parameterlist'}}) {
526 if ($parameter =~ /^#/) {
527 print "$parameter<br>\n";
528 next;
529 }
530 my $parameter_name = $parameter;
531 $parameter_name =~ s/\[.*//;
532
Randy Dunlap3c308792007-05-08 00:24:39 -0700533 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 $type = $args{'parametertypes'}{$parameter};
535 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
536 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700537 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700539 # bitfield
540 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700542 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
544 }
545 print "};<br>\n";
546
547 print "<h3>Members</h3>\n";
548 print "<dl>\n";
549 foreach $parameter (@{$args{'parameterlist'}}) {
550 ($parameter =~ /^#/) && next;
551
552 my $parameter_name = $parameter;
553 $parameter_name =~ s/\[.*//;
554
Randy Dunlap3c308792007-05-08 00:24:39 -0700555 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 print "<dt><b>".$parameter."</b>\n";
557 print "<dd>";
558 output_highlight($args{'parameterdescs'}{$parameter_name});
559 }
560 print "</dl>\n";
561 output_section_html(@_);
562 print "<hr>\n";
563}
564
565# output function in html
566sub output_function_html(%) {
567 my %args = %{$_[0]};
568 my ($parameter, $section);
569 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Randy Dunlap262d9b02007-02-20 13:58:04 -0800571 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 print "<i>".$args{'functiontype'}."</i>\n";
573 print "<b>".$args{'function'}."</b>\n";
574 print "(";
575 $count = 0;
576 foreach $parameter (@{$args{'parameterlist'}}) {
577 $type = $args{'parametertypes'}{$parameter};
578 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
579 # pointer-to-function
580 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
581 } else {
582 print "<i>".$type."</i> <b>".$parameter."</b>";
583 }
584 if ($count != $#{$args{'parameterlist'}}) {
585 $count++;
586 print ",\n";
587 }
588 }
589 print ")\n";
590
591 print "<h3>Arguments</h3>\n";
592 print "<dl>\n";
593 foreach $parameter (@{$args{'parameterlist'}}) {
594 my $parameter_name = $parameter;
595 $parameter_name =~ s/\[.*//;
596
Randy Dunlap3c308792007-05-08 00:24:39 -0700597 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 print "<dt><b>".$parameter."</b>\n";
599 print "<dd>";
600 output_highlight($args{'parameterdescs'}{$parameter_name});
601 }
602 print "</dl>\n";
603 output_section_html(@_);
604 print "<hr>\n";
605}
606
Johannes Bergb112e0f2007-10-24 15:08:48 -0700607# output DOC: block header in html
608sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 my %args = %{$_[0]};
610 my ($parameter, $section);
611 my $count;
612
613 foreach $section (@{$args{'sectionlist'}}) {
614 print "<h3>$section</h3>\n";
615 print "<ul>\n";
616 output_highlight($args{'sections'}{$section});
617 print "</ul>\n";
618 }
619 print "<hr>\n";
620}
621
622sub output_section_xml(%) {
623 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800624 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 # print out each section
626 $lineprefix=" ";
627 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700628 print "<refsect1>\n";
629 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700631 print "<informalexample><programlisting>\n";
632 } else {
633 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635 output_highlight($args{'sections'}{$section});
636 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700637 print "</programlisting></informalexample>\n";
638 } else {
639 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Rich Walkerc73894c2005-05-01 08:59:26 -0700641 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643}
644
645# output function in XML DocBook
646sub output_function_xml(%) {
647 my %args = %{$_[0]};
648 my ($parameter, $section);
649 my $count;
650 my $id;
651
652 $id = "API-".$args{'function'};
653 $id =~ s/[^A-Za-z0-9]/-/g;
654
Pavel Pisa5449bc92007-02-10 01:45:37 -0800655 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700656 print "<refentryinfo>\n";
657 print " <title>LINUX</title>\n";
658 print " <productname>Kernel Hackers Manual</productname>\n";
659 print " <date>$man_date</date>\n";
660 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 print "<refmeta>\n";
Pavel Pisa5449bc92007-02-10 01:45:37 -0800662 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700663 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -0700664 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 print "</refmeta>\n";
666 print "<refnamediv>\n";
667 print " <refname>".$args{'function'}."</refname>\n";
668 print " <refpurpose>\n";
669 print " ";
670 output_highlight ($args{'purpose'});
671 print " </refpurpose>\n";
672 print "</refnamediv>\n";
673
674 print "<refsynopsisdiv>\n";
675 print " <title>Synopsis</title>\n";
676 print " <funcsynopsis><funcprototype>\n";
677 print " <funcdef>".$args{'functiontype'}." ";
678 print "<function>".$args{'function'}." </function></funcdef>\n";
679
680 $count = 0;
681 if ($#{$args{'parameterlist'}} >= 0) {
682 foreach $parameter (@{$args{'parameterlist'}}) {
683 $type = $args{'parametertypes'}{$parameter};
684 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
685 # pointer-to-function
686 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
687 print " <funcparams>$2</funcparams></paramdef>\n";
688 } else {
689 print " <paramdef>".$type;
690 print " <parameter>$parameter</parameter></paramdef>\n";
691 }
692 }
693 } else {
Martin Waitz6013d542005-05-01 08:59:25 -0700694 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 }
696 print " </funcprototype></funcsynopsis>\n";
697 print "</refsynopsisdiv>\n";
698
699 # print parameters
700 print "<refsect1>\n <title>Arguments</title>\n";
701 if ($#{$args{'parameterlist'}} >= 0) {
702 print " <variablelist>\n";
703 foreach $parameter (@{$args{'parameterlist'}}) {
704 my $parameter_name = $parameter;
705 $parameter_name =~ s/\[.*//;
706
707 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
708 print " <listitem>\n <para>\n";
709 $lineprefix=" ";
710 output_highlight($args{'parameterdescs'}{$parameter_name});
711 print " </para>\n </listitem>\n </varlistentry>\n";
712 }
713 print " </variablelist>\n";
714 } else {
715 print " <para>\n None\n </para>\n";
716 }
717 print "</refsect1>\n";
718
719 output_section_xml(@_);
720 print "</refentry>\n\n";
721}
722
723# output struct in XML DocBook
724sub output_struct_xml(%) {
725 my %args = %{$_[0]};
726 my ($parameter, $section);
727 my $id;
728
729 $id = "API-struct-".$args{'struct'};
730 $id =~ s/[^A-Za-z0-9]/-/g;
731
Pavel Pisa5449bc92007-02-10 01:45:37 -0800732 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700733 print "<refentryinfo>\n";
734 print " <title>LINUX</title>\n";
735 print " <productname>Kernel Hackers Manual</productname>\n";
736 print " <date>$man_date</date>\n";
737 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 print "<refmeta>\n";
Pavel Pisa5449bc92007-02-10 01:45:37 -0800739 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700740 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -0700741 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 print "</refmeta>\n";
743 print "<refnamediv>\n";
744 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
745 print " <refpurpose>\n";
746 print " ";
747 output_highlight ($args{'purpose'});
748 print " </refpurpose>\n";
749 print "</refnamediv>\n";
750
751 print "<refsynopsisdiv>\n";
752 print " <title>Synopsis</title>\n";
753 print " <programlisting>\n";
754 print $args{'type'}." ".$args{'struct'}." {\n";
755 foreach $parameter (@{$args{'parameterlist'}}) {
756 if ($parameter =~ /^#/) {
757 print "$parameter\n";
758 next;
759 }
760
761 my $parameter_name = $parameter;
762 $parameter_name =~ s/\[.*//;
763
764 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -0700765 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 $type = $args{'parametertypes'}{$parameter};
767 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
768 # pointer-to-function
769 print " $1 $parameter) ($2);\n";
770 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -0700771 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 print " $1 $parameter$2;\n";
773 } else {
774 print " ".$type." ".$parameter.";\n";
775 }
776 }
777 print "};";
778 print " </programlisting>\n";
779 print "</refsynopsisdiv>\n";
780
781 print " <refsect1>\n";
782 print " <title>Members</title>\n";
783
784 print " <variablelist>\n";
785 foreach $parameter (@{$args{'parameterlist'}}) {
786 ($parameter =~ /^#/) && next;
787
788 my $parameter_name = $parameter;
789 $parameter_name =~ s/\[.*//;
790
791 defined($args{'parameterdescs'}{$parameter_name}) || next;
792 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
793 print " <varlistentry>";
794 print " <term>$parameter</term>\n";
795 print " <listitem><para>\n";
796 output_highlight($args{'parameterdescs'}{$parameter_name});
797 print " </para></listitem>\n";
798 print " </varlistentry>\n";
799 }
800 print " </variablelist>\n";
801 print " </refsect1>\n";
802
803 output_section_xml(@_);
804
805 print "</refentry>\n\n";
806}
807
808# output enum in XML DocBook
809sub output_enum_xml(%) {
810 my %args = %{$_[0]};
811 my ($parameter, $section);
812 my $count;
813 my $id;
814
815 $id = "API-enum-".$args{'enum'};
816 $id =~ s/[^A-Za-z0-9]/-/g;
817
Pavel Pisa5449bc92007-02-10 01:45:37 -0800818 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700819 print "<refentryinfo>\n";
820 print " <title>LINUX</title>\n";
821 print " <productname>Kernel Hackers Manual</productname>\n";
822 print " <date>$man_date</date>\n";
823 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 print "<refmeta>\n";
Pavel Pisa5449bc92007-02-10 01:45:37 -0800825 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700826 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -0700827 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 print "</refmeta>\n";
829 print "<refnamediv>\n";
830 print " <refname>enum ".$args{'enum'}."</refname>\n";
831 print " <refpurpose>\n";
832 print " ";
833 output_highlight ($args{'purpose'});
834 print " </refpurpose>\n";
835 print "</refnamediv>\n";
836
837 print "<refsynopsisdiv>\n";
838 print " <title>Synopsis</title>\n";
839 print " <programlisting>\n";
840 print "enum ".$args{'enum'}." {\n";
841 $count = 0;
842 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -0700843 print " $parameter";
844 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 $count++;
846 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -0700847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 print "\n";
849 }
850 print "};";
851 print " </programlisting>\n";
852 print "</refsynopsisdiv>\n";
853
854 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800855 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 print " <variablelist>\n";
857 foreach $parameter (@{$args{'parameterlist'}}) {
858 my $parameter_name = $parameter;
859 $parameter_name =~ s/\[.*//;
860
861 print " <varlistentry>";
862 print " <term>$parameter</term>\n";
863 print " <listitem><para>\n";
864 output_highlight($args{'parameterdescs'}{$parameter_name});
865 print " </para></listitem>\n";
866 print " </varlistentry>\n";
867 }
868 print " </variablelist>\n";
869 print "</refsect1>\n";
870
871 output_section_xml(@_);
872
873 print "</refentry>\n\n";
874}
875
876# output typedef in XML DocBook
877sub output_typedef_xml(%) {
878 my %args = %{$_[0]};
879 my ($parameter, $section);
880 my $id;
881
882 $id = "API-typedef-".$args{'typedef'};
883 $id =~ s/[^A-Za-z0-9]/-/g;
884
Pavel Pisa5449bc92007-02-10 01:45:37 -0800885 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700886 print "<refentryinfo>\n";
887 print " <title>LINUX</title>\n";
888 print " <productname>Kernel Hackers Manual</productname>\n";
889 print " <date>$man_date</date>\n";
890 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 print "<refmeta>\n";
Pavel Pisa5449bc92007-02-10 01:45:37 -0800892 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700893 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 print "</refmeta>\n";
895 print "<refnamediv>\n";
896 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
897 print " <refpurpose>\n";
898 print " ";
899 output_highlight ($args{'purpose'});
900 print " </refpurpose>\n";
901 print "</refnamediv>\n";
902
903 print "<refsynopsisdiv>\n";
904 print " <title>Synopsis</title>\n";
905 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
906 print "</refsynopsisdiv>\n";
907
908 output_section_xml(@_);
909
910 print "</refentry>\n\n";
911}
912
913# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -0700914sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 my %args = %{$_[0]};
916 my ($parameter, $section);
917 my $count;
918
919 my $id = $args{'module'};
920 $id =~ s/[^A-Za-z0-9]/-/g;
921
922 # print out each section
923 $lineprefix=" ";
924 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -0700925 if (!$args{'content-only'}) {
926 print "<refsect1>\n <title>$section</title>\n";
927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if ($section =~ m/EXAMPLE/i) {
929 print "<example><para>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -0700930 } else {
931 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933 output_highlight($args{'sections'}{$section});
934 if ($section =~ m/EXAMPLE/i) {
935 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -0700936 } else {
937 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 }
Johannes Bergb112e0f2007-10-24 15:08:48 -0700939 if (!$args{'content-only'}) {
940 print "\n</refsect1>\n";
941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 }
943
944 print "\n\n";
945}
946
947# output in XML DocBook
948sub output_function_gnome {
949 my %args = %{$_[0]};
950 my ($parameter, $section);
951 my $count;
952 my $id;
953
954 $id = $args{'module'}."-".$args{'function'};
955 $id =~ s/[^A-Za-z0-9]/-/g;
956
957 print "<sect2>\n";
958 print " <title id=\"$id\">".$args{'function'}."</title>\n";
959
960 print " <funcsynopsis>\n";
961 print " <funcdef>".$args{'functiontype'}." ";
962 print "<function>".$args{'function'}." ";
963 print "</function></funcdef>\n";
964
965 $count = 0;
966 if ($#{$args{'parameterlist'}} >= 0) {
967 foreach $parameter (@{$args{'parameterlist'}}) {
968 $type = $args{'parametertypes'}{$parameter};
969 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
970 # pointer-to-function
971 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
972 print " <funcparams>$2</funcparams></paramdef>\n";
973 } else {
974 print " <paramdef>".$type;
975 print " <parameter>$parameter</parameter></paramdef>\n";
976 }
977 }
978 } else {
979 print " <void>\n";
980 }
981 print " </funcsynopsis>\n";
982 if ($#{$args{'parameterlist'}} >= 0) {
983 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
984 print "<tgroup cols=\"2\">\n";
985 print "<colspec colwidth=\"2*\">\n";
986 print "<colspec colwidth=\"8*\">\n";
987 print "<tbody>\n";
988 foreach $parameter (@{$args{'parameterlist'}}) {
989 my $parameter_name = $parameter;
990 $parameter_name =~ s/\[.*//;
991
992 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
993 print " <entry>\n";
994 $lineprefix=" ";
995 output_highlight($args{'parameterdescs'}{$parameter_name});
996 print " </entry></row>\n";
997 }
998 print " </tbody></tgroup></informaltable>\n";
999 } else {
1000 print " <para>\n None\n </para>\n";
1001 }
1002
1003 # print out each section
1004 $lineprefix=" ";
1005 foreach $section (@{$args{'sectionlist'}}) {
1006 print "<simplesect>\n <title>$section</title>\n";
1007 if ($section =~ m/EXAMPLE/i) {
1008 print "<example><programlisting>\n";
1009 } else {
1010 }
1011 print "<para>\n";
1012 output_highlight($args{'sections'}{$section});
1013 print "</para>\n";
1014 if ($section =~ m/EXAMPLE/i) {
1015 print "</programlisting></example>\n";
1016 } else {
1017 }
1018 print " </simplesect>\n";
1019 }
1020
1021 print "</sect2>\n\n";
1022}
1023
1024##
1025# output function in man
1026sub output_function_man(%) {
1027 my %args = %{$_[0]};
1028 my ($parameter, $section);
1029 my $count;
1030
1031 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1032
1033 print ".SH NAME\n";
1034 print $args{'function'}." \\- ".$args{'purpose'}."\n";
1035
1036 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001037 if ($args{'functiontype'} ne "") {
1038 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
1039 } else {
1040 print ".B \"".$args{'function'}."\n";
1041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 $count = 0;
1043 my $parenth = "(";
1044 my $post = ",";
1045 foreach my $parameter (@{$args{'parameterlist'}}) {
1046 if ($count == $#{$args{'parameterlist'}}) {
1047 $post = ");";
1048 }
1049 $type = $args{'parametertypes'}{$parameter};
1050 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1051 # pointer-to-function
1052 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
1053 } else {
1054 $type =~ s/([^\*])$/$1 /;
1055 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1056 }
1057 $count++;
1058 $parenth = "";
1059 }
1060
1061 print ".SH ARGUMENTS\n";
1062 foreach $parameter (@{$args{'parameterlist'}}) {
1063 my $parameter_name = $parameter;
1064 $parameter_name =~ s/\[.*//;
1065
1066 print ".IP \"".$parameter."\" 12\n";
1067 output_highlight($args{'parameterdescs'}{$parameter_name});
1068 }
1069 foreach $section (@{$args{'sectionlist'}}) {
1070 print ".SH \"", uc $section, "\"\n";
1071 output_highlight($args{'sections'}{$section});
1072 }
1073}
1074
1075##
1076# output enum in man
1077sub output_enum_man(%) {
1078 my %args = %{$_[0]};
1079 my ($parameter, $section);
1080 my $count;
1081
1082 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1083
1084 print ".SH NAME\n";
1085 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1086
1087 print ".SH SYNOPSIS\n";
1088 print "enum ".$args{'enum'}." {\n";
1089 $count = 0;
1090 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001091 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 if ($count == $#{$args{'parameterlist'}}) {
1093 print "\n};\n";
1094 last;
1095 }
1096 else {
1097 print ", \n.br\n";
1098 }
1099 $count++;
1100 }
1101
1102 print ".SH Constants\n";
1103 foreach $parameter (@{$args{'parameterlist'}}) {
1104 my $parameter_name = $parameter;
1105 $parameter_name =~ s/\[.*//;
1106
1107 print ".IP \"".$parameter."\" 12\n";
1108 output_highlight($args{'parameterdescs'}{$parameter_name});
1109 }
1110 foreach $section (@{$args{'sectionlist'}}) {
1111 print ".SH \"$section\"\n";
1112 output_highlight($args{'sections'}{$section});
1113 }
1114}
1115
1116##
1117# output struct in man
1118sub output_struct_man(%) {
1119 my %args = %{$_[0]};
1120 my ($parameter, $section);
1121
1122 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1123
1124 print ".SH NAME\n";
1125 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1126
1127 print ".SH SYNOPSIS\n";
1128 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1129
1130 foreach my $parameter (@{$args{'parameterlist'}}) {
1131 if ($parameter =~ /^#/) {
1132 print ".BI \"$parameter\"\n.br\n";
1133 next;
1134 }
1135 my $parameter_name = $parameter;
1136 $parameter_name =~ s/\[.*//;
1137
Randy Dunlap3c308792007-05-08 00:24:39 -07001138 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 $type = $args{'parametertypes'}{$parameter};
1140 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1141 # pointer-to-function
1142 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1143 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001144 # bitfield
1145 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 } else {
1147 $type =~ s/([^\*])$/$1 /;
1148 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1149 }
1150 print "\n.br\n";
1151 }
1152 print "};\n.br\n";
1153
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001154 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 foreach $parameter (@{$args{'parameterlist'}}) {
1156 ($parameter =~ /^#/) && next;
1157
1158 my $parameter_name = $parameter;
1159 $parameter_name =~ s/\[.*//;
1160
Randy Dunlap3c308792007-05-08 00:24:39 -07001161 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 print ".IP \"".$parameter."\" 12\n";
1163 output_highlight($args{'parameterdescs'}{$parameter_name});
1164 }
1165 foreach $section (@{$args{'sectionlist'}}) {
1166 print ".SH \"$section\"\n";
1167 output_highlight($args{'sections'}{$section});
1168 }
1169}
1170
1171##
1172# output typedef in man
1173sub output_typedef_man(%) {
1174 my %args = %{$_[0]};
1175 my ($parameter, $section);
1176
1177 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1178
1179 print ".SH NAME\n";
1180 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1181
1182 foreach $section (@{$args{'sectionlist'}}) {
1183 print ".SH \"$section\"\n";
1184 output_highlight($args{'sections'}{$section});
1185 }
1186}
1187
Johannes Bergb112e0f2007-10-24 15:08:48 -07001188sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 my %args = %{$_[0]};
1190 my ($parameter, $section);
1191 my $count;
1192
1193 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1194
1195 foreach $section (@{$args{'sectionlist'}}) {
1196 print ".SH \"$section\"\n";
1197 output_highlight($args{'sections'}{$section});
1198 }
1199}
1200
1201##
1202# output in text
1203sub output_function_text(%) {
1204 my %args = %{$_[0]};
1205 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001206 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Randy Dunlapf47634b2006-07-01 04:36:36 -07001208 print "Name:\n\n";
1209 print $args{'function'}." - ".$args{'purpose'}."\n";
1210
1211 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001212 if ($args{'functiontype'} ne "") {
1213 $start = $args{'functiontype'}." ".$args{'function'}." (";
1214 } else {
1215 $start = $args{'function'}." (";
1216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 my $count = 0;
1220 foreach my $parameter (@{$args{'parameterlist'}}) {
1221 $type = $args{'parametertypes'}{$parameter};
1222 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1223 # pointer-to-function
1224 print $1.$parameter.") (".$2;
1225 } else {
1226 print $type." ".$parameter;
1227 }
1228 if ($count != $#{$args{'parameterlist'}}) {
1229 $count++;
1230 print ",\n";
1231 print " " x length($start);
1232 } else {
1233 print ");\n\n";
1234 }
1235 }
1236
1237 print "Arguments:\n\n";
1238 foreach $parameter (@{$args{'parameterlist'}}) {
1239 my $parameter_name = $parameter;
1240 $parameter_name =~ s/\[.*//;
1241
1242 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1243 }
1244 output_section_text(@_);
1245}
1246
1247#output sections in text
1248sub output_section_text(%) {
1249 my %args = %{$_[0]};
1250 my $section;
1251
1252 print "\n";
1253 foreach $section (@{$args{'sectionlist'}}) {
1254 print "$section:\n\n";
1255 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 print "\n\n";
1258}
1259
1260# output enum in text
1261sub output_enum_text(%) {
1262 my %args = %{$_[0]};
1263 my ($parameter);
1264 my $count;
1265 print "Enum:\n\n";
1266
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001267 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 print "enum ".$args{'enum'}." {\n";
1269 $count = 0;
1270 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001271 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 if ($count != $#{$args{'parameterlist'}}) {
1273 $count++;
1274 print ",";
1275 }
1276 print "\n";
1277 }
1278 print "};\n\n";
1279
1280 print "Constants:\n\n";
1281 foreach $parameter (@{$args{'parameterlist'}}) {
1282 print "$parameter\n\t";
1283 print $args{'parameterdescs'}{$parameter}."\n";
1284 }
1285
1286 output_section_text(@_);
1287}
1288
1289# output typedef in text
1290sub output_typedef_text(%) {
1291 my %args = %{$_[0]};
1292 my ($parameter);
1293 my $count;
1294 print "Typedef:\n\n";
1295
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001296 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 output_section_text(@_);
1298}
1299
1300# output struct as text
1301sub output_struct_text(%) {
1302 my %args = %{$_[0]};
1303 my ($parameter);
1304
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001305 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 print $args{'type'}." ".$args{'struct'}." {\n";
1307 foreach $parameter (@{$args{'parameterlist'}}) {
1308 if ($parameter =~ /^#/) {
1309 print "$parameter\n";
1310 next;
1311 }
1312
1313 my $parameter_name = $parameter;
1314 $parameter_name =~ s/\[.*//;
1315
Randy Dunlap3c308792007-05-08 00:24:39 -07001316 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 $type = $args{'parametertypes'}{$parameter};
1318 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1319 # pointer-to-function
1320 print "\t$1 $parameter) ($2);\n";
1321 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001322 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 print "\t$1 $parameter$2;\n";
1324 } else {
1325 print "\t".$type." ".$parameter.";\n";
1326 }
1327 }
1328 print "};\n\n";
1329
1330 print "Members:\n\n";
1331 foreach $parameter (@{$args{'parameterlist'}}) {
1332 ($parameter =~ /^#/) && next;
1333
1334 my $parameter_name = $parameter;
1335 $parameter_name =~ s/\[.*//;
1336
Randy Dunlap3c308792007-05-08 00:24:39 -07001337 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 print "$parameter\n\t";
1339 print $args{'parameterdescs'}{$parameter_name}."\n";
1340 }
1341 print "\n";
1342 output_section_text(@_);
1343}
1344
Johannes Bergb112e0f2007-10-24 15:08:48 -07001345sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 my %args = %{$_[0]};
1347 my ($parameter, $section);
1348
1349 foreach $section (@{$args{'sectionlist'}}) {
1350 print " $section:\n";
1351 print " -> ";
1352 output_highlight($args{'sections'}{$section});
1353 }
1354}
1355
1356##
Randy Dunlap27205742006-10-11 01:22:12 -07001357# generic output function for all types (function, struct/union, typedef, enum);
1358# calls the generated, variable output_ function name based on
1359# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360sub output_declaration {
1361 no strict 'refs';
1362 my $name = shift;
1363 my $functype = shift;
1364 my $func = "output_${functype}_$output_mode";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001365 if (($function_only==0) ||
1366 ( $function_only == 1 && defined($function_table{$name})) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 ( $function_only == 2 && !defined($function_table{$name})))
1368 {
Randy Dunlap3c308792007-05-08 00:24:39 -07001369 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 $section_counter++;
1371 }
1372}
1373
1374##
Randy Dunlap27205742006-10-11 01:22:12 -07001375# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07001376sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 no strict 'refs';
Johannes Bergb112e0f2007-10-24 15:08:48 -07001378 my $func = "output_blockhead_".$output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 &$func(@_);
1380 $section_counter++;
1381}
1382
1383##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001384# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385# invokes the right handler. NOT called for functions.
1386sub dump_declaration($$) {
1387 no strict 'refs';
1388 my ($prototype, $file) = @_;
1389 my $func = "dump_".$decl_type;
1390 &$func(@_);
1391}
1392
1393sub dump_union($$) {
1394 dump_struct(@_);
1395}
1396
1397sub dump_struct($$) {
1398 my $x = shift;
1399 my $file = shift;
1400
1401 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001402 $declaration_name = $2;
1403 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 # ignore embedded structs or unions
1406 $members =~ s/{.*?}//g;
1407
Martin Waitzaeec46b2005-11-13 16:08:13 -08001408 # ignore members marked private:
1409 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1410 $members =~ s/\/\*.*?private:.*//gos;
1411 # strip comments:
1412 $members =~ s/\/\*.*?\*\///gos;
1413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 create_parameterlist($members, ';', $file);
1415
1416 output_declaration($declaration_name,
1417 'struct',
1418 {'struct' => $declaration_name,
1419 'module' => $modulename,
1420 'parameterlist' => \@parameterlist,
1421 'parameterdescs' => \%parameterdescs,
1422 'parametertypes' => \%parametertypes,
1423 'sectionlist' => \@sectionlist,
1424 'sections' => \%sections,
1425 'purpose' => $declaration_purpose,
1426 'type' => $decl_type
1427 });
1428 }
1429 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001430 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 ++$errors;
1432 }
1433}
1434
1435sub dump_enum($$) {
1436 my $x = shift;
1437 my $file = shift;
1438
Martin Waitzaeec46b2005-11-13 16:08:13 -08001439 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001441 $declaration_name = $1;
1442 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
1444 foreach my $arg (split ',', $members) {
1445 $arg =~ s/^\s*(\w+).*/$1/;
1446 push @parameterlist, $arg;
1447 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001448 $parameterdescs{$arg} = $undescribed;
1449 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 "not described in enum '$declaration_name'\n";
1451 }
1452
1453 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 output_declaration($declaration_name,
1456 'enum',
1457 {'enum' => $declaration_name,
1458 'module' => $modulename,
1459 'parameterlist' => \@parameterlist,
1460 'parameterdescs' => \%parameterdescs,
1461 'sectionlist' => \@sectionlist,
1462 'sections' => \%sections,
1463 'purpose' => $declaration_purpose
1464 });
1465 }
1466 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001467 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 ++$errors;
1469 }
1470}
1471
1472sub dump_typedef($$) {
1473 my $x = shift;
1474 my $file = shift;
1475
Martin Waitzaeec46b2005-11-13 16:08:13 -08001476 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001478 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 $x =~ s/\[*.\]\s*;$/;/;
1480 }
1481
1482 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001483 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 output_declaration($declaration_name,
1486 'typedef',
1487 {'typedef' => $declaration_name,
1488 'module' => $modulename,
1489 'sectionlist' => \@sectionlist,
1490 'sections' => \%sections,
1491 'purpose' => $declaration_purpose
1492 });
1493 }
1494 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001495 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 ++$errors;
1497 }
1498}
1499
1500sub create_parameterlist($$$) {
1501 my $args = shift;
1502 my $splitter = shift;
1503 my $file = shift;
1504 my $type;
1505 my $param;
1506
Martin Waitza6d3fe72006-01-09 20:53:55 -08001507 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001509 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 foreach my $arg (split($splitter, $args)) {
1513 # strip comments
1514 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07001515 # strip leading/trailing spaces
1516 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 $arg =~ s/\s*$//;
1518 $arg =~ s/\s+/ /;
1519
1520 if ($arg =~ /^#/) {
1521 # Treat preprocessor directive as a typeless variable just to fill
1522 # corresponding data structures "correctly". Catch it later in
1523 # output_* subs.
1524 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08001525 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 # pointer-to-function
1527 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08001528 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 $param = $1;
1530 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08001531 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08001533 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 $arg =~ s/\s*:\s*/:/g;
1535 $arg =~ s/\s*\[/\[/g;
1536
1537 my @args = split('\s*,\s*', $arg);
1538 if ($args[0] =~ m/\*/) {
1539 $args[0] =~ s/(\*+)\s*/ $1/;
1540 }
Borislav Petkov884f2812007-05-08 00:29:05 -07001541
1542 my @first_arg;
1543 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1544 shift @args;
1545 push(@first_arg, split('\s+', $1));
1546 push(@first_arg, $2);
1547 } else {
1548 @first_arg = split('\s+', shift @args);
1549 }
1550
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 unshift(@args, pop @first_arg);
1552 $type = join " ", @first_arg;
1553
1554 foreach $param (@args) {
1555 if ($param =~ m/^(\*+)\s*(.*)/) {
1556 push_parameter($2, "$type $1", $file);
1557 }
1558 elsif ($param =~ m/(.*?):(\d+)/) {
1559 push_parameter($1, "$type:$2", $file)
1560 }
1561 else {
1562 push_parameter($param, $type, $file);
1563 }
1564 }
1565 }
1566 }
1567}
1568
1569sub push_parameter($$$) {
1570 my $param = shift;
1571 my $type = shift;
1572 my $file = shift;
1573
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001574 if (($anon_struct_union == 1) && ($type eq "") &&
1575 ($param eq "}")) {
1576 return; # ignore the ending }; from anon. struct/union
1577 }
1578
1579 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 my $param_name = $param;
1581 $param_name =~ s/\[.*//;
1582
Martin Waitza6d3fe72006-01-09 20:53:55 -08001583 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 {
1585 $type="";
Martin Waitza6d3fe72006-01-09 20:53:55 -08001586 $parameterdescs{$param} = "variable arguments";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 }
1588 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1589 {
1590 $type="";
1591 $param="void";
1592 $parameterdescs{void} = "no arguments";
1593 }
Randy Dunlap134fe012006-12-22 01:10:50 -08001594 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1595 # handle unnamed (anonymous) union or struct:
1596 {
1597 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001598 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08001599 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001600 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08001601 }
1602
Martin Waitza6d3fe72006-01-09 20:53:55 -08001603 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08001604 # (but ignore ones starting with # as these are not parameters
1605 # but inline preprocessor statements);
1606 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001607 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08001608 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 $parameterdescs{$param_name} = $undescribed;
1611
1612 if (($type eq 'function') || ($type eq 'enum')) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001613 print STDERR "Warning(${file}:$.): Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 "or member '$param' not " .
1615 "described in '$declaration_name'\n";
1616 }
1617 print STDERR "Warning(${file}:$.):".
Randy Dunlap3c308792007-05-08 00:24:39 -07001618 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07001620 }
1621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 push @parameterlist, $param;
1624 $parametertypes{$param} = $type;
1625}
1626
1627##
1628# takes a function prototype and the name of the current file being
1629# processed and spits out all the details stored in the global
1630# arrays/hashes.
1631sub dump_function($$) {
1632 my $prototype = shift;
1633 my $file = shift;
1634
1635 $prototype =~ s/^static +//;
1636 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07001637 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 $prototype =~ s/^inline +//;
1639 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07001640 $prototype =~ s/^__inline +//;
1641 $prototype =~ s/^__always_inline +//;
1642 $prototype =~ s/^noinline +//;
Randy Dunlap0129a052006-07-30 03:03:41 -07001643 $prototype =~ s/__devinit +//;
Randy Dunlap996a07b2007-02-10 01:45:56 -08001644 $prototype =~ s/^#define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08001645 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 # Yes, this truly is vile. We are looking for:
1648 # 1. Return type (may be nothing if we're looking at a macro)
1649 # 2. Function name
1650 # 3. Function parameters.
1651 #
1652 # All the while we have to watch out for function pointer parameters
1653 # (which IIRC is what the two sections are for), C types (these
1654 # regexps don't even start to express all the possibilities), and
1655 # so on.
1656 #
1657 # If you mess with these regexps, it's a good idea to check that
1658 # the following functions' documentation still comes out right:
1659 # - parport_register_device (function pointer parameters)
1660 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08001661 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
1663 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1664 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1665 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1666 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08001667 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1669 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1670 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1671 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1672 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1673 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1674 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1675 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08001676 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1677 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd72007-02-10 22:47:33 -08001678 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1679 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 $return_type = $1;
1681 $declaration_name = $2;
1682 my $args = $3;
1683
1684 create_parameterlist($args, ',', $file);
1685 } else {
1686 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1687 ++$errors;
1688 return;
1689 }
1690
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001691 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 'function',
1693 {'function' => $declaration_name,
1694 'module' => $modulename,
1695 'functiontype' => $return_type,
1696 'parameterlist' => \@parameterlist,
1697 'parameterdescs' => \%parameterdescs,
1698 'parametertypes' => \%parametertypes,
1699 'sectionlist' => \@sectionlist,
1700 'sections' => \%sections,
1701 'purpose' => $declaration_purpose
1702 });
1703}
1704
1705sub process_file($);
1706
1707# Read the file that maps relative names to absolute names for
1708# separate source and object directories and for shadow trees.
1709if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1710 my ($relname, $absname);
1711 while(<SOURCE_MAP>) {
1712 chop();
1713 ($relname, $absname) = (split())[0..1];
1714 $relname =~ s:^/+::;
1715 $source_map{$relname} = $absname;
1716 }
1717 close(SOURCE_MAP);
1718}
1719
1720if ($filelist) {
1721 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1722 while(<FLIST>) {
1723 chop;
1724 process_file($_);
1725 }
1726}
1727
1728foreach (@ARGV) {
1729 chomp;
1730 process_file($_);
1731}
1732if ($verbose && $errors) {
1733 print STDERR "$errors errors\n";
1734}
1735if ($verbose && $warnings) {
1736 print STDERR "$warnings warnings\n";
1737}
1738
1739exit($errors);
1740
1741sub reset_state {
1742 $function = "";
1743 %constants = ();
1744 %parameterdescs = ();
1745 %parametertypes = ();
1746 @parameterlist = ();
1747 %sections = ();
1748 @sectionlist = ();
1749 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001750
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 $state = 0;
1752}
1753
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001754sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 my $x = shift;
1756 my $file = shift;
1757
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001758 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1761 # do nothing
1762 }
1763 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001764 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 }
1766 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001767 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1769 $prototype =~ s@^\s+@@gos; # strip leading spaces
1770 dump_function($prototype,$file);
1771 reset_state();
1772 }
1773}
1774
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001775sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 my $x = shift;
1777 my $file = shift;
1778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1780 $x =~ s@^\s+@@gos; # strip leading spaces
1781 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001782 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1783
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if ($x =~ /^#/) {
1785 # To distinguish preprocessor directive from regular declaration later.
1786 $x .= ";";
1787 }
1788
1789 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001790 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 $prototype .= $1 . $2;
1792 ($2 eq '{') && $brcount++;
1793 ($2 eq '}') && $brcount--;
1794 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001795 dump_declaration($prototype,$file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07001797 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 }
1799 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07001800 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 $prototype .= $x;
1802 last;
1803 }
1804 }
1805}
1806
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07001807# xml_escape: replace <, >, and & in the text stream;
1808#
1809# however, formatting controls that are generated internally/locally in the
1810# kernel-doc script are not escaped here; instead, they begin life like
1811# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1812# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1813# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814sub xml_escape($) {
1815 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07001816 if (($output_mode eq "text") || ($output_mode eq "man")) {
1817 return $text;
1818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 $text =~ s/\&/\\\\\\amp;/g;
1820 $text =~ s/\</\\\\\\lt;/g;
1821 $text =~ s/\>/\\\\\\gt;/g;
1822 return $text;
1823}
1824
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07001825# convert local escape strings to html
1826# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1827sub local_unescape($) {
1828 my $text = shift;
1829 if (($output_mode eq "text") || ($output_mode eq "man")) {
1830 return $text;
1831 }
1832 $text =~ s/\\\\\\\\lt:/</g;
1833 $text =~ s/\\\\\\\\gt:/>/g;
1834 return $text;
1835}
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07001838 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 my $identifier;
1840 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001841 my $descr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 my $initial_section_counter = $section_counter;
1843
Randy Dunlap2283a112005-07-07 15:39:26 -07001844 if (defined($ENV{'SRCTREE'})) {
1845 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1846 }
1847 else {
1848 $file = "@_";
1849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 if (defined($source_map{$file})) {
1851 $file = $source_map{$file};
1852 }
1853
1854 if (!open(IN,"<$file")) {
1855 print STDERR "Error: Cannot open file $file\n";
1856 ++$errors;
1857 return;
1858 }
1859
1860 $section_counter = 0;
1861 while (<IN>) {
1862 if ($state == 0) {
1863 if (/$doc_start/o) {
1864 $state = 1; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07001865 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
1867 } elsif ($state == 1) { # this line is the function name (always)
1868 if (/$doc_block/o) {
1869 $state = 4;
1870 $contents = "";
1871 if ( $1 eq "" ) {
1872 $section = $section_intro;
1873 } else {
1874 $section = $1;
1875 }
Randy Dunlap3c308792007-05-08 00:24:39 -07001876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 elsif (/$doc_decl/o) {
1878 $identifier = $1;
1879 if (/\s*([\w\s]+?)\s*-/) {
1880 $identifier = $1;
1881 }
1882
1883 $state = 2;
1884 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001885 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08001886 $descr= $1;
1887 $descr =~ s/^\s*//;
1888 $descr =~ s/\s*$//;
1889 $descr =~ s/\s+/ /;
1890 $declaration_purpose = xml_escape($descr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 } else {
1892 $declaration_purpose = "";
1893 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08001894
1895 if (($declaration_purpose eq "") && $verbose) {
1896 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
1897 print STDERR $_;
1898 ++$warnings;
1899 }
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 if ($identifier =~ m/^struct/) {
1902 $decl_type = 'struct';
1903 } elsif ($identifier =~ m/^union/) {
1904 $decl_type = 'union';
1905 } elsif ($identifier =~ m/^enum/) {
1906 $decl_type = 'enum';
1907 } elsif ($identifier =~ m/^typedef/) {
1908 $decl_type = 'typedef';
1909 } else {
1910 $decl_type = 'function';
1911 }
1912
1913 if ($verbose) {
1914 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1915 }
1916 } else {
1917 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1918 " - I thought it was a doc line\n";
1919 ++$warnings;
1920 $state = 0;
1921 }
1922 } elsif ($state == 2) { # look for head: lines, and include content
1923 if (/$doc_sect/o) {
1924 $newsection = $1;
1925 $newcontents = $2;
1926
Randy Dunlap792aa2f2008-02-07 00:13:41 -08001927 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07001928 if (!$in_doc_sect && $verbose) {
1929 print STDERR "Warning(${file}:$.): contents before sections\n";
1930 ++$warnings;
1931 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07001932 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 $section = $section_default;
1934 }
1935
Randy Dunlap850622d2006-06-25 05:48:55 -07001936 $in_doc_sect = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 $contents = $newcontents;
1938 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07001939 while ((substr($contents, 0, 1) eq " ") ||
1940 substr($contents, 0, 1) eq "\t") {
1941 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07001942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 $contents .= "\n";
1944 }
1945 $section = $newsection;
1946 } elsif (/$doc_end/) {
1947
1948 if ($contents ne "") {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07001949 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 $section = $section_default;
1951 $contents = "";
1952 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07001953 # look for doc_com + <text> + doc_end:
1954 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
1955 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
1956 ++$warnings;
1957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
1959 $prototype = "";
1960 $state = 3;
1961 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07001962# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 } elsif (/$doc_content/) {
1964 # miguel-style comment kludge, look for blank lines after
1965 # @parameter line to signify start of description
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001966 if ($1 eq "" &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 ($section =~ m/^@/ || $section eq $section_context)) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07001968 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 $section = $section_default;
1970 $contents = "";
1971 } else {
1972 $contents .= $1."\n";
1973 }
1974 } else {
1975 # i dont know - bad line? ignore.
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001976 print STDERR "Warning(${file}:$.): bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 ++$warnings;
1978 }
Randy Dunlap232acbc2006-06-25 05:47:48 -07001979 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 if ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07001981 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001983 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 }
1985 } elsif ($state == 4) {
1986 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07001987 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07001988 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 $contents = "";
1990 $function = "";
1991 %constants = ();
1992 %parameterdescs = ();
1993 %parametertypes = ();
1994 @parameterlist = ();
1995 %sections = ();
1996 @sectionlist = ();
1997 $prototype = "";
1998 if ( $1 eq "" ) {
1999 $section = $section_intro;
2000 } else {
2001 $section = $1;
2002 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 elsif (/$doc_end/)
2005 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002006 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 $contents = "";
2008 $function = "";
2009 %constants = ();
2010 %parameterdescs = ();
2011 %parametertypes = ();
2012 @parameterlist = ();
2013 %sections = ();
2014 @sectionlist = ();
2015 $prototype = "";
2016 $state = 0;
2017 }
2018 elsif (/$doc_content/)
2019 {
2020 if ( $1 eq "" )
2021 {
2022 $contents .= $blankline;
2023 }
2024 else
2025 {
2026 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002027 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002028 }
2029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031 if ($initial_section_counter == $section_counter) {
2032 print STDERR "Warning(${file}): no structured comments found\n";
2033 if ($output_mode eq "xml") {
2034 # The template wants at least one RefEntry here; make one.
2035 print "<refentry>\n";
2036 print " <refnamediv>\n";
2037 print " <refname>\n";
2038 print " ${file}\n";
2039 print " </refname>\n";
2040 print " <refpurpose>\n";
2041 print " Document generation inconsistency\n";
2042 print " </refpurpose>\n";
2043 print " </refnamediv>\n";
2044 print " <refsect1>\n";
2045 print " <title>\n";
2046 print " Oops\n";
2047 print " </title>\n";
2048 print " <warning>\n";
2049 print " <para>\n";
2050 print " The template for this document tried to insert\n";
2051 print " the structured comment from the file\n";
2052 print " <filename>${file}</filename> at this point,\n";
2053 print " but none was found.\n";
2054 print " This dummy section is inserted to allow\n";
2055 print " generation to continue.\n";
2056 print " </para>\n";
2057 print " </warning>\n";
2058 print " </refsect1>\n";
2059 print "</refentry>\n";
2060 }
2061 }
2062}