kernel-doc 87 KB

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