kernel-doc 62 KB

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