kernel-doc 74 KB

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