kernel-doc 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603
  1. #!/usr/bin/perl -w
  2. use strict;
  3. ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
  4. ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
  5. ## Copyright (C) 2001 Simon Huggins ##
  6. ## Copyright (C) 2005-2012 Randy Dunlap ##
  7. ## Copyright (C) 2012 Dan Luedtke ##
  8. ## ##
  9. ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
  10. ## Copyright (c) 2000 MontaVista Software, Inc. ##
  11. ## ##
  12. ## This software falls under the GNU General Public License. ##
  13. ## Please read the COPYING file for more information ##
  14. # 18/01/2001 - Cleanups
  15. # Functions prototyped as foo(void) same as foo()
  16. # Stop eval'ing where we don't need to.
  17. # -- huggie@earth.li
  18. # 27/06/2001 - Allowed whitespace after initial "/**" and
  19. # allowed comments before function declarations.
  20. # -- Christian Kreibich <ck@whoop.org>
  21. # Still to do:
  22. # - add perldoc documentation
  23. # - Look more closely at some of the scarier bits :)
  24. # 26/05/2001 - Support for separate source and object trees.
  25. # Return error code.
  26. # Keith Owens <kaos@ocs.com.au>
  27. # 23/09/2001 - Added support for typedefs, structs, enums and unions
  28. # Support for Context section; can be terminated using empty line
  29. # Small fixes (like spaces vs. \s in regex)
  30. # -- Tim Jansen <tim@tjansen.de>
  31. # 25/07/2012 - Added support for HTML5
  32. # -- Dan Luedtke <mail@danrl.de>
  33. #
  34. # This will read a 'c' file and scan for embedded comments in the
  35. # style of gnome comments (+minor extensions - see below).
  36. #
  37. # Note: This only supports 'c'.
  38. # usage:
  39. # kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ]
  40. # [ -no-doc-sections ]
  41. # [ -function funcname [ -function funcname ...] ]
  42. # c file(s)s > outputfile
  43. # or
  44. # [ -nofunction funcname [ -function funcname ...] ]
  45. # c file(s)s > outputfile
  46. #
  47. # Set output format using one of -docbook -html -html5 -text or -man.
  48. # Default is man.
  49. # The -list format is for internal use by docproc.
  50. #
  51. # -no-doc-sections
  52. # Do not output DOC: sections
  53. #
  54. # -function funcname
  55. # If set, then only generate documentation for the given function(s) or
  56. # DOC: section titles. All other functions and DOC: sections are ignored.
  57. #
  58. # -nofunction funcname
  59. # If set, then only generate documentation for the other function(s)/DOC:
  60. # sections. Cannot be used together with -function (yes, that's a bug --
  61. # perl hackers can fix it 8))
  62. #
  63. # c files - list of 'c' files to process
  64. #
  65. # All output goes to stdout, with errors to stderr.
  66. #
  67. # format of comments.
  68. # In the following table, (...)? signifies optional structure.
  69. # (...)* signifies 0 or more structure elements
  70. # /**
  71. # * function_name(:)? (- short description)?
  72. # (* @parameterx: (description of parameter x)?)*
  73. # (* a blank line)?
  74. # * (Description:)? (Description of function)?
  75. # * (section header: (section description)? )*
  76. # (*)?*/
  77. #
  78. # So .. the trivial example would be:
  79. #
  80. # /**
  81. # * my_function
  82. # */
  83. #
  84. # If the Description: header tag is omitted, then there must be a blank line
  85. # after the last parameter specification.
  86. # e.g.
  87. # /**
  88. # * my_function - does my stuff
  89. # * @my_arg: its mine damnit
  90. # *
  91. # * Does my stuff explained.
  92. # */
  93. #
  94. # or, could also use:
  95. # /**
  96. # * my_function - does my stuff
  97. # * @my_arg: its mine damnit
  98. # * Description: Does my stuff explained.
  99. # */
  100. # etc.
  101. #
  102. # Besides functions you can also write documentation for structs, unions,
  103. # enums and typedefs. Instead of the function name you must write the name
  104. # of the declaration; the struct/union/enum/typedef must always precede
  105. # the name. Nesting of declarations is not supported.
  106. # Use the argument mechanism to document members or constants.
  107. # e.g.
  108. # /**
  109. # * struct my_struct - short description
  110. # * @a: first member
  111. # * @b: second member
  112. # *
  113. # * Longer description
  114. # */
  115. # struct my_struct {
  116. # int a;
  117. # int b;
  118. # /* private: */
  119. # int c;
  120. # };
  121. #
  122. # All descriptions can be multiline, except the short function description.
  123. #
  124. # You can also add additional sections. When documenting kernel functions you
  125. # should document the "Context:" of the function, e.g. whether the functions
  126. # can be called form interrupts. Unlike other sections you can end it with an
  127. # empty line.
  128. # A non-void function should have a "Return:" section describing the return
  129. # value(s).
  130. # Example-sections should contain the string EXAMPLE so that they are marked
  131. # appropriately in DocBook.
  132. #
  133. # Example:
  134. # /**
  135. # * user_function - function that can only be called in user context
  136. # * @a: some argument
  137. # * Context: !in_interrupt()
  138. # *
  139. # * Some description
  140. # * Example:
  141. # * user_function(22);
  142. # */
  143. # ...
  144. #
  145. #
  146. # All descriptive text is further processed, scanning for the following special
  147. # patterns, which are highlighted appropriately.
  148. #
  149. # 'funcname()' - function
  150. # '$ENVVAR' - environmental variable
  151. # '&struct_name' - name of a structure (up to two words including 'struct')
  152. # '@parameter' - name of a parameter
  153. # '%CONST' - name of a constant.
  154. ## init lots of data
  155. my $errors = 0;
  156. my $warnings = 0;
  157. my $anon_struct_union = 0;
  158. # match expressions used to find embedded type information
  159. my $type_constant = '\%([-_\w]+)';
  160. my $type_func = '(\w+)\(\)';
  161. my $type_param = '\@(\w+)';
  162. my $type_struct = '\&((struct\s*)*[_\w]+)';
  163. my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
  164. my $type_env = '(\$\w+)';
  165. # Output conversion substitutions.
  166. # One for each output format
  167. # these work fairly well
  168. my %highlights_html = ( $type_constant, "<i>\$1</i>",
  169. $type_func, "<b>\$1</b>",
  170. $type_struct_xml, "<i>\$1</i>",
  171. $type_env, "<b><i>\$1</i></b>",
  172. $type_param, "<tt><b>\$1</b></tt>" );
  173. my $local_lt = "\\\\\\\\lt:";
  174. my $local_gt = "\\\\\\\\gt:";
  175. my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
  176. # html version 5
  177. my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>",
  178. $type_func, "<span class=\"func\">\$1</span>",
  179. $type_struct_xml, "<span class=\"struct\">\$1</span>",
  180. $type_env, "<span class=\"env\">\$1</span>",
  181. $type_param, "<span class=\"param\">\$1</span>" );
  182. my $blankline_html5 = $local_lt . "br /" . $local_gt;
  183. # XML, docbook format
  184. my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
  185. $type_constant, "<constant>\$1</constant>",
  186. $type_func, "<function>\$1</function>",
  187. $type_struct_xml, "<structname>\$1</structname>",
  188. $type_env, "<envar>\$1</envar>",
  189. $type_param, "<parameter>\$1</parameter>" );
  190. my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
  191. # gnome, docbook format
  192. my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
  193. $type_func, "<function>\$1</function>",
  194. $type_struct, "<structname>\$1</structname>",
  195. $type_env, "<envar>\$1</envar>",
  196. $type_param, "<parameter>\$1</parameter>" );
  197. my $blankline_gnome = "</para><para>\n";
  198. # these are pretty rough
  199. my %highlights_man = ( $type_constant, "\$1",
  200. $type_func, "\\\\fB\$1\\\\fP",
  201. $type_struct, "\\\\fI\$1\\\\fP",
  202. $type_param, "\\\\fI\$1\\\\fP" );
  203. my $blankline_man = "";
  204. # text-mode
  205. my %highlights_text = ( $type_constant, "\$1",
  206. $type_func, "\$1",
  207. $type_struct, "\$1",
  208. $type_param, "\$1" );
  209. my $blankline_text = "";
  210. # list mode
  211. my %highlights_list = ( $type_constant, "\$1",
  212. $type_func, "\$1",
  213. $type_struct, "\$1",
  214. $type_param, "\$1" );
  215. my $blankline_list = "";
  216. # read arguments
  217. if ($#ARGV == -1) {
  218. usage();
  219. }
  220. my $kernelversion;
  221. my $dohighlight = "";
  222. my $verbose = 0;
  223. my $output_mode = "man";
  224. my $output_preformatted = 0;
  225. my $no_doc_sections = 0;
  226. my %highlights = %highlights_man;
  227. my $blankline = $blankline_man;
  228. my $modulename = "Kernel API";
  229. my $function_only = 0;
  230. my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
  231. 'July', 'August', 'September', 'October',
  232. 'November', 'December')[(localtime)[4]] .
  233. " " . ((localtime)[5]+1900);
  234. # Essentially these are globals.
  235. # They probably want to be tidied up, made more localised or something.
  236. # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
  237. # could cause "use of undefined value" or other bugs.
  238. my ($function, %function_table, %parametertypes, $declaration_purpose);
  239. my ($type, $declaration_name, $return_type);
  240. my ($newsection, $newcontents, $prototype, $brcount, %source_map);
  241. if (defined($ENV{'KBUILD_VERBOSE'})) {
  242. $verbose = "$ENV{'KBUILD_VERBOSE'}";
  243. }
  244. # Generated docbook code is inserted in a template at a point where
  245. # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
  246. # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
  247. # We keep track of number of generated entries and generate a dummy
  248. # if needs be to ensure the expanded template can be postprocessed
  249. # into html.
  250. my $section_counter = 0;
  251. my $lineprefix="";
  252. # states
  253. # 0 - normal code
  254. # 1 - looking for function name
  255. # 2 - scanning field start.
  256. # 3 - scanning prototype.
  257. # 4 - documentation block
  258. my $state;
  259. my $in_doc_sect;
  260. #declaration types: can be
  261. # 'function', 'struct', 'union', 'enum', 'typedef'
  262. my $decl_type;
  263. my $doc_special = "\@\%\$\&";
  264. my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
  265. my $doc_end = '\*/';
  266. my $doc_com = '\s*\*\s*';
  267. my $doc_com_body = '\s*\* ?';
  268. my $doc_decl = $doc_com . '(\w+)';
  269. my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
  270. my $doc_content = $doc_com_body . '(.*)';
  271. my $doc_block = $doc_com . 'DOC:\s*(.*)?';
  272. my %constants;
  273. my %parameterdescs;
  274. my @parameterlist;
  275. my %sections;
  276. my @sectionlist;
  277. my $sectcheck;
  278. my $struct_actual;
  279. my $contents = "";
  280. my $section_default = "Description"; # default section
  281. my $section_intro = "Introduction";
  282. my $section = $section_default;
  283. my $section_context = "Context";
  284. my $section_return = "Return";
  285. my $undescribed = "-- undescribed --";
  286. reset_state();
  287. while ($ARGV[0] =~ m/^-(.*)/) {
  288. my $cmd = shift @ARGV;
  289. if ($cmd eq "-html") {
  290. $output_mode = "html";
  291. %highlights = %highlights_html;
  292. $blankline = $blankline_html;
  293. } elsif ($cmd eq "-html5") {
  294. $output_mode = "html5";
  295. %highlights = %highlights_html5;
  296. $blankline = $blankline_html5;
  297. } elsif ($cmd eq "-man") {
  298. $output_mode = "man";
  299. %highlights = %highlights_man;
  300. $blankline = $blankline_man;
  301. } elsif ($cmd eq "-text") {
  302. $output_mode = "text";
  303. %highlights = %highlights_text;
  304. $blankline = $blankline_text;
  305. } elsif ($cmd eq "-docbook") {
  306. $output_mode = "xml";
  307. %highlights = %highlights_xml;
  308. $blankline = $blankline_xml;
  309. } elsif ($cmd eq "-list") {
  310. $output_mode = "list";
  311. %highlights = %highlights_list;
  312. $blankline = $blankline_list;
  313. } elsif ($cmd eq "-gnome") {
  314. $output_mode = "gnome";
  315. %highlights = %highlights_gnome;
  316. $blankline = $blankline_gnome;
  317. } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
  318. $modulename = shift @ARGV;
  319. } elsif ($cmd eq "-function") { # to only output specific functions
  320. $function_only = 1;
  321. $function = shift @ARGV;
  322. $function_table{$function} = 1;
  323. } elsif ($cmd eq "-nofunction") { # to only output specific functions
  324. $function_only = 2;
  325. $function = shift @ARGV;
  326. $function_table{$function} = 1;
  327. } elsif ($cmd eq "-v") {
  328. $verbose = 1;
  329. } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
  330. usage();
  331. } elsif ($cmd eq '-no-doc-sections') {
  332. $no_doc_sections = 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*\(.+\)//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. # Checks the section describing the return value of a function.
  1804. sub check_return_section {
  1805. my $file = shift;
  1806. my $declaration_name = shift;
  1807. my $return_type = shift;
  1808. # Ignore an empty return type (It's a macro)
  1809. # Ignore functions with a "void" return type. (But don't ignore "void *")
  1810. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  1811. return;
  1812. }
  1813. if (!defined($sections{$section_return}) ||
  1814. $sections{$section_return} eq "") {
  1815. print STDERR "Warning(${file}:$.): " .
  1816. "No description found for return value of " .
  1817. "'$declaration_name'\n";
  1818. ++$warnings;
  1819. }
  1820. }
  1821. ##
  1822. # takes a function prototype and the name of the current file being
  1823. # processed and spits out all the details stored in the global
  1824. # arrays/hashes.
  1825. sub dump_function($$) {
  1826. my $prototype = shift;
  1827. my $file = shift;
  1828. $prototype =~ s/^static +//;
  1829. $prototype =~ s/^extern +//;
  1830. $prototype =~ s/^asmlinkage +//;
  1831. $prototype =~ s/^inline +//;
  1832. $prototype =~ s/^__inline__ +//;
  1833. $prototype =~ s/^__inline +//;
  1834. $prototype =~ s/^__always_inline +//;
  1835. $prototype =~ s/^noinline +//;
  1836. $prototype =~ s/__init +//;
  1837. $prototype =~ s/__init_or_module +//;
  1838. $prototype =~ s/__must_check +//;
  1839. $prototype =~ s/__weak +//;
  1840. $prototype =~ s/^#\s*define\s+//; #ak added
  1841. $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
  1842. # Yes, this truly is vile. We are looking for:
  1843. # 1. Return type (may be nothing if we're looking at a macro)
  1844. # 2. Function name
  1845. # 3. Function parameters.
  1846. #
  1847. # All the while we have to watch out for function pointer parameters
  1848. # (which IIRC is what the two sections are for), C types (these
  1849. # regexps don't even start to express all the possibilities), and
  1850. # so on.
  1851. #
  1852. # If you mess with these regexps, it's a good idea to check that
  1853. # the following functions' documentation still comes out right:
  1854. # - parport_register_device (function pointer parameters)
  1855. # - atomic_set (macro)
  1856. # - pci_match_device, __copy_to_user (long return type)
  1857. if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1858. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1859. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1860. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1861. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1862. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1863. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  1864. $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1865. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1866. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1867. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1868. $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1869. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1870. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1871. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1872. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  1873. $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  1874. $return_type = $1;
  1875. $declaration_name = $2;
  1876. my $args = $3;
  1877. create_parameterlist($args, ',', $file);
  1878. } else {
  1879. print STDERR "Warning(${file}:$.): cannot understand function prototype: '$prototype'\n";
  1880. return;
  1881. }
  1882. my $prms = join " ", @parameterlist;
  1883. check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
  1884. # This check emits a lot of warnings at the moment, because many
  1885. # functions don't have a 'Return' doc section. So until the number
  1886. # of warnings goes sufficiently down, the check is only performed in
  1887. # verbose mode.
  1888. # TODO: always perform the check.
  1889. if ($verbose) {
  1890. check_return_section($file, $declaration_name, $return_type);
  1891. }
  1892. output_declaration($declaration_name,
  1893. 'function',
  1894. {'function' => $declaration_name,
  1895. 'module' => $modulename,
  1896. 'functiontype' => $return_type,
  1897. 'parameterlist' => \@parameterlist,
  1898. 'parameterdescs' => \%parameterdescs,
  1899. 'parametertypes' => \%parametertypes,
  1900. 'sectionlist' => \@sectionlist,
  1901. 'sections' => \%sections,
  1902. 'purpose' => $declaration_purpose
  1903. });
  1904. }
  1905. sub reset_state {
  1906. $function = "";
  1907. %constants = ();
  1908. %parameterdescs = ();
  1909. %parametertypes = ();
  1910. @parameterlist = ();
  1911. %sections = ();
  1912. @sectionlist = ();
  1913. $sectcheck = "";
  1914. $struct_actual = "";
  1915. $prototype = "";
  1916. $state = 0;
  1917. }
  1918. sub tracepoint_munge($) {
  1919. my $file = shift;
  1920. my $tracepointname = 0;
  1921. my $tracepointargs = 0;
  1922. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  1923. $tracepointname = $1;
  1924. }
  1925. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  1926. $tracepointname = $1;
  1927. }
  1928. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  1929. $tracepointname = $2;
  1930. }
  1931. $tracepointname =~ s/^\s+//; #strip leading whitespace
  1932. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  1933. $tracepointargs = $1;
  1934. }
  1935. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  1936. print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
  1937. "$prototype\n";
  1938. } else {
  1939. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  1940. }
  1941. }
  1942. sub syscall_munge() {
  1943. my $void = 0;
  1944. $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
  1945. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  1946. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  1947. $void = 1;
  1948. ## $prototype = "long sys_$1(void)";
  1949. }
  1950. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  1951. if ($prototype =~ m/long (sys_.*?),/) {
  1952. $prototype =~ s/,/\(/;
  1953. } elsif ($void) {
  1954. $prototype =~ s/\)/\(void\)/;
  1955. }
  1956. # now delete all of the odd-number commas in $prototype
  1957. # so that arg types & arg names don't have a comma between them
  1958. my $count = 0;
  1959. my $len = length($prototype);
  1960. if ($void) {
  1961. $len = 0; # skip the for-loop
  1962. }
  1963. for (my $ix = 0; $ix < $len; $ix++) {
  1964. if (substr($prototype, $ix, 1) eq ',') {
  1965. $count++;
  1966. if ($count % 2 == 1) {
  1967. substr($prototype, $ix, 1) = ' ';
  1968. }
  1969. }
  1970. }
  1971. }
  1972. sub process_state3_function($$) {
  1973. my $x = shift;
  1974. my $file = shift;
  1975. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1976. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  1977. # do nothing
  1978. }
  1979. elsif ($x =~ /([^\{]*)/) {
  1980. $prototype .= $1;
  1981. }
  1982. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  1983. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  1984. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1985. $prototype =~ s@^\s+@@gos; # strip leading spaces
  1986. if ($prototype =~ /SYSCALL_DEFINE/) {
  1987. syscall_munge();
  1988. }
  1989. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  1990. $prototype =~ /DEFINE_SINGLE_EVENT/)
  1991. {
  1992. tracepoint_munge($file);
  1993. }
  1994. dump_function($prototype, $file);
  1995. reset_state();
  1996. }
  1997. }
  1998. sub process_state3_type($$) {
  1999. my $x = shift;
  2000. my $file = shift;
  2001. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2002. $x =~ s@^\s+@@gos; # strip leading spaces
  2003. $x =~ s@\s+$@@gos; # strip trailing spaces
  2004. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2005. if ($x =~ /^#/) {
  2006. # To distinguish preprocessor directive from regular declaration later.
  2007. $x .= ";";
  2008. }
  2009. while (1) {
  2010. if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
  2011. $prototype .= $1 . $2;
  2012. ($2 eq '{') && $brcount++;
  2013. ($2 eq '}') && $brcount--;
  2014. if (($2 eq ';') && ($brcount == 0)) {
  2015. dump_declaration($prototype, $file);
  2016. reset_state();
  2017. last;
  2018. }
  2019. $x = $3;
  2020. } else {
  2021. $prototype .= $x;
  2022. last;
  2023. }
  2024. }
  2025. }
  2026. # xml_escape: replace <, >, and & in the text stream;
  2027. #
  2028. # however, formatting controls that are generated internally/locally in the
  2029. # kernel-doc script are not escaped here; instead, they begin life like
  2030. # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
  2031. # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
  2032. # just before actual output; (this is done by local_unescape())
  2033. sub xml_escape($) {
  2034. my $text = shift;
  2035. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2036. return $text;
  2037. }
  2038. $text =~ s/\&/\\\\\\amp;/g;
  2039. $text =~ s/\</\\\\\\lt;/g;
  2040. $text =~ s/\>/\\\\\\gt;/g;
  2041. return $text;
  2042. }
  2043. # convert local escape strings to html
  2044. # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
  2045. sub local_unescape($) {
  2046. my $text = shift;
  2047. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2048. return $text;
  2049. }
  2050. $text =~ s/\\\\\\\\lt:/</g;
  2051. $text =~ s/\\\\\\\\gt:/>/g;
  2052. return $text;
  2053. }
  2054. sub process_file($) {
  2055. my $file;
  2056. my $identifier;
  2057. my $func;
  2058. my $descr;
  2059. my $in_purpose = 0;
  2060. my $initial_section_counter = $section_counter;
  2061. if (defined($ENV{'SRCTREE'})) {
  2062. $file = "$ENV{'SRCTREE'}" . "/" . "@_";
  2063. }
  2064. else {
  2065. $file = "@_";
  2066. }
  2067. if (defined($source_map{$file})) {
  2068. $file = $source_map{$file};
  2069. }
  2070. if (!open(IN,"<$file")) {
  2071. print STDERR "Error: Cannot open file $file\n";
  2072. ++$errors;
  2073. return;
  2074. }
  2075. $. = 1;
  2076. $section_counter = 0;
  2077. while (<IN>) {
  2078. while (s/\\\s*$//) {
  2079. $_ .= <IN>;
  2080. }
  2081. if ($state == 0) {
  2082. if (/$doc_start/o) {
  2083. $state = 1; # next line is always the function name
  2084. $in_doc_sect = 0;
  2085. }
  2086. } elsif ($state == 1) { # this line is the function name (always)
  2087. if (/$doc_block/o) {
  2088. $state = 4;
  2089. $contents = "";
  2090. if ( $1 eq "" ) {
  2091. $section = $section_intro;
  2092. } else {
  2093. $section = $1;
  2094. }
  2095. }
  2096. elsif (/$doc_decl/o) {
  2097. $identifier = $1;
  2098. if (/\s*([\w\s]+?)\s*-/) {
  2099. $identifier = $1;
  2100. }
  2101. $state = 2;
  2102. if (/-(.*)/) {
  2103. # strip leading/trailing/multiple spaces
  2104. $descr= $1;
  2105. $descr =~ s/^\s*//;
  2106. $descr =~ s/\s*$//;
  2107. $descr =~ s/\s+/ /g;
  2108. $declaration_purpose = xml_escape($descr);
  2109. $in_purpose = 1;
  2110. } else {
  2111. $declaration_purpose = "";
  2112. }
  2113. if (($declaration_purpose eq "") && $verbose) {
  2114. print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
  2115. print STDERR $_;
  2116. ++$warnings;
  2117. }
  2118. if ($identifier =~ m/^struct/) {
  2119. $decl_type = 'struct';
  2120. } elsif ($identifier =~ m/^union/) {
  2121. $decl_type = 'union';
  2122. } elsif ($identifier =~ m/^enum/) {
  2123. $decl_type = 'enum';
  2124. } elsif ($identifier =~ m/^typedef/) {
  2125. $decl_type = 'typedef';
  2126. } else {
  2127. $decl_type = 'function';
  2128. }
  2129. if ($verbose) {
  2130. print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
  2131. }
  2132. } else {
  2133. print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
  2134. " - I thought it was a doc line\n";
  2135. ++$warnings;
  2136. $state = 0;
  2137. }
  2138. } elsif ($state == 2) { # look for head: lines, and include content
  2139. if (/$doc_sect/o) {
  2140. $newsection = $1;
  2141. $newcontents = $2;
  2142. if (($contents ne "") && ($contents ne "\n")) {
  2143. if (!$in_doc_sect && $verbose) {
  2144. print STDERR "Warning(${file}:$.): contents before sections\n";
  2145. ++$warnings;
  2146. }
  2147. dump_section($file, $section, xml_escape($contents));
  2148. $section = $section_default;
  2149. }
  2150. $in_doc_sect = 1;
  2151. $in_purpose = 0;
  2152. $contents = $newcontents;
  2153. if ($contents ne "") {
  2154. while ((substr($contents, 0, 1) eq " ") ||
  2155. substr($contents, 0, 1) eq "\t") {
  2156. $contents = substr($contents, 1);
  2157. }
  2158. $contents .= "\n";
  2159. }
  2160. $section = $newsection;
  2161. } elsif (/$doc_end/) {
  2162. if (($contents ne "") && ($contents ne "\n")) {
  2163. dump_section($file, $section, xml_escape($contents));
  2164. $section = $section_default;
  2165. $contents = "";
  2166. }
  2167. # look for doc_com + <text> + doc_end:
  2168. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  2169. print STDERR "Warning(${file}:$.): suspicious ending line: $_";
  2170. ++$warnings;
  2171. }
  2172. $prototype = "";
  2173. $state = 3;
  2174. $brcount = 0;
  2175. # print STDERR "end of doc comment, looking for prototype\n";
  2176. } elsif (/$doc_content/) {
  2177. # miguel-style comment kludge, look for blank lines after
  2178. # @parameter line to signify start of description
  2179. if ($1 eq "") {
  2180. if ($section =~ m/^@/ || $section eq $section_context) {
  2181. dump_section($file, $section, xml_escape($contents));
  2182. $section = $section_default;
  2183. $contents = "";
  2184. } else {
  2185. $contents .= "\n";
  2186. }
  2187. $in_purpose = 0;
  2188. } elsif ($in_purpose == 1) {
  2189. # Continued declaration purpose
  2190. chomp($declaration_purpose);
  2191. $declaration_purpose .= " " . xml_escape($1);
  2192. $declaration_purpose =~ s/\s+/ /g;
  2193. } else {
  2194. $contents .= $1 . "\n";
  2195. }
  2196. } else {
  2197. # i dont know - bad line? ignore.
  2198. print STDERR "Warning(${file}:$.): bad line: $_";
  2199. ++$warnings;
  2200. }
  2201. } elsif ($state == 3) { # scanning for function '{' (end of prototype)
  2202. if ($decl_type eq 'function') {
  2203. process_state3_function($_, $file);
  2204. } else {
  2205. process_state3_type($_, $file);
  2206. }
  2207. } elsif ($state == 4) {
  2208. # Documentation block
  2209. if (/$doc_block/) {
  2210. dump_doc_section($file, $section, xml_escape($contents));
  2211. $contents = "";
  2212. $function = "";
  2213. %constants = ();
  2214. %parameterdescs = ();
  2215. %parametertypes = ();
  2216. @parameterlist = ();
  2217. %sections = ();
  2218. @sectionlist = ();
  2219. $prototype = "";
  2220. if ( $1 eq "" ) {
  2221. $section = $section_intro;
  2222. } else {
  2223. $section = $1;
  2224. }
  2225. }
  2226. elsif (/$doc_end/)
  2227. {
  2228. dump_doc_section($file, $section, xml_escape($contents));
  2229. $contents = "";
  2230. $function = "";
  2231. %constants = ();
  2232. %parameterdescs = ();
  2233. %parametertypes = ();
  2234. @parameterlist = ();
  2235. %sections = ();
  2236. @sectionlist = ();
  2237. $prototype = "";
  2238. $state = 0;
  2239. }
  2240. elsif (/$doc_content/)
  2241. {
  2242. if ( $1 eq "" )
  2243. {
  2244. $contents .= $blankline;
  2245. }
  2246. else
  2247. {
  2248. $contents .= $1 . "\n";
  2249. }
  2250. }
  2251. }
  2252. }
  2253. if ($initial_section_counter == $section_counter) {
  2254. print STDERR "Warning(${file}): no structured comments found\n";
  2255. if ($output_mode eq "xml") {
  2256. # The template wants at least one RefEntry here; make one.
  2257. print "<refentry>\n";
  2258. print " <refnamediv>\n";
  2259. print " <refname>\n";
  2260. print " ${file}\n";
  2261. print " </refname>\n";
  2262. print " <refpurpose>\n";
  2263. print " Document generation inconsistency\n";
  2264. print " </refpurpose>\n";
  2265. print " </refnamediv>\n";
  2266. print " <refsect1>\n";
  2267. print " <title>\n";
  2268. print " Oops\n";
  2269. print " </title>\n";
  2270. print " <warning>\n";
  2271. print " <para>\n";
  2272. print " The template for this document tried to insert\n";
  2273. print " the structured comment from the file\n";
  2274. print " <filename>${file}</filename> at this point,\n";
  2275. print " but none was found.\n";
  2276. print " This dummy section is inserted to allow\n";
  2277. print " generation to continue.\n";
  2278. print " </para>\n";
  2279. print " </warning>\n";
  2280. print " </refsect1>\n";
  2281. print "</refentry>\n";
  2282. }
  2283. }
  2284. }
  2285. $kernelversion = get_kernel_version();
  2286. # generate a sequence of code that will splice in highlighting information
  2287. # using the s// operator.
  2288. foreach my $pattern (keys %highlights) {
  2289. # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
  2290. $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
  2291. }
  2292. # Read the file that maps relative names to absolute names for
  2293. # separate source and object directories and for shadow trees.
  2294. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2295. my ($relname, $absname);
  2296. while(<SOURCE_MAP>) {
  2297. chop();
  2298. ($relname, $absname) = (split())[0..1];
  2299. $relname =~ s:^/+::;
  2300. $source_map{$relname} = $absname;
  2301. }
  2302. close(SOURCE_MAP);
  2303. }
  2304. foreach (@ARGV) {
  2305. chomp;
  2306. process_file($_);
  2307. }
  2308. if ($verbose && $errors) {
  2309. print STDERR "$errors errors\n";
  2310. }
  2311. if ($verbose && $warnings) {
  2312. print STDERR "$warnings warnings\n";
  2313. }
  2314. exit($errors);