kernel-doc 84 KB

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