kernel-doc 53 KB

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