kernel-doc 85 KB

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