kernel-doc 50 KB

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