kernel-doc 56 KB

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