kernel-doc 62 KB

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