kernel-doc 85 KB

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