kernel-doc 72 KB

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