kernel-doc 88 KB

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