kernel-doc 53 KB

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