kernel-doc 53 KB

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