kernel-doc 61 KB

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