xref: /linux/scripts/kernel-doc (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds#!/usr/bin/perl -w
2*1da177e4SLinus Torvalds
3*1da177e4SLinus Torvaldsuse strict;
4*1da177e4SLinus Torvalds
5*1da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved        ##
6*1da177e4SLinus Torvalds## Copyright (C) 2000, 1  Tim Waugh <twaugh@redhat.com>          ##
7*1da177e4SLinus Torvalds## Copyright (C) 2001  Simon Huggins                             ##
8*1da177e4SLinus Torvalds## 								 ##
9*1da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com>	 ##
10*1da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc.			 ##
11*1da177e4SLinus Torvalds## 								 ##
12*1da177e4SLinus Torvalds## This software falls under the GNU General Public License.     ##
13*1da177e4SLinus Torvalds## Please read the COPYING file for more information             ##
14*1da177e4SLinus Torvalds
15*1da177e4SLinus Torvalds# w.o. 03-11-2000: added the '-filelist' option.
16*1da177e4SLinus Torvalds
17*1da177e4SLinus Torvalds# 18/01/2001 - 	Cleanups
18*1da177e4SLinus Torvalds# 		Functions prototyped as foo(void) same as foo()
19*1da177e4SLinus Torvalds# 		Stop eval'ing where we don't need to.
20*1da177e4SLinus Torvalds# -- huggie@earth.li
21*1da177e4SLinus Torvalds
22*1da177e4SLinus Torvalds# 27/06/2001 -  Allowed whitespace after initial "/**" and
23*1da177e4SLinus Torvalds#               allowed comments before function declarations.
24*1da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org>
25*1da177e4SLinus Torvalds
26*1da177e4SLinus Torvalds# Still to do:
27*1da177e4SLinus Torvalds# 	- add perldoc documentation
28*1da177e4SLinus Torvalds# 	- Look more closely at some of the scarier bits :)
29*1da177e4SLinus Torvalds
30*1da177e4SLinus Torvalds# 26/05/2001 - 	Support for separate source and object trees.
31*1da177e4SLinus Torvalds#		Return error code.
32*1da177e4SLinus Torvalds# 		Keith Owens <kaos@ocs.com.au>
33*1da177e4SLinus Torvalds
34*1da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions
35*1da177e4SLinus Torvalds#              Support for Context section; can be terminated using empty line
36*1da177e4SLinus Torvalds#              Small fixes (like spaces vs. \s in regex)
37*1da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de>
38*1da177e4SLinus Torvalds
39*1da177e4SLinus Torvalds
40*1da177e4SLinus Torvalds#
41*1da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the
42*1da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below).
43*1da177e4SLinus Torvalds#
44*1da177e4SLinus Torvalds
45*1da177e4SLinus Torvalds# Note: This only supports 'c'.
46*1da177e4SLinus Torvalds
47*1da177e4SLinus Torvalds# usage:
48*1da177e4SLinus Torvalds# kerneldoc [ -docbook | -html | -text | -man ]
49*1da177e4SLinus Torvalds#           [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
50*1da177e4SLinus Torvalds# or
51*1da177e4SLinus Torvalds#           [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
52*1da177e4SLinus Torvalds#
53*1da177e4SLinus Torvalds#  Set output format using one of -docbook -html -text or -man.  Default is man.
54*1da177e4SLinus Torvalds#
55*1da177e4SLinus Torvalds#  -function funcname
56*1da177e4SLinus Torvalds#	If set, then only generate documentation for the given function(s).  All
57*1da177e4SLinus Torvalds#	other functions are ignored.
58*1da177e4SLinus Torvalds#
59*1da177e4SLinus Torvalds#  -nofunction funcname
60*1da177e4SLinus Torvalds#	If set, then only generate documentation for the other function(s).  All
61*1da177e4SLinus Torvalds#	other functions are ignored. Cannot be used with -function together
62*1da177e4SLinus Torvalds#	(yes thats a bug - perl hackers can fix it 8))
63*1da177e4SLinus Torvalds#
64*1da177e4SLinus Torvalds#  c files - list of 'c' files to process
65*1da177e4SLinus Torvalds#
66*1da177e4SLinus Torvalds#  All output goes to stdout, with errors to stderr.
67*1da177e4SLinus Torvalds
68*1da177e4SLinus Torvalds#
69*1da177e4SLinus Torvalds# format of comments.
70*1da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure.
71*1da177e4SLinus Torvalds#                         (...)* signifies 0 or more structure elements
72*1da177e4SLinus Torvalds# /**
73*1da177e4SLinus Torvalds#  * function_name(:)? (- short description)?
74*1da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)*
75*1da177e4SLinus Torvalds# (* a blank line)?
76*1da177e4SLinus Torvalds#  * (Description:)? (Description of function)?
77*1da177e4SLinus Torvalds#  * (section header: (section description)? )*
78*1da177e4SLinus Torvalds#  (*)?*/
79*1da177e4SLinus Torvalds#
80*1da177e4SLinus Torvalds# So .. the trivial example would be:
81*1da177e4SLinus Torvalds#
82*1da177e4SLinus Torvalds# /**
83*1da177e4SLinus Torvalds#  * my_function
84*1da177e4SLinus Torvalds#  **/
85*1da177e4SLinus Torvalds#
86*1da177e4SLinus Torvalds# If the Description: header tag is ommitted, then there must be a blank line
87*1da177e4SLinus Torvalds# after the last parameter specification.
88*1da177e4SLinus Torvalds# e.g.
89*1da177e4SLinus Torvalds# /**
90*1da177e4SLinus Torvalds#  * my_function - does my stuff
91*1da177e4SLinus Torvalds#  * @my_arg: its mine damnit
92*1da177e4SLinus Torvalds#  *
93*1da177e4SLinus Torvalds#  * Does my stuff explained.
94*1da177e4SLinus Torvalds#  */
95*1da177e4SLinus Torvalds#
96*1da177e4SLinus Torvalds#  or, could also use:
97*1da177e4SLinus Torvalds# /**
98*1da177e4SLinus Torvalds#  * my_function - does my stuff
99*1da177e4SLinus Torvalds#  * @my_arg: its mine damnit
100*1da177e4SLinus Torvalds#  * Description: Does my stuff explained.
101*1da177e4SLinus Torvalds#  */
102*1da177e4SLinus Torvalds# etc.
103*1da177e4SLinus Torvalds#
104*1da177e4SLinus Torvalds# Beside functions you can also write documentation for structs, unions,
105*1da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name
106*1da177e4SLinus Torvalds# of the declaration;  the struct/union/enum/typedef must always precede
107*1da177e4SLinus Torvalds# the name. Nesting of declarations is not supported.
108*1da177e4SLinus Torvalds# Use the argument mechanism to document members or constants.
109*1da177e4SLinus Torvalds# e.g.
110*1da177e4SLinus Torvalds# /**
111*1da177e4SLinus Torvalds#  * struct my_struct - short description
112*1da177e4SLinus Torvalds#  * @a: first member
113*1da177e4SLinus Torvalds#  * @b: second member
114*1da177e4SLinus Torvalds#  *
115*1da177e4SLinus Torvalds#  * Longer description
116*1da177e4SLinus Torvalds#  */
117*1da177e4SLinus Torvalds# struct my_struct {
118*1da177e4SLinus Torvalds#     int a;
119*1da177e4SLinus Torvalds#     int b;
120*1da177e4SLinus Torvalds# };
121*1da177e4SLinus Torvalds#
122*1da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description.
123*1da177e4SLinus Torvalds#
124*1da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you
125*1da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions
126*1da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an
127*1da177e4SLinus Torvalds# empty line.
128*1da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked
129*1da177e4SLinus Torvalds# appropriately in DocBook.
130*1da177e4SLinus Torvalds#
131*1da177e4SLinus Torvalds# Example:
132*1da177e4SLinus Torvalds# /**
133*1da177e4SLinus Torvalds#  * user_function - function that can only be called in user context
134*1da177e4SLinus Torvalds#  * @a: some argument
135*1da177e4SLinus Torvalds#  * Context: !in_interrupt()
136*1da177e4SLinus Torvalds#  *
137*1da177e4SLinus Torvalds#  * Some description
138*1da177e4SLinus Torvalds#  * Example:
139*1da177e4SLinus Torvalds#  *    user_function(22);
140*1da177e4SLinus Torvalds#  */
141*1da177e4SLinus Torvalds# ...
142*1da177e4SLinus Torvalds#
143*1da177e4SLinus Torvalds#
144*1da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special
145*1da177e4SLinus Torvalds# patterns, which are highlighted appropriately.
146*1da177e4SLinus Torvalds#
147*1da177e4SLinus Torvalds# 'funcname()' - function
148*1da177e4SLinus Torvalds# '$ENVVAR' - environmental variable
149*1da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct')
150*1da177e4SLinus Torvalds# '@parameter' - name of a parameter
151*1da177e4SLinus Torvalds# '%CONST' - name of a constant.
152*1da177e4SLinus Torvalds
153*1da177e4SLinus Torvaldsmy $errors = 0;
154*1da177e4SLinus Torvaldsmy $warnings = 0;
155*1da177e4SLinus Torvalds
156*1da177e4SLinus Torvalds# match expressions used to find embedded type information
157*1da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)';
158*1da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)';
159*1da177e4SLinus Torvaldsmy $type_param = '\@(\w+)';
160*1da177e4SLinus Torvaldsmy $type_struct = '\&((struct\s*)?[_\w]+)';
161*1da177e4SLinus Torvaldsmy $type_env = '(\$\w+)';
162*1da177e4SLinus Torvalds
163*1da177e4SLinus Torvalds# Output conversion substitutions.
164*1da177e4SLinus Torvalds#  One for each output format
165*1da177e4SLinus Torvalds
166*1da177e4SLinus Torvalds# these work fairly well
167*1da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>",
168*1da177e4SLinus Torvalds			$type_func, "<b>\$1</b>",
169*1da177e4SLinus Torvalds			$type_struct, "<i>\$1</i>",
170*1da177e4SLinus Torvalds			$type_param, "<tt><b>\$1</b></tt>" );
171*1da177e4SLinus Torvaldsmy $blankline_html = "<p>";
172*1da177e4SLinus Torvalds
173*1da177e4SLinus Torvalds# XML, docbook format
174*1da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
175*1da177e4SLinus Torvalds			$type_constant, "<constant>\$1</constant>",
176*1da177e4SLinus Torvalds			$type_func, "<function>\$1</function>",
177*1da177e4SLinus Torvalds			$type_struct, "<structname>\$1</structname>",
178*1da177e4SLinus Torvalds			$type_env, "<envar>\$1</envar>",
179*1da177e4SLinus Torvalds			$type_param, "<parameter>\$1</parameter>" );
180*1da177e4SLinus Torvaldsmy $blankline_xml = "</para><para>\n";
181*1da177e4SLinus Torvalds
182*1da177e4SLinus Torvalds# gnome, docbook format
183*1da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
184*1da177e4SLinus Torvalds			 $type_func, "<function>\$1</function>",
185*1da177e4SLinus Torvalds			 $type_struct, "<structname>\$1</structname>",
186*1da177e4SLinus Torvalds			 $type_env, "<envar>\$1</envar>",
187*1da177e4SLinus Torvalds			 $type_param, "<parameter>\$1</parameter>" );
188*1da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n";
189*1da177e4SLinus Torvalds
190*1da177e4SLinus Torvalds# these are pretty rough
191*1da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1",
192*1da177e4SLinus Torvalds		       $type_func, "\\\\fB\$1\\\\fP",
193*1da177e4SLinus Torvalds		       $type_struct, "\\\\fI\$1\\\\fP",
194*1da177e4SLinus Torvalds		       $type_param, "\\\\fI\$1\\\\fP" );
195*1da177e4SLinus Torvaldsmy $blankline_man = "";
196*1da177e4SLinus Torvalds
197*1da177e4SLinus Torvalds# text-mode
198*1da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1",
199*1da177e4SLinus Torvalds			$type_func, "\$1",
200*1da177e4SLinus Torvalds			$type_struct, "\$1",
201*1da177e4SLinus Torvalds			$type_param, "\$1" );
202*1da177e4SLinus Torvaldsmy $blankline_text = "";
203*1da177e4SLinus Torvalds
204*1da177e4SLinus Torvalds
205*1da177e4SLinus Torvaldssub usage {
206*1da177e4SLinus Torvalds    print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n";
207*1da177e4SLinus Torvalds    print "         [ -function funcname [ -function funcname ...] ]\n";
208*1da177e4SLinus Torvalds    print "         [ -nofunction funcname [ -nofunction funcname ...] ]\n";
209*1da177e4SLinus Torvalds    print "         c source file(s) > outputfile\n";
210*1da177e4SLinus Torvalds    exit 1;
211*1da177e4SLinus Torvalds}
212*1da177e4SLinus Torvalds
213*1da177e4SLinus Torvalds# read arguments
214*1da177e4SLinus Torvaldsif ($#ARGV==-1) {
215*1da177e4SLinus Torvalds    usage();
216*1da177e4SLinus Torvalds}
217*1da177e4SLinus Torvalds
218*1da177e4SLinus Torvaldsmy $verbose = 0;
219*1da177e4SLinus Torvaldsmy $output_mode = "man";
220*1da177e4SLinus Torvaldsmy %highlights = %highlights_man;
221*1da177e4SLinus Torvaldsmy $blankline = $blankline_man;
222*1da177e4SLinus Torvaldsmy $modulename = "Kernel API";
223*1da177e4SLinus Torvaldsmy $function_only = 0;
224*1da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
225*1da177e4SLinus Torvalds		'July', 'August', 'September', 'October',
226*1da177e4SLinus Torvalds		'November', 'December')[(localtime)[4]] .
227*1da177e4SLinus Torvalds  " " . ((localtime)[5]+1900);
228*1da177e4SLinus Torvalds
229*1da177e4SLinus Torvalds# Essentially these are globals
230*1da177e4SLinus Torvalds# They probably want to be tidied up made more localised or summat.
231*1da177e4SLinus Torvalds# CAVEAT EMPTOR!  Some of the others I localised may not want to be which
232*1da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs.
233*1da177e4SLinus Torvaldsmy ($function, %function_table,%parametertypes,$declaration_purpose);
234*1da177e4SLinus Torvaldsmy ($type,$declaration_name,$return_type);
235*1da177e4SLinus Torvaldsmy ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
236*1da177e4SLinus Torvalds
237*1da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where
238*1da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
239*1da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
240*1da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy
241*1da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed
242*1da177e4SLinus Torvalds# into html.
243*1da177e4SLinus Torvaldsmy $section_counter = 0;
244*1da177e4SLinus Torvalds
245*1da177e4SLinus Torvaldsmy $lineprefix="";
246*1da177e4SLinus Torvalds
247*1da177e4SLinus Torvalds# states
248*1da177e4SLinus Torvalds# 0 - normal code
249*1da177e4SLinus Torvalds# 1 - looking for function name
250*1da177e4SLinus Torvalds# 2 - scanning field start.
251*1da177e4SLinus Torvalds# 3 - scanning prototype.
252*1da177e4SLinus Torvalds# 4 - documentation block
253*1da177e4SLinus Torvaldsmy $state;
254*1da177e4SLinus Torvalds
255*1da177e4SLinus Torvalds#declaration types: can be
256*1da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef'
257*1da177e4SLinus Torvaldsmy $decl_type;
258*1da177e4SLinus Torvalds
259*1da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&";
260*1da177e4SLinus Torvalds
261*1da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
262*1da177e4SLinus Torvaldsmy $doc_end = '\*/';
263*1da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*';
264*1da177e4SLinus Torvaldsmy $doc_decl = $doc_com.'(\w+)';
265*1da177e4SLinus Torvaldsmy $doc_sect = $doc_com.'(['.$doc_special.']?[\w ]+):(.*)';
266*1da177e4SLinus Torvaldsmy $doc_content = $doc_com.'(.*)';
267*1da177e4SLinus Torvaldsmy $doc_block = $doc_com.'DOC:\s*(.*)?';
268*1da177e4SLinus Torvalds
269*1da177e4SLinus Torvaldsmy %constants;
270*1da177e4SLinus Torvaldsmy %parameterdescs;
271*1da177e4SLinus Torvaldsmy @parameterlist;
272*1da177e4SLinus Torvaldsmy %sections;
273*1da177e4SLinus Torvaldsmy @sectionlist;
274*1da177e4SLinus Torvalds
275*1da177e4SLinus Torvaldsmy $contents = "";
276*1da177e4SLinus Torvaldsmy $section_default = "Description";	# default section
277*1da177e4SLinus Torvaldsmy $section_intro = "Introduction";
278*1da177e4SLinus Torvaldsmy $section = $section_default;
279*1da177e4SLinus Torvaldsmy $section_context = "Context";
280*1da177e4SLinus Torvalds
281*1da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --";
282*1da177e4SLinus Torvalds
283*1da177e4SLinus Torvaldsreset_state();
284*1da177e4SLinus Torvalds
285*1da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) {
286*1da177e4SLinus Torvalds    my $cmd = shift @ARGV;
287*1da177e4SLinus Torvalds    if ($cmd eq "-html") {
288*1da177e4SLinus Torvalds	$output_mode = "html";
289*1da177e4SLinus Torvalds	%highlights = %highlights_html;
290*1da177e4SLinus Torvalds	$blankline = $blankline_html;
291*1da177e4SLinus Torvalds    } elsif ($cmd eq "-man") {
292*1da177e4SLinus Torvalds	$output_mode = "man";
293*1da177e4SLinus Torvalds	%highlights = %highlights_man;
294*1da177e4SLinus Torvalds	$blankline = $blankline_man;
295*1da177e4SLinus Torvalds    } elsif ($cmd eq "-text") {
296*1da177e4SLinus Torvalds	$output_mode = "text";
297*1da177e4SLinus Torvalds	%highlights = %highlights_text;
298*1da177e4SLinus Torvalds	$blankline = $blankline_text;
299*1da177e4SLinus Torvalds    } elsif ($cmd eq "-docbook") {
300*1da177e4SLinus Torvalds	$output_mode = "xml";
301*1da177e4SLinus Torvalds	%highlights = %highlights_xml;
302*1da177e4SLinus Torvalds	$blankline = $blankline_xml;
303*1da177e4SLinus Torvalds    } elsif ($cmd eq "-gnome") {
304*1da177e4SLinus Torvalds	$output_mode = "gnome";
305*1da177e4SLinus Torvalds	%highlights = %highlights_gnome;
306*1da177e4SLinus Torvalds	$blankline = $blankline_gnome;
307*1da177e4SLinus Torvalds    } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
308*1da177e4SLinus Torvalds	$modulename = shift @ARGV;
309*1da177e4SLinus Torvalds    } elsif ($cmd eq "-function") { # to only output specific functions
310*1da177e4SLinus Torvalds	$function_only = 1;
311*1da177e4SLinus Torvalds	$function = shift @ARGV;
312*1da177e4SLinus Torvalds	$function_table{$function} = 1;
313*1da177e4SLinus Torvalds    } elsif ($cmd eq "-nofunction") { # to only output specific functions
314*1da177e4SLinus Torvalds	$function_only = 2;
315*1da177e4SLinus Torvalds	$function = shift @ARGV;
316*1da177e4SLinus Torvalds	$function_table{$function} = 1;
317*1da177e4SLinus Torvalds    } elsif ($cmd eq "-v") {
318*1da177e4SLinus Torvalds	$verbose = 1;
319*1da177e4SLinus Torvalds    } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
320*1da177e4SLinus Torvalds	usage();
321*1da177e4SLinus Torvalds    } elsif ($cmd eq '-filelist') {
322*1da177e4SLinus Torvalds	    $filelist = shift @ARGV;
323*1da177e4SLinus Torvalds    }
324*1da177e4SLinus Torvalds}
325*1da177e4SLinus Torvalds
326*1da177e4SLinus Torvalds
327*1da177e4SLinus Torvalds# generate a sequence of code that will splice in highlighting information
328*1da177e4SLinus Torvalds# using the s// operator.
329*1da177e4SLinus Torvaldsmy $dohighlight = "";
330*1da177e4SLinus Torvaldsforeach my $pattern (keys %highlights) {
331*1da177e4SLinus Torvalds#    print "scanning pattern $pattern ($highlights{$pattern})\n";
332*1da177e4SLinus Torvalds    $dohighlight .=  "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
333*1da177e4SLinus Torvalds}
334*1da177e4SLinus Torvalds
335*1da177e4SLinus Torvalds##
336*1da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose.
337*1da177e4SLinus Torvalds#
338*1da177e4SLinus Torvaldssub dump_section {
339*1da177e4SLinus Torvalds    my $name = shift;
340*1da177e4SLinus Torvalds    my $contents = join "\n", @_;
341*1da177e4SLinus Torvalds
342*1da177e4SLinus Torvalds    if ($name =~ m/$type_constant/) {
343*1da177e4SLinus Torvalds	$name = $1;
344*1da177e4SLinus Torvalds#	print STDERR "constant section '$1' = '$contents'\n";
345*1da177e4SLinus Torvalds	$constants{$name} = $contents;
346*1da177e4SLinus Torvalds    } elsif ($name =~ m/$type_param/) {
347*1da177e4SLinus Torvalds#	print STDERR "parameter def '$1' = '$contents'\n";
348*1da177e4SLinus Torvalds	$name = $1;
349*1da177e4SLinus Torvalds	$parameterdescs{$name} = $contents;
350*1da177e4SLinus Torvalds    } else {
351*1da177e4SLinus Torvalds#	print STDERR "other section '$name' = '$contents'\n";
352*1da177e4SLinus Torvalds	$sections{$name} = $contents;
353*1da177e4SLinus Torvalds	push @sectionlist, $name;
354*1da177e4SLinus Torvalds    }
355*1da177e4SLinus Torvalds}
356*1da177e4SLinus Torvalds
357*1da177e4SLinus Torvalds##
358*1da177e4SLinus Torvalds# output function
359*1da177e4SLinus Torvalds#
360*1da177e4SLinus Torvalds# parameterdescs, a hash.
361*1da177e4SLinus Torvalds#  function => "function name"
362*1da177e4SLinus Torvalds#  parameterlist => @list of parameters
363*1da177e4SLinus Torvalds#  parameterdescs => %parameter descriptions
364*1da177e4SLinus Torvalds#  sectionlist => @list of sections
365*1da177e4SLinus Torvalds#  sections => %descriont descriptions
366*1da177e4SLinus Torvalds#
367*1da177e4SLinus Torvalds
368*1da177e4SLinus Torvaldssub output_highlight {
369*1da177e4SLinus Torvalds    my $contents = join "\n",@_;
370*1da177e4SLinus Torvalds    my $line;
371*1da177e4SLinus Torvalds
372*1da177e4SLinus Torvalds#   DEBUG
373*1da177e4SLinus Torvalds#   if (!defined $contents) {
374*1da177e4SLinus Torvalds#	use Carp;
375*1da177e4SLinus Torvalds#	confess "output_highlight got called with no args?\n";
376*1da177e4SLinus Torvalds#   }
377*1da177e4SLinus Torvalds
378*1da177e4SLinus Torvalds    eval $dohighlight;
379*1da177e4SLinus Torvalds    die $@ if $@;
380*1da177e4SLinus Torvalds    foreach $line (split "\n", $contents) {
381*1da177e4SLinus Torvalds      if ($line eq ""){
382*1da177e4SLinus Torvalds	    print $lineprefix, $blankline;
383*1da177e4SLinus Torvalds	} else {
384*1da177e4SLinus Torvalds            $line =~ s/\\\\\\/\&/g;
385*1da177e4SLinus Torvalds	    print $lineprefix, $line;
386*1da177e4SLinus Torvalds	}
387*1da177e4SLinus Torvalds	print "\n";
388*1da177e4SLinus Torvalds    }
389*1da177e4SLinus Torvalds}
390*1da177e4SLinus Torvalds
391*1da177e4SLinus Torvalds#output sections in html
392*1da177e4SLinus Torvaldssub output_section_html(%) {
393*1da177e4SLinus Torvalds    my %args = %{$_[0]};
394*1da177e4SLinus Torvalds    my $section;
395*1da177e4SLinus Torvalds
396*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
397*1da177e4SLinus Torvalds	print "<h3>$section</h3>\n";
398*1da177e4SLinus Torvalds	print "<blockquote>\n";
399*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
400*1da177e4SLinus Torvalds	print "</blockquote>\n";
401*1da177e4SLinus Torvalds    }
402*1da177e4SLinus Torvalds}
403*1da177e4SLinus Torvalds
404*1da177e4SLinus Torvalds# output enum in html
405*1da177e4SLinus Torvaldssub output_enum_html(%) {
406*1da177e4SLinus Torvalds    my %args = %{$_[0]};
407*1da177e4SLinus Torvalds    my ($parameter);
408*1da177e4SLinus Torvalds    my $count;
409*1da177e4SLinus Torvalds    print "<h2>enum ".$args{'enum'}."</h2>\n";
410*1da177e4SLinus Torvalds
411*1da177e4SLinus Torvalds    print "<b>enum ".$args{'enum'}."</b> {<br>\n";
412*1da177e4SLinus Torvalds    $count = 0;
413*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
414*1da177e4SLinus Torvalds        print " <b>".$parameter."</b>";
415*1da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
416*1da177e4SLinus Torvalds	    $count++;
417*1da177e4SLinus Torvalds	    print ",\n";
418*1da177e4SLinus Torvalds	}
419*1da177e4SLinus Torvalds	print "<br>";
420*1da177e4SLinus Torvalds    }
421*1da177e4SLinus Torvalds    print "};<br>\n";
422*1da177e4SLinus Torvalds
423*1da177e4SLinus Torvalds    print "<h3>Constants</h3>\n";
424*1da177e4SLinus Torvalds    print "<dl>\n";
425*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
426*1da177e4SLinus Torvalds	print "<dt><b>".$parameter."</b>\n";
427*1da177e4SLinus Torvalds	print "<dd>";
428*1da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter});
429*1da177e4SLinus Torvalds    }
430*1da177e4SLinus Torvalds    print "</dl>\n";
431*1da177e4SLinus Torvalds    output_section_html(@_);
432*1da177e4SLinus Torvalds    print "<hr>\n";
433*1da177e4SLinus Torvalds}
434*1da177e4SLinus Torvalds
435*1da177e4SLinus Torvalds# output tyepdef in html
436*1da177e4SLinus Torvaldssub output_typedef_html(%) {
437*1da177e4SLinus Torvalds    my %args = %{$_[0]};
438*1da177e4SLinus Torvalds    my ($parameter);
439*1da177e4SLinus Torvalds    my $count;
440*1da177e4SLinus Torvalds    print "<h2>typedef ".$args{'typedef'}."</h2>\n";
441*1da177e4SLinus Torvalds
442*1da177e4SLinus Torvalds    print "<b>typedef ".$args{'typedef'}."</b>\n";
443*1da177e4SLinus Torvalds    output_section_html(@_);
444*1da177e4SLinus Torvalds    print "<hr>\n";
445*1da177e4SLinus Torvalds}
446*1da177e4SLinus Torvalds
447*1da177e4SLinus Torvalds# output struct in html
448*1da177e4SLinus Torvaldssub output_struct_html(%) {
449*1da177e4SLinus Torvalds    my %args = %{$_[0]};
450*1da177e4SLinus Torvalds    my ($parameter);
451*1da177e4SLinus Torvalds
452*1da177e4SLinus Torvalds    print "<h2>".$args{'type'}." ".$args{'struct'}."</h2>\n";
453*1da177e4SLinus Torvalds    print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
454*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
455*1da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
456*1da177e4SLinus Torvalds		print "$parameter<br>\n";
457*1da177e4SLinus Torvalds		next;
458*1da177e4SLinus Torvalds	}
459*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
460*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
461*1da177e4SLinus Torvalds
462*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
463*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
464*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
465*1da177e4SLinus Torvalds	    # pointer-to-function
466*1da177e4SLinus Torvalds	    print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
467*1da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
468*1da177e4SLinus Torvalds	    print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
469*1da177e4SLinus Torvalds	} else {
470*1da177e4SLinus Torvalds	    print " <i>$type</i> <b>$parameter</b>;<br>\n";
471*1da177e4SLinus Torvalds	}
472*1da177e4SLinus Torvalds    }
473*1da177e4SLinus Torvalds    print "};<br>\n";
474*1da177e4SLinus Torvalds
475*1da177e4SLinus Torvalds    print "<h3>Members</h3>\n";
476*1da177e4SLinus Torvalds    print "<dl>\n";
477*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
478*1da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
479*1da177e4SLinus Torvalds
480*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
481*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
482*1da177e4SLinus Torvalds
483*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
484*1da177e4SLinus Torvalds	print "<dt><b>".$parameter."</b>\n";
485*1da177e4SLinus Torvalds	print "<dd>";
486*1da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
487*1da177e4SLinus Torvalds    }
488*1da177e4SLinus Torvalds    print "</dl>\n";
489*1da177e4SLinus Torvalds    output_section_html(@_);
490*1da177e4SLinus Torvalds    print "<hr>\n";
491*1da177e4SLinus Torvalds}
492*1da177e4SLinus Torvalds
493*1da177e4SLinus Torvalds# output function in html
494*1da177e4SLinus Torvaldssub output_function_html(%) {
495*1da177e4SLinus Torvalds    my %args = %{$_[0]};
496*1da177e4SLinus Torvalds    my ($parameter, $section);
497*1da177e4SLinus Torvalds    my $count;
498*1da177e4SLinus Torvalds    print "<h2>Function</h2>\n";
499*1da177e4SLinus Torvalds
500*1da177e4SLinus Torvalds    print "<i>".$args{'functiontype'}."</i>\n";
501*1da177e4SLinus Torvalds    print "<b>".$args{'function'}."</b>\n";
502*1da177e4SLinus Torvalds    print "(";
503*1da177e4SLinus Torvalds    $count = 0;
504*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
505*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
506*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
507*1da177e4SLinus Torvalds	    # pointer-to-function
508*1da177e4SLinus Torvalds	    print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
509*1da177e4SLinus Torvalds	} else {
510*1da177e4SLinus Torvalds	    print "<i>".$type."</i> <b>".$parameter."</b>";
511*1da177e4SLinus Torvalds	}
512*1da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
513*1da177e4SLinus Torvalds	    $count++;
514*1da177e4SLinus Torvalds	    print ",\n";
515*1da177e4SLinus Torvalds	}
516*1da177e4SLinus Torvalds    }
517*1da177e4SLinus Torvalds    print ")\n";
518*1da177e4SLinus Torvalds
519*1da177e4SLinus Torvalds    print "<h3>Arguments</h3>\n";
520*1da177e4SLinus Torvalds    print "<dl>\n";
521*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
522*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
523*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
524*1da177e4SLinus Torvalds
525*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
526*1da177e4SLinus Torvalds	print "<dt><b>".$parameter."</b>\n";
527*1da177e4SLinus Torvalds	print "<dd>";
528*1da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
529*1da177e4SLinus Torvalds    }
530*1da177e4SLinus Torvalds    print "</dl>\n";
531*1da177e4SLinus Torvalds    output_section_html(@_);
532*1da177e4SLinus Torvalds    print "<hr>\n";
533*1da177e4SLinus Torvalds}
534*1da177e4SLinus Torvalds
535*1da177e4SLinus Torvalds# output intro in html
536*1da177e4SLinus Torvaldssub output_intro_html(%) {
537*1da177e4SLinus Torvalds    my %args = %{$_[0]};
538*1da177e4SLinus Torvalds    my ($parameter, $section);
539*1da177e4SLinus Torvalds    my $count;
540*1da177e4SLinus Torvalds
541*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
542*1da177e4SLinus Torvalds	print "<h3>$section</h3>\n";
543*1da177e4SLinus Torvalds	print "<ul>\n";
544*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
545*1da177e4SLinus Torvalds	print "</ul>\n";
546*1da177e4SLinus Torvalds    }
547*1da177e4SLinus Torvalds    print "<hr>\n";
548*1da177e4SLinus Torvalds}
549*1da177e4SLinus Torvalds
550*1da177e4SLinus Torvaldssub output_section_xml(%) {
551*1da177e4SLinus Torvalds    my %args = %{$_[0]};
552*1da177e4SLinus Torvalds    my $section;
553*1da177e4SLinus Torvalds    # print out each section
554*1da177e4SLinus Torvalds    $lineprefix="   ";
555*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
556*1da177e4SLinus Torvalds	print "<refsect1>\n <title>$section</title>\n <para>\n";
557*1da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
558*1da177e4SLinus Torvalds	    print "<example><para>\n";
559*1da177e4SLinus Torvalds	}
560*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
561*1da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
562*1da177e4SLinus Torvalds	    print "</para></example>\n";
563*1da177e4SLinus Torvalds	}
564*1da177e4SLinus Torvalds	print " </para>\n</refsect1>\n";
565*1da177e4SLinus Torvalds    }
566*1da177e4SLinus Torvalds}
567*1da177e4SLinus Torvalds
568*1da177e4SLinus Torvalds# output function in XML DocBook
569*1da177e4SLinus Torvaldssub output_function_xml(%) {
570*1da177e4SLinus Torvalds    my %args = %{$_[0]};
571*1da177e4SLinus Torvalds    my ($parameter, $section);
572*1da177e4SLinus Torvalds    my $count;
573*1da177e4SLinus Torvalds    my $id;
574*1da177e4SLinus Torvalds
575*1da177e4SLinus Torvalds    $id = "API-".$args{'function'};
576*1da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
577*1da177e4SLinus Torvalds
578*1da177e4SLinus Torvalds    print "<refentry>\n";
579*1da177e4SLinus Torvalds    print "<refmeta>\n";
580*1da177e4SLinus Torvalds    print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
581*1da177e4SLinus Torvalds    print "</refmeta>\n";
582*1da177e4SLinus Torvalds    print "<refnamediv>\n";
583*1da177e4SLinus Torvalds    print " <refname>".$args{'function'}."</refname>\n";
584*1da177e4SLinus Torvalds    print " <refpurpose>\n";
585*1da177e4SLinus Torvalds    print "  ";
586*1da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
587*1da177e4SLinus Torvalds    print " </refpurpose>\n";
588*1da177e4SLinus Torvalds    print "</refnamediv>\n";
589*1da177e4SLinus Torvalds
590*1da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
591*1da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
592*1da177e4SLinus Torvalds    print "  <funcsynopsis><funcprototype>\n";
593*1da177e4SLinus Torvalds    print "   <funcdef>".$args{'functiontype'}." ";
594*1da177e4SLinus Torvalds    print "<function>".$args{'function'}." </function></funcdef>\n";
595*1da177e4SLinus Torvalds
596*1da177e4SLinus Torvalds    $count = 0;
597*1da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
598*1da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
599*1da177e4SLinus Torvalds	    $type = $args{'parametertypes'}{$parameter};
600*1da177e4SLinus Torvalds	    if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
601*1da177e4SLinus Torvalds		# pointer-to-function
602*1da177e4SLinus Torvalds		print "   <paramdef>$1<parameter>$parameter</parameter>)\n";
603*1da177e4SLinus Torvalds		print "     <funcparams>$2</funcparams></paramdef>\n";
604*1da177e4SLinus Torvalds	    } else {
605*1da177e4SLinus Torvalds		print "   <paramdef>".$type;
606*1da177e4SLinus Torvalds		print " <parameter>$parameter</parameter></paramdef>\n";
607*1da177e4SLinus Torvalds	    }
608*1da177e4SLinus Torvalds	}
609*1da177e4SLinus Torvalds    } else {
610*1da177e4SLinus Torvalds	print "  <void>\n";
611*1da177e4SLinus Torvalds    }
612*1da177e4SLinus Torvalds    print "  </funcprototype></funcsynopsis>\n";
613*1da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
614*1da177e4SLinus Torvalds
615*1da177e4SLinus Torvalds    # print parameters
616*1da177e4SLinus Torvalds    print "<refsect1>\n <title>Arguments</title>\n";
617*1da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
618*1da177e4SLinus Torvalds	print " <variablelist>\n";
619*1da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
620*1da177e4SLinus Torvalds	    my $parameter_name = $parameter;
621*1da177e4SLinus Torvalds	    $parameter_name =~ s/\[.*//;
622*1da177e4SLinus Torvalds
623*1da177e4SLinus Torvalds	    print "  <varlistentry>\n   <term><parameter>$parameter</parameter></term>\n";
624*1da177e4SLinus Torvalds	    print "   <listitem>\n    <para>\n";
625*1da177e4SLinus Torvalds	    $lineprefix="     ";
626*1da177e4SLinus Torvalds	    output_highlight($args{'parameterdescs'}{$parameter_name});
627*1da177e4SLinus Torvalds	    print "    </para>\n   </listitem>\n  </varlistentry>\n";
628*1da177e4SLinus Torvalds	}
629*1da177e4SLinus Torvalds	print " </variablelist>\n";
630*1da177e4SLinus Torvalds    } else {
631*1da177e4SLinus Torvalds	print " <para>\n  None\n </para>\n";
632*1da177e4SLinus Torvalds    }
633*1da177e4SLinus Torvalds    print "</refsect1>\n";
634*1da177e4SLinus Torvalds
635*1da177e4SLinus Torvalds    output_section_xml(@_);
636*1da177e4SLinus Torvalds    print "</refentry>\n\n";
637*1da177e4SLinus Torvalds}
638*1da177e4SLinus Torvalds
639*1da177e4SLinus Torvalds# output struct in XML DocBook
640*1da177e4SLinus Torvaldssub output_struct_xml(%) {
641*1da177e4SLinus Torvalds    my %args = %{$_[0]};
642*1da177e4SLinus Torvalds    my ($parameter, $section);
643*1da177e4SLinus Torvalds    my $id;
644*1da177e4SLinus Torvalds
645*1da177e4SLinus Torvalds    $id = "API-struct-".$args{'struct'};
646*1da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
647*1da177e4SLinus Torvalds
648*1da177e4SLinus Torvalds    print "<refentry>\n";
649*1da177e4SLinus Torvalds    print "<refmeta>\n";
650*1da177e4SLinus Torvalds    print "<refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
651*1da177e4SLinus Torvalds    print "</refmeta>\n";
652*1da177e4SLinus Torvalds    print "<refnamediv>\n";
653*1da177e4SLinus Torvalds    print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
654*1da177e4SLinus Torvalds    print " <refpurpose>\n";
655*1da177e4SLinus Torvalds    print "  ";
656*1da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
657*1da177e4SLinus Torvalds    print " </refpurpose>\n";
658*1da177e4SLinus Torvalds    print "</refnamediv>\n";
659*1da177e4SLinus Torvalds
660*1da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
661*1da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
662*1da177e4SLinus Torvalds    print "  <programlisting>\n";
663*1da177e4SLinus Torvalds    print $args{'type'}." ".$args{'struct'}." {\n";
664*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
665*1da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
666*1da177e4SLinus Torvalds	    print "$parameter\n";
667*1da177e4SLinus Torvalds	    next;
668*1da177e4SLinus Torvalds	}
669*1da177e4SLinus Torvalds
670*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
671*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
672*1da177e4SLinus Torvalds
673*1da177e4SLinus Torvalds	defined($args{'parameterdescs'}{$parameter_name}) || next;
674*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
675*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
676*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
677*1da177e4SLinus Torvalds	    # pointer-to-function
678*1da177e4SLinus Torvalds	    print "  $1 $parameter) ($2);\n";
679*1da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
680*1da177e4SLinus Torvalds	    print "  $1 $parameter$2;\n";
681*1da177e4SLinus Torvalds	} else {
682*1da177e4SLinus Torvalds	    print "  ".$type." ".$parameter.";\n";
683*1da177e4SLinus Torvalds	}
684*1da177e4SLinus Torvalds    }
685*1da177e4SLinus Torvalds    print "};";
686*1da177e4SLinus Torvalds    print "  </programlisting>\n";
687*1da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
688*1da177e4SLinus Torvalds
689*1da177e4SLinus Torvalds    print " <refsect1>\n";
690*1da177e4SLinus Torvalds    print "  <title>Members</title>\n";
691*1da177e4SLinus Torvalds
692*1da177e4SLinus Torvalds    print "  <variablelist>\n";
693*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
694*1da177e4SLinus Torvalds      ($parameter =~ /^#/) && next;
695*1da177e4SLinus Torvalds
696*1da177e4SLinus Torvalds      my $parameter_name = $parameter;
697*1da177e4SLinus Torvalds      $parameter_name =~ s/\[.*//;
698*1da177e4SLinus Torvalds
699*1da177e4SLinus Torvalds      defined($args{'parameterdescs'}{$parameter_name}) || next;
700*1da177e4SLinus Torvalds      ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
701*1da177e4SLinus Torvalds      print "    <varlistentry>";
702*1da177e4SLinus Torvalds      print "      <term>$parameter</term>\n";
703*1da177e4SLinus Torvalds      print "      <listitem><para>\n";
704*1da177e4SLinus Torvalds      output_highlight($args{'parameterdescs'}{$parameter_name});
705*1da177e4SLinus Torvalds      print "      </para></listitem>\n";
706*1da177e4SLinus Torvalds      print "    </varlistentry>\n";
707*1da177e4SLinus Torvalds    }
708*1da177e4SLinus Torvalds    print "  </variablelist>\n";
709*1da177e4SLinus Torvalds    print " </refsect1>\n";
710*1da177e4SLinus Torvalds
711*1da177e4SLinus Torvalds    output_section_xml(@_);
712*1da177e4SLinus Torvalds
713*1da177e4SLinus Torvalds    print "</refentry>\n\n";
714*1da177e4SLinus Torvalds}
715*1da177e4SLinus Torvalds
716*1da177e4SLinus Torvalds# output enum in XML DocBook
717*1da177e4SLinus Torvaldssub output_enum_xml(%) {
718*1da177e4SLinus Torvalds    my %args = %{$_[0]};
719*1da177e4SLinus Torvalds    my ($parameter, $section);
720*1da177e4SLinus Torvalds    my $count;
721*1da177e4SLinus Torvalds    my $id;
722*1da177e4SLinus Torvalds
723*1da177e4SLinus Torvalds    $id = "API-enum-".$args{'enum'};
724*1da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
725*1da177e4SLinus Torvalds
726*1da177e4SLinus Torvalds    print "<refentry>\n";
727*1da177e4SLinus Torvalds    print "<refmeta>\n";
728*1da177e4SLinus Torvalds    print "<refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n";
729*1da177e4SLinus Torvalds    print "</refmeta>\n";
730*1da177e4SLinus Torvalds    print "<refnamediv>\n";
731*1da177e4SLinus Torvalds    print " <refname>enum ".$args{'enum'}."</refname>\n";
732*1da177e4SLinus Torvalds    print " <refpurpose>\n";
733*1da177e4SLinus Torvalds    print "  ";
734*1da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
735*1da177e4SLinus Torvalds    print " </refpurpose>\n";
736*1da177e4SLinus Torvalds    print "</refnamediv>\n";
737*1da177e4SLinus Torvalds
738*1da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
739*1da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
740*1da177e4SLinus Torvalds    print "  <programlisting>\n";
741*1da177e4SLinus Torvalds    print "enum ".$args{'enum'}." {\n";
742*1da177e4SLinus Torvalds    $count = 0;
743*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
744*1da177e4SLinus Torvalds        print "  $parameter";
745*1da177e4SLinus Torvalds        if ($count != $#{$args{'parameterlist'}}) {
746*1da177e4SLinus Torvalds	    $count++;
747*1da177e4SLinus Torvalds	    print ",";
748*1da177e4SLinus Torvalds        }
749*1da177e4SLinus Torvalds	print "\n";
750*1da177e4SLinus Torvalds    }
751*1da177e4SLinus Torvalds    print "};";
752*1da177e4SLinus Torvalds    print "  </programlisting>\n";
753*1da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
754*1da177e4SLinus Torvalds
755*1da177e4SLinus Torvalds    print "<refsect1>\n";
756*1da177e4SLinus Torvalds    print " <title>Constants</title>\n";
757*1da177e4SLinus Torvalds    print "  <variablelist>\n";
758*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
759*1da177e4SLinus Torvalds      my $parameter_name = $parameter;
760*1da177e4SLinus Torvalds      $parameter_name =~ s/\[.*//;
761*1da177e4SLinus Torvalds
762*1da177e4SLinus Torvalds      print "    <varlistentry>";
763*1da177e4SLinus Torvalds      print "      <term>$parameter</term>\n";
764*1da177e4SLinus Torvalds      print "      <listitem><para>\n";
765*1da177e4SLinus Torvalds      output_highlight($args{'parameterdescs'}{$parameter_name});
766*1da177e4SLinus Torvalds      print "      </para></listitem>\n";
767*1da177e4SLinus Torvalds      print "    </varlistentry>\n";
768*1da177e4SLinus Torvalds    }
769*1da177e4SLinus Torvalds    print "  </variablelist>\n";
770*1da177e4SLinus Torvalds    print "</refsect1>\n";
771*1da177e4SLinus Torvalds
772*1da177e4SLinus Torvalds    output_section_xml(@_);
773*1da177e4SLinus Torvalds
774*1da177e4SLinus Torvalds    print "</refentry>\n\n";
775*1da177e4SLinus Torvalds}
776*1da177e4SLinus Torvalds
777*1da177e4SLinus Torvalds# output typedef in XML DocBook
778*1da177e4SLinus Torvaldssub output_typedef_xml(%) {
779*1da177e4SLinus Torvalds    my %args = %{$_[0]};
780*1da177e4SLinus Torvalds    my ($parameter, $section);
781*1da177e4SLinus Torvalds    my $id;
782*1da177e4SLinus Torvalds
783*1da177e4SLinus Torvalds    $id = "API-typedef-".$args{'typedef'};
784*1da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
785*1da177e4SLinus Torvalds
786*1da177e4SLinus Torvalds    print "<refentry>\n";
787*1da177e4SLinus Torvalds    print "<refmeta>\n";
788*1da177e4SLinus Torvalds    print "<refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
789*1da177e4SLinus Torvalds    print "</refmeta>\n";
790*1da177e4SLinus Torvalds    print "<refnamediv>\n";
791*1da177e4SLinus Torvalds    print " <refname>typedef ".$args{'typedef'}."</refname>\n";
792*1da177e4SLinus Torvalds    print " <refpurpose>\n";
793*1da177e4SLinus Torvalds    print "  ";
794*1da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
795*1da177e4SLinus Torvalds    print " </refpurpose>\n";
796*1da177e4SLinus Torvalds    print "</refnamediv>\n";
797*1da177e4SLinus Torvalds
798*1da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
799*1da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
800*1da177e4SLinus Torvalds    print "  <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
801*1da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
802*1da177e4SLinus Torvalds
803*1da177e4SLinus Torvalds    output_section_xml(@_);
804*1da177e4SLinus Torvalds
805*1da177e4SLinus Torvalds    print "</refentry>\n\n";
806*1da177e4SLinus Torvalds}
807*1da177e4SLinus Torvalds
808*1da177e4SLinus Torvalds# output in XML DocBook
809*1da177e4SLinus Torvaldssub output_intro_xml(%) {
810*1da177e4SLinus Torvalds    my %args = %{$_[0]};
811*1da177e4SLinus Torvalds    my ($parameter, $section);
812*1da177e4SLinus Torvalds    my $count;
813*1da177e4SLinus Torvalds
814*1da177e4SLinus Torvalds    my $id = $args{'module'};
815*1da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
816*1da177e4SLinus Torvalds
817*1da177e4SLinus Torvalds    # print out each section
818*1da177e4SLinus Torvalds    $lineprefix="   ";
819*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
820*1da177e4SLinus Torvalds	print "<refsect1>\n <title>$section</title>\n <para>\n";
821*1da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
822*1da177e4SLinus Torvalds	    print "<example><para>\n";
823*1da177e4SLinus Torvalds	}
824*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
825*1da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
826*1da177e4SLinus Torvalds	    print "</para></example>\n";
827*1da177e4SLinus Torvalds	}
828*1da177e4SLinus Torvalds	print " </para>\n</refsect1>\n";
829*1da177e4SLinus Torvalds    }
830*1da177e4SLinus Torvalds
831*1da177e4SLinus Torvalds    print "\n\n";
832*1da177e4SLinus Torvalds}
833*1da177e4SLinus Torvalds
834*1da177e4SLinus Torvalds# output in XML DocBook
835*1da177e4SLinus Torvaldssub output_function_gnome {
836*1da177e4SLinus Torvalds    my %args = %{$_[0]};
837*1da177e4SLinus Torvalds    my ($parameter, $section);
838*1da177e4SLinus Torvalds    my $count;
839*1da177e4SLinus Torvalds    my $id;
840*1da177e4SLinus Torvalds
841*1da177e4SLinus Torvalds    $id = $args{'module'}."-".$args{'function'};
842*1da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
843*1da177e4SLinus Torvalds
844*1da177e4SLinus Torvalds    print "<sect2>\n";
845*1da177e4SLinus Torvalds    print " <title id=\"$id\">".$args{'function'}."</title>\n";
846*1da177e4SLinus Torvalds
847*1da177e4SLinus Torvalds    print "  <funcsynopsis>\n";
848*1da177e4SLinus Torvalds    print "   <funcdef>".$args{'functiontype'}." ";
849*1da177e4SLinus Torvalds    print "<function>".$args{'function'}." ";
850*1da177e4SLinus Torvalds    print "</function></funcdef>\n";
851*1da177e4SLinus Torvalds
852*1da177e4SLinus Torvalds    $count = 0;
853*1da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
854*1da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
855*1da177e4SLinus Torvalds	    $type = $args{'parametertypes'}{$parameter};
856*1da177e4SLinus Torvalds	    if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
857*1da177e4SLinus Torvalds		# pointer-to-function
858*1da177e4SLinus Torvalds		print "   <paramdef>$1 <parameter>$parameter</parameter>)\n";
859*1da177e4SLinus Torvalds		print "     <funcparams>$2</funcparams></paramdef>\n";
860*1da177e4SLinus Torvalds	    } else {
861*1da177e4SLinus Torvalds		print "   <paramdef>".$type;
862*1da177e4SLinus Torvalds		print " <parameter>$parameter</parameter></paramdef>\n";
863*1da177e4SLinus Torvalds	    }
864*1da177e4SLinus Torvalds	}
865*1da177e4SLinus Torvalds    } else {
866*1da177e4SLinus Torvalds	print "  <void>\n";
867*1da177e4SLinus Torvalds    }
868*1da177e4SLinus Torvalds    print "  </funcsynopsis>\n";
869*1da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
870*1da177e4SLinus Torvalds	print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
871*1da177e4SLinus Torvalds	print "<tgroup cols=\"2\">\n";
872*1da177e4SLinus Torvalds	print "<colspec colwidth=\"2*\">\n";
873*1da177e4SLinus Torvalds	print "<colspec colwidth=\"8*\">\n";
874*1da177e4SLinus Torvalds	print "<tbody>\n";
875*1da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
876*1da177e4SLinus Torvalds	    my $parameter_name = $parameter;
877*1da177e4SLinus Torvalds	    $parameter_name =~ s/\[.*//;
878*1da177e4SLinus Torvalds
879*1da177e4SLinus Torvalds	    print "  <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
880*1da177e4SLinus Torvalds	    print "   <entry>\n";
881*1da177e4SLinus Torvalds	    $lineprefix="     ";
882*1da177e4SLinus Torvalds	    output_highlight($args{'parameterdescs'}{$parameter_name});
883*1da177e4SLinus Torvalds	    print "    </entry></row>\n";
884*1da177e4SLinus Torvalds	}
885*1da177e4SLinus Torvalds	print " </tbody></tgroup></informaltable>\n";
886*1da177e4SLinus Torvalds    } else {
887*1da177e4SLinus Torvalds	print " <para>\n  None\n </para>\n";
888*1da177e4SLinus Torvalds    }
889*1da177e4SLinus Torvalds
890*1da177e4SLinus Torvalds    # print out each section
891*1da177e4SLinus Torvalds    $lineprefix="   ";
892*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
893*1da177e4SLinus Torvalds	print "<simplesect>\n <title>$section</title>\n";
894*1da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
895*1da177e4SLinus Torvalds	    print "<example><programlisting>\n";
896*1da177e4SLinus Torvalds	} else {
897*1da177e4SLinus Torvalds	}
898*1da177e4SLinus Torvalds	print "<para>\n";
899*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
900*1da177e4SLinus Torvalds	print "</para>\n";
901*1da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
902*1da177e4SLinus Torvalds	    print "</programlisting></example>\n";
903*1da177e4SLinus Torvalds	} else {
904*1da177e4SLinus Torvalds	}
905*1da177e4SLinus Torvalds	print " </simplesect>\n";
906*1da177e4SLinus Torvalds    }
907*1da177e4SLinus Torvalds
908*1da177e4SLinus Torvalds    print "</sect2>\n\n";
909*1da177e4SLinus Torvalds}
910*1da177e4SLinus Torvalds
911*1da177e4SLinus Torvalds##
912*1da177e4SLinus Torvalds# output function in man
913*1da177e4SLinus Torvaldssub output_function_man(%) {
914*1da177e4SLinus Torvalds    my %args = %{$_[0]};
915*1da177e4SLinus Torvalds    my ($parameter, $section);
916*1da177e4SLinus Torvalds    my $count;
917*1da177e4SLinus Torvalds
918*1da177e4SLinus Torvalds    print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
919*1da177e4SLinus Torvalds
920*1da177e4SLinus Torvalds    print ".SH NAME\n";
921*1da177e4SLinus Torvalds    print $args{'function'}." \\- ".$args{'purpose'}."\n";
922*1da177e4SLinus Torvalds
923*1da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
924*1da177e4SLinus Torvalds    print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
925*1da177e4SLinus Torvalds    $count = 0;
926*1da177e4SLinus Torvalds    my $parenth = "(";
927*1da177e4SLinus Torvalds    my $post = ",";
928*1da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
929*1da177e4SLinus Torvalds	if ($count == $#{$args{'parameterlist'}}) {
930*1da177e4SLinus Torvalds	    $post = ");";
931*1da177e4SLinus Torvalds	}
932*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
933*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
934*1da177e4SLinus Torvalds	    # pointer-to-function
935*1da177e4SLinus Torvalds	    print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
936*1da177e4SLinus Torvalds	} else {
937*1da177e4SLinus Torvalds	    $type =~ s/([^\*])$/$1 /;
938*1da177e4SLinus Torvalds	    print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
939*1da177e4SLinus Torvalds	}
940*1da177e4SLinus Torvalds	$count++;
941*1da177e4SLinus Torvalds	$parenth = "";
942*1da177e4SLinus Torvalds    }
943*1da177e4SLinus Torvalds
944*1da177e4SLinus Torvalds    print ".SH ARGUMENTS\n";
945*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
946*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
947*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
948*1da177e4SLinus Torvalds
949*1da177e4SLinus Torvalds	print ".IP \"".$parameter."\" 12\n";
950*1da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
951*1da177e4SLinus Torvalds    }
952*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
953*1da177e4SLinus Torvalds	print ".SH \"", uc $section, "\"\n";
954*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
955*1da177e4SLinus Torvalds    }
956*1da177e4SLinus Torvalds}
957*1da177e4SLinus Torvalds
958*1da177e4SLinus Torvalds##
959*1da177e4SLinus Torvalds# output enum in man
960*1da177e4SLinus Torvaldssub output_enum_man(%) {
961*1da177e4SLinus Torvalds    my %args = %{$_[0]};
962*1da177e4SLinus Torvalds    my ($parameter, $section);
963*1da177e4SLinus Torvalds    my $count;
964*1da177e4SLinus Torvalds
965*1da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
966*1da177e4SLinus Torvalds
967*1da177e4SLinus Torvalds    print ".SH NAME\n";
968*1da177e4SLinus Torvalds    print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
969*1da177e4SLinus Torvalds
970*1da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
971*1da177e4SLinus Torvalds    print "enum ".$args{'enum'}." {\n";
972*1da177e4SLinus Torvalds    $count = 0;
973*1da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
974*1da177e4SLinus Torvalds        print ".br\n.BI \"    $parameter\"\n";
975*1da177e4SLinus Torvalds	if ($count == $#{$args{'parameterlist'}}) {
976*1da177e4SLinus Torvalds	    print "\n};\n";
977*1da177e4SLinus Torvalds	    last;
978*1da177e4SLinus Torvalds	}
979*1da177e4SLinus Torvalds	else {
980*1da177e4SLinus Torvalds	    print ", \n.br\n";
981*1da177e4SLinus Torvalds	}
982*1da177e4SLinus Torvalds	$count++;
983*1da177e4SLinus Torvalds    }
984*1da177e4SLinus Torvalds
985*1da177e4SLinus Torvalds    print ".SH Constants\n";
986*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
987*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
988*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
989*1da177e4SLinus Torvalds
990*1da177e4SLinus Torvalds	print ".IP \"".$parameter."\" 12\n";
991*1da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
992*1da177e4SLinus Torvalds    }
993*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
994*1da177e4SLinus Torvalds	print ".SH \"$section\"\n";
995*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
996*1da177e4SLinus Torvalds    }
997*1da177e4SLinus Torvalds}
998*1da177e4SLinus Torvalds
999*1da177e4SLinus Torvalds##
1000*1da177e4SLinus Torvalds# output struct in man
1001*1da177e4SLinus Torvaldssub output_struct_man(%) {
1002*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1003*1da177e4SLinus Torvalds    my ($parameter, $section);
1004*1da177e4SLinus Torvalds
1005*1da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1006*1da177e4SLinus Torvalds
1007*1da177e4SLinus Torvalds    print ".SH NAME\n";
1008*1da177e4SLinus Torvalds    print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1009*1da177e4SLinus Torvalds
1010*1da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
1011*1da177e4SLinus Torvalds    print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1012*1da177e4SLinus Torvalds
1013*1da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
1014*1da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
1015*1da177e4SLinus Torvalds	    print ".BI \"$parameter\"\n.br\n";
1016*1da177e4SLinus Torvalds	    next;
1017*1da177e4SLinus Torvalds	}
1018*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
1019*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
1020*1da177e4SLinus Torvalds
1021*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1022*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
1023*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1024*1da177e4SLinus Torvalds	    # pointer-to-function
1025*1da177e4SLinus Torvalds	    print ".BI \"    ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1026*1da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1027*1da177e4SLinus Torvalds	    print ".BI \"    ".$1."\" ".$parameter.$2." \""."\"\n;\n";
1028*1da177e4SLinus Torvalds	} else {
1029*1da177e4SLinus Torvalds	    $type =~ s/([^\*])$/$1 /;
1030*1da177e4SLinus Torvalds	    print ".BI \"    ".$type."\" ".$parameter." \""."\"\n;\n";
1031*1da177e4SLinus Torvalds	}
1032*1da177e4SLinus Torvalds	print "\n.br\n";
1033*1da177e4SLinus Torvalds    }
1034*1da177e4SLinus Torvalds    print "};\n.br\n";
1035*1da177e4SLinus Torvalds
1036*1da177e4SLinus Torvalds    print ".SH Arguments\n";
1037*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
1038*1da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
1039*1da177e4SLinus Torvalds
1040*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
1041*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
1042*1da177e4SLinus Torvalds
1043*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1044*1da177e4SLinus Torvalds	print ".IP \"".$parameter."\" 12\n";
1045*1da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
1046*1da177e4SLinus Torvalds    }
1047*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1048*1da177e4SLinus Torvalds	print ".SH \"$section\"\n";
1049*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1050*1da177e4SLinus Torvalds    }
1051*1da177e4SLinus Torvalds}
1052*1da177e4SLinus Torvalds
1053*1da177e4SLinus Torvalds##
1054*1da177e4SLinus Torvalds# output typedef in man
1055*1da177e4SLinus Torvaldssub output_typedef_man(%) {
1056*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1057*1da177e4SLinus Torvalds    my ($parameter, $section);
1058*1da177e4SLinus Torvalds
1059*1da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1060*1da177e4SLinus Torvalds
1061*1da177e4SLinus Torvalds    print ".SH NAME\n";
1062*1da177e4SLinus Torvalds    print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1063*1da177e4SLinus Torvalds
1064*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1065*1da177e4SLinus Torvalds	print ".SH \"$section\"\n";
1066*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1067*1da177e4SLinus Torvalds    }
1068*1da177e4SLinus Torvalds}
1069*1da177e4SLinus Torvalds
1070*1da177e4SLinus Torvaldssub output_intro_man(%) {
1071*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1072*1da177e4SLinus Torvalds    my ($parameter, $section);
1073*1da177e4SLinus Torvalds    my $count;
1074*1da177e4SLinus Torvalds
1075*1da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1076*1da177e4SLinus Torvalds
1077*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1078*1da177e4SLinus Torvalds	print ".SH \"$section\"\n";
1079*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1080*1da177e4SLinus Torvalds    }
1081*1da177e4SLinus Torvalds}
1082*1da177e4SLinus Torvalds
1083*1da177e4SLinus Torvalds##
1084*1da177e4SLinus Torvalds# output in text
1085*1da177e4SLinus Torvaldssub output_function_text(%) {
1086*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1087*1da177e4SLinus Torvalds    my ($parameter, $section);
1088*1da177e4SLinus Torvalds
1089*1da177e4SLinus Torvalds    print "Function:\n\n";
1090*1da177e4SLinus Torvalds    my $start=$args{'functiontype'}." ".$args{'function'}." (";
1091*1da177e4SLinus Torvalds    print $start;
1092*1da177e4SLinus Torvalds    my $count = 0;
1093*1da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
1094*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
1095*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1096*1da177e4SLinus Torvalds	    # pointer-to-function
1097*1da177e4SLinus Torvalds	    print $1.$parameter.") (".$2;
1098*1da177e4SLinus Torvalds	} else {
1099*1da177e4SLinus Torvalds	    print $type." ".$parameter;
1100*1da177e4SLinus Torvalds	}
1101*1da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
1102*1da177e4SLinus Torvalds	    $count++;
1103*1da177e4SLinus Torvalds	    print ",\n";
1104*1da177e4SLinus Torvalds	    print " " x length($start);
1105*1da177e4SLinus Torvalds	} else {
1106*1da177e4SLinus Torvalds	    print ");\n\n";
1107*1da177e4SLinus Torvalds	}
1108*1da177e4SLinus Torvalds    }
1109*1da177e4SLinus Torvalds
1110*1da177e4SLinus Torvalds    print "Arguments:\n\n";
1111*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
1112*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
1113*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
1114*1da177e4SLinus Torvalds
1115*1da177e4SLinus Torvalds	print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1116*1da177e4SLinus Torvalds    }
1117*1da177e4SLinus Torvalds    output_section_text(@_);
1118*1da177e4SLinus Torvalds}
1119*1da177e4SLinus Torvalds
1120*1da177e4SLinus Torvalds#output sections in text
1121*1da177e4SLinus Torvaldssub output_section_text(%) {
1122*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1123*1da177e4SLinus Torvalds    my $section;
1124*1da177e4SLinus Torvalds
1125*1da177e4SLinus Torvalds    print "\n";
1126*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1127*1da177e4SLinus Torvalds	print "$section:\n\n";
1128*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1129*1da177e4SLinus Torvalds    }
1130*1da177e4SLinus Torvalds    print "\n\n";
1131*1da177e4SLinus Torvalds}
1132*1da177e4SLinus Torvalds
1133*1da177e4SLinus Torvalds# output enum in text
1134*1da177e4SLinus Torvaldssub output_enum_text(%) {
1135*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1136*1da177e4SLinus Torvalds    my ($parameter);
1137*1da177e4SLinus Torvalds    my $count;
1138*1da177e4SLinus Torvalds    print "Enum:\n\n";
1139*1da177e4SLinus Torvalds
1140*1da177e4SLinus Torvalds    print "enum ".$args{'enum'}." {\n";
1141*1da177e4SLinus Torvalds    $count = 0;
1142*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
1143*1da177e4SLinus Torvalds        print "\t$parameter";
1144*1da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
1145*1da177e4SLinus Torvalds	    $count++;
1146*1da177e4SLinus Torvalds	    print ",";
1147*1da177e4SLinus Torvalds	}
1148*1da177e4SLinus Torvalds	print "\n";
1149*1da177e4SLinus Torvalds    }
1150*1da177e4SLinus Torvalds    print "};\n\n";
1151*1da177e4SLinus Torvalds
1152*1da177e4SLinus Torvalds    print "Constants:\n\n";
1153*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
1154*1da177e4SLinus Torvalds	print "$parameter\n\t";
1155*1da177e4SLinus Torvalds	print $args{'parameterdescs'}{$parameter}."\n";
1156*1da177e4SLinus Torvalds    }
1157*1da177e4SLinus Torvalds
1158*1da177e4SLinus Torvalds    output_section_text(@_);
1159*1da177e4SLinus Torvalds}
1160*1da177e4SLinus Torvalds
1161*1da177e4SLinus Torvalds# output typedef in text
1162*1da177e4SLinus Torvaldssub output_typedef_text(%) {
1163*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1164*1da177e4SLinus Torvalds    my ($parameter);
1165*1da177e4SLinus Torvalds    my $count;
1166*1da177e4SLinus Torvalds    print "Typedef:\n\n";
1167*1da177e4SLinus Torvalds
1168*1da177e4SLinus Torvalds    print "typedef ".$args{'typedef'}."\n";
1169*1da177e4SLinus Torvalds    output_section_text(@_);
1170*1da177e4SLinus Torvalds}
1171*1da177e4SLinus Torvalds
1172*1da177e4SLinus Torvalds# output struct as text
1173*1da177e4SLinus Torvaldssub output_struct_text(%) {
1174*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1175*1da177e4SLinus Torvalds    my ($parameter);
1176*1da177e4SLinus Torvalds
1177*1da177e4SLinus Torvalds    print $args{'type'}." ".$args{'struct'}.":\n\n";
1178*1da177e4SLinus Torvalds    print $args{'type'}." ".$args{'struct'}." {\n";
1179*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
1180*1da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
1181*1da177e4SLinus Torvalds	    print "$parameter\n";
1182*1da177e4SLinus Torvalds	    next;
1183*1da177e4SLinus Torvalds	}
1184*1da177e4SLinus Torvalds
1185*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
1186*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
1187*1da177e4SLinus Torvalds
1188*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1189*1da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
1190*1da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1191*1da177e4SLinus Torvalds	    # pointer-to-function
1192*1da177e4SLinus Torvalds	    print "\t$1 $parameter) ($2);\n";
1193*1da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1194*1da177e4SLinus Torvalds	    print "\t$1 $parameter$2;\n";
1195*1da177e4SLinus Torvalds	} else {
1196*1da177e4SLinus Torvalds	    print "\t".$type." ".$parameter.";\n";
1197*1da177e4SLinus Torvalds	}
1198*1da177e4SLinus Torvalds    }
1199*1da177e4SLinus Torvalds    print "};\n\n";
1200*1da177e4SLinus Torvalds
1201*1da177e4SLinus Torvalds    print "Members:\n\n";
1202*1da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
1203*1da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
1204*1da177e4SLinus Torvalds
1205*1da177e4SLinus Torvalds	my $parameter_name = $parameter;
1206*1da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
1207*1da177e4SLinus Torvalds
1208*1da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1209*1da177e4SLinus Torvalds	print "$parameter\n\t";
1210*1da177e4SLinus Torvalds	print $args{'parameterdescs'}{$parameter_name}."\n";
1211*1da177e4SLinus Torvalds    }
1212*1da177e4SLinus Torvalds    print "\n";
1213*1da177e4SLinus Torvalds    output_section_text(@_);
1214*1da177e4SLinus Torvalds}
1215*1da177e4SLinus Torvalds
1216*1da177e4SLinus Torvaldssub output_intro_text(%) {
1217*1da177e4SLinus Torvalds    my %args = %{$_[0]};
1218*1da177e4SLinus Torvalds    my ($parameter, $section);
1219*1da177e4SLinus Torvalds
1220*1da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1221*1da177e4SLinus Torvalds	print " $section:\n";
1222*1da177e4SLinus Torvalds	print "    -> ";
1223*1da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1224*1da177e4SLinus Torvalds    }
1225*1da177e4SLinus Torvalds}
1226*1da177e4SLinus Torvalds
1227*1da177e4SLinus Torvalds##
1228*1da177e4SLinus Torvalds# generic output function for typedefs
1229*1da177e4SLinus Torvaldssub output_declaration {
1230*1da177e4SLinus Torvalds    no strict 'refs';
1231*1da177e4SLinus Torvalds    my $name = shift;
1232*1da177e4SLinus Torvalds    my $functype = shift;
1233*1da177e4SLinus Torvalds    my $func = "output_${functype}_$output_mode";
1234*1da177e4SLinus Torvalds    if (($function_only==0) ||
1235*1da177e4SLinus Torvalds	( $function_only == 1 && defined($function_table{$name})) ||
1236*1da177e4SLinus Torvalds	( $function_only == 2 && !defined($function_table{$name})))
1237*1da177e4SLinus Torvalds    {
1238*1da177e4SLinus Torvalds        &$func(@_);
1239*1da177e4SLinus Torvalds	$section_counter++;
1240*1da177e4SLinus Torvalds    }
1241*1da177e4SLinus Torvalds}
1242*1da177e4SLinus Torvalds
1243*1da177e4SLinus Torvalds##
1244*1da177e4SLinus Torvalds# generic output function - calls the right one based
1245*1da177e4SLinus Torvalds# on current output mode.
1246*1da177e4SLinus Torvaldssub output_intro {
1247*1da177e4SLinus Torvalds    no strict 'refs';
1248*1da177e4SLinus Torvalds    my $func = "output_intro_".$output_mode;
1249*1da177e4SLinus Torvalds    &$func(@_);
1250*1da177e4SLinus Torvalds    $section_counter++;
1251*1da177e4SLinus Torvalds}
1252*1da177e4SLinus Torvalds
1253*1da177e4SLinus Torvalds##
1254*1da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and
1255*1da177e4SLinus Torvalds# invokes the right handler. NOT called for functions.
1256*1da177e4SLinus Torvaldssub dump_declaration($$) {
1257*1da177e4SLinus Torvalds    no strict 'refs';
1258*1da177e4SLinus Torvalds    my ($prototype, $file) = @_;
1259*1da177e4SLinus Torvalds    my $func = "dump_".$decl_type;
1260*1da177e4SLinus Torvalds    &$func(@_);
1261*1da177e4SLinus Torvalds}
1262*1da177e4SLinus Torvalds
1263*1da177e4SLinus Torvaldssub dump_union($$) {
1264*1da177e4SLinus Torvalds    dump_struct(@_);
1265*1da177e4SLinus Torvalds}
1266*1da177e4SLinus Torvalds
1267*1da177e4SLinus Torvaldssub dump_struct($$) {
1268*1da177e4SLinus Torvalds    my $x = shift;
1269*1da177e4SLinus Torvalds    my $file = shift;
1270*1da177e4SLinus Torvalds
1271*1da177e4SLinus Torvalds    if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1272*1da177e4SLinus Torvalds        $declaration_name = $2;
1273*1da177e4SLinus Torvalds        my $members = $3;
1274*1da177e4SLinus Torvalds
1275*1da177e4SLinus Torvalds	# ignore embedded structs or unions
1276*1da177e4SLinus Torvalds	$members =~ s/{.*?}//g;
1277*1da177e4SLinus Torvalds
1278*1da177e4SLinus Torvalds	create_parameterlist($members, ';', $file);
1279*1da177e4SLinus Torvalds
1280*1da177e4SLinus Torvalds	output_declaration($declaration_name,
1281*1da177e4SLinus Torvalds			   'struct',
1282*1da177e4SLinus Torvalds			   {'struct' => $declaration_name,
1283*1da177e4SLinus Torvalds			    'module' => $modulename,
1284*1da177e4SLinus Torvalds			    'parameterlist' => \@parameterlist,
1285*1da177e4SLinus Torvalds			    'parameterdescs' => \%parameterdescs,
1286*1da177e4SLinus Torvalds			    'parametertypes' => \%parametertypes,
1287*1da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
1288*1da177e4SLinus Torvalds			    'sections' => \%sections,
1289*1da177e4SLinus Torvalds			    'purpose' => $declaration_purpose,
1290*1da177e4SLinus Torvalds			    'type' => $decl_type
1291*1da177e4SLinus Torvalds			   });
1292*1da177e4SLinus Torvalds    }
1293*1da177e4SLinus Torvalds    else {
1294*1da177e4SLinus Torvalds        print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1295*1da177e4SLinus Torvalds	++$errors;
1296*1da177e4SLinus Torvalds    }
1297*1da177e4SLinus Torvalds}
1298*1da177e4SLinus Torvalds
1299*1da177e4SLinus Torvaldssub dump_enum($$) {
1300*1da177e4SLinus Torvalds    my $x = shift;
1301*1da177e4SLinus Torvalds    my $file = shift;
1302*1da177e4SLinus Torvalds
1303*1da177e4SLinus Torvalds    if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1304*1da177e4SLinus Torvalds        $declaration_name = $1;
1305*1da177e4SLinus Torvalds        my $members = $2;
1306*1da177e4SLinus Torvalds
1307*1da177e4SLinus Torvalds	foreach my $arg (split ',', $members) {
1308*1da177e4SLinus Torvalds	    $arg =~ s/^\s*(\w+).*/$1/;
1309*1da177e4SLinus Torvalds	    push @parameterlist, $arg;
1310*1da177e4SLinus Torvalds	    if (!$parameterdescs{$arg}) {
1311*1da177e4SLinus Torvalds	        $parameterdescs{$arg} = $undescribed;
1312*1da177e4SLinus Torvalds	        print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1313*1da177e4SLinus Torvalds		    "not described in enum '$declaration_name'\n";
1314*1da177e4SLinus Torvalds	    }
1315*1da177e4SLinus Torvalds
1316*1da177e4SLinus Torvalds	}
1317*1da177e4SLinus Torvalds
1318*1da177e4SLinus Torvalds	output_declaration($declaration_name,
1319*1da177e4SLinus Torvalds			   'enum',
1320*1da177e4SLinus Torvalds			   {'enum' => $declaration_name,
1321*1da177e4SLinus Torvalds			    'module' => $modulename,
1322*1da177e4SLinus Torvalds			    'parameterlist' => \@parameterlist,
1323*1da177e4SLinus Torvalds			    'parameterdescs' => \%parameterdescs,
1324*1da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
1325*1da177e4SLinus Torvalds			    'sections' => \%sections,
1326*1da177e4SLinus Torvalds			    'purpose' => $declaration_purpose
1327*1da177e4SLinus Torvalds			   });
1328*1da177e4SLinus Torvalds    }
1329*1da177e4SLinus Torvalds    else {
1330*1da177e4SLinus Torvalds        print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1331*1da177e4SLinus Torvalds	++$errors;
1332*1da177e4SLinus Torvalds    }
1333*1da177e4SLinus Torvalds}
1334*1da177e4SLinus Torvalds
1335*1da177e4SLinus Torvaldssub dump_typedef($$) {
1336*1da177e4SLinus Torvalds    my $x = shift;
1337*1da177e4SLinus Torvalds    my $file = shift;
1338*1da177e4SLinus Torvalds
1339*1da177e4SLinus Torvalds    while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1340*1da177e4SLinus Torvalds        $x =~ s/\(*.\)\s*;$/;/;
1341*1da177e4SLinus Torvalds	$x =~ s/\[*.\]\s*;$/;/;
1342*1da177e4SLinus Torvalds    }
1343*1da177e4SLinus Torvalds
1344*1da177e4SLinus Torvalds    if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1345*1da177e4SLinus Torvalds        $declaration_name = $1;
1346*1da177e4SLinus Torvalds
1347*1da177e4SLinus Torvalds	output_declaration($declaration_name,
1348*1da177e4SLinus Torvalds			   'typedef',
1349*1da177e4SLinus Torvalds			   {'typedef' => $declaration_name,
1350*1da177e4SLinus Torvalds			    'module' => $modulename,
1351*1da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
1352*1da177e4SLinus Torvalds			    'sections' => \%sections,
1353*1da177e4SLinus Torvalds			    'purpose' => $declaration_purpose
1354*1da177e4SLinus Torvalds			   });
1355*1da177e4SLinus Torvalds    }
1356*1da177e4SLinus Torvalds    else {
1357*1da177e4SLinus Torvalds        print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1358*1da177e4SLinus Torvalds	++$errors;
1359*1da177e4SLinus Torvalds    }
1360*1da177e4SLinus Torvalds}
1361*1da177e4SLinus Torvalds
1362*1da177e4SLinus Torvaldssub create_parameterlist($$$) {
1363*1da177e4SLinus Torvalds    my $args = shift;
1364*1da177e4SLinus Torvalds    my $splitter = shift;
1365*1da177e4SLinus Torvalds    my $file = shift;
1366*1da177e4SLinus Torvalds    my $type;
1367*1da177e4SLinus Torvalds    my $param;
1368*1da177e4SLinus Torvalds
1369*1da177e4SLinus Torvalds    while ($args =~ /(\([^\),]+),/) {
1370*1da177e4SLinus Torvalds        $args =~ s/(\([^\),]+),/$1#/g;
1371*1da177e4SLinus Torvalds    }
1372*1da177e4SLinus Torvalds
1373*1da177e4SLinus Torvalds    foreach my $arg (split($splitter, $args)) {
1374*1da177e4SLinus Torvalds	# strip comments
1375*1da177e4SLinus Torvalds	$arg =~ s/\/\*.*\*\///;
1376*1da177e4SLinus Torvalds        # strip leading/trailing spaces
1377*1da177e4SLinus Torvalds        $arg =~ s/^\s*//;
1378*1da177e4SLinus Torvalds	$arg =~ s/\s*$//;
1379*1da177e4SLinus Torvalds	$arg =~ s/\s+/ /;
1380*1da177e4SLinus Torvalds
1381*1da177e4SLinus Torvalds	if ($arg =~ /^#/) {
1382*1da177e4SLinus Torvalds	    # Treat preprocessor directive as a typeless variable just to fill
1383*1da177e4SLinus Torvalds	    # corresponding data structures "correctly". Catch it later in
1384*1da177e4SLinus Torvalds	    # output_* subs.
1385*1da177e4SLinus Torvalds	    push_parameter($arg, "", $file);
1386*1da177e4SLinus Torvalds	} elsif ($arg =~ m/\(/) {
1387*1da177e4SLinus Torvalds	    # pointer-to-function
1388*1da177e4SLinus Torvalds	    $arg =~ tr/#/,/;
1389*1da177e4SLinus Torvalds	    $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
1390*1da177e4SLinus Torvalds	    $param = $1;
1391*1da177e4SLinus Torvalds	    $type = $arg;
1392*1da177e4SLinus Torvalds	    $type =~ s/([^\(]+\(\*)$param/$1/;
1393*1da177e4SLinus Torvalds	    push_parameter($param, $type, $file);
1394*1da177e4SLinus Torvalds	} else {
1395*1da177e4SLinus Torvalds	    $arg =~ s/\s*:\s*/:/g;
1396*1da177e4SLinus Torvalds	    $arg =~ s/\s*\[/\[/g;
1397*1da177e4SLinus Torvalds
1398*1da177e4SLinus Torvalds	    my @args = split('\s*,\s*', $arg);
1399*1da177e4SLinus Torvalds	    if ($args[0] =~ m/\*/) {
1400*1da177e4SLinus Torvalds		$args[0] =~ s/(\*+)\s*/ $1/;
1401*1da177e4SLinus Torvalds	    }
1402*1da177e4SLinus Torvalds	    my @first_arg = split('\s+', shift @args);
1403*1da177e4SLinus Torvalds	    unshift(@args, pop @first_arg);
1404*1da177e4SLinus Torvalds	    $type = join " ", @first_arg;
1405*1da177e4SLinus Torvalds
1406*1da177e4SLinus Torvalds	    foreach $param (@args) {
1407*1da177e4SLinus Torvalds		if ($param =~ m/^(\*+)\s*(.*)/) {
1408*1da177e4SLinus Torvalds		    push_parameter($2, "$type $1", $file);
1409*1da177e4SLinus Torvalds		}
1410*1da177e4SLinus Torvalds		elsif ($param =~ m/(.*?):(\d+)/) {
1411*1da177e4SLinus Torvalds		    push_parameter($1, "$type:$2", $file)
1412*1da177e4SLinus Torvalds		}
1413*1da177e4SLinus Torvalds		else {
1414*1da177e4SLinus Torvalds		    push_parameter($param, $type, $file);
1415*1da177e4SLinus Torvalds		}
1416*1da177e4SLinus Torvalds	    }
1417*1da177e4SLinus Torvalds	}
1418*1da177e4SLinus Torvalds    }
1419*1da177e4SLinus Torvalds}
1420*1da177e4SLinus Torvalds
1421*1da177e4SLinus Torvaldssub push_parameter($$$) {
1422*1da177e4SLinus Torvalds	my $param = shift;
1423*1da177e4SLinus Torvalds	my $type = shift;
1424*1da177e4SLinus Torvalds	my $file = shift;
1425*1da177e4SLinus Torvalds
1426*1da177e4SLinus Torvalds	my $param_name = $param;
1427*1da177e4SLinus Torvalds	$param_name =~ s/\[.*//;
1428*1da177e4SLinus Torvalds
1429*1da177e4SLinus Torvalds	if ($type eq "" && $param eq "...")
1430*1da177e4SLinus Torvalds	{
1431*1da177e4SLinus Torvalds	    $type="";
1432*1da177e4SLinus Torvalds	    $param="...";
1433*1da177e4SLinus Torvalds	    $parameterdescs{"..."} = "variable arguments";
1434*1da177e4SLinus Torvalds	}
1435*1da177e4SLinus Torvalds	elsif ($type eq "" && ($param eq "" or $param eq "void"))
1436*1da177e4SLinus Torvalds	{
1437*1da177e4SLinus Torvalds	    $type="";
1438*1da177e4SLinus Torvalds	    $param="void";
1439*1da177e4SLinus Torvalds	    $parameterdescs{void} = "no arguments";
1440*1da177e4SLinus Torvalds	}
1441*1da177e4SLinus Torvalds	if (defined $type && $type && !defined $parameterdescs{$param_name}) {
1442*1da177e4SLinus Torvalds	    $parameterdescs{$param_name} = $undescribed;
1443*1da177e4SLinus Torvalds
1444*1da177e4SLinus Torvalds	    if (($type eq 'function') || ($type eq 'enum')) {
1445*1da177e4SLinus Torvalds	        print STDERR "Warning(${file}:$.): Function parameter ".
1446*1da177e4SLinus Torvalds		    "or member '$param' not " .
1447*1da177e4SLinus Torvalds		    "described in '$declaration_name'\n";
1448*1da177e4SLinus Torvalds	    }
1449*1da177e4SLinus Torvalds	    print STDERR "Warning(${file}:$.):".
1450*1da177e4SLinus Torvalds	                 " No description found for parameter '$param'\n";
1451*1da177e4SLinus Torvalds	    ++$warnings;
1452*1da177e4SLinus Torvalds        }
1453*1da177e4SLinus Torvalds
1454*1da177e4SLinus Torvalds	push @parameterlist, $param;
1455*1da177e4SLinus Torvalds	$parametertypes{$param} = $type;
1456*1da177e4SLinus Torvalds}
1457*1da177e4SLinus Torvalds
1458*1da177e4SLinus Torvalds##
1459*1da177e4SLinus Torvalds# takes a function prototype and the name of the current file being
1460*1da177e4SLinus Torvalds# processed and spits out all the details stored in the global
1461*1da177e4SLinus Torvalds# arrays/hashes.
1462*1da177e4SLinus Torvaldssub dump_function($$) {
1463*1da177e4SLinus Torvalds    my $prototype = shift;
1464*1da177e4SLinus Torvalds    my $file = shift;
1465*1da177e4SLinus Torvalds
1466*1da177e4SLinus Torvalds    $prototype =~ s/^static +//;
1467*1da177e4SLinus Torvalds    $prototype =~ s/^extern +//;
1468*1da177e4SLinus Torvalds    $prototype =~ s/^inline +//;
1469*1da177e4SLinus Torvalds    $prototype =~ s/^__inline__ +//;
1470*1da177e4SLinus Torvalds    $prototype =~ s/^#define +//; #ak added
1471*1da177e4SLinus Torvalds    $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//;
1472*1da177e4SLinus Torvalds
1473*1da177e4SLinus Torvalds    # Yes, this truly is vile.  We are looking for:
1474*1da177e4SLinus Torvalds    # 1. Return type (may be nothing if we're looking at a macro)
1475*1da177e4SLinus Torvalds    # 2. Function name
1476*1da177e4SLinus Torvalds    # 3. Function parameters.
1477*1da177e4SLinus Torvalds    #
1478*1da177e4SLinus Torvalds    # All the while we have to watch out for function pointer parameters
1479*1da177e4SLinus Torvalds    # (which IIRC is what the two sections are for), C types (these
1480*1da177e4SLinus Torvalds    # regexps don't even start to express all the possibilities), and
1481*1da177e4SLinus Torvalds    # so on.
1482*1da177e4SLinus Torvalds    #
1483*1da177e4SLinus Torvalds    # If you mess with these regexps, it's a good idea to check that
1484*1da177e4SLinus Torvalds    # the following functions' documentation still comes out right:
1485*1da177e4SLinus Torvalds    # - parport_register_device (function pointer parameters)
1486*1da177e4SLinus Torvalds    # - atomic_set (macro)
1487*1da177e4SLinus Torvalds    # - pci_match_device (long return type)
1488*1da177e4SLinus Torvalds
1489*1da177e4SLinus Torvalds    if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1490*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1491*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1492*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1493*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1494*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1495*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1496*1da177e4SLinus Torvalds	$prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1497*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1498*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1499*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1500*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1501*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1502*1da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/)  {
1503*1da177e4SLinus Torvalds	$return_type = $1;
1504*1da177e4SLinus Torvalds	$declaration_name = $2;
1505*1da177e4SLinus Torvalds	my $args = $3;
1506*1da177e4SLinus Torvalds
1507*1da177e4SLinus Torvalds	create_parameterlist($args, ',', $file);
1508*1da177e4SLinus Torvalds    } else {
1509*1da177e4SLinus Torvalds	print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1510*1da177e4SLinus Torvalds	++$errors;
1511*1da177e4SLinus Torvalds	return;
1512*1da177e4SLinus Torvalds    }
1513*1da177e4SLinus Torvalds
1514*1da177e4SLinus Torvalds    output_declaration($declaration_name,
1515*1da177e4SLinus Torvalds		       'function',
1516*1da177e4SLinus Torvalds		       {'function' => $declaration_name,
1517*1da177e4SLinus Torvalds			'module' => $modulename,
1518*1da177e4SLinus Torvalds			'functiontype' => $return_type,
1519*1da177e4SLinus Torvalds			'parameterlist' => \@parameterlist,
1520*1da177e4SLinus Torvalds			'parameterdescs' => \%parameterdescs,
1521*1da177e4SLinus Torvalds			'parametertypes' => \%parametertypes,
1522*1da177e4SLinus Torvalds			'sectionlist' => \@sectionlist,
1523*1da177e4SLinus Torvalds			'sections' => \%sections,
1524*1da177e4SLinus Torvalds			'purpose' => $declaration_purpose
1525*1da177e4SLinus Torvalds		       });
1526*1da177e4SLinus Torvalds}
1527*1da177e4SLinus Torvalds
1528*1da177e4SLinus Torvaldssub process_file($);
1529*1da177e4SLinus Torvalds
1530*1da177e4SLinus Torvalds# Read the file that maps relative names to absolute names for
1531*1da177e4SLinus Torvalds# separate source and object directories and for shadow trees.
1532*1da177e4SLinus Torvaldsif (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1533*1da177e4SLinus Torvalds	my ($relname, $absname);
1534*1da177e4SLinus Torvalds	while(<SOURCE_MAP>) {
1535*1da177e4SLinus Torvalds		chop();
1536*1da177e4SLinus Torvalds		($relname, $absname) = (split())[0..1];
1537*1da177e4SLinus Torvalds		$relname =~ s:^/+::;
1538*1da177e4SLinus Torvalds		$source_map{$relname} = $absname;
1539*1da177e4SLinus Torvalds	}
1540*1da177e4SLinus Torvalds	close(SOURCE_MAP);
1541*1da177e4SLinus Torvalds}
1542*1da177e4SLinus Torvalds
1543*1da177e4SLinus Torvaldsif ($filelist) {
1544*1da177e4SLinus Torvalds	open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1545*1da177e4SLinus Torvalds	while(<FLIST>) {
1546*1da177e4SLinus Torvalds		chop;
1547*1da177e4SLinus Torvalds		process_file($_);
1548*1da177e4SLinus Torvalds	}
1549*1da177e4SLinus Torvalds}
1550*1da177e4SLinus Torvalds
1551*1da177e4SLinus Torvaldsforeach (@ARGV) {
1552*1da177e4SLinus Torvalds    chomp;
1553*1da177e4SLinus Torvalds    process_file($_);
1554*1da177e4SLinus Torvalds}
1555*1da177e4SLinus Torvaldsif ($verbose && $errors) {
1556*1da177e4SLinus Torvalds  print STDERR "$errors errors\n";
1557*1da177e4SLinus Torvalds}
1558*1da177e4SLinus Torvaldsif ($verbose && $warnings) {
1559*1da177e4SLinus Torvalds  print STDERR "$warnings warnings\n";
1560*1da177e4SLinus Torvalds}
1561*1da177e4SLinus Torvalds
1562*1da177e4SLinus Torvaldsexit($errors);
1563*1da177e4SLinus Torvalds
1564*1da177e4SLinus Torvaldssub reset_state {
1565*1da177e4SLinus Torvalds    $function = "";
1566*1da177e4SLinus Torvalds    %constants = ();
1567*1da177e4SLinus Torvalds    %parameterdescs = ();
1568*1da177e4SLinus Torvalds    %parametertypes = ();
1569*1da177e4SLinus Torvalds    @parameterlist = ();
1570*1da177e4SLinus Torvalds    %sections = ();
1571*1da177e4SLinus Torvalds    @sectionlist = ();
1572*1da177e4SLinus Torvalds    $prototype = "";
1573*1da177e4SLinus Torvalds
1574*1da177e4SLinus Torvalds    $state = 0;
1575*1da177e4SLinus Torvalds}
1576*1da177e4SLinus Torvalds
1577*1da177e4SLinus Torvaldssub process_state3_function($$) {
1578*1da177e4SLinus Torvalds    my $x = shift;
1579*1da177e4SLinus Torvalds    my $file = shift;
1580*1da177e4SLinus Torvalds
1581*1da177e4SLinus Torvalds    if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1582*1da177e4SLinus Torvalds	# do nothing
1583*1da177e4SLinus Torvalds    }
1584*1da177e4SLinus Torvalds    elsif ($x =~ /([^\{]*)/) {
1585*1da177e4SLinus Torvalds        $prototype .= $1;
1586*1da177e4SLinus Torvalds    }
1587*1da177e4SLinus Torvalds    if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1588*1da177e4SLinus Torvalds        $prototype =~ s@/\*.*?\*/@@gos;	# strip comments.
1589*1da177e4SLinus Torvalds	$prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1590*1da177e4SLinus Torvalds	$prototype =~ s@^\s+@@gos; # strip leading spaces
1591*1da177e4SLinus Torvalds	dump_function($prototype,$file);
1592*1da177e4SLinus Torvalds	reset_state();
1593*1da177e4SLinus Torvalds    }
1594*1da177e4SLinus Torvalds}
1595*1da177e4SLinus Torvalds
1596*1da177e4SLinus Torvaldssub process_state3_type($$) {
1597*1da177e4SLinus Torvalds    my $x = shift;
1598*1da177e4SLinus Torvalds    my $file = shift;
1599*1da177e4SLinus Torvalds
1600*1da177e4SLinus Torvalds    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
1601*1da177e4SLinus Torvalds    $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1602*1da177e4SLinus Torvalds    $x =~ s@^\s+@@gos; # strip leading spaces
1603*1da177e4SLinus Torvalds    $x =~ s@\s+$@@gos; # strip trailing spaces
1604*1da177e4SLinus Torvalds    if ($x =~ /^#/) {
1605*1da177e4SLinus Torvalds	# To distinguish preprocessor directive from regular declaration later.
1606*1da177e4SLinus Torvalds	$x .= ";";
1607*1da177e4SLinus Torvalds    }
1608*1da177e4SLinus Torvalds
1609*1da177e4SLinus Torvalds    while (1) {
1610*1da177e4SLinus Torvalds        if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1611*1da177e4SLinus Torvalds	    $prototype .= $1 . $2;
1612*1da177e4SLinus Torvalds	    ($2 eq '{') && $brcount++;
1613*1da177e4SLinus Torvalds	    ($2 eq '}') && $brcount--;
1614*1da177e4SLinus Torvalds	    if (($2 eq ';') && ($brcount == 0)) {
1615*1da177e4SLinus Torvalds	        dump_declaration($prototype,$file);
1616*1da177e4SLinus Torvalds		reset_state();
1617*1da177e4SLinus Torvalds	        last;
1618*1da177e4SLinus Torvalds	    }
1619*1da177e4SLinus Torvalds	    $x = $3;
1620*1da177e4SLinus Torvalds        } else {
1621*1da177e4SLinus Torvalds	    $prototype .= $x;
1622*1da177e4SLinus Torvalds	    last;
1623*1da177e4SLinus Torvalds	}
1624*1da177e4SLinus Torvalds    }
1625*1da177e4SLinus Torvalds}
1626*1da177e4SLinus Torvalds
1627*1da177e4SLinus Torvalds# replace <, >, and &
1628*1da177e4SLinus Torvaldssub xml_escape($) {
1629*1da177e4SLinus Torvalds	my $text = shift;
1630*1da177e4SLinus Torvalds	$text =~ s/\&/\\\\\\amp;/g;
1631*1da177e4SLinus Torvalds	$text =~ s/\</\\\\\\lt;/g;
1632*1da177e4SLinus Torvalds	$text =~ s/\>/\\\\\\gt;/g;
1633*1da177e4SLinus Torvalds	return $text;
1634*1da177e4SLinus Torvalds}
1635*1da177e4SLinus Torvalds
1636*1da177e4SLinus Torvaldssub process_file($) {
1637*1da177e4SLinus Torvalds    my ($file) = "$ENV{'SRCTREE'}@_";
1638*1da177e4SLinus Torvalds    my $identifier;
1639*1da177e4SLinus Torvalds    my $func;
1640*1da177e4SLinus Torvalds    my $initial_section_counter = $section_counter;
1641*1da177e4SLinus Torvalds
1642*1da177e4SLinus Torvalds    if (defined($source_map{$file})) {
1643*1da177e4SLinus Torvalds	$file = $source_map{$file};
1644*1da177e4SLinus Torvalds    }
1645*1da177e4SLinus Torvalds
1646*1da177e4SLinus Torvalds    if (!open(IN,"<$file")) {
1647*1da177e4SLinus Torvalds	print STDERR "Error: Cannot open file $file\n";
1648*1da177e4SLinus Torvalds	++$errors;
1649*1da177e4SLinus Torvalds	return;
1650*1da177e4SLinus Torvalds    }
1651*1da177e4SLinus Torvalds
1652*1da177e4SLinus Torvalds    $section_counter = 0;
1653*1da177e4SLinus Torvalds    while (<IN>) {
1654*1da177e4SLinus Torvalds	if ($state == 0) {
1655*1da177e4SLinus Torvalds	    if (/$doc_start/o) {
1656*1da177e4SLinus Torvalds		$state = 1;		# next line is always the function name
1657*1da177e4SLinus Torvalds	    }
1658*1da177e4SLinus Torvalds	} elsif ($state == 1) {	# this line is the function name (always)
1659*1da177e4SLinus Torvalds	    if (/$doc_block/o) {
1660*1da177e4SLinus Torvalds		$state = 4;
1661*1da177e4SLinus Torvalds		$contents = "";
1662*1da177e4SLinus Torvalds		if ( $1 eq "" ) {
1663*1da177e4SLinus Torvalds			$section = $section_intro;
1664*1da177e4SLinus Torvalds		} else {
1665*1da177e4SLinus Torvalds			$section = $1;
1666*1da177e4SLinus Torvalds		}
1667*1da177e4SLinus Torvalds            }
1668*1da177e4SLinus Torvalds	    elsif (/$doc_decl/o) {
1669*1da177e4SLinus Torvalds		$identifier = $1;
1670*1da177e4SLinus Torvalds		if (/\s*([\w\s]+?)\s*-/) {
1671*1da177e4SLinus Torvalds		    $identifier = $1;
1672*1da177e4SLinus Torvalds		}
1673*1da177e4SLinus Torvalds
1674*1da177e4SLinus Torvalds		$state = 2;
1675*1da177e4SLinus Torvalds		if (/-(.*)/) {
1676*1da177e4SLinus Torvalds		    $declaration_purpose = xml_escape($1);
1677*1da177e4SLinus Torvalds		} else {
1678*1da177e4SLinus Torvalds		    $declaration_purpose = "";
1679*1da177e4SLinus Torvalds		}
1680*1da177e4SLinus Torvalds		if ($identifier =~ m/^struct/) {
1681*1da177e4SLinus Torvalds		    $decl_type = 'struct';
1682*1da177e4SLinus Torvalds		} elsif ($identifier =~ m/^union/) {
1683*1da177e4SLinus Torvalds		    $decl_type = 'union';
1684*1da177e4SLinus Torvalds		} elsif ($identifier =~ m/^enum/) {
1685*1da177e4SLinus Torvalds		    $decl_type = 'enum';
1686*1da177e4SLinus Torvalds		} elsif ($identifier =~ m/^typedef/) {
1687*1da177e4SLinus Torvalds		    $decl_type = 'typedef';
1688*1da177e4SLinus Torvalds		} else {
1689*1da177e4SLinus Torvalds		    $decl_type = 'function';
1690*1da177e4SLinus Torvalds		}
1691*1da177e4SLinus Torvalds
1692*1da177e4SLinus Torvalds		if ($verbose) {
1693*1da177e4SLinus Torvalds		    print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1694*1da177e4SLinus Torvalds		}
1695*1da177e4SLinus Torvalds	    } else {
1696*1da177e4SLinus Torvalds		print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1697*1da177e4SLinus Torvalds		" - I thought it was a doc line\n";
1698*1da177e4SLinus Torvalds		++$warnings;
1699*1da177e4SLinus Torvalds		$state = 0;
1700*1da177e4SLinus Torvalds	    }
1701*1da177e4SLinus Torvalds	} elsif ($state == 2) {	# look for head: lines, and include content
1702*1da177e4SLinus Torvalds	    if (/$doc_sect/o) {
1703*1da177e4SLinus Torvalds		$newsection = $1;
1704*1da177e4SLinus Torvalds		$newcontents = $2;
1705*1da177e4SLinus Torvalds
1706*1da177e4SLinus Torvalds		if ($contents ne "") {
1707*1da177e4SLinus Torvalds		    dump_section($section, xml_escape($contents));
1708*1da177e4SLinus Torvalds		    $section = $section_default;
1709*1da177e4SLinus Torvalds		}
1710*1da177e4SLinus Torvalds
1711*1da177e4SLinus Torvalds		$contents = $newcontents;
1712*1da177e4SLinus Torvalds		if ($contents ne "") {
1713*1da177e4SLinus Torvalds		    $contents .= "\n";
1714*1da177e4SLinus Torvalds		}
1715*1da177e4SLinus Torvalds		$section = $newsection;
1716*1da177e4SLinus Torvalds	    } elsif (/$doc_end/) {
1717*1da177e4SLinus Torvalds
1718*1da177e4SLinus Torvalds		if ($contents ne "") {
1719*1da177e4SLinus Torvalds		    dump_section($section, xml_escape($contents));
1720*1da177e4SLinus Torvalds		    $section = $section_default;
1721*1da177e4SLinus Torvalds		    $contents = "";
1722*1da177e4SLinus Torvalds		}
1723*1da177e4SLinus Torvalds
1724*1da177e4SLinus Torvalds		$prototype = "";
1725*1da177e4SLinus Torvalds		$state = 3;
1726*1da177e4SLinus Torvalds		$brcount = 0;
1727*1da177e4SLinus Torvalds#	    print STDERR "end of doc comment, looking for prototype\n";
1728*1da177e4SLinus Torvalds	    } elsif (/$doc_content/) {
1729*1da177e4SLinus Torvalds		# miguel-style comment kludge, look for blank lines after
1730*1da177e4SLinus Torvalds		# @parameter line to signify start of description
1731*1da177e4SLinus Torvalds		if ($1 eq "" &&
1732*1da177e4SLinus Torvalds			($section =~ m/^@/ || $section eq $section_context)) {
1733*1da177e4SLinus Torvalds		    dump_section($section, xml_escape($contents));
1734*1da177e4SLinus Torvalds		    $section = $section_default;
1735*1da177e4SLinus Torvalds		    $contents = "";
1736*1da177e4SLinus Torvalds		} else {
1737*1da177e4SLinus Torvalds		    $contents .= $1."\n";
1738*1da177e4SLinus Torvalds		}
1739*1da177e4SLinus Torvalds	    } else {
1740*1da177e4SLinus Torvalds		# i dont know - bad line?  ignore.
1741*1da177e4SLinus Torvalds		print STDERR "Warning(${file}:$.): bad line: $_";
1742*1da177e4SLinus Torvalds		++$warnings;
1743*1da177e4SLinus Torvalds	    }
1744*1da177e4SLinus Torvalds	} elsif ($state == 3) {	# scanning for function { (end of prototype)
1745*1da177e4SLinus Torvalds	    if ($decl_type eq 'function') {
1746*1da177e4SLinus Torvalds	        process_state3_function($_, $file);
1747*1da177e4SLinus Torvalds	    } else {
1748*1da177e4SLinus Torvalds	        process_state3_type($_, $file);
1749*1da177e4SLinus Torvalds	    }
1750*1da177e4SLinus Torvalds	} elsif ($state == 4) {
1751*1da177e4SLinus Torvalds		# Documentation block
1752*1da177e4SLinus Torvalds	        if (/$doc_block/) {
1753*1da177e4SLinus Torvalds			dump_section($section, $contents);
1754*1da177e4SLinus Torvalds			output_intro({'sectionlist' => \@sectionlist,
1755*1da177e4SLinus Torvalds				      'sections' => \%sections });
1756*1da177e4SLinus Torvalds			$contents = "";
1757*1da177e4SLinus Torvalds			$function = "";
1758*1da177e4SLinus Torvalds			%constants = ();
1759*1da177e4SLinus Torvalds			%parameterdescs = ();
1760*1da177e4SLinus Torvalds			%parametertypes = ();
1761*1da177e4SLinus Torvalds			@parameterlist = ();
1762*1da177e4SLinus Torvalds			%sections = ();
1763*1da177e4SLinus Torvalds			@sectionlist = ();
1764*1da177e4SLinus Torvalds			$prototype = "";
1765*1da177e4SLinus Torvalds			if ( $1 eq "" ) {
1766*1da177e4SLinus Torvalds				$section = $section_intro;
1767*1da177e4SLinus Torvalds			} else {
1768*1da177e4SLinus Torvalds				$section = $1;
1769*1da177e4SLinus Torvalds			}
1770*1da177e4SLinus Torvalds                }
1771*1da177e4SLinus Torvalds		elsif (/$doc_end/)
1772*1da177e4SLinus Torvalds		{
1773*1da177e4SLinus Torvalds			dump_section($section, $contents);
1774*1da177e4SLinus Torvalds			output_intro({'sectionlist' => \@sectionlist,
1775*1da177e4SLinus Torvalds				      'sections' => \%sections });
1776*1da177e4SLinus Torvalds			$contents = "";
1777*1da177e4SLinus Torvalds			$function = "";
1778*1da177e4SLinus Torvalds			%constants = ();
1779*1da177e4SLinus Torvalds			%parameterdescs = ();
1780*1da177e4SLinus Torvalds			%parametertypes = ();
1781*1da177e4SLinus Torvalds			@parameterlist = ();
1782*1da177e4SLinus Torvalds			%sections = ();
1783*1da177e4SLinus Torvalds			@sectionlist = ();
1784*1da177e4SLinus Torvalds			$prototype = "";
1785*1da177e4SLinus Torvalds			$state = 0;
1786*1da177e4SLinus Torvalds		}
1787*1da177e4SLinus Torvalds		elsif (/$doc_content/)
1788*1da177e4SLinus Torvalds		{
1789*1da177e4SLinus Torvalds			if ( $1 eq "" )
1790*1da177e4SLinus Torvalds			{
1791*1da177e4SLinus Torvalds				$contents .= $blankline;
1792*1da177e4SLinus Torvalds			}
1793*1da177e4SLinus Torvalds			else
1794*1da177e4SLinus Torvalds			{
1795*1da177e4SLinus Torvalds				$contents .= $1 . "\n";
1796*1da177e4SLinus Torvalds			}
1797*1da177e4SLinus Torvalds        	}
1798*1da177e4SLinus Torvalds          }
1799*1da177e4SLinus Torvalds    }
1800*1da177e4SLinus Torvalds    if ($initial_section_counter == $section_counter) {
1801*1da177e4SLinus Torvalds	print STDERR "Warning(${file}): no structured comments found\n";
1802*1da177e4SLinus Torvalds	if ($output_mode eq "xml") {
1803*1da177e4SLinus Torvalds	    # The template wants at least one RefEntry here; make one.
1804*1da177e4SLinus Torvalds	    print "<refentry>\n";
1805*1da177e4SLinus Torvalds	    print " <refnamediv>\n";
1806*1da177e4SLinus Torvalds	    print "  <refname>\n";
1807*1da177e4SLinus Torvalds	    print "   ${file}\n";
1808*1da177e4SLinus Torvalds	    print "  </refname>\n";
1809*1da177e4SLinus Torvalds	    print "  <refpurpose>\n";
1810*1da177e4SLinus Torvalds	    print "   Document generation inconsistency\n";
1811*1da177e4SLinus Torvalds	    print "  </refpurpose>\n";
1812*1da177e4SLinus Torvalds	    print " </refnamediv>\n";
1813*1da177e4SLinus Torvalds	    print " <refsect1>\n";
1814*1da177e4SLinus Torvalds	    print "  <title>\n";
1815*1da177e4SLinus Torvalds	    print "   Oops\n";
1816*1da177e4SLinus Torvalds	    print "  </title>\n";
1817*1da177e4SLinus Torvalds	    print "  <warning>\n";
1818*1da177e4SLinus Torvalds	    print "   <para>\n";
1819*1da177e4SLinus Torvalds	    print "    The template for this document tried to insert\n";
1820*1da177e4SLinus Torvalds	    print "    the structured comment from the file\n";
1821*1da177e4SLinus Torvalds	    print "    <filename>${file}</filename> at this point,\n";
1822*1da177e4SLinus Torvalds	    print "    but none was found.\n";
1823*1da177e4SLinus Torvalds	    print "    This dummy section is inserted to allow\n";
1824*1da177e4SLinus Torvalds	    print "    generation to continue.\n";
1825*1da177e4SLinus Torvalds	    print "   </para>\n";
1826*1da177e4SLinus Torvalds	    print "  </warning>\n";
1827*1da177e4SLinus Torvalds	    print " </refsect1>\n";
1828*1da177e4SLinus Torvalds	    print "</refentry>\n";
1829*1da177e4SLinus Torvalds	}
1830*1da177e4SLinus Torvalds    }
1831*1da177e4SLinus Torvalds}
1832