kernel-doc 74 KB

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