kernel-doc 87 KB

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