kernel-doc 55 KB

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