kernel-doc 89 KB

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