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