kernel-doc 55 KB

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