kernel-doc 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728
  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 "${file}:$.: error: 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/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  1593. $members =~ s/__aligned\s*\([^;]*\)//gos;
  1594. $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
  1595. create_parameterlist($members, ';', $file);
  1596. check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
  1597. output_declaration($declaration_name,
  1598. 'struct',
  1599. {'struct' => $declaration_name,
  1600. 'module' => $modulename,
  1601. 'parameterlist' => \@parameterlist,
  1602. 'parameterdescs' => \%parameterdescs,
  1603. 'parametertypes' => \%parametertypes,
  1604. 'sectionlist' => \@sectionlist,
  1605. 'sections' => \%sections,
  1606. 'purpose' => $declaration_purpose,
  1607. 'type' => $decl_type
  1608. });
  1609. }
  1610. else {
  1611. print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
  1612. ++$errors;
  1613. }
  1614. }
  1615. sub dump_enum($$) {
  1616. my $x = shift;
  1617. my $file = shift;
  1618. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1619. $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
  1620. if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
  1621. $declaration_name = $1;
  1622. my $members = $2;
  1623. foreach my $arg (split ',', $members) {
  1624. $arg =~ s/^\s*(\w+).*/$1/;
  1625. push @parameterlist, $arg;
  1626. if (!$parameterdescs{$arg}) {
  1627. $parameterdescs{$arg} = $undescribed;
  1628. print STDERR "${file}:$.: warning: Enum value '$arg' ".
  1629. "not described in enum '$declaration_name'\n";
  1630. }
  1631. }
  1632. output_declaration($declaration_name,
  1633. 'enum',
  1634. {'enum' => $declaration_name,
  1635. 'module' => $modulename,
  1636. 'parameterlist' => \@parameterlist,
  1637. 'parameterdescs' => \%parameterdescs,
  1638. 'sectionlist' => \@sectionlist,
  1639. 'sections' => \%sections,
  1640. 'purpose' => $declaration_purpose
  1641. });
  1642. }
  1643. else {
  1644. print STDERR "${file}:$.: error: Cannot parse enum!\n";
  1645. ++$errors;
  1646. }
  1647. }
  1648. sub dump_typedef($$) {
  1649. my $x = shift;
  1650. my $file = shift;
  1651. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1652. # Parse function prototypes
  1653. if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
  1654. # Function typedefs
  1655. $return_type = $1;
  1656. $declaration_name = $2;
  1657. my $args = $3;
  1658. create_parameterlist($args, ',', $file);
  1659. output_declaration($declaration_name,
  1660. 'function',
  1661. {'function' => $declaration_name,
  1662. 'module' => $modulename,
  1663. 'functiontype' => $return_type,
  1664. 'parameterlist' => \@parameterlist,
  1665. 'parameterdescs' => \%parameterdescs,
  1666. 'parametertypes' => \%parametertypes,
  1667. 'sectionlist' => \@sectionlist,
  1668. 'sections' => \%sections,
  1669. 'purpose' => $declaration_purpose
  1670. });
  1671. return;
  1672. }
  1673. while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
  1674. $x =~ s/\(*.\)\s*;$/;/;
  1675. $x =~ s/\[*.\]\s*;$/;/;
  1676. }
  1677. if ($x =~ /typedef.*\s+(\w+)\s*;/) {
  1678. $declaration_name = $1;
  1679. output_declaration($declaration_name,
  1680. 'typedef',
  1681. {'typedef' => $declaration_name,
  1682. 'module' => $modulename,
  1683. 'sectionlist' => \@sectionlist,
  1684. 'sections' => \%sections,
  1685. 'purpose' => $declaration_purpose
  1686. });
  1687. }
  1688. else {
  1689. print STDERR "${file}:$.: error: Cannot parse typedef!\n";
  1690. ++$errors;
  1691. }
  1692. }
  1693. sub save_struct_actual($) {
  1694. my $actual = shift;
  1695. # strip all spaces from the actual param so that it looks like one string item
  1696. $actual =~ s/\s*//g;
  1697. $struct_actual = $struct_actual . $actual . " ";
  1698. }
  1699. sub create_parameterlist($$$) {
  1700. my $args = shift;
  1701. my $splitter = shift;
  1702. my $file = shift;
  1703. my $type;
  1704. my $param;
  1705. # temporarily replace commas inside function pointer definition
  1706. while ($args =~ /(\([^\),]+),/) {
  1707. $args =~ s/(\([^\),]+),/$1#/g;
  1708. }
  1709. foreach my $arg (split($splitter, $args)) {
  1710. # strip comments
  1711. $arg =~ s/\/\*.*\*\///;
  1712. # strip leading/trailing spaces
  1713. $arg =~ s/^\s*//;
  1714. $arg =~ s/\s*$//;
  1715. $arg =~ s/\s+/ /;
  1716. if ($arg =~ /^#/) {
  1717. # Treat preprocessor directive as a typeless variable just to fill
  1718. # corresponding data structures "correctly". Catch it later in
  1719. # output_* subs.
  1720. push_parameter($arg, "", $file);
  1721. } elsif ($arg =~ m/\(.+\)\s*\(/) {
  1722. # pointer-to-function
  1723. $arg =~ tr/#/,/;
  1724. $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
  1725. $param = $1;
  1726. $type = $arg;
  1727. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1728. save_struct_actual($param);
  1729. push_parameter($param, $type, $file);
  1730. } elsif ($arg) {
  1731. $arg =~ s/\s*:\s*/:/g;
  1732. $arg =~ s/\s*\[/\[/g;
  1733. my @args = split('\s*,\s*', $arg);
  1734. if ($args[0] =~ m/\*/) {
  1735. $args[0] =~ s/(\*+)\s*/ $1/;
  1736. }
  1737. my @first_arg;
  1738. if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
  1739. shift @args;
  1740. push(@first_arg, split('\s+', $1));
  1741. push(@first_arg, $2);
  1742. } else {
  1743. @first_arg = split('\s+', shift @args);
  1744. }
  1745. unshift(@args, pop @first_arg);
  1746. $type = join " ", @first_arg;
  1747. foreach $param (@args) {
  1748. if ($param =~ m/^(\*+)\s*(.*)/) {
  1749. save_struct_actual($2);
  1750. push_parameter($2, "$type $1", $file);
  1751. }
  1752. elsif ($param =~ m/(.*?):(\d+)/) {
  1753. if ($type ne "") { # skip unnamed bit-fields
  1754. save_struct_actual($1);
  1755. push_parameter($1, "$type:$2", $file)
  1756. }
  1757. }
  1758. else {
  1759. save_struct_actual($param);
  1760. push_parameter($param, $type, $file);
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. sub push_parameter($$$) {
  1767. my $param = shift;
  1768. my $type = shift;
  1769. my $file = shift;
  1770. if (($anon_struct_union == 1) && ($type eq "") &&
  1771. ($param eq "}")) {
  1772. return; # ignore the ending }; from anon. struct/union
  1773. }
  1774. $anon_struct_union = 0;
  1775. my $param_name = $param;
  1776. $param_name =~ s/\[.*//;
  1777. if ($type eq "" && $param =~ /\.\.\.$/)
  1778. {
  1779. if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
  1780. $parameterdescs{$param} = "variable arguments";
  1781. }
  1782. }
  1783. elsif ($type eq "" && ($param eq "" or $param eq "void"))
  1784. {
  1785. $param="void";
  1786. $parameterdescs{void} = "no arguments";
  1787. }
  1788. elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
  1789. # handle unnamed (anonymous) union or struct:
  1790. {
  1791. $type = $param;
  1792. $param = "{unnamed_" . $param . "}";
  1793. $parameterdescs{$param} = "anonymous\n";
  1794. $anon_struct_union = 1;
  1795. }
  1796. # warn if parameter has no description
  1797. # (but ignore ones starting with # as these are not parameters
  1798. # but inline preprocessor statements);
  1799. # also ignore unnamed structs/unions;
  1800. if (!$anon_struct_union) {
  1801. if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
  1802. $parameterdescs{$param_name} = $undescribed;
  1803. if (($type eq 'function') || ($type eq 'enum')) {
  1804. print STDERR "${file}:$.: warning: Function parameter ".
  1805. "or member '$param' not " .
  1806. "described in '$declaration_name'\n";
  1807. }
  1808. print STDERR "${file}:$.: warning:" .
  1809. " No description found for parameter '$param'\n";
  1810. ++$warnings;
  1811. }
  1812. }
  1813. $param = xml_escape($param);
  1814. # strip spaces from $param so that it is one continuous string
  1815. # on @parameterlist;
  1816. # this fixes a problem where check_sections() cannot find
  1817. # a parameter like "addr[6 + 2]" because it actually appears
  1818. # as "addr[6", "+", "2]" on the parameter list;
  1819. # but it's better to maintain the param string unchanged for output,
  1820. # so just weaken the string compare in check_sections() to ignore
  1821. # "[blah" in a parameter string;
  1822. ###$param =~ s/\s*//g;
  1823. push @parameterlist, $param;
  1824. $parametertypes{$param} = $type;
  1825. }
  1826. sub check_sections($$$$$$) {
  1827. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
  1828. my @sects = split ' ', $sectcheck;
  1829. my @prms = split ' ', $prmscheck;
  1830. my $err;
  1831. my ($px, $sx);
  1832. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  1833. foreach $sx (0 .. $#sects) {
  1834. $err = 1;
  1835. foreach $px (0 .. $#prms) {
  1836. $prm_clean = $prms[$px];
  1837. $prm_clean =~ s/\[.*\]//;
  1838. $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  1839. # ignore array size in a parameter string;
  1840. # however, the original param string may contain
  1841. # spaces, e.g.: addr[6 + 2]
  1842. # and this appears in @prms as "addr[6" since the
  1843. # parameter list is split at spaces;
  1844. # hence just ignore "[..." for the sections check;
  1845. $prm_clean =~ s/\[.*//;
  1846. ##$prm_clean =~ s/^\**//;
  1847. if ($prm_clean eq $sects[$sx]) {
  1848. $err = 0;
  1849. last;
  1850. }
  1851. }
  1852. if ($err) {
  1853. if ($decl_type eq "function") {
  1854. print STDERR "${file}:$.: warning: " .
  1855. "Excess function parameter " .
  1856. "'$sects[$sx]' " .
  1857. "description in '$decl_name'\n";
  1858. ++$warnings;
  1859. } else {
  1860. if ($nested !~ m/\Q$sects[$sx]\E/) {
  1861. print STDERR "${file}:$.: warning: " .
  1862. "Excess struct/union/enum/typedef member " .
  1863. "'$sects[$sx]' " .
  1864. "description in '$decl_name'\n";
  1865. ++$warnings;
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. ##
  1872. # Checks the section describing the return value of a function.
  1873. sub check_return_section {
  1874. my $file = shift;
  1875. my $declaration_name = shift;
  1876. my $return_type = shift;
  1877. # Ignore an empty return type (It's a macro)
  1878. # Ignore functions with a "void" return type. (But don't ignore "void *")
  1879. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  1880. return;
  1881. }
  1882. if (!defined($sections{$section_return}) ||
  1883. $sections{$section_return} eq "") {
  1884. print STDERR "${file}:$.: warning: " .
  1885. "No description found for return value of " .
  1886. "'$declaration_name'\n";
  1887. ++$warnings;
  1888. }
  1889. }
  1890. ##
  1891. # takes a function prototype and the name of the current file being
  1892. # processed and spits out all the details stored in the global
  1893. # arrays/hashes.
  1894. sub dump_function($$) {
  1895. my $prototype = shift;
  1896. my $file = shift;
  1897. my $noret = 0;
  1898. $prototype =~ s/^static +//;
  1899. $prototype =~ s/^extern +//;
  1900. $prototype =~ s/^asmlinkage +//;
  1901. $prototype =~ s/^inline +//;
  1902. $prototype =~ s/^__inline__ +//;
  1903. $prototype =~ s/^__inline +//;
  1904. $prototype =~ s/^__always_inline +//;
  1905. $prototype =~ s/^noinline +//;
  1906. $prototype =~ s/__init +//;
  1907. $prototype =~ s/__init_or_module +//;
  1908. $prototype =~ s/__meminit +//;
  1909. $prototype =~ s/__must_check +//;
  1910. $prototype =~ s/__weak +//;
  1911. my $define = $prototype =~ s/^#\s*define\s+//; #ak added
  1912. $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
  1913. # Yes, this truly is vile. We are looking for:
  1914. # 1. Return type (may be nothing if we're looking at a macro)
  1915. # 2. Function name
  1916. # 3. Function parameters.
  1917. #
  1918. # All the while we have to watch out for function pointer parameters
  1919. # (which IIRC is what the two sections are for), C types (these
  1920. # regexps don't even start to express all the possibilities), and
  1921. # so on.
  1922. #
  1923. # If you mess with these regexps, it's a good idea to check that
  1924. # the following functions' documentation still comes out right:
  1925. # - parport_register_device (function pointer parameters)
  1926. # - atomic_set (macro)
  1927. # - pci_match_device, __copy_to_user (long return type)
  1928. if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
  1929. # This is an object-like macro, it has no return type and no parameter
  1930. # list.
  1931. # Function-like macros are not allowed to have spaces between
  1932. # declaration_name and opening parenthesis (notice the \s+).
  1933. $return_type = $1;
  1934. $declaration_name = $2;
  1935. $noret = 1;
  1936. } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1937. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1938. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1939. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1940. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1941. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1942. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1943. $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1944. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1945. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1946. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1947. $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1948. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1949. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1950. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1951. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1952. $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  1953. $return_type = $1;
  1954. $declaration_name = $2;
  1955. my $args = $3;
  1956. create_parameterlist($args, ',', $file);
  1957. } else {
  1958. print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
  1959. return;
  1960. }
  1961. my $prms = join " ", @parameterlist;
  1962. check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
  1963. # This check emits a lot of warnings at the moment, because many
  1964. # functions don't have a 'Return' doc section. So until the number
  1965. # of warnings goes sufficiently down, the check is only performed in
  1966. # verbose mode.
  1967. # TODO: always perform the check.
  1968. if ($verbose && !$noret) {
  1969. check_return_section($file, $declaration_name, $return_type);
  1970. }
  1971. output_declaration($declaration_name,
  1972. 'function',
  1973. {'function' => $declaration_name,
  1974. 'module' => $modulename,
  1975. 'functiontype' => $return_type,
  1976. 'parameterlist' => \@parameterlist,
  1977. 'parameterdescs' => \%parameterdescs,
  1978. 'parametertypes' => \%parametertypes,
  1979. 'sectionlist' => \@sectionlist,
  1980. 'sections' => \%sections,
  1981. 'purpose' => $declaration_purpose
  1982. });
  1983. }
  1984. sub reset_state {
  1985. $function = "";
  1986. %constants = ();
  1987. %parameterdescs = ();
  1988. %parametertypes = ();
  1989. @parameterlist = ();
  1990. %sections = ();
  1991. @sectionlist = ();
  1992. $sectcheck = "";
  1993. $struct_actual = "";
  1994. $prototype = "";
  1995. $state = 0;
  1996. $split_doc_state = 0;
  1997. }
  1998. sub tracepoint_munge($) {
  1999. my $file = shift;
  2000. my $tracepointname = 0;
  2001. my $tracepointargs = 0;
  2002. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  2003. $tracepointname = $1;
  2004. }
  2005. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  2006. $tracepointname = $1;
  2007. }
  2008. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  2009. $tracepointname = $2;
  2010. }
  2011. $tracepointname =~ s/^\s+//; #strip leading whitespace
  2012. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  2013. $tracepointargs = $1;
  2014. }
  2015. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  2016. print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
  2017. "$prototype\n";
  2018. } else {
  2019. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  2020. }
  2021. }
  2022. sub syscall_munge() {
  2023. my $void = 0;
  2024. $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
  2025. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  2026. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  2027. $void = 1;
  2028. ## $prototype = "long sys_$1(void)";
  2029. }
  2030. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  2031. if ($prototype =~ m/long (sys_.*?),/) {
  2032. $prototype =~ s/,/\(/;
  2033. } elsif ($void) {
  2034. $prototype =~ s/\)/\(void\)/;
  2035. }
  2036. # now delete all of the odd-number commas in $prototype
  2037. # so that arg types & arg names don't have a comma between them
  2038. my $count = 0;
  2039. my $len = length($prototype);
  2040. if ($void) {
  2041. $len = 0; # skip the for-loop
  2042. }
  2043. for (my $ix = 0; $ix < $len; $ix++) {
  2044. if (substr($prototype, $ix, 1) eq ',') {
  2045. $count++;
  2046. if ($count % 2 == 1) {
  2047. substr($prototype, $ix, 1) = ' ';
  2048. }
  2049. }
  2050. }
  2051. }
  2052. sub process_state3_function($$) {
  2053. my $x = shift;
  2054. my $file = shift;
  2055. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2056. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  2057. # do nothing
  2058. }
  2059. elsif ($x =~ /([^\{]*)/) {
  2060. $prototype .= $1;
  2061. }
  2062. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  2063. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  2064. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2065. $prototype =~ s@^\s+@@gos; # strip leading spaces
  2066. if ($prototype =~ /SYSCALL_DEFINE/) {
  2067. syscall_munge();
  2068. }
  2069. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  2070. $prototype =~ /DEFINE_SINGLE_EVENT/)
  2071. {
  2072. tracepoint_munge($file);
  2073. }
  2074. dump_function($prototype, $file);
  2075. reset_state();
  2076. }
  2077. }
  2078. sub process_state3_type($$) {
  2079. my $x = shift;
  2080. my $file = shift;
  2081. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2082. $x =~ s@^\s+@@gos; # strip leading spaces
  2083. $x =~ s@\s+$@@gos; # strip trailing spaces
  2084. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2085. if ($x =~ /^#/) {
  2086. # To distinguish preprocessor directive from regular declaration later.
  2087. $x .= ";";
  2088. }
  2089. while (1) {
  2090. if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
  2091. $prototype .= $1 . $2;
  2092. ($2 eq '{') && $brcount++;
  2093. ($2 eq '}') && $brcount--;
  2094. if (($2 eq ';') && ($brcount == 0)) {
  2095. dump_declaration($prototype, $file);
  2096. reset_state();
  2097. last;
  2098. }
  2099. $x = $3;
  2100. } else {
  2101. $prototype .= $x;
  2102. last;
  2103. }
  2104. }
  2105. }
  2106. # xml_escape: replace <, >, and & in the text stream;
  2107. #
  2108. # however, formatting controls that are generated internally/locally in the
  2109. # kernel-doc script are not escaped here; instead, they begin life like
  2110. # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
  2111. # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
  2112. # just before actual output; (this is done by local_unescape())
  2113. sub xml_escape($) {
  2114. my $text = shift;
  2115. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2116. return $text;
  2117. }
  2118. $text =~ s/\&/\\\\\\amp;/g;
  2119. $text =~ s/\</\\\\\\lt;/g;
  2120. $text =~ s/\>/\\\\\\gt;/g;
  2121. return $text;
  2122. }
  2123. # convert local escape strings to html
  2124. # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
  2125. sub local_unescape($) {
  2126. my $text = shift;
  2127. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2128. return $text;
  2129. }
  2130. $text =~ s/\\\\\\\\lt:/</g;
  2131. $text =~ s/\\\\\\\\gt:/>/g;
  2132. return $text;
  2133. }
  2134. sub process_file($) {
  2135. my $file;
  2136. my $identifier;
  2137. my $func;
  2138. my $descr;
  2139. my $in_purpose = 0;
  2140. my $initial_section_counter = $section_counter;
  2141. if (defined($ENV{'SRCTREE'})) {
  2142. $file = "$ENV{'SRCTREE'}" . "/" . "@_";
  2143. }
  2144. else {
  2145. $file = "@_";
  2146. }
  2147. if (defined($source_map{$file})) {
  2148. $file = $source_map{$file};
  2149. }
  2150. if (!open(IN,"<$file")) {
  2151. print STDERR "Error: Cannot open file $file\n";
  2152. ++$errors;
  2153. return;
  2154. }
  2155. $. = 1;
  2156. $section_counter = 0;
  2157. while (<IN>) {
  2158. while (s/\\\s*$//) {
  2159. $_ .= <IN>;
  2160. }
  2161. if ($state == 0) {
  2162. if (/$doc_start/o) {
  2163. $state = 1; # next line is always the function name
  2164. $in_doc_sect = 0;
  2165. }
  2166. } elsif ($state == 1) { # this line is the function name (always)
  2167. if (/$doc_block/o) {
  2168. $state = 4;
  2169. $contents = "";
  2170. if ( $1 eq "" ) {
  2171. $section = $section_intro;
  2172. } else {
  2173. $section = $1;
  2174. }
  2175. }
  2176. elsif (/$doc_decl/o) {
  2177. $identifier = $1;
  2178. if (/\s*([\w\s]+?)\s*-/) {
  2179. $identifier = $1;
  2180. }
  2181. $state = 2;
  2182. if (/-(.*)/) {
  2183. # strip leading/trailing/multiple spaces
  2184. $descr= $1;
  2185. $descr =~ s/^\s*//;
  2186. $descr =~ s/\s*$//;
  2187. $descr =~ s/\s+/ /g;
  2188. $declaration_purpose = xml_escape($descr);
  2189. $in_purpose = 1;
  2190. } else {
  2191. $declaration_purpose = "";
  2192. }
  2193. if (($declaration_purpose eq "") && $verbose) {
  2194. print STDERR "${file}:$.: warning: missing initial short description on line:\n";
  2195. print STDERR $_;
  2196. ++$warnings;
  2197. }
  2198. if ($identifier =~ m/^struct/) {
  2199. $decl_type = 'struct';
  2200. } elsif ($identifier =~ m/^union/) {
  2201. $decl_type = 'union';
  2202. } elsif ($identifier =~ m/^enum/) {
  2203. $decl_type = 'enum';
  2204. } elsif ($identifier =~ m/^typedef/) {
  2205. $decl_type = 'typedef';
  2206. } else {
  2207. $decl_type = 'function';
  2208. }
  2209. if ($verbose) {
  2210. print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
  2211. }
  2212. } else {
  2213. print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
  2214. " - I thought it was a doc line\n";
  2215. ++$warnings;
  2216. $state = 0;
  2217. }
  2218. } elsif ($state == 2) { # look for head: lines, and include content
  2219. if (/$doc_sect/o) {
  2220. $newsection = $1;
  2221. $newcontents = $2;
  2222. if (($contents ne "") && ($contents ne "\n")) {
  2223. if (!$in_doc_sect && $verbose) {
  2224. print STDERR "${file}:$.: warning: contents before sections\n";
  2225. ++$warnings;
  2226. }
  2227. dump_section($file, $section, xml_escape($contents));
  2228. $section = $section_default;
  2229. }
  2230. $in_doc_sect = 1;
  2231. $in_purpose = 0;
  2232. $contents = $newcontents;
  2233. if ($contents ne "") {
  2234. while ((substr($contents, 0, 1) eq " ") ||
  2235. substr($contents, 0, 1) eq "\t") {
  2236. $contents = substr($contents, 1);
  2237. }
  2238. $contents .= "\n";
  2239. }
  2240. $section = $newsection;
  2241. } elsif (/$doc_end/) {
  2242. if (($contents ne "") && ($contents ne "\n")) {
  2243. dump_section($file, $section, xml_escape($contents));
  2244. $section = $section_default;
  2245. $contents = "";
  2246. }
  2247. # look for doc_com + <text> + doc_end:
  2248. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  2249. print STDERR "${file}:$.: warning: suspicious ending line: $_";
  2250. ++$warnings;
  2251. }
  2252. $prototype = "";
  2253. $state = 3;
  2254. $brcount = 0;
  2255. # print STDERR "end of doc comment, looking for prototype\n";
  2256. } elsif (/$doc_content/) {
  2257. # miguel-style comment kludge, look for blank lines after
  2258. # @parameter line to signify start of description
  2259. if ($1 eq "") {
  2260. if ($section =~ m/^@/ || $section eq $section_context) {
  2261. dump_section($file, $section, xml_escape($contents));
  2262. $section = $section_default;
  2263. $contents = "";
  2264. } else {
  2265. $contents .= "\n";
  2266. }
  2267. $in_purpose = 0;
  2268. } elsif ($in_purpose == 1) {
  2269. # Continued declaration purpose
  2270. chomp($declaration_purpose);
  2271. $declaration_purpose .= " " . xml_escape($1);
  2272. $declaration_purpose =~ s/\s+/ /g;
  2273. } else {
  2274. $contents .= $1 . "\n";
  2275. }
  2276. } else {
  2277. # i dont know - bad line? ignore.
  2278. print STDERR "${file}:$.: warning: bad line: $_";
  2279. ++$warnings;
  2280. }
  2281. } elsif ($state == 5) { # scanning for split parameters
  2282. # First line (state 1) needs to be a @parameter
  2283. if ($split_doc_state == 1 && /$doc_split_sect/o) {
  2284. $section = $1;
  2285. $contents = $2;
  2286. if ($contents ne "") {
  2287. while ((substr($contents, 0, 1) eq " ") ||
  2288. substr($contents, 0, 1) eq "\t") {
  2289. $contents = substr($contents, 1);
  2290. }
  2291. $contents .= "\n";
  2292. }
  2293. $split_doc_state = 2;
  2294. # Documentation block end */
  2295. } elsif (/$doc_split_end/) {
  2296. if (($contents ne "") && ($contents ne "\n")) {
  2297. dump_section($file, $section, xml_escape($contents));
  2298. $section = $section_default;
  2299. $contents = "";
  2300. }
  2301. $state = 3;
  2302. $split_doc_state = 0;
  2303. # Regular text
  2304. } elsif (/$doc_content/) {
  2305. if ($split_doc_state == 2) {
  2306. $contents .= $1 . "\n";
  2307. } elsif ($split_doc_state == 1) {
  2308. $split_doc_state = 4;
  2309. print STDERR "Warning(${file}:$.): ";
  2310. print STDERR "Incorrect use of kernel-doc format: $_";
  2311. ++$warnings;
  2312. }
  2313. }
  2314. } elsif ($state == 3) { # scanning for function '{' (end of prototype)
  2315. if (/$doc_split_start/) {
  2316. $state = 5;
  2317. $split_doc_state = 1;
  2318. } elsif ($decl_type eq 'function') {
  2319. process_state3_function($_, $file);
  2320. } else {
  2321. process_state3_type($_, $file);
  2322. }
  2323. } elsif ($state == 4) {
  2324. # Documentation block
  2325. if (/$doc_block/) {
  2326. dump_doc_section($file, $section, xml_escape($contents));
  2327. $contents = "";
  2328. $function = "";
  2329. %constants = ();
  2330. %parameterdescs = ();
  2331. %parametertypes = ();
  2332. @parameterlist = ();
  2333. %sections = ();
  2334. @sectionlist = ();
  2335. $prototype = "";
  2336. if ( $1 eq "" ) {
  2337. $section = $section_intro;
  2338. } else {
  2339. $section = $1;
  2340. }
  2341. }
  2342. elsif (/$doc_end/)
  2343. {
  2344. dump_doc_section($file, $section, xml_escape($contents));
  2345. $contents = "";
  2346. $function = "";
  2347. %constants = ();
  2348. %parameterdescs = ();
  2349. %parametertypes = ();
  2350. @parameterlist = ();
  2351. %sections = ();
  2352. @sectionlist = ();
  2353. $prototype = "";
  2354. $state = 0;
  2355. }
  2356. elsif (/$doc_content/)
  2357. {
  2358. if ( $1 eq "" )
  2359. {
  2360. $contents .= $blankline;
  2361. }
  2362. else
  2363. {
  2364. $contents .= $1 . "\n";
  2365. }
  2366. }
  2367. }
  2368. }
  2369. if ($initial_section_counter == $section_counter) {
  2370. print STDERR "${file}:1: warning: no structured comments found\n";
  2371. if (($function_only == 1) && ($show_not_found == 1)) {
  2372. print STDERR " Was looking for '$_'.\n" for keys %function_table;
  2373. }
  2374. if ($output_mode eq "xml") {
  2375. # The template wants at least one RefEntry here; make one.
  2376. print "<refentry>\n";
  2377. print " <refnamediv>\n";
  2378. print " <refname>\n";
  2379. print " ${file}\n";
  2380. print " </refname>\n";
  2381. print " <refpurpose>\n";
  2382. print " Document generation inconsistency\n";
  2383. print " </refpurpose>\n";
  2384. print " </refnamediv>\n";
  2385. print " <refsect1>\n";
  2386. print " <title>\n";
  2387. print " Oops\n";
  2388. print " </title>\n";
  2389. print " <warning>\n";
  2390. print " <para>\n";
  2391. print " The template for this document tried to insert\n";
  2392. print " the structured comment from the file\n";
  2393. print " <filename>${file}</filename> at this point,\n";
  2394. print " but none was found.\n";
  2395. print " This dummy section is inserted to allow\n";
  2396. print " generation to continue.\n";
  2397. print " </para>\n";
  2398. print " </warning>\n";
  2399. print " </refsect1>\n";
  2400. print "</refentry>\n";
  2401. }
  2402. }
  2403. }
  2404. $kernelversion = get_kernel_version();
  2405. # generate a sequence of code that will splice in highlighting information
  2406. # using the s// operator.
  2407. foreach my $pattern (sort keys %highlights) {
  2408. # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
  2409. $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
  2410. }
  2411. # Read the file that maps relative names to absolute names for
  2412. # separate source and object directories and for shadow trees.
  2413. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2414. my ($relname, $absname);
  2415. while(<SOURCE_MAP>) {
  2416. chop();
  2417. ($relname, $absname) = (split())[0..1];
  2418. $relname =~ s:^/+::;
  2419. $source_map{$relname} = $absname;
  2420. }
  2421. close(SOURCE_MAP);
  2422. }
  2423. foreach (@ARGV) {
  2424. chomp;
  2425. process_file($_);
  2426. }
  2427. if ($verbose && $errors) {
  2428. print STDERR "$errors errors\n";
  2429. }
  2430. if ($verbose && $warnings) {
  2431. print STDERR "$warnings warnings\n";
  2432. }
  2433. exit($errors);