kernel-doc 51 KB

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