kernel-doc 61 KB

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