kernel-doc 76 KB

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