kernel-doc 88 KB

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