kernel-doc 54 KB

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