kernel-doc 92 KB

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