kernel-doc 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163
  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. $type =~ s/\s\s+/ /g;
  2124. $parametertypes{$param} = $type;
  2125. }
  2126. sub check_sections($$$$$$) {
  2127. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
  2128. my @sects = split ' ', $sectcheck;
  2129. my @prms = split ' ', $prmscheck;
  2130. my $err;
  2131. my ($px, $sx);
  2132. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  2133. foreach $sx (0 .. $#sects) {
  2134. $err = 1;
  2135. foreach $px (0 .. $#prms) {
  2136. $prm_clean = $prms[$px];
  2137. $prm_clean =~ s/\[.*\]//;
  2138. $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  2139. # ignore array size in a parameter string;
  2140. # however, the original param string may contain
  2141. # spaces, e.g.: addr[6 + 2]
  2142. # and this appears in @prms as "addr[6" since the
  2143. # parameter list is split at spaces;
  2144. # hence just ignore "[..." for the sections check;
  2145. $prm_clean =~ s/\[.*//;
  2146. ##$prm_clean =~ s/^\**//;
  2147. if ($prm_clean eq $sects[$sx]) {
  2148. $err = 0;
  2149. last;
  2150. }
  2151. }
  2152. if ($err) {
  2153. if ($decl_type eq "function") {
  2154. print STDERR "${file}:$.: warning: " .
  2155. "Excess function parameter " .
  2156. "'$sects[$sx]' " .
  2157. "description in '$decl_name'\n";
  2158. ++$warnings;
  2159. } else {
  2160. if ($nested !~ m/\Q$sects[$sx]\E/) {
  2161. print STDERR "${file}:$.: warning: " .
  2162. "Excess struct/union/enum/typedef member " .
  2163. "'$sects[$sx]' " .
  2164. "description in '$decl_name'\n";
  2165. ++$warnings;
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. ##
  2172. # Checks the section describing the return value of a function.
  2173. sub check_return_section {
  2174. my $file = shift;
  2175. my $declaration_name = shift;
  2176. my $return_type = shift;
  2177. # Ignore an empty return type (It's a macro)
  2178. # Ignore functions with a "void" return type. (But don't ignore "void *")
  2179. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  2180. return;
  2181. }
  2182. if (!defined($sections{$section_return}) ||
  2183. $sections{$section_return} eq "") {
  2184. print STDERR "${file}:$.: warning: " .
  2185. "No description found for return value of " .
  2186. "'$declaration_name'\n";
  2187. ++$warnings;
  2188. }
  2189. }
  2190. ##
  2191. # takes a function prototype and the name of the current file being
  2192. # processed and spits out all the details stored in the global
  2193. # arrays/hashes.
  2194. sub dump_function($$) {
  2195. my $prototype = shift;
  2196. my $file = shift;
  2197. my $noret = 0;
  2198. $prototype =~ s/^static +//;
  2199. $prototype =~ s/^extern +//;
  2200. $prototype =~ s/^asmlinkage +//;
  2201. $prototype =~ s/^inline +//;
  2202. $prototype =~ s/^__inline__ +//;
  2203. $prototype =~ s/^__inline +//;
  2204. $prototype =~ s/^__always_inline +//;
  2205. $prototype =~ s/^noinline +//;
  2206. $prototype =~ s/__init +//;
  2207. $prototype =~ s/__init_or_module +//;
  2208. $prototype =~ s/__meminit +//;
  2209. $prototype =~ s/__must_check +//;
  2210. $prototype =~ s/__weak +//;
  2211. my $define = $prototype =~ s/^#\s*define\s+//; #ak added
  2212. $prototype =~ s/__attribute__\s*\(\(
  2213. (?:
  2214. [\w\s]++ # attribute name
  2215. (?:\([^)]*+\))? # attribute arguments
  2216. \s*+,? # optional comma at the end
  2217. )+
  2218. \)\)\s+//x;
  2219. # Yes, this truly is vile. We are looking for:
  2220. # 1. Return type (may be nothing if we're looking at a macro)
  2221. # 2. Function name
  2222. # 3. Function parameters.
  2223. #
  2224. # All the while we have to watch out for function pointer parameters
  2225. # (which IIRC is what the two sections are for), C types (these
  2226. # regexps don't even start to express all the possibilities), and
  2227. # so on.
  2228. #
  2229. # If you mess with these regexps, it's a good idea to check that
  2230. # the following functions' documentation still comes out right:
  2231. # - parport_register_device (function pointer parameters)
  2232. # - atomic_set (macro)
  2233. # - pci_match_device, __copy_to_user (long return type)
  2234. if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
  2235. # This is an object-like macro, it has no return type and no parameter
  2236. # list.
  2237. # Function-like macros are not allowed to have spaces between
  2238. # declaration_name and opening parenthesis (notice the \s+).
  2239. $return_type = $1;
  2240. $declaration_name = $2;
  2241. $noret = 1;
  2242. } elsif ($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/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2250. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2251. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2252. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2253. $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2254. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2255. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2256. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2257. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2258. $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  2259. $return_type = $1;
  2260. $declaration_name = $2;
  2261. my $args = $3;
  2262. create_parameterlist($args, ',', $file);
  2263. } else {
  2264. print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
  2265. return;
  2266. }
  2267. my $prms = join " ", @parameterlist;
  2268. check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
  2269. # This check emits a lot of warnings at the moment, because many
  2270. # functions don't have a 'Return' doc section. So until the number
  2271. # of warnings goes sufficiently down, the check is only performed in
  2272. # verbose mode.
  2273. # TODO: always perform the check.
  2274. if ($verbose && !$noret) {
  2275. check_return_section($file, $declaration_name, $return_type);
  2276. }
  2277. output_declaration($declaration_name,
  2278. 'function',
  2279. {'function' => $declaration_name,
  2280. 'module' => $modulename,
  2281. 'functiontype' => $return_type,
  2282. 'parameterlist' => \@parameterlist,
  2283. 'parameterdescs' => \%parameterdescs,
  2284. 'parametertypes' => \%parametertypes,
  2285. 'sectionlist' => \@sectionlist,
  2286. 'sections' => \%sections,
  2287. 'purpose' => $declaration_purpose
  2288. });
  2289. }
  2290. sub reset_state {
  2291. $function = "";
  2292. %parameterdescs = ();
  2293. %parametertypes = ();
  2294. @parameterlist = ();
  2295. %sections = ();
  2296. @sectionlist = ();
  2297. $sectcheck = "";
  2298. $struct_actual = "";
  2299. $prototype = "";
  2300. $state = STATE_NORMAL;
  2301. $inline_doc_state = STATE_INLINE_NA;
  2302. }
  2303. sub tracepoint_munge($) {
  2304. my $file = shift;
  2305. my $tracepointname = 0;
  2306. my $tracepointargs = 0;
  2307. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  2308. $tracepointname = $1;
  2309. }
  2310. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  2311. $tracepointname = $1;
  2312. }
  2313. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  2314. $tracepointname = $2;
  2315. }
  2316. $tracepointname =~ s/^\s+//; #strip leading whitespace
  2317. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  2318. $tracepointargs = $1;
  2319. }
  2320. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  2321. print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
  2322. "$prototype\n";
  2323. } else {
  2324. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  2325. }
  2326. }
  2327. sub syscall_munge() {
  2328. my $void = 0;
  2329. $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
  2330. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  2331. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  2332. $void = 1;
  2333. ## $prototype = "long sys_$1(void)";
  2334. }
  2335. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  2336. if ($prototype =~ m/long (sys_.*?),/) {
  2337. $prototype =~ s/,/\(/;
  2338. } elsif ($void) {
  2339. $prototype =~ s/\)/\(void\)/;
  2340. }
  2341. # now delete all of the odd-number commas in $prototype
  2342. # so that arg types & arg names don't have a comma between them
  2343. my $count = 0;
  2344. my $len = length($prototype);
  2345. if ($void) {
  2346. $len = 0; # skip the for-loop
  2347. }
  2348. for (my $ix = 0; $ix < $len; $ix++) {
  2349. if (substr($prototype, $ix, 1) eq ',') {
  2350. $count++;
  2351. if ($count % 2 == 1) {
  2352. substr($prototype, $ix, 1) = ' ';
  2353. }
  2354. }
  2355. }
  2356. }
  2357. sub process_proto_function($$) {
  2358. my $x = shift;
  2359. my $file = shift;
  2360. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2361. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  2362. # do nothing
  2363. }
  2364. elsif ($x =~ /([^\{]*)/) {
  2365. $prototype .= $1;
  2366. }
  2367. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  2368. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  2369. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2370. $prototype =~ s@^\s+@@gos; # strip leading spaces
  2371. if ($prototype =~ /SYSCALL_DEFINE/) {
  2372. syscall_munge();
  2373. }
  2374. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  2375. $prototype =~ /DEFINE_SINGLE_EVENT/)
  2376. {
  2377. tracepoint_munge($file);
  2378. }
  2379. dump_function($prototype, $file);
  2380. reset_state();
  2381. }
  2382. }
  2383. sub process_proto_type($$) {
  2384. my $x = shift;
  2385. my $file = shift;
  2386. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2387. $x =~ s@^\s+@@gos; # strip leading spaces
  2388. $x =~ s@\s+$@@gos; # strip trailing spaces
  2389. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2390. if ($x =~ /^#/) {
  2391. # To distinguish preprocessor directive from regular declaration later.
  2392. $x .= ";";
  2393. }
  2394. while (1) {
  2395. if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
  2396. $prototype .= $1 . $2;
  2397. ($2 eq '{') && $brcount++;
  2398. ($2 eq '}') && $brcount--;
  2399. if (($2 eq ';') && ($brcount == 0)) {
  2400. dump_declaration($prototype, $file);
  2401. reset_state();
  2402. last;
  2403. }
  2404. $x = $3;
  2405. } else {
  2406. $prototype .= $x;
  2407. last;
  2408. }
  2409. }
  2410. }
  2411. # xml_escape: replace <, >, and & in the text stream;
  2412. #
  2413. # however, formatting controls that are generated internally/locally in the
  2414. # kernel-doc script are not escaped here; instead, they begin life like
  2415. # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
  2416. # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
  2417. # just before actual output; (this is done by local_unescape())
  2418. sub xml_escape($) {
  2419. my $text = shift;
  2420. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2421. return $text;
  2422. }
  2423. $text =~ s/\&/\\\\\\amp;/g;
  2424. $text =~ s/\</\\\\\\lt;/g;
  2425. $text =~ s/\>/\\\\\\gt;/g;
  2426. return $text;
  2427. }
  2428. # xml_unescape: reverse the effects of xml_escape
  2429. sub xml_unescape($) {
  2430. my $text = shift;
  2431. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2432. return $text;
  2433. }
  2434. $text =~ s/\\\\\\amp;/\&/g;
  2435. $text =~ s/\\\\\\lt;/</g;
  2436. $text =~ s/\\\\\\gt;/>/g;
  2437. return $text;
  2438. }
  2439. # convert local escape strings to html
  2440. # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
  2441. sub local_unescape($) {
  2442. my $text = shift;
  2443. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2444. return $text;
  2445. }
  2446. $text =~ s/\\\\\\\\lt:/</g;
  2447. $text =~ s/\\\\\\\\gt:/>/g;
  2448. return $text;
  2449. }
  2450. sub map_filename($) {
  2451. my $file;
  2452. my ($orig_file) = @_;
  2453. if (defined($ENV{'SRCTREE'})) {
  2454. $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
  2455. } else {
  2456. $file = $orig_file;
  2457. }
  2458. if (defined($source_map{$file})) {
  2459. $file = $source_map{$file};
  2460. }
  2461. return $file;
  2462. }
  2463. sub process_export_file($) {
  2464. my ($orig_file) = @_;
  2465. my $file = map_filename($orig_file);
  2466. if (!open(IN,"<$file")) {
  2467. print STDERR "Error: Cannot open file $file\n";
  2468. ++$errors;
  2469. return;
  2470. }
  2471. while (<IN>) {
  2472. if (/$export_symbol/) {
  2473. $function_table{$2} = 1;
  2474. }
  2475. }
  2476. close(IN);
  2477. }
  2478. sub process_file($) {
  2479. my $file;
  2480. my $identifier;
  2481. my $func;
  2482. my $descr;
  2483. my $in_purpose = 0;
  2484. my $initial_section_counter = $section_counter;
  2485. my ($orig_file) = @_;
  2486. my $leading_space;
  2487. $file = map_filename($orig_file);
  2488. if (!open(IN,"<$file")) {
  2489. print STDERR "Error: Cannot open file $file\n";
  2490. ++$errors;
  2491. return;
  2492. }
  2493. $. = 1;
  2494. $section_counter = 0;
  2495. while (<IN>) {
  2496. while (s/\\\s*$//) {
  2497. $_ .= <IN>;
  2498. }
  2499. if ($state == STATE_NORMAL) {
  2500. if (/$doc_start/o) {
  2501. $state = STATE_NAME; # next line is always the function name
  2502. $in_doc_sect = 0;
  2503. $declaration_start_line = $. + 1;
  2504. }
  2505. } elsif ($state == STATE_NAME) {# this line is the function name (always)
  2506. if (/$doc_block/o) {
  2507. $state = STATE_DOCBLOCK;
  2508. $contents = "";
  2509. $new_start_line = $. + 1;
  2510. if ( $1 eq "" ) {
  2511. $section = $section_intro;
  2512. } else {
  2513. $section = $1;
  2514. }
  2515. }
  2516. elsif (/$doc_decl/o) {
  2517. $identifier = $1;
  2518. if (/\s*([\w\s]+?)\s*-/) {
  2519. $identifier = $1;
  2520. }
  2521. $state = STATE_FIELD;
  2522. # if there's no @param blocks need to set up default section
  2523. # here
  2524. $contents = "";
  2525. $section = $section_default;
  2526. $new_start_line = $. + 1;
  2527. if (/-(.*)/) {
  2528. # strip leading/trailing/multiple spaces
  2529. $descr= $1;
  2530. $descr =~ s/^\s*//;
  2531. $descr =~ s/\s*$//;
  2532. $descr =~ s/\s+/ /g;
  2533. $declaration_purpose = xml_escape($descr);
  2534. $in_purpose = 1;
  2535. } else {
  2536. $declaration_purpose = "";
  2537. }
  2538. if (($declaration_purpose eq "") && $verbose) {
  2539. print STDERR "${file}:$.: warning: missing initial short description on line:\n";
  2540. print STDERR $_;
  2541. ++$warnings;
  2542. }
  2543. if ($identifier =~ m/^struct/) {
  2544. $decl_type = 'struct';
  2545. } elsif ($identifier =~ m/^union/) {
  2546. $decl_type = 'union';
  2547. } elsif ($identifier =~ m/^enum/) {
  2548. $decl_type = 'enum';
  2549. } elsif ($identifier =~ m/^typedef/) {
  2550. $decl_type = 'typedef';
  2551. } else {
  2552. $decl_type = 'function';
  2553. }
  2554. if ($verbose) {
  2555. print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
  2556. }
  2557. } else {
  2558. print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
  2559. " - I thought it was a doc line\n";
  2560. ++$warnings;
  2561. $state = STATE_NORMAL;
  2562. }
  2563. } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
  2564. if (/$doc_sect/i) { # case insensitive for supported section names
  2565. $newsection = $1;
  2566. $newcontents = $2;
  2567. # map the supported section names to the canonical names
  2568. if ($newsection =~ m/^description$/i) {
  2569. $newsection = $section_default;
  2570. } elsif ($newsection =~ m/^context$/i) {
  2571. $newsection = $section_context;
  2572. } elsif ($newsection =~ m/^returns?$/i) {
  2573. $newsection = $section_return;
  2574. } elsif ($newsection =~ m/^\@return$/) {
  2575. # special: @return is a section, not a param description
  2576. $newsection = $section_return;
  2577. }
  2578. if (($contents ne "") && ($contents ne "\n")) {
  2579. if (!$in_doc_sect && $verbose) {
  2580. print STDERR "${file}:$.: warning: contents before sections\n";
  2581. ++$warnings;
  2582. }
  2583. dump_section($file, $section, xml_escape($contents));
  2584. $section = $section_default;
  2585. }
  2586. $in_doc_sect = 1;
  2587. $in_purpose = 0;
  2588. $contents = $newcontents;
  2589. $new_start_line = $.;
  2590. while ((substr($contents, 0, 1) eq " ") ||
  2591. substr($contents, 0, 1) eq "\t") {
  2592. $contents = substr($contents, 1);
  2593. }
  2594. if ($contents ne "") {
  2595. $contents .= "\n";
  2596. }
  2597. $section = $newsection;
  2598. $leading_space = undef;
  2599. } elsif (/$doc_end/) {
  2600. if (($contents ne "") && ($contents ne "\n")) {
  2601. dump_section($file, $section, xml_escape($contents));
  2602. $section = $section_default;
  2603. $contents = "";
  2604. }
  2605. # look for doc_com + <text> + doc_end:
  2606. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  2607. print STDERR "${file}:$.: warning: suspicious ending line: $_";
  2608. ++$warnings;
  2609. }
  2610. $prototype = "";
  2611. $state = STATE_PROTO;
  2612. $brcount = 0;
  2613. # print STDERR "end of doc comment, looking for prototype\n";
  2614. } elsif (/$doc_content/) {
  2615. # miguel-style comment kludge, look for blank lines after
  2616. # @parameter line to signify start of description
  2617. if ($1 eq "") {
  2618. if ($section =~ m/^@/ || $section eq $section_context) {
  2619. dump_section($file, $section, xml_escape($contents));
  2620. $section = $section_default;
  2621. $contents = "";
  2622. $new_start_line = $.;
  2623. } else {
  2624. $contents .= "\n";
  2625. }
  2626. $in_purpose = 0;
  2627. } elsif ($in_purpose == 1) {
  2628. # Continued declaration purpose
  2629. chomp($declaration_purpose);
  2630. $declaration_purpose .= " " . xml_escape($1);
  2631. $declaration_purpose =~ s/\s+/ /g;
  2632. } else {
  2633. my $cont = $1;
  2634. if ($section =~ m/^@/ || $section eq $section_context) {
  2635. if (!defined $leading_space) {
  2636. if ($cont =~ m/^(\s+)/) {
  2637. $leading_space = $1;
  2638. } else {
  2639. $leading_space = "";
  2640. }
  2641. }
  2642. $cont =~ s/^$leading_space//;
  2643. }
  2644. $contents .= $cont . "\n";
  2645. }
  2646. } else {
  2647. # i dont know - bad line? ignore.
  2648. print STDERR "${file}:$.: warning: bad line: $_";
  2649. ++$warnings;
  2650. }
  2651. } elsif ($state == STATE_INLINE) { # scanning for inline parameters
  2652. # First line (state 1) needs to be a @parameter
  2653. if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
  2654. $section = $1;
  2655. $contents = $2;
  2656. $new_start_line = $.;
  2657. if ($contents ne "") {
  2658. while ((substr($contents, 0, 1) eq " ") ||
  2659. substr($contents, 0, 1) eq "\t") {
  2660. $contents = substr($contents, 1);
  2661. }
  2662. $contents .= "\n";
  2663. }
  2664. $inline_doc_state = STATE_INLINE_TEXT;
  2665. # Documentation block end */
  2666. } elsif (/$doc_inline_end/) {
  2667. if (($contents ne "") && ($contents ne "\n")) {
  2668. dump_section($file, $section, xml_escape($contents));
  2669. $section = $section_default;
  2670. $contents = "";
  2671. }
  2672. $state = STATE_PROTO;
  2673. $inline_doc_state = STATE_INLINE_NA;
  2674. # Regular text
  2675. } elsif (/$doc_content/) {
  2676. if ($inline_doc_state == STATE_INLINE_TEXT) {
  2677. $contents .= $1 . "\n";
  2678. # nuke leading blank lines
  2679. if ($contents =~ /^\s*$/) {
  2680. $contents = "";
  2681. }
  2682. } elsif ($inline_doc_state == STATE_INLINE_NAME) {
  2683. $inline_doc_state = STATE_INLINE_ERROR;
  2684. print STDERR "${file}:$.: warning: ";
  2685. print STDERR "Incorrect use of kernel-doc format: $_";
  2686. ++$warnings;
  2687. }
  2688. }
  2689. } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
  2690. if (/$doc_inline_oneline/) {
  2691. $section = $1;
  2692. $contents = $2;
  2693. if ($contents ne "") {
  2694. $contents .= "\n";
  2695. dump_section($file, $section, xml_escape($contents));
  2696. $section = $section_default;
  2697. $contents = "";
  2698. }
  2699. } elsif (/$doc_inline_start/) {
  2700. $state = STATE_INLINE;
  2701. $inline_doc_state = STATE_INLINE_NAME;
  2702. } elsif ($decl_type eq 'function') {
  2703. process_proto_function($_, $file);
  2704. } else {
  2705. process_proto_type($_, $file);
  2706. }
  2707. } elsif ($state == STATE_DOCBLOCK) {
  2708. if (/$doc_end/)
  2709. {
  2710. dump_doc_section($file, $section, xml_escape($contents));
  2711. $section = $section_default;
  2712. $contents = "";
  2713. $function = "";
  2714. %parameterdescs = ();
  2715. %parametertypes = ();
  2716. @parameterlist = ();
  2717. %sections = ();
  2718. @sectionlist = ();
  2719. $prototype = "";
  2720. $state = STATE_NORMAL;
  2721. }
  2722. elsif (/$doc_content/)
  2723. {
  2724. if ( $1 eq "" )
  2725. {
  2726. $contents .= $blankline;
  2727. }
  2728. else
  2729. {
  2730. $contents .= $1 . "\n";
  2731. }
  2732. }
  2733. }
  2734. }
  2735. if ($initial_section_counter == $section_counter) {
  2736. print STDERR "${file}:1: warning: no structured comments found\n";
  2737. if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
  2738. print STDERR " Was looking for '$_'.\n" for keys %function_table;
  2739. }
  2740. if ($output_mode eq "xml") {
  2741. # The template wants at least one RefEntry here; make one.
  2742. print "<refentry>\n";
  2743. print " <refnamediv>\n";
  2744. print " <refname>\n";
  2745. print " ${orig_file}\n";
  2746. print " </refname>\n";
  2747. print " <refpurpose>\n";
  2748. print " Document generation inconsistency\n";
  2749. print " </refpurpose>\n";
  2750. print " </refnamediv>\n";
  2751. print " <refsect1>\n";
  2752. print " <title>\n";
  2753. print " Oops\n";
  2754. print " </title>\n";
  2755. print " <warning>\n";
  2756. print " <para>\n";
  2757. print " The template for this document tried to insert\n";
  2758. print " the structured comment from the file\n";
  2759. print " <filename>${orig_file}</filename> at this point,\n";
  2760. print " but none was found.\n";
  2761. print " This dummy section is inserted to allow\n";
  2762. print " generation to continue.\n";
  2763. print " </para>\n";
  2764. print " </warning>\n";
  2765. print " </refsect1>\n";
  2766. print "</refentry>\n";
  2767. }
  2768. }
  2769. }
  2770. $kernelversion = get_kernel_version();
  2771. # generate a sequence of code that will splice in highlighting information
  2772. # using the s// operator.
  2773. for (my $k = 0; $k < @highlights; $k++) {
  2774. my $pattern = $highlights[$k][0];
  2775. my $result = $highlights[$k][1];
  2776. # print STDERR "scanning pattern:$pattern, highlight:($result)\n";
  2777. $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
  2778. }
  2779. # Read the file that maps relative names to absolute names for
  2780. # separate source and object directories and for shadow trees.
  2781. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2782. my ($relname, $absname);
  2783. while(<SOURCE_MAP>) {
  2784. chop();
  2785. ($relname, $absname) = (split())[0..1];
  2786. $relname =~ s:^/+::;
  2787. $source_map{$relname} = $absname;
  2788. }
  2789. close(SOURCE_MAP);
  2790. }
  2791. if ($output_selection == OUTPUT_EXPORTED ||
  2792. $output_selection == OUTPUT_INTERNAL) {
  2793. push(@export_file_list, @ARGV);
  2794. foreach (@export_file_list) {
  2795. chomp;
  2796. process_export_file($_);
  2797. }
  2798. }
  2799. foreach (@ARGV) {
  2800. chomp;
  2801. process_file($_);
  2802. }
  2803. if ($verbose && $errors) {
  2804. print STDERR "$errors errors\n";
  2805. }
  2806. if ($verbose && $warnings) {
  2807. print STDERR "$warnings warnings\n";
  2808. }
  2809. exit($errors);