kernel-doc 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  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 $sectcheck;
  259. my $struct_actual;
  260. my $contents = "";
  261. my $section_default = "Description"; # default section
  262. my $section_intro = "Introduction";
  263. my $section = $section_default;
  264. my $section_context = "Context";
  265. my $undescribed = "-- undescribed --";
  266. reset_state();
  267. while ($ARGV[0] =~ m/^-(.*)/) {
  268. my $cmd = shift @ARGV;
  269. if ($cmd eq "-html") {
  270. $output_mode = "html";
  271. %highlights = %highlights_html;
  272. $blankline = $blankline_html;
  273. } elsif ($cmd eq "-man") {
  274. $output_mode = "man";
  275. %highlights = %highlights_man;
  276. $blankline = $blankline_man;
  277. } elsif ($cmd eq "-text") {
  278. $output_mode = "text";
  279. %highlights = %highlights_text;
  280. $blankline = $blankline_text;
  281. } elsif ($cmd eq "-docbook") {
  282. $output_mode = "xml";
  283. %highlights = %highlights_xml;
  284. $blankline = $blankline_xml;
  285. } elsif ($cmd eq "-gnome") {
  286. $output_mode = "gnome";
  287. %highlights = %highlights_gnome;
  288. $blankline = $blankline_gnome;
  289. } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
  290. $modulename = shift @ARGV;
  291. } elsif ($cmd eq "-function") { # to only output specific functions
  292. $function_only = 1;
  293. $function = shift @ARGV;
  294. $function_table{$function} = 1;
  295. } elsif ($cmd eq "-nofunction") { # to only output specific functions
  296. $function_only = 2;
  297. $function = shift @ARGV;
  298. $function_table{$function} = 1;
  299. } elsif ($cmd eq "-v") {
  300. $verbose = 1;
  301. } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
  302. usage();
  303. } elsif ($cmd eq '-filelist') {
  304. $filelist = shift @ARGV;
  305. } elsif ($cmd eq '-no-doc-sections') {
  306. $no_doc_sections = 1;
  307. }
  308. }
  309. # get kernel version from env
  310. sub get_kernel_version() {
  311. my $version = 'unknown kernel version';
  312. if (defined($ENV{'KERNELVERSION'})) {
  313. $version = $ENV{'KERNELVERSION'};
  314. }
  315. return $version;
  316. }
  317. my $kernelversion = get_kernel_version();
  318. # generate a sequence of code that will splice in highlighting information
  319. # using the s// operator.
  320. my $dohighlight = "";
  321. foreach my $pattern (keys %highlights) {
  322. # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
  323. $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
  324. }
  325. ##
  326. # dumps section contents to arrays/hashes intended for that purpose.
  327. #
  328. sub dump_section {
  329. my $file = shift;
  330. my $name = shift;
  331. my $contents = join "\n", @_;
  332. if ($name =~ m/$type_constant/) {
  333. $name = $1;
  334. # print STDERR "constant section '$1' = '$contents'\n";
  335. $constants{$name} = $contents;
  336. } elsif ($name =~ m/$type_param/) {
  337. # print STDERR "parameter def '$1' = '$contents'\n";
  338. $name = $1;
  339. $parameterdescs{$name} = $contents;
  340. $sectcheck = $sectcheck . $name . " ";
  341. } elsif ($name eq "@\.\.\.") {
  342. # print STDERR "parameter def '...' = '$contents'\n";
  343. $name = "...";
  344. $parameterdescs{$name} = $contents;
  345. $sectcheck = $sectcheck . $name . " ";
  346. } else {
  347. # print STDERR "other section '$name' = '$contents'\n";
  348. if (defined($sections{$name}) && ($sections{$name} ne "")) {
  349. print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
  350. ++$errors;
  351. }
  352. $sections{$name} = $contents;
  353. push @sectionlist, $name;
  354. }
  355. }
  356. ##
  357. # dump DOC: section after checking that it should go out
  358. #
  359. sub dump_doc_section {
  360. my $file = shift;
  361. my $name = shift;
  362. my $contents = join "\n", @_;
  363. if ($no_doc_sections) {
  364. return;
  365. }
  366. if (($function_only == 0) ||
  367. ( $function_only == 1 && defined($function_table{$name})) ||
  368. ( $function_only == 2 && !defined($function_table{$name})))
  369. {
  370. dump_section($file, $name, $contents);
  371. output_blockhead({'sectionlist' => \@sectionlist,
  372. 'sections' => \%sections,
  373. 'module' => $modulename,
  374. 'content-only' => ($function_only != 0), });
  375. }
  376. }
  377. ##
  378. # output function
  379. #
  380. # parameterdescs, a hash.
  381. # function => "function name"
  382. # parameterlist => @list of parameters
  383. # parameterdescs => %parameter descriptions
  384. # sectionlist => @list of sections
  385. # sections => %section descriptions
  386. #
  387. sub output_highlight {
  388. my $contents = join "\n",@_;
  389. my $line;
  390. # DEBUG
  391. # if (!defined $contents) {
  392. # use Carp;
  393. # confess "output_highlight got called with no args?\n";
  394. # }
  395. if ($output_mode eq "html" || $output_mode eq "xml") {
  396. $contents = local_unescape($contents);
  397. # convert data read & converted thru xml_escape() into &xyz; format:
  398. $contents =~ s/\\\\\\/&/g;
  399. }
  400. # print STDERR "contents b4:$contents\n";
  401. eval $dohighlight;
  402. die $@ if $@;
  403. # print STDERR "contents af:$contents\n";
  404. foreach $line (split "\n", $contents) {
  405. if ($line eq ""){
  406. print $lineprefix, local_unescape($blankline);
  407. } else {
  408. $line =~ s/\\\\\\/\&/g;
  409. if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
  410. print "\\&$line";
  411. } else {
  412. print $lineprefix, $line;
  413. }
  414. }
  415. print "\n";
  416. }
  417. }
  418. #output sections in html
  419. sub output_section_html(%) {
  420. my %args = %{$_[0]};
  421. my $section;
  422. foreach $section (@{$args{'sectionlist'}}) {
  423. print "<h3>$section</h3>\n";
  424. print "<blockquote>\n";
  425. output_highlight($args{'sections'}{$section});
  426. print "</blockquote>\n";
  427. }
  428. }
  429. # output enum in html
  430. sub output_enum_html(%) {
  431. my %args = %{$_[0]};
  432. my ($parameter);
  433. my $count;
  434. print "<h2>enum ".$args{'enum'}."</h2>\n";
  435. print "<b>enum ".$args{'enum'}."</b> {<br>\n";
  436. $count = 0;
  437. foreach $parameter (@{$args{'parameterlist'}}) {
  438. print " <b>".$parameter."</b>";
  439. if ($count != $#{$args{'parameterlist'}}) {
  440. $count++;
  441. print ",\n";
  442. }
  443. print "<br>";
  444. }
  445. print "};<br>\n";
  446. print "<h3>Constants</h3>\n";
  447. print "<dl>\n";
  448. foreach $parameter (@{$args{'parameterlist'}}) {
  449. print "<dt><b>".$parameter."</b>\n";
  450. print "<dd>";
  451. output_highlight($args{'parameterdescs'}{$parameter});
  452. }
  453. print "</dl>\n";
  454. output_section_html(@_);
  455. print "<hr>\n";
  456. }
  457. # output typedef in html
  458. sub output_typedef_html(%) {
  459. my %args = %{$_[0]};
  460. my ($parameter);
  461. my $count;
  462. print "<h2>typedef ".$args{'typedef'}."</h2>\n";
  463. print "<b>typedef ".$args{'typedef'}."</b>\n";
  464. output_section_html(@_);
  465. print "<hr>\n";
  466. }
  467. # output struct in html
  468. sub output_struct_html(%) {
  469. my %args = %{$_[0]};
  470. my ($parameter);
  471. print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
  472. print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
  473. foreach $parameter (@{$args{'parameterlist'}}) {
  474. if ($parameter =~ /^#/) {
  475. print "$parameter<br>\n";
  476. next;
  477. }
  478. my $parameter_name = $parameter;
  479. $parameter_name =~ s/\[.*//;
  480. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  481. $type = $args{'parametertypes'}{$parameter};
  482. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  483. # pointer-to-function
  484. print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
  485. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  486. # bitfield
  487. print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
  488. } else {
  489. print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
  490. }
  491. }
  492. print "};<br>\n";
  493. print "<h3>Members</h3>\n";
  494. print "<dl>\n";
  495. foreach $parameter (@{$args{'parameterlist'}}) {
  496. ($parameter =~ /^#/) && next;
  497. my $parameter_name = $parameter;
  498. $parameter_name =~ s/\[.*//;
  499. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  500. print "<dt><b>".$parameter."</b>\n";
  501. print "<dd>";
  502. output_highlight($args{'parameterdescs'}{$parameter_name});
  503. }
  504. print "</dl>\n";
  505. output_section_html(@_);
  506. print "<hr>\n";
  507. }
  508. # output function in html
  509. sub output_function_html(%) {
  510. my %args = %{$_[0]};
  511. my ($parameter, $section);
  512. my $count;
  513. print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
  514. print "<i>".$args{'functiontype'}."</i>\n";
  515. print "<b>".$args{'function'}."</b>\n";
  516. print "(";
  517. $count = 0;
  518. foreach $parameter (@{$args{'parameterlist'}}) {
  519. $type = $args{'parametertypes'}{$parameter};
  520. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  521. # pointer-to-function
  522. print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
  523. } else {
  524. print "<i>".$type."</i> <b>".$parameter."</b>";
  525. }
  526. if ($count != $#{$args{'parameterlist'}}) {
  527. $count++;
  528. print ",\n";
  529. }
  530. }
  531. print ")\n";
  532. print "<h3>Arguments</h3>\n";
  533. print "<dl>\n";
  534. foreach $parameter (@{$args{'parameterlist'}}) {
  535. my $parameter_name = $parameter;
  536. $parameter_name =~ s/\[.*//;
  537. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  538. print "<dt><b>".$parameter."</b>\n";
  539. print "<dd>";
  540. output_highlight($args{'parameterdescs'}{$parameter_name});
  541. }
  542. print "</dl>\n";
  543. output_section_html(@_);
  544. print "<hr>\n";
  545. }
  546. # output DOC: block header in html
  547. sub output_blockhead_html(%) {
  548. my %args = %{$_[0]};
  549. my ($parameter, $section);
  550. my $count;
  551. foreach $section (@{$args{'sectionlist'}}) {
  552. print "<h3>$section</h3>\n";
  553. print "<ul>\n";
  554. output_highlight($args{'sections'}{$section});
  555. print "</ul>\n";
  556. }
  557. print "<hr>\n";
  558. }
  559. sub output_section_xml(%) {
  560. my %args = %{$_[0]};
  561. my $section;
  562. # print out each section
  563. $lineprefix=" ";
  564. foreach $section (@{$args{'sectionlist'}}) {
  565. print "<refsect1>\n";
  566. print "<title>$section</title>\n";
  567. if ($section =~ m/EXAMPLE/i) {
  568. print "<informalexample><programlisting>\n";
  569. } else {
  570. print "<para>\n";
  571. }
  572. output_highlight($args{'sections'}{$section});
  573. if ($section =~ m/EXAMPLE/i) {
  574. print "</programlisting></informalexample>\n";
  575. } else {
  576. print "</para>\n";
  577. }
  578. print "</refsect1>\n";
  579. }
  580. }
  581. # output function in XML DocBook
  582. sub output_function_xml(%) {
  583. my %args = %{$_[0]};
  584. my ($parameter, $section);
  585. my $count;
  586. my $id;
  587. $id = "API-".$args{'function'};
  588. $id =~ s/[^A-Za-z0-9]/-/g;
  589. print "<refentry id=\"$id\">\n";
  590. print "<refentryinfo>\n";
  591. print " <title>LINUX</title>\n";
  592. print " <productname>Kernel Hackers Manual</productname>\n";
  593. print " <date>$man_date</date>\n";
  594. print "</refentryinfo>\n";
  595. print "<refmeta>\n";
  596. print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
  597. print " <manvolnum>9</manvolnum>\n";
  598. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  599. print "</refmeta>\n";
  600. print "<refnamediv>\n";
  601. print " <refname>".$args{'function'}."</refname>\n";
  602. print " <refpurpose>\n";
  603. print " ";
  604. output_highlight ($args{'purpose'});
  605. print " </refpurpose>\n";
  606. print "</refnamediv>\n";
  607. print "<refsynopsisdiv>\n";
  608. print " <title>Synopsis</title>\n";
  609. print " <funcsynopsis><funcprototype>\n";
  610. print " <funcdef>".$args{'functiontype'}." ";
  611. print "<function>".$args{'function'}." </function></funcdef>\n";
  612. $count = 0;
  613. if ($#{$args{'parameterlist'}} >= 0) {
  614. foreach $parameter (@{$args{'parameterlist'}}) {
  615. $type = $args{'parametertypes'}{$parameter};
  616. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  617. # pointer-to-function
  618. print " <paramdef>$1<parameter>$parameter</parameter>)\n";
  619. print " <funcparams>$2</funcparams></paramdef>\n";
  620. } else {
  621. print " <paramdef>".$type;
  622. print " <parameter>$parameter</parameter></paramdef>\n";
  623. }
  624. }
  625. } else {
  626. print " <void/>\n";
  627. }
  628. print " </funcprototype></funcsynopsis>\n";
  629. print "</refsynopsisdiv>\n";
  630. # print parameters
  631. print "<refsect1>\n <title>Arguments</title>\n";
  632. if ($#{$args{'parameterlist'}} >= 0) {
  633. print " <variablelist>\n";
  634. foreach $parameter (@{$args{'parameterlist'}}) {
  635. my $parameter_name = $parameter;
  636. $parameter_name =~ s/\[.*//;
  637. print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
  638. print " <listitem>\n <para>\n";
  639. $lineprefix=" ";
  640. output_highlight($args{'parameterdescs'}{$parameter_name});
  641. print " </para>\n </listitem>\n </varlistentry>\n";
  642. }
  643. print " </variablelist>\n";
  644. } else {
  645. print " <para>\n None\n </para>\n";
  646. }
  647. print "</refsect1>\n";
  648. output_section_xml(@_);
  649. print "</refentry>\n\n";
  650. }
  651. # output struct in XML DocBook
  652. sub output_struct_xml(%) {
  653. my %args = %{$_[0]};
  654. my ($parameter, $section);
  655. my $id;
  656. $id = "API-struct-".$args{'struct'};
  657. $id =~ s/[^A-Za-z0-9]/-/g;
  658. print "<refentry id=\"$id\">\n";
  659. print "<refentryinfo>\n";
  660. print " <title>LINUX</title>\n";
  661. print " <productname>Kernel Hackers Manual</productname>\n";
  662. print " <date>$man_date</date>\n";
  663. print "</refentryinfo>\n";
  664. print "<refmeta>\n";
  665. print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
  666. print " <manvolnum>9</manvolnum>\n";
  667. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  668. print "</refmeta>\n";
  669. print "<refnamediv>\n";
  670. print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
  671. print " <refpurpose>\n";
  672. print " ";
  673. output_highlight ($args{'purpose'});
  674. print " </refpurpose>\n";
  675. print "</refnamediv>\n";
  676. print "<refsynopsisdiv>\n";
  677. print " <title>Synopsis</title>\n";
  678. print " <programlisting>\n";
  679. print $args{'type'}." ".$args{'struct'}." {\n";
  680. foreach $parameter (@{$args{'parameterlist'}}) {
  681. if ($parameter =~ /^#/) {
  682. print "$parameter\n";
  683. next;
  684. }
  685. my $parameter_name = $parameter;
  686. $parameter_name =~ s/\[.*//;
  687. defined($args{'parameterdescs'}{$parameter_name}) || next;
  688. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  689. $type = $args{'parametertypes'}{$parameter};
  690. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  691. # pointer-to-function
  692. print " $1 $parameter) ($2);\n";
  693. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  694. # bitfield
  695. print " $1 $parameter$2;\n";
  696. } else {
  697. print " ".$type." ".$parameter.";\n";
  698. }
  699. }
  700. print "};";
  701. print " </programlisting>\n";
  702. print "</refsynopsisdiv>\n";
  703. print " <refsect1>\n";
  704. print " <title>Members</title>\n";
  705. if ($#{$args{'parameterlist'}} >= 0) {
  706. print " <variablelist>\n";
  707. foreach $parameter (@{$args{'parameterlist'}}) {
  708. ($parameter =~ /^#/) && next;
  709. my $parameter_name = $parameter;
  710. $parameter_name =~ s/\[.*//;
  711. defined($args{'parameterdescs'}{$parameter_name}) || next;
  712. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  713. print " <varlistentry>";
  714. print " <term>$parameter</term>\n";
  715. print " <listitem><para>\n";
  716. output_highlight($args{'parameterdescs'}{$parameter_name});
  717. print " </para></listitem>\n";
  718. print " </varlistentry>\n";
  719. }
  720. print " </variablelist>\n";
  721. } else {
  722. print " <para>\n None\n </para>\n";
  723. }
  724. print " </refsect1>\n";
  725. output_section_xml(@_);
  726. print "</refentry>\n\n";
  727. }
  728. # output enum in XML DocBook
  729. sub output_enum_xml(%) {
  730. my %args = %{$_[0]};
  731. my ($parameter, $section);
  732. my $count;
  733. my $id;
  734. $id = "API-enum-".$args{'enum'};
  735. $id =~ s/[^A-Za-z0-9]/-/g;
  736. print "<refentry id=\"$id\">\n";
  737. print "<refentryinfo>\n";
  738. print " <title>LINUX</title>\n";
  739. print " <productname>Kernel Hackers Manual</productname>\n";
  740. print " <date>$man_date</date>\n";
  741. print "</refentryinfo>\n";
  742. print "<refmeta>\n";
  743. print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
  744. print " <manvolnum>9</manvolnum>\n";
  745. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  746. print "</refmeta>\n";
  747. print "<refnamediv>\n";
  748. print " <refname>enum ".$args{'enum'}."</refname>\n";
  749. print " <refpurpose>\n";
  750. print " ";
  751. output_highlight ($args{'purpose'});
  752. print " </refpurpose>\n";
  753. print "</refnamediv>\n";
  754. print "<refsynopsisdiv>\n";
  755. print " <title>Synopsis</title>\n";
  756. print " <programlisting>\n";
  757. print "enum ".$args{'enum'}." {\n";
  758. $count = 0;
  759. foreach $parameter (@{$args{'parameterlist'}}) {
  760. print " $parameter";
  761. if ($count != $#{$args{'parameterlist'}}) {
  762. $count++;
  763. print ",";
  764. }
  765. print "\n";
  766. }
  767. print "};";
  768. print " </programlisting>\n";
  769. print "</refsynopsisdiv>\n";
  770. print "<refsect1>\n";
  771. print " <title>Constants</title>\n";
  772. print " <variablelist>\n";
  773. foreach $parameter (@{$args{'parameterlist'}}) {
  774. my $parameter_name = $parameter;
  775. $parameter_name =~ s/\[.*//;
  776. print " <varlistentry>";
  777. print " <term>$parameter</term>\n";
  778. print " <listitem><para>\n";
  779. output_highlight($args{'parameterdescs'}{$parameter_name});
  780. print " </para></listitem>\n";
  781. print " </varlistentry>\n";
  782. }
  783. print " </variablelist>\n";
  784. print "</refsect1>\n";
  785. output_section_xml(@_);
  786. print "</refentry>\n\n";
  787. }
  788. # output typedef in XML DocBook
  789. sub output_typedef_xml(%) {
  790. my %args = %{$_[0]};
  791. my ($parameter, $section);
  792. my $id;
  793. $id = "API-typedef-".$args{'typedef'};
  794. $id =~ s/[^A-Za-z0-9]/-/g;
  795. print "<refentry id=\"$id\">\n";
  796. print "<refentryinfo>\n";
  797. print " <title>LINUX</title>\n";
  798. print " <productname>Kernel Hackers Manual</productname>\n";
  799. print " <date>$man_date</date>\n";
  800. print "</refentryinfo>\n";
  801. print "<refmeta>\n";
  802. print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
  803. print " <manvolnum>9</manvolnum>\n";
  804. print "</refmeta>\n";
  805. print "<refnamediv>\n";
  806. print " <refname>typedef ".$args{'typedef'}."</refname>\n";
  807. print " <refpurpose>\n";
  808. print " ";
  809. output_highlight ($args{'purpose'});
  810. print " </refpurpose>\n";
  811. print "</refnamediv>\n";
  812. print "<refsynopsisdiv>\n";
  813. print " <title>Synopsis</title>\n";
  814. print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
  815. print "</refsynopsisdiv>\n";
  816. output_section_xml(@_);
  817. print "</refentry>\n\n";
  818. }
  819. # output in XML DocBook
  820. sub output_blockhead_xml(%) {
  821. my %args = %{$_[0]};
  822. my ($parameter, $section);
  823. my $count;
  824. my $id = $args{'module'};
  825. $id =~ s/[^A-Za-z0-9]/-/g;
  826. # print out each section
  827. $lineprefix=" ";
  828. foreach $section (@{$args{'sectionlist'}}) {
  829. if (!$args{'content-only'}) {
  830. print "<refsect1>\n <title>$section</title>\n";
  831. }
  832. if ($section =~ m/EXAMPLE/i) {
  833. print "<example><para>\n";
  834. } else {
  835. print "<para>\n";
  836. }
  837. output_highlight($args{'sections'}{$section});
  838. if ($section =~ m/EXAMPLE/i) {
  839. print "</para></example>\n";
  840. } else {
  841. print "</para>";
  842. }
  843. if (!$args{'content-only'}) {
  844. print "\n</refsect1>\n";
  845. }
  846. }
  847. print "\n\n";
  848. }
  849. # output in XML DocBook
  850. sub output_function_gnome {
  851. my %args = %{$_[0]};
  852. my ($parameter, $section);
  853. my $count;
  854. my $id;
  855. $id = $args{'module'}."-".$args{'function'};
  856. $id =~ s/[^A-Za-z0-9]/-/g;
  857. print "<sect2>\n";
  858. print " <title id=\"$id\">".$args{'function'}."</title>\n";
  859. print " <funcsynopsis>\n";
  860. print " <funcdef>".$args{'functiontype'}." ";
  861. print "<function>".$args{'function'}." ";
  862. print "</function></funcdef>\n";
  863. $count = 0;
  864. if ($#{$args{'parameterlist'}} >= 0) {
  865. foreach $parameter (@{$args{'parameterlist'}}) {
  866. $type = $args{'parametertypes'}{$parameter};
  867. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  868. # pointer-to-function
  869. print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
  870. print " <funcparams>$2</funcparams></paramdef>\n";
  871. } else {
  872. print " <paramdef>".$type;
  873. print " <parameter>$parameter</parameter></paramdef>\n";
  874. }
  875. }
  876. } else {
  877. print " <void>\n";
  878. }
  879. print " </funcsynopsis>\n";
  880. if ($#{$args{'parameterlist'}} >= 0) {
  881. print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
  882. print "<tgroup cols=\"2\">\n";
  883. print "<colspec colwidth=\"2*\">\n";
  884. print "<colspec colwidth=\"8*\">\n";
  885. print "<tbody>\n";
  886. foreach $parameter (@{$args{'parameterlist'}}) {
  887. my $parameter_name = $parameter;
  888. $parameter_name =~ s/\[.*//;
  889. print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
  890. print " <entry>\n";
  891. $lineprefix=" ";
  892. output_highlight($args{'parameterdescs'}{$parameter_name});
  893. print " </entry></row>\n";
  894. }
  895. print " </tbody></tgroup></informaltable>\n";
  896. } else {
  897. print " <para>\n None\n </para>\n";
  898. }
  899. # print out each section
  900. $lineprefix=" ";
  901. foreach $section (@{$args{'sectionlist'}}) {
  902. print "<simplesect>\n <title>$section</title>\n";
  903. if ($section =~ m/EXAMPLE/i) {
  904. print "<example><programlisting>\n";
  905. } else {
  906. }
  907. print "<para>\n";
  908. output_highlight($args{'sections'}{$section});
  909. print "</para>\n";
  910. if ($section =~ m/EXAMPLE/i) {
  911. print "</programlisting></example>\n";
  912. } else {
  913. }
  914. print " </simplesect>\n";
  915. }
  916. print "</sect2>\n\n";
  917. }
  918. ##
  919. # output function in man
  920. sub output_function_man(%) {
  921. my %args = %{$_[0]};
  922. my ($parameter, $section);
  923. my $count;
  924. print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
  925. print ".SH NAME\n";
  926. print $args{'function'}." \\- ".$args{'purpose'}."\n";
  927. print ".SH SYNOPSIS\n";
  928. if ($args{'functiontype'} ne "") {
  929. print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
  930. } else {
  931. print ".B \"".$args{'function'}."\n";
  932. }
  933. $count = 0;
  934. my $parenth = "(";
  935. my $post = ",";
  936. foreach my $parameter (@{$args{'parameterlist'}}) {
  937. if ($count == $#{$args{'parameterlist'}}) {
  938. $post = ");";
  939. }
  940. $type = $args{'parametertypes'}{$parameter};
  941. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  942. # pointer-to-function
  943. print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
  944. } else {
  945. $type =~ s/([^\*])$/$1 /;
  946. print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
  947. }
  948. $count++;
  949. $parenth = "";
  950. }
  951. print ".SH ARGUMENTS\n";
  952. foreach $parameter (@{$args{'parameterlist'}}) {
  953. my $parameter_name = $parameter;
  954. $parameter_name =~ s/\[.*//;
  955. print ".IP \"".$parameter."\" 12\n";
  956. output_highlight($args{'parameterdescs'}{$parameter_name});
  957. }
  958. foreach $section (@{$args{'sectionlist'}}) {
  959. print ".SH \"", uc $section, "\"\n";
  960. output_highlight($args{'sections'}{$section});
  961. }
  962. }
  963. ##
  964. # output enum in man
  965. sub output_enum_man(%) {
  966. my %args = %{$_[0]};
  967. my ($parameter, $section);
  968. my $count;
  969. print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
  970. print ".SH NAME\n";
  971. print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
  972. print ".SH SYNOPSIS\n";
  973. print "enum ".$args{'enum'}." {\n";
  974. $count = 0;
  975. foreach my $parameter (@{$args{'parameterlist'}}) {
  976. print ".br\n.BI \" $parameter\"\n";
  977. if ($count == $#{$args{'parameterlist'}}) {
  978. print "\n};\n";
  979. last;
  980. }
  981. else {
  982. print ", \n.br\n";
  983. }
  984. $count++;
  985. }
  986. print ".SH Constants\n";
  987. foreach $parameter (@{$args{'parameterlist'}}) {
  988. my $parameter_name = $parameter;
  989. $parameter_name =~ s/\[.*//;
  990. print ".IP \"".$parameter."\" 12\n";
  991. output_highlight($args{'parameterdescs'}{$parameter_name});
  992. }
  993. foreach $section (@{$args{'sectionlist'}}) {
  994. print ".SH \"$section\"\n";
  995. output_highlight($args{'sections'}{$section});
  996. }
  997. }
  998. ##
  999. # output struct in man
  1000. sub output_struct_man(%) {
  1001. my %args = %{$_[0]};
  1002. my ($parameter, $section);
  1003. print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
  1004. print ".SH NAME\n";
  1005. print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
  1006. print ".SH SYNOPSIS\n";
  1007. print $args{'type'}." ".$args{'struct'}." {\n.br\n";
  1008. foreach my $parameter (@{$args{'parameterlist'}}) {
  1009. if ($parameter =~ /^#/) {
  1010. print ".BI \"$parameter\"\n.br\n";
  1011. next;
  1012. }
  1013. my $parameter_name = $parameter;
  1014. $parameter_name =~ s/\[.*//;
  1015. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1016. $type = $args{'parametertypes'}{$parameter};
  1017. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1018. # pointer-to-function
  1019. print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
  1020. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1021. # bitfield
  1022. print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
  1023. } else {
  1024. $type =~ s/([^\*])$/$1 /;
  1025. print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
  1026. }
  1027. print "\n.br\n";
  1028. }
  1029. print "};\n.br\n";
  1030. print ".SH Members\n";
  1031. foreach $parameter (@{$args{'parameterlist'}}) {
  1032. ($parameter =~ /^#/) && next;
  1033. my $parameter_name = $parameter;
  1034. $parameter_name =~ s/\[.*//;
  1035. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1036. print ".IP \"".$parameter."\" 12\n";
  1037. output_highlight($args{'parameterdescs'}{$parameter_name});
  1038. }
  1039. foreach $section (@{$args{'sectionlist'}}) {
  1040. print ".SH \"$section\"\n";
  1041. output_highlight($args{'sections'}{$section});
  1042. }
  1043. }
  1044. ##
  1045. # output typedef in man
  1046. sub output_typedef_man(%) {
  1047. my %args = %{$_[0]};
  1048. my ($parameter, $section);
  1049. print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1050. print ".SH NAME\n";
  1051. print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
  1052. foreach $section (@{$args{'sectionlist'}}) {
  1053. print ".SH \"$section\"\n";
  1054. output_highlight($args{'sections'}{$section});
  1055. }
  1056. }
  1057. sub output_blockhead_man(%) {
  1058. my %args = %{$_[0]};
  1059. my ($parameter, $section);
  1060. my $count;
  1061. print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1062. foreach $section (@{$args{'sectionlist'}}) {
  1063. print ".SH \"$section\"\n";
  1064. output_highlight($args{'sections'}{$section});
  1065. }
  1066. }
  1067. ##
  1068. # output in text
  1069. sub output_function_text(%) {
  1070. my %args = %{$_[0]};
  1071. my ($parameter, $section);
  1072. my $start;
  1073. print "Name:\n\n";
  1074. print $args{'function'}." - ".$args{'purpose'}."\n";
  1075. print "\nSynopsis:\n\n";
  1076. if ($args{'functiontype'} ne "") {
  1077. $start = $args{'functiontype'}." ".$args{'function'}." (";
  1078. } else {
  1079. $start = $args{'function'}." (";
  1080. }
  1081. print $start;
  1082. my $count = 0;
  1083. foreach my $parameter (@{$args{'parameterlist'}}) {
  1084. $type = $args{'parametertypes'}{$parameter};
  1085. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1086. # pointer-to-function
  1087. print $1.$parameter.") (".$2;
  1088. } else {
  1089. print $type." ".$parameter;
  1090. }
  1091. if ($count != $#{$args{'parameterlist'}}) {
  1092. $count++;
  1093. print ",\n";
  1094. print " " x length($start);
  1095. } else {
  1096. print ");\n\n";
  1097. }
  1098. }
  1099. print "Arguments:\n\n";
  1100. foreach $parameter (@{$args{'parameterlist'}}) {
  1101. my $parameter_name = $parameter;
  1102. $parameter_name =~ s/\[.*//;
  1103. print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
  1104. }
  1105. output_section_text(@_);
  1106. }
  1107. #output sections in text
  1108. sub output_section_text(%) {
  1109. my %args = %{$_[0]};
  1110. my $section;
  1111. print "\n";
  1112. foreach $section (@{$args{'sectionlist'}}) {
  1113. print "$section:\n\n";
  1114. output_highlight($args{'sections'}{$section});
  1115. }
  1116. print "\n\n";
  1117. }
  1118. # output enum in text
  1119. sub output_enum_text(%) {
  1120. my %args = %{$_[0]};
  1121. my ($parameter);
  1122. my $count;
  1123. print "Enum:\n\n";
  1124. print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
  1125. print "enum ".$args{'enum'}." {\n";
  1126. $count = 0;
  1127. foreach $parameter (@{$args{'parameterlist'}}) {
  1128. print "\t$parameter";
  1129. if ($count != $#{$args{'parameterlist'}}) {
  1130. $count++;
  1131. print ",";
  1132. }
  1133. print "\n";
  1134. }
  1135. print "};\n\n";
  1136. print "Constants:\n\n";
  1137. foreach $parameter (@{$args{'parameterlist'}}) {
  1138. print "$parameter\n\t";
  1139. print $args{'parameterdescs'}{$parameter}."\n";
  1140. }
  1141. output_section_text(@_);
  1142. }
  1143. # output typedef in text
  1144. sub output_typedef_text(%) {
  1145. my %args = %{$_[0]};
  1146. my ($parameter);
  1147. my $count;
  1148. print "Typedef:\n\n";
  1149. print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
  1150. output_section_text(@_);
  1151. }
  1152. # output struct as text
  1153. sub output_struct_text(%) {
  1154. my %args = %{$_[0]};
  1155. my ($parameter);
  1156. print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
  1157. print $args{'type'}." ".$args{'struct'}." {\n";
  1158. foreach $parameter (@{$args{'parameterlist'}}) {
  1159. if ($parameter =~ /^#/) {
  1160. print "$parameter\n";
  1161. next;
  1162. }
  1163. my $parameter_name = $parameter;
  1164. $parameter_name =~ s/\[.*//;
  1165. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1166. $type = $args{'parametertypes'}{$parameter};
  1167. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1168. # pointer-to-function
  1169. print "\t$1 $parameter) ($2);\n";
  1170. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1171. # bitfield
  1172. print "\t$1 $parameter$2;\n";
  1173. } else {
  1174. print "\t".$type." ".$parameter.";\n";
  1175. }
  1176. }
  1177. print "};\n\n";
  1178. print "Members:\n\n";
  1179. foreach $parameter (@{$args{'parameterlist'}}) {
  1180. ($parameter =~ /^#/) && next;
  1181. my $parameter_name = $parameter;
  1182. $parameter_name =~ s/\[.*//;
  1183. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1184. print "$parameter\n\t";
  1185. print $args{'parameterdescs'}{$parameter_name}."\n";
  1186. }
  1187. print "\n";
  1188. output_section_text(@_);
  1189. }
  1190. sub output_blockhead_text(%) {
  1191. my %args = %{$_[0]};
  1192. my ($parameter, $section);
  1193. foreach $section (@{$args{'sectionlist'}}) {
  1194. print " $section:\n";
  1195. print " -> ";
  1196. output_highlight($args{'sections'}{$section});
  1197. }
  1198. }
  1199. ##
  1200. # generic output function for all types (function, struct/union, typedef, enum);
  1201. # calls the generated, variable output_ function name based on
  1202. # functype and output_mode
  1203. sub output_declaration {
  1204. no strict 'refs';
  1205. my $name = shift;
  1206. my $functype = shift;
  1207. my $func = "output_${functype}_$output_mode";
  1208. if (($function_only==0) ||
  1209. ( $function_only == 1 && defined($function_table{$name})) ||
  1210. ( $function_only == 2 && !defined($function_table{$name})))
  1211. {
  1212. &$func(@_);
  1213. $section_counter++;
  1214. }
  1215. }
  1216. ##
  1217. # generic output function - calls the right one based on current output mode.
  1218. sub output_blockhead {
  1219. no strict 'refs';
  1220. my $func = "output_blockhead_".$output_mode;
  1221. &$func(@_);
  1222. $section_counter++;
  1223. }
  1224. ##
  1225. # takes a declaration (struct, union, enum, typedef) and
  1226. # invokes the right handler. NOT called for functions.
  1227. sub dump_declaration($$) {
  1228. no strict 'refs';
  1229. my ($prototype, $file) = @_;
  1230. my $func = "dump_".$decl_type;
  1231. &$func(@_);
  1232. }
  1233. sub dump_union($$) {
  1234. dump_struct(@_);
  1235. }
  1236. sub dump_struct($$) {
  1237. my $x = shift;
  1238. my $file = shift;
  1239. my $nested;
  1240. if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
  1241. $declaration_name = $2;
  1242. my $members = $3;
  1243. # ignore embedded structs or unions
  1244. $members =~ s/({.*})//g;
  1245. $nested = $1;
  1246. # ignore members marked private:
  1247. $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
  1248. $members =~ s/\/\*.*?private:.*//gos;
  1249. # strip comments:
  1250. $members =~ s/\/\*.*?\*\///gos;
  1251. $nested =~ s/\/\*.*?\*\///gos;
  1252. create_parameterlist($members, ';', $file);
  1253. check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
  1254. output_declaration($declaration_name,
  1255. 'struct',
  1256. {'struct' => $declaration_name,
  1257. 'module' => $modulename,
  1258. 'parameterlist' => \@parameterlist,
  1259. 'parameterdescs' => \%parameterdescs,
  1260. 'parametertypes' => \%parametertypes,
  1261. 'sectionlist' => \@sectionlist,
  1262. 'sections' => \%sections,
  1263. 'purpose' => $declaration_purpose,
  1264. 'type' => $decl_type
  1265. });
  1266. }
  1267. else {
  1268. print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
  1269. ++$errors;
  1270. }
  1271. }
  1272. sub dump_enum($$) {
  1273. my $x = shift;
  1274. my $file = shift;
  1275. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1276. if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
  1277. $declaration_name = $1;
  1278. my $members = $2;
  1279. foreach my $arg (split ',', $members) {
  1280. $arg =~ s/^\s*(\w+).*/$1/;
  1281. push @parameterlist, $arg;
  1282. if (!$parameterdescs{$arg}) {
  1283. $parameterdescs{$arg} = $undescribed;
  1284. print STDERR "Warning(${file}:$.): Enum value '$arg' ".
  1285. "not described in enum '$declaration_name'\n";
  1286. }
  1287. }
  1288. output_declaration($declaration_name,
  1289. 'enum',
  1290. {'enum' => $declaration_name,
  1291. 'module' => $modulename,
  1292. 'parameterlist' => \@parameterlist,
  1293. 'parameterdescs' => \%parameterdescs,
  1294. 'sectionlist' => \@sectionlist,
  1295. 'sections' => \%sections,
  1296. 'purpose' => $declaration_purpose
  1297. });
  1298. }
  1299. else {
  1300. print STDERR "Error(${file}:$.): Cannot parse enum!\n";
  1301. ++$errors;
  1302. }
  1303. }
  1304. sub dump_typedef($$) {
  1305. my $x = shift;
  1306. my $file = shift;
  1307. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1308. while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
  1309. $x =~ s/\(*.\)\s*;$/;/;
  1310. $x =~ s/\[*.\]\s*;$/;/;
  1311. }
  1312. if ($x =~ /typedef.*\s+(\w+)\s*;/) {
  1313. $declaration_name = $1;
  1314. output_declaration($declaration_name,
  1315. 'typedef',
  1316. {'typedef' => $declaration_name,
  1317. 'module' => $modulename,
  1318. 'sectionlist' => \@sectionlist,
  1319. 'sections' => \%sections,
  1320. 'purpose' => $declaration_purpose
  1321. });
  1322. }
  1323. else {
  1324. print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
  1325. ++$errors;
  1326. }
  1327. }
  1328. sub save_struct_actual($) {
  1329. my $actual = shift;
  1330. # strip all spaces from the actual param so that it looks like one string item
  1331. $actual =~ s/\s*//g;
  1332. $struct_actual = $struct_actual . $actual . " ";
  1333. }
  1334. sub create_parameterlist($$$) {
  1335. my $args = shift;
  1336. my $splitter = shift;
  1337. my $file = shift;
  1338. my $type;
  1339. my $param;
  1340. # temporarily replace commas inside function pointer definition
  1341. while ($args =~ /(\([^\),]+),/) {
  1342. $args =~ s/(\([^\),]+),/$1#/g;
  1343. }
  1344. foreach my $arg (split($splitter, $args)) {
  1345. # strip comments
  1346. $arg =~ s/\/\*.*\*\///;
  1347. # strip leading/trailing spaces
  1348. $arg =~ s/^\s*//;
  1349. $arg =~ s/\s*$//;
  1350. $arg =~ s/\s+/ /;
  1351. if ($arg =~ /^#/) {
  1352. # Treat preprocessor directive as a typeless variable just to fill
  1353. # corresponding data structures "correctly". Catch it later in
  1354. # output_* subs.
  1355. push_parameter($arg, "", $file);
  1356. } elsif ($arg =~ m/\(.+\)\s*\(/) {
  1357. # pointer-to-function
  1358. $arg =~ tr/#/,/;
  1359. $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
  1360. $param = $1;
  1361. $type = $arg;
  1362. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1363. save_struct_actual($param);
  1364. push_parameter($param, $type, $file);
  1365. } elsif ($arg) {
  1366. $arg =~ s/\s*:\s*/:/g;
  1367. $arg =~ s/\s*\[/\[/g;
  1368. my @args = split('\s*,\s*', $arg);
  1369. if ($args[0] =~ m/\*/) {
  1370. $args[0] =~ s/(\*+)\s*/ $1/;
  1371. }
  1372. my @first_arg;
  1373. if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
  1374. shift @args;
  1375. push(@first_arg, split('\s+', $1));
  1376. push(@first_arg, $2);
  1377. } else {
  1378. @first_arg = split('\s+', shift @args);
  1379. }
  1380. unshift(@args, pop @first_arg);
  1381. $type = join " ", @first_arg;
  1382. foreach $param (@args) {
  1383. if ($param =~ m/^(\*+)\s*(.*)/) {
  1384. save_struct_actual($2);
  1385. push_parameter($2, "$type $1", $file);
  1386. }
  1387. elsif ($param =~ m/(.*?):(\d+)/) {
  1388. if ($type ne "") { # skip unnamed bit-fields
  1389. save_struct_actual($1);
  1390. push_parameter($1, "$type:$2", $file)
  1391. }
  1392. }
  1393. else {
  1394. save_struct_actual($param);
  1395. push_parameter($param, $type, $file);
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. sub push_parameter($$$) {
  1402. my $param = shift;
  1403. my $type = shift;
  1404. my $file = shift;
  1405. if (($anon_struct_union == 1) && ($type eq "") &&
  1406. ($param eq "}")) {
  1407. return; # ignore the ending }; from anon. struct/union
  1408. }
  1409. $anon_struct_union = 0;
  1410. my $param_name = $param;
  1411. $param_name =~ s/\[.*//;
  1412. if ($type eq "" && $param =~ /\.\.\.$/)
  1413. {
  1414. if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
  1415. $parameterdescs{$param} = "variable arguments";
  1416. }
  1417. }
  1418. elsif ($type eq "" && ($param eq "" or $param eq "void"))
  1419. {
  1420. $param="void";
  1421. $parameterdescs{void} = "no arguments";
  1422. }
  1423. elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
  1424. # handle unnamed (anonymous) union or struct:
  1425. {
  1426. $type = $param;
  1427. $param = "{unnamed_" . $param . "}";
  1428. $parameterdescs{$param} = "anonymous\n";
  1429. $anon_struct_union = 1;
  1430. }
  1431. # warn if parameter has no description
  1432. # (but ignore ones starting with # as these are not parameters
  1433. # but inline preprocessor statements);
  1434. # also ignore unnamed structs/unions;
  1435. if (!$anon_struct_union) {
  1436. if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
  1437. $parameterdescs{$param_name} = $undescribed;
  1438. if (($type eq 'function') || ($type eq 'enum')) {
  1439. print STDERR "Warning(${file}:$.): Function parameter ".
  1440. "or member '$param' not " .
  1441. "described in '$declaration_name'\n";
  1442. }
  1443. print STDERR "Warning(${file}:$.):".
  1444. " No description found for parameter '$param'\n";
  1445. ++$warnings;
  1446. }
  1447. }
  1448. push @parameterlist, $param;
  1449. $parametertypes{$param} = $type;
  1450. }
  1451. sub check_sections($$$$$$) {
  1452. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
  1453. my @sects = split ' ', $sectcheck;
  1454. my @prms = split ' ', $prmscheck;
  1455. my $err;
  1456. my ($px, $sx);
  1457. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  1458. foreach $sx (0 .. $#sects) {
  1459. $err = 1;
  1460. foreach $px (0 .. $#prms) {
  1461. $prm_clean = $prms[$px];
  1462. $prm_clean =~ s/\[.*\]//;
  1463. $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//;
  1464. ##$prm_clean =~ s/^\**//;
  1465. if ($prm_clean eq $sects[$sx]) {
  1466. $err = 0;
  1467. last;
  1468. }
  1469. }
  1470. if ($err) {
  1471. if ($decl_type eq "function") {
  1472. print STDERR "Warning(${file}:$.): " .
  1473. "Excess function parameter " .
  1474. "'$sects[$sx]' " .
  1475. "description in '$decl_name'\n";
  1476. ++$warnings;
  1477. } else {
  1478. if ($nested !~ m/\Q$sects[$sx]\E/) {
  1479. print STDERR "Warning(${file}:$.): " .
  1480. "Excess struct/union/enum/typedef member " .
  1481. "'$sects[$sx]' " .
  1482. "description in '$decl_name'\n";
  1483. ++$warnings;
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. ##
  1490. # takes a function prototype and the name of the current file being
  1491. # processed and spits out all the details stored in the global
  1492. # arrays/hashes.
  1493. sub dump_function($$) {
  1494. my $prototype = shift;
  1495. my $file = shift;
  1496. $prototype =~ s/^static +//;
  1497. $prototype =~ s/^extern +//;
  1498. $prototype =~ s/^asmlinkage +//;
  1499. $prototype =~ s/^inline +//;
  1500. $prototype =~ s/^__inline__ +//;
  1501. $prototype =~ s/^__inline +//;
  1502. $prototype =~ s/^__always_inline +//;
  1503. $prototype =~ s/^noinline +//;
  1504. $prototype =~ s/__devinit +//;
  1505. $prototype =~ s/__init +//;
  1506. $prototype =~ s/^#\s*define\s+//; #ak added
  1507. $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
  1508. # Yes, this truly is vile. We are looking for:
  1509. # 1. Return type (may be nothing if we're looking at a macro)
  1510. # 2. Function name
  1511. # 3. Function parameters.
  1512. #
  1513. # All the while we have to watch out for function pointer parameters
  1514. # (which IIRC is what the two sections are for), C types (these
  1515. # regexps don't even start to express all the possibilities), and
  1516. # so on.
  1517. #
  1518. # If you mess with these regexps, it's a good idea to check that
  1519. # the following functions' documentation still comes out right:
  1520. # - parport_register_device (function pointer parameters)
  1521. # - atomic_set (macro)
  1522. # - pci_match_device, __copy_to_user (long return type)
  1523. if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1524. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1525. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1526. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1527. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1528. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1529. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1530. $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1531. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1532. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1533. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1534. $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1535. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1536. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1537. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1538. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1539. $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  1540. $return_type = $1;
  1541. $declaration_name = $2;
  1542. my $args = $3;
  1543. create_parameterlist($args, ',', $file);
  1544. } else {
  1545. print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
  1546. ++$errors;
  1547. return;
  1548. }
  1549. my $prms = join " ", @parameterlist;
  1550. check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
  1551. output_declaration($declaration_name,
  1552. 'function',
  1553. {'function' => $declaration_name,
  1554. 'module' => $modulename,
  1555. 'functiontype' => $return_type,
  1556. 'parameterlist' => \@parameterlist,
  1557. 'parameterdescs' => \%parameterdescs,
  1558. 'parametertypes' => \%parametertypes,
  1559. 'sectionlist' => \@sectionlist,
  1560. 'sections' => \%sections,
  1561. 'purpose' => $declaration_purpose
  1562. });
  1563. }
  1564. sub process_file($);
  1565. # Read the file that maps relative names to absolute names for
  1566. # separate source and object directories and for shadow trees.
  1567. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  1568. my ($relname, $absname);
  1569. while(<SOURCE_MAP>) {
  1570. chop();
  1571. ($relname, $absname) = (split())[0..1];
  1572. $relname =~ s:^/+::;
  1573. $source_map{$relname} = $absname;
  1574. }
  1575. close(SOURCE_MAP);
  1576. }
  1577. if ($filelist) {
  1578. open(FLIST,"<$filelist") or die "Can't open file list $filelist";
  1579. while(<FLIST>) {
  1580. chop;
  1581. process_file($_);
  1582. }
  1583. }
  1584. foreach (@ARGV) {
  1585. chomp;
  1586. process_file($_);
  1587. }
  1588. if ($verbose && $errors) {
  1589. print STDERR "$errors errors\n";
  1590. }
  1591. if ($verbose && $warnings) {
  1592. print STDERR "$warnings warnings\n";
  1593. }
  1594. exit($errors);
  1595. sub reset_state {
  1596. $function = "";
  1597. %constants = ();
  1598. %parameterdescs = ();
  1599. %parametertypes = ();
  1600. @parameterlist = ();
  1601. %sections = ();
  1602. @sectionlist = ();
  1603. $sectcheck = "";
  1604. $struct_actual = "";
  1605. $prototype = "";
  1606. $state = 0;
  1607. }
  1608. sub process_state3_function($$) {
  1609. my $x = shift;
  1610. my $file = shift;
  1611. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1612. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  1613. # do nothing
  1614. }
  1615. elsif ($x =~ /([^\{]*)/) {
  1616. $prototype .= $1;
  1617. }
  1618. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  1619. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  1620. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1621. $prototype =~ s@^\s+@@gos; # strip leading spaces
  1622. dump_function($prototype,$file);
  1623. reset_state();
  1624. }
  1625. }
  1626. sub process_state3_type($$) {
  1627. my $x = shift;
  1628. my $file = shift;
  1629. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1630. $x =~ s@^\s+@@gos; # strip leading spaces
  1631. $x =~ s@\s+$@@gos; # strip trailing spaces
  1632. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1633. if ($x =~ /^#/) {
  1634. # To distinguish preprocessor directive from regular declaration later.
  1635. $x .= ";";
  1636. }
  1637. while (1) {
  1638. if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
  1639. $prototype .= $1 . $2;
  1640. ($2 eq '{') && $brcount++;
  1641. ($2 eq '}') && $brcount--;
  1642. if (($2 eq ';') && ($brcount == 0)) {
  1643. dump_declaration($prototype,$file);
  1644. reset_state();
  1645. last;
  1646. }
  1647. $x = $3;
  1648. } else {
  1649. $prototype .= $x;
  1650. last;
  1651. }
  1652. }
  1653. }
  1654. # xml_escape: replace <, >, and & in the text stream;
  1655. #
  1656. # however, formatting controls that are generated internally/locally in the
  1657. # kernel-doc script are not escaped here; instead, they begin life like
  1658. # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
  1659. # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
  1660. # just before actual output; (this is done by local_unescape())
  1661. sub xml_escape($) {
  1662. my $text = shift;
  1663. if (($output_mode eq "text") || ($output_mode eq "man")) {
  1664. return $text;
  1665. }
  1666. $text =~ s/\&/\\\\\\amp;/g;
  1667. $text =~ s/\</\\\\\\lt;/g;
  1668. $text =~ s/\>/\\\\\\gt;/g;
  1669. return $text;
  1670. }
  1671. # convert local escape strings to html
  1672. # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
  1673. sub local_unescape($) {
  1674. my $text = shift;
  1675. if (($output_mode eq "text") || ($output_mode eq "man")) {
  1676. return $text;
  1677. }
  1678. $text =~ s/\\\\\\\\lt:/</g;
  1679. $text =~ s/\\\\\\\\gt:/>/g;
  1680. return $text;
  1681. }
  1682. sub process_file($) {
  1683. my $file;
  1684. my $identifier;
  1685. my $func;
  1686. my $descr;
  1687. my $initial_section_counter = $section_counter;
  1688. if (defined($ENV{'SRCTREE'})) {
  1689. $file = "$ENV{'SRCTREE'}" . "/" . "@_";
  1690. }
  1691. else {
  1692. $file = "@_";
  1693. }
  1694. if (defined($source_map{$file})) {
  1695. $file = $source_map{$file};
  1696. }
  1697. if (!open(IN,"<$file")) {
  1698. print STDERR "Error: Cannot open file $file\n";
  1699. ++$errors;
  1700. return;
  1701. }
  1702. $section_counter = 0;
  1703. while (<IN>) {
  1704. if ($state == 0) {
  1705. if (/$doc_start/o) {
  1706. $state = 1; # next line is always the function name
  1707. $in_doc_sect = 0;
  1708. }
  1709. } elsif ($state == 1) { # this line is the function name (always)
  1710. if (/$doc_block/o) {
  1711. $state = 4;
  1712. $contents = "";
  1713. if ( $1 eq "" ) {
  1714. $section = $section_intro;
  1715. } else {
  1716. $section = $1;
  1717. }
  1718. }
  1719. elsif (/$doc_decl/o) {
  1720. $identifier = $1;
  1721. if (/\s*([\w\s]+?)\s*-/) {
  1722. $identifier = $1;
  1723. }
  1724. $state = 2;
  1725. if (/-(.*)/) {
  1726. # strip leading/trailing/multiple spaces
  1727. $descr= $1;
  1728. $descr =~ s/^\s*//;
  1729. $descr =~ s/\s*$//;
  1730. $descr =~ s/\s+/ /;
  1731. $declaration_purpose = xml_escape($descr);
  1732. } else {
  1733. $declaration_purpose = "";
  1734. }
  1735. if (($declaration_purpose eq "") && $verbose) {
  1736. print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
  1737. print STDERR $_;
  1738. ++$warnings;
  1739. }
  1740. if ($identifier =~ m/^struct/) {
  1741. $decl_type = 'struct';
  1742. } elsif ($identifier =~ m/^union/) {
  1743. $decl_type = 'union';
  1744. } elsif ($identifier =~ m/^enum/) {
  1745. $decl_type = 'enum';
  1746. } elsif ($identifier =~ m/^typedef/) {
  1747. $decl_type = 'typedef';
  1748. } else {
  1749. $decl_type = 'function';
  1750. }
  1751. if ($verbose) {
  1752. print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
  1753. }
  1754. } else {
  1755. print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
  1756. " - I thought it was a doc line\n";
  1757. ++$warnings;
  1758. $state = 0;
  1759. }
  1760. } elsif ($state == 2) { # look for head: lines, and include content
  1761. if (/$doc_sect/o) {
  1762. $newsection = $1;
  1763. $newcontents = $2;
  1764. if (($contents ne "") && ($contents ne "\n")) {
  1765. if (!$in_doc_sect && $verbose) {
  1766. print STDERR "Warning(${file}:$.): contents before sections\n";
  1767. ++$warnings;
  1768. }
  1769. dump_section($file, $section, xml_escape($contents));
  1770. $section = $section_default;
  1771. }
  1772. $in_doc_sect = 1;
  1773. $contents = $newcontents;
  1774. if ($contents ne "") {
  1775. while ((substr($contents, 0, 1) eq " ") ||
  1776. substr($contents, 0, 1) eq "\t") {
  1777. $contents = substr($contents, 1);
  1778. }
  1779. $contents .= "\n";
  1780. }
  1781. $section = $newsection;
  1782. } elsif (/$doc_end/) {
  1783. if ($contents ne "") {
  1784. dump_section($file, $section, xml_escape($contents));
  1785. $section = $section_default;
  1786. $contents = "";
  1787. }
  1788. # look for doc_com + <text> + doc_end:
  1789. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  1790. print STDERR "Warning(${file}:$.): suspicious ending line: $_";
  1791. ++$warnings;
  1792. }
  1793. $prototype = "";
  1794. $state = 3;
  1795. $brcount = 0;
  1796. # print STDERR "end of doc comment, looking for prototype\n";
  1797. } elsif (/$doc_content/) {
  1798. # miguel-style comment kludge, look for blank lines after
  1799. # @parameter line to signify start of description
  1800. if ($1 eq "" &&
  1801. ($section =~ m/^@/ || $section eq $section_context)) {
  1802. dump_section($file, $section, xml_escape($contents));
  1803. $section = $section_default;
  1804. $contents = "";
  1805. } else {
  1806. $contents .= $1."\n";
  1807. }
  1808. } else {
  1809. # i dont know - bad line? ignore.
  1810. print STDERR "Warning(${file}:$.): bad line: $_";
  1811. ++$warnings;
  1812. }
  1813. } elsif ($state == 3) { # scanning for function '{' (end of prototype)
  1814. if ($decl_type eq 'function') {
  1815. process_state3_function($_, $file);
  1816. } else {
  1817. process_state3_type($_, $file);
  1818. }
  1819. } elsif ($state == 4) {
  1820. # Documentation block
  1821. if (/$doc_block/) {
  1822. dump_doc_section($file, $section, xml_escape($contents));
  1823. $contents = "";
  1824. $function = "";
  1825. %constants = ();
  1826. %parameterdescs = ();
  1827. %parametertypes = ();
  1828. @parameterlist = ();
  1829. %sections = ();
  1830. @sectionlist = ();
  1831. $prototype = "";
  1832. if ( $1 eq "" ) {
  1833. $section = $section_intro;
  1834. } else {
  1835. $section = $1;
  1836. }
  1837. }
  1838. elsif (/$doc_end/)
  1839. {
  1840. dump_doc_section($file, $section, xml_escape($contents));
  1841. $contents = "";
  1842. $function = "";
  1843. %constants = ();
  1844. %parameterdescs = ();
  1845. %parametertypes = ();
  1846. @parameterlist = ();
  1847. %sections = ();
  1848. @sectionlist = ();
  1849. $prototype = "";
  1850. $state = 0;
  1851. }
  1852. elsif (/$doc_content/)
  1853. {
  1854. if ( $1 eq "" )
  1855. {
  1856. $contents .= $blankline;
  1857. }
  1858. else
  1859. {
  1860. $contents .= $1 . "\n";
  1861. }
  1862. }
  1863. }
  1864. }
  1865. if ($initial_section_counter == $section_counter) {
  1866. print STDERR "Warning(${file}): no structured comments found\n";
  1867. if ($output_mode eq "xml") {
  1868. # The template wants at least one RefEntry here; make one.
  1869. print "<refentry>\n";
  1870. print " <refnamediv>\n";
  1871. print " <refname>\n";
  1872. print " ${file}\n";
  1873. print " </refname>\n";
  1874. print " <refpurpose>\n";
  1875. print " Document generation inconsistency\n";
  1876. print " </refpurpose>\n";
  1877. print " </refnamediv>\n";
  1878. print " <refsect1>\n";
  1879. print " <title>\n";
  1880. print " Oops\n";
  1881. print " </title>\n";
  1882. print " <warning>\n";
  1883. print " <para>\n";
  1884. print " The template for this document tried to insert\n";
  1885. print " the structured comment from the file\n";
  1886. print " <filename>${file}</filename> at this point,\n";
  1887. print " but none was found.\n";
  1888. print " This dummy section is inserted to allow\n";
  1889. print " generation to continue.\n";
  1890. print " </para>\n";
  1891. print " </warning>\n";
  1892. print " </refsect1>\n";
  1893. print "</refentry>\n";
  1894. }
  1895. }
  1896. }