kernel-doc 62 KB

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