kernel-doc 86 KB

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