kernel-doc 61 KB

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