kernel-doc 63 KB

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