kernel-doc 76 KB

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