kernel-doc 92 KB

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