kernel-doc 70 KB

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