kernel-doc 70 KB

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