blob: 97e037aa97a7a3d1f41c1a9645982b8c82023b8a [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 Dunlap70c95b02012-01-21 10:31:54 -08008## Copyright (C) 2005-2012 Randy Dunlap ##
Dan Luedtke1b40c192012-08-12 10:46:15 +02009## Copyright (C) 2012 Dan Luedtke ##
Linus Torvalds1da177e2005-04-16 15:20:36 -070010## ##
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017# 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
Dan Luedtke1b40c192012-08-12 10:46:15 +020039# 25/07/2012 - Added support for HTML5
40# -- Dan Luedtke <mail@danrl.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#
43# This will read a 'c' file and scan for embedded comments in the
44# style of gnome comments (+minor extensions - see below).
45#
46
47# Note: This only supports 'c'.
48
49# usage:
Dan Luedtke1b40c192012-08-12 10:46:15 +020050# kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ]
51# [ -no-doc-sections ]
52# [ -function funcname [ -function funcname ...] ]
53# c file(s)s > outputfile
Linus Torvalds1da177e2005-04-16 15:20:36 -070054# or
Dan Luedtke1b40c192012-08-12 10:46:15 +020055# [ -nofunction funcname [ -function funcname ...] ]
56# c file(s)s > outputfile
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#
Dan Luedtke1b40c192012-08-12 10:46:15 +020058# Set output format using one of -docbook -html -html5 -text or -man.
59# Default is man.
Johannes Bergeda603f2010-09-11 15:55:22 -070060# The -list format is for internal use by docproc.
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#
Johannes Berg4b445952007-10-24 15:08:48 -070062# -no-doc-sections
63# Do not output DOC: sections
64#
Linus Torvalds1da177e2005-04-16 15:20:36 -070065# -function funcname
Johannes Bergb112e0f2007-10-24 15:08:48 -070066# If set, then only generate documentation for the given function(s) or
67# DOC: section titles. All other functions and DOC: sections are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#
69# -nofunction funcname
Johannes Bergb112e0f2007-10-24 15:08:48 -070070# If set, then only generate documentation for the other function(s)/DOC:
71# sections. Cannot be used together with -function (yes, that's a bug --
72# perl hackers can fix it 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#
74# c files - list of 'c' files to process
75#
76# All output goes to stdout, with errors to stderr.
77
78#
79# format of comments.
80# In the following table, (...)? signifies optional structure.
81# (...)* signifies 0 or more structure elements
82# /**
83# * function_name(:)? (- short description)?
84# (* @parameterx: (description of parameter x)?)*
85# (* a blank line)?
86# * (Description:)? (Description of function)?
87# * (section header: (section description)? )*
88# (*)?*/
89#
90# So .. the trivial example would be:
91#
92# /**
93# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -070094# */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#
Randy Dunlap891dcd22007-02-10 01:45:53 -080096# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -070097# after the last parameter specification.
98# e.g.
99# /**
100# * my_function - does my stuff
101# * @my_arg: its mine damnit
102# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800103# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104# */
105#
106# or, could also use:
107# /**
108# * my_function - does my stuff
109# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800110# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111# */
112# etc.
113#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700114# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800115# enums and typedefs. Instead of the function name you must write the name
116# of the declaration; the struct/union/enum/typedef must always precede
117# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118# Use the argument mechanism to document members or constants.
119# e.g.
120# /**
121# * struct my_struct - short description
122# * @a: first member
123# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800124# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125# * Longer description
126# */
127# struct my_struct {
128# int a;
129# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800130# /* private: */
131# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132# };
133#
134# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800135#
136# You can also add additional sections. When documenting kernel functions you
137# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800139# empty line.
140# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141# appropriately in DocBook.
142#
143# Example:
144# /**
145# * user_function - function that can only be called in user context
146# * @a: some argument
147# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800148# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149# * Some description
150# * Example:
151# * user_function(22);
152# */
153# ...
154#
155#
156# All descriptive text is further processed, scanning for the following special
157# patterns, which are highlighted appropriately.
158#
159# 'funcname()' - function
160# '$ENVVAR' - environmental variable
161# '&struct_name' - name of a structure (up to two words including 'struct')
162# '@parameter' - name of a parameter
163# '%CONST' - name of a constant.
164
Randy Dunlap8484baa2011-01-05 16:28:43 -0800165## init lots of data
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167my $errors = 0;
168my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700169my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171# match expressions used to find embedded type information
172my $type_constant = '\%([-_\w]+)';
173my $type_func = '(\w+)\(\)';
174my $type_param = '\@(\w+)';
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700175my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700176my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177my $type_env = '(\$\w+)';
178
179# Output conversion substitutions.
180# One for each output format
181
182# these work fairly well
183my %highlights_html = ( $type_constant, "<i>\$1</i>",
184 $type_func, "<b>\$1</b>",
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700185 $type_struct_xml, "<i>\$1</i>",
186 $type_env, "<b><i>\$1</i></b>",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 $type_param, "<tt><b>\$1</b></tt>" );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700188my $local_lt = "\\\\\\\\lt:";
189my $local_gt = "\\\\\\\\gt:";
190my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Dan Luedtke1b40c192012-08-12 10:46:15 +0200192# html version 5
193my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>",
194 $type_func, "<span class=\"func\">\$1</span>",
195 $type_struct_xml, "<span class=\"struct\">\$1</span>",
196 $type_env, "<span class=\"env\">\$1</span>",
197 $type_param, "<span class=\"param\">\$1</span>" );
198my $blankline_html5 = $local_lt . "br /" . $local_gt;
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200# XML, docbook format
201my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
202 $type_constant, "<constant>\$1</constant>",
203 $type_func, "<function>\$1</function>",
Johannes Berg5c98fc02007-10-24 15:08:48 -0700204 $type_struct_xml, "<structname>\$1</structname>",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 $type_env, "<envar>\$1</envar>",
206 $type_param, "<parameter>\$1</parameter>" );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700207my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209# gnome, docbook format
210my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
211 $type_func, "<function>\$1</function>",
212 $type_struct, "<structname>\$1</structname>",
213 $type_env, "<envar>\$1</envar>",
214 $type_param, "<parameter>\$1</parameter>" );
215my $blankline_gnome = "</para><para>\n";
216
217# these are pretty rough
218my %highlights_man = ( $type_constant, "\$1",
219 $type_func, "\\\\fB\$1\\\\fP",
220 $type_struct, "\\\\fI\$1\\\\fP",
221 $type_param, "\\\\fI\$1\\\\fP" );
222my $blankline_man = "";
223
224# text-mode
225my %highlights_text = ( $type_constant, "\$1",
226 $type_func, "\$1",
227 $type_struct, "\$1",
228 $type_param, "\$1" );
229my $blankline_text = "";
230
Johannes Bergeda603f2010-09-11 15:55:22 -0700231# list mode
232my %highlights_list = ( $type_constant, "\$1",
233 $type_func, "\$1",
234 $type_struct, "\$1",
235 $type_param, "\$1" );
236my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700239if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 usage();
241}
242
Randy Dunlap8484baa2011-01-05 16:28:43 -0800243my $kernelversion;
244my $dohighlight = "";
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246my $verbose = 0;
247my $output_mode = "man";
Johannes Berg4b445952007-10-24 15:08:48 -0700248my $no_doc_sections = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249my %highlights = %highlights_man;
250my $blankline = $blankline_man;
251my $modulename = "Kernel API";
252my $function_only = 0;
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800253my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
254 'July', 'August', 'September', 'October',
255 'November', 'December')[(localtime)[4]] .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 " " . ((localtime)[5]+1900);
257
Randy Dunlap8484baa2011-01-05 16:28:43 -0800258# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700259# They probably want to be tidied up, made more localised or something.
260# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700262my ($function, %function_table, %parametertypes, $declaration_purpose);
263my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800264my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700266if (defined($ENV{'KBUILD_VERBOSE'})) {
267 $verbose = "$ENV{'KBUILD_VERBOSE'}";
268}
269
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800270# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
272# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
273# We keep track of number of generated entries and generate a dummy
274# if needs be to ensure the expanded template can be postprocessed
275# into html.
276my $section_counter = 0;
277
278my $lineprefix="";
279
280# states
281# 0 - normal code
282# 1 - looking for function name
283# 2 - scanning field start.
284# 3 - scanning prototype.
285# 4 - documentation block
286my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700287my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289#declaration types: can be
290# 'function', 'struct', 'union', 'enum', 'typedef'
291my $decl_type;
292
293my $doc_special = "\@\%\$\&";
294
295my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
296my $doc_end = '\*/';
297my $doc_com = '\s*\*\s*';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700298my $doc_decl = $doc_com . '(\w+)';
299my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
300my $doc_content = $doc_com . '(.*)';
301my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303my %constants;
304my %parameterdescs;
305my @parameterlist;
306my %sections;
307my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800308my $sectcheck;
309my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311my $contents = "";
312my $section_default = "Description"; # default section
313my $section_intro = "Introduction";
314my $section = $section_default;
315my $section_context = "Context";
316
317my $undescribed = "-- undescribed --";
318
319reset_state();
320
321while ($ARGV[0] =~ m/^-(.*)/) {
322 my $cmd = shift @ARGV;
323 if ($cmd eq "-html") {
324 $output_mode = "html";
325 %highlights = %highlights_html;
326 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200327 } elsif ($cmd eq "-html5") {
328 $output_mode = "html5";
329 %highlights = %highlights_html5;
330 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 } elsif ($cmd eq "-man") {
332 $output_mode = "man";
333 %highlights = %highlights_man;
334 $blankline = $blankline_man;
335 } elsif ($cmd eq "-text") {
336 $output_mode = "text";
337 %highlights = %highlights_text;
338 $blankline = $blankline_text;
339 } elsif ($cmd eq "-docbook") {
340 $output_mode = "xml";
341 %highlights = %highlights_xml;
342 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700343 } elsif ($cmd eq "-list") {
344 $output_mode = "list";
345 %highlights = %highlights_list;
346 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 } elsif ($cmd eq "-gnome") {
348 $output_mode = "gnome";
349 %highlights = %highlights_gnome;
350 $blankline = $blankline_gnome;
351 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
352 $modulename = shift @ARGV;
353 } elsif ($cmd eq "-function") { # to only output specific functions
354 $function_only = 1;
355 $function = shift @ARGV;
356 $function_table{$function} = 1;
357 } elsif ($cmd eq "-nofunction") { # to only output specific functions
358 $function_only = 2;
359 $function = shift @ARGV;
360 $function_table{$function} = 1;
361 } elsif ($cmd eq "-v") {
362 $verbose = 1;
363 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
364 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700365 } elsif ($cmd eq '-no-doc-sections') {
366 $no_doc_sections = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
368}
369
Randy Dunlap8484baa2011-01-05 16:28:43 -0800370# continue execution near EOF;
371
372sub usage {
Dan Luedtke1b40c192012-08-12 10:46:15 +0200373 print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -0800374 print " [ -no-doc-sections ]\n";
375 print " [ -function funcname [ -function funcname ...] ]\n";
376 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
Dan Luedtke1b40c192012-08-12 10:46:15 +0200377 print " [ -v ]\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -0800378 print " c source file(s) > outputfile\n";
379 print " -v : verbose output, more warnings & other info listed\n";
380 exit 1;
381}
382
Borislav Petkov53f049f2007-05-08 00:30:54 -0700383# get kernel version from env
384sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700385 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700386
387 if (defined($ENV{'KERNELVERSION'})) {
388 $version = $ENV{'KERNELVERSION'};
389 }
390 return $version;
391}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393##
394# dumps section contents to arrays/hashes intended for that purpose.
395#
396sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700397 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 my $name = shift;
399 my $contents = join "\n", @_;
400
401 if ($name =~ m/$type_constant/) {
402 $name = $1;
403# print STDERR "constant section '$1' = '$contents'\n";
404 $constants{$name} = $contents;
405 } elsif ($name =~ m/$type_param/) {
406# print STDERR "parameter def '$1' = '$contents'\n";
407 $name = $1;
408 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800409 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800410 } elsif ($name eq "@\.\.\.") {
411# print STDERR "parameter def '...' = '$contents'\n";
412 $name = "...";
413 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800414 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 } else {
416# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700417 if (defined($sections{$name}) && ($sections{$name} ne "")) {
418 print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
419 ++$errors;
420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 $sections{$name} = $contents;
422 push @sectionlist, $name;
423 }
424}
425
426##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700427# dump DOC: section after checking that it should go out
428#
429sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700430 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700431 my $name = shift;
432 my $contents = join "\n", @_;
433
Johannes Berg4b445952007-10-24 15:08:48 -0700434 if ($no_doc_sections) {
435 return;
436 }
437
Johannes Bergb112e0f2007-10-24 15:08:48 -0700438 if (($function_only == 0) ||
439 ( $function_only == 1 && defined($function_table{$name})) ||
440 ( $function_only == 2 && !defined($function_table{$name})))
441 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700442 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700443 output_blockhead({'sectionlist' => \@sectionlist,
444 'sections' => \%sections,
445 'module' => $modulename,
446 'content-only' => ($function_only != 0), });
447 }
448}
449
450##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451# output function
452#
453# parameterdescs, a hash.
454# function => "function name"
455# parameterlist => @list of parameters
456# parameterdescs => %parameter descriptions
457# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800458# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800459#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461sub output_highlight {
462 my $contents = join "\n",@_;
463 my $line;
464
465# DEBUG
466# if (!defined $contents) {
467# use Carp;
468# confess "output_highlight got called with no args?\n";
469# }
470
Dan Luedtke1b40c192012-08-12 10:46:15 +0200471 if ($output_mode eq "html" || $output_mode eq "html5" ||
472 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700473 $contents = local_unescape($contents);
474 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800475 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700476 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700477# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 eval $dohighlight;
479 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700480# print STDERR "contents af:$contents\n";
481
Dan Luedtke1b40c192012-08-12 10:46:15 +0200482# strip whitespaces when generating html5
483 if ($output_mode eq "html5") {
484 $contents =~ s/^\s+//;
485 $contents =~ s/\s+$//;
486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 foreach $line (split "\n", $contents) {
Randy Dunlap3c308792007-05-08 00:24:39 -0700488 if ($line eq ""){
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700489 print $lineprefix, local_unescape($blankline);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700491 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700492 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
493 print "\\&$line";
494 } else {
495 print $lineprefix, $line;
496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498 print "\n";
499 }
500}
501
Dan Luedtke1b40c192012-08-12 10:46:15 +0200502# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503sub output_section_html(%) {
504 my %args = %{$_[0]};
505 my $section;
506
507 foreach $section (@{$args{'sectionlist'}}) {
508 print "<h3>$section</h3>\n";
509 print "<blockquote>\n";
510 output_highlight($args{'sections'}{$section});
511 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
515# output enum in html
516sub output_enum_html(%) {
517 my %args = %{$_[0]};
518 my ($parameter);
519 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700520 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Randy Dunlapb9d973282009-06-09 08:50:38 -0700522 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 $count = 0;
524 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700525 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if ($count != $#{$args{'parameterlist'}}) {
527 $count++;
528 print ",\n";
529 }
530 print "<br>";
531 }
532 print "};<br>\n";
533
534 print "<h3>Constants</h3>\n";
535 print "<dl>\n";
536 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700537 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 print "<dd>";
539 output_highlight($args{'parameterdescs'}{$parameter});
540 }
541 print "</dl>\n";
542 output_section_html(@_);
543 print "<hr>\n";
544}
545
Randy Dunlapd28bee02006-02-01 03:06:57 -0800546# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547sub output_typedef_html(%) {
548 my %args = %{$_[0]};
549 my ($parameter);
550 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700551 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
Randy Dunlapb9d973282009-06-09 08:50:38 -0700553 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 output_section_html(@_);
555 print "<hr>\n";
556}
557
558# output struct in html
559sub output_struct_html(%) {
560 my %args = %{$_[0]};
561 my ($parameter);
562
Randy Dunlapb9d973282009-06-09 08:50:38 -0700563 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
564 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 foreach $parameter (@{$args{'parameterlist'}}) {
566 if ($parameter =~ /^#/) {
567 print "$parameter<br>\n";
568 next;
569 }
570 my $parameter_name = $parameter;
571 $parameter_name =~ s/\[.*//;
572
Randy Dunlap3c308792007-05-08 00:24:39 -0700573 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 $type = $args{'parametertypes'}{$parameter};
575 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
576 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700577 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700579 # bitfield
580 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700582 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 }
584 }
585 print "};<br>\n";
586
587 print "<h3>Members</h3>\n";
588 print "<dl>\n";
589 foreach $parameter (@{$args{'parameterlist'}}) {
590 ($parameter =~ /^#/) && next;
591
592 my $parameter_name = $parameter;
593 $parameter_name =~ s/\[.*//;
594
Randy Dunlap3c308792007-05-08 00:24:39 -0700595 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700596 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 print "<dd>";
598 output_highlight($args{'parameterdescs'}{$parameter_name});
599 }
600 print "</dl>\n";
601 output_section_html(@_);
602 print "<hr>\n";
603}
604
605# output function in html
606sub output_function_html(%) {
607 my %args = %{$_[0]};
608 my ($parameter, $section);
609 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Randy Dunlapb9d973282009-06-09 08:50:38 -0700611 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
612 print "<i>" . $args{'functiontype'} . "</i>\n";
613 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 print "(";
615 $count = 0;
616 foreach $parameter (@{$args{'parameterlist'}}) {
617 $type = $args{'parametertypes'}{$parameter};
618 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
619 # pointer-to-function
620 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
621 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700622 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624 if ($count != $#{$args{'parameterlist'}}) {
625 $count++;
626 print ",\n";
627 }
628 }
629 print ")\n";
630
631 print "<h3>Arguments</h3>\n";
632 print "<dl>\n";
633 foreach $parameter (@{$args{'parameterlist'}}) {
634 my $parameter_name = $parameter;
635 $parameter_name =~ s/\[.*//;
636
Randy Dunlap3c308792007-05-08 00:24:39 -0700637 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700638 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 print "<dd>";
640 output_highlight($args{'parameterdescs'}{$parameter_name});
641 }
642 print "</dl>\n";
643 output_section_html(@_);
644 print "<hr>\n";
645}
646
Johannes Bergb112e0f2007-10-24 15:08:48 -0700647# output DOC: block header in html
648sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 my %args = %{$_[0]};
650 my ($parameter, $section);
651 my $count;
652
653 foreach $section (@{$args{'sectionlist'}}) {
654 print "<h3>$section</h3>\n";
655 print "<ul>\n";
656 output_highlight($args{'sections'}{$section});
657 print "</ul>\n";
658 }
659 print "<hr>\n";
660}
661
Dan Luedtke1b40c192012-08-12 10:46:15 +0200662# output sections in html5
663sub output_section_html5(%) {
664 my %args = %{$_[0]};
665 my $section;
666
667 foreach $section (@{$args{'sectionlist'}}) {
668 print "<section>\n";
669 print "<h1>$section</h1>\n";
670 print "<p>\n";
671 output_highlight($args{'sections'}{$section});
672 print "</p>\n";
673 print "</section>\n";
674 }
675}
676
677# output enum in html5
678sub output_enum_html5(%) {
679 my %args = %{$_[0]};
680 my ($parameter);
681 my $count;
682 my $html5id;
683
684 $html5id = $args{'enum'};
685 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
686 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
687 print "<h1>enum " . $args{'enum'} . "</h1>\n";
688 print "<ol class=\"code\">\n";
689 print "<li>";
690 print "<span class=\"keyword\">enum</span> ";
691 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
692 print "</li>\n";
693 $count = 0;
694 foreach $parameter (@{$args{'parameterlist'}}) {
695 print "<li class=\"indent\">";
696 print "<span class=\"param\">" . $parameter . "</span>";
697 if ($count != $#{$args{'parameterlist'}}) {
698 $count++;
699 print ",";
700 }
701 print "</li>\n";
702 }
703 print "<li>};</li>\n";
704 print "</ol>\n";
705
706 print "<section>\n";
707 print "<h1>Constants</h1>\n";
708 print "<dl>\n";
709 foreach $parameter (@{$args{'parameterlist'}}) {
710 print "<dt>" . $parameter . "</dt>\n";
711 print "<dd>";
712 output_highlight($args{'parameterdescs'}{$parameter});
713 print "</dd>\n";
714 }
715 print "</dl>\n";
716 print "</section>\n";
717 output_section_html5(@_);
718 print "</article>\n";
719}
720
721# output typedef in html5
722sub output_typedef_html5(%) {
723 my %args = %{$_[0]};
724 my ($parameter);
725 my $count;
726 my $html5id;
727
728 $html5id = $args{'typedef'};
729 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
730 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
731 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
732
733 print "<ol class=\"code\">\n";
734 print "<li>";
735 print "<span class=\"keyword\">typedef</span> ";
736 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
737 print "</li>\n";
738 print "</ol>\n";
739 output_section_html5(@_);
740 print "</article>\n";
741}
742
743# output struct in html5
744sub output_struct_html5(%) {
745 my %args = %{$_[0]};
746 my ($parameter);
747 my $html5id;
748
749 $html5id = $args{'struct'};
750 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
751 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
752 print "<hgroup>\n";
753 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
754 print "<h2>". $args{'purpose'} . "</h2>\n";
755 print "</hgroup>\n";
756 print "<ol class=\"code\">\n";
757 print "<li>";
758 print "<span class=\"type\">" . $args{'type'} . "</span> ";
759 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
760 print "</li>\n";
761 foreach $parameter (@{$args{'parameterlist'}}) {
762 print "<li class=\"indent\">";
763 if ($parameter =~ /^#/) {
764 print "<span class=\"param\">" . $parameter ."</span>\n";
765 print "</li>\n";
766 next;
767 }
768 my $parameter_name = $parameter;
769 $parameter_name =~ s/\[.*//;
770
771 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
772 $type = $args{'parametertypes'}{$parameter};
773 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
774 # pointer-to-function
775 print "<span class=\"type\">$1</span> ";
776 print "<span class=\"param\">$parameter</span>";
777 print "<span class=\"type\">)</span> ";
778 print "(<span class=\"args\">$2</span>);";
779 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
780 # bitfield
781 print "<span class=\"type\">$1</span> ";
782 print "<span class=\"param\">$parameter</span>";
783 print "<span class=\"bits\">$2</span>;";
784 } else {
785 print "<span class=\"type\">$type</span> ";
786 print "<span class=\"param\">$parameter</span>;";
787 }
788 print "</li>\n";
789 }
790 print "<li>};</li>\n";
791 print "</ol>\n";
792
793 print "<section>\n";
794 print "<h1>Members</h1>\n";
795 print "<dl>\n";
796 foreach $parameter (@{$args{'parameterlist'}}) {
797 ($parameter =~ /^#/) && next;
798
799 my $parameter_name = $parameter;
800 $parameter_name =~ s/\[.*//;
801
802 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
803 print "<dt>" . $parameter . "</dt>\n";
804 print "<dd>";
805 output_highlight($args{'parameterdescs'}{$parameter_name});
806 print "</dd>\n";
807 }
808 print "</dl>\n";
809 print "</section>\n";
810 output_section_html5(@_);
811 print "</article>\n";
812}
813
814# output function in html5
815sub output_function_html5(%) {
816 my %args = %{$_[0]};
817 my ($parameter, $section);
818 my $count;
819 my $html5id;
820
821 $html5id = $args{'function'};
822 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
823 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
824 print "<hgroup>\n";
825 print "<h1>" . $args{'function'} . "</h1>";
826 print "<h2>" . $args{'purpose'} . "</h2>\n";
827 print "</hgroup>\n";
828 print "<ol class=\"code\">\n";
829 print "<li>";
830 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
831 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
832 print "</li>";
833 $count = 0;
834 foreach $parameter (@{$args{'parameterlist'}}) {
835 print "<li class=\"indent\">";
836 $type = $args{'parametertypes'}{$parameter};
837 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
838 # pointer-to-function
839 print "<span class=\"type\">$1</span> ";
840 print "<span class=\"param\">$parameter</span>";
841 print "<span class=\"type\">)</span> ";
842 print "(<span class=\"args\">$2</span>)";
843 } else {
844 print "<span class=\"type\">$type</span> ";
845 print "<span class=\"param\">$parameter</span>";
846 }
847 if ($count != $#{$args{'parameterlist'}}) {
848 $count++;
849 print ",";
850 }
851 print "</li>\n";
852 }
853 print "<li>)</li>\n";
854 print "</ol>\n";
855
856 print "<section>\n";
857 print "<h1>Arguments</h1>\n";
858 print "<p>\n";
859 print "<dl>\n";
860 foreach $parameter (@{$args{'parameterlist'}}) {
861 my $parameter_name = $parameter;
862 $parameter_name =~ s/\[.*//;
863
864 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
865 print "<dt>" . $parameter . "</dt>\n";
866 print "<dd>";
867 output_highlight($args{'parameterdescs'}{$parameter_name});
868 print "</dd>\n";
869 }
870 print "</dl>\n";
871 print "</section>\n";
872 output_section_html5(@_);
873 print "</article>\n";
874}
875
876# output DOC: block header in html5
877sub output_blockhead_html5(%) {
878 my %args = %{$_[0]};
879 my ($parameter, $section);
880 my $count;
881 my $html5id;
882
883 foreach $section (@{$args{'sectionlist'}}) {
884 $html5id = $section;
885 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
886 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
887 print "<h1>$section</h1>\n";
888 print "<p>\n";
889 output_highlight($args{'sections'}{$section});
890 print "</p>\n";
891 }
892 print "</article>\n";
893}
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895sub output_section_xml(%) {
896 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800897 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 # print out each section
899 $lineprefix=" ";
900 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700901 print "<refsect1>\n";
902 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700904 print "<informalexample><programlisting>\n";
905 } else {
906 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 }
908 output_highlight($args{'sections'}{$section});
909 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700910 print "</programlisting></informalexample>\n";
911 } else {
912 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
Rich Walkerc73894c2005-05-01 08:59:26 -0700914 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916}
917
918# output function in XML DocBook
919sub output_function_xml(%) {
920 my %args = %{$_[0]};
921 my ($parameter, $section);
922 my $count;
923 my $id;
924
Randy Dunlapb9d973282009-06-09 08:50:38 -0700925 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 $id =~ s/[^A-Za-z0-9]/-/g;
927
Pavel Pisa5449bc92007-02-10 01:45:37 -0800928 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700929 print "<refentryinfo>\n";
930 print " <title>LINUX</title>\n";
931 print " <productname>Kernel Hackers Manual</productname>\n";
932 print " <date>$man_date</date>\n";
933 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700935 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700936 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -0700937 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 print "</refmeta>\n";
939 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700940 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 print " <refpurpose>\n";
942 print " ";
943 output_highlight ($args{'purpose'});
944 print " </refpurpose>\n";
945 print "</refnamediv>\n";
946
947 print "<refsynopsisdiv>\n";
948 print " <title>Synopsis</title>\n";
949 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700950 print " <funcdef>" . $args{'functiontype'} . " ";
951 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
953 $count = 0;
954 if ($#{$args{'parameterlist'}} >= 0) {
955 foreach $parameter (@{$args{'parameterlist'}}) {
956 $type = $args{'parametertypes'}{$parameter};
957 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
958 # pointer-to-function
959 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
960 print " <funcparams>$2</funcparams></paramdef>\n";
961 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700962 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 print " <parameter>$parameter</parameter></paramdef>\n";
964 }
965 }
966 } else {
Martin Waitz6013d542005-05-01 08:59:25 -0700967 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 }
969 print " </funcprototype></funcsynopsis>\n";
970 print "</refsynopsisdiv>\n";
971
972 # print parameters
973 print "<refsect1>\n <title>Arguments</title>\n";
974 if ($#{$args{'parameterlist'}} >= 0) {
975 print " <variablelist>\n";
976 foreach $parameter (@{$args{'parameterlist'}}) {
977 my $parameter_name = $parameter;
978 $parameter_name =~ s/\[.*//;
979
980 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
981 print " <listitem>\n <para>\n";
982 $lineprefix=" ";
983 output_highlight($args{'parameterdescs'}{$parameter_name});
984 print " </para>\n </listitem>\n </varlistentry>\n";
985 }
986 print " </variablelist>\n";
987 } else {
988 print " <para>\n None\n </para>\n";
989 }
990 print "</refsect1>\n";
991
992 output_section_xml(@_);
993 print "</refentry>\n\n";
994}
995
996# output struct in XML DocBook
997sub output_struct_xml(%) {
998 my %args = %{$_[0]};
999 my ($parameter, $section);
1000 my $id;
1001
Randy Dunlapb9d973282009-06-09 08:50:38 -07001002 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 $id =~ s/[^A-Za-z0-9]/-/g;
1004
Pavel Pisa5449bc92007-02-10 01:45:37 -08001005 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001006 print "<refentryinfo>\n";
1007 print " <title>LINUX</title>\n";
1008 print " <productname>Kernel Hackers Manual</productname>\n";
1009 print " <date>$man_date</date>\n";
1010 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001012 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001013 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001014 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 print "</refmeta>\n";
1016 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001017 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 print " <refpurpose>\n";
1019 print " ";
1020 output_highlight ($args{'purpose'});
1021 print " </refpurpose>\n";
1022 print "</refnamediv>\n";
1023
1024 print "<refsynopsisdiv>\n";
1025 print " <title>Synopsis</title>\n";
1026 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001027 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 foreach $parameter (@{$args{'parameterlist'}}) {
1029 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001030 my $prm = $parameter;
1031 # convert data read & converted thru xml_escape() into &xyz; format:
1032 # This allows us to have #define macros interspersed in a struct.
1033 $prm =~ s/\\\\\\/\&/g;
1034 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 next;
1036 }
1037
1038 my $parameter_name = $parameter;
1039 $parameter_name =~ s/\[.*//;
1040
1041 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001042 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 $type = $args{'parametertypes'}{$parameter};
1044 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1045 # pointer-to-function
1046 print " $1 $parameter) ($2);\n";
1047 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001048 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 print " $1 $parameter$2;\n";
1050 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001051 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 }
1053 }
1054 print "};";
1055 print " </programlisting>\n";
1056 print "</refsynopsisdiv>\n";
1057
1058 print " <refsect1>\n";
1059 print " <title>Members</title>\n";
1060
Randy Dunlap39f00c02008-09-22 13:57:44 -07001061 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 print " <variablelist>\n";
1063 foreach $parameter (@{$args{'parameterlist'}}) {
1064 ($parameter =~ /^#/) && next;
1065
1066 my $parameter_name = $parameter;
1067 $parameter_name =~ s/\[.*//;
1068
1069 defined($args{'parameterdescs'}{$parameter_name}) || next;
1070 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1071 print " <varlistentry>";
1072 print " <term>$parameter</term>\n";
1073 print " <listitem><para>\n";
1074 output_highlight($args{'parameterdescs'}{$parameter_name});
1075 print " </para></listitem>\n";
1076 print " </varlistentry>\n";
1077 }
1078 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001079 } else {
1080 print " <para>\n None\n </para>\n";
1081 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 print " </refsect1>\n";
1083
1084 output_section_xml(@_);
1085
1086 print "</refentry>\n\n";
1087}
1088
1089# output enum in XML DocBook
1090sub output_enum_xml(%) {
1091 my %args = %{$_[0]};
1092 my ($parameter, $section);
1093 my $count;
1094 my $id;
1095
Randy Dunlapb9d973282009-06-09 08:50:38 -07001096 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 $id =~ s/[^A-Za-z0-9]/-/g;
1098
Pavel Pisa5449bc92007-02-10 01:45:37 -08001099 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001100 print "<refentryinfo>\n";
1101 print " <title>LINUX</title>\n";
1102 print " <productname>Kernel Hackers Manual</productname>\n";
1103 print " <date>$man_date</date>\n";
1104 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001106 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001107 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001108 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 print "</refmeta>\n";
1110 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001111 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 print " <refpurpose>\n";
1113 print " ";
1114 output_highlight ($args{'purpose'});
1115 print " </refpurpose>\n";
1116 print "</refnamediv>\n";
1117
1118 print "<refsynopsisdiv>\n";
1119 print " <title>Synopsis</title>\n";
1120 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001121 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 $count = 0;
1123 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001124 print " $parameter";
1125 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 $count++;
1127 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 print "\n";
1130 }
1131 print "};";
1132 print " </programlisting>\n";
1133 print "</refsynopsisdiv>\n";
1134
1135 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001136 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 print " <variablelist>\n";
1138 foreach $parameter (@{$args{'parameterlist'}}) {
1139 my $parameter_name = $parameter;
1140 $parameter_name =~ s/\[.*//;
1141
1142 print " <varlistentry>";
1143 print " <term>$parameter</term>\n";
1144 print " <listitem><para>\n";
1145 output_highlight($args{'parameterdescs'}{$parameter_name});
1146 print " </para></listitem>\n";
1147 print " </varlistentry>\n";
1148 }
1149 print " </variablelist>\n";
1150 print "</refsect1>\n";
1151
1152 output_section_xml(@_);
1153
1154 print "</refentry>\n\n";
1155}
1156
1157# output typedef in XML DocBook
1158sub output_typedef_xml(%) {
1159 my %args = %{$_[0]};
1160 my ($parameter, $section);
1161 my $id;
1162
Randy Dunlapb9d973282009-06-09 08:50:38 -07001163 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 $id =~ s/[^A-Za-z0-9]/-/g;
1165
Pavel Pisa5449bc92007-02-10 01:45:37 -08001166 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001167 print "<refentryinfo>\n";
1168 print " <title>LINUX</title>\n";
1169 print " <productname>Kernel Hackers Manual</productname>\n";
1170 print " <date>$man_date</date>\n";
1171 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001173 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001174 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 print "</refmeta>\n";
1176 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001177 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 print " <refpurpose>\n";
1179 print " ";
1180 output_highlight ($args{'purpose'});
1181 print " </refpurpose>\n";
1182 print "</refnamediv>\n";
1183
1184 print "<refsynopsisdiv>\n";
1185 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001186 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 print "</refsynopsisdiv>\n";
1188
1189 output_section_xml(@_);
1190
1191 print "</refentry>\n\n";
1192}
1193
1194# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001195sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 my %args = %{$_[0]};
1197 my ($parameter, $section);
1198 my $count;
1199
1200 my $id = $args{'module'};
1201 $id =~ s/[^A-Za-z0-9]/-/g;
1202
1203 # print out each section
1204 $lineprefix=" ";
1205 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001206 if (!$args{'content-only'}) {
1207 print "<refsect1>\n <title>$section</title>\n";
1208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 if ($section =~ m/EXAMPLE/i) {
1210 print "<example><para>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001211 } else {
1212 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214 output_highlight($args{'sections'}{$section});
1215 if ($section =~ m/EXAMPLE/i) {
1216 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001217 } else {
1218 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001220 if (!$args{'content-only'}) {
1221 print "\n</refsect1>\n";
1222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 }
1224
1225 print "\n\n";
1226}
1227
1228# output in XML DocBook
1229sub output_function_gnome {
1230 my %args = %{$_[0]};
1231 my ($parameter, $section);
1232 my $count;
1233 my $id;
1234
Randy Dunlapb9d973282009-06-09 08:50:38 -07001235 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 $id =~ s/[^A-Za-z0-9]/-/g;
1237
1238 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001239 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001242 print " <funcdef>" . $args{'functiontype'} . " ";
1243 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 print "</function></funcdef>\n";
1245
1246 $count = 0;
1247 if ($#{$args{'parameterlist'}} >= 0) {
1248 foreach $parameter (@{$args{'parameterlist'}}) {
1249 $type = $args{'parametertypes'}{$parameter};
1250 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1251 # pointer-to-function
1252 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1253 print " <funcparams>$2</funcparams></paramdef>\n";
1254 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001255 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 print " <parameter>$parameter</parameter></paramdef>\n";
1257 }
1258 }
1259 } else {
1260 print " <void>\n";
1261 }
1262 print " </funcsynopsis>\n";
1263 if ($#{$args{'parameterlist'}} >= 0) {
1264 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1265 print "<tgroup cols=\"2\">\n";
1266 print "<colspec colwidth=\"2*\">\n";
1267 print "<colspec colwidth=\"8*\">\n";
1268 print "<tbody>\n";
1269 foreach $parameter (@{$args{'parameterlist'}}) {
1270 my $parameter_name = $parameter;
1271 $parameter_name =~ s/\[.*//;
1272
1273 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1274 print " <entry>\n";
1275 $lineprefix=" ";
1276 output_highlight($args{'parameterdescs'}{$parameter_name});
1277 print " </entry></row>\n";
1278 }
1279 print " </tbody></tgroup></informaltable>\n";
1280 } else {
1281 print " <para>\n None\n </para>\n";
1282 }
1283
1284 # print out each section
1285 $lineprefix=" ";
1286 foreach $section (@{$args{'sectionlist'}}) {
1287 print "<simplesect>\n <title>$section</title>\n";
1288 if ($section =~ m/EXAMPLE/i) {
1289 print "<example><programlisting>\n";
1290 } else {
1291 }
1292 print "<para>\n";
1293 output_highlight($args{'sections'}{$section});
1294 print "</para>\n";
1295 if ($section =~ m/EXAMPLE/i) {
1296 print "</programlisting></example>\n";
1297 } else {
1298 }
1299 print " </simplesect>\n";
1300 }
1301
1302 print "</sect2>\n\n";
1303}
1304
1305##
1306# output function in man
1307sub output_function_man(%) {
1308 my %args = %{$_[0]};
1309 my ($parameter, $section);
1310 my $count;
1311
1312 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1313
1314 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001315 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001318 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001319 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001320 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001321 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 $count = 0;
1324 my $parenth = "(";
1325 my $post = ",";
1326 foreach my $parameter (@{$args{'parameterlist'}}) {
1327 if ($count == $#{$args{'parameterlist'}}) {
1328 $post = ");";
1329 }
1330 $type = $args{'parametertypes'}{$parameter};
1331 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1332 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001333 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 } else {
1335 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001336 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338 $count++;
1339 $parenth = "";
1340 }
1341
1342 print ".SH ARGUMENTS\n";
1343 foreach $parameter (@{$args{'parameterlist'}}) {
1344 my $parameter_name = $parameter;
1345 $parameter_name =~ s/\[.*//;
1346
Randy Dunlapb9d973282009-06-09 08:50:38 -07001347 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 output_highlight($args{'parameterdescs'}{$parameter_name});
1349 }
1350 foreach $section (@{$args{'sectionlist'}}) {
1351 print ".SH \"", uc $section, "\"\n";
1352 output_highlight($args{'sections'}{$section});
1353 }
1354}
1355
1356##
1357# output enum in man
1358sub output_enum_man(%) {
1359 my %args = %{$_[0]};
1360 my ($parameter, $section);
1361 my $count;
1362
1363 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1364
1365 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001366 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
1368 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001369 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 $count = 0;
1371 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001372 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if ($count == $#{$args{'parameterlist'}}) {
1374 print "\n};\n";
1375 last;
1376 }
1377 else {
1378 print ", \n.br\n";
1379 }
1380 $count++;
1381 }
1382
1383 print ".SH Constants\n";
1384 foreach $parameter (@{$args{'parameterlist'}}) {
1385 my $parameter_name = $parameter;
1386 $parameter_name =~ s/\[.*//;
1387
Randy Dunlapb9d973282009-06-09 08:50:38 -07001388 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 output_highlight($args{'parameterdescs'}{$parameter_name});
1390 }
1391 foreach $section (@{$args{'sectionlist'}}) {
1392 print ".SH \"$section\"\n";
1393 output_highlight($args{'sections'}{$section});
1394 }
1395}
1396
1397##
1398# output struct in man
1399sub output_struct_man(%) {
1400 my %args = %{$_[0]};
1401 my ($parameter, $section);
1402
Randy Dunlapb9d973282009-06-09 08:50:38 -07001403 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001406 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001409 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 foreach my $parameter (@{$args{'parameterlist'}}) {
1412 if ($parameter =~ /^#/) {
1413 print ".BI \"$parameter\"\n.br\n";
1414 next;
1415 }
1416 my $parameter_name = $parameter;
1417 $parameter_name =~ s/\[.*//;
1418
Randy Dunlap3c308792007-05-08 00:24:39 -07001419 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 $type = $args{'parametertypes'}{$parameter};
1421 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1422 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001423 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001425 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001426 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 } else {
1428 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001429 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431 print "\n.br\n";
1432 }
1433 print "};\n.br\n";
1434
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001435 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 foreach $parameter (@{$args{'parameterlist'}}) {
1437 ($parameter =~ /^#/) && next;
1438
1439 my $parameter_name = $parameter;
1440 $parameter_name =~ s/\[.*//;
1441
Randy Dunlap3c308792007-05-08 00:24:39 -07001442 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001443 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 output_highlight($args{'parameterdescs'}{$parameter_name});
1445 }
1446 foreach $section (@{$args{'sectionlist'}}) {
1447 print ".SH \"$section\"\n";
1448 output_highlight($args{'sections'}{$section});
1449 }
1450}
1451
1452##
1453# output typedef in man
1454sub output_typedef_man(%) {
1455 my %args = %{$_[0]};
1456 my ($parameter, $section);
1457
1458 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1459
1460 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001461 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 foreach $section (@{$args{'sectionlist'}}) {
1464 print ".SH \"$section\"\n";
1465 output_highlight($args{'sections'}{$section});
1466 }
1467}
1468
Johannes Bergb112e0f2007-10-24 15:08:48 -07001469sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 my %args = %{$_[0]};
1471 my ($parameter, $section);
1472 my $count;
1473
1474 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1475
1476 foreach $section (@{$args{'sectionlist'}}) {
1477 print ".SH \"$section\"\n";
1478 output_highlight($args{'sections'}{$section});
1479 }
1480}
1481
1482##
1483# output in text
1484sub output_function_text(%) {
1485 my %args = %{$_[0]};
1486 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001487 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Randy Dunlapf47634b2006-07-01 04:36:36 -07001489 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001490 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001491
1492 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001493 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001494 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001495 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001496 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 my $count = 0;
1501 foreach my $parameter (@{$args{'parameterlist'}}) {
1502 $type = $args{'parametertypes'}{$parameter};
1503 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1504 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001505 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001507 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 }
1509 if ($count != $#{$args{'parameterlist'}}) {
1510 $count++;
1511 print ",\n";
1512 print " " x length($start);
1513 } else {
1514 print ");\n\n";
1515 }
1516 }
1517
1518 print "Arguments:\n\n";
1519 foreach $parameter (@{$args{'parameterlist'}}) {
1520 my $parameter_name = $parameter;
1521 $parameter_name =~ s/\[.*//;
1522
Randy Dunlapb9d973282009-06-09 08:50:38 -07001523 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525 output_section_text(@_);
1526}
1527
1528#output sections in text
1529sub output_section_text(%) {
1530 my %args = %{$_[0]};
1531 my $section;
1532
1533 print "\n";
1534 foreach $section (@{$args{'sectionlist'}}) {
1535 print "$section:\n\n";
1536 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 print "\n\n";
1539}
1540
1541# output enum in text
1542sub output_enum_text(%) {
1543 my %args = %{$_[0]};
1544 my ($parameter);
1545 my $count;
1546 print "Enum:\n\n";
1547
Randy Dunlapb9d973282009-06-09 08:50:38 -07001548 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1549 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 $count = 0;
1551 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001552 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 if ($count != $#{$args{'parameterlist'}}) {
1554 $count++;
1555 print ",";
1556 }
1557 print "\n";
1558 }
1559 print "};\n\n";
1560
1561 print "Constants:\n\n";
1562 foreach $parameter (@{$args{'parameterlist'}}) {
1563 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 }
1566
1567 output_section_text(@_);
1568}
1569
1570# output typedef in text
1571sub output_typedef_text(%) {
1572 my %args = %{$_[0]};
1573 my ($parameter);
1574 my $count;
1575 print "Typedef:\n\n";
1576
Randy Dunlapb9d973282009-06-09 08:50:38 -07001577 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 output_section_text(@_);
1579}
1580
1581# output struct as text
1582sub output_struct_text(%) {
1583 my %args = %{$_[0]};
1584 my ($parameter);
1585
Randy Dunlapb9d973282009-06-09 08:50:38 -07001586 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1587 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 foreach $parameter (@{$args{'parameterlist'}}) {
1589 if ($parameter =~ /^#/) {
1590 print "$parameter\n";
1591 next;
1592 }
1593
1594 my $parameter_name = $parameter;
1595 $parameter_name =~ s/\[.*//;
1596
Randy Dunlap3c308792007-05-08 00:24:39 -07001597 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 $type = $args{'parametertypes'}{$parameter};
1599 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1600 # pointer-to-function
1601 print "\t$1 $parameter) ($2);\n";
1602 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001603 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 print "\t$1 $parameter$2;\n";
1605 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001606 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
1608 }
1609 print "};\n\n";
1610
1611 print "Members:\n\n";
1612 foreach $parameter (@{$args{'parameterlist'}}) {
1613 ($parameter =~ /^#/) && next;
1614
1615 my $parameter_name = $parameter;
1616 $parameter_name =~ s/\[.*//;
1617
Randy Dunlap3c308792007-05-08 00:24:39 -07001618 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001620 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 }
1622 print "\n";
1623 output_section_text(@_);
1624}
1625
Johannes Bergb112e0f2007-10-24 15:08:48 -07001626sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 my %args = %{$_[0]};
1628 my ($parameter, $section);
1629
1630 foreach $section (@{$args{'sectionlist'}}) {
1631 print " $section:\n";
1632 print " -> ";
1633 output_highlight($args{'sections'}{$section});
1634 }
1635}
1636
Johannes Bergeda603f2010-09-11 15:55:22 -07001637## list mode output functions
1638
1639sub output_function_list(%) {
1640 my %args = %{$_[0]};
1641
1642 print $args{'function'} . "\n";
1643}
1644
1645# output enum in list
1646sub output_enum_list(%) {
1647 my %args = %{$_[0]};
1648 print $args{'enum'} . "\n";
1649}
1650
1651# output typedef in list
1652sub output_typedef_list(%) {
1653 my %args = %{$_[0]};
1654 print $args{'typedef'} . "\n";
1655}
1656
1657# output struct as list
1658sub output_struct_list(%) {
1659 my %args = %{$_[0]};
1660
1661 print $args{'struct'} . "\n";
1662}
1663
1664sub output_blockhead_list(%) {
1665 my %args = %{$_[0]};
1666 my ($parameter, $section);
1667
1668 foreach $section (@{$args{'sectionlist'}}) {
1669 print "DOC: $section\n";
1670 }
1671}
1672
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673##
Randy Dunlap27205742006-10-11 01:22:12 -07001674# generic output function for all types (function, struct/union, typedef, enum);
1675# calls the generated, variable output_ function name based on
1676# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677sub output_declaration {
1678 no strict 'refs';
1679 my $name = shift;
1680 my $functype = shift;
1681 my $func = "output_${functype}_$output_mode";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001682 if (($function_only==0) ||
1683 ( $function_only == 1 && defined($function_table{$name})) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 ( $function_only == 2 && !defined($function_table{$name})))
1685 {
Randy Dunlap3c308792007-05-08 00:24:39 -07001686 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 $section_counter++;
1688 }
1689}
1690
1691##
Randy Dunlap27205742006-10-11 01:22:12 -07001692# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07001693sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07001695 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 &$func(@_);
1697 $section_counter++;
1698}
1699
1700##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001701# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702# invokes the right handler. NOT called for functions.
1703sub dump_declaration($$) {
1704 no strict 'refs';
1705 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001706 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 &$func(@_);
1708}
1709
1710sub dump_union($$) {
1711 dump_struct(@_);
1712}
1713
1714sub dump_struct($$) {
1715 my $x = shift;
1716 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001717 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07001719 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1720 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07001721 $declaration_name = $2;
1722 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001725 $members =~ s/({.*})//g;
1726 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Martin Waitzaeec46b2005-11-13 16:08:13 -08001728 # ignore members marked private:
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07001729 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
1730 $members =~ s/\/\*\s*private:.*//gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001731 # strip comments:
1732 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001733 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07001734 # strip kmemcheck_bitfield_{begin,end}.*;
1735 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07001736 # strip attributes
1737 $members =~ s/__aligned\s*\(\d+\)//gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001740 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742 output_declaration($declaration_name,
1743 'struct',
1744 {'struct' => $declaration_name,
1745 'module' => $modulename,
1746 'parameterlist' => \@parameterlist,
1747 'parameterdescs' => \%parameterdescs,
1748 'parametertypes' => \%parametertypes,
1749 'sectionlist' => \@sectionlist,
1750 'sections' => \%sections,
1751 'purpose' => $declaration_purpose,
1752 'type' => $decl_type
1753 });
1754 }
1755 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001756 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 ++$errors;
1758 }
1759}
1760
1761sub dump_enum($$) {
1762 my $x = shift;
1763 my $file = shift;
1764
Martin Waitzaeec46b2005-11-13 16:08:13 -08001765 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Randy Dunlapb6d676d2010-08-10 18:02:50 -07001766 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001769 $declaration_name = $1;
1770 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 foreach my $arg (split ',', $members) {
1773 $arg =~ s/^\s*(\w+).*/$1/;
1774 push @parameterlist, $arg;
1775 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001776 $parameterdescs{$arg} = $undescribed;
1777 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 "not described in enum '$declaration_name'\n";
1779 }
1780
1781 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 output_declaration($declaration_name,
1784 'enum',
1785 {'enum' => $declaration_name,
1786 'module' => $modulename,
1787 'parameterlist' => \@parameterlist,
1788 'parameterdescs' => \%parameterdescs,
1789 'sectionlist' => \@sectionlist,
1790 'sections' => \%sections,
1791 'purpose' => $declaration_purpose
1792 });
1793 }
1794 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001795 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 ++$errors;
1797 }
1798}
1799
1800sub dump_typedef($$) {
1801 my $x = shift;
1802 my $file = shift;
1803
Martin Waitzaeec46b2005-11-13 16:08:13 -08001804 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001806 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 $x =~ s/\[*.\]\s*;$/;/;
1808 }
1809
1810 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001811 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
1813 output_declaration($declaration_name,
1814 'typedef',
1815 {'typedef' => $declaration_name,
1816 'module' => $modulename,
1817 'sectionlist' => \@sectionlist,
1818 'sections' => \%sections,
1819 'purpose' => $declaration_purpose
1820 });
1821 }
1822 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001823 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 ++$errors;
1825 }
1826}
1827
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001828sub save_struct_actual($) {
1829 my $actual = shift;
1830
1831 # strip all spaces from the actual param so that it looks like one string item
1832 $actual =~ s/\s*//g;
1833 $struct_actual = $struct_actual . $actual . " ";
1834}
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836sub create_parameterlist($$$) {
1837 my $args = shift;
1838 my $splitter = shift;
1839 my $file = shift;
1840 my $type;
1841 my $param;
1842
Martin Waitza6d3fe72006-01-09 20:53:55 -08001843 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001845 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 foreach my $arg (split($splitter, $args)) {
1849 # strip comments
1850 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07001851 # strip leading/trailing spaces
1852 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 $arg =~ s/\s*$//;
1854 $arg =~ s/\s+/ /;
1855
1856 if ($arg =~ /^#/) {
1857 # Treat preprocessor directive as a typeless variable just to fill
1858 # corresponding data structures "correctly". Catch it later in
1859 # output_* subs.
1860 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08001861 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 # pointer-to-function
1863 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08001864 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 $param = $1;
1866 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08001867 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001868 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08001870 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 $arg =~ s/\s*:\s*/:/g;
1872 $arg =~ s/\s*\[/\[/g;
1873
1874 my @args = split('\s*,\s*', $arg);
1875 if ($args[0] =~ m/\*/) {
1876 $args[0] =~ s/(\*+)\s*/ $1/;
1877 }
Borislav Petkov884f2812007-05-08 00:29:05 -07001878
1879 my @first_arg;
1880 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1881 shift @args;
1882 push(@first_arg, split('\s+', $1));
1883 push(@first_arg, $2);
1884 } else {
1885 @first_arg = split('\s+', shift @args);
1886 }
1887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 unshift(@args, pop @first_arg);
1889 $type = join " ", @first_arg;
1890
1891 foreach $param (@args) {
1892 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001893 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 push_parameter($2, "$type $1", $file);
1895 }
1896 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07001897 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001898 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07001899 push_parameter($1, "$type:$2", $file)
1900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 }
1902 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001903 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 push_parameter($param, $type, $file);
1905 }
1906 }
1907 }
1908 }
1909}
1910
1911sub push_parameter($$$) {
1912 my $param = shift;
1913 my $type = shift;
1914 my $file = shift;
1915
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001916 if (($anon_struct_union == 1) && ($type eq "") &&
1917 ($param eq "}")) {
1918 return; # ignore the ending }; from anon. struct/union
1919 }
1920
1921 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 my $param_name = $param;
1923 $param_name =~ s/\[.*//;
1924
Martin Waitza6d3fe72006-01-09 20:53:55 -08001925 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 {
Randy Dunlapced69092008-12-01 13:14:03 -08001927 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1928 $parameterdescs{$param} = "variable arguments";
1929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 }
1931 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1932 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 $param="void";
1934 $parameterdescs{void} = "no arguments";
1935 }
Randy Dunlap134fe012006-12-22 01:10:50 -08001936 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1937 # handle unnamed (anonymous) union or struct:
1938 {
1939 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001940 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08001941 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001942 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08001943 }
1944
Martin Waitza6d3fe72006-01-09 20:53:55 -08001945 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08001946 # (but ignore ones starting with # as these are not parameters
1947 # but inline preprocessor statements);
1948 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001949 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08001950 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1951
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 $parameterdescs{$param_name} = $undescribed;
1953
1954 if (($type eq 'function') || ($type eq 'enum')) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001955 print STDERR "Warning(${file}:$.): Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 "or member '$param' not " .
1957 "described in '$declaration_name'\n";
1958 }
Randy Dunlapb9d973282009-06-09 08:50:38 -07001959 print STDERR "Warning(${file}:$.):" .
Randy Dunlap3c308792007-05-08 00:24:39 -07001960 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07001962 }
1963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001965 $param = xml_escape($param);
1966
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001967 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07001968 # on @parameterlist;
1969 # this fixes a problem where check_sections() cannot find
1970 # a parameter like "addr[6 + 2]" because it actually appears
1971 # as "addr[6", "+", "2]" on the parameter list;
1972 # but it's better to maintain the param string unchanged for output,
1973 # so just weaken the string compare in check_sections() to ignore
1974 # "[blah" in a parameter string;
1975 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 push @parameterlist, $param;
1977 $parametertypes{$param} = $type;
1978}
1979
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001980sub check_sections($$$$$$) {
1981 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1982 my @sects = split ' ', $sectcheck;
1983 my @prms = split ' ', $prmscheck;
1984 my $err;
1985 my ($px, $sx);
1986 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1987
1988 foreach $sx (0 .. $#sects) {
1989 $err = 1;
1990 foreach $px (0 .. $#prms) {
1991 $prm_clean = $prms[$px];
1992 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07001993 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07001994 # ignore array size in a parameter string;
1995 # however, the original param string may contain
1996 # spaces, e.g.: addr[6 + 2]
1997 # and this appears in @prms as "addr[6" since the
1998 # parameter list is split at spaces;
1999 # hence just ignore "[..." for the sections check;
2000 $prm_clean =~ s/\[.*//;
2001
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002002 ##$prm_clean =~ s/^\**//;
2003 if ($prm_clean eq $sects[$sx]) {
2004 $err = 0;
2005 last;
2006 }
2007 }
2008 if ($err) {
2009 if ($decl_type eq "function") {
2010 print STDERR "Warning(${file}:$.): " .
2011 "Excess function parameter " .
2012 "'$sects[$sx]' " .
2013 "description in '$decl_name'\n";
2014 ++$warnings;
2015 } else {
2016 if ($nested !~ m/\Q$sects[$sx]\E/) {
2017 print STDERR "Warning(${file}:$.): " .
2018 "Excess struct/union/enum/typedef member " .
2019 "'$sects[$sx]' " .
2020 "description in '$decl_name'\n";
2021 ++$warnings;
2022 }
2023 }
2024 }
2025 }
2026}
2027
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028##
2029# takes a function prototype and the name of the current file being
2030# processed and spits out all the details stored in the global
2031# arrays/hashes.
2032sub dump_function($$) {
2033 my $prototype = shift;
2034 my $file = shift;
2035
2036 $prototype =~ s/^static +//;
2037 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002038 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 $prototype =~ s/^inline +//;
2040 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002041 $prototype =~ s/^__inline +//;
2042 $prototype =~ s/^__always_inline +//;
2043 $prototype =~ s/^noinline +//;
Randy Dunlap0129a052006-07-30 03:03:41 -07002044 $prototype =~ s/__devinit +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002045 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002046 $prototype =~ s/__init_or_module +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002047 $prototype =~ s/__must_check +//;
Randy Dunlap890c78c2008-10-25 17:06:43 -07002048 $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002049 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 # Yes, this truly is vile. We are looking for:
2052 # 1. Return type (may be nothing if we're looking at a macro)
2053 # 2. Function name
2054 # 3. Function parameters.
2055 #
2056 # All the while we have to watch out for function pointer parameters
2057 # (which IIRC is what the two sections are for), C types (these
2058 # regexps don't even start to express all the possibilities), and
2059 # so on.
2060 #
2061 # If you mess with these regexps, it's a good idea to check that
2062 # the following functions' documentation still comes out right:
2063 # - parport_register_device (function pointer parameters)
2064 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002065 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
2067 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2068 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2069 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2070 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002071 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2073 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2074 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2075 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2076 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2077 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2078 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2079 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002080 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2081 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002082 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2083 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 $return_type = $1;
2085 $declaration_name = $2;
2086 my $args = $3;
2087
2088 create_parameterlist($args, ',', $file);
2089 } else {
2090 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
2091 ++$errors;
2092 return;
2093 }
2094
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002095 my $prms = join " ", @parameterlist;
2096 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2097
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002098 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 'function',
2100 {'function' => $declaration_name,
2101 'module' => $modulename,
2102 'functiontype' => $return_type,
2103 'parameterlist' => \@parameterlist,
2104 'parameterdescs' => \%parameterdescs,
2105 'parametertypes' => \%parametertypes,
2106 'sectionlist' => \@sectionlist,
2107 'sections' => \%sections,
2108 'purpose' => $declaration_purpose
2109 });
2110}
2111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112sub reset_state {
2113 $function = "";
2114 %constants = ();
2115 %parameterdescs = ();
2116 %parametertypes = ();
2117 @parameterlist = ();
2118 %sections = ();
2119 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002120 $sectcheck = "";
2121 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 $state = 0;
2125}
2126
Jason Baron56afb0f2009-04-30 13:29:36 -04002127sub tracepoint_munge($) {
2128 my $file = shift;
2129 my $tracepointname = 0;
2130 my $tracepointargs = 0;
2131
Jason Baron3a9089f2009-12-01 12:18:49 -05002132 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002133 $tracepointname = $1;
2134 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002135 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2136 $tracepointname = $1;
2137 }
2138 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2139 $tracepointname = $2;
2140 }
2141 $tracepointname =~ s/^\s+//; #strip leading whitespace
2142 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002143 $tracepointargs = $1;
2144 }
2145 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
2146 print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
2147 "$prototype\n";
2148 } else {
2149 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2150 }
2151}
2152
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002153sub syscall_munge() {
2154 my $void = 0;
2155
2156 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2157## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2158 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2159 $void = 1;
2160## $prototype = "long sys_$1(void)";
2161 }
2162
2163 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2164 if ($prototype =~ m/long (sys_.*?),/) {
2165 $prototype =~ s/,/\(/;
2166 } elsif ($void) {
2167 $prototype =~ s/\)/\(void\)/;
2168 }
2169
2170 # now delete all of the odd-number commas in $prototype
2171 # so that arg types & arg names don't have a comma between them
2172 my $count = 0;
2173 my $len = length($prototype);
2174 if ($void) {
2175 $len = 0; # skip the for-loop
2176 }
2177 for (my $ix = 0; $ix < $len; $ix++) {
2178 if (substr($prototype, $ix, 1) eq ',') {
2179 $count++;
2180 if ($count % 2 == 1) {
2181 substr($prototype, $ix, 1) = ' ';
2182 }
2183 }
2184 }
2185}
2186
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002187sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 my $x = shift;
2189 my $file = shift;
2190
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002191 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2192
Randy Dunlap890c78c2008-10-25 17:06:43 -07002193 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 # do nothing
2195 }
2196 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002197 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002199
Randy Dunlap890c78c2008-10-25 17:06:43 -07002200 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002201 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2203 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002204 if ($prototype =~ /SYSCALL_DEFINE/) {
2205 syscall_munge();
2206 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002207 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2208 $prototype =~ /DEFINE_SINGLE_EVENT/)
2209 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002210 tracepoint_munge($file);
2211 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002212 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 reset_state();
2214 }
2215}
2216
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002217sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 my $x = shift;
2219 my $file = shift;
2220
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2222 $x =~ s@^\s+@@gos; # strip leading spaces
2223 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002224 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2225
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 if ($x =~ /^#/) {
2227 # To distinguish preprocessor directive from regular declaration later.
2228 $x .= ";";
2229 }
2230
2231 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002232 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 $prototype .= $1 . $2;
2234 ($2 eq '{') && $brcount++;
2235 ($2 eq '}') && $brcount--;
2236 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002237 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002239 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 }
2241 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002242 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 $prototype .= $x;
2244 last;
2245 }
2246 }
2247}
2248
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002249# xml_escape: replace <, >, and & in the text stream;
2250#
2251# however, formatting controls that are generated internally/locally in the
2252# kernel-doc script are not escaped here; instead, they begin life like
2253# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2254# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2255# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256sub xml_escape($) {
2257 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002258 if (($output_mode eq "text") || ($output_mode eq "man")) {
2259 return $text;
2260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 $text =~ s/\&/\\\\\\amp;/g;
2262 $text =~ s/\</\\\\\\lt;/g;
2263 $text =~ s/\>/\\\\\\gt;/g;
2264 return $text;
2265}
2266
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002267# convert local escape strings to html
2268# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2269sub local_unescape($) {
2270 my $text = shift;
2271 if (($output_mode eq "text") || ($output_mode eq "man")) {
2272 return $text;
2273 }
2274 $text =~ s/\\\\\\\\lt:/</g;
2275 $text =~ s/\\\\\\\\gt:/>/g;
2276 return $text;
2277}
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002280 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 my $identifier;
2282 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002283 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002284 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 my $initial_section_counter = $section_counter;
2286
Randy Dunlap2283a112005-07-07 15:39:26 -07002287 if (defined($ENV{'SRCTREE'})) {
2288 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2289 }
2290 else {
2291 $file = "@_";
2292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 if (defined($source_map{$file})) {
2294 $file = $source_map{$file};
2295 }
2296
2297 if (!open(IN,"<$file")) {
2298 print STDERR "Error: Cannot open file $file\n";
2299 ++$errors;
2300 return;
2301 }
2302
Ilya Dryomova9e73142010-02-26 13:05:47 -08002303 $. = 1;
2304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 $section_counter = 0;
2306 while (<IN>) {
2307 if ($state == 0) {
2308 if (/$doc_start/o) {
2309 $state = 1; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002310 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312 } elsif ($state == 1) { # this line is the function name (always)
2313 if (/$doc_block/o) {
2314 $state = 4;
2315 $contents = "";
2316 if ( $1 eq "" ) {
2317 $section = $section_intro;
2318 } else {
2319 $section = $1;
2320 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 elsif (/$doc_decl/o) {
2323 $identifier = $1;
2324 if (/\s*([\w\s]+?)\s*-/) {
2325 $identifier = $1;
2326 }
2327
2328 $state = 2;
2329 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002330 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002331 $descr= $1;
2332 $descr =~ s/^\s*//;
2333 $descr =~ s/\s*$//;
2334 $descr =~ s/\s+/ /;
2335 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002336 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 } else {
2338 $declaration_purpose = "";
2339 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002340
2341 if (($declaration_purpose eq "") && $verbose) {
2342 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
2343 print STDERR $_;
2344 ++$warnings;
2345 }
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 if ($identifier =~ m/^struct/) {
2348 $decl_type = 'struct';
2349 } elsif ($identifier =~ m/^union/) {
2350 $decl_type = 'union';
2351 } elsif ($identifier =~ m/^enum/) {
2352 $decl_type = 'enum';
2353 } elsif ($identifier =~ m/^typedef/) {
2354 $decl_type = 'typedef';
2355 } else {
2356 $decl_type = 'function';
2357 }
2358
2359 if ($verbose) {
2360 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
2361 }
2362 } else {
2363 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
2364 " - I thought it was a doc line\n";
2365 ++$warnings;
2366 $state = 0;
2367 }
2368 } elsif ($state == 2) { # look for head: lines, and include content
2369 if (/$doc_sect/o) {
2370 $newsection = $1;
2371 $newcontents = $2;
2372
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002373 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002374 if (!$in_doc_sect && $verbose) {
2375 print STDERR "Warning(${file}:$.): contents before sections\n";
2376 ++$warnings;
2377 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002378 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 $section = $section_default;
2380 }
2381
Randy Dunlap850622d2006-06-25 05:48:55 -07002382 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002383 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 $contents = $newcontents;
2385 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002386 while ((substr($contents, 0, 1) eq " ") ||
2387 substr($contents, 0, 1) eq "\t") {
2388 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 $contents .= "\n";
2391 }
2392 $section = $newsection;
2393 } elsif (/$doc_end/) {
2394
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002395 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002396 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 $section = $section_default;
2398 $contents = "";
2399 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002400 # look for doc_com + <text> + doc_end:
2401 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2402 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
2403 ++$warnings;
2404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
2406 $prototype = "";
2407 $state = 3;
2408 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002409# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 } elsif (/$doc_content/) {
2411 # miguel-style comment kludge, look for blank lines after
2412 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002413 if ($1 eq "") {
2414 if ($section =~ m/^@/ || $section eq $section_context) {
2415 dump_section($file, $section, xml_escape($contents));
2416 $section = $section_default;
2417 $contents = "";
2418 } else {
2419 $contents .= "\n";
2420 }
2421 $in_purpose = 0;
2422 } elsif ($in_purpose == 1) {
2423 # Continued declaration purpose
2424 chomp($declaration_purpose);
2425 $declaration_purpose .= " " . xml_escape($1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002427 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
2429 } else {
2430 # i dont know - bad line? ignore.
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002431 print STDERR "Warning(${file}:$.): bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 ++$warnings;
2433 }
Randy Dunlap232acbc2006-06-25 05:47:48 -07002434 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 if ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002436 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002438 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 }
2440 } elsif ($state == 4) {
2441 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002442 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002443 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 $contents = "";
2445 $function = "";
2446 %constants = ();
2447 %parameterdescs = ();
2448 %parametertypes = ();
2449 @parameterlist = ();
2450 %sections = ();
2451 @sectionlist = ();
2452 $prototype = "";
2453 if ( $1 eq "" ) {
2454 $section = $section_intro;
2455 } else {
2456 $section = $1;
2457 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 elsif (/$doc_end/)
2460 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002461 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 $contents = "";
2463 $function = "";
2464 %constants = ();
2465 %parameterdescs = ();
2466 %parametertypes = ();
2467 @parameterlist = ();
2468 %sections = ();
2469 @sectionlist = ();
2470 $prototype = "";
2471 $state = 0;
2472 }
2473 elsif (/$doc_content/)
2474 {
2475 if ( $1 eq "" )
2476 {
2477 $contents .= $blankline;
2478 }
2479 else
2480 {
2481 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002482 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002483 }
2484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 }
2486 if ($initial_section_counter == $section_counter) {
2487 print STDERR "Warning(${file}): no structured comments found\n";
2488 if ($output_mode eq "xml") {
2489 # The template wants at least one RefEntry here; make one.
2490 print "<refentry>\n";
2491 print " <refnamediv>\n";
2492 print " <refname>\n";
2493 print " ${file}\n";
2494 print " </refname>\n";
2495 print " <refpurpose>\n";
2496 print " Document generation inconsistency\n";
2497 print " </refpurpose>\n";
2498 print " </refnamediv>\n";
2499 print " <refsect1>\n";
2500 print " <title>\n";
2501 print " Oops\n";
2502 print " </title>\n";
2503 print " <warning>\n";
2504 print " <para>\n";
2505 print " The template for this document tried to insert\n";
2506 print " the structured comment from the file\n";
2507 print " <filename>${file}</filename> at this point,\n";
2508 print " but none was found.\n";
2509 print " This dummy section is inserted to allow\n";
2510 print " generation to continue.\n";
2511 print " </para>\n";
2512 print " </warning>\n";
2513 print " </refsect1>\n";
2514 print "</refentry>\n";
2515 }
2516 }
2517}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002518
2519
2520$kernelversion = get_kernel_version();
2521
2522# generate a sequence of code that will splice in highlighting information
2523# using the s// operator.
2524foreach my $pattern (keys %highlights) {
2525# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2526 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2527}
2528
2529# Read the file that maps relative names to absolute names for
2530# separate source and object directories and for shadow trees.
2531if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2532 my ($relname, $absname);
2533 while(<SOURCE_MAP>) {
2534 chop();
2535 ($relname, $absname) = (split())[0..1];
2536 $relname =~ s:^/+::;
2537 $source_map{$relname} = $absname;
2538 }
2539 close(SOURCE_MAP);
2540}
2541
2542foreach (@ARGV) {
2543 chomp;
2544 process_file($_);
2545}
2546if ($verbose && $errors) {
2547 print STDERR "$errors errors\n";
2548}
2549if ($verbose && $warnings) {
2550 print STDERR "$warnings warnings\n";
2551}
2552
2553exit($errors);