kernel-doc 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447
  1. #!/usr/bin/env perl
  2. # SPDX-License-Identifier: GPL-2.0
  3. use warnings;
  4. use strict;
  5. ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
  6. ## Copyright (C) 2000, 1 Tim Waugh <[email protected]> ##
  7. ## Copyright (C) 2001 Simon Huggins ##
  8. ## Copyright (C) 2005-2012 Randy Dunlap ##
  9. ## Copyright (C) 2012 Dan Luedtke ##
  10. ## ##
  11. ## #define enhancements by Armin Kuster <[email protected]> ##
  12. ## Copyright (c) 2000 MontaVista Software, Inc. ##
  13. ## ##
  14. ## This software falls under the GNU General Public License. ##
  15. ## Please read the COPYING file for more information ##
  16. # 18/01/2001 - Cleanups
  17. # Functions prototyped as foo(void) same as foo()
  18. # Stop eval'ing where we don't need to.
  19. # -- [email protected]
  20. # 27/06/2001 - Allowed whitespace after initial "/**" and
  21. # allowed comments before function declarations.
  22. # -- Christian Kreibich <[email protected]>
  23. # Still to do:
  24. # - add perldoc documentation
  25. # - Look more closely at some of the scarier bits :)
  26. # 26/05/2001 - Support for separate source and object trees.
  27. # Return error code.
  28. # Keith Owens <[email protected]>
  29. # 23/09/2001 - Added support for typedefs, structs, enums and unions
  30. # Support for Context section; can be terminated using empty line
  31. # Small fixes (like spaces vs. \s in regex)
  32. # -- Tim Jansen <[email protected]>
  33. # 25/07/2012 - Added support for HTML5
  34. # -- Dan Luedtke <[email protected]>
  35. sub usage {
  36. my $message = <<"EOF";
  37. Usage: $0 [OPTION ...] FILE ...
  38. Read C language source or header FILEs, extract embedded documentation comments,
  39. and print formatted documentation to standard output.
  40. The documentation comments are identified by "/**" opening comment mark. See
  41. Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax.
  42. Output format selection (mutually exclusive):
  43. -man Output troff manual page format. This is the default.
  44. -rst Output reStructuredText format.
  45. -none Do not output documentation, only warnings.
  46. Output format selection modifier (affects only ReST output):
  47. -sphinx-version Use the ReST C domain dialect compatible with an
  48. specific Sphinx Version.
  49. If not specified, kernel-doc will auto-detect using
  50. the sphinx-build version found on PATH.
  51. Output selection (mutually exclusive):
  52. -export Only output documentation for symbols that have been
  53. exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
  54. in any input FILE or -export-file FILE.
  55. -internal Only output documentation for symbols that have NOT been
  56. exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
  57. in any input FILE or -export-file FILE.
  58. -function NAME Only output documentation for the given function(s)
  59. or DOC: section title(s). All other functions and DOC:
  60. sections are ignored. May be specified multiple times.
  61. -nosymbol NAME Exclude the specified symbols from the output
  62. documentation. May be specified multiple times.
  63. Output selection modifiers:
  64. -no-doc-sections Do not output DOC: sections.
  65. -enable-lineno Enable output of #define LINENO lines. Only works with
  66. reStructuredText format.
  67. -export-file FILE Specify an additional FILE in which to look for
  68. EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with
  69. -export or -internal. May be specified multiple times.
  70. Other parameters:
  71. -v Verbose output, more warnings and other information.
  72. -h Print this help.
  73. -Werror Treat warnings as errors.
  74. EOF
  75. print $message;
  76. exit 1;
  77. }
  78. #
  79. # format of comments.
  80. # In the following table, (...)? signifies optional structure.
  81. # (...)* signifies 0 or more structure elements
  82. # /**
  83. # * function_name(:)? (- short description)?
  84. # (* @parameterx: (description of parameter x)?)*
  85. # (* a blank line)?
  86. # * (Description:)? (Description of function)?
  87. # * (section header: (section description)? )*
  88. # (*)?*/
  89. #
  90. # So .. the trivial example would be:
  91. #
  92. # /**
  93. # * my_function
  94. # */
  95. #
  96. # If the Description: header tag is omitted, then there must be a blank line
  97. # after the last parameter specification.
  98. # e.g.
  99. # /**
  100. # * my_function - does my stuff
  101. # * @my_arg: its mine damnit
  102. # *
  103. # * Does my stuff explained.
  104. # */
  105. #
  106. # or, could also use:
  107. # /**
  108. # * my_function - does my stuff
  109. # * @my_arg: its mine damnit
  110. # * Description: Does my stuff explained.
  111. # */
  112. # etc.
  113. #
  114. # Besides functions you can also write documentation for structs, unions,
  115. # enums and typedefs. Instead of the function name you must write the name
  116. # of the declaration; the struct/union/enum/typedef must always precede
  117. # the name. Nesting of declarations is not supported.
  118. # Use the argument mechanism to document members or constants.
  119. # e.g.
  120. # /**
  121. # * struct my_struct - short description
  122. # * @a: first member
  123. # * @b: second member
  124. # *
  125. # * Longer description
  126. # */
  127. # struct my_struct {
  128. # int a;
  129. # int b;
  130. # /* private: */
  131. # int c;
  132. # };
  133. #
  134. # All descriptions can be multiline, except the short function description.
  135. #
  136. # For really longs structs, you can also describe arguments inside the
  137. # body of the struct.
  138. # eg.
  139. # /**
  140. # * struct my_struct - short description
  141. # * @a: first member
  142. # * @b: second member
  143. # *
  144. # * Longer description
  145. # */
  146. # struct my_struct {
  147. # int a;
  148. # int b;
  149. # /**
  150. # * @c: This is longer description of C
  151. # *
  152. # * You can use paragraphs to describe arguments
  153. # * using this method.
  154. # */
  155. # int c;
  156. # };
  157. #
  158. # This should be use only for struct/enum members.
  159. #
  160. # You can also add additional sections. When documenting kernel functions you
  161. # should document the "Context:" of the function, e.g. whether the functions
  162. # can be called form interrupts. Unlike other sections you can end it with an
  163. # empty line.
  164. # A non-void function should have a "Return:" section describing the return
  165. # value(s).
  166. # Example-sections should contain the string EXAMPLE so that they are marked
  167. # appropriately in DocBook.
  168. #
  169. # Example:
  170. # /**
  171. # * user_function - function that can only be called in user context
  172. # * @a: some argument
  173. # * Context: !in_interrupt()
  174. # *
  175. # * Some description
  176. # * Example:
  177. # * user_function(22);
  178. # */
  179. # ...
  180. #
  181. #
  182. # All descriptive text is further processed, scanning for the following special
  183. # patterns, which are highlighted appropriately.
  184. #
  185. # 'funcname()' - function
  186. # '$ENVVAR' - environmental variable
  187. # '&struct_name' - name of a structure (up to two words including 'struct')
  188. # '&struct_name.member' - name of a structure member
  189. # '@parameter' - name of a parameter
  190. # '%CONST' - name of a constant.
  191. # '``LITERAL``' - literal string without any spaces on it.
  192. ## init lots of data
  193. my $errors = 0;
  194. my $warnings = 0;
  195. my $anon_struct_union = 0;
  196. # match expressions used to find embedded type information
  197. my $type_constant = '\b``([^\`]+)``\b';
  198. my $type_constant2 = '\%([-_\w]+)';
  199. my $type_func = '(\w+)\(\)';
  200. my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
  201. my $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
  202. my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
  203. my $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params
  204. my $type_env = '(\$\w+)';
  205. my $type_enum = '\&(enum\s*([_\w]+))';
  206. my $type_struct = '\&(struct\s*([_\w]+))';
  207. my $type_typedef = '\&(typedef\s*([_\w]+))';
  208. my $type_union = '\&(union\s*([_\w]+))';
  209. my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
  210. my $type_fallback = '\&([_\w]+)';
  211. my $type_member_func = $type_member . '\(\)';
  212. # Output conversion substitutions.
  213. # One for each output format
  214. # these are pretty rough
  215. my @highlights_man = (
  216. [$type_constant, "\$1"],
  217. [$type_constant2, "\$1"],
  218. [$type_func, "\\\\fB\$1\\\\fP"],
  219. [$type_enum, "\\\\fI\$1\\\\fP"],
  220. [$type_struct, "\\\\fI\$1\\\\fP"],
  221. [$type_typedef, "\\\\fI\$1\\\\fP"],
  222. [$type_union, "\\\\fI\$1\\\\fP"],
  223. [$type_param, "\\\\fI\$1\\\\fP"],
  224. [$type_param_ref, "\\\\fI\$1\$2\\\\fP"],
  225. [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
  226. [$type_fallback, "\\\\fI\$1\\\\fP"]
  227. );
  228. my $blankline_man = "";
  229. # rst-mode
  230. my @highlights_rst = (
  231. [$type_constant, "``\$1``"],
  232. [$type_constant2, "``\$1``"],
  233. # Note: need to escape () to avoid func matching later
  234. [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
  235. [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
  236. [$type_fp_param, "**\$1\\\\(\\\\)**"],
  237. [$type_fp_param2, "**\$1\\\\(\\\\)**"],
  238. [$type_func, "\$1()"],
  239. [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
  240. [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
  241. [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
  242. [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
  243. # in rst this can refer to any type
  244. [$type_fallback, "\\:c\\:type\\:`\$1`"],
  245. [$type_param_ref, "**\$1\$2**"]
  246. );
  247. my $blankline_rst = "\n";
  248. # read arguments
  249. if ($#ARGV == -1) {
  250. usage();
  251. }
  252. my $kernelversion;
  253. my ($sphinx_major, $sphinx_minor, $sphinx_patch);
  254. my $dohighlight = "";
  255. my $verbose = 0;
  256. my $Werror = 0;
  257. my $output_mode = "rst";
  258. my $output_preformatted = 0;
  259. my $no_doc_sections = 0;
  260. my $enable_lineno = 0;
  261. my @highlights = @highlights_rst;
  262. my $blankline = $blankline_rst;
  263. my $modulename = "Kernel API";
  264. use constant {
  265. OUTPUT_ALL => 0, # output all symbols and doc sections
  266. OUTPUT_INCLUDE => 1, # output only specified symbols
  267. OUTPUT_EXPORTED => 2, # output exported symbols
  268. OUTPUT_INTERNAL => 3, # output non-exported symbols
  269. };
  270. my $output_selection = OUTPUT_ALL;
  271. my $show_not_found = 0; # No longer used
  272. my @export_file_list;
  273. my @build_time;
  274. if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
  275. (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
  276. @build_time = gmtime($seconds);
  277. } else {
  278. @build_time = localtime;
  279. }
  280. my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
  281. 'July', 'August', 'September', 'October',
  282. 'November', 'December')[$build_time[4]] .
  283. " " . ($build_time[5]+1900);
  284. # Essentially these are globals.
  285. # They probably want to be tidied up, made more localised or something.
  286. # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
  287. # could cause "use of undefined value" or other bugs.
  288. my ($function, %function_table, %parametertypes, $declaration_purpose);
  289. my %nosymbol_table = ();
  290. my $declaration_start_line;
  291. my ($type, $declaration_name, $return_type);
  292. my ($newsection, $newcontents, $prototype, $brcount, %source_map);
  293. if (defined($ENV{'KBUILD_VERBOSE'})) {
  294. $verbose = "$ENV{'KBUILD_VERBOSE'}";
  295. }
  296. if (defined($ENV{'KDOC_WERROR'})) {
  297. $Werror = "$ENV{'KDOC_WERROR'}";
  298. }
  299. if (defined($ENV{'KCFLAGS'})) {
  300. my $kcflags = "$ENV{'KCFLAGS'}";
  301. if ($kcflags =~ /Werror/) {
  302. $Werror = 1;
  303. }
  304. }
  305. # Generated docbook code is inserted in a template at a point where
  306. # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
  307. # https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
  308. # We keep track of number of generated entries and generate a dummy
  309. # if needs be to ensure the expanded template can be postprocessed
  310. # into html.
  311. my $section_counter = 0;
  312. my $lineprefix="";
  313. # Parser states
  314. use constant {
  315. STATE_NORMAL => 0, # normal code
  316. STATE_NAME => 1, # looking for function name
  317. STATE_BODY_MAYBE => 2, # body - or maybe more description
  318. STATE_BODY => 3, # the body of the comment
  319. STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line
  320. STATE_PROTO => 5, # scanning prototype
  321. STATE_DOCBLOCK => 6, # documentation block
  322. STATE_INLINE => 7, # gathering doc outside main block
  323. };
  324. my $state;
  325. my $in_doc_sect;
  326. my $leading_space;
  327. # Inline documentation state
  328. use constant {
  329. STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
  330. STATE_INLINE_NAME => 1, # looking for member name (@foo:)
  331. STATE_INLINE_TEXT => 2, # looking for member documentation
  332. STATE_INLINE_END => 3, # done
  333. STATE_INLINE_ERROR => 4, # error - Comment without header was found.
  334. # Spit a warning as it's not
  335. # proper kernel-doc and ignore the rest.
  336. };
  337. my $inline_doc_state;
  338. #declaration types: can be
  339. # 'function', 'struct', 'union', 'enum', 'typedef'
  340. my $decl_type;
  341. my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
  342. my $doc_end = '\*/';
  343. my $doc_com = '\s*\*\s*';
  344. my $doc_com_body = '\s*\* ?';
  345. my $doc_decl = $doc_com . '(\w+)';
  346. # @params and a strictly limited set of supported section names
  347. my $doc_sect = $doc_com .
  348. '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
  349. my $doc_content = $doc_com_body . '(.*)';
  350. my $doc_block = $doc_com . 'DOC:\s*(.*)?';
  351. my $doc_inline_start = '^\s*/\*\*\s*$';
  352. my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';
  353. my $doc_inline_end = '^\s*\*/\s*$';
  354. my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
  355. my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
  356. my %parameterdescs;
  357. my %parameterdesc_start_lines;
  358. my @parameterlist;
  359. my %sections;
  360. my @sectionlist;
  361. my %section_start_lines;
  362. my $sectcheck;
  363. my $struct_actual;
  364. my $contents = "";
  365. my $new_start_line = 0;
  366. # the canonical section names. see also $doc_sect above.
  367. my $section_default = "Description"; # default section
  368. my $section_intro = "Introduction";
  369. my $section = $section_default;
  370. my $section_context = "Context";
  371. my $section_return = "Return";
  372. my $undescribed = "-- undescribed --";
  373. reset_state();
  374. while ($ARGV[0] =~ m/^--?(.*)/) {
  375. my $cmd = $1;
  376. shift @ARGV;
  377. if ($cmd eq "man") {
  378. $output_mode = "man";
  379. @highlights = @highlights_man;
  380. $blankline = $blankline_man;
  381. } elsif ($cmd eq "rst") {
  382. $output_mode = "rst";
  383. @highlights = @highlights_rst;
  384. $blankline = $blankline_rst;
  385. } elsif ($cmd eq "none") {
  386. $output_mode = "none";
  387. } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document
  388. $modulename = shift @ARGV;
  389. } elsif ($cmd eq "function") { # to only output specific functions
  390. $output_selection = OUTPUT_INCLUDE;
  391. $function = shift @ARGV;
  392. $function_table{$function} = 1;
  393. } elsif ($cmd eq "nosymbol") { # Exclude specific symbols
  394. my $symbol = shift @ARGV;
  395. $nosymbol_table{$symbol} = 1;
  396. } elsif ($cmd eq "export") { # only exported symbols
  397. $output_selection = OUTPUT_EXPORTED;
  398. %function_table = ();
  399. } elsif ($cmd eq "internal") { # only non-exported symbols
  400. $output_selection = OUTPUT_INTERNAL;
  401. %function_table = ();
  402. } elsif ($cmd eq "export-file") {
  403. my $file = shift @ARGV;
  404. push(@export_file_list, $file);
  405. } elsif ($cmd eq "v") {
  406. $verbose = 1;
  407. } elsif ($cmd eq "Werror") {
  408. $Werror = 1;
  409. } elsif (($cmd eq "h") || ($cmd eq "help")) {
  410. usage();
  411. } elsif ($cmd eq 'no-doc-sections') {
  412. $no_doc_sections = 1;
  413. } elsif ($cmd eq 'enable-lineno') {
  414. $enable_lineno = 1;
  415. } elsif ($cmd eq 'show-not-found') {
  416. $show_not_found = 1; # A no-op but don't fail
  417. } elsif ($cmd eq "sphinx-version") {
  418. my $ver_string = shift @ARGV;
  419. if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) {
  420. $sphinx_major = $1;
  421. if (defined($2)) {
  422. $sphinx_minor = substr($2,1);
  423. } else {
  424. $sphinx_minor = 0;
  425. }
  426. if (defined($3)) {
  427. $sphinx_patch = substr($3,1)
  428. } else {
  429. $sphinx_patch = 0;
  430. }
  431. } else {
  432. die "Sphinx version should either major.minor or major.minor.patch format\n";
  433. }
  434. } else {
  435. # Unknown argument
  436. usage();
  437. }
  438. }
  439. # continue execution near EOF;
  440. # The C domain dialect changed on Sphinx 3. So, we need to check the
  441. # version in order to produce the right tags.
  442. sub findprog($)
  443. {
  444. foreach(split(/:/, $ENV{PATH})) {
  445. return "$_/$_[0]" if(-x "$_/$_[0]");
  446. }
  447. }
  448. sub get_sphinx_version()
  449. {
  450. my $ver;
  451. my $cmd = "sphinx-build";
  452. if (!findprog($cmd)) {
  453. my $cmd = "sphinx-build3";
  454. if (!findprog($cmd)) {
  455. $sphinx_major = 1;
  456. $sphinx_minor = 2;
  457. $sphinx_patch = 0;
  458. printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n",
  459. $sphinx_major, $sphinx_minor, $sphinx_patch;
  460. return;
  461. }
  462. }
  463. open IN, "$cmd --version 2>&1 |";
  464. while (<IN>) {
  465. if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) {
  466. $sphinx_major = $1;
  467. $sphinx_minor = $2;
  468. $sphinx_patch = $3;
  469. last;
  470. }
  471. # Sphinx 1.2.x uses a different format
  472. if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) {
  473. $sphinx_major = $1;
  474. $sphinx_minor = $2;
  475. $sphinx_patch = $3;
  476. last;
  477. }
  478. }
  479. close IN;
  480. }
  481. # get kernel version from env
  482. sub get_kernel_version() {
  483. my $version = 'unknown kernel version';
  484. if (defined($ENV{'KERNELVERSION'})) {
  485. $version = $ENV{'KERNELVERSION'};
  486. }
  487. return $version;
  488. }
  489. #
  490. sub print_lineno {
  491. my $lineno = shift;
  492. if ($enable_lineno && defined($lineno)) {
  493. print "#define LINENO " . $lineno . "\n";
  494. }
  495. }
  496. ##
  497. # dumps section contents to arrays/hashes intended for that purpose.
  498. #
  499. sub dump_section {
  500. my $file = shift;
  501. my $name = shift;
  502. my $contents = join "\n", @_;
  503. if ($name =~ m/$type_param/) {
  504. $name = $1;
  505. $parameterdescs{$name} = $contents;
  506. $sectcheck = $sectcheck . $name . " ";
  507. $parameterdesc_start_lines{$name} = $new_start_line;
  508. $new_start_line = 0;
  509. } elsif ($name eq "@\.\.\.") {
  510. $name = "...";
  511. $parameterdescs{$name} = $contents;
  512. $sectcheck = $sectcheck . $name . " ";
  513. $parameterdesc_start_lines{$name} = $new_start_line;
  514. $new_start_line = 0;
  515. } else {
  516. if (defined($sections{$name}) && ($sections{$name} ne "")) {
  517. # Only warn on user specified duplicate section names.
  518. if ($name ne $section_default) {
  519. print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
  520. ++$warnings;
  521. }
  522. $sections{$name} .= $contents;
  523. } else {
  524. $sections{$name} = $contents;
  525. push @sectionlist, $name;
  526. $section_start_lines{$name} = $new_start_line;
  527. $new_start_line = 0;
  528. }
  529. }
  530. }
  531. ##
  532. # dump DOC: section after checking that it should go out
  533. #
  534. sub dump_doc_section {
  535. my $file = shift;
  536. my $name = shift;
  537. my $contents = join "\n", @_;
  538. if ($no_doc_sections) {
  539. return;
  540. }
  541. return if (defined($nosymbol_table{$name}));
  542. if (($output_selection == OUTPUT_ALL) ||
  543. (($output_selection == OUTPUT_INCLUDE) &&
  544. defined($function_table{$name})))
  545. {
  546. dump_section($file, $name, $contents);
  547. output_blockhead({'sectionlist' => \@sectionlist,
  548. 'sections' => \%sections,
  549. 'module' => $modulename,
  550. 'content-only' => ($output_selection != OUTPUT_ALL), });
  551. }
  552. }
  553. ##
  554. # output function
  555. #
  556. # parameterdescs, a hash.
  557. # function => "function name"
  558. # parameterlist => @list of parameters
  559. # parameterdescs => %parameter descriptions
  560. # sectionlist => @list of sections
  561. # sections => %section descriptions
  562. #
  563. sub output_highlight {
  564. my $contents = join "\n",@_;
  565. my $line;
  566. # DEBUG
  567. # if (!defined $contents) {
  568. # use Carp;
  569. # confess "output_highlight got called with no args?\n";
  570. # }
  571. # print STDERR "contents b4:$contents\n";
  572. eval $dohighlight;
  573. die $@ if $@;
  574. # print STDERR "contents af:$contents\n";
  575. foreach $line (split "\n", $contents) {
  576. if (! $output_preformatted) {
  577. $line =~ s/^\s*//;
  578. }
  579. if ($line eq ""){
  580. if (! $output_preformatted) {
  581. print $lineprefix, $blankline;
  582. }
  583. } else {
  584. if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
  585. print "\\&$line";
  586. } else {
  587. print $lineprefix, $line;
  588. }
  589. }
  590. print "\n";
  591. }
  592. }
  593. ##
  594. # output function in man
  595. sub output_function_man(%) {
  596. my %args = %{$_[0]};
  597. my ($parameter, $section);
  598. my $count;
  599. print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
  600. print ".SH NAME\n";
  601. print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
  602. print ".SH SYNOPSIS\n";
  603. if ($args{'functiontype'} ne "") {
  604. print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
  605. } else {
  606. print ".B \"" . $args{'function'} . "\n";
  607. }
  608. $count = 0;
  609. my $parenth = "(";
  610. my $post = ",";
  611. foreach my $parameter (@{$args{'parameterlist'}}) {
  612. if ($count == $#{$args{'parameterlist'}}) {
  613. $post = ");";
  614. }
  615. $type = $args{'parametertypes'}{$parameter};
  616. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  617. # pointer-to-function
  618. print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n";
  619. } else {
  620. $type =~ s/([^\*])$/$1 /;
  621. print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n";
  622. }
  623. $count++;
  624. $parenth = "";
  625. }
  626. print ".SH ARGUMENTS\n";
  627. foreach $parameter (@{$args{'parameterlist'}}) {
  628. my $parameter_name = $parameter;
  629. $parameter_name =~ s/\[.*//;
  630. print ".IP \"" . $parameter . "\" 12\n";
  631. output_highlight($args{'parameterdescs'}{$parameter_name});
  632. }
  633. foreach $section (@{$args{'sectionlist'}}) {
  634. print ".SH \"", uc $section, "\"\n";
  635. output_highlight($args{'sections'}{$section});
  636. }
  637. }
  638. ##
  639. # output enum in man
  640. sub output_enum_man(%) {
  641. my %args = %{$_[0]};
  642. my ($parameter, $section);
  643. my $count;
  644. print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
  645. print ".SH NAME\n";
  646. print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
  647. print ".SH SYNOPSIS\n";
  648. print "enum " . $args{'enum'} . " {\n";
  649. $count = 0;
  650. foreach my $parameter (@{$args{'parameterlist'}}) {
  651. print ".br\n.BI \" $parameter\"\n";
  652. if ($count == $#{$args{'parameterlist'}}) {
  653. print "\n};\n";
  654. last;
  655. }
  656. else {
  657. print ", \n.br\n";
  658. }
  659. $count++;
  660. }
  661. print ".SH Constants\n";
  662. foreach $parameter (@{$args{'parameterlist'}}) {
  663. my $parameter_name = $parameter;
  664. $parameter_name =~ s/\[.*//;
  665. print ".IP \"" . $parameter . "\" 12\n";
  666. output_highlight($args{'parameterdescs'}{$parameter_name});
  667. }
  668. foreach $section (@{$args{'sectionlist'}}) {
  669. print ".SH \"$section\"\n";
  670. output_highlight($args{'sections'}{$section});
  671. }
  672. }
  673. ##
  674. # output struct in man
  675. sub output_struct_man(%) {
  676. my %args = %{$_[0]};
  677. my ($parameter, $section);
  678. print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
  679. print ".SH NAME\n";
  680. print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
  681. my $declaration = $args{'definition'};
  682. $declaration =~ s/\t/ /g;
  683. $declaration =~ s/\n/"\n.br\n.BI \"/g;
  684. print ".SH SYNOPSIS\n";
  685. print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
  686. print ".BI \"$declaration\n};\n.br\n\n";
  687. print ".SH Members\n";
  688. foreach $parameter (@{$args{'parameterlist'}}) {
  689. ($parameter =~ /^#/) && next;
  690. my $parameter_name = $parameter;
  691. $parameter_name =~ s/\[.*//;
  692. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  693. print ".IP \"" . $parameter . "\" 12\n";
  694. output_highlight($args{'parameterdescs'}{$parameter_name});
  695. }
  696. foreach $section (@{$args{'sectionlist'}}) {
  697. print ".SH \"$section\"\n";
  698. output_highlight($args{'sections'}{$section});
  699. }
  700. }
  701. ##
  702. # output typedef in man
  703. sub output_typedef_man(%) {
  704. my %args = %{$_[0]};
  705. my ($parameter, $section);
  706. print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
  707. print ".SH NAME\n";
  708. print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
  709. foreach $section (@{$args{'sectionlist'}}) {
  710. print ".SH \"$section\"\n";
  711. output_highlight($args{'sections'}{$section});
  712. }
  713. }
  714. sub output_blockhead_man(%) {
  715. my %args = %{$_[0]};
  716. my ($parameter, $section);
  717. my $count;
  718. print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
  719. foreach $section (@{$args{'sectionlist'}}) {
  720. print ".SH \"$section\"\n";
  721. output_highlight($args{'sections'}{$section});
  722. }
  723. }
  724. ##
  725. # output in restructured text
  726. #
  727. #
  728. # This could use some work; it's used to output the DOC: sections, and
  729. # starts by putting out the name of the doc section itself, but that tends
  730. # to duplicate a header already in the template file.
  731. #
  732. sub output_blockhead_rst(%) {
  733. my %args = %{$_[0]};
  734. my ($parameter, $section);
  735. foreach $section (@{$args{'sectionlist'}}) {
  736. next if (defined($nosymbol_table{$section}));
  737. if ($output_selection != OUTPUT_INCLUDE) {
  738. print "**$section**\n\n";
  739. }
  740. print_lineno($section_start_lines{$section});
  741. output_highlight_rst($args{'sections'}{$section});
  742. print "\n";
  743. }
  744. }
  745. #
  746. # Apply the RST highlights to a sub-block of text.
  747. #
  748. sub highlight_block($) {
  749. # The dohighlight kludge requires the text be called $contents
  750. my $contents = shift;
  751. eval $dohighlight;
  752. die $@ if $@;
  753. return $contents;
  754. }
  755. #
  756. # Regexes used only here.
  757. #
  758. my $sphinx_literal = '^[^.].*::$';
  759. my $sphinx_cblock = '^\.\.\ +code-block::';
  760. sub output_highlight_rst {
  761. my $input = join "\n",@_;
  762. my $output = "";
  763. my $line;
  764. my $in_literal = 0;
  765. my $litprefix;
  766. my $block = "";
  767. foreach $line (split "\n",$input) {
  768. #
  769. # If we're in a literal block, see if we should drop out
  770. # of it. Otherwise pass the line straight through unmunged.
  771. #
  772. if ($in_literal) {
  773. if (! ($line =~ /^\s*$/)) {
  774. #
  775. # If this is the first non-blank line in a literal
  776. # block we need to figure out what the proper indent is.
  777. #
  778. if ($litprefix eq "") {
  779. $line =~ /^(\s*)/;
  780. $litprefix = '^' . $1;
  781. $output .= $line . "\n";
  782. } elsif (! ($line =~ /$litprefix/)) {
  783. $in_literal = 0;
  784. } else {
  785. $output .= $line . "\n";
  786. }
  787. } else {
  788. $output .= $line . "\n";
  789. }
  790. }
  791. #
  792. # Not in a literal block (or just dropped out)
  793. #
  794. if (! $in_literal) {
  795. $block .= $line . "\n";
  796. if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) {
  797. $in_literal = 1;
  798. $litprefix = "";
  799. $output .= highlight_block($block);
  800. $block = ""
  801. }
  802. }
  803. }
  804. if ($block) {
  805. $output .= highlight_block($block);
  806. }
  807. foreach $line (split "\n", $output) {
  808. print $lineprefix . $line . "\n";
  809. }
  810. }
  811. sub output_function_rst(%) {
  812. my %args = %{$_[0]};
  813. my ($parameter, $section);
  814. my $oldprefix = $lineprefix;
  815. my $start = "";
  816. my $is_macro = 0;
  817. if ($sphinx_major < 3) {
  818. if ($args{'typedef'}) {
  819. print ".. c:type:: ". $args{'function'} . "\n\n";
  820. print_lineno($declaration_start_line);
  821. print " **Typedef**: ";
  822. $lineprefix = "";
  823. output_highlight_rst($args{'purpose'});
  824. $start = "\n\n**Syntax**\n\n ``";
  825. $is_macro = 1;
  826. } else {
  827. print ".. c:function:: ";
  828. }
  829. } else {
  830. if ($args{'typedef'} || $args{'functiontype'} eq "") {
  831. $is_macro = 1;
  832. print ".. c:macro:: ". $args{'function'} . "\n\n";
  833. } else {
  834. print ".. c:function:: ";
  835. }
  836. if ($args{'typedef'}) {
  837. print_lineno($declaration_start_line);
  838. print " **Typedef**: ";
  839. $lineprefix = "";
  840. output_highlight_rst($args{'purpose'});
  841. $start = "\n\n**Syntax**\n\n ``";
  842. } else {
  843. print "``" if ($is_macro);
  844. }
  845. }
  846. if ($args{'functiontype'} ne "") {
  847. $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
  848. } else {
  849. $start .= $args{'function'} . " (";
  850. }
  851. print $start;
  852. my $count = 0;
  853. foreach my $parameter (@{$args{'parameterlist'}}) {
  854. if ($count ne 0) {
  855. print ", ";
  856. }
  857. $count++;
  858. $type = $args{'parametertypes'}{$parameter};
  859. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  860. # pointer-to-function
  861. print $1 . $parameter . ") (" . $2 . ")";
  862. } else {
  863. print $type;
  864. }
  865. }
  866. if ($is_macro) {
  867. print ")``\n\n";
  868. } else {
  869. print ")\n\n";
  870. }
  871. if (!$args{'typedef'}) {
  872. print_lineno($declaration_start_line);
  873. $lineprefix = " ";
  874. output_highlight_rst($args{'purpose'});
  875. print "\n";
  876. }
  877. print "**Parameters**\n\n";
  878. $lineprefix = " ";
  879. foreach $parameter (@{$args{'parameterlist'}}) {
  880. my $parameter_name = $parameter;
  881. $parameter_name =~ s/\[.*//;
  882. $type = $args{'parametertypes'}{$parameter};
  883. if ($type ne "") {
  884. print "``$type``\n";
  885. } else {
  886. print "``$parameter``\n";
  887. }
  888. print_lineno($parameterdesc_start_lines{$parameter_name});
  889. if (defined($args{'parameterdescs'}{$parameter_name}) &&
  890. $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
  891. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  892. } else {
  893. print " *undescribed*\n";
  894. }
  895. print "\n";
  896. }
  897. $lineprefix = $oldprefix;
  898. output_section_rst(@_);
  899. }
  900. sub output_section_rst(%) {
  901. my %args = %{$_[0]};
  902. my $section;
  903. my $oldprefix = $lineprefix;
  904. $lineprefix = "";
  905. foreach $section (@{$args{'sectionlist'}}) {
  906. print "**$section**\n\n";
  907. print_lineno($section_start_lines{$section});
  908. output_highlight_rst($args{'sections'}{$section});
  909. print "\n";
  910. }
  911. print "\n";
  912. $lineprefix = $oldprefix;
  913. }
  914. sub output_enum_rst(%) {
  915. my %args = %{$_[0]};
  916. my ($parameter);
  917. my $oldprefix = $lineprefix;
  918. my $count;
  919. if ($sphinx_major < 3) {
  920. my $name = "enum " . $args{'enum'};
  921. print "\n\n.. c:type:: " . $name . "\n\n";
  922. } else {
  923. my $name = $args{'enum'};
  924. print "\n\n.. c:enum:: " . $name . "\n\n";
  925. }
  926. print_lineno($declaration_start_line);
  927. $lineprefix = " ";
  928. output_highlight_rst($args{'purpose'});
  929. print "\n";
  930. print "**Constants**\n\n";
  931. $lineprefix = " ";
  932. foreach $parameter (@{$args{'parameterlist'}}) {
  933. print "``$parameter``\n";
  934. if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
  935. output_highlight_rst($args{'parameterdescs'}{$parameter});
  936. } else {
  937. print " *undescribed*\n";
  938. }
  939. print "\n";
  940. }
  941. $lineprefix = $oldprefix;
  942. output_section_rst(@_);
  943. }
  944. sub output_typedef_rst(%) {
  945. my %args = %{$_[0]};
  946. my ($parameter);
  947. my $oldprefix = $lineprefix;
  948. my $name;
  949. if ($sphinx_major < 3) {
  950. $name = "typedef " . $args{'typedef'};
  951. } else {
  952. $name = $args{'typedef'};
  953. }
  954. print "\n\n.. c:type:: " . $name . "\n\n";
  955. print_lineno($declaration_start_line);
  956. $lineprefix = " ";
  957. output_highlight_rst($args{'purpose'});
  958. print "\n";
  959. $lineprefix = $oldprefix;
  960. output_section_rst(@_);
  961. }
  962. sub output_struct_rst(%) {
  963. my %args = %{$_[0]};
  964. my ($parameter);
  965. my $oldprefix = $lineprefix;
  966. if ($sphinx_major < 3) {
  967. my $name = $args{'type'} . " " . $args{'struct'};
  968. print "\n\n.. c:type:: " . $name . "\n\n";
  969. } else {
  970. my $name = $args{'struct'};
  971. if ($args{'type'} eq 'union') {
  972. print "\n\n.. c:union:: " . $name . "\n\n";
  973. } else {
  974. print "\n\n.. c:struct:: " . $name . "\n\n";
  975. }
  976. }
  977. print_lineno($declaration_start_line);
  978. $lineprefix = " ";
  979. output_highlight_rst($args{'purpose'});
  980. print "\n";
  981. print "**Definition**\n\n";
  982. print "::\n\n";
  983. my $declaration = $args{'definition'};
  984. $declaration =~ s/\t/ /g;
  985. print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n";
  986. print "**Members**\n\n";
  987. $lineprefix = " ";
  988. foreach $parameter (@{$args{'parameterlist'}}) {
  989. ($parameter =~ /^#/) && next;
  990. my $parameter_name = $parameter;
  991. $parameter_name =~ s/\[.*//;
  992. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  993. $type = $args{'parametertypes'}{$parameter};
  994. print_lineno($parameterdesc_start_lines{$parameter_name});
  995. print "``" . $parameter . "``\n";
  996. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  997. print "\n";
  998. }
  999. print "\n";
  1000. $lineprefix = $oldprefix;
  1001. output_section_rst(@_);
  1002. }
  1003. ## none mode output functions
  1004. sub output_function_none(%) {
  1005. }
  1006. sub output_enum_none(%) {
  1007. }
  1008. sub output_typedef_none(%) {
  1009. }
  1010. sub output_struct_none(%) {
  1011. }
  1012. sub output_blockhead_none(%) {
  1013. }
  1014. ##
  1015. # generic output function for all types (function, struct/union, typedef, enum);
  1016. # calls the generated, variable output_ function name based on
  1017. # functype and output_mode
  1018. sub output_declaration {
  1019. no strict 'refs';
  1020. my $name = shift;
  1021. my $functype = shift;
  1022. my $func = "output_${functype}_$output_mode";
  1023. return if (defined($nosymbol_table{$name}));
  1024. if (($output_selection == OUTPUT_ALL) ||
  1025. (($output_selection == OUTPUT_INCLUDE ||
  1026. $output_selection == OUTPUT_EXPORTED) &&
  1027. defined($function_table{$name})) ||
  1028. ($output_selection == OUTPUT_INTERNAL &&
  1029. !($functype eq "function" && defined($function_table{$name}))))
  1030. {
  1031. &$func(@_);
  1032. $section_counter++;
  1033. }
  1034. }
  1035. ##
  1036. # generic output function - calls the right one based on current output mode.
  1037. sub output_blockhead {
  1038. no strict 'refs';
  1039. my $func = "output_blockhead_" . $output_mode;
  1040. &$func(@_);
  1041. $section_counter++;
  1042. }
  1043. ##
  1044. # takes a declaration (struct, union, enum, typedef) and
  1045. # invokes the right handler. NOT called for functions.
  1046. sub dump_declaration($$) {
  1047. no strict 'refs';
  1048. my ($prototype, $file) = @_;
  1049. my $func = "dump_" . $decl_type;
  1050. &$func(@_);
  1051. }
  1052. sub dump_union($$) {
  1053. dump_struct(@_);
  1054. }
  1055. sub dump_struct($$) {
  1056. my $x = shift;
  1057. my $file = shift;
  1058. if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
  1059. my $decl_type = $1;
  1060. $declaration_name = $2;
  1061. my $members = $3;
  1062. # ignore members marked private:
  1063. $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
  1064. $members =~ s/\/\*\s*private:.*//gosi;
  1065. # strip comments:
  1066. $members =~ s/\/\*.*?\*\///gos;
  1067. # strip attributes
  1068. $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi;
  1069. $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos;
  1070. $members =~ s/\s*__packed\s*/ /gos;
  1071. $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos;
  1072. $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;
  1073. $members =~ s/\s*____cacheline_aligned/ /gos;
  1074. # unwrap struct_group():
  1075. # - first eat non-declaration parameters and rewrite for final match
  1076. # - then remove macro, outer parens, and trailing semicolon
  1077. $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos;
  1078. $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos;
  1079. $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos;
  1080. $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos;
  1081. # replace DECLARE_BITMAP
  1082. $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos;
  1083. $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
  1084. # replace DECLARE_HASHTABLE
  1085. $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
  1086. # replace DECLARE_KFIFO
  1087. $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
  1088. # replace DECLARE_KFIFO_PTR
  1089. $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
  1090. # replace DECLARE_FLEX_ARRAY
  1091. $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\(([^,)]+),\s*([^,)]+)\)/$1 $2\[\]/gos;
  1092. my $declaration = $members;
  1093. # Split nested struct/union elements as newer ones
  1094. while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) {
  1095. my $newmember;
  1096. my $maintype = $1;
  1097. my $ids = $4;
  1098. my $content = $3;
  1099. foreach my $id(split /,/, $ids) {
  1100. $newmember .= "$maintype $id; ";
  1101. $id =~ s/[:\[].*//;
  1102. $id =~ s/^\s*\**(\S+)\s*/$1/;
  1103. foreach my $arg (split /;/, $content) {
  1104. next if ($arg =~ m/^\s*$/);
  1105. if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) {
  1106. # pointer-to-function
  1107. my $type = $1;
  1108. my $name = $2;
  1109. my $extra = $3;
  1110. next if (!$name);
  1111. if ($id =~ m/^\s*$/) {
  1112. # anonymous struct/union
  1113. $newmember .= "$type$name$extra; ";
  1114. } else {
  1115. $newmember .= "$type$id.$name$extra; ";
  1116. }
  1117. } else {
  1118. my $type;
  1119. my $names;
  1120. $arg =~ s/^\s+//;
  1121. $arg =~ s/\s+$//;
  1122. # Handle bitmaps
  1123. $arg =~ s/:\s*\d+\s*//g;
  1124. # Handle arrays
  1125. $arg =~ s/\[.*\]//g;
  1126. # The type may have multiple words,
  1127. # and multiple IDs can be defined, like:
  1128. # const struct foo, *bar, foobar
  1129. # So, we remove spaces when parsing the
  1130. # names, in order to match just names
  1131. # and commas for the names
  1132. $arg =~ s/\s*,\s*/,/g;
  1133. if ($arg =~ m/(.*)\s+([\S+,]+)/) {
  1134. $type = $1;
  1135. $names = $2;
  1136. } else {
  1137. $newmember .= "$arg; ";
  1138. next;
  1139. }
  1140. foreach my $name (split /,/, $names) {
  1141. $name =~ s/^\s*\**(\S+)\s*/$1/;
  1142. next if (($name =~ m/^\s*$/));
  1143. if ($id =~ m/^\s*$/) {
  1144. # anonymous struct/union
  1145. $newmember .= "$type $name; ";
  1146. } else {
  1147. $newmember .= "$type $id.$name; ";
  1148. }
  1149. }
  1150. }
  1151. }
  1152. }
  1153. $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/;
  1154. }
  1155. # Ignore other nested elements, like enums
  1156. $members =~ s/(\{[^\{\}]*\})//g;
  1157. create_parameterlist($members, ';', $file, $declaration_name);
  1158. check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
  1159. # Adjust declaration for better display
  1160. $declaration =~ s/([\{;])/$1\n/g;
  1161. $declaration =~ s/\}\s+;/};/g;
  1162. # Better handle inlined enums
  1163. do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);
  1164. my @def_args = split /\n/, $declaration;
  1165. my $level = 1;
  1166. $declaration = "";
  1167. foreach my $clause (@def_args) {
  1168. $clause =~ s/^\s+//;
  1169. $clause =~ s/\s+$//;
  1170. $clause =~ s/\s+/ /;
  1171. next if (!$clause);
  1172. $level-- if ($clause =~ m/(\})/ && $level > 1);
  1173. if (!($clause =~ m/^\s*#/)) {
  1174. $declaration .= "\t" x $level;
  1175. }
  1176. $declaration .= "\t" . $clause . "\n";
  1177. $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
  1178. }
  1179. output_declaration($declaration_name,
  1180. 'struct',
  1181. {'struct' => $declaration_name,
  1182. 'module' => $modulename,
  1183. 'definition' => $declaration,
  1184. 'parameterlist' => \@parameterlist,
  1185. 'parameterdescs' => \%parameterdescs,
  1186. 'parametertypes' => \%parametertypes,
  1187. 'sectionlist' => \@sectionlist,
  1188. 'sections' => \%sections,
  1189. 'purpose' => $declaration_purpose,
  1190. 'type' => $decl_type
  1191. });
  1192. }
  1193. else {
  1194. print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
  1195. ++$errors;
  1196. }
  1197. }
  1198. sub show_warnings($$) {
  1199. my $functype = shift;
  1200. my $name = shift;
  1201. return 0 if (defined($nosymbol_table{$name}));
  1202. return 1 if ($output_selection == OUTPUT_ALL);
  1203. if ($output_selection == OUTPUT_EXPORTED) {
  1204. if (defined($function_table{$name})) {
  1205. return 1;
  1206. } else {
  1207. return 0;
  1208. }
  1209. }
  1210. if ($output_selection == OUTPUT_INTERNAL) {
  1211. if (!($functype eq "function" && defined($function_table{$name}))) {
  1212. return 1;
  1213. } else {
  1214. return 0;
  1215. }
  1216. }
  1217. if ($output_selection == OUTPUT_INCLUDE) {
  1218. if (defined($function_table{$name})) {
  1219. return 1;
  1220. } else {
  1221. return 0;
  1222. }
  1223. }
  1224. die("Please add the new output type at show_warnings()");
  1225. }
  1226. sub dump_enum($$) {
  1227. my $x = shift;
  1228. my $file = shift;
  1229. my $members;
  1230. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1231. # strip #define macros inside enums
  1232. $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
  1233. if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) {
  1234. $declaration_name = $2;
  1235. $members = $1;
  1236. } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) {
  1237. $declaration_name = $1;
  1238. $members = $2;
  1239. }
  1240. if ($members) {
  1241. my %_members;
  1242. $members =~ s/\s+$//;
  1243. foreach my $arg (split ',', $members) {
  1244. $arg =~ s/^\s*(\w+).*/$1/;
  1245. push @parameterlist, $arg;
  1246. if (!$parameterdescs{$arg}) {
  1247. $parameterdescs{$arg} = $undescribed;
  1248. if (show_warnings("enum", $declaration_name)) {
  1249. print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n";
  1250. }
  1251. }
  1252. $_members{$arg} = 1;
  1253. }
  1254. while (my ($k, $v) = each %parameterdescs) {
  1255. if (!exists($_members{$k})) {
  1256. if (show_warnings("enum", $declaration_name)) {
  1257. print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n";
  1258. }
  1259. }
  1260. }
  1261. output_declaration($declaration_name,
  1262. 'enum',
  1263. {'enum' => $declaration_name,
  1264. 'module' => $modulename,
  1265. 'parameterlist' => \@parameterlist,
  1266. 'parameterdescs' => \%parameterdescs,
  1267. 'sectionlist' => \@sectionlist,
  1268. 'sections' => \%sections,
  1269. 'purpose' => $declaration_purpose
  1270. });
  1271. } else {
  1272. print STDERR "${file}:$.: error: Cannot parse enum!\n";
  1273. ++$errors;
  1274. }
  1275. }
  1276. my $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x;
  1277. my $typedef_ident = qr { \*?\s*(\w\S+)\s* }x;
  1278. my $typedef_args = qr { \s*\((.*)\); }x;
  1279. my $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x;
  1280. my $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x;
  1281. sub dump_typedef($$) {
  1282. my $x = shift;
  1283. my $file = shift;
  1284. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1285. # Parse function typedef prototypes
  1286. if ($x =~ $typedef1 || $x =~ $typedef2) {
  1287. $return_type = $1;
  1288. $declaration_name = $2;
  1289. my $args = $3;
  1290. $return_type =~ s/^\s+//;
  1291. create_parameterlist($args, ',', $file, $declaration_name);
  1292. output_declaration($declaration_name,
  1293. 'function',
  1294. {'function' => $declaration_name,
  1295. 'typedef' => 1,
  1296. 'module' => $modulename,
  1297. 'functiontype' => $return_type,
  1298. 'parameterlist' => \@parameterlist,
  1299. 'parameterdescs' => \%parameterdescs,
  1300. 'parametertypes' => \%parametertypes,
  1301. 'sectionlist' => \@sectionlist,
  1302. 'sections' => \%sections,
  1303. 'purpose' => $declaration_purpose
  1304. });
  1305. return;
  1306. }
  1307. while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
  1308. $x =~ s/\(*.\)\s*;$/;/;
  1309. $x =~ s/\[*.\]\s*;$/;/;
  1310. }
  1311. if ($x =~ /typedef.*\s+(\w+)\s*;/) {
  1312. $declaration_name = $1;
  1313. output_declaration($declaration_name,
  1314. 'typedef',
  1315. {'typedef' => $declaration_name,
  1316. 'module' => $modulename,
  1317. 'sectionlist' => \@sectionlist,
  1318. 'sections' => \%sections,
  1319. 'purpose' => $declaration_purpose
  1320. });
  1321. }
  1322. else {
  1323. print STDERR "${file}:$.: error: Cannot parse typedef!\n";
  1324. ++$errors;
  1325. }
  1326. }
  1327. sub save_struct_actual($) {
  1328. my $actual = shift;
  1329. # strip all spaces from the actual param so that it looks like one string item
  1330. $actual =~ s/\s*//g;
  1331. $struct_actual = $struct_actual . $actual . " ";
  1332. }
  1333. sub create_parameterlist($$$$) {
  1334. my $args = shift;
  1335. my $splitter = shift;
  1336. my $file = shift;
  1337. my $declaration_name = shift;
  1338. my $type;
  1339. my $param;
  1340. # temporarily replace commas inside function pointer definition
  1341. while ($args =~ /(\([^\),]+),/) {
  1342. $args =~ s/(\([^\),]+),/$1#/g;
  1343. }
  1344. foreach my $arg (split($splitter, $args)) {
  1345. # strip comments
  1346. $arg =~ s/\/\*.*\*\///;
  1347. # strip leading/trailing spaces
  1348. $arg =~ s/^\s*//;
  1349. $arg =~ s/\s*$//;
  1350. $arg =~ s/\s+/ /;
  1351. if ($arg =~ /^#/) {
  1352. # Treat preprocessor directive as a typeless variable just to fill
  1353. # corresponding data structures "correctly". Catch it later in
  1354. # output_* subs.
  1355. push_parameter($arg, "", "", $file);
  1356. } elsif ($arg =~ m/\(.+\)\s*\(/) {
  1357. # pointer-to-function
  1358. $arg =~ tr/#/,/;
  1359. $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/;
  1360. $param = $1;
  1361. $type = $arg;
  1362. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1363. save_struct_actual($param);
  1364. push_parameter($param, $type, $arg, $file, $declaration_name);
  1365. } elsif ($arg) {
  1366. $arg =~ s/\s*:\s*/:/g;
  1367. $arg =~ s/\s*\[/\[/g;
  1368. my @args = split('\s*,\s*', $arg);
  1369. if ($args[0] =~ m/\*/) {
  1370. $args[0] =~ s/(\*+)\s*/ $1/;
  1371. }
  1372. my @first_arg;
  1373. if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
  1374. shift @args;
  1375. push(@first_arg, split('\s+', $1));
  1376. push(@first_arg, $2);
  1377. } else {
  1378. @first_arg = split('\s+', shift @args);
  1379. }
  1380. unshift(@args, pop @first_arg);
  1381. $type = join " ", @first_arg;
  1382. foreach $param (@args) {
  1383. if ($param =~ m/^(\*+)\s*(.*)/) {
  1384. save_struct_actual($2);
  1385. push_parameter($2, "$type $1", $arg, $file, $declaration_name);
  1386. }
  1387. elsif ($param =~ m/(.*?):(\d+)/) {
  1388. if ($type ne "") { # skip unnamed bit-fields
  1389. save_struct_actual($1);
  1390. push_parameter($1, "$type:$2", $arg, $file, $declaration_name)
  1391. }
  1392. }
  1393. else {
  1394. save_struct_actual($param);
  1395. push_parameter($param, $type, $arg, $file, $declaration_name);
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. sub push_parameter($$$$$) {
  1402. my $param = shift;
  1403. my $type = shift;
  1404. my $org_arg = shift;
  1405. my $file = shift;
  1406. my $declaration_name = shift;
  1407. if (($anon_struct_union == 1) && ($type eq "") &&
  1408. ($param eq "}")) {
  1409. return; # ignore the ending }; from anon. struct/union
  1410. }
  1411. $anon_struct_union = 0;
  1412. $param =~ s/[\[\)].*//;
  1413. if ($type eq "" && $param =~ /\.\.\.$/)
  1414. {
  1415. if (!$param =~ /\w\.\.\.$/) {
  1416. # handles unnamed variable parameters
  1417. $param = "...";
  1418. }
  1419. elsif ($param =~ /\w\.\.\.$/) {
  1420. # for named variable parameters of the form `x...`, remove the dots
  1421. $param =~ s/\.\.\.$//;
  1422. }
  1423. if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
  1424. $parameterdescs{$param} = "variable arguments";
  1425. }
  1426. }
  1427. elsif ($type eq "" && ($param eq "" or $param eq "void"))
  1428. {
  1429. $param="void";
  1430. $parameterdescs{void} = "no arguments";
  1431. }
  1432. elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
  1433. # handle unnamed (anonymous) union or struct:
  1434. {
  1435. $type = $param;
  1436. $param = "{unnamed_" . $param . "}";
  1437. $parameterdescs{$param} = "anonymous\n";
  1438. $anon_struct_union = 1;
  1439. }
  1440. # warn if parameter has no description
  1441. # (but ignore ones starting with # as these are not parameters
  1442. # but inline preprocessor statements);
  1443. # Note: It will also ignore void params and unnamed structs/unions
  1444. if (!defined $parameterdescs{$param} && $param !~ /^#/) {
  1445. $parameterdescs{$param} = $undescribed;
  1446. if (show_warnings($type, $declaration_name) && $param !~ /\./) {
  1447. print STDERR
  1448. "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n";
  1449. ++$warnings;
  1450. }
  1451. }
  1452. # strip spaces from $param so that it is one continuous string
  1453. # on @parameterlist;
  1454. # this fixes a problem where check_sections() cannot find
  1455. # a parameter like "addr[6 + 2]" because it actually appears
  1456. # as "addr[6", "+", "2]" on the parameter list;
  1457. # but it's better to maintain the param string unchanged for output,
  1458. # so just weaken the string compare in check_sections() to ignore
  1459. # "[blah" in a parameter string;
  1460. ###$param =~ s/\s*//g;
  1461. push @parameterlist, $param;
  1462. $org_arg =~ s/\s\s+/ /g;
  1463. $parametertypes{$param} = $org_arg;
  1464. }
  1465. sub check_sections($$$$$) {
  1466. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_;
  1467. my @sects = split ' ', $sectcheck;
  1468. my @prms = split ' ', $prmscheck;
  1469. my $err;
  1470. my ($px, $sx);
  1471. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  1472. foreach $sx (0 .. $#sects) {
  1473. $err = 1;
  1474. foreach $px (0 .. $#prms) {
  1475. $prm_clean = $prms[$px];
  1476. $prm_clean =~ s/\[.*\]//;
  1477. $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  1478. # ignore array size in a parameter string;
  1479. # however, the original param string may contain
  1480. # spaces, e.g.: addr[6 + 2]
  1481. # and this appears in @prms as "addr[6" since the
  1482. # parameter list is split at spaces;
  1483. # hence just ignore "[..." for the sections check;
  1484. $prm_clean =~ s/\[.*//;
  1485. ##$prm_clean =~ s/^\**//;
  1486. if ($prm_clean eq $sects[$sx]) {
  1487. $err = 0;
  1488. last;
  1489. }
  1490. }
  1491. if ($err) {
  1492. if ($decl_type eq "function") {
  1493. print STDERR "${file}:$.: warning: " .
  1494. "Excess function parameter " .
  1495. "'$sects[$sx]' " .
  1496. "description in '$decl_name'\n";
  1497. ++$warnings;
  1498. }
  1499. }
  1500. }
  1501. }
  1502. ##
  1503. # Checks the section describing the return value of a function.
  1504. sub check_return_section {
  1505. my $file = shift;
  1506. my $declaration_name = shift;
  1507. my $return_type = shift;
  1508. # Ignore an empty return type (It's a macro)
  1509. # Ignore functions with a "void" return type. (But don't ignore "void *")
  1510. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  1511. return;
  1512. }
  1513. if (!defined($sections{$section_return}) ||
  1514. $sections{$section_return} eq "") {
  1515. print STDERR "${file}:$.: warning: " .
  1516. "No description found for return value of " .
  1517. "'$declaration_name'\n";
  1518. ++$warnings;
  1519. }
  1520. }
  1521. ##
  1522. # takes a function prototype and the name of the current file being
  1523. # processed and spits out all the details stored in the global
  1524. # arrays/hashes.
  1525. sub dump_function($$) {
  1526. my $prototype = shift;
  1527. my $file = shift;
  1528. my $noret = 0;
  1529. print_lineno($new_start_line);
  1530. $prototype =~ s/^static +//;
  1531. $prototype =~ s/^extern +//;
  1532. $prototype =~ s/^asmlinkage +//;
  1533. $prototype =~ s/^inline +//;
  1534. $prototype =~ s/^__inline__ +//;
  1535. $prototype =~ s/^__inline +//;
  1536. $prototype =~ s/^__always_inline +//;
  1537. $prototype =~ s/^noinline +//;
  1538. $prototype =~ s/__init +//;
  1539. $prototype =~ s/__init_or_module +//;
  1540. $prototype =~ s/__meminit +//;
  1541. $prototype =~ s/__must_check +//;
  1542. $prototype =~ s/__weak +//;
  1543. $prototype =~ s/__sched +//;
  1544. $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
  1545. my $define = $prototype =~ s/^#\s*define\s+//; #ak added
  1546. $prototype =~ s/__attribute__\s*\(\(
  1547. (?:
  1548. [\w\s]++ # attribute name
  1549. (?:\([^)]*+\))? # attribute arguments
  1550. \s*+,? # optional comma at the end
  1551. )+
  1552. \)\)\s+//x;
  1553. # Yes, this truly is vile. We are looking for:
  1554. # 1. Return type (may be nothing if we're looking at a macro)
  1555. # 2. Function name
  1556. # 3. Function parameters.
  1557. #
  1558. # All the while we have to watch out for function pointer parameters
  1559. # (which IIRC is what the two sections are for), C types (these
  1560. # regexps don't even start to express all the possibilities), and
  1561. # so on.
  1562. #
  1563. # If you mess with these regexps, it's a good idea to check that
  1564. # the following functions' documentation still comes out right:
  1565. # - parport_register_device (function pointer parameters)
  1566. # - atomic_set (macro)
  1567. # - pci_match_device, __copy_to_user (long return type)
  1568. if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
  1569. # This is an object-like macro, it has no return type and no parameter
  1570. # list.
  1571. # Function-like macros are not allowed to have spaces between
  1572. # declaration_name and opening parenthesis (notice the \s+).
  1573. $return_type = $1;
  1574. $declaration_name = $2;
  1575. $noret = 1;
  1576. } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1577. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1578. $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1579. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1580. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1581. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1582. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1583. $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1584. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1585. $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1586. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1587. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1588. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1589. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1590. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1591. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1592. $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  1593. $return_type = $1;
  1594. $declaration_name = $2;
  1595. my $args = $3;
  1596. create_parameterlist($args, ',', $file, $declaration_name);
  1597. } else {
  1598. print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
  1599. return;
  1600. }
  1601. my $prms = join " ", @parameterlist;
  1602. check_sections($file, $declaration_name, "function", $sectcheck, $prms);
  1603. # This check emits a lot of warnings at the moment, because many
  1604. # functions don't have a 'Return' doc section. So until the number
  1605. # of warnings goes sufficiently down, the check is only performed in
  1606. # verbose mode.
  1607. # TODO: always perform the check.
  1608. if ($verbose && !$noret) {
  1609. check_return_section($file, $declaration_name, $return_type);
  1610. }
  1611. # The function parser can be called with a typedef parameter.
  1612. # Handle it.
  1613. if ($return_type =~ /typedef/) {
  1614. output_declaration($declaration_name,
  1615. 'function',
  1616. {'function' => $declaration_name,
  1617. 'typedef' => 1,
  1618. 'module' => $modulename,
  1619. 'functiontype' => $return_type,
  1620. 'parameterlist' => \@parameterlist,
  1621. 'parameterdescs' => \%parameterdescs,
  1622. 'parametertypes' => \%parametertypes,
  1623. 'sectionlist' => \@sectionlist,
  1624. 'sections' => \%sections,
  1625. 'purpose' => $declaration_purpose
  1626. });
  1627. } else {
  1628. output_declaration($declaration_name,
  1629. 'function',
  1630. {'function' => $declaration_name,
  1631. 'module' => $modulename,
  1632. 'functiontype' => $return_type,
  1633. 'parameterlist' => \@parameterlist,
  1634. 'parameterdescs' => \%parameterdescs,
  1635. 'parametertypes' => \%parametertypes,
  1636. 'sectionlist' => \@sectionlist,
  1637. 'sections' => \%sections,
  1638. 'purpose' => $declaration_purpose
  1639. });
  1640. }
  1641. }
  1642. sub reset_state {
  1643. $function = "";
  1644. %parameterdescs = ();
  1645. %parametertypes = ();
  1646. @parameterlist = ();
  1647. %sections = ();
  1648. @sectionlist = ();
  1649. $sectcheck = "";
  1650. $struct_actual = "";
  1651. $prototype = "";
  1652. $state = STATE_NORMAL;
  1653. $inline_doc_state = STATE_INLINE_NA;
  1654. }
  1655. sub tracepoint_munge($) {
  1656. my $file = shift;
  1657. my $tracepointname = 0;
  1658. my $tracepointargs = 0;
  1659. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  1660. $tracepointname = $1;
  1661. }
  1662. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  1663. $tracepointname = $1;
  1664. }
  1665. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  1666. $tracepointname = $2;
  1667. }
  1668. $tracepointname =~ s/^\s+//; #strip leading whitespace
  1669. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  1670. $tracepointargs = $1;
  1671. }
  1672. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  1673. print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
  1674. "$prototype\n";
  1675. } else {
  1676. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  1677. }
  1678. }
  1679. sub syscall_munge() {
  1680. my $void = 0;
  1681. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's
  1682. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  1683. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  1684. $void = 1;
  1685. ## $prototype = "long sys_$1(void)";
  1686. }
  1687. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  1688. if ($prototype =~ m/long (sys_.*?),/) {
  1689. $prototype =~ s/,/\(/;
  1690. } elsif ($void) {
  1691. $prototype =~ s/\)/\(void\)/;
  1692. }
  1693. # now delete all of the odd-number commas in $prototype
  1694. # so that arg types & arg names don't have a comma between them
  1695. my $count = 0;
  1696. my $len = length($prototype);
  1697. if ($void) {
  1698. $len = 0; # skip the for-loop
  1699. }
  1700. for (my $ix = 0; $ix < $len; $ix++) {
  1701. if (substr($prototype, $ix, 1) eq ',') {
  1702. $count++;
  1703. if ($count % 2 == 1) {
  1704. substr($prototype, $ix, 1) = ' ';
  1705. }
  1706. }
  1707. }
  1708. }
  1709. sub process_proto_function($$) {
  1710. my $x = shift;
  1711. my $file = shift;
  1712. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1713. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  1714. # do nothing
  1715. }
  1716. elsif ($x =~ /([^\{]*)/) {
  1717. $prototype .= $1;
  1718. }
  1719. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  1720. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  1721. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1722. $prototype =~ s@^\s+@@gos; # strip leading spaces
  1723. # Handle prototypes for function pointers like:
  1724. # int (*pcs_config)(struct foo)
  1725. $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos;
  1726. if ($prototype =~ /SYSCALL_DEFINE/) {
  1727. syscall_munge();
  1728. }
  1729. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  1730. $prototype =~ /DEFINE_SINGLE_EVENT/)
  1731. {
  1732. tracepoint_munge($file);
  1733. }
  1734. dump_function($prototype, $file);
  1735. reset_state();
  1736. }
  1737. }
  1738. sub process_proto_type($$) {
  1739. my $x = shift;
  1740. my $file = shift;
  1741. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1742. $x =~ s@^\s+@@gos; # strip leading spaces
  1743. $x =~ s@\s+$@@gos; # strip trailing spaces
  1744. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1745. if ($x =~ /^#/) {
  1746. # To distinguish preprocessor directive from regular declaration later.
  1747. $x .= ";";
  1748. }
  1749. while (1) {
  1750. if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
  1751. if( length $prototype ) {
  1752. $prototype .= " "
  1753. }
  1754. $prototype .= $1 . $2;
  1755. ($2 eq '{') && $brcount++;
  1756. ($2 eq '}') && $brcount--;
  1757. if (($2 eq ';') && ($brcount == 0)) {
  1758. dump_declaration($prototype, $file);
  1759. reset_state();
  1760. last;
  1761. }
  1762. $x = $3;
  1763. } else {
  1764. $prototype .= $x;
  1765. last;
  1766. }
  1767. }
  1768. }
  1769. sub map_filename($) {
  1770. my $file;
  1771. my ($orig_file) = @_;
  1772. if (defined($ENV{'SRCTREE'})) {
  1773. $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
  1774. } else {
  1775. $file = $orig_file;
  1776. }
  1777. if (defined($source_map{$file})) {
  1778. $file = $source_map{$file};
  1779. }
  1780. return $file;
  1781. }
  1782. sub process_export_file($) {
  1783. my ($orig_file) = @_;
  1784. my $file = map_filename($orig_file);
  1785. if (!open(IN,"<$file")) {
  1786. print STDERR "Error: Cannot open file $file\n";
  1787. ++$errors;
  1788. return;
  1789. }
  1790. while (<IN>) {
  1791. if (/$export_symbol/) {
  1792. next if (defined($nosymbol_table{$2}));
  1793. $function_table{$2} = 1;
  1794. }
  1795. }
  1796. close(IN);
  1797. }
  1798. #
  1799. # Parsers for the various processing states.
  1800. #
  1801. # STATE_NORMAL: looking for the /** to begin everything.
  1802. #
  1803. sub process_normal() {
  1804. if (/$doc_start/o) {
  1805. $state = STATE_NAME; # next line is always the function name
  1806. $in_doc_sect = 0;
  1807. $declaration_start_line = $. + 1;
  1808. }
  1809. }
  1810. #
  1811. # STATE_NAME: Looking for the "name - description" line
  1812. #
  1813. sub process_name($$) {
  1814. my $file = shift;
  1815. my $identifier;
  1816. my $descr;
  1817. if (/$doc_block/o) {
  1818. $state = STATE_DOCBLOCK;
  1819. $contents = "";
  1820. $new_start_line = $.;
  1821. if ( $1 eq "" ) {
  1822. $section = $section_intro;
  1823. } else {
  1824. $section = $1;
  1825. }
  1826. }
  1827. elsif (/$doc_decl/o) {
  1828. $identifier = $1;
  1829. if (/\s*([\w\s]+?)(\(\))?\s*-/) {
  1830. $identifier = $1;
  1831. }
  1832. $state = STATE_BODY;
  1833. # if there's no @param blocks need to set up default section
  1834. # here
  1835. $contents = "";
  1836. $section = $section_default;
  1837. $new_start_line = $. + 1;
  1838. if (/-(.*)/) {
  1839. # strip leading/trailing/multiple spaces
  1840. $descr= $1;
  1841. $descr =~ s/^\s*//;
  1842. $descr =~ s/\s*$//;
  1843. $descr =~ s/\s+/ /g;
  1844. $declaration_purpose = $descr;
  1845. $state = STATE_BODY_MAYBE;
  1846. } else {
  1847. $declaration_purpose = "";
  1848. }
  1849. if (($declaration_purpose eq "") && $verbose) {
  1850. print STDERR "${file}:$.: warning: missing initial short description on line:\n";
  1851. print STDERR $_;
  1852. ++$warnings;
  1853. }
  1854. if ($identifier =~ m/^struct\b/) {
  1855. $decl_type = 'struct';
  1856. } elsif ($identifier =~ m/^union\b/) {
  1857. $decl_type = 'union';
  1858. } elsif ($identifier =~ m/^enum\b/) {
  1859. $decl_type = 'enum';
  1860. } elsif ($identifier =~ m/^typedef\b/) {
  1861. $decl_type = 'typedef';
  1862. } else {
  1863. $decl_type = 'function';
  1864. }
  1865. if ($verbose) {
  1866. print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
  1867. }
  1868. } else {
  1869. print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
  1870. " - I thought it was a doc line\n";
  1871. ++$warnings;
  1872. $state = STATE_NORMAL;
  1873. }
  1874. }
  1875. #
  1876. # STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment.
  1877. #
  1878. sub process_body($$) {
  1879. my $file = shift;
  1880. # Until all named variable macro parameters are
  1881. # documented using the bare name (`x`) rather than with
  1882. # dots (`x...`), strip the dots:
  1883. if ($section =~ /\w\.\.\.$/) {
  1884. $section =~ s/\.\.\.$//;
  1885. if ($verbose) {
  1886. print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n";
  1887. ++$warnings;
  1888. }
  1889. }
  1890. if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) {
  1891. dump_section($file, $section, $contents);
  1892. $section = $section_default;
  1893. $new_start_line = $.;
  1894. $contents = "";
  1895. }
  1896. if (/$doc_sect/i) { # case insensitive for supported section names
  1897. $newsection = $1;
  1898. $newcontents = $2;
  1899. # map the supported section names to the canonical names
  1900. if ($newsection =~ m/^description$/i) {
  1901. $newsection = $section_default;
  1902. } elsif ($newsection =~ m/^context$/i) {
  1903. $newsection = $section_context;
  1904. } elsif ($newsection =~ m/^returns?$/i) {
  1905. $newsection = $section_return;
  1906. } elsif ($newsection =~ m/^\@return$/) {
  1907. # special: @return is a section, not a param description
  1908. $newsection = $section_return;
  1909. }
  1910. if (($contents ne "") && ($contents ne "\n")) {
  1911. if (!$in_doc_sect && $verbose) {
  1912. print STDERR "${file}:$.: warning: contents before sections\n";
  1913. ++$warnings;
  1914. }
  1915. dump_section($file, $section, $contents);
  1916. $section = $section_default;
  1917. }
  1918. $in_doc_sect = 1;
  1919. $state = STATE_BODY;
  1920. $contents = $newcontents;
  1921. $new_start_line = $.;
  1922. while (substr($contents, 0, 1) eq " ") {
  1923. $contents = substr($contents, 1);
  1924. }
  1925. if ($contents ne "") {
  1926. $contents .= "\n";
  1927. }
  1928. $section = $newsection;
  1929. $leading_space = undef;
  1930. } elsif (/$doc_end/) {
  1931. if (($contents ne "") && ($contents ne "\n")) {
  1932. dump_section($file, $section, $contents);
  1933. $section = $section_default;
  1934. $contents = "";
  1935. }
  1936. # look for doc_com + <text> + doc_end:
  1937. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  1938. print STDERR "${file}:$.: warning: suspicious ending line: $_";
  1939. ++$warnings;
  1940. }
  1941. $prototype = "";
  1942. $state = STATE_PROTO;
  1943. $brcount = 0;
  1944. $new_start_line = $. + 1;
  1945. } elsif (/$doc_content/) {
  1946. if ($1 eq "") {
  1947. if ($section eq $section_context) {
  1948. dump_section($file, $section, $contents);
  1949. $section = $section_default;
  1950. $contents = "";
  1951. $new_start_line = $.;
  1952. $state = STATE_BODY;
  1953. } else {
  1954. if ($section ne $section_default) {
  1955. $state = STATE_BODY_WITH_BLANK_LINE;
  1956. } else {
  1957. $state = STATE_BODY;
  1958. }
  1959. $contents .= "\n";
  1960. }
  1961. } elsif ($state == STATE_BODY_MAYBE) {
  1962. # Continued declaration purpose
  1963. chomp($declaration_purpose);
  1964. $declaration_purpose .= " " . $1;
  1965. $declaration_purpose =~ s/\s+/ /g;
  1966. } else {
  1967. my $cont = $1;
  1968. if ($section =~ m/^@/ || $section eq $section_context) {
  1969. if (!defined $leading_space) {
  1970. if ($cont =~ m/^(\s+)/) {
  1971. $leading_space = $1;
  1972. } else {
  1973. $leading_space = "";
  1974. }
  1975. }
  1976. $cont =~ s/^$leading_space//;
  1977. }
  1978. $contents .= $cont . "\n";
  1979. }
  1980. } else {
  1981. # i dont know - bad line? ignore.
  1982. print STDERR "${file}:$.: warning: bad line: $_";
  1983. ++$warnings;
  1984. }
  1985. }
  1986. #
  1987. # STATE_PROTO: reading a function/whatever prototype.
  1988. #
  1989. sub process_proto($$) {
  1990. my $file = shift;
  1991. if (/$doc_inline_oneline/) {
  1992. $section = $1;
  1993. $contents = $2;
  1994. if ($contents ne "") {
  1995. $contents .= "\n";
  1996. dump_section($file, $section, $contents);
  1997. $section = $section_default;
  1998. $contents = "";
  1999. }
  2000. } elsif (/$doc_inline_start/) {
  2001. $state = STATE_INLINE;
  2002. $inline_doc_state = STATE_INLINE_NAME;
  2003. } elsif ($decl_type eq 'function') {
  2004. process_proto_function($_, $file);
  2005. } else {
  2006. process_proto_type($_, $file);
  2007. }
  2008. }
  2009. #
  2010. # STATE_DOCBLOCK: within a DOC: block.
  2011. #
  2012. sub process_docblock($$) {
  2013. my $file = shift;
  2014. if (/$doc_end/) {
  2015. dump_doc_section($file, $section, $contents);
  2016. $section = $section_default;
  2017. $contents = "";
  2018. $function = "";
  2019. %parameterdescs = ();
  2020. %parametertypes = ();
  2021. @parameterlist = ();
  2022. %sections = ();
  2023. @sectionlist = ();
  2024. $prototype = "";
  2025. $state = STATE_NORMAL;
  2026. } elsif (/$doc_content/) {
  2027. if ( $1 eq "" ) {
  2028. $contents .= $blankline;
  2029. } else {
  2030. $contents .= $1 . "\n";
  2031. }
  2032. }
  2033. }
  2034. #
  2035. # STATE_INLINE: docbook comments within a prototype.
  2036. #
  2037. sub process_inline($$) {
  2038. my $file = shift;
  2039. # First line (state 1) needs to be a @parameter
  2040. if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
  2041. $section = $1;
  2042. $contents = $2;
  2043. $new_start_line = $.;
  2044. if ($contents ne "") {
  2045. while (substr($contents, 0, 1) eq " ") {
  2046. $contents = substr($contents, 1);
  2047. }
  2048. $contents .= "\n";
  2049. }
  2050. $inline_doc_state = STATE_INLINE_TEXT;
  2051. # Documentation block end */
  2052. } elsif (/$doc_inline_end/) {
  2053. if (($contents ne "") && ($contents ne "\n")) {
  2054. dump_section($file, $section, $contents);
  2055. $section = $section_default;
  2056. $contents = "";
  2057. }
  2058. $state = STATE_PROTO;
  2059. $inline_doc_state = STATE_INLINE_NA;
  2060. # Regular text
  2061. } elsif (/$doc_content/) {
  2062. if ($inline_doc_state == STATE_INLINE_TEXT) {
  2063. $contents .= $1 . "\n";
  2064. # nuke leading blank lines
  2065. if ($contents =~ /^\s*$/) {
  2066. $contents = "";
  2067. }
  2068. } elsif ($inline_doc_state == STATE_INLINE_NAME) {
  2069. $inline_doc_state = STATE_INLINE_ERROR;
  2070. print STDERR "${file}:$.: warning: ";
  2071. print STDERR "Incorrect use of kernel-doc format: $_";
  2072. ++$warnings;
  2073. }
  2074. }
  2075. }
  2076. sub process_file($) {
  2077. my $file;
  2078. my $initial_section_counter = $section_counter;
  2079. my ($orig_file) = @_;
  2080. $file = map_filename($orig_file);
  2081. if (!open(IN_FILE,"<$file")) {
  2082. print STDERR "Error: Cannot open file $file\n";
  2083. ++$errors;
  2084. return;
  2085. }
  2086. $. = 1;
  2087. $section_counter = 0;
  2088. while (<IN_FILE>) {
  2089. while (s/\\\s*$//) {
  2090. $_ .= <IN_FILE>;
  2091. }
  2092. # Replace tabs by spaces
  2093. while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
  2094. # Hand this line to the appropriate state handler
  2095. if ($state == STATE_NORMAL) {
  2096. process_normal();
  2097. } elsif ($state == STATE_NAME) {
  2098. process_name($file, $_);
  2099. } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE ||
  2100. $state == STATE_BODY_WITH_BLANK_LINE) {
  2101. process_body($file, $_);
  2102. } elsif ($state == STATE_INLINE) { # scanning for inline parameters
  2103. process_inline($file, $_);
  2104. } elsif ($state == STATE_PROTO) {
  2105. process_proto($file, $_);
  2106. } elsif ($state == STATE_DOCBLOCK) {
  2107. process_docblock($file, $_);
  2108. }
  2109. }
  2110. # Make sure we got something interesting.
  2111. if ($initial_section_counter == $section_counter && $
  2112. output_mode ne "none") {
  2113. if ($output_selection == OUTPUT_INCLUDE) {
  2114. print STDERR "${file}:1: warning: '$_' not found\n"
  2115. for keys %function_table;
  2116. }
  2117. else {
  2118. print STDERR "${file}:1: warning: no structured comments found\n";
  2119. }
  2120. }
  2121. close IN_FILE;
  2122. }
  2123. if ($output_mode eq "rst") {
  2124. get_sphinx_version() if (!$sphinx_major);
  2125. }
  2126. $kernelversion = get_kernel_version();
  2127. # generate a sequence of code that will splice in highlighting information
  2128. # using the s// operator.
  2129. for (my $k = 0; $k < @highlights; $k++) {
  2130. my $pattern = $highlights[$k][0];
  2131. my $result = $highlights[$k][1];
  2132. # print STDERR "scanning pattern:$pattern, highlight:($result)\n";
  2133. $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
  2134. }
  2135. # Read the file that maps relative names to absolute names for
  2136. # separate source and object directories and for shadow trees.
  2137. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2138. my ($relname, $absname);
  2139. while(<SOURCE_MAP>) {
  2140. chop();
  2141. ($relname, $absname) = (split())[0..1];
  2142. $relname =~ s:^/+::;
  2143. $source_map{$relname} = $absname;
  2144. }
  2145. close(SOURCE_MAP);
  2146. }
  2147. if ($output_selection == OUTPUT_EXPORTED ||
  2148. $output_selection == OUTPUT_INTERNAL) {
  2149. push(@export_file_list, @ARGV);
  2150. foreach (@export_file_list) {
  2151. chomp;
  2152. process_export_file($_);
  2153. }
  2154. }
  2155. foreach (@ARGV) {
  2156. chomp;
  2157. process_file($_);
  2158. }
  2159. if ($verbose && $errors) {
  2160. print STDERR "$errors errors\n";
  2161. }
  2162. if ($verbose && $warnings) {
  2163. print STDERR "$warnings warnings\n";
  2164. }
  2165. if ($Werror && $warnings) {
  2166. print STDERR "$warnings warnings as Errors\n";
  2167. exit($warnings);
  2168. } else {
  2169. exit($output_mode eq "none" ? 0 : $errors)
  2170. }