kernel-doc 92 KB

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