blob: 46e7aff80d1a8d1b2ea054d1febc0e8ce0404c35 [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";
Daniel Santose314ba32012-10-04 17:15:08 -0700248my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700249my $no_doc_sections = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250my %highlights = %highlights_man;
251my $blankline = $blankline_man;
252my $modulename = "Kernel API";
253my $function_only = 0;
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800254my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
255 'July', 'August', 'September', 'October',
256 'November', 'December')[(localtime)[4]] .
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 " " . ((localtime)[5]+1900);
258
Randy Dunlap8484baa2011-01-05 16:28:43 -0800259# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700260# They probably want to be tidied up, made more localised or something.
261# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700263my ($function, %function_table, %parametertypes, $declaration_purpose);
264my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800265my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700267if (defined($ENV{'KBUILD_VERBOSE'})) {
268 $verbose = "$ENV{'KBUILD_VERBOSE'}";
269}
270
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800271# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
273# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
274# We keep track of number of generated entries and generate a dummy
275# if needs be to ensure the expanded template can be postprocessed
276# into html.
277my $section_counter = 0;
278
279my $lineprefix="";
280
281# states
282# 0 - normal code
283# 1 - looking for function name
284# 2 - scanning field start.
285# 3 - scanning prototype.
286# 4 - documentation block
287my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700288my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290#declaration types: can be
291# 'function', 'struct', 'union', 'enum', 'typedef'
292my $decl_type;
293
294my $doc_special = "\@\%\$\&";
295
296my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
297my $doc_end = '\*/';
298my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700299my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700300my $doc_decl = $doc_com . '(\w+)';
301my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700302my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700303my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305my %constants;
306my %parameterdescs;
307my @parameterlist;
308my %sections;
309my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800310my $sectcheck;
311my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313my $contents = "";
314my $section_default = "Description"; # default section
315my $section_intro = "Introduction";
316my $section = $section_default;
317my $section_context = "Context";
318
319my $undescribed = "-- undescribed --";
320
321reset_state();
322
323while ($ARGV[0] =~ m/^-(.*)/) {
324 my $cmd = shift @ARGV;
325 if ($cmd eq "-html") {
326 $output_mode = "html";
327 %highlights = %highlights_html;
328 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200329 } elsif ($cmd eq "-html5") {
330 $output_mode = "html5";
331 %highlights = %highlights_html5;
332 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 } elsif ($cmd eq "-man") {
334 $output_mode = "man";
335 %highlights = %highlights_man;
336 $blankline = $blankline_man;
337 } elsif ($cmd eq "-text") {
338 $output_mode = "text";
339 %highlights = %highlights_text;
340 $blankline = $blankline_text;
341 } elsif ($cmd eq "-docbook") {
342 $output_mode = "xml";
343 %highlights = %highlights_xml;
344 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700345 } elsif ($cmd eq "-list") {
346 $output_mode = "list";
347 %highlights = %highlights_list;
348 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 } elsif ($cmd eq "-gnome") {
350 $output_mode = "gnome";
351 %highlights = %highlights_gnome;
352 $blankline = $blankline_gnome;
353 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
354 $modulename = shift @ARGV;
355 } elsif ($cmd eq "-function") { # to only output specific functions
356 $function_only = 1;
357 $function = shift @ARGV;
358 $function_table{$function} = 1;
359 } elsif ($cmd eq "-nofunction") { # to only output specific functions
360 $function_only = 2;
361 $function = shift @ARGV;
362 $function_table{$function} = 1;
363 } elsif ($cmd eq "-v") {
364 $verbose = 1;
365 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
366 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700367 } elsif ($cmd eq '-no-doc-sections') {
368 $no_doc_sections = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370}
371
Randy Dunlap8484baa2011-01-05 16:28:43 -0800372# continue execution near EOF;
373
374sub usage {
Dan Luedtke1b40c192012-08-12 10:46:15 +0200375 print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -0800376 print " [ -no-doc-sections ]\n";
377 print " [ -function funcname [ -function funcname ...] ]\n";
378 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
Dan Luedtke1b40c192012-08-12 10:46:15 +0200379 print " [ -v ]\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -0800380 print " c source file(s) > outputfile\n";
381 print " -v : verbose output, more warnings & other info listed\n";
382 exit 1;
383}
384
Borislav Petkov53f049f2007-05-08 00:30:54 -0700385# get kernel version from env
386sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700387 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700388
389 if (defined($ENV{'KERNELVERSION'})) {
390 $version = $ENV{'KERNELVERSION'};
391 }
392 return $version;
393}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395##
396# dumps section contents to arrays/hashes intended for that purpose.
397#
398sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700399 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 my $name = shift;
401 my $contents = join "\n", @_;
402
403 if ($name =~ m/$type_constant/) {
404 $name = $1;
405# print STDERR "constant section '$1' = '$contents'\n";
406 $constants{$name} = $contents;
407 } elsif ($name =~ m/$type_param/) {
408# print STDERR "parameter def '$1' = '$contents'\n";
409 $name = $1;
410 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800411 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800412 } elsif ($name eq "@\.\.\.") {
413# print STDERR "parameter def '...' = '$contents'\n";
414 $name = "...";
415 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800416 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 } else {
418# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700419 if (defined($sections{$name}) && ($sections{$name} ne "")) {
420 print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
421 ++$errors;
422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 $sections{$name} = $contents;
424 push @sectionlist, $name;
425 }
426}
427
428##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700429# dump DOC: section after checking that it should go out
430#
431sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700432 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700433 my $name = shift;
434 my $contents = join "\n", @_;
435
Johannes Berg4b445952007-10-24 15:08:48 -0700436 if ($no_doc_sections) {
437 return;
438 }
439
Johannes Bergb112e0f2007-10-24 15:08:48 -0700440 if (($function_only == 0) ||
441 ( $function_only == 1 && defined($function_table{$name})) ||
442 ( $function_only == 2 && !defined($function_table{$name})))
443 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700444 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700445 output_blockhead({'sectionlist' => \@sectionlist,
446 'sections' => \%sections,
447 'module' => $modulename,
448 'content-only' => ($function_only != 0), });
449 }
450}
451
452##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453# output function
454#
455# parameterdescs, a hash.
456# function => "function name"
457# parameterlist => @list of parameters
458# parameterdescs => %parameter descriptions
459# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800460# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800461#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463sub output_highlight {
464 my $contents = join "\n",@_;
465 my $line;
466
467# DEBUG
468# if (!defined $contents) {
469# use Carp;
470# confess "output_highlight got called with no args?\n";
471# }
472
Dan Luedtke1b40c192012-08-12 10:46:15 +0200473 if ($output_mode eq "html" || $output_mode eq "html5" ||
474 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700475 $contents = local_unescape($contents);
476 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800477 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700478 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700479# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 eval $dohighlight;
481 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700482# print STDERR "contents af:$contents\n";
483
Dan Luedtke1b40c192012-08-12 10:46:15 +0200484# strip whitespaces when generating html5
485 if ($output_mode eq "html5") {
486 $contents =~ s/^\s+//;
487 $contents =~ s/\s+$//;
488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700490 if (! $output_preformatted) {
491 $line =~ s/^\s*//;
492 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700493 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700494 if (! $output_preformatted) {
495 print $lineprefix, local_unescape($blankline);
496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700498 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700499 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
500 print "\\&$line";
501 } else {
502 print $lineprefix, $line;
503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505 print "\n";
506 }
507}
508
Dan Luedtke1b40c192012-08-12 10:46:15 +0200509# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510sub output_section_html(%) {
511 my %args = %{$_[0]};
512 my $section;
513
514 foreach $section (@{$args{'sectionlist'}}) {
515 print "<h3>$section</h3>\n";
516 print "<blockquote>\n";
517 output_highlight($args{'sections'}{$section});
518 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
522# output enum in html
523sub output_enum_html(%) {
524 my %args = %{$_[0]};
525 my ($parameter);
526 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700527 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Randy Dunlapb9d973282009-06-09 08:50:38 -0700529 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 $count = 0;
531 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700532 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if ($count != $#{$args{'parameterlist'}}) {
534 $count++;
535 print ",\n";
536 }
537 print "<br>";
538 }
539 print "};<br>\n";
540
541 print "<h3>Constants</h3>\n";
542 print "<dl>\n";
543 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700544 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 print "<dd>";
546 output_highlight($args{'parameterdescs'}{$parameter});
547 }
548 print "</dl>\n";
549 output_section_html(@_);
550 print "<hr>\n";
551}
552
Randy Dunlapd28bee02006-02-01 03:06:57 -0800553# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554sub output_typedef_html(%) {
555 my %args = %{$_[0]};
556 my ($parameter);
557 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700558 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Randy Dunlapb9d973282009-06-09 08:50:38 -0700560 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 output_section_html(@_);
562 print "<hr>\n";
563}
564
565# output struct in html
566sub output_struct_html(%) {
567 my %args = %{$_[0]};
568 my ($parameter);
569
Randy Dunlapb9d973282009-06-09 08:50:38 -0700570 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
571 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 foreach $parameter (@{$args{'parameterlist'}}) {
573 if ($parameter =~ /^#/) {
574 print "$parameter<br>\n";
575 next;
576 }
577 my $parameter_name = $parameter;
578 $parameter_name =~ s/\[.*//;
579
Randy Dunlap3c308792007-05-08 00:24:39 -0700580 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 $type = $args{'parametertypes'}{$parameter};
582 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
583 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700584 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700586 # bitfield
587 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700589 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
591 }
592 print "};<br>\n";
593
594 print "<h3>Members</h3>\n";
595 print "<dl>\n";
596 foreach $parameter (@{$args{'parameterlist'}}) {
597 ($parameter =~ /^#/) && next;
598
599 my $parameter_name = $parameter;
600 $parameter_name =~ s/\[.*//;
601
Randy Dunlap3c308792007-05-08 00:24:39 -0700602 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700603 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 print "<dd>";
605 output_highlight($args{'parameterdescs'}{$parameter_name});
606 }
607 print "</dl>\n";
608 output_section_html(@_);
609 print "<hr>\n";
610}
611
612# output function in html
613sub output_function_html(%) {
614 my %args = %{$_[0]};
615 my ($parameter, $section);
616 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Randy Dunlapb9d973282009-06-09 08:50:38 -0700618 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
619 print "<i>" . $args{'functiontype'} . "</i>\n";
620 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 print "(";
622 $count = 0;
623 foreach $parameter (@{$args{'parameterlist'}}) {
624 $type = $args{'parametertypes'}{$parameter};
625 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
626 # pointer-to-function
627 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
628 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700629 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631 if ($count != $#{$args{'parameterlist'}}) {
632 $count++;
633 print ",\n";
634 }
635 }
636 print ")\n";
637
638 print "<h3>Arguments</h3>\n";
639 print "<dl>\n";
640 foreach $parameter (@{$args{'parameterlist'}}) {
641 my $parameter_name = $parameter;
642 $parameter_name =~ s/\[.*//;
643
Randy Dunlap3c308792007-05-08 00:24:39 -0700644 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700645 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 print "<dd>";
647 output_highlight($args{'parameterdescs'}{$parameter_name});
648 }
649 print "</dl>\n";
650 output_section_html(@_);
651 print "<hr>\n";
652}
653
Johannes Bergb112e0f2007-10-24 15:08:48 -0700654# output DOC: block header in html
655sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 my %args = %{$_[0]};
657 my ($parameter, $section);
658 my $count;
659
660 foreach $section (@{$args{'sectionlist'}}) {
661 print "<h3>$section</h3>\n";
662 print "<ul>\n";
663 output_highlight($args{'sections'}{$section});
664 print "</ul>\n";
665 }
666 print "<hr>\n";
667}
668
Dan Luedtke1b40c192012-08-12 10:46:15 +0200669# output sections in html5
670sub output_section_html5(%) {
671 my %args = %{$_[0]};
672 my $section;
673
674 foreach $section (@{$args{'sectionlist'}}) {
675 print "<section>\n";
676 print "<h1>$section</h1>\n";
677 print "<p>\n";
678 output_highlight($args{'sections'}{$section});
679 print "</p>\n";
680 print "</section>\n";
681 }
682}
683
684# output enum in html5
685sub output_enum_html5(%) {
686 my %args = %{$_[0]};
687 my ($parameter);
688 my $count;
689 my $html5id;
690
691 $html5id = $args{'enum'};
692 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
693 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
694 print "<h1>enum " . $args{'enum'} . "</h1>\n";
695 print "<ol class=\"code\">\n";
696 print "<li>";
697 print "<span class=\"keyword\">enum</span> ";
698 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
699 print "</li>\n";
700 $count = 0;
701 foreach $parameter (@{$args{'parameterlist'}}) {
702 print "<li class=\"indent\">";
703 print "<span class=\"param\">" . $parameter . "</span>";
704 if ($count != $#{$args{'parameterlist'}}) {
705 $count++;
706 print ",";
707 }
708 print "</li>\n";
709 }
710 print "<li>};</li>\n";
711 print "</ol>\n";
712
713 print "<section>\n";
714 print "<h1>Constants</h1>\n";
715 print "<dl>\n";
716 foreach $parameter (@{$args{'parameterlist'}}) {
717 print "<dt>" . $parameter . "</dt>\n";
718 print "<dd>";
719 output_highlight($args{'parameterdescs'}{$parameter});
720 print "</dd>\n";
721 }
722 print "</dl>\n";
723 print "</section>\n";
724 output_section_html5(@_);
725 print "</article>\n";
726}
727
728# output typedef in html5
729sub output_typedef_html5(%) {
730 my %args = %{$_[0]};
731 my ($parameter);
732 my $count;
733 my $html5id;
734
735 $html5id = $args{'typedef'};
736 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
737 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
738 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
739
740 print "<ol class=\"code\">\n";
741 print "<li>";
742 print "<span class=\"keyword\">typedef</span> ";
743 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
744 print "</li>\n";
745 print "</ol>\n";
746 output_section_html5(@_);
747 print "</article>\n";
748}
749
750# output struct in html5
751sub output_struct_html5(%) {
752 my %args = %{$_[0]};
753 my ($parameter);
754 my $html5id;
755
756 $html5id = $args{'struct'};
757 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
758 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
759 print "<hgroup>\n";
760 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
761 print "<h2>". $args{'purpose'} . "</h2>\n";
762 print "</hgroup>\n";
763 print "<ol class=\"code\">\n";
764 print "<li>";
765 print "<span class=\"type\">" . $args{'type'} . "</span> ";
766 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
767 print "</li>\n";
768 foreach $parameter (@{$args{'parameterlist'}}) {
769 print "<li class=\"indent\">";
770 if ($parameter =~ /^#/) {
771 print "<span class=\"param\">" . $parameter ."</span>\n";
772 print "</li>\n";
773 next;
774 }
775 my $parameter_name = $parameter;
776 $parameter_name =~ s/\[.*//;
777
778 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
779 $type = $args{'parametertypes'}{$parameter};
780 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
781 # pointer-to-function
782 print "<span class=\"type\">$1</span> ";
783 print "<span class=\"param\">$parameter</span>";
784 print "<span class=\"type\">)</span> ";
785 print "(<span class=\"args\">$2</span>);";
786 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
787 # bitfield
788 print "<span class=\"type\">$1</span> ";
789 print "<span class=\"param\">$parameter</span>";
790 print "<span class=\"bits\">$2</span>;";
791 } else {
792 print "<span class=\"type\">$type</span> ";
793 print "<span class=\"param\">$parameter</span>;";
794 }
795 print "</li>\n";
796 }
797 print "<li>};</li>\n";
798 print "</ol>\n";
799
800 print "<section>\n";
801 print "<h1>Members</h1>\n";
802 print "<dl>\n";
803 foreach $parameter (@{$args{'parameterlist'}}) {
804 ($parameter =~ /^#/) && next;
805
806 my $parameter_name = $parameter;
807 $parameter_name =~ s/\[.*//;
808
809 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
810 print "<dt>" . $parameter . "</dt>\n";
811 print "<dd>";
812 output_highlight($args{'parameterdescs'}{$parameter_name});
813 print "</dd>\n";
814 }
815 print "</dl>\n";
816 print "</section>\n";
817 output_section_html5(@_);
818 print "</article>\n";
819}
820
821# output function in html5
822sub output_function_html5(%) {
823 my %args = %{$_[0]};
824 my ($parameter, $section);
825 my $count;
826 my $html5id;
827
828 $html5id = $args{'function'};
829 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
830 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
831 print "<hgroup>\n";
832 print "<h1>" . $args{'function'} . "</h1>";
833 print "<h2>" . $args{'purpose'} . "</h2>\n";
834 print "</hgroup>\n";
835 print "<ol class=\"code\">\n";
836 print "<li>";
837 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
838 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
839 print "</li>";
840 $count = 0;
841 foreach $parameter (@{$args{'parameterlist'}}) {
842 print "<li class=\"indent\">";
843 $type = $args{'parametertypes'}{$parameter};
844 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
845 # pointer-to-function
846 print "<span class=\"type\">$1</span> ";
847 print "<span class=\"param\">$parameter</span>";
848 print "<span class=\"type\">)</span> ";
849 print "(<span class=\"args\">$2</span>)";
850 } else {
851 print "<span class=\"type\">$type</span> ";
852 print "<span class=\"param\">$parameter</span>";
853 }
854 if ($count != $#{$args{'parameterlist'}}) {
855 $count++;
856 print ",";
857 }
858 print "</li>\n";
859 }
860 print "<li>)</li>\n";
861 print "</ol>\n";
862
863 print "<section>\n";
864 print "<h1>Arguments</h1>\n";
865 print "<p>\n";
866 print "<dl>\n";
867 foreach $parameter (@{$args{'parameterlist'}}) {
868 my $parameter_name = $parameter;
869 $parameter_name =~ s/\[.*//;
870
871 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
872 print "<dt>" . $parameter . "</dt>\n";
873 print "<dd>";
874 output_highlight($args{'parameterdescs'}{$parameter_name});
875 print "</dd>\n";
876 }
877 print "</dl>\n";
878 print "</section>\n";
879 output_section_html5(@_);
880 print "</article>\n";
881}
882
883# output DOC: block header in html5
884sub output_blockhead_html5(%) {
885 my %args = %{$_[0]};
886 my ($parameter, $section);
887 my $count;
888 my $html5id;
889
890 foreach $section (@{$args{'sectionlist'}}) {
891 $html5id = $section;
892 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
893 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
894 print "<h1>$section</h1>\n";
895 print "<p>\n";
896 output_highlight($args{'sections'}{$section});
897 print "</p>\n";
898 }
899 print "</article>\n";
900}
901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902sub output_section_xml(%) {
903 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800904 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 # print out each section
906 $lineprefix=" ";
907 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700908 print "<refsect1>\n";
909 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700911 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -0700912 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -0700913 } else {
914 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -0700917 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700919 print "</programlisting></informalexample>\n";
920 } else {
921 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
Rich Walkerc73894c2005-05-01 08:59:26 -0700923 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925}
926
927# output function in XML DocBook
928sub output_function_xml(%) {
929 my %args = %{$_[0]};
930 my ($parameter, $section);
931 my $count;
932 my $id;
933
Randy Dunlapb9d973282009-06-09 08:50:38 -0700934 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 $id =~ s/[^A-Za-z0-9]/-/g;
936
Pavel Pisa5449bc92007-02-10 01:45:37 -0800937 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700938 print "<refentryinfo>\n";
939 print " <title>LINUX</title>\n";
940 print " <productname>Kernel Hackers Manual</productname>\n";
941 print " <date>$man_date</date>\n";
942 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700944 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700945 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -0700946 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 print "</refmeta>\n";
948 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700949 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 print " <refpurpose>\n";
951 print " ";
952 output_highlight ($args{'purpose'});
953 print " </refpurpose>\n";
954 print "</refnamediv>\n";
955
956 print "<refsynopsisdiv>\n";
957 print " <title>Synopsis</title>\n";
958 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700959 print " <funcdef>" . $args{'functiontype'} . " ";
960 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 $count = 0;
963 if ($#{$args{'parameterlist'}} >= 0) {
964 foreach $parameter (@{$args{'parameterlist'}}) {
965 $type = $args{'parametertypes'}{$parameter};
966 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
967 # pointer-to-function
968 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
969 print " <funcparams>$2</funcparams></paramdef>\n";
970 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700971 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 print " <parameter>$parameter</parameter></paramdef>\n";
973 }
974 }
975 } else {
Martin Waitz6013d542005-05-01 08:59:25 -0700976 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
978 print " </funcprototype></funcsynopsis>\n";
979 print "</refsynopsisdiv>\n";
980
981 # print parameters
982 print "<refsect1>\n <title>Arguments</title>\n";
983 if ($#{$args{'parameterlist'}} >= 0) {
984 print " <variablelist>\n";
985 foreach $parameter (@{$args{'parameterlist'}}) {
986 my $parameter_name = $parameter;
987 $parameter_name =~ s/\[.*//;
988
989 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
990 print " <listitem>\n <para>\n";
991 $lineprefix=" ";
992 output_highlight($args{'parameterdescs'}{$parameter_name});
993 print " </para>\n </listitem>\n </varlistentry>\n";
994 }
995 print " </variablelist>\n";
996 } else {
997 print " <para>\n None\n </para>\n";
998 }
999 print "</refsect1>\n";
1000
1001 output_section_xml(@_);
1002 print "</refentry>\n\n";
1003}
1004
1005# output struct in XML DocBook
1006sub output_struct_xml(%) {
1007 my %args = %{$_[0]};
1008 my ($parameter, $section);
1009 my $id;
1010
Randy Dunlapb9d973282009-06-09 08:50:38 -07001011 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 $id =~ s/[^A-Za-z0-9]/-/g;
1013
Pavel Pisa5449bc92007-02-10 01:45:37 -08001014 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001015 print "<refentryinfo>\n";
1016 print " <title>LINUX</title>\n";
1017 print " <productname>Kernel Hackers Manual</productname>\n";
1018 print " <date>$man_date</date>\n";
1019 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001021 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001022 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001023 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 print "</refmeta>\n";
1025 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001026 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 print " <refpurpose>\n";
1028 print " ";
1029 output_highlight ($args{'purpose'});
1030 print " </refpurpose>\n";
1031 print "</refnamediv>\n";
1032
1033 print "<refsynopsisdiv>\n";
1034 print " <title>Synopsis</title>\n";
1035 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001036 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 foreach $parameter (@{$args{'parameterlist'}}) {
1038 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001039 my $prm = $parameter;
1040 # convert data read & converted thru xml_escape() into &xyz; format:
1041 # This allows us to have #define macros interspersed in a struct.
1042 $prm =~ s/\\\\\\/\&/g;
1043 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 next;
1045 }
1046
1047 my $parameter_name = $parameter;
1048 $parameter_name =~ s/\[.*//;
1049
1050 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001051 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 $type = $args{'parametertypes'}{$parameter};
1053 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1054 # pointer-to-function
1055 print " $1 $parameter) ($2);\n";
1056 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001057 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 print " $1 $parameter$2;\n";
1059 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001060 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062 }
1063 print "};";
1064 print " </programlisting>\n";
1065 print "</refsynopsisdiv>\n";
1066
1067 print " <refsect1>\n";
1068 print " <title>Members</title>\n";
1069
Randy Dunlap39f00c02008-09-22 13:57:44 -07001070 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 print " <variablelist>\n";
1072 foreach $parameter (@{$args{'parameterlist'}}) {
1073 ($parameter =~ /^#/) && next;
1074
1075 my $parameter_name = $parameter;
1076 $parameter_name =~ s/\[.*//;
1077
1078 defined($args{'parameterdescs'}{$parameter_name}) || next;
1079 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1080 print " <varlistentry>";
1081 print " <term>$parameter</term>\n";
1082 print " <listitem><para>\n";
1083 output_highlight($args{'parameterdescs'}{$parameter_name});
1084 print " </para></listitem>\n";
1085 print " </varlistentry>\n";
1086 }
1087 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001088 } else {
1089 print " <para>\n None\n </para>\n";
1090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 print " </refsect1>\n";
1092
1093 output_section_xml(@_);
1094
1095 print "</refentry>\n\n";
1096}
1097
1098# output enum in XML DocBook
1099sub output_enum_xml(%) {
1100 my %args = %{$_[0]};
1101 my ($parameter, $section);
1102 my $count;
1103 my $id;
1104
Randy Dunlapb9d973282009-06-09 08:50:38 -07001105 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 $id =~ s/[^A-Za-z0-9]/-/g;
1107
Pavel Pisa5449bc92007-02-10 01:45:37 -08001108 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001109 print "<refentryinfo>\n";
1110 print " <title>LINUX</title>\n";
1111 print " <productname>Kernel Hackers Manual</productname>\n";
1112 print " <date>$man_date</date>\n";
1113 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001115 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001116 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001117 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 print "</refmeta>\n";
1119 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001120 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 print " <refpurpose>\n";
1122 print " ";
1123 output_highlight ($args{'purpose'});
1124 print " </refpurpose>\n";
1125 print "</refnamediv>\n";
1126
1127 print "<refsynopsisdiv>\n";
1128 print " <title>Synopsis</title>\n";
1129 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001130 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 $count = 0;
1132 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001133 print " $parameter";
1134 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 $count++;
1136 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 print "\n";
1139 }
1140 print "};";
1141 print " </programlisting>\n";
1142 print "</refsynopsisdiv>\n";
1143
1144 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001145 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 print " <variablelist>\n";
1147 foreach $parameter (@{$args{'parameterlist'}}) {
1148 my $parameter_name = $parameter;
1149 $parameter_name =~ s/\[.*//;
1150
1151 print " <varlistentry>";
1152 print " <term>$parameter</term>\n";
1153 print " <listitem><para>\n";
1154 output_highlight($args{'parameterdescs'}{$parameter_name});
1155 print " </para></listitem>\n";
1156 print " </varlistentry>\n";
1157 }
1158 print " </variablelist>\n";
1159 print "</refsect1>\n";
1160
1161 output_section_xml(@_);
1162
1163 print "</refentry>\n\n";
1164}
1165
1166# output typedef in XML DocBook
1167sub output_typedef_xml(%) {
1168 my %args = %{$_[0]};
1169 my ($parameter, $section);
1170 my $id;
1171
Randy Dunlapb9d973282009-06-09 08:50:38 -07001172 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 $id =~ s/[^A-Za-z0-9]/-/g;
1174
Pavel Pisa5449bc92007-02-10 01:45:37 -08001175 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001176 print "<refentryinfo>\n";
1177 print " <title>LINUX</title>\n";
1178 print " <productname>Kernel Hackers Manual</productname>\n";
1179 print " <date>$man_date</date>\n";
1180 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001182 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001183 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 print "</refmeta>\n";
1185 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001186 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 print " <refpurpose>\n";
1188 print " ";
1189 output_highlight ($args{'purpose'});
1190 print " </refpurpose>\n";
1191 print "</refnamediv>\n";
1192
1193 print "<refsynopsisdiv>\n";
1194 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001195 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 print "</refsynopsisdiv>\n";
1197
1198 output_section_xml(@_);
1199
1200 print "</refentry>\n\n";
1201}
1202
1203# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001204sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 my %args = %{$_[0]};
1206 my ($parameter, $section);
1207 my $count;
1208
1209 my $id = $args{'module'};
1210 $id =~ s/[^A-Za-z0-9]/-/g;
1211
1212 # print out each section
1213 $lineprefix=" ";
1214 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001215 if (!$args{'content-only'}) {
1216 print "<refsect1>\n <title>$section</title>\n";
1217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 if ($section =~ m/EXAMPLE/i) {
1219 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001220 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001221 } else {
1222 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 }
1224 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001225 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 if ($section =~ m/EXAMPLE/i) {
1227 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001228 } else {
1229 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001231 if (!$args{'content-only'}) {
1232 print "\n</refsect1>\n";
1233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 }
1235
1236 print "\n\n";
1237}
1238
1239# output in XML DocBook
1240sub output_function_gnome {
1241 my %args = %{$_[0]};
1242 my ($parameter, $section);
1243 my $count;
1244 my $id;
1245
Randy Dunlapb9d973282009-06-09 08:50:38 -07001246 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 $id =~ s/[^A-Za-z0-9]/-/g;
1248
1249 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001250 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
1252 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001253 print " <funcdef>" . $args{'functiontype'} . " ";
1254 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 print "</function></funcdef>\n";
1256
1257 $count = 0;
1258 if ($#{$args{'parameterlist'}} >= 0) {
1259 foreach $parameter (@{$args{'parameterlist'}}) {
1260 $type = $args{'parametertypes'}{$parameter};
1261 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1262 # pointer-to-function
1263 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1264 print " <funcparams>$2</funcparams></paramdef>\n";
1265 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001266 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 print " <parameter>$parameter</parameter></paramdef>\n";
1268 }
1269 }
1270 } else {
1271 print " <void>\n";
1272 }
1273 print " </funcsynopsis>\n";
1274 if ($#{$args{'parameterlist'}} >= 0) {
1275 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1276 print "<tgroup cols=\"2\">\n";
1277 print "<colspec colwidth=\"2*\">\n";
1278 print "<colspec colwidth=\"8*\">\n";
1279 print "<tbody>\n";
1280 foreach $parameter (@{$args{'parameterlist'}}) {
1281 my $parameter_name = $parameter;
1282 $parameter_name =~ s/\[.*//;
1283
1284 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1285 print " <entry>\n";
1286 $lineprefix=" ";
1287 output_highlight($args{'parameterdescs'}{$parameter_name});
1288 print " </entry></row>\n";
1289 }
1290 print " </tbody></tgroup></informaltable>\n";
1291 } else {
1292 print " <para>\n None\n </para>\n";
1293 }
1294
1295 # print out each section
1296 $lineprefix=" ";
1297 foreach $section (@{$args{'sectionlist'}}) {
1298 print "<simplesect>\n <title>$section</title>\n";
1299 if ($section =~ m/EXAMPLE/i) {
1300 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001301 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 } else {
1303 }
1304 print "<para>\n";
1305 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001306 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 print "</para>\n";
1308 if ($section =~ m/EXAMPLE/i) {
1309 print "</programlisting></example>\n";
1310 } else {
1311 }
1312 print " </simplesect>\n";
1313 }
1314
1315 print "</sect2>\n\n";
1316}
1317
1318##
1319# output function in man
1320sub output_function_man(%) {
1321 my %args = %{$_[0]};
1322 my ($parameter, $section);
1323 my $count;
1324
1325 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1326
1327 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001328 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001331 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001332 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001333 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001334 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 $count = 0;
1337 my $parenth = "(";
1338 my $post = ",";
1339 foreach my $parameter (@{$args{'parameterlist'}}) {
1340 if ($count == $#{$args{'parameterlist'}}) {
1341 $post = ");";
1342 }
1343 $type = $args{'parametertypes'}{$parameter};
1344 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1345 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001346 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 } else {
1348 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001349 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 }
1351 $count++;
1352 $parenth = "";
1353 }
1354
1355 print ".SH ARGUMENTS\n";
1356 foreach $parameter (@{$args{'parameterlist'}}) {
1357 my $parameter_name = $parameter;
1358 $parameter_name =~ s/\[.*//;
1359
Randy Dunlapb9d973282009-06-09 08:50:38 -07001360 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 output_highlight($args{'parameterdescs'}{$parameter_name});
1362 }
1363 foreach $section (@{$args{'sectionlist'}}) {
1364 print ".SH \"", uc $section, "\"\n";
1365 output_highlight($args{'sections'}{$section});
1366 }
1367}
1368
1369##
1370# output enum in man
1371sub output_enum_man(%) {
1372 my %args = %{$_[0]};
1373 my ($parameter, $section);
1374 my $count;
1375
1376 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1377
1378 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001379 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001382 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 $count = 0;
1384 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001385 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 if ($count == $#{$args{'parameterlist'}}) {
1387 print "\n};\n";
1388 last;
1389 }
1390 else {
1391 print ", \n.br\n";
1392 }
1393 $count++;
1394 }
1395
1396 print ".SH Constants\n";
1397 foreach $parameter (@{$args{'parameterlist'}}) {
1398 my $parameter_name = $parameter;
1399 $parameter_name =~ s/\[.*//;
1400
Randy Dunlapb9d973282009-06-09 08:50:38 -07001401 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 output_highlight($args{'parameterdescs'}{$parameter_name});
1403 }
1404 foreach $section (@{$args{'sectionlist'}}) {
1405 print ".SH \"$section\"\n";
1406 output_highlight($args{'sections'}{$section});
1407 }
1408}
1409
1410##
1411# output struct in man
1412sub output_struct_man(%) {
1413 my %args = %{$_[0]};
1414 my ($parameter, $section);
1415
Randy Dunlapb9d973282009-06-09 08:50:38 -07001416 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001419 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
1421 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001422 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
1424 foreach my $parameter (@{$args{'parameterlist'}}) {
1425 if ($parameter =~ /^#/) {
1426 print ".BI \"$parameter\"\n.br\n";
1427 next;
1428 }
1429 my $parameter_name = $parameter;
1430 $parameter_name =~ s/\[.*//;
1431
Randy Dunlap3c308792007-05-08 00:24:39 -07001432 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 $type = $args{'parametertypes'}{$parameter};
1434 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1435 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001436 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001438 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001439 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 } else {
1441 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001442 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444 print "\n.br\n";
1445 }
1446 print "};\n.br\n";
1447
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001448 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 foreach $parameter (@{$args{'parameterlist'}}) {
1450 ($parameter =~ /^#/) && next;
1451
1452 my $parameter_name = $parameter;
1453 $parameter_name =~ s/\[.*//;
1454
Randy Dunlap3c308792007-05-08 00:24:39 -07001455 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001456 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 output_highlight($args{'parameterdescs'}{$parameter_name});
1458 }
1459 foreach $section (@{$args{'sectionlist'}}) {
1460 print ".SH \"$section\"\n";
1461 output_highlight($args{'sections'}{$section});
1462 }
1463}
1464
1465##
1466# output typedef in man
1467sub output_typedef_man(%) {
1468 my %args = %{$_[0]};
1469 my ($parameter, $section);
1470
1471 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1472
1473 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001474 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 foreach $section (@{$args{'sectionlist'}}) {
1477 print ".SH \"$section\"\n";
1478 output_highlight($args{'sections'}{$section});
1479 }
1480}
1481
Johannes Bergb112e0f2007-10-24 15:08:48 -07001482sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 my %args = %{$_[0]};
1484 my ($parameter, $section);
1485 my $count;
1486
1487 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1488
1489 foreach $section (@{$args{'sectionlist'}}) {
1490 print ".SH \"$section\"\n";
1491 output_highlight($args{'sections'}{$section});
1492 }
1493}
1494
1495##
1496# output in text
1497sub output_function_text(%) {
1498 my %args = %{$_[0]};
1499 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001500 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Randy Dunlapf47634b2006-07-01 04:36:36 -07001502 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001503 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001504
1505 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001506 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001507 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001508 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001509 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 my $count = 0;
1514 foreach my $parameter (@{$args{'parameterlist'}}) {
1515 $type = $args{'parametertypes'}{$parameter};
1516 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1517 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001518 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001520 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
1522 if ($count != $#{$args{'parameterlist'}}) {
1523 $count++;
1524 print ",\n";
1525 print " " x length($start);
1526 } else {
1527 print ");\n\n";
1528 }
1529 }
1530
1531 print "Arguments:\n\n";
1532 foreach $parameter (@{$args{'parameterlist'}}) {
1533 my $parameter_name = $parameter;
1534 $parameter_name =~ s/\[.*//;
1535
Randy Dunlapb9d973282009-06-09 08:50:38 -07001536 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
1538 output_section_text(@_);
1539}
1540
1541#output sections in text
1542sub output_section_text(%) {
1543 my %args = %{$_[0]};
1544 my $section;
1545
1546 print "\n";
1547 foreach $section (@{$args{'sectionlist'}}) {
1548 print "$section:\n\n";
1549 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 print "\n\n";
1552}
1553
1554# output enum in text
1555sub output_enum_text(%) {
1556 my %args = %{$_[0]};
1557 my ($parameter);
1558 my $count;
1559 print "Enum:\n\n";
1560
Randy Dunlapb9d973282009-06-09 08:50:38 -07001561 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1562 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 $count = 0;
1564 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001565 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 if ($count != $#{$args{'parameterlist'}}) {
1567 $count++;
1568 print ",";
1569 }
1570 print "\n";
1571 }
1572 print "};\n\n";
1573
1574 print "Constants:\n\n";
1575 foreach $parameter (@{$args{'parameterlist'}}) {
1576 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001577 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 }
1579
1580 output_section_text(@_);
1581}
1582
1583# output typedef in text
1584sub output_typedef_text(%) {
1585 my %args = %{$_[0]};
1586 my ($parameter);
1587 my $count;
1588 print "Typedef:\n\n";
1589
Randy Dunlapb9d973282009-06-09 08:50:38 -07001590 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 output_section_text(@_);
1592}
1593
1594# output struct as text
1595sub output_struct_text(%) {
1596 my %args = %{$_[0]};
1597 my ($parameter);
1598
Randy Dunlapb9d973282009-06-09 08:50:38 -07001599 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1600 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 foreach $parameter (@{$args{'parameterlist'}}) {
1602 if ($parameter =~ /^#/) {
1603 print "$parameter\n";
1604 next;
1605 }
1606
1607 my $parameter_name = $parameter;
1608 $parameter_name =~ s/\[.*//;
1609
Randy Dunlap3c308792007-05-08 00:24:39 -07001610 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 $type = $args{'parametertypes'}{$parameter};
1612 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1613 # pointer-to-function
1614 print "\t$1 $parameter) ($2);\n";
1615 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001616 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 print "\t$1 $parameter$2;\n";
1618 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001619 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 }
1621 }
1622 print "};\n\n";
1623
1624 print "Members:\n\n";
1625 foreach $parameter (@{$args{'parameterlist'}}) {
1626 ($parameter =~ /^#/) && next;
1627
1628 my $parameter_name = $parameter;
1629 $parameter_name =~ s/\[.*//;
1630
Randy Dunlap3c308792007-05-08 00:24:39 -07001631 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001633 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 }
1635 print "\n";
1636 output_section_text(@_);
1637}
1638
Johannes Bergb112e0f2007-10-24 15:08:48 -07001639sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 my %args = %{$_[0]};
1641 my ($parameter, $section);
1642
1643 foreach $section (@{$args{'sectionlist'}}) {
1644 print " $section:\n";
1645 print " -> ";
1646 output_highlight($args{'sections'}{$section});
1647 }
1648}
1649
Johannes Bergeda603f2010-09-11 15:55:22 -07001650## list mode output functions
1651
1652sub output_function_list(%) {
1653 my %args = %{$_[0]};
1654
1655 print $args{'function'} . "\n";
1656}
1657
1658# output enum in list
1659sub output_enum_list(%) {
1660 my %args = %{$_[0]};
1661 print $args{'enum'} . "\n";
1662}
1663
1664# output typedef in list
1665sub output_typedef_list(%) {
1666 my %args = %{$_[0]};
1667 print $args{'typedef'} . "\n";
1668}
1669
1670# output struct as list
1671sub output_struct_list(%) {
1672 my %args = %{$_[0]};
1673
1674 print $args{'struct'} . "\n";
1675}
1676
1677sub output_blockhead_list(%) {
1678 my %args = %{$_[0]};
1679 my ($parameter, $section);
1680
1681 foreach $section (@{$args{'sectionlist'}}) {
1682 print "DOC: $section\n";
1683 }
1684}
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686##
Randy Dunlap27205742006-10-11 01:22:12 -07001687# generic output function for all types (function, struct/union, typedef, enum);
1688# calls the generated, variable output_ function name based on
1689# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690sub output_declaration {
1691 no strict 'refs';
1692 my $name = shift;
1693 my $functype = shift;
1694 my $func = "output_${functype}_$output_mode";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001695 if (($function_only==0) ||
1696 ( $function_only == 1 && defined($function_table{$name})) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 ( $function_only == 2 && !defined($function_table{$name})))
1698 {
Randy Dunlap3c308792007-05-08 00:24:39 -07001699 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 $section_counter++;
1701 }
1702}
1703
1704##
Randy Dunlap27205742006-10-11 01:22:12 -07001705# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07001706sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07001708 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 &$func(@_);
1710 $section_counter++;
1711}
1712
1713##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001714# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715# invokes the right handler. NOT called for functions.
1716sub dump_declaration($$) {
1717 no strict 'refs';
1718 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001719 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 &$func(@_);
1721}
1722
1723sub dump_union($$) {
1724 dump_struct(@_);
1725}
1726
1727sub dump_struct($$) {
1728 my $x = shift;
1729 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001730 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07001732 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1733 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07001734 $declaration_name = $2;
1735 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001738 $members =~ s/({.*})//g;
1739 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Martin Waitzaeec46b2005-11-13 16:08:13 -08001741 # ignore members marked private:
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07001742 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
1743 $members =~ s/\/\*\s*private:.*//gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001744 # strip comments:
1745 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001746 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07001747 # strip kmemcheck_bitfield_{begin,end}.*;
1748 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07001749 # strip attributes
1750 $members =~ s/__aligned\s*\(\d+\)//gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001751
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001753 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 output_declaration($declaration_name,
1756 'struct',
1757 {'struct' => $declaration_name,
1758 'module' => $modulename,
1759 'parameterlist' => \@parameterlist,
1760 'parameterdescs' => \%parameterdescs,
1761 'parametertypes' => \%parametertypes,
1762 'sectionlist' => \@sectionlist,
1763 'sections' => \%sections,
1764 'purpose' => $declaration_purpose,
1765 'type' => $decl_type
1766 });
1767 }
1768 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001769 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 ++$errors;
1771 }
1772}
1773
1774sub dump_enum($$) {
1775 my $x = shift;
1776 my $file = shift;
1777
Martin Waitzaeec46b2005-11-13 16:08:13 -08001778 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Randy Dunlapb6d676d2010-08-10 18:02:50 -07001779 $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001782 $declaration_name = $1;
1783 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
1785 foreach my $arg (split ',', $members) {
1786 $arg =~ s/^\s*(\w+).*/$1/;
1787 push @parameterlist, $arg;
1788 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001789 $parameterdescs{$arg} = $undescribed;
1790 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 "not described in enum '$declaration_name'\n";
1792 }
1793
1794 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 output_declaration($declaration_name,
1797 'enum',
1798 {'enum' => $declaration_name,
1799 'module' => $modulename,
1800 'parameterlist' => \@parameterlist,
1801 'parameterdescs' => \%parameterdescs,
1802 'sectionlist' => \@sectionlist,
1803 'sections' => \%sections,
1804 'purpose' => $declaration_purpose
1805 });
1806 }
1807 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001808 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 ++$errors;
1810 }
1811}
1812
1813sub dump_typedef($$) {
1814 my $x = shift;
1815 my $file = shift;
1816
Martin Waitzaeec46b2005-11-13 16:08:13 -08001817 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001819 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 $x =~ s/\[*.\]\s*;$/;/;
1821 }
1822
1823 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001824 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
1826 output_declaration($declaration_name,
1827 'typedef',
1828 {'typedef' => $declaration_name,
1829 'module' => $modulename,
1830 'sectionlist' => \@sectionlist,
1831 'sections' => \%sections,
1832 'purpose' => $declaration_purpose
1833 });
1834 }
1835 else {
Randy Dunlap3c308792007-05-08 00:24:39 -07001836 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 ++$errors;
1838 }
1839}
1840
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001841sub save_struct_actual($) {
1842 my $actual = shift;
1843
1844 # strip all spaces from the actual param so that it looks like one string item
1845 $actual =~ s/\s*//g;
1846 $struct_actual = $struct_actual . $actual . " ";
1847}
1848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849sub create_parameterlist($$$) {
1850 my $args = shift;
1851 my $splitter = shift;
1852 my $file = shift;
1853 my $type;
1854 my $param;
1855
Martin Waitza6d3fe72006-01-09 20:53:55 -08001856 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001858 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001860
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 foreach my $arg (split($splitter, $args)) {
1862 # strip comments
1863 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07001864 # strip leading/trailing spaces
1865 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 $arg =~ s/\s*$//;
1867 $arg =~ s/\s+/ /;
1868
1869 if ($arg =~ /^#/) {
1870 # Treat preprocessor directive as a typeless variable just to fill
1871 # corresponding data structures "correctly". Catch it later in
1872 # output_* subs.
1873 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08001874 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 # pointer-to-function
1876 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08001877 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 $param = $1;
1879 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08001880 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001881 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08001883 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 $arg =~ s/\s*:\s*/:/g;
1885 $arg =~ s/\s*\[/\[/g;
1886
1887 my @args = split('\s*,\s*', $arg);
1888 if ($args[0] =~ m/\*/) {
1889 $args[0] =~ s/(\*+)\s*/ $1/;
1890 }
Borislav Petkov884f2812007-05-08 00:29:05 -07001891
1892 my @first_arg;
1893 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1894 shift @args;
1895 push(@first_arg, split('\s+', $1));
1896 push(@first_arg, $2);
1897 } else {
1898 @first_arg = split('\s+', shift @args);
1899 }
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 unshift(@args, pop @first_arg);
1902 $type = join " ", @first_arg;
1903
1904 foreach $param (@args) {
1905 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001906 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 push_parameter($2, "$type $1", $file);
1908 }
1909 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07001910 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001911 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07001912 push_parameter($1, "$type:$2", $file)
1913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 }
1915 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001916 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 push_parameter($param, $type, $file);
1918 }
1919 }
1920 }
1921 }
1922}
1923
1924sub push_parameter($$$) {
1925 my $param = shift;
1926 my $type = shift;
1927 my $file = shift;
1928
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001929 if (($anon_struct_union == 1) && ($type eq "") &&
1930 ($param eq "}")) {
1931 return; # ignore the ending }; from anon. struct/union
1932 }
1933
1934 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 my $param_name = $param;
1936 $param_name =~ s/\[.*//;
1937
Martin Waitza6d3fe72006-01-09 20:53:55 -08001938 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 {
Randy Dunlapced69092008-12-01 13:14:03 -08001940 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1941 $parameterdescs{$param} = "variable arguments";
1942 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 }
1944 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1945 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 $param="void";
1947 $parameterdescs{void} = "no arguments";
1948 }
Randy Dunlap134fe012006-12-22 01:10:50 -08001949 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1950 # handle unnamed (anonymous) union or struct:
1951 {
1952 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001953 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08001954 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001955 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08001956 }
1957
Martin Waitza6d3fe72006-01-09 20:53:55 -08001958 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08001959 # (but ignore ones starting with # as these are not parameters
1960 # but inline preprocessor statements);
1961 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001962 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08001963 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1964
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 $parameterdescs{$param_name} = $undescribed;
1966
1967 if (($type eq 'function') || ($type eq 'enum')) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001968 print STDERR "Warning(${file}:$.): Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 "or member '$param' not " .
1970 "described in '$declaration_name'\n";
1971 }
Randy Dunlapb9d973282009-06-09 08:50:38 -07001972 print STDERR "Warning(${file}:$.):" .
Randy Dunlap3c308792007-05-08 00:24:39 -07001973 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07001975 }
1976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001978 $param = xml_escape($param);
1979
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001980 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07001981 # on @parameterlist;
1982 # this fixes a problem where check_sections() cannot find
1983 # a parameter like "addr[6 + 2]" because it actually appears
1984 # as "addr[6", "+", "2]" on the parameter list;
1985 # but it's better to maintain the param string unchanged for output,
1986 # so just weaken the string compare in check_sections() to ignore
1987 # "[blah" in a parameter string;
1988 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 push @parameterlist, $param;
1990 $parametertypes{$param} = $type;
1991}
1992
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001993sub check_sections($$$$$$) {
1994 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1995 my @sects = split ' ', $sectcheck;
1996 my @prms = split ' ', $prmscheck;
1997 my $err;
1998 my ($px, $sx);
1999 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2000
2001 foreach $sx (0 .. $#sects) {
2002 $err = 1;
2003 foreach $px (0 .. $#prms) {
2004 $prm_clean = $prms[$px];
2005 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002006 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002007 # ignore array size in a parameter string;
2008 # however, the original param string may contain
2009 # spaces, e.g.: addr[6 + 2]
2010 # and this appears in @prms as "addr[6" since the
2011 # parameter list is split at spaces;
2012 # hence just ignore "[..." for the sections check;
2013 $prm_clean =~ s/\[.*//;
2014
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002015 ##$prm_clean =~ s/^\**//;
2016 if ($prm_clean eq $sects[$sx]) {
2017 $err = 0;
2018 last;
2019 }
2020 }
2021 if ($err) {
2022 if ($decl_type eq "function") {
2023 print STDERR "Warning(${file}:$.): " .
2024 "Excess function parameter " .
2025 "'$sects[$sx]' " .
2026 "description in '$decl_name'\n";
2027 ++$warnings;
2028 } else {
2029 if ($nested !~ m/\Q$sects[$sx]\E/) {
2030 print STDERR "Warning(${file}:$.): " .
2031 "Excess struct/union/enum/typedef member " .
2032 "'$sects[$sx]' " .
2033 "description in '$decl_name'\n";
2034 ++$warnings;
2035 }
2036 }
2037 }
2038 }
2039}
2040
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041##
2042# takes a function prototype and the name of the current file being
2043# processed and spits out all the details stored in the global
2044# arrays/hashes.
2045sub dump_function($$) {
2046 my $prototype = shift;
2047 my $file = shift;
2048
2049 $prototype =~ s/^static +//;
2050 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002051 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 $prototype =~ s/^inline +//;
2053 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002054 $prototype =~ s/^__inline +//;
2055 $prototype =~ s/^__always_inline +//;
2056 $prototype =~ s/^noinline +//;
Randy Dunlap0129a052006-07-30 03:03:41 -07002057 $prototype =~ s/__devinit +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002058 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002059 $prototype =~ s/__init_or_module +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002060 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002061 $prototype =~ s/__weak +//;
Randy Dunlap890c78c2008-10-25 17:06:43 -07002062 $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002063 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 # Yes, this truly is vile. We are looking for:
2066 # 1. Return type (may be nothing if we're looking at a macro)
2067 # 2. Function name
2068 # 3. Function parameters.
2069 #
2070 # All the while we have to watch out for function pointer parameters
2071 # (which IIRC is what the two sections are for), C types (these
2072 # regexps don't even start to express all the possibilities), and
2073 # so on.
2074 #
2075 # If you mess with these regexps, it's a good idea to check that
2076 # the following functions' documentation still comes out right:
2077 # - parport_register_device (function pointer parameters)
2078 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002079 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2082 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2083 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2084 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002085 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2087 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2088 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2089 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2090 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2091 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2092 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2093 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002094 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2095 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002096 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2097 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 $return_type = $1;
2099 $declaration_name = $2;
2100 my $args = $3;
2101
2102 create_parameterlist($args, ',', $file);
2103 } else {
2104 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
2105 ++$errors;
2106 return;
2107 }
2108
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002109 my $prms = join " ", @parameterlist;
2110 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2111
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002112 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 'function',
2114 {'function' => $declaration_name,
2115 'module' => $modulename,
2116 'functiontype' => $return_type,
2117 'parameterlist' => \@parameterlist,
2118 'parameterdescs' => \%parameterdescs,
2119 'parametertypes' => \%parametertypes,
2120 'sectionlist' => \@sectionlist,
2121 'sections' => \%sections,
2122 'purpose' => $declaration_purpose
2123 });
2124}
2125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126sub reset_state {
2127 $function = "";
2128 %constants = ();
2129 %parameterdescs = ();
2130 %parametertypes = ();
2131 @parameterlist = ();
2132 %sections = ();
2133 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002134 $sectcheck = "";
2135 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 $state = 0;
2139}
2140
Jason Baron56afb0f2009-04-30 13:29:36 -04002141sub tracepoint_munge($) {
2142 my $file = shift;
2143 my $tracepointname = 0;
2144 my $tracepointargs = 0;
2145
Jason Baron3a9089f2009-12-01 12:18:49 -05002146 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002147 $tracepointname = $1;
2148 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002149 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2150 $tracepointname = $1;
2151 }
2152 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2153 $tracepointname = $2;
2154 }
2155 $tracepointname =~ s/^\s+//; #strip leading whitespace
2156 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002157 $tracepointargs = $1;
2158 }
2159 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
2160 print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
2161 "$prototype\n";
2162 } else {
2163 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2164 }
2165}
2166
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002167sub syscall_munge() {
2168 my $void = 0;
2169
2170 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2171## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2172 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2173 $void = 1;
2174## $prototype = "long sys_$1(void)";
2175 }
2176
2177 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2178 if ($prototype =~ m/long (sys_.*?),/) {
2179 $prototype =~ s/,/\(/;
2180 } elsif ($void) {
2181 $prototype =~ s/\)/\(void\)/;
2182 }
2183
2184 # now delete all of the odd-number commas in $prototype
2185 # so that arg types & arg names don't have a comma between them
2186 my $count = 0;
2187 my $len = length($prototype);
2188 if ($void) {
2189 $len = 0; # skip the for-loop
2190 }
2191 for (my $ix = 0; $ix < $len; $ix++) {
2192 if (substr($prototype, $ix, 1) eq ',') {
2193 $count++;
2194 if ($count % 2 == 1) {
2195 substr($prototype, $ix, 1) = ' ';
2196 }
2197 }
2198 }
2199}
2200
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002201sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 my $x = shift;
2203 my $file = shift;
2204
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002205 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2206
Randy Dunlap890c78c2008-10-25 17:06:43 -07002207 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 # do nothing
2209 }
2210 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002211 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002213
Randy Dunlap890c78c2008-10-25 17:06:43 -07002214 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002215 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2217 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002218 if ($prototype =~ /SYSCALL_DEFINE/) {
2219 syscall_munge();
2220 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002221 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2222 $prototype =~ /DEFINE_SINGLE_EVENT/)
2223 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002224 tracepoint_munge($file);
2225 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002226 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 reset_state();
2228 }
2229}
2230
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002231sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 my $x = shift;
2233 my $file = shift;
2234
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2236 $x =~ s@^\s+@@gos; # strip leading spaces
2237 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002238 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 if ($x =~ /^#/) {
2241 # To distinguish preprocessor directive from regular declaration later.
2242 $x .= ";";
2243 }
2244
2245 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002246 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 $prototype .= $1 . $2;
2248 ($2 eq '{') && $brcount++;
2249 ($2 eq '}') && $brcount--;
2250 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002251 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002253 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 }
2255 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002256 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 $prototype .= $x;
2258 last;
2259 }
2260 }
2261}
2262
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002263# xml_escape: replace <, >, and & in the text stream;
2264#
2265# however, formatting controls that are generated internally/locally in the
2266# kernel-doc script are not escaped here; instead, they begin life like
2267# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2268# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2269# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270sub xml_escape($) {
2271 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002272 if (($output_mode eq "text") || ($output_mode eq "man")) {
2273 return $text;
2274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 $text =~ s/\&/\\\\\\amp;/g;
2276 $text =~ s/\</\\\\\\lt;/g;
2277 $text =~ s/\>/\\\\\\gt;/g;
2278 return $text;
2279}
2280
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002281# convert local escape strings to html
2282# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2283sub local_unescape($) {
2284 my $text = shift;
2285 if (($output_mode eq "text") || ($output_mode eq "man")) {
2286 return $text;
2287 }
2288 $text =~ s/\\\\\\\\lt:/</g;
2289 $text =~ s/\\\\\\\\gt:/>/g;
2290 return $text;
2291}
2292
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002294 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 my $identifier;
2296 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002297 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002298 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 my $initial_section_counter = $section_counter;
2300
Randy Dunlap2283a112005-07-07 15:39:26 -07002301 if (defined($ENV{'SRCTREE'})) {
2302 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
2303 }
2304 else {
2305 $file = "@_";
2306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 if (defined($source_map{$file})) {
2308 $file = $source_map{$file};
2309 }
2310
2311 if (!open(IN,"<$file")) {
2312 print STDERR "Error: Cannot open file $file\n";
2313 ++$errors;
2314 return;
2315 }
2316
Ilya Dryomova9e73142010-02-26 13:05:47 -08002317 $. = 1;
2318
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 $section_counter = 0;
2320 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002321 while (s/\\\s*$//) {
2322 $_ .= <IN>;
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 if ($state == 0) {
2325 if (/$doc_start/o) {
2326 $state = 1; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002327 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329 } elsif ($state == 1) { # this line is the function name (always)
2330 if (/$doc_block/o) {
2331 $state = 4;
2332 $contents = "";
2333 if ( $1 eq "" ) {
2334 $section = $section_intro;
2335 } else {
2336 $section = $1;
2337 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 elsif (/$doc_decl/o) {
2340 $identifier = $1;
2341 if (/\s*([\w\s]+?)\s*-/) {
2342 $identifier = $1;
2343 }
2344
2345 $state = 2;
2346 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002347 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002348 $descr= $1;
2349 $descr =~ s/^\s*//;
2350 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002351 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002352 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002353 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 } else {
2355 $declaration_purpose = "";
2356 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002357
2358 if (($declaration_purpose eq "") && $verbose) {
2359 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
2360 print STDERR $_;
2361 ++$warnings;
2362 }
2363
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 if ($identifier =~ m/^struct/) {
2365 $decl_type = 'struct';
2366 } elsif ($identifier =~ m/^union/) {
2367 $decl_type = 'union';
2368 } elsif ($identifier =~ m/^enum/) {
2369 $decl_type = 'enum';
2370 } elsif ($identifier =~ m/^typedef/) {
2371 $decl_type = 'typedef';
2372 } else {
2373 $decl_type = 'function';
2374 }
2375
2376 if ($verbose) {
2377 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
2378 }
2379 } else {
2380 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
2381 " - I thought it was a doc line\n";
2382 ++$warnings;
2383 $state = 0;
2384 }
2385 } elsif ($state == 2) { # look for head: lines, and include content
2386 if (/$doc_sect/o) {
2387 $newsection = $1;
2388 $newcontents = $2;
2389
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002390 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002391 if (!$in_doc_sect && $verbose) {
2392 print STDERR "Warning(${file}:$.): contents before sections\n";
2393 ++$warnings;
2394 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002395 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 $section = $section_default;
2397 }
2398
Randy Dunlap850622d2006-06-25 05:48:55 -07002399 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002400 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 $contents = $newcontents;
2402 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002403 while ((substr($contents, 0, 1) eq " ") ||
2404 substr($contents, 0, 1) eq "\t") {
2405 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 $contents .= "\n";
2408 }
2409 $section = $newsection;
2410 } elsif (/$doc_end/) {
2411
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002412 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002413 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 $section = $section_default;
2415 $contents = "";
2416 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002417 # look for doc_com + <text> + doc_end:
2418 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2419 print STDERR "Warning(${file}:$.): suspicious ending line: $_";
2420 ++$warnings;
2421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
2423 $prototype = "";
2424 $state = 3;
2425 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002426# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 } elsif (/$doc_content/) {
2428 # miguel-style comment kludge, look for blank lines after
2429 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002430 if ($1 eq "") {
2431 if ($section =~ m/^@/ || $section eq $section_context) {
2432 dump_section($file, $section, xml_escape($contents));
2433 $section = $section_default;
2434 $contents = "";
2435 } else {
2436 $contents .= "\n";
2437 }
2438 $in_purpose = 0;
2439 } elsif ($in_purpose == 1) {
2440 # Continued declaration purpose
2441 chomp($declaration_purpose);
2442 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002443 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002445 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 }
2447 } else {
2448 # i dont know - bad line? ignore.
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002449 print STDERR "Warning(${file}:$.): bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 ++$warnings;
2451 }
Randy Dunlap232acbc2006-06-25 05:47:48 -07002452 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 if ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002454 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002456 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 }
2458 } elsif ($state == 4) {
2459 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002460 if (/$doc_block/) {
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 if ( $1 eq "" ) {
2472 $section = $section_intro;
2473 } else {
2474 $section = $1;
2475 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 elsif (/$doc_end/)
2478 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002479 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 $contents = "";
2481 $function = "";
2482 %constants = ();
2483 %parameterdescs = ();
2484 %parametertypes = ();
2485 @parameterlist = ();
2486 %sections = ();
2487 @sectionlist = ();
2488 $prototype = "";
2489 $state = 0;
2490 }
2491 elsif (/$doc_content/)
2492 {
2493 if ( $1 eq "" )
2494 {
2495 $contents .= $blankline;
2496 }
2497 else
2498 {
2499 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002500 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002501 }
2502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 }
2504 if ($initial_section_counter == $section_counter) {
2505 print STDERR "Warning(${file}): no structured comments found\n";
2506 if ($output_mode eq "xml") {
2507 # The template wants at least one RefEntry here; make one.
2508 print "<refentry>\n";
2509 print " <refnamediv>\n";
2510 print " <refname>\n";
2511 print " ${file}\n";
2512 print " </refname>\n";
2513 print " <refpurpose>\n";
2514 print " Document generation inconsistency\n";
2515 print " </refpurpose>\n";
2516 print " </refnamediv>\n";
2517 print " <refsect1>\n";
2518 print " <title>\n";
2519 print " Oops\n";
2520 print " </title>\n";
2521 print " <warning>\n";
2522 print " <para>\n";
2523 print " The template for this document tried to insert\n";
2524 print " the structured comment from the file\n";
2525 print " <filename>${file}</filename> at this point,\n";
2526 print " but none was found.\n";
2527 print " This dummy section is inserted to allow\n";
2528 print " generation to continue.\n";
2529 print " </para>\n";
2530 print " </warning>\n";
2531 print " </refsect1>\n";
2532 print "</refentry>\n";
2533 }
2534 }
2535}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002536
2537
2538$kernelversion = get_kernel_version();
2539
2540# generate a sequence of code that will splice in highlighting information
2541# using the s// operator.
2542foreach my $pattern (keys %highlights) {
2543# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
2544 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
2545}
2546
2547# Read the file that maps relative names to absolute names for
2548# separate source and object directories and for shadow trees.
2549if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2550 my ($relname, $absname);
2551 while(<SOURCE_MAP>) {
2552 chop();
2553 ($relname, $absname) = (split())[0..1];
2554 $relname =~ s:^/+::;
2555 $source_map{$relname} = $absname;
2556 }
2557 close(SOURCE_MAP);
2558}
2559
2560foreach (@ARGV) {
2561 chomp;
2562 process_file($_);
2563}
2564if ($verbose && $errors) {
2565 print STDERR "$errors errors\n";
2566}
2567if ($verbose && $warnings) {
2568 print STDERR "$warnings warnings\n";
2569}
2570
2571exit($errors);