kernel-doc 82 KB

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