PageRenderTime 71ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/linux-2.6.28.6/scripts/kernel-doc

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