kernel-doc 56 KB

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