kernel-doc 55 KB

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