kernel-doc 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972
  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-2012 Randy Dunlap ##
  7. ## Copyright (C) 2012 Dan Luedtke ##
  8. ## ##
  9. ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
  10. ## Copyright (c) 2000 MontaVista Software, Inc. ##
  11. ## ##
  12. ## This software falls under the GNU General Public License. ##
  13. ## Please read the COPYING file for more information ##
  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. # 25/07/2012 - Added support for HTML5
  32. # -- Dan Luedtke <mail@danrl.de>
  33. sub usage {
  34. my $message = <<"EOF";
  35. Usage: $0 [OPTION ...] FILE ...
  36. Read C language source or header FILEs, extract embedded documentation comments,
  37. and print formatted documentation to standard output.
  38. The documentation comments are identified by "/**" opening comment mark. See
  39. Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
  40. Output format selection (mutually exclusive):
  41. -docbook Output DocBook format.
  42. -html Output HTML format.
  43. -html5 Output HTML5 format.
  44. -list Output symbol list format. This is for use by docproc.
  45. -man Output troff manual page format. This is the default.
  46. -rst Output reStructuredText format.
  47. -text Output plain text format.
  48. Output selection (mutually exclusive):
  49. -function NAME Only output documentation for the given function(s)
  50. or DOC: section title(s). All other functions and DOC:
  51. sections are ignored. May be specified multiple times.
  52. -nofunction NAME Do NOT output documentation for the given function(s);
  53. only output documentation for the other functions and
  54. DOC: sections. May be specified multiple times.
  55. Output selection modifiers:
  56. -no-doc-sections Do not output DOC: sections.
  57. Other parameters:
  58. -v Verbose output, more warnings and other information.
  59. -h Print this help.
  60. EOF
  61. print $message;
  62. exit 1;
  63. }
  64. #
  65. # format of comments.
  66. # In the following table, (...)? signifies optional structure.
  67. # (...)* signifies 0 or more structure elements
  68. # /**
  69. # * function_name(:)? (- short description)?
  70. # (* @parameterx: (description of parameter x)?)*
  71. # (* a blank line)?
  72. # * (Description:)? (Description of function)?
  73. # * (section header: (section description)? )*
  74. # (*)?*/
  75. #
  76. # So .. the trivial example would be:
  77. #
  78. # /**
  79. # * my_function
  80. # */
  81. #
  82. # If the Description: header tag is omitted, then there must be a blank line
  83. # after the last parameter specification.
  84. # e.g.
  85. # /**
  86. # * my_function - does my stuff
  87. # * @my_arg: its mine damnit
  88. # *
  89. # * Does my stuff explained.
  90. # */
  91. #
  92. # or, could also use:
  93. # /**
  94. # * my_function - does my stuff
  95. # * @my_arg: its mine damnit
  96. # * Description: Does my stuff explained.
  97. # */
  98. # etc.
  99. #
  100. # Besides functions you can also write documentation for structs, unions,
  101. # enums and typedefs. Instead of the function name you must write the name
  102. # of the declaration; the struct/union/enum/typedef must always precede
  103. # the name. Nesting of declarations is not supported.
  104. # Use the argument mechanism to document members or constants.
  105. # e.g.
  106. # /**
  107. # * struct my_struct - short description
  108. # * @a: first member
  109. # * @b: second member
  110. # *
  111. # * Longer description
  112. # */
  113. # struct my_struct {
  114. # int a;
  115. # int b;
  116. # /* private: */
  117. # int c;
  118. # };
  119. #
  120. # All descriptions can be multiline, except the short function description.
  121. #
  122. # For really longs structs, you can also describe arguments inside the
  123. # body of the struct.
  124. # eg.
  125. # /**
  126. # * struct my_struct - short description
  127. # * @a: first member
  128. # * @b: second member
  129. # *
  130. # * Longer description
  131. # */
  132. # struct my_struct {
  133. # int a;
  134. # int b;
  135. # /**
  136. # * @c: This is longer description of C
  137. # *
  138. # * You can use paragraphs to describe arguments
  139. # * using this method.
  140. # */
  141. # int c;
  142. # };
  143. #
  144. # This should be use only for struct/enum members.
  145. #
  146. # You can also add additional sections. When documenting kernel functions you
  147. # should document the "Context:" of the function, e.g. whether the functions
  148. # can be called form interrupts. Unlike other sections you can end it with an
  149. # empty line.
  150. # A non-void function should have a "Return:" section describing the return
  151. # value(s).
  152. # Example-sections should contain the string EXAMPLE so that they are marked
  153. # appropriately in DocBook.
  154. #
  155. # Example:
  156. # /**
  157. # * user_function - function that can only be called in user context
  158. # * @a: some argument
  159. # * Context: !in_interrupt()
  160. # *
  161. # * Some description
  162. # * Example:
  163. # * user_function(22);
  164. # */
  165. # ...
  166. #
  167. #
  168. # All descriptive text is further processed, scanning for the following special
  169. # patterns, which are highlighted appropriately.
  170. #
  171. # 'funcname()' - function
  172. # '$ENVVAR' - environmental variable
  173. # '&struct_name' - name of a structure (up to two words including 'struct')
  174. # '@parameter' - name of a parameter
  175. # '%CONST' - name of a constant.
  176. ## init lots of data
  177. my $errors = 0;
  178. my $warnings = 0;
  179. my $anon_struct_union = 0;
  180. # match expressions used to find embedded type information
  181. my $type_constant = '\%([-_\w]+)';
  182. my $type_func = '(\w+)\(\)';
  183. my $type_param = '\@(\w+)';
  184. my $type_struct = '\&((struct\s*)*[_\w]+)';
  185. my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
  186. my $type_env = '(\$\w+)';
  187. my $type_enum_full = '\&(enum)\s*([_\w]+)';
  188. my $type_struct_full = '\&(struct)\s*([_\w]+)';
  189. # Output conversion substitutions.
  190. # One for each output format
  191. # these work fairly well
  192. my @highlights_html = (
  193. [$type_constant, "<i>\$1</i>"],
  194. [$type_func, "<b>\$1</b>"],
  195. [$type_struct_xml, "<i>\$1</i>"],
  196. [$type_env, "<b><i>\$1</i></b>"],
  197. [$type_param, "<tt><b>\$1</b></tt>"]
  198. );
  199. my $local_lt = "\\\\\\\\lt:";
  200. my $local_gt = "\\\\\\\\gt:";
  201. my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
  202. # html version 5
  203. my @highlights_html5 = (
  204. [$type_constant, "<span class=\"const\">\$1</span>"],
  205. [$type_func, "<span class=\"func\">\$1</span>"],
  206. [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
  207. [$type_env, "<span class=\"env\">\$1</span>"],
  208. [$type_param, "<span class=\"param\">\$1</span>]"]
  209. );
  210. my $blankline_html5 = $local_lt . "br /" . $local_gt;
  211. # XML, docbook format
  212. my @highlights_xml = (
  213. ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
  214. [$type_constant, "<constant>\$1</constant>"],
  215. [$type_struct_xml, "<structname>\$1</structname>"],
  216. [$type_param, "<parameter>\$1</parameter>"],
  217. [$type_func, "<function>\$1</function>"],
  218. [$type_env, "<envar>\$1</envar>"]
  219. );
  220. my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
  221. # gnome, docbook format
  222. my @highlights_gnome = (
  223. [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
  224. [$type_func, "<function>\$1</function>"],
  225. [$type_struct, "<structname>\$1</structname>"],
  226. [$type_env, "<envar>\$1</envar>"],
  227. [$type_param, "<parameter>\$1</parameter>" ]
  228. );
  229. my $blankline_gnome = "</para><para>\n";
  230. # these are pretty rough
  231. my @highlights_man = (
  232. [$type_constant, "\$1"],
  233. [$type_func, "\\\\fB\$1\\\\fP"],
  234. [$type_struct, "\\\\fI\$1\\\\fP"],
  235. [$type_param, "\\\\fI\$1\\\\fP"]
  236. );
  237. my $blankline_man = "";
  238. # text-mode
  239. my @highlights_text = (
  240. [$type_constant, "\$1"],
  241. [$type_func, "\$1"],
  242. [$type_struct, "\$1"],
  243. [$type_param, "\$1"]
  244. );
  245. my $blankline_text = "";
  246. # rst-mode
  247. my @highlights_rst = (
  248. [$type_constant, "``\$1``"],
  249. [$type_func, "\\:c\\:func\\:`\$1`"],
  250. [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
  251. [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
  252. [$type_struct, "\\:c\\:type\\:`struct \$1 <\$1>`"],
  253. [$type_param, "**\$1**"]
  254. );
  255. my $blankline_rst = "\n";
  256. # list mode
  257. my @highlights_list = (
  258. [$type_constant, "\$1"],
  259. [$type_func, "\$1"],
  260. [$type_struct, "\$1"],
  261. [$type_param, "\$1"]
  262. );
  263. my $blankline_list = "";
  264. # read arguments
  265. if ($#ARGV == -1) {
  266. usage();
  267. }
  268. my $kernelversion;
  269. my $dohighlight = "";
  270. my $verbose = 0;
  271. my $output_mode = "man";
  272. my $output_preformatted = 0;
  273. my $no_doc_sections = 0;
  274. my @highlights = @highlights_man;
  275. my $blankline = $blankline_man;
  276. my $modulename = "Kernel API";
  277. my $function_only = 0;
  278. my $show_not_found = 0;
  279. my @build_time;
  280. if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
  281. (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
  282. @build_time = gmtime($seconds);
  283. } else {
  284. @build_time = localtime;
  285. }
  286. my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
  287. 'July', 'August', 'September', 'October',
  288. 'November', 'December')[$build_time[4]] .
  289. " " . ($build_time[5]+1900);
  290. # Essentially these are globals.
  291. # They probably want to be tidied up, made more localised or something.
  292. # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
  293. # could cause "use of undefined value" or other bugs.
  294. my ($function, %function_table, %parametertypes, $declaration_purpose);
  295. my ($type, $declaration_name, $return_type);
  296. my ($newsection, $newcontents, $prototype, $brcount, %source_map);
  297. if (defined($ENV{'KBUILD_VERBOSE'})) {
  298. $verbose = "$ENV{'KBUILD_VERBOSE'}";
  299. }
  300. # Generated docbook code is inserted in a template at a point where
  301. # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
  302. # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
  303. # We keep track of number of generated entries and generate a dummy
  304. # if needs be to ensure the expanded template can be postprocessed
  305. # into html.
  306. my $section_counter = 0;
  307. my $lineprefix="";
  308. # states
  309. # 0 - normal code
  310. # 1 - looking for function name
  311. # 2 - scanning field start.
  312. # 3 - scanning prototype.
  313. # 4 - documentation block
  314. # 5 - gathering documentation outside main block
  315. my $state;
  316. my $in_doc_sect;
  317. # Split Doc State
  318. # 0 - Invalid (Before start or after finish)
  319. # 1 - Is started (the /** was found inside a struct)
  320. # 2 - The @parameter header was found, start accepting multi paragraph text.
  321. # 3 - Finished (the */ was found)
  322. # 4 - Error - Comment without header was found. Spit a warning as it's not
  323. # proper kernel-doc and ignore the rest.
  324. my $split_doc_state;
  325. #declaration types: can be
  326. # 'function', 'struct', 'union', 'enum', 'typedef'
  327. my $decl_type;
  328. my $doc_special = "\@\%\$\&";
  329. my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
  330. my $doc_end = '\*/';
  331. my $doc_com = '\s*\*\s*';
  332. my $doc_com_body = '\s*\* ?';
  333. my $doc_decl = $doc_com . '(\w+)';
  334. my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
  335. my $doc_content = $doc_com_body . '(.*)';
  336. my $doc_block = $doc_com . 'DOC:\s*(.*)?';
  337. my $doc_split_start = '^\s*/\*\*\s*$';
  338. my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
  339. my $doc_split_end = '^\s*\*/\s*$';
  340. my %constants;
  341. my %parameterdescs;
  342. my @parameterlist;
  343. my %sections;
  344. my @sectionlist;
  345. my $sectcheck;
  346. my $struct_actual;
  347. my $contents = "";
  348. my $section_default = "Description"; # default section
  349. my $section_intro = "Introduction";
  350. my $section = $section_default;
  351. my $section_context = "Context";
  352. my $section_return = "Return";
  353. my $undescribed = "-- undescribed --";
  354. reset_state();
  355. while ($ARGV[0] =~ m/^-(.*)/) {
  356. my $cmd = shift @ARGV;
  357. if ($cmd eq "-html") {
  358. $output_mode = "html";
  359. @highlights = @highlights_html;
  360. $blankline = $blankline_html;
  361. } elsif ($cmd eq "-html5") {
  362. $output_mode = "html5";
  363. @highlights = @highlights_html5;
  364. $blankline = $blankline_html5;
  365. } elsif ($cmd eq "-man") {
  366. $output_mode = "man";
  367. @highlights = @highlights_man;
  368. $blankline = $blankline_man;
  369. } elsif ($cmd eq "-text") {
  370. $output_mode = "text";
  371. @highlights = @highlights_text;
  372. $blankline = $blankline_text;
  373. } elsif ($cmd eq "-rst") {
  374. $output_mode = "rst";
  375. @highlights = @highlights_rst;
  376. $blankline = $blankline_rst;
  377. } elsif ($cmd eq "-docbook") {
  378. $output_mode = "xml";
  379. @highlights = @highlights_xml;
  380. $blankline = $blankline_xml;
  381. } elsif ($cmd eq "-list") {
  382. $output_mode = "list";
  383. @highlights = @highlights_list;
  384. $blankline = $blankline_list;
  385. } elsif ($cmd eq "-gnome") {
  386. $output_mode = "gnome";
  387. @highlights = @highlights_gnome;
  388. $blankline = $blankline_gnome;
  389. } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
  390. $modulename = shift @ARGV;
  391. } elsif ($cmd eq "-function") { # to only output specific functions
  392. $function_only = 1;
  393. $function = shift @ARGV;
  394. $function_table{$function} = 1;
  395. } elsif ($cmd eq "-nofunction") { # to only output specific functions
  396. $function_only = 2;
  397. $function = shift @ARGV;
  398. $function_table{$function} = 1;
  399. } elsif ($cmd eq "-v") {
  400. $verbose = 1;
  401. } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
  402. usage();
  403. } elsif ($cmd eq '-no-doc-sections') {
  404. $no_doc_sections = 1;
  405. } elsif ($cmd eq '-show-not-found') {
  406. $show_not_found = 1;
  407. }
  408. }
  409. # continue execution near EOF;
  410. # get kernel version from env
  411. sub get_kernel_version() {
  412. my $version = 'unknown kernel version';
  413. if (defined($ENV{'KERNELVERSION'})) {
  414. $version = $ENV{'KERNELVERSION'};
  415. }
  416. return $version;
  417. }
  418. ##
  419. # dumps section contents to arrays/hashes intended for that purpose.
  420. #
  421. sub dump_section {
  422. my $file = shift;
  423. my $name = shift;
  424. my $contents = join "\n", @_;
  425. if ($name =~ m/$type_constant/) {
  426. $name = $1;
  427. # print STDERR "constant section '$1' = '$contents'\n";
  428. $constants{$name} = $contents;
  429. } elsif ($name =~ m/$type_param/) {
  430. # print STDERR "parameter def '$1' = '$contents'\n";
  431. $name = $1;
  432. $parameterdescs{$name} = $contents;
  433. $sectcheck = $sectcheck . $name . " ";
  434. } elsif ($name eq "@\.\.\.") {
  435. # print STDERR "parameter def '...' = '$contents'\n";
  436. $name = "...";
  437. $parameterdescs{$name} = $contents;
  438. $sectcheck = $sectcheck . $name . " ";
  439. } else {
  440. # print STDERR "other section '$name' = '$contents'\n";
  441. if (defined($sections{$name}) && ($sections{$name} ne "")) {
  442. print STDERR "${file}:$.: error: duplicate section name '$name'\n";
  443. ++$errors;
  444. }
  445. $sections{$name} = $contents;
  446. push @sectionlist, $name;
  447. }
  448. }
  449. ##
  450. # dump DOC: section after checking that it should go out
  451. #
  452. sub dump_doc_section {
  453. my $file = shift;
  454. my $name = shift;
  455. my $contents = join "\n", @_;
  456. if ($no_doc_sections) {
  457. return;
  458. }
  459. if (($function_only == 0) ||
  460. ( $function_only == 1 && defined($function_table{$name})) ||
  461. ( $function_only == 2 && !defined($function_table{$name})))
  462. {
  463. dump_section($file, $name, $contents);
  464. output_blockhead({'sectionlist' => \@sectionlist,
  465. 'sections' => \%sections,
  466. 'module' => $modulename,
  467. 'content-only' => ($function_only != 0), });
  468. }
  469. }
  470. ##
  471. # output function
  472. #
  473. # parameterdescs, a hash.
  474. # function => "function name"
  475. # parameterlist => @list of parameters
  476. # parameterdescs => %parameter descriptions
  477. # sectionlist => @list of sections
  478. # sections => %section descriptions
  479. #
  480. sub output_highlight {
  481. my $contents = join "\n",@_;
  482. my $line;
  483. # DEBUG
  484. # if (!defined $contents) {
  485. # use Carp;
  486. # confess "output_highlight got called with no args?\n";
  487. # }
  488. if ($output_mode eq "html" || $output_mode eq "html5" ||
  489. $output_mode eq "xml") {
  490. $contents = local_unescape($contents);
  491. # convert data read & converted thru xml_escape() into &xyz; format:
  492. $contents =~ s/\\\\\\/\&/g;
  493. }
  494. # print STDERR "contents b4:$contents\n";
  495. eval $dohighlight;
  496. die $@ if $@;
  497. # print STDERR "contents af:$contents\n";
  498. # strip whitespaces when generating html5
  499. if ($output_mode eq "html5") {
  500. $contents =~ s/^\s+//;
  501. $contents =~ s/\s+$//;
  502. }
  503. foreach $line (split "\n", $contents) {
  504. if (! $output_preformatted) {
  505. $line =~ s/^\s*//;
  506. }
  507. if ($line eq ""){
  508. if (! $output_preformatted) {
  509. print $lineprefix, local_unescape($blankline);
  510. }
  511. } else {
  512. $line =~ s/\\\\\\/\&/g;
  513. if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
  514. print "\\&$line";
  515. } else {
  516. print $lineprefix, $line;
  517. }
  518. }
  519. print "\n";
  520. }
  521. }
  522. # output sections in html
  523. sub output_section_html(%) {
  524. my %args = %{$_[0]};
  525. my $section;
  526. foreach $section (@{$args{'sectionlist'}}) {
  527. print "<h3>$section</h3>\n";
  528. print "<blockquote>\n";
  529. output_highlight($args{'sections'}{$section});
  530. print "</blockquote>\n";
  531. }
  532. }
  533. # output enum in html
  534. sub output_enum_html(%) {
  535. my %args = %{$_[0]};
  536. my ($parameter);
  537. my $count;
  538. print "<h2>enum " . $args{'enum'} . "</h2>\n";
  539. print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
  540. $count = 0;
  541. foreach $parameter (@{$args{'parameterlist'}}) {
  542. print " <b>" . $parameter . "</b>";
  543. if ($count != $#{$args{'parameterlist'}}) {
  544. $count++;
  545. print ",\n";
  546. }
  547. print "<br>";
  548. }
  549. print "};<br>\n";
  550. print "<h3>Constants</h3>\n";
  551. print "<dl>\n";
  552. foreach $parameter (@{$args{'parameterlist'}}) {
  553. print "<dt><b>" . $parameter . "</b>\n";
  554. print "<dd>";
  555. output_highlight($args{'parameterdescs'}{$parameter});
  556. }
  557. print "</dl>\n";
  558. output_section_html(@_);
  559. print "<hr>\n";
  560. }
  561. # output typedef in html
  562. sub output_typedef_html(%) {
  563. my %args = %{$_[0]};
  564. my ($parameter);
  565. my $count;
  566. print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
  567. print "<b>typedef " . $args{'typedef'} . "</b>\n";
  568. output_section_html(@_);
  569. print "<hr>\n";
  570. }
  571. # output struct in html
  572. sub output_struct_html(%) {
  573. my %args = %{$_[0]};
  574. my ($parameter);
  575. print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
  576. print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
  577. foreach $parameter (@{$args{'parameterlist'}}) {
  578. if ($parameter =~ /^#/) {
  579. print "$parameter<br>\n";
  580. next;
  581. }
  582. my $parameter_name = $parameter;
  583. $parameter_name =~ s/\[.*//;
  584. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  585. $type = $args{'parametertypes'}{$parameter};
  586. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  587. # pointer-to-function
  588. print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
  589. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  590. # bitfield
  591. print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
  592. } else {
  593. print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
  594. }
  595. }
  596. print "};<br>\n";
  597. print "<h3>Members</h3>\n";
  598. print "<dl>\n";
  599. foreach $parameter (@{$args{'parameterlist'}}) {
  600. ($parameter =~ /^#/) && next;
  601. my $parameter_name = $parameter;
  602. $parameter_name =~ s/\[.*//;
  603. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  604. print "<dt><b>" . $parameter . "</b>\n";
  605. print "<dd>";
  606. output_highlight($args{'parameterdescs'}{$parameter_name});
  607. }
  608. print "</dl>\n";
  609. output_section_html(@_);
  610. print "<hr>\n";
  611. }
  612. # output function in html
  613. sub output_function_html(%) {
  614. my %args = %{$_[0]};
  615. my ($parameter, $section);
  616. my $count;
  617. print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
  618. print "<i>" . $args{'functiontype'} . "</i>\n";
  619. print "<b>" . $args{'function'} . "</b>\n";
  620. print "(";
  621. $count = 0;
  622. foreach $parameter (@{$args{'parameterlist'}}) {
  623. $type = $args{'parametertypes'}{$parameter};
  624. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  625. # pointer-to-function
  626. print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
  627. } else {
  628. print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
  629. }
  630. if ($count != $#{$args{'parameterlist'}}) {
  631. $count++;
  632. print ",\n";
  633. }
  634. }
  635. print ")\n";
  636. print "<h3>Arguments</h3>\n";
  637. print "<dl>\n";
  638. foreach $parameter (@{$args{'parameterlist'}}) {
  639. my $parameter_name = $parameter;
  640. $parameter_name =~ s/\[.*//;
  641. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  642. print "<dt><b>" . $parameter . "</b>\n";
  643. print "<dd>";
  644. output_highlight($args{'parameterdescs'}{$parameter_name});
  645. }
  646. print "</dl>\n";
  647. output_section_html(@_);
  648. print "<hr>\n";
  649. }
  650. # output DOC: block header in html
  651. sub output_blockhead_html(%) {
  652. my %args = %{$_[0]};
  653. my ($parameter, $section);
  654. my $count;
  655. foreach $section (@{$args{'sectionlist'}}) {
  656. print "<h3>$section</h3>\n";
  657. print "<ul>\n";
  658. output_highlight($args{'sections'}{$section});
  659. print "</ul>\n";
  660. }
  661. print "<hr>\n";
  662. }
  663. # output sections in html5
  664. sub output_section_html5(%) {
  665. my %args = %{$_[0]};
  666. my $section;
  667. foreach $section (@{$args{'sectionlist'}}) {
  668. print "<section>\n";
  669. print "<h1>$section</h1>\n";
  670. print "<p>\n";
  671. output_highlight($args{'sections'}{$section});
  672. print "</p>\n";
  673. print "</section>\n";
  674. }
  675. }
  676. # output enum in html5
  677. sub output_enum_html5(%) {
  678. my %args = %{$_[0]};
  679. my ($parameter);
  680. my $count;
  681. my $html5id;
  682. $html5id = $args{'enum'};
  683. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  684. print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
  685. print "<h1>enum " . $args{'enum'} . "</h1>\n";
  686. print "<ol class=\"code\">\n";
  687. print "<li>";
  688. print "<span class=\"keyword\">enum</span> ";
  689. print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
  690. print "</li>\n";
  691. $count = 0;
  692. foreach $parameter (@{$args{'parameterlist'}}) {
  693. print "<li class=\"indent\">";
  694. print "<span class=\"param\">" . $parameter . "</span>";
  695. if ($count != $#{$args{'parameterlist'}}) {
  696. $count++;
  697. print ",";
  698. }
  699. print "</li>\n";
  700. }
  701. print "<li>};</li>\n";
  702. print "</ol>\n";
  703. print "<section>\n";
  704. print "<h1>Constants</h1>\n";
  705. print "<dl>\n";
  706. foreach $parameter (@{$args{'parameterlist'}}) {
  707. print "<dt>" . $parameter . "</dt>\n";
  708. print "<dd>";
  709. output_highlight($args{'parameterdescs'}{$parameter});
  710. print "</dd>\n";
  711. }
  712. print "</dl>\n";
  713. print "</section>\n";
  714. output_section_html5(@_);
  715. print "</article>\n";
  716. }
  717. # output typedef in html5
  718. sub output_typedef_html5(%) {
  719. my %args = %{$_[0]};
  720. my ($parameter);
  721. my $count;
  722. my $html5id;
  723. $html5id = $args{'typedef'};
  724. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  725. print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
  726. print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
  727. print "<ol class=\"code\">\n";
  728. print "<li>";
  729. print "<span class=\"keyword\">typedef</span> ";
  730. print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
  731. print "</li>\n";
  732. print "</ol>\n";
  733. output_section_html5(@_);
  734. print "</article>\n";
  735. }
  736. # output struct in html5
  737. sub output_struct_html5(%) {
  738. my %args = %{$_[0]};
  739. my ($parameter);
  740. my $html5id;
  741. $html5id = $args{'struct'};
  742. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  743. print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
  744. print "<hgroup>\n";
  745. print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
  746. print "<h2>". $args{'purpose'} . "</h2>\n";
  747. print "</hgroup>\n";
  748. print "<ol class=\"code\">\n";
  749. print "<li>";
  750. print "<span class=\"type\">" . $args{'type'} . "</span> ";
  751. print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
  752. print "</li>\n";
  753. foreach $parameter (@{$args{'parameterlist'}}) {
  754. print "<li class=\"indent\">";
  755. if ($parameter =~ /^#/) {
  756. print "<span class=\"param\">" . $parameter ."</span>\n";
  757. print "</li>\n";
  758. next;
  759. }
  760. my $parameter_name = $parameter;
  761. $parameter_name =~ s/\[.*//;
  762. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  763. $type = $args{'parametertypes'}{$parameter};
  764. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  765. # pointer-to-function
  766. print "<span class=\"type\">$1</span> ";
  767. print "<span class=\"param\">$parameter</span>";
  768. print "<span class=\"type\">)</span> ";
  769. print "(<span class=\"args\">$2</span>);";
  770. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  771. # bitfield
  772. print "<span class=\"type\">$1</span> ";
  773. print "<span class=\"param\">$parameter</span>";
  774. print "<span class=\"bits\">$2</span>;";
  775. } else {
  776. print "<span class=\"type\">$type</span> ";
  777. print "<span class=\"param\">$parameter</span>;";
  778. }
  779. print "</li>\n";
  780. }
  781. print "<li>};</li>\n";
  782. print "</ol>\n";
  783. print "<section>\n";
  784. print "<h1>Members</h1>\n";
  785. print "<dl>\n";
  786. foreach $parameter (@{$args{'parameterlist'}}) {
  787. ($parameter =~ /^#/) && next;
  788. my $parameter_name = $parameter;
  789. $parameter_name =~ s/\[.*//;
  790. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  791. print "<dt>" . $parameter . "</dt>\n";
  792. print "<dd>";
  793. output_highlight($args{'parameterdescs'}{$parameter_name});
  794. print "</dd>\n";
  795. }
  796. print "</dl>\n";
  797. print "</section>\n";
  798. output_section_html5(@_);
  799. print "</article>\n";
  800. }
  801. # output function in html5
  802. sub output_function_html5(%) {
  803. my %args = %{$_[0]};
  804. my ($parameter, $section);
  805. my $count;
  806. my $html5id;
  807. $html5id = $args{'function'};
  808. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  809. print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
  810. print "<hgroup>\n";
  811. print "<h1>" . $args{'function'} . "</h1>";
  812. print "<h2>" . $args{'purpose'} . "</h2>\n";
  813. print "</hgroup>\n";
  814. print "<ol class=\"code\">\n";
  815. print "<li>";
  816. print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
  817. print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
  818. print "</li>";
  819. $count = 0;
  820. foreach $parameter (@{$args{'parameterlist'}}) {
  821. print "<li class=\"indent\">";
  822. $type = $args{'parametertypes'}{$parameter};
  823. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  824. # pointer-to-function
  825. print "<span class=\"type\">$1</span> ";
  826. print "<span class=\"param\">$parameter</span>";
  827. print "<span class=\"type\">)</span> ";
  828. print "(<span class=\"args\">$2</span>)";
  829. } else {
  830. print "<span class=\"type\">$type</span> ";
  831. print "<span class=\"param\">$parameter</span>";
  832. }
  833. if ($count != $#{$args{'parameterlist'}}) {
  834. $count++;
  835. print ",";
  836. }
  837. print "</li>\n";
  838. }
  839. print "<li>)</li>\n";
  840. print "</ol>\n";
  841. print "<section>\n";
  842. print "<h1>Arguments</h1>\n";
  843. print "<p>\n";
  844. print "<dl>\n";
  845. foreach $parameter (@{$args{'parameterlist'}}) {
  846. my $parameter_name = $parameter;
  847. $parameter_name =~ s/\[.*//;
  848. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  849. print "<dt>" . $parameter . "</dt>\n";
  850. print "<dd>";
  851. output_highlight($args{'parameterdescs'}{$parameter_name});
  852. print "</dd>\n";
  853. }
  854. print "</dl>\n";
  855. print "</section>\n";
  856. output_section_html5(@_);
  857. print "</article>\n";
  858. }
  859. # output DOC: block header in html5
  860. sub output_blockhead_html5(%) {
  861. my %args = %{$_[0]};
  862. my ($parameter, $section);
  863. my $count;
  864. my $html5id;
  865. foreach $section (@{$args{'sectionlist'}}) {
  866. $html5id = $section;
  867. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  868. print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
  869. print "<h1>$section</h1>\n";
  870. print "<p>\n";
  871. output_highlight($args{'sections'}{$section});
  872. print "</p>\n";
  873. }
  874. print "</article>\n";
  875. }
  876. sub output_section_xml(%) {
  877. my %args = %{$_[0]};
  878. my $section;
  879. # print out each section
  880. $lineprefix=" ";
  881. foreach $section (@{$args{'sectionlist'}}) {
  882. print "<refsect1>\n";
  883. print "<title>$section</title>\n";
  884. if ($section =~ m/EXAMPLE/i) {
  885. print "<informalexample><programlisting>\n";
  886. $output_preformatted = 1;
  887. } else {
  888. print "<para>\n";
  889. }
  890. output_highlight($args{'sections'}{$section});
  891. $output_preformatted = 0;
  892. if ($section =~ m/EXAMPLE/i) {
  893. print "</programlisting></informalexample>\n";
  894. } else {
  895. print "</para>\n";
  896. }
  897. print "</refsect1>\n";
  898. }
  899. }
  900. # output function in XML DocBook
  901. sub output_function_xml(%) {
  902. my %args = %{$_[0]};
  903. my ($parameter, $section);
  904. my $count;
  905. my $id;
  906. $id = "API-" . $args{'function'};
  907. $id =~ s/[^A-Za-z0-9]/-/g;
  908. print "<refentry id=\"$id\">\n";
  909. print "<refentryinfo>\n";
  910. print " <title>LINUX</title>\n";
  911. print " <productname>Kernel Hackers Manual</productname>\n";
  912. print " <date>$man_date</date>\n";
  913. print "</refentryinfo>\n";
  914. print "<refmeta>\n";
  915. print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
  916. print " <manvolnum>9</manvolnum>\n";
  917. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  918. print "</refmeta>\n";
  919. print "<refnamediv>\n";
  920. print " <refname>" . $args{'function'} . "</refname>\n";
  921. print " <refpurpose>\n";
  922. print " ";
  923. output_highlight ($args{'purpose'});
  924. print " </refpurpose>\n";
  925. print "</refnamediv>\n";
  926. print "<refsynopsisdiv>\n";
  927. print " <title>Synopsis</title>\n";
  928. print " <funcsynopsis><funcprototype>\n";
  929. print " <funcdef>" . $args{'functiontype'} . " ";
  930. print "<function>" . $args{'function'} . " </function></funcdef>\n";
  931. $count = 0;
  932. if ($#{$args{'parameterlist'}} >= 0) {
  933. foreach $parameter (@{$args{'parameterlist'}}) {
  934. $type = $args{'parametertypes'}{$parameter};
  935. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  936. # pointer-to-function
  937. print " <paramdef>$1<parameter>$parameter</parameter>)\n";
  938. print " <funcparams>$2</funcparams></paramdef>\n";
  939. } else {
  940. print " <paramdef>" . $type;
  941. print " <parameter>$parameter</parameter></paramdef>\n";
  942. }
  943. }
  944. } else {
  945. print " <void/>\n";
  946. }
  947. print " </funcprototype></funcsynopsis>\n";
  948. print "</refsynopsisdiv>\n";
  949. # print parameters
  950. print "<refsect1>\n <title>Arguments</title>\n";
  951. if ($#{$args{'parameterlist'}} >= 0) {
  952. print " <variablelist>\n";
  953. foreach $parameter (@{$args{'parameterlist'}}) {
  954. my $parameter_name = $parameter;
  955. $parameter_name =~ s/\[.*//;
  956. print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
  957. print " <listitem>\n <para>\n";
  958. $lineprefix=" ";
  959. output_highlight($args{'parameterdescs'}{$parameter_name});
  960. print " </para>\n </listitem>\n </varlistentry>\n";
  961. }
  962. print " </variablelist>\n";
  963. } else {
  964. print " <para>\n None\n </para>\n";
  965. }
  966. print "</refsect1>\n";
  967. output_section_xml(@_);
  968. print "</refentry>\n\n";
  969. }
  970. # output struct in XML DocBook
  971. sub output_struct_xml(%) {
  972. my %args = %{$_[0]};
  973. my ($parameter, $section);
  974. my $id;
  975. $id = "API-struct-" . $args{'struct'};
  976. $id =~ s/[^A-Za-z0-9]/-/g;
  977. print "<refentry id=\"$id\">\n";
  978. print "<refentryinfo>\n";
  979. print " <title>LINUX</title>\n";
  980. print " <productname>Kernel Hackers Manual</productname>\n";
  981. print " <date>$man_date</date>\n";
  982. print "</refentryinfo>\n";
  983. print "<refmeta>\n";
  984. print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
  985. print " <manvolnum>9</manvolnum>\n";
  986. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  987. print "</refmeta>\n";
  988. print "<refnamediv>\n";
  989. print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
  990. print " <refpurpose>\n";
  991. print " ";
  992. output_highlight ($args{'purpose'});
  993. print " </refpurpose>\n";
  994. print "</refnamediv>\n";
  995. print "<refsynopsisdiv>\n";
  996. print " <title>Synopsis</title>\n";
  997. print " <programlisting>\n";
  998. print $args{'type'} . " " . $args{'struct'} . " {\n";
  999. foreach $parameter (@{$args{'parameterlist'}}) {
  1000. if ($parameter =~ /^#/) {
  1001. my $prm = $parameter;
  1002. # convert data read & converted thru xml_escape() into &xyz; format:
  1003. # This allows us to have #define macros interspersed in a struct.
  1004. $prm =~ s/\\\\\\/\&/g;
  1005. print "$prm\n";
  1006. next;
  1007. }
  1008. my $parameter_name = $parameter;
  1009. $parameter_name =~ s/\[.*//;
  1010. defined($args{'parameterdescs'}{$parameter_name}) || next;
  1011. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1012. $type = $args{'parametertypes'}{$parameter};
  1013. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1014. # pointer-to-function
  1015. print " $1 $parameter) ($2);\n";
  1016. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1017. # bitfield
  1018. print " $1 $parameter$2;\n";
  1019. } else {
  1020. print " " . $type . " " . $parameter . ";\n";
  1021. }
  1022. }
  1023. print "};";
  1024. print " </programlisting>\n";
  1025. print "</refsynopsisdiv>\n";
  1026. print " <refsect1>\n";
  1027. print " <title>Members</title>\n";
  1028. if ($#{$args{'parameterlist'}} >= 0) {
  1029. print " <variablelist>\n";
  1030. foreach $parameter (@{$args{'parameterlist'}}) {
  1031. ($parameter =~ /^#/) && next;
  1032. my $parameter_name = $parameter;
  1033. $parameter_name =~ s/\[.*//;
  1034. defined($args{'parameterdescs'}{$parameter_name}) || next;
  1035. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1036. print " <varlistentry>";
  1037. print " <term>$parameter</term>\n";
  1038. print " <listitem><para>\n";
  1039. output_highlight($args{'parameterdescs'}{$parameter_name});
  1040. print " </para></listitem>\n";
  1041. print " </varlistentry>\n";
  1042. }
  1043. print " </variablelist>\n";
  1044. } else {
  1045. print " <para>\n None\n </para>\n";
  1046. }
  1047. print " </refsect1>\n";
  1048. output_section_xml(@_);
  1049. print "</refentry>\n\n";
  1050. }
  1051. # output enum in XML DocBook
  1052. sub output_enum_xml(%) {
  1053. my %args = %{$_[0]};
  1054. my ($parameter, $section);
  1055. my $count;
  1056. my $id;
  1057. $id = "API-enum-" . $args{'enum'};
  1058. $id =~ s/[^A-Za-z0-9]/-/g;
  1059. print "<refentry id=\"$id\">\n";
  1060. print "<refentryinfo>\n";
  1061. print " <title>LINUX</title>\n";
  1062. print " <productname>Kernel Hackers Manual</productname>\n";
  1063. print " <date>$man_date</date>\n";
  1064. print "</refentryinfo>\n";
  1065. print "<refmeta>\n";
  1066. print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
  1067. print " <manvolnum>9</manvolnum>\n";
  1068. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  1069. print "</refmeta>\n";
  1070. print "<refnamediv>\n";
  1071. print " <refname>enum " . $args{'enum'} . "</refname>\n";
  1072. print " <refpurpose>\n";
  1073. print " ";
  1074. output_highlight ($args{'purpose'});
  1075. print " </refpurpose>\n";
  1076. print "</refnamediv>\n";
  1077. print "<refsynopsisdiv>\n";
  1078. print " <title>Synopsis</title>\n";
  1079. print " <programlisting>\n";
  1080. print "enum " . $args{'enum'} . " {\n";
  1081. $count = 0;
  1082. foreach $parameter (@{$args{'parameterlist'}}) {
  1083. print " $parameter";
  1084. if ($count != $#{$args{'parameterlist'}}) {
  1085. $count++;
  1086. print ",";
  1087. }
  1088. print "\n";
  1089. }
  1090. print "};";
  1091. print " </programlisting>\n";
  1092. print "</refsynopsisdiv>\n";
  1093. print "<refsect1>\n";
  1094. print " <title>Constants</title>\n";
  1095. print " <variablelist>\n";
  1096. foreach $parameter (@{$args{'parameterlist'}}) {
  1097. my $parameter_name = $parameter;
  1098. $parameter_name =~ s/\[.*//;
  1099. print " <varlistentry>";
  1100. print " <term>$parameter</term>\n";
  1101. print " <listitem><para>\n";
  1102. output_highlight($args{'parameterdescs'}{$parameter_name});
  1103. print " </para></listitem>\n";
  1104. print " </varlistentry>\n";
  1105. }
  1106. print " </variablelist>\n";
  1107. print "</refsect1>\n";
  1108. output_section_xml(@_);
  1109. print "</refentry>\n\n";
  1110. }
  1111. # output typedef in XML DocBook
  1112. sub output_typedef_xml(%) {
  1113. my %args = %{$_[0]};
  1114. my ($parameter, $section);
  1115. my $id;
  1116. $id = "API-typedef-" . $args{'typedef'};
  1117. $id =~ s/[^A-Za-z0-9]/-/g;
  1118. print "<refentry id=\"$id\">\n";
  1119. print "<refentryinfo>\n";
  1120. print " <title>LINUX</title>\n";
  1121. print " <productname>Kernel Hackers Manual</productname>\n";
  1122. print " <date>$man_date</date>\n";
  1123. print "</refentryinfo>\n";
  1124. print "<refmeta>\n";
  1125. print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
  1126. print " <manvolnum>9</manvolnum>\n";
  1127. print "</refmeta>\n";
  1128. print "<refnamediv>\n";
  1129. print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
  1130. print " <refpurpose>\n";
  1131. print " ";
  1132. output_highlight ($args{'purpose'});
  1133. print " </refpurpose>\n";
  1134. print "</refnamediv>\n";
  1135. print "<refsynopsisdiv>\n";
  1136. print " <title>Synopsis</title>\n";
  1137. print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
  1138. print "</refsynopsisdiv>\n";
  1139. output_section_xml(@_);
  1140. print "</refentry>\n\n";
  1141. }
  1142. # output in XML DocBook
  1143. sub output_blockhead_xml(%) {
  1144. my %args = %{$_[0]};
  1145. my ($parameter, $section);
  1146. my $count;
  1147. my $id = $args{'module'};
  1148. $id =~ s/[^A-Za-z0-9]/-/g;
  1149. # print out each section
  1150. $lineprefix=" ";
  1151. foreach $section (@{$args{'sectionlist'}}) {
  1152. if (!$args{'content-only'}) {
  1153. print "<refsect1>\n <title>$section</title>\n";
  1154. }
  1155. if ($section =~ m/EXAMPLE/i) {
  1156. print "<example><para>\n";
  1157. $output_preformatted = 1;
  1158. } else {
  1159. print "<para>\n";
  1160. }
  1161. output_highlight($args{'sections'}{$section});
  1162. $output_preformatted = 0;
  1163. if ($section =~ m/EXAMPLE/i) {
  1164. print "</para></example>\n";
  1165. } else {
  1166. print "</para>";
  1167. }
  1168. if (!$args{'content-only'}) {
  1169. print "\n</refsect1>\n";
  1170. }
  1171. }
  1172. print "\n\n";
  1173. }
  1174. # output in XML DocBook
  1175. sub output_function_gnome {
  1176. my %args = %{$_[0]};
  1177. my ($parameter, $section);
  1178. my $count;
  1179. my $id;
  1180. $id = $args{'module'} . "-" . $args{'function'};
  1181. $id =~ s/[^A-Za-z0-9]/-/g;
  1182. print "<sect2>\n";
  1183. print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
  1184. print " <funcsynopsis>\n";
  1185. print " <funcdef>" . $args{'functiontype'} . " ";
  1186. print "<function>" . $args{'function'} . " ";
  1187. print "</function></funcdef>\n";
  1188. $count = 0;
  1189. if ($#{$args{'parameterlist'}} >= 0) {
  1190. foreach $parameter (@{$args{'parameterlist'}}) {
  1191. $type = $args{'parametertypes'}{$parameter};
  1192. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1193. # pointer-to-function
  1194. print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
  1195. print " <funcparams>$2</funcparams></paramdef>\n";
  1196. } else {
  1197. print " <paramdef>" . $type;
  1198. print " <parameter>$parameter</parameter></paramdef>\n";
  1199. }
  1200. }
  1201. } else {
  1202. print " <void>\n";
  1203. }
  1204. print " </funcsynopsis>\n";
  1205. if ($#{$args{'parameterlist'}} >= 0) {
  1206. print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
  1207. print "<tgroup cols=\"2\">\n";
  1208. print "<colspec colwidth=\"2*\">\n";
  1209. print "<colspec colwidth=\"8*\">\n";
  1210. print "<tbody>\n";
  1211. foreach $parameter (@{$args{'parameterlist'}}) {
  1212. my $parameter_name = $parameter;
  1213. $parameter_name =~ s/\[.*//;
  1214. print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
  1215. print " <entry>\n";
  1216. $lineprefix=" ";
  1217. output_highlight($args{'parameterdescs'}{$parameter_name});
  1218. print " </entry></row>\n";
  1219. }
  1220. print " </tbody></tgroup></informaltable>\n";
  1221. } else {
  1222. print " <para>\n None\n </para>\n";
  1223. }
  1224. # print out each section
  1225. $lineprefix=" ";
  1226. foreach $section (@{$args{'sectionlist'}}) {
  1227. print "<simplesect>\n <title>$section</title>\n";
  1228. if ($section =~ m/EXAMPLE/i) {
  1229. print "<example><programlisting>\n";
  1230. $output_preformatted = 1;
  1231. } else {
  1232. }
  1233. print "<para>\n";
  1234. output_highlight($args{'sections'}{$section});
  1235. $output_preformatted = 0;
  1236. print "</para>\n";
  1237. if ($section =~ m/EXAMPLE/i) {
  1238. print "</programlisting></example>\n";
  1239. } else {
  1240. }
  1241. print " </simplesect>\n";
  1242. }
  1243. print "</sect2>\n\n";
  1244. }
  1245. ##
  1246. # output function in man
  1247. sub output_function_man(%) {
  1248. my %args = %{$_[0]};
  1249. my ($parameter, $section);
  1250. my $count;
  1251. print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
  1252. print ".SH NAME\n";
  1253. print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
  1254. print ".SH SYNOPSIS\n";
  1255. if ($args{'functiontype'} ne "") {
  1256. print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
  1257. } else {
  1258. print ".B \"" . $args{'function'} . "\n";
  1259. }
  1260. $count = 0;
  1261. my $parenth = "(";
  1262. my $post = ",";
  1263. foreach my $parameter (@{$args{'parameterlist'}}) {
  1264. if ($count == $#{$args{'parameterlist'}}) {
  1265. $post = ");";
  1266. }
  1267. $type = $args{'parametertypes'}{$parameter};
  1268. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1269. # pointer-to-function
  1270. print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
  1271. } else {
  1272. $type =~ s/([^\*])$/$1 /;
  1273. print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
  1274. }
  1275. $count++;
  1276. $parenth = "";
  1277. }
  1278. print ".SH ARGUMENTS\n";
  1279. foreach $parameter (@{$args{'parameterlist'}}) {
  1280. my $parameter_name = $parameter;
  1281. $parameter_name =~ s/\[.*//;
  1282. print ".IP \"" . $parameter . "\" 12\n";
  1283. output_highlight($args{'parameterdescs'}{$parameter_name});
  1284. }
  1285. foreach $section (@{$args{'sectionlist'}}) {
  1286. print ".SH \"", uc $section, "\"\n";
  1287. output_highlight($args{'sections'}{$section});
  1288. }
  1289. }
  1290. ##
  1291. # output enum in man
  1292. sub output_enum_man(%) {
  1293. my %args = %{$_[0]};
  1294. my ($parameter, $section);
  1295. my $count;
  1296. print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1297. print ".SH NAME\n";
  1298. print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
  1299. print ".SH SYNOPSIS\n";
  1300. print "enum " . $args{'enum'} . " {\n";
  1301. $count = 0;
  1302. foreach my $parameter (@{$args{'parameterlist'}}) {
  1303. print ".br\n.BI \" $parameter\"\n";
  1304. if ($count == $#{$args{'parameterlist'}}) {
  1305. print "\n};\n";
  1306. last;
  1307. }
  1308. else {
  1309. print ", \n.br\n";
  1310. }
  1311. $count++;
  1312. }
  1313. print ".SH Constants\n";
  1314. foreach $parameter (@{$args{'parameterlist'}}) {
  1315. my $parameter_name = $parameter;
  1316. $parameter_name =~ s/\[.*//;
  1317. print ".IP \"" . $parameter . "\" 12\n";
  1318. output_highlight($args{'parameterdescs'}{$parameter_name});
  1319. }
  1320. foreach $section (@{$args{'sectionlist'}}) {
  1321. print ".SH \"$section\"\n";
  1322. output_highlight($args{'sections'}{$section});
  1323. }
  1324. }
  1325. ##
  1326. # output struct in man
  1327. sub output_struct_man(%) {
  1328. my %args = %{$_[0]};
  1329. my ($parameter, $section);
  1330. print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
  1331. print ".SH NAME\n";
  1332. print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
  1333. print ".SH SYNOPSIS\n";
  1334. print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
  1335. foreach my $parameter (@{$args{'parameterlist'}}) {
  1336. if ($parameter =~ /^#/) {
  1337. print ".BI \"$parameter\"\n.br\n";
  1338. next;
  1339. }
  1340. my $parameter_name = $parameter;
  1341. $parameter_name =~ s/\[.*//;
  1342. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1343. $type = $args{'parametertypes'}{$parameter};
  1344. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1345. # pointer-to-function
  1346. print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
  1347. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1348. # bitfield
  1349. print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
  1350. } else {
  1351. $type =~ s/([^\*])$/$1 /;
  1352. print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
  1353. }
  1354. print "\n.br\n";
  1355. }
  1356. print "};\n.br\n";
  1357. print ".SH Members\n";
  1358. foreach $parameter (@{$args{'parameterlist'}}) {
  1359. ($parameter =~ /^#/) && next;
  1360. my $parameter_name = $parameter;
  1361. $parameter_name =~ s/\[.*//;
  1362. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1363. print ".IP \"" . $parameter . "\" 12\n";
  1364. output_highlight($args{'parameterdescs'}{$parameter_name});
  1365. }
  1366. foreach $section (@{$args{'sectionlist'}}) {
  1367. print ".SH \"$section\"\n";
  1368. output_highlight($args{'sections'}{$section});
  1369. }
  1370. }
  1371. ##
  1372. # output typedef in man
  1373. sub output_typedef_man(%) {
  1374. my %args = %{$_[0]};
  1375. my ($parameter, $section);
  1376. print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1377. print ".SH NAME\n";
  1378. print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
  1379. foreach $section (@{$args{'sectionlist'}}) {
  1380. print ".SH \"$section\"\n";
  1381. output_highlight($args{'sections'}{$section});
  1382. }
  1383. }
  1384. sub output_blockhead_man(%) {
  1385. my %args = %{$_[0]};
  1386. my ($parameter, $section);
  1387. my $count;
  1388. print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1389. foreach $section (@{$args{'sectionlist'}}) {
  1390. print ".SH \"$section\"\n";
  1391. output_highlight($args{'sections'}{$section});
  1392. }
  1393. }
  1394. ##
  1395. # output in text
  1396. sub output_function_text(%) {
  1397. my %args = %{$_[0]};
  1398. my ($parameter, $section);
  1399. my $start;
  1400. print "Name:\n\n";
  1401. print $args{'function'} . " - " . $args{'purpose'} . "\n";
  1402. print "\nSynopsis:\n\n";
  1403. if ($args{'functiontype'} ne "") {
  1404. $start = $args{'functiontype'} . " " . $args{'function'} . " (";
  1405. } else {
  1406. $start = $args{'function'} . " (";
  1407. }
  1408. print $start;
  1409. my $count = 0;
  1410. foreach my $parameter (@{$args{'parameterlist'}}) {
  1411. $type = $args{'parametertypes'}{$parameter};
  1412. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1413. # pointer-to-function
  1414. print $1 . $parameter . ") (" . $2;
  1415. } else {
  1416. print $type . " " . $parameter;
  1417. }
  1418. if ($count != $#{$args{'parameterlist'}}) {
  1419. $count++;
  1420. print ",\n";
  1421. print " " x length($start);
  1422. } else {
  1423. print ");\n\n";
  1424. }
  1425. }
  1426. print "Arguments:\n\n";
  1427. foreach $parameter (@{$args{'parameterlist'}}) {
  1428. my $parameter_name = $parameter;
  1429. $parameter_name =~ s/\[.*//;
  1430. print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
  1431. }
  1432. output_section_text(@_);
  1433. }
  1434. #output sections in text
  1435. sub output_section_text(%) {
  1436. my %args = %{$_[0]};
  1437. my $section;
  1438. print "\n";
  1439. foreach $section (@{$args{'sectionlist'}}) {
  1440. print "$section:\n\n";
  1441. output_highlight($args{'sections'}{$section});
  1442. }
  1443. print "\n\n";
  1444. }
  1445. # output enum in text
  1446. sub output_enum_text(%) {
  1447. my %args = %{$_[0]};
  1448. my ($parameter);
  1449. my $count;
  1450. print "Enum:\n\n";
  1451. print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
  1452. print "enum " . $args{'enum'} . " {\n";
  1453. $count = 0;
  1454. foreach $parameter (@{$args{'parameterlist'}}) {
  1455. print "\t$parameter";
  1456. if ($count != $#{$args{'parameterlist'}}) {
  1457. $count++;
  1458. print ",";
  1459. }
  1460. print "\n";
  1461. }
  1462. print "};\n\n";
  1463. print "Constants:\n\n";
  1464. foreach $parameter (@{$args{'parameterlist'}}) {
  1465. print "$parameter\n\t";
  1466. print $args{'parameterdescs'}{$parameter} . "\n";
  1467. }
  1468. output_section_text(@_);
  1469. }
  1470. # output typedef in text
  1471. sub output_typedef_text(%) {
  1472. my %args = %{$_[0]};
  1473. my ($parameter);
  1474. my $count;
  1475. print "Typedef:\n\n";
  1476. print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
  1477. output_section_text(@_);
  1478. }
  1479. # output struct as text
  1480. sub output_struct_text(%) {
  1481. my %args = %{$_[0]};
  1482. my ($parameter);
  1483. print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
  1484. print $args{'type'} . " " . $args{'struct'} . " {\n";
  1485. foreach $parameter (@{$args{'parameterlist'}}) {
  1486. if ($parameter =~ /^#/) {
  1487. print "$parameter\n";
  1488. next;
  1489. }
  1490. my $parameter_name = $parameter;
  1491. $parameter_name =~ s/\[.*//;
  1492. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1493. $type = $args{'parametertypes'}{$parameter};
  1494. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1495. # pointer-to-function
  1496. print "\t$1 $parameter) ($2);\n";
  1497. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1498. # bitfield
  1499. print "\t$1 $parameter$2;\n";
  1500. } else {
  1501. print "\t" . $type . " " . $parameter . ";\n";
  1502. }
  1503. }
  1504. print "};\n\n";
  1505. print "Members:\n\n";
  1506. foreach $parameter (@{$args{'parameterlist'}}) {
  1507. ($parameter =~ /^#/) && next;
  1508. my $parameter_name = $parameter;
  1509. $parameter_name =~ s/\[.*//;
  1510. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1511. print "$parameter\n\t";
  1512. print $args{'parameterdescs'}{$parameter_name} . "\n";
  1513. }
  1514. print "\n";
  1515. output_section_text(@_);
  1516. }
  1517. sub output_blockhead_text(%) {
  1518. my %args = %{$_[0]};
  1519. my ($parameter, $section);
  1520. foreach $section (@{$args{'sectionlist'}}) {
  1521. print " $section:\n";
  1522. print " -> ";
  1523. output_highlight($args{'sections'}{$section});
  1524. }
  1525. }
  1526. ##
  1527. # output in restructured text
  1528. #
  1529. #
  1530. # This could use some work; it's used to output the DOC: sections, and
  1531. # starts by putting out the name of the doc section itself, but that tends
  1532. # to duplicate a header already in the template file.
  1533. #
  1534. sub output_blockhead_rst(%) {
  1535. my %args = %{$_[0]};
  1536. my ($parameter, $section);
  1537. foreach $section (@{$args{'sectionlist'}}) {
  1538. print "**$section**\n\n";
  1539. output_highlight_rst($args{'sections'}{$section});
  1540. print "\n";
  1541. }
  1542. }
  1543. sub output_highlight_rst {
  1544. my $contents = join "\n",@_;
  1545. my $line;
  1546. # undo the evil effects of xml_escape() earlier
  1547. $contents = xml_unescape($contents);
  1548. eval $dohighlight;
  1549. die $@ if $@;
  1550. foreach $line (split "\n", $contents) {
  1551. if ($line eq "") {
  1552. print $lineprefix, $blankline;
  1553. } else {
  1554. $line =~ s/\\\\\\/\&/g;
  1555. print $lineprefix, $line;
  1556. }
  1557. print "\n";
  1558. }
  1559. }
  1560. sub output_function_rst(%) {
  1561. my %args = %{$_[0]};
  1562. my ($parameter, $section);
  1563. my $start;
  1564. print ".. c:function:: ";
  1565. if ($args{'functiontype'} ne "") {
  1566. $start = $args{'functiontype'} . " " . $args{'function'} . " (";
  1567. } else {
  1568. $start = $args{'function'} . " (";
  1569. }
  1570. print $start;
  1571. my $count = 0;
  1572. foreach my $parameter (@{$args{'parameterlist'}}) {
  1573. if ($count ne 0) {
  1574. print ", ";
  1575. }
  1576. $count++;
  1577. $type = $args{'parametertypes'}{$parameter};
  1578. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1579. # pointer-to-function
  1580. print $1 . $parameter . ") (" . $2;
  1581. } else {
  1582. print $type . " " . $parameter;
  1583. }
  1584. }
  1585. print ")\n\n " . $args{'purpose'} . "\n\n";
  1586. print ":Parameters:\n\n";
  1587. foreach $parameter (@{$args{'parameterlist'}}) {
  1588. my $parameter_name = $parameter;
  1589. #$parameter_name =~ s/\[.*//;
  1590. $type = $args{'parametertypes'}{$parameter};
  1591. if ($type ne "") {
  1592. print " ``$type $parameter``\n";
  1593. } else {
  1594. print " ``$parameter``\n";
  1595. }
  1596. if (defined($args{'parameterdescs'}{$parameter_name}) &&
  1597. $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
  1598. my $oldprefix = $lineprefix;
  1599. $lineprefix = " ";
  1600. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  1601. $lineprefix = $oldprefix;
  1602. } else {
  1603. print "\n _undescribed_\n";
  1604. }
  1605. print "\n";
  1606. }
  1607. output_section_rst(@_);
  1608. }
  1609. sub output_section_rst(%) {
  1610. my %args = %{$_[0]};
  1611. my $section;
  1612. my $oldprefix = $lineprefix;
  1613. $lineprefix = " ";
  1614. foreach $section (@{$args{'sectionlist'}}) {
  1615. print ":$section:\n\n";
  1616. output_highlight_rst($args{'sections'}{$section});
  1617. print "\n";
  1618. }
  1619. print "\n";
  1620. $lineprefix = $oldprefix;
  1621. }
  1622. sub output_enum_rst(%) {
  1623. my %args = %{$_[0]};
  1624. my ($parameter);
  1625. my $count;
  1626. my $name = "enum " . $args{'enum'};
  1627. print "\n\n.. c:type:: " . $name . "\n\n";
  1628. print " " . $args{'purpose'} . "\n\n";
  1629. print "..\n\n:Constants:\n\n";
  1630. my $oldprefix = $lineprefix;
  1631. $lineprefix = " ";
  1632. foreach $parameter (@{$args{'parameterlist'}}) {
  1633. print " `$parameter`\n";
  1634. if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
  1635. output_highlight_rst($args{'parameterdescs'}{$parameter});
  1636. } else {
  1637. print " undescribed\n";
  1638. }
  1639. print "\n";
  1640. }
  1641. $lineprefix = $oldprefix;
  1642. output_section_rst(@_);
  1643. }
  1644. sub output_typedef_rst(%) {
  1645. my %args = %{$_[0]};
  1646. my ($parameter);
  1647. my $count;
  1648. my $name = "typedef " . $args{'typedef'};
  1649. ### FIXME: should the name below contain "typedef" or not?
  1650. print "\n\n.. c:type:: " . $name . "\n\n";
  1651. print " " . $args{'purpose'} . "\n\n";
  1652. output_section_rst(@_);
  1653. }
  1654. sub output_struct_rst(%) {
  1655. my %args = %{$_[0]};
  1656. my ($parameter);
  1657. my $name = $args{'type'} . " " . $args{'struct'};
  1658. print "\n\n.. c:type:: " . $name . "\n\n";
  1659. print " " . $args{'purpose'} . "\n\n";
  1660. print ":Definition:\n\n";
  1661. print " ::\n\n";
  1662. print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
  1663. foreach $parameter (@{$args{'parameterlist'}}) {
  1664. if ($parameter =~ /^#/) {
  1665. print " " . "$parameter\n";
  1666. next;
  1667. }
  1668. my $parameter_name = $parameter;
  1669. $parameter_name =~ s/\[.*//;
  1670. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1671. $type = $args{'parametertypes'}{$parameter};
  1672. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1673. # pointer-to-function
  1674. print " $1 $parameter) ($2);\n";
  1675. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1676. # bitfield
  1677. print " $1 $parameter$2;\n";
  1678. } else {
  1679. print " " . $type . " " . $parameter . ";\n";
  1680. }
  1681. }
  1682. print " };\n\n";
  1683. print ":Members:\n\n";
  1684. foreach $parameter (@{$args{'parameterlist'}}) {
  1685. ($parameter =~ /^#/) && next;
  1686. my $parameter_name = $parameter;
  1687. $parameter_name =~ s/\[.*//;
  1688. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1689. $type = $args{'parametertypes'}{$parameter};
  1690. print " `$type $parameter`" . "\n";
  1691. my $oldprefix = $lineprefix;
  1692. $lineprefix = " ";
  1693. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  1694. $lineprefix = $oldprefix;
  1695. print "\n";
  1696. }
  1697. print "\n";
  1698. output_section_rst(@_);
  1699. }
  1700. ## list mode output functions
  1701. sub output_function_list(%) {
  1702. my %args = %{$_[0]};
  1703. print $args{'function'} . "\n";
  1704. }
  1705. # output enum in list
  1706. sub output_enum_list(%) {
  1707. my %args = %{$_[0]};
  1708. print $args{'enum'} . "\n";
  1709. }
  1710. # output typedef in list
  1711. sub output_typedef_list(%) {
  1712. my %args = %{$_[0]};
  1713. print $args{'typedef'} . "\n";
  1714. }
  1715. # output struct as list
  1716. sub output_struct_list(%) {
  1717. my %args = %{$_[0]};
  1718. print $args{'struct'} . "\n";
  1719. }
  1720. sub output_blockhead_list(%) {
  1721. my %args = %{$_[0]};
  1722. my ($parameter, $section);
  1723. foreach $section (@{$args{'sectionlist'}}) {
  1724. print "DOC: $section\n";
  1725. }
  1726. }
  1727. ##
  1728. # generic output function for all types (function, struct/union, typedef, enum);
  1729. # calls the generated, variable output_ function name based on
  1730. # functype and output_mode
  1731. sub output_declaration {
  1732. no strict 'refs';
  1733. my $name = shift;
  1734. my $functype = shift;
  1735. my $func = "output_${functype}_$output_mode";
  1736. if (($function_only==0) ||
  1737. ( $function_only == 1 && defined($function_table{$name})) ||
  1738. ( $function_only == 2 && !($functype eq "function" && defined($function_table{$name}))))
  1739. {
  1740. &$func(@_);
  1741. $section_counter++;
  1742. }
  1743. }
  1744. ##
  1745. # generic output function - calls the right one based on current output mode.
  1746. sub output_blockhead {
  1747. no strict 'refs';
  1748. my $func = "output_blockhead_" . $output_mode;
  1749. &$func(@_);
  1750. $section_counter++;
  1751. }
  1752. ##
  1753. # takes a declaration (struct, union, enum, typedef) and
  1754. # invokes the right handler. NOT called for functions.
  1755. sub dump_declaration($$) {
  1756. no strict 'refs';
  1757. my ($prototype, $file) = @_;
  1758. my $func = "dump_" . $decl_type;
  1759. &$func(@_);
  1760. }
  1761. sub dump_union($$) {
  1762. dump_struct(@_);
  1763. }
  1764. sub dump_struct($$) {
  1765. my $x = shift;
  1766. my $file = shift;
  1767. my $nested;
  1768. if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
  1769. #my $decl_type = $1;
  1770. $declaration_name = $2;
  1771. my $members = $3;
  1772. # ignore embedded structs or unions
  1773. $members =~ s/({.*})//g;
  1774. $nested = $1;
  1775. # ignore members marked private:
  1776. $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
  1777. $members =~ s/\/\*\s*private:.*//gosi;
  1778. # strip comments:
  1779. $members =~ s/\/\*.*?\*\///gos;
  1780. $nested =~ s/\/\*.*?\*\///gos;
  1781. # strip kmemcheck_bitfield_{begin,end}.*;
  1782. $members =~ s/kmemcheck_bitfield_.*?;//gos;
  1783. # strip attributes
  1784. $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  1785. $members =~ s/__aligned\s*\([^;]*\)//gos;
  1786. $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
  1787. # replace DECLARE_BITMAP
  1788. $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
  1789. create_parameterlist($members, ';', $file);
  1790. check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
  1791. output_declaration($declaration_name,
  1792. 'struct',
  1793. {'struct' => $declaration_name,
  1794. 'module' => $modulename,
  1795. 'parameterlist' => \@parameterlist,
  1796. 'parameterdescs' => \%parameterdescs,
  1797. 'parametertypes' => \%parametertypes,
  1798. 'sectionlist' => \@sectionlist,
  1799. 'sections' => \%sections,
  1800. 'purpose' => $declaration_purpose,
  1801. 'type' => $decl_type
  1802. });
  1803. }
  1804. else {
  1805. print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
  1806. ++$errors;
  1807. }
  1808. }
  1809. sub dump_enum($$) {
  1810. my $x = shift;
  1811. my $file = shift;
  1812. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1813. # strip #define macros inside enums
  1814. $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
  1815. if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
  1816. $declaration_name = $1;
  1817. my $members = $2;
  1818. foreach my $arg (split ',', $members) {
  1819. $arg =~ s/^\s*(\w+).*/$1/;
  1820. push @parameterlist, $arg;
  1821. if (!$parameterdescs{$arg}) {
  1822. $parameterdescs{$arg} = $undescribed;
  1823. print STDERR "${file}:$.: warning: Enum value '$arg' ".
  1824. "not described in enum '$declaration_name'\n";
  1825. }
  1826. }
  1827. output_declaration($declaration_name,
  1828. 'enum',
  1829. {'enum' => $declaration_name,
  1830. 'module' => $modulename,
  1831. 'parameterlist' => \@parameterlist,
  1832. 'parameterdescs' => \%parameterdescs,
  1833. 'sectionlist' => \@sectionlist,
  1834. 'sections' => \%sections,
  1835. 'purpose' => $declaration_purpose
  1836. });
  1837. }
  1838. else {
  1839. print STDERR "${file}:$.: error: Cannot parse enum!\n";
  1840. ++$errors;
  1841. }
  1842. }
  1843. sub dump_typedef($$) {
  1844. my $x = shift;
  1845. my $file = shift;
  1846. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1847. # Parse function prototypes
  1848. if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
  1849. # Function typedefs
  1850. $return_type = $1;
  1851. $declaration_name = $2;
  1852. my $args = $3;
  1853. create_parameterlist($args, ',', $file);
  1854. output_declaration($declaration_name,
  1855. 'function',
  1856. {'function' => $declaration_name,
  1857. 'module' => $modulename,
  1858. 'functiontype' => $return_type,
  1859. 'parameterlist' => \@parameterlist,
  1860. 'parameterdescs' => \%parameterdescs,
  1861. 'parametertypes' => \%parametertypes,
  1862. 'sectionlist' => \@sectionlist,
  1863. 'sections' => \%sections,
  1864. 'purpose' => $declaration_purpose
  1865. });
  1866. return;
  1867. }
  1868. while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
  1869. $x =~ s/\(*.\)\s*;$/;/;
  1870. $x =~ s/\[*.\]\s*;$/;/;
  1871. }
  1872. if ($x =~ /typedef.*\s+(\w+)\s*;/) {
  1873. $declaration_name = $1;
  1874. output_declaration($declaration_name,
  1875. 'typedef',
  1876. {'typedef' => $declaration_name,
  1877. 'module' => $modulename,
  1878. 'sectionlist' => \@sectionlist,
  1879. 'sections' => \%sections,
  1880. 'purpose' => $declaration_purpose
  1881. });
  1882. }
  1883. else {
  1884. print STDERR "${file}:$.: error: Cannot parse typedef!\n";
  1885. ++$errors;
  1886. }
  1887. }
  1888. sub save_struct_actual($) {
  1889. my $actual = shift;
  1890. # strip all spaces from the actual param so that it looks like one string item
  1891. $actual =~ s/\s*//g;
  1892. $struct_actual = $struct_actual . $actual . " ";
  1893. }
  1894. sub create_parameterlist($$$) {
  1895. my $args = shift;
  1896. my $splitter = shift;
  1897. my $file = shift;
  1898. my $type;
  1899. my $param;
  1900. # temporarily replace commas inside function pointer definition
  1901. while ($args =~ /(\([^\),]+),/) {
  1902. $args =~ s/(\([^\),]+),/$1#/g;
  1903. }
  1904. foreach my $arg (split($splitter, $args)) {
  1905. # strip comments
  1906. $arg =~ s/\/\*.*\*\///;
  1907. # strip leading/trailing spaces
  1908. $arg =~ s/^\s*//;
  1909. $arg =~ s/\s*$//;
  1910. $arg =~ s/\s+/ /;
  1911. if ($arg =~ /^#/) {
  1912. # Treat preprocessor directive as a typeless variable just to fill
  1913. # corresponding data structures "correctly". Catch it later in
  1914. # output_* subs.
  1915. push_parameter($arg, "", $file);
  1916. } elsif ($arg =~ m/\(.+\)\s*\(/) {
  1917. # pointer-to-function
  1918. $arg =~ tr/#/,/;
  1919. $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
  1920. $param = $1;
  1921. $type = $arg;
  1922. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1923. save_struct_actual($param);
  1924. push_parameter($param, $type, $file);
  1925. } elsif ($arg) {
  1926. $arg =~ s/\s*:\s*/:/g;
  1927. $arg =~ s/\s*\[/\[/g;
  1928. my @args = split('\s*,\s*', $arg);
  1929. if ($args[0] =~ m/\*/) {
  1930. $args[0] =~ s/(\*+)\s*/ $1/;
  1931. }
  1932. my @first_arg;
  1933. if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
  1934. shift @args;
  1935. push(@first_arg, split('\s+', $1));
  1936. push(@first_arg, $2);
  1937. } else {
  1938. @first_arg = split('\s+', shift @args);
  1939. }
  1940. unshift(@args, pop @first_arg);
  1941. $type = join " ", @first_arg;
  1942. foreach $param (@args) {
  1943. if ($param =~ m/^(\*+)\s*(.*)/) {
  1944. save_struct_actual($2);
  1945. push_parameter($2, "$type $1", $file);
  1946. }
  1947. elsif ($param =~ m/(.*?):(\d+)/) {
  1948. if ($type ne "") { # skip unnamed bit-fields
  1949. save_struct_actual($1);
  1950. push_parameter($1, "$type:$2", $file)
  1951. }
  1952. }
  1953. else {
  1954. save_struct_actual($param);
  1955. push_parameter($param, $type, $file);
  1956. }
  1957. }
  1958. }
  1959. }
  1960. }
  1961. sub push_parameter($$$) {
  1962. my $param = shift;
  1963. my $type = shift;
  1964. my $file = shift;
  1965. if (($anon_struct_union == 1) && ($type eq "") &&
  1966. ($param eq "}")) {
  1967. return; # ignore the ending }; from anon. struct/union
  1968. }
  1969. $anon_struct_union = 0;
  1970. my $param_name = $param;
  1971. $param_name =~ s/\[.*//;
  1972. if ($type eq "" && $param =~ /\.\.\.$/)
  1973. {
  1974. if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
  1975. $parameterdescs{$param} = "variable arguments";
  1976. }
  1977. }
  1978. elsif ($type eq "" && ($param eq "" or $param eq "void"))
  1979. {
  1980. $param="void";
  1981. $parameterdescs{void} = "no arguments";
  1982. }
  1983. elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
  1984. # handle unnamed (anonymous) union or struct:
  1985. {
  1986. $type = $param;
  1987. $param = "{unnamed_" . $param . "}";
  1988. $parameterdescs{$param} = "anonymous\n";
  1989. $anon_struct_union = 1;
  1990. }
  1991. # warn if parameter has no description
  1992. # (but ignore ones starting with # as these are not parameters
  1993. # but inline preprocessor statements);
  1994. # also ignore unnamed structs/unions;
  1995. if (!$anon_struct_union) {
  1996. if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
  1997. $parameterdescs{$param_name} = $undescribed;
  1998. if (($type eq 'function') || ($type eq 'enum')) {
  1999. print STDERR "${file}:$.: warning: Function parameter ".
  2000. "or member '$param' not " .
  2001. "described in '$declaration_name'\n";
  2002. }
  2003. print STDERR "${file}:$.: warning:" .
  2004. " No description found for parameter '$param'\n";
  2005. ++$warnings;
  2006. }
  2007. }
  2008. $param = xml_escape($param);
  2009. # strip spaces from $param so that it is one continuous string
  2010. # on @parameterlist;
  2011. # this fixes a problem where check_sections() cannot find
  2012. # a parameter like "addr[6 + 2]" because it actually appears
  2013. # as "addr[6", "+", "2]" on the parameter list;
  2014. # but it's better to maintain the param string unchanged for output,
  2015. # so just weaken the string compare in check_sections() to ignore
  2016. # "[blah" in a parameter string;
  2017. ###$param =~ s/\s*//g;
  2018. push @parameterlist, $param;
  2019. $parametertypes{$param} = $type;
  2020. }
  2021. sub check_sections($$$$$$) {
  2022. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
  2023. my @sects = split ' ', $sectcheck;
  2024. my @prms = split ' ', $prmscheck;
  2025. my $err;
  2026. my ($px, $sx);
  2027. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  2028. foreach $sx (0 .. $#sects) {
  2029. $err = 1;
  2030. foreach $px (0 .. $#prms) {
  2031. $prm_clean = $prms[$px];
  2032. $prm_clean =~ s/\[.*\]//;
  2033. $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  2034. # ignore array size in a parameter string;
  2035. # however, the original param string may contain
  2036. # spaces, e.g.: addr[6 + 2]
  2037. # and this appears in @prms as "addr[6" since the
  2038. # parameter list is split at spaces;
  2039. # hence just ignore "[..." for the sections check;
  2040. $prm_clean =~ s/\[.*//;
  2041. ##$prm_clean =~ s/^\**//;
  2042. if ($prm_clean eq $sects[$sx]) {
  2043. $err = 0;
  2044. last;
  2045. }
  2046. }
  2047. if ($err) {
  2048. if ($decl_type eq "function") {
  2049. print STDERR "${file}:$.: warning: " .
  2050. "Excess function parameter " .
  2051. "'$sects[$sx]' " .
  2052. "description in '$decl_name'\n";
  2053. ++$warnings;
  2054. } else {
  2055. if ($nested !~ m/\Q$sects[$sx]\E/) {
  2056. print STDERR "${file}:$.: warning: " .
  2057. "Excess struct/union/enum/typedef member " .
  2058. "'$sects[$sx]' " .
  2059. "description in '$decl_name'\n";
  2060. ++$warnings;
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. ##
  2067. # Checks the section describing the return value of a function.
  2068. sub check_return_section {
  2069. my $file = shift;
  2070. my $declaration_name = shift;
  2071. my $return_type = shift;
  2072. # Ignore an empty return type (It's a macro)
  2073. # Ignore functions with a "void" return type. (But don't ignore "void *")
  2074. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  2075. return;
  2076. }
  2077. if (!defined($sections{$section_return}) ||
  2078. $sections{$section_return} eq "") {
  2079. print STDERR "${file}:$.: warning: " .
  2080. "No description found for return value of " .
  2081. "'$declaration_name'\n";
  2082. ++$warnings;
  2083. }
  2084. }
  2085. ##
  2086. # takes a function prototype and the name of the current file being
  2087. # processed and spits out all the details stored in the global
  2088. # arrays/hashes.
  2089. sub dump_function($$) {
  2090. my $prototype = shift;
  2091. my $file = shift;
  2092. my $noret = 0;
  2093. $prototype =~ s/^static +//;
  2094. $prototype =~ s/^extern +//;
  2095. $prototype =~ s/^asmlinkage +//;
  2096. $prototype =~ s/^inline +//;
  2097. $prototype =~ s/^__inline__ +//;
  2098. $prototype =~ s/^__inline +//;
  2099. $prototype =~ s/^__always_inline +//;
  2100. $prototype =~ s/^noinline +//;
  2101. $prototype =~ s/__init +//;
  2102. $prototype =~ s/__init_or_module +//;
  2103. $prototype =~ s/__meminit +//;
  2104. $prototype =~ s/__must_check +//;
  2105. $prototype =~ s/__weak +//;
  2106. my $define = $prototype =~ s/^#\s*define\s+//; #ak added
  2107. $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
  2108. # Yes, this truly is vile. We are looking for:
  2109. # 1. Return type (may be nothing if we're looking at a macro)
  2110. # 2. Function name
  2111. # 3. Function parameters.
  2112. #
  2113. # All the while we have to watch out for function pointer parameters
  2114. # (which IIRC is what the two sections are for), C types (these
  2115. # regexps don't even start to express all the possibilities), and
  2116. # so on.
  2117. #
  2118. # If you mess with these regexps, it's a good idea to check that
  2119. # the following functions' documentation still comes out right:
  2120. # - parport_register_device (function pointer parameters)
  2121. # - atomic_set (macro)
  2122. # - pci_match_device, __copy_to_user (long return type)
  2123. if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
  2124. # This is an object-like macro, it has no return type and no parameter
  2125. # list.
  2126. # Function-like macros are not allowed to have spaces between
  2127. # declaration_name and opening parenthesis (notice the \s+).
  2128. $return_type = $1;
  2129. $declaration_name = $2;
  2130. $noret = 1;
  2131. } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2132. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2133. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2134. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2135. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2136. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2137. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2138. $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2139. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2140. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2141. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2142. $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2143. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2144. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2145. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2146. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2147. $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  2148. $return_type = $1;
  2149. $declaration_name = $2;
  2150. my $args = $3;
  2151. create_parameterlist($args, ',', $file);
  2152. } else {
  2153. print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
  2154. return;
  2155. }
  2156. my $prms = join " ", @parameterlist;
  2157. check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
  2158. # This check emits a lot of warnings at the moment, because many
  2159. # functions don't have a 'Return' doc section. So until the number
  2160. # of warnings goes sufficiently down, the check is only performed in
  2161. # verbose mode.
  2162. # TODO: always perform the check.
  2163. if ($verbose && !$noret) {
  2164. check_return_section($file, $declaration_name, $return_type);
  2165. }
  2166. output_declaration($declaration_name,
  2167. 'function',
  2168. {'function' => $declaration_name,
  2169. 'module' => $modulename,
  2170. 'functiontype' => $return_type,
  2171. 'parameterlist' => \@parameterlist,
  2172. 'parameterdescs' => \%parameterdescs,
  2173. 'parametertypes' => \%parametertypes,
  2174. 'sectionlist' => \@sectionlist,
  2175. 'sections' => \%sections,
  2176. 'purpose' => $declaration_purpose
  2177. });
  2178. }
  2179. sub reset_state {
  2180. $function = "";
  2181. %constants = ();
  2182. %parameterdescs = ();
  2183. %parametertypes = ();
  2184. @parameterlist = ();
  2185. %sections = ();
  2186. @sectionlist = ();
  2187. $sectcheck = "";
  2188. $struct_actual = "";
  2189. $prototype = "";
  2190. $state = 0;
  2191. $split_doc_state = 0;
  2192. }
  2193. sub tracepoint_munge($) {
  2194. my $file = shift;
  2195. my $tracepointname = 0;
  2196. my $tracepointargs = 0;
  2197. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  2198. $tracepointname = $1;
  2199. }
  2200. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  2201. $tracepointname = $1;
  2202. }
  2203. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  2204. $tracepointname = $2;
  2205. }
  2206. $tracepointname =~ s/^\s+//; #strip leading whitespace
  2207. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  2208. $tracepointargs = $1;
  2209. }
  2210. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  2211. print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
  2212. "$prototype\n";
  2213. } else {
  2214. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  2215. }
  2216. }
  2217. sub syscall_munge() {
  2218. my $void = 0;
  2219. $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
  2220. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  2221. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  2222. $void = 1;
  2223. ## $prototype = "long sys_$1(void)";
  2224. }
  2225. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  2226. if ($prototype =~ m/long (sys_.*?),/) {
  2227. $prototype =~ s/,/\(/;
  2228. } elsif ($void) {
  2229. $prototype =~ s/\)/\(void\)/;
  2230. }
  2231. # now delete all of the odd-number commas in $prototype
  2232. # so that arg types & arg names don't have a comma between them
  2233. my $count = 0;
  2234. my $len = length($prototype);
  2235. if ($void) {
  2236. $len = 0; # skip the for-loop
  2237. }
  2238. for (my $ix = 0; $ix < $len; $ix++) {
  2239. if (substr($prototype, $ix, 1) eq ',') {
  2240. $count++;
  2241. if ($count % 2 == 1) {
  2242. substr($prototype, $ix, 1) = ' ';
  2243. }
  2244. }
  2245. }
  2246. }
  2247. sub process_state3_function($$) {
  2248. my $x = shift;
  2249. my $file = shift;
  2250. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2251. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  2252. # do nothing
  2253. }
  2254. elsif ($x =~ /([^\{]*)/) {
  2255. $prototype .= $1;
  2256. }
  2257. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  2258. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  2259. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2260. $prototype =~ s@^\s+@@gos; # strip leading spaces
  2261. if ($prototype =~ /SYSCALL_DEFINE/) {
  2262. syscall_munge();
  2263. }
  2264. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  2265. $prototype =~ /DEFINE_SINGLE_EVENT/)
  2266. {
  2267. tracepoint_munge($file);
  2268. }
  2269. dump_function($prototype, $file);
  2270. reset_state();
  2271. }
  2272. }
  2273. sub process_state3_type($$) {
  2274. my $x = shift;
  2275. my $file = shift;
  2276. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2277. $x =~ s@^\s+@@gos; # strip leading spaces
  2278. $x =~ s@\s+$@@gos; # strip trailing spaces
  2279. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2280. if ($x =~ /^#/) {
  2281. # To distinguish preprocessor directive from regular declaration later.
  2282. $x .= ";";
  2283. }
  2284. while (1) {
  2285. if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
  2286. $prototype .= $1 . $2;
  2287. ($2 eq '{') && $brcount++;
  2288. ($2 eq '}') && $brcount--;
  2289. if (($2 eq ';') && ($brcount == 0)) {
  2290. dump_declaration($prototype, $file);
  2291. reset_state();
  2292. last;
  2293. }
  2294. $x = $3;
  2295. } else {
  2296. $prototype .= $x;
  2297. last;
  2298. }
  2299. }
  2300. }
  2301. # xml_escape: replace <, >, and & in the text stream;
  2302. #
  2303. # however, formatting controls that are generated internally/locally in the
  2304. # kernel-doc script are not escaped here; instead, they begin life like
  2305. # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
  2306. # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
  2307. # just before actual output; (this is done by local_unescape())
  2308. sub xml_escape($) {
  2309. my $text = shift;
  2310. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2311. return $text;
  2312. }
  2313. $text =~ s/\&/\\\\\\amp;/g;
  2314. $text =~ s/\</\\\\\\lt;/g;
  2315. $text =~ s/\>/\\\\\\gt;/g;
  2316. return $text;
  2317. }
  2318. # xml_unescape: reverse the effects of xml_escape
  2319. sub xml_unescape($) {
  2320. my $text = shift;
  2321. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2322. return $text;
  2323. }
  2324. $text =~ s/\\\\\\amp;/\&/g;
  2325. $text =~ s/\\\\\\lt;/</g;
  2326. $text =~ s/\\\\\\gt;/>/g;
  2327. return $text;
  2328. }
  2329. # convert local escape strings to html
  2330. # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
  2331. sub local_unescape($) {
  2332. my $text = shift;
  2333. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2334. return $text;
  2335. }
  2336. $text =~ s/\\\\\\\\lt:/</g;
  2337. $text =~ s/\\\\\\\\gt:/>/g;
  2338. return $text;
  2339. }
  2340. sub process_file($) {
  2341. my $file;
  2342. my $identifier;
  2343. my $func;
  2344. my $descr;
  2345. my $in_purpose = 0;
  2346. my $initial_section_counter = $section_counter;
  2347. my ($orig_file) = @_;
  2348. if (defined($ENV{'SRCTREE'})) {
  2349. $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
  2350. }
  2351. else {
  2352. $file = $orig_file;
  2353. }
  2354. if (defined($source_map{$file})) {
  2355. $file = $source_map{$file};
  2356. }
  2357. if (!open(IN,"<$file")) {
  2358. print STDERR "Error: Cannot open file $file\n";
  2359. ++$errors;
  2360. return;
  2361. }
  2362. $. = 1;
  2363. $section_counter = 0;
  2364. while (<IN>) {
  2365. while (s/\\\s*$//) {
  2366. $_ .= <IN>;
  2367. }
  2368. if ($state == 0) {
  2369. if (/$doc_start/o) {
  2370. $state = 1; # next line is always the function name
  2371. $in_doc_sect = 0;
  2372. }
  2373. } elsif ($state == 1) { # this line is the function name (always)
  2374. if (/$doc_block/o) {
  2375. $state = 4;
  2376. $contents = "";
  2377. if ( $1 eq "" ) {
  2378. $section = $section_intro;
  2379. } else {
  2380. $section = $1;
  2381. }
  2382. }
  2383. elsif (/$doc_decl/o) {
  2384. $identifier = $1;
  2385. if (/\s*([\w\s]+?)\s*-/) {
  2386. $identifier = $1;
  2387. }
  2388. $state = 2;
  2389. if (/-(.*)/) {
  2390. # strip leading/trailing/multiple spaces
  2391. $descr= $1;
  2392. $descr =~ s/^\s*//;
  2393. $descr =~ s/\s*$//;
  2394. $descr =~ s/\s+/ /g;
  2395. $declaration_purpose = xml_escape($descr);
  2396. $in_purpose = 1;
  2397. } else {
  2398. $declaration_purpose = "";
  2399. }
  2400. if (($declaration_purpose eq "") && $verbose) {
  2401. print STDERR "${file}:$.: warning: missing initial short description on line:\n";
  2402. print STDERR $_;
  2403. ++$warnings;
  2404. }
  2405. if ($identifier =~ m/^struct/) {
  2406. $decl_type = 'struct';
  2407. } elsif ($identifier =~ m/^union/) {
  2408. $decl_type = 'union';
  2409. } elsif ($identifier =~ m/^enum/) {
  2410. $decl_type = 'enum';
  2411. } elsif ($identifier =~ m/^typedef/) {
  2412. $decl_type = 'typedef';
  2413. } else {
  2414. $decl_type = 'function';
  2415. }
  2416. if ($verbose) {
  2417. print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
  2418. }
  2419. } else {
  2420. print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
  2421. " - I thought it was a doc line\n";
  2422. ++$warnings;
  2423. $state = 0;
  2424. }
  2425. } elsif ($state == 2) { # look for head: lines, and include content
  2426. if (/$doc_sect/o) {
  2427. $newsection = $1;
  2428. $newcontents = $2;
  2429. if (($contents ne "") && ($contents ne "\n")) {
  2430. if (!$in_doc_sect && $verbose) {
  2431. print STDERR "${file}:$.: warning: contents before sections\n";
  2432. ++$warnings;
  2433. }
  2434. dump_section($file, $section, xml_escape($contents));
  2435. $section = $section_default;
  2436. }
  2437. $in_doc_sect = 1;
  2438. $in_purpose = 0;
  2439. $contents = $newcontents;
  2440. if ($contents ne "") {
  2441. while ((substr($contents, 0, 1) eq " ") ||
  2442. substr($contents, 0, 1) eq "\t") {
  2443. $contents = substr($contents, 1);
  2444. }
  2445. $contents .= "\n";
  2446. }
  2447. $section = $newsection;
  2448. } elsif (/$doc_end/) {
  2449. if (($contents ne "") && ($contents ne "\n")) {
  2450. dump_section($file, $section, xml_escape($contents));
  2451. $section = $section_default;
  2452. $contents = "";
  2453. }
  2454. # look for doc_com + <text> + doc_end:
  2455. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  2456. print STDERR "${file}:$.: warning: suspicious ending line: $_";
  2457. ++$warnings;
  2458. }
  2459. $prototype = "";
  2460. $state = 3;
  2461. $brcount = 0;
  2462. # print STDERR "end of doc comment, looking for prototype\n";
  2463. } elsif (/$doc_content/) {
  2464. # miguel-style comment kludge, look for blank lines after
  2465. # @parameter line to signify start of description
  2466. if ($1 eq "") {
  2467. if ($section =~ m/^@/ || $section eq $section_context) {
  2468. dump_section($file, $section, xml_escape($contents));
  2469. $section = $section_default;
  2470. $contents = "";
  2471. } else {
  2472. $contents .= "\n";
  2473. }
  2474. $in_purpose = 0;
  2475. } elsif ($in_purpose == 1) {
  2476. # Continued declaration purpose
  2477. chomp($declaration_purpose);
  2478. $declaration_purpose .= " " . xml_escape($1);
  2479. $declaration_purpose =~ s/\s+/ /g;
  2480. } else {
  2481. $contents .= $1 . "\n";
  2482. }
  2483. } else {
  2484. # i dont know - bad line? ignore.
  2485. print STDERR "${file}:$.: warning: bad line: $_";
  2486. ++$warnings;
  2487. }
  2488. } elsif ($state == 5) { # scanning for split parameters
  2489. # First line (state 1) needs to be a @parameter
  2490. if ($split_doc_state == 1 && /$doc_split_sect/o) {
  2491. $section = $1;
  2492. $contents = $2;
  2493. if ($contents ne "") {
  2494. while ((substr($contents, 0, 1) eq " ") ||
  2495. substr($contents, 0, 1) eq "\t") {
  2496. $contents = substr($contents, 1);
  2497. }
  2498. $contents .= "\n";
  2499. }
  2500. $split_doc_state = 2;
  2501. # Documentation block end */
  2502. } elsif (/$doc_split_end/) {
  2503. if (($contents ne "") && ($contents ne "\n")) {
  2504. dump_section($file, $section, xml_escape($contents));
  2505. $section = $section_default;
  2506. $contents = "";
  2507. }
  2508. $state = 3;
  2509. $split_doc_state = 0;
  2510. # Regular text
  2511. } elsif (/$doc_content/) {
  2512. if ($split_doc_state == 2) {
  2513. $contents .= $1 . "\n";
  2514. } elsif ($split_doc_state == 1) {
  2515. $split_doc_state = 4;
  2516. print STDERR "Warning(${file}:$.): ";
  2517. print STDERR "Incorrect use of kernel-doc format: $_";
  2518. ++$warnings;
  2519. }
  2520. }
  2521. } elsif ($state == 3) { # scanning for function '{' (end of prototype)
  2522. if (/$doc_split_start/) {
  2523. $state = 5;
  2524. $split_doc_state = 1;
  2525. } elsif ($decl_type eq 'function') {
  2526. process_state3_function($_, $file);
  2527. } else {
  2528. process_state3_type($_, $file);
  2529. }
  2530. } elsif ($state == 4) {
  2531. # Documentation block
  2532. if (/$doc_block/) {
  2533. dump_doc_section($file, $section, xml_escape($contents));
  2534. $contents = "";
  2535. $function = "";
  2536. %constants = ();
  2537. %parameterdescs = ();
  2538. %parametertypes = ();
  2539. @parameterlist = ();
  2540. %sections = ();
  2541. @sectionlist = ();
  2542. $prototype = "";
  2543. if ( $1 eq "" ) {
  2544. $section = $section_intro;
  2545. } else {
  2546. $section = $1;
  2547. }
  2548. }
  2549. elsif (/$doc_end/)
  2550. {
  2551. dump_doc_section($file, $section, xml_escape($contents));
  2552. $contents = "";
  2553. $function = "";
  2554. %constants = ();
  2555. %parameterdescs = ();
  2556. %parametertypes = ();
  2557. @parameterlist = ();
  2558. %sections = ();
  2559. @sectionlist = ();
  2560. $prototype = "";
  2561. $state = 0;
  2562. }
  2563. elsif (/$doc_content/)
  2564. {
  2565. if ( $1 eq "" )
  2566. {
  2567. $contents .= $blankline;
  2568. }
  2569. else
  2570. {
  2571. $contents .= $1 . "\n";
  2572. }
  2573. }
  2574. }
  2575. }
  2576. if ($initial_section_counter == $section_counter) {
  2577. print STDERR "${file}:1: warning: no structured comments found\n";
  2578. if (($function_only == 1) && ($show_not_found == 1)) {
  2579. print STDERR " Was looking for '$_'.\n" for keys %function_table;
  2580. }
  2581. if ($output_mode eq "xml") {
  2582. # The template wants at least one RefEntry here; make one.
  2583. print "<refentry>\n";
  2584. print " <refnamediv>\n";
  2585. print " <refname>\n";
  2586. print " ${orig_file}\n";
  2587. print " </refname>\n";
  2588. print " <refpurpose>\n";
  2589. print " Document generation inconsistency\n";
  2590. print " </refpurpose>\n";
  2591. print " </refnamediv>\n";
  2592. print " <refsect1>\n";
  2593. print " <title>\n";
  2594. print " Oops\n";
  2595. print " </title>\n";
  2596. print " <warning>\n";
  2597. print " <para>\n";
  2598. print " The template for this document tried to insert\n";
  2599. print " the structured comment from the file\n";
  2600. print " <filename>${orig_file}</filename> at this point,\n";
  2601. print " but none was found.\n";
  2602. print " This dummy section is inserted to allow\n";
  2603. print " generation to continue.\n";
  2604. print " </para>\n";
  2605. print " </warning>\n";
  2606. print " </refsect1>\n";
  2607. print "</refentry>\n";
  2608. }
  2609. }
  2610. }
  2611. $kernelversion = get_kernel_version();
  2612. # generate a sequence of code that will splice in highlighting information
  2613. # using the s// operator.
  2614. for (my $k = 0; $k < @highlights; $k++) {
  2615. my $pattern = $highlights[$k][0];
  2616. my $result = $highlights[$k][1];
  2617. # print STDERR "scanning pattern:$pattern, highlight:($result)\n";
  2618. $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
  2619. }
  2620. # Read the file that maps relative names to absolute names for
  2621. # separate source and object directories and for shadow trees.
  2622. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2623. my ($relname, $absname);
  2624. while(<SOURCE_MAP>) {
  2625. chop();
  2626. ($relname, $absname) = (split())[0..1];
  2627. $relname =~ s:^/+::;
  2628. $source_map{$relname} = $absname;
  2629. }
  2630. close(SOURCE_MAP);
  2631. }
  2632. foreach (@ARGV) {
  2633. chomp;
  2634. process_file($_);
  2635. }
  2636. if ($verbose && $errors) {
  2637. print STDERR "$errors errors\n";
  2638. }
  2639. if ($verbose && $warnings) {
  2640. print STDERR "$warnings warnings\n";
  2641. }
  2642. exit($errors);