kernel-doc 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560
  1. #!/usr/bin/env perl
  2. # SPDX-License-Identifier: GPL-2.0
  3. # vim: softtabstop=4
  4. use warnings;
  5. use strict;
  6. ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
  7. ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
  8. ## Copyright (C) 2001 Simon Huggins ##
  9. ## Copyright (C) 2005-2012 Randy Dunlap ##
  10. ## Copyright (C) 2012 Dan Luedtke ##
  11. ## ##
  12. ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
  13. ## Copyright (c) 2000 MontaVista Software, Inc. ##
  14. #
  15. # Copyright (C) 2022 Tomasz Warniełło (POD)
  16. use Pod::Usage qw/pod2usage/;
  17. =head1 NAME
  18. kernel-doc - Print formatted kernel documentation to stdout
  19. =head1 SYNOPSIS
  20. kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wreturn] [-Wshort-desc[ription]] [-Wcontents-before-sections]
  21. [ -man |
  22. -rst [-sphinx-version VERSION] [-enable-lineno] |
  23. -none
  24. ]
  25. [
  26. -export |
  27. -internal |
  28. [-function NAME] ... |
  29. [-nosymbol NAME] ...
  30. ]
  31. [-no-doc-sections]
  32. [-export-file FILE] ...
  33. FILE ...
  34. Run `kernel-doc -h` for details.
  35. =head1 DESCRIPTION
  36. Read C language source or header FILEs, extract embedded documentation comments,
  37. and print formatted documentation to standard output.
  38. The documentation comments are identified by the "/**" opening comment mark.
  39. See Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax.
  40. =cut
  41. # more perldoc at the end of the file
  42. ## init lots of data
  43. my $errors = 0;
  44. my $warnings = 0;
  45. my $anon_struct_union = 0;
  46. # match expressions used to find embedded type information
  47. my $type_constant = '\b``([^\`]+)``\b';
  48. my $type_constant2 = '\%([-_*\w]+)';
  49. my $type_func = '(\w+)\(\)';
  50. my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
  51. my $type_param_ref = '([\!~\*]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
  52. my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
  53. my $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params
  54. my $type_env = '(\$\w+)';
  55. my $type_enum = '\&(enum\s*([_\w]+))';
  56. my $type_struct = '\&(struct\s*([_\w]+))';
  57. my $type_typedef = '\&(typedef\s*([_\w]+))';
  58. my $type_union = '\&(union\s*([_\w]+))';
  59. my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
  60. my $type_fallback = '\&([_\w]+)';
  61. my $type_member_func = $type_member . '\(\)';
  62. # Output conversion substitutions.
  63. # One for each output format
  64. # these are pretty rough
  65. my @highlights_man = (
  66. [$type_constant, "\$1"],
  67. [$type_constant2, "\$1"],
  68. [$type_func, "\\\\fB\$1\\\\fP"],
  69. [$type_enum, "\\\\fI\$1\\\\fP"],
  70. [$type_struct, "\\\\fI\$1\\\\fP"],
  71. [$type_typedef, "\\\\fI\$1\\\\fP"],
  72. [$type_union, "\\\\fI\$1\\\\fP"],
  73. [$type_param, "\\\\fI\$1\\\\fP"],
  74. [$type_param_ref, "\\\\fI\$1\$2\\\\fP"],
  75. [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
  76. [$type_fallback, "\\\\fI\$1\\\\fP"]
  77. );
  78. my $blankline_man = "";
  79. # rst-mode
  80. my @highlights_rst = (
  81. [$type_constant, "``\$1``"],
  82. [$type_constant2, "``\$1``"],
  83. # Note: need to escape () to avoid func matching later
  84. [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
  85. [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
  86. [$type_fp_param, "**\$1\\\\(\\\\)**"],
  87. [$type_fp_param2, "**\$1\\\\(\\\\)**"],
  88. [$type_func, "\$1()"],
  89. [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
  90. [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
  91. [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
  92. [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
  93. # in rst this can refer to any type
  94. [$type_fallback, "\\:c\\:type\\:`\$1`"],
  95. [$type_param_ref, "**\$1\$2**"]
  96. );
  97. my $blankline_rst = "\n";
  98. # read arguments
  99. if ($#ARGV == -1) {
  100. pod2usage(
  101. -message => "No arguments!\n",
  102. -exitval => 1,
  103. -verbose => 99,
  104. -sections => 'SYNOPSIS',
  105. -output => \*STDERR,
  106. );
  107. }
  108. my $kernelversion;
  109. my ($sphinx_major, $sphinx_minor, $sphinx_patch);
  110. my $dohighlight = "";
  111. my $verbose = 0;
  112. my $Werror = 0;
  113. my $Wreturn = 0;
  114. my $Wshort_desc = 0;
  115. my $Wcontents_before_sections = 0;
  116. my $output_mode = "rst";
  117. my $output_preformatted = 0;
  118. my $no_doc_sections = 0;
  119. my $enable_lineno = 0;
  120. my @highlights = @highlights_rst;
  121. my $blankline = $blankline_rst;
  122. my $modulename = "Kernel API";
  123. use constant {
  124. OUTPUT_ALL => 0, # output all symbols and doc sections
  125. OUTPUT_INCLUDE => 1, # output only specified symbols
  126. OUTPUT_EXPORTED => 2, # output exported symbols
  127. OUTPUT_INTERNAL => 3, # output non-exported symbols
  128. };
  129. my $output_selection = OUTPUT_ALL;
  130. my $show_not_found = 0; # No longer used
  131. my @export_file_list;
  132. my @build_time;
  133. if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
  134. (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
  135. @build_time = gmtime($seconds);
  136. } else {
  137. @build_time = localtime;
  138. }
  139. my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
  140. 'July', 'August', 'September', 'October',
  141. 'November', 'December')[$build_time[4]] .
  142. " " . ($build_time[5]+1900);
  143. # Essentially these are globals.
  144. # They probably want to be tidied up, made more localised or something.
  145. # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
  146. # could cause "use of undefined value" or other bugs.
  147. my ($function, %function_table, %parametertypes, $declaration_purpose);
  148. my %nosymbol_table = ();
  149. my $declaration_start_line;
  150. my ($type, $declaration_name, $return_type);
  151. my ($newsection, $newcontents, $prototype, $brcount, %source_map);
  152. if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') {
  153. $verbose = 1;
  154. }
  155. if (defined($ENV{'KCFLAGS'})) {
  156. my $kcflags = "$ENV{'KCFLAGS'}";
  157. if ($kcflags =~ /(\s|^)-Werror(\s|$)/) {
  158. $Werror = 1;
  159. }
  160. }
  161. # reading this variable is for backwards compat just in case
  162. # someone was calling it with the variable from outside the
  163. # kernel's build system
  164. if (defined($ENV{'KDOC_WERROR'})) {
  165. $Werror = "$ENV{'KDOC_WERROR'}";
  166. }
  167. # other environment variables are converted to command-line
  168. # arguments in cmd_checkdoc in the build system
  169. # Generated docbook code is inserted in a template at a point where
  170. # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
  171. # https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
  172. # We keep track of number of generated entries and generate a dummy
  173. # if needs be to ensure the expanded template can be postprocessed
  174. # into html.
  175. my $section_counter = 0;
  176. my $lineprefix="";
  177. # Parser states
  178. use constant {
  179. STATE_NORMAL => 0, # normal code
  180. STATE_NAME => 1, # looking for function name
  181. STATE_BODY_MAYBE => 2, # body - or maybe more description
  182. STATE_BODY => 3, # the body of the comment
  183. STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line
  184. STATE_PROTO => 5, # scanning prototype
  185. STATE_DOCBLOCK => 6, # documentation block
  186. STATE_INLINE => 7, # gathering doc outside main block
  187. };
  188. my $state;
  189. my $in_doc_sect;
  190. my $leading_space;
  191. # Inline documentation state
  192. use constant {
  193. STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
  194. STATE_INLINE_NAME => 1, # looking for member name (@foo:)
  195. STATE_INLINE_TEXT => 2, # looking for member documentation
  196. STATE_INLINE_END => 3, # done
  197. STATE_INLINE_ERROR => 4, # error - Comment without header was found.
  198. # Spit a warning as it's not
  199. # proper kernel-doc and ignore the rest.
  200. };
  201. my $inline_doc_state;
  202. #declaration types: can be
  203. # 'function', 'struct', 'union', 'enum', 'typedef'
  204. my $decl_type;
  205. # Name of the kernel-doc identifier for non-DOC markups
  206. my $identifier;
  207. my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
  208. my $doc_end = '\*/';
  209. my $doc_com = '\s*\*\s*';
  210. my $doc_com_body = '\s*\* ?';
  211. my $doc_decl = $doc_com . '(\w+)';
  212. # @params and a strictly limited set of supported section names
  213. # Specifically:
  214. # Match @word:
  215. # @...:
  216. # @{section-name}:
  217. # while trying to not match literal block starts like "example::"
  218. #
  219. my $doc_sect = $doc_com .
  220. '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$';
  221. my $doc_content = $doc_com_body . '(.*)';
  222. my $doc_block = $doc_com . 'DOC:\s*(.*)?';
  223. my $doc_inline_start = '^\s*/\*\*\s*$';
  224. my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';
  225. my $doc_inline_end = '^\s*\*/\s*$';
  226. my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
  227. my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
  228. my $export_symbol_ns = '^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*\w+\)\s*;';
  229. my $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)};
  230. my $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i;
  231. my %parameterdescs;
  232. my %parameterdesc_start_lines;
  233. my @parameterlist;
  234. my %sections;
  235. my @sectionlist;
  236. my %section_start_lines;
  237. my $sectcheck;
  238. my $struct_actual;
  239. my $contents = "";
  240. my $new_start_line = 0;
  241. # the canonical section names. see also $doc_sect above.
  242. my $section_default = "Description"; # default section
  243. my $section_intro = "Introduction";
  244. my $section = $section_default;
  245. my $section_context = "Context";
  246. my $section_return = "Return";
  247. my $undescribed = "-- undescribed --";
  248. reset_state();
  249. while ($ARGV[0] =~ m/^--?(.*)/) {
  250. my $cmd = $1;
  251. shift @ARGV;
  252. if ($cmd eq "man") {
  253. $output_mode = "man";
  254. @highlights = @highlights_man;
  255. $blankline = $blankline_man;
  256. } elsif ($cmd eq "rst") {
  257. $output_mode = "rst";
  258. @highlights = @highlights_rst;
  259. $blankline = $blankline_rst;
  260. } elsif ($cmd eq "none") {
  261. $output_mode = "none";
  262. } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document
  263. $modulename = shift @ARGV;
  264. } elsif ($cmd eq "function") { # to only output specific functions
  265. $output_selection = OUTPUT_INCLUDE;
  266. $function = shift @ARGV;
  267. $function_table{$function} = 1;
  268. } elsif ($cmd eq "nosymbol") { # Exclude specific symbols
  269. my $symbol = shift @ARGV;
  270. $nosymbol_table{$symbol} = 1;
  271. } elsif ($cmd eq "export") { # only exported symbols
  272. $output_selection = OUTPUT_EXPORTED;
  273. %function_table = ();
  274. } elsif ($cmd eq "internal") { # only non-exported symbols
  275. $output_selection = OUTPUT_INTERNAL;
  276. %function_table = ();
  277. } elsif ($cmd eq "export-file") {
  278. my $file = shift @ARGV;
  279. push(@export_file_list, $file);
  280. } elsif ($cmd eq "v") {
  281. $verbose = 1;
  282. } elsif ($cmd eq "Werror") {
  283. $Werror = 1;
  284. } elsif ($cmd eq "Wreturn") {
  285. $Wreturn = 1;
  286. } elsif ($cmd eq "Wshort-desc" or $cmd eq "Wshort-description") {
  287. $Wshort_desc = 1;
  288. } elsif ($cmd eq "Wcontents-before-sections") {
  289. $Wcontents_before_sections = 1;
  290. } elsif ($cmd eq "Wall") {
  291. $Wreturn = 1;
  292. $Wshort_desc = 1;
  293. $Wcontents_before_sections = 1;
  294. } elsif (($cmd eq "h") || ($cmd eq "help")) {
  295. pod2usage(-exitval => 0, -verbose => 2);
  296. } elsif ($cmd eq 'no-doc-sections') {
  297. $no_doc_sections = 1;
  298. } elsif ($cmd eq 'enable-lineno') {
  299. $enable_lineno = 1;
  300. } elsif ($cmd eq 'show-not-found') {
  301. $show_not_found = 1; # A no-op but don't fail
  302. } elsif ($cmd eq "sphinx-version") {
  303. my $ver_string = shift @ARGV;
  304. if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) {
  305. $sphinx_major = $1;
  306. if (defined($2)) {
  307. $sphinx_minor = substr($2,1);
  308. } else {
  309. $sphinx_minor = 0;
  310. }
  311. if (defined($3)) {
  312. $sphinx_patch = substr($3,1)
  313. } else {
  314. $sphinx_patch = 0;
  315. }
  316. } else {
  317. die "Sphinx version should either major.minor or major.minor.patch format\n";
  318. }
  319. } else {
  320. # Unknown argument
  321. pod2usage(
  322. -message => "Argument unknown!\n",
  323. -exitval => 1,
  324. -verbose => 99,
  325. -sections => 'SYNOPSIS',
  326. -output => \*STDERR,
  327. );
  328. }
  329. if ($#ARGV < 0){
  330. pod2usage(
  331. -message => "FILE argument missing\n",
  332. -exitval => 1,
  333. -verbose => 99,
  334. -sections => 'SYNOPSIS',
  335. -output => \*STDERR,
  336. );
  337. }
  338. }
  339. # continue execution near EOF;
  340. # The C domain dialect changed on Sphinx 3. So, we need to check the
  341. # version in order to produce the right tags.
  342. sub findprog($)
  343. {
  344. foreach(split(/:/, $ENV{PATH})) {
  345. return "$_/$_[0]" if(-x "$_/$_[0]");
  346. }
  347. }
  348. sub get_sphinx_version()
  349. {
  350. my $ver;
  351. my $cmd = "sphinx-build";
  352. if (!findprog($cmd)) {
  353. my $cmd = "sphinx-build3";
  354. if (!findprog($cmd)) {
  355. $sphinx_major = 1;
  356. $sphinx_minor = 2;
  357. $sphinx_patch = 0;
  358. printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n",
  359. $sphinx_major, $sphinx_minor, $sphinx_patch;
  360. return;
  361. }
  362. }
  363. open IN, "$cmd --version 2>&1 |";
  364. while (<IN>) {
  365. if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) {
  366. $sphinx_major = $1;
  367. $sphinx_minor = $2;
  368. $sphinx_patch = $3;
  369. last;
  370. }
  371. # Sphinx 1.2.x uses a different format
  372. if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) {
  373. $sphinx_major = $1;
  374. $sphinx_minor = $2;
  375. $sphinx_patch = $3;
  376. last;
  377. }
  378. }
  379. close IN;
  380. }
  381. # get kernel version from env
  382. sub get_kernel_version() {
  383. my $version = 'unknown kernel version';
  384. if (defined($ENV{'KERNELVERSION'})) {
  385. $version = $ENV{'KERNELVERSION'};
  386. }
  387. return $version;
  388. }
  389. #
  390. sub print_lineno {
  391. my $lineno = shift;
  392. if ($enable_lineno && defined($lineno)) {
  393. print ".. LINENO " . $lineno . "\n";
  394. }
  395. }
  396. sub emit_warning {
  397. my $location = shift;
  398. my $msg = shift;
  399. print STDERR "$location: warning: $msg";
  400. ++$warnings;
  401. }
  402. ##
  403. # dumps section contents to arrays/hashes intended for that purpose.
  404. #
  405. sub dump_section {
  406. my $file = shift;
  407. my $name = shift;
  408. my $contents = join "\n", @_;
  409. if ($name =~ m/$type_param/) {
  410. $name = $1;
  411. $parameterdescs{$name} = $contents;
  412. $sectcheck = $sectcheck . $name . " ";
  413. $parameterdesc_start_lines{$name} = $new_start_line;
  414. $new_start_line = 0;
  415. } elsif ($name eq "@\.\.\.") {
  416. $name = "...";
  417. $parameterdescs{$name} = $contents;
  418. $sectcheck = $sectcheck . $name . " ";
  419. $parameterdesc_start_lines{$name} = $new_start_line;
  420. $new_start_line = 0;
  421. } else {
  422. if (defined($sections{$name}) && ($sections{$name} ne "")) {
  423. # Only warn on user specified duplicate section names.
  424. if ($name ne $section_default) {
  425. emit_warning("${file}:$.", "duplicate section name '$name'\n");
  426. }
  427. $sections{$name} .= $contents;
  428. } else {
  429. $sections{$name} = $contents;
  430. push @sectionlist, $name;
  431. $section_start_lines{$name} = $new_start_line;
  432. $new_start_line = 0;
  433. }
  434. }
  435. }
  436. ##
  437. # dump DOC: section after checking that it should go out
  438. #
  439. sub dump_doc_section {
  440. my $file = shift;
  441. my $name = shift;
  442. my $contents = join "\n", @_;
  443. if ($no_doc_sections) {
  444. return;
  445. }
  446. return if (defined($nosymbol_table{$name}));
  447. if (($output_selection == OUTPUT_ALL) ||
  448. (($output_selection == OUTPUT_INCLUDE) &&
  449. defined($function_table{$name})))
  450. {
  451. dump_section($file, $name, $contents);
  452. output_blockhead({'sectionlist' => \@sectionlist,
  453. 'sections' => \%sections,
  454. 'module' => $modulename,
  455. 'content-only' => ($output_selection != OUTPUT_ALL), });
  456. }
  457. }
  458. ##
  459. # output function
  460. #
  461. # parameterdescs, a hash.
  462. # function => "function name"
  463. # parameterlist => @list of parameters
  464. # parameterdescs => %parameter descriptions
  465. # sectionlist => @list of sections
  466. # sections => %section descriptions
  467. #
  468. sub output_highlight {
  469. my $contents = join "\n",@_;
  470. my $line;
  471. # DEBUG
  472. # if (!defined $contents) {
  473. # use Carp;
  474. # confess "output_highlight got called with no args?\n";
  475. # }
  476. # print STDERR "contents b4:$contents\n";
  477. eval $dohighlight;
  478. die $@ if $@;
  479. # print STDERR "contents af:$contents\n";
  480. foreach $line (split "\n", $contents) {
  481. if (! $output_preformatted) {
  482. $line =~ s/^\s*//;
  483. }
  484. if ($line eq ""){
  485. if (! $output_preformatted) {
  486. print $lineprefix, $blankline;
  487. }
  488. } else {
  489. if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
  490. print "\\&$line";
  491. } else {
  492. print $lineprefix, $line;
  493. }
  494. }
  495. print "\n";
  496. }
  497. }
  498. ##
  499. # output function in man
  500. sub output_function_man(%) {
  501. my %args = %{$_[0]};
  502. my ($parameter, $section);
  503. my $count;
  504. my $func_macro = $args{'func_macro'};
  505. my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
  506. print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
  507. print ".SH NAME\n";
  508. print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
  509. print ".SH SYNOPSIS\n";
  510. if ($args{'functiontype'} ne "") {
  511. print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
  512. } else {
  513. print ".B \"" . $args{'function'} . "\n";
  514. }
  515. $count = 0;
  516. my $parenth = "(";
  517. my $post = ",";
  518. foreach my $parameter (@{$args{'parameterlist'}}) {
  519. if ($count == $#{$args{'parameterlist'}}) {
  520. $post = ");";
  521. }
  522. $type = $args{'parametertypes'}{$parameter};
  523. if ($type =~ m/$function_pointer/) {
  524. # pointer-to-function
  525. print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n";
  526. } else {
  527. $type =~ s/([^\*])$/$1 /;
  528. print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n";
  529. }
  530. $count++;
  531. $parenth = "";
  532. }
  533. $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
  534. if ($paramcount >= 0) {
  535. print ".SH ARGUMENTS\n";
  536. }
  537. foreach $parameter (@{$args{'parameterlist'}}) {
  538. my $parameter_name = $parameter;
  539. $parameter_name =~ s/\[.*//;
  540. print ".IP \"" . $parameter . "\" 12\n";
  541. output_highlight($args{'parameterdescs'}{$parameter_name});
  542. }
  543. foreach $section (@{$args{'sectionlist'}}) {
  544. print ".SH \"", uc $section, "\"\n";
  545. output_highlight($args{'sections'}{$section});
  546. }
  547. }
  548. ##
  549. # output enum in man
  550. sub output_enum_man(%) {
  551. my %args = %{$_[0]};
  552. my ($parameter, $section);
  553. my $count;
  554. print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
  555. print ".SH NAME\n";
  556. print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
  557. print ".SH SYNOPSIS\n";
  558. print "enum " . $args{'enum'} . " {\n";
  559. $count = 0;
  560. foreach my $parameter (@{$args{'parameterlist'}}) {
  561. print ".br\n.BI \" $parameter\"\n";
  562. if ($count == $#{$args{'parameterlist'}}) {
  563. print "\n};\n";
  564. last;
  565. } else {
  566. print ", \n.br\n";
  567. }
  568. $count++;
  569. }
  570. print ".SH Constants\n";
  571. foreach $parameter (@{$args{'parameterlist'}}) {
  572. my $parameter_name = $parameter;
  573. $parameter_name =~ s/\[.*//;
  574. print ".IP \"" . $parameter . "\" 12\n";
  575. output_highlight($args{'parameterdescs'}{$parameter_name});
  576. }
  577. foreach $section (@{$args{'sectionlist'}}) {
  578. print ".SH \"$section\"\n";
  579. output_highlight($args{'sections'}{$section});
  580. }
  581. }
  582. ##
  583. # output struct in man
  584. sub output_struct_man(%) {
  585. my %args = %{$_[0]};
  586. my ($parameter, $section);
  587. print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
  588. print ".SH NAME\n";
  589. print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
  590. my $declaration = $args{'definition'};
  591. $declaration =~ s/\t/ /g;
  592. $declaration =~ s/\n/"\n.br\n.BI \"/g;
  593. print ".SH SYNOPSIS\n";
  594. print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
  595. print ".BI \"$declaration\n};\n.br\n\n";
  596. print ".SH Members\n";
  597. foreach $parameter (@{$args{'parameterlist'}}) {
  598. ($parameter =~ /^#/) && next;
  599. my $parameter_name = $parameter;
  600. $parameter_name =~ s/\[.*//;
  601. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  602. print ".IP \"" . $parameter . "\" 12\n";
  603. output_highlight($args{'parameterdescs'}{$parameter_name});
  604. }
  605. foreach $section (@{$args{'sectionlist'}}) {
  606. print ".SH \"$section\"\n";
  607. output_highlight($args{'sections'}{$section});
  608. }
  609. }
  610. ##
  611. # output typedef in man
  612. sub output_typedef_man(%) {
  613. my %args = %{$_[0]};
  614. my ($parameter, $section);
  615. print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
  616. print ".SH NAME\n";
  617. print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
  618. foreach $section (@{$args{'sectionlist'}}) {
  619. print ".SH \"$section\"\n";
  620. output_highlight($args{'sections'}{$section});
  621. }
  622. }
  623. sub output_blockhead_man(%) {
  624. my %args = %{$_[0]};
  625. my ($parameter, $section);
  626. my $count;
  627. print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
  628. foreach $section (@{$args{'sectionlist'}}) {
  629. print ".SH \"$section\"\n";
  630. output_highlight($args{'sections'}{$section});
  631. }
  632. }
  633. ##
  634. # output in restructured text
  635. #
  636. #
  637. # This could use some work; it's used to output the DOC: sections, and
  638. # starts by putting out the name of the doc section itself, but that tends
  639. # to duplicate a header already in the template file.
  640. #
  641. sub output_blockhead_rst(%) {
  642. my %args = %{$_[0]};
  643. my ($parameter, $section);
  644. foreach $section (@{$args{'sectionlist'}}) {
  645. next if (defined($nosymbol_table{$section}));
  646. if ($output_selection != OUTPUT_INCLUDE) {
  647. print ".. _$section:\n\n";
  648. print "**$section**\n\n";
  649. }
  650. print_lineno($section_start_lines{$section});
  651. output_highlight_rst($args{'sections'}{$section});
  652. print "\n";
  653. }
  654. }
  655. #
  656. # Apply the RST highlights to a sub-block of text.
  657. #
  658. sub highlight_block($) {
  659. # The dohighlight kludge requires the text be called $contents
  660. my $contents = shift;
  661. eval $dohighlight;
  662. die $@ if $@;
  663. return $contents;
  664. }
  665. #
  666. # Regexes used only here.
  667. #
  668. my $sphinx_literal = '^[^.].*::$';
  669. my $sphinx_cblock = '^\.\.\ +code-block::';
  670. sub output_highlight_rst {
  671. my $input = join "\n",@_;
  672. my $output = "";
  673. my $line;
  674. my $in_literal = 0;
  675. my $litprefix;
  676. my $block = "";
  677. foreach $line (split "\n",$input) {
  678. #
  679. # If we're in a literal block, see if we should drop out
  680. # of it. Otherwise pass the line straight through unmunged.
  681. #
  682. if ($in_literal) {
  683. if (! ($line =~ /^\s*$/)) {
  684. #
  685. # If this is the first non-blank line in a literal
  686. # block we need to figure out what the proper indent is.
  687. #
  688. if ($litprefix eq "") {
  689. $line =~ /^(\s*)/;
  690. $litprefix = '^' . $1;
  691. $output .= $line . "\n";
  692. } elsif (! ($line =~ /$litprefix/)) {
  693. $in_literal = 0;
  694. } else {
  695. $output .= $line . "\n";
  696. }
  697. } else {
  698. $output .= $line . "\n";
  699. }
  700. }
  701. #
  702. # Not in a literal block (or just dropped out)
  703. #
  704. if (! $in_literal) {
  705. $block .= $line . "\n";
  706. if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) {
  707. $in_literal = 1;
  708. $litprefix = "";
  709. $output .= highlight_block($block);
  710. $block = ""
  711. }
  712. }
  713. }
  714. if ($block) {
  715. $output .= highlight_block($block);
  716. }
  717. foreach $line (split "\n", $output) {
  718. print $lineprefix . $line . "\n";
  719. }
  720. }
  721. sub output_function_rst(%) {
  722. my %args = %{$_[0]};
  723. my ($parameter, $section);
  724. my $oldprefix = $lineprefix;
  725. my $signature = "";
  726. my $func_macro = $args{'func_macro'};
  727. my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
  728. if ($func_macro) {
  729. $signature = $args{'function'};
  730. } else {
  731. if ($args{'functiontype'}) {
  732. $signature = $args{'functiontype'} . " ";
  733. }
  734. $signature .= $args{'function'} . " (";
  735. }
  736. my $count = 0;
  737. foreach my $parameter (@{$args{'parameterlist'}}) {
  738. if ($count ne 0) {
  739. $signature .= ", ";
  740. }
  741. $count++;
  742. $type = $args{'parametertypes'}{$parameter};
  743. if ($type =~ m/$function_pointer/) {
  744. # pointer-to-function
  745. $signature .= $1 . $parameter . ") (" . $2 . ")";
  746. } else {
  747. $signature .= $type;
  748. }
  749. }
  750. if (!$func_macro) {
  751. $signature .= ")";
  752. }
  753. if ($sphinx_major < 3) {
  754. if ($args{'typedef'}) {
  755. print ".. c:type:: ". $args{'function'} . "\n\n";
  756. print_lineno($declaration_start_line);
  757. print " **Typedef**: ";
  758. $lineprefix = "";
  759. output_highlight_rst($args{'purpose'});
  760. print "\n\n**Syntax**\n\n";
  761. print " ``$signature``\n\n";
  762. } else {
  763. print ".. c:function:: $signature\n\n";
  764. }
  765. } else {
  766. if ($args{'typedef'} || $args{'functiontype'} eq "") {
  767. print ".. c:macro:: ". $args{'function'} . "\n\n";
  768. if ($args{'typedef'}) {
  769. print_lineno($declaration_start_line);
  770. print " **Typedef**: ";
  771. $lineprefix = "";
  772. output_highlight_rst($args{'purpose'});
  773. print "\n\n**Syntax**\n\n";
  774. print " ``$signature``\n\n";
  775. } else {
  776. print "``$signature``\n\n";
  777. }
  778. } else {
  779. print ".. c:function:: $signature\n\n";
  780. }
  781. }
  782. if (!$args{'typedef'}) {
  783. print_lineno($declaration_start_line);
  784. $lineprefix = " ";
  785. output_highlight_rst($args{'purpose'});
  786. print "\n";
  787. }
  788. #
  789. # Put our descriptive text into a container (thus an HTML <div>) to help
  790. # set the function prototypes apart.
  791. #
  792. $lineprefix = " ";
  793. if ($paramcount >= 0) {
  794. print ".. container:: kernelindent\n\n";
  795. print $lineprefix . "**Parameters**\n\n";
  796. }
  797. foreach $parameter (@{$args{'parameterlist'}}) {
  798. my $parameter_name = $parameter;
  799. $parameter_name =~ s/\[.*//;
  800. $type = $args{'parametertypes'}{$parameter};
  801. if ($type ne "") {
  802. print $lineprefix . "``$type``\n";
  803. } else {
  804. print $lineprefix . "``$parameter``\n";
  805. }
  806. print_lineno($parameterdesc_start_lines{$parameter_name});
  807. $lineprefix = " ";
  808. if (defined($args{'parameterdescs'}{$parameter_name}) &&
  809. $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
  810. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  811. } else {
  812. print $lineprefix . "*undescribed*\n";
  813. }
  814. $lineprefix = " ";
  815. print "\n";
  816. }
  817. output_section_rst(@_);
  818. $lineprefix = $oldprefix;
  819. }
  820. sub output_section_rst(%) {
  821. my %args = %{$_[0]};
  822. my $section;
  823. my $oldprefix = $lineprefix;
  824. foreach $section (@{$args{'sectionlist'}}) {
  825. print $lineprefix . "**$section**\n\n";
  826. print_lineno($section_start_lines{$section});
  827. output_highlight_rst($args{'sections'}{$section});
  828. print "\n";
  829. }
  830. print "\n";
  831. }
  832. sub output_enum_rst(%) {
  833. my %args = %{$_[0]};
  834. my ($parameter);
  835. my $oldprefix = $lineprefix;
  836. my $count;
  837. my $outer;
  838. if ($sphinx_major < 3) {
  839. my $name = "enum " . $args{'enum'};
  840. print "\n\n.. c:type:: " . $name . "\n\n";
  841. } else {
  842. my $name = $args{'enum'};
  843. print "\n\n.. c:enum:: " . $name . "\n\n";
  844. }
  845. print_lineno($declaration_start_line);
  846. $lineprefix = " ";
  847. output_highlight_rst($args{'purpose'});
  848. print "\n";
  849. print ".. container:: kernelindent\n\n";
  850. $outer = $lineprefix . " ";
  851. $lineprefix = $outer . " ";
  852. print $outer . "**Constants**\n\n";
  853. foreach $parameter (@{$args{'parameterlist'}}) {
  854. print $outer . "``$parameter``\n";
  855. if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
  856. output_highlight_rst($args{'parameterdescs'}{$parameter});
  857. } else {
  858. print $lineprefix . "*undescribed*\n";
  859. }
  860. print "\n";
  861. }
  862. print "\n";
  863. $lineprefix = $oldprefix;
  864. output_section_rst(@_);
  865. }
  866. sub output_typedef_rst(%) {
  867. my %args = %{$_[0]};
  868. my ($parameter);
  869. my $oldprefix = $lineprefix;
  870. my $name;
  871. if ($sphinx_major < 3) {
  872. $name = "typedef " . $args{'typedef'};
  873. } else {
  874. $name = $args{'typedef'};
  875. }
  876. print "\n\n.. c:type:: " . $name . "\n\n";
  877. print_lineno($declaration_start_line);
  878. $lineprefix = " ";
  879. output_highlight_rst($args{'purpose'});
  880. print "\n";
  881. $lineprefix = $oldprefix;
  882. output_section_rst(@_);
  883. }
  884. sub output_struct_rst(%) {
  885. my %args = %{$_[0]};
  886. my ($parameter);
  887. my $oldprefix = $lineprefix;
  888. if ($sphinx_major < 3) {
  889. my $name = $args{'type'} . " " . $args{'struct'};
  890. print "\n\n.. c:type:: " . $name . "\n\n";
  891. } else {
  892. my $name = $args{'struct'};
  893. if ($args{'type'} eq 'union') {
  894. print "\n\n.. c:union:: " . $name . "\n\n";
  895. } else {
  896. print "\n\n.. c:struct:: " . $name . "\n\n";
  897. }
  898. }
  899. print_lineno($declaration_start_line);
  900. $lineprefix = " ";
  901. output_highlight_rst($args{'purpose'});
  902. print "\n";
  903. print ".. container:: kernelindent\n\n";
  904. print $lineprefix . "**Definition**::\n\n";
  905. my $declaration = $args{'definition'};
  906. $lineprefix = $lineprefix . " ";
  907. $declaration =~ s/\t/$lineprefix/g;
  908. print $lineprefix . $args{'type'} . " " . $args{'struct'} . " {\n$declaration" . $lineprefix . "};\n\n";
  909. $lineprefix = " ";
  910. print $lineprefix . "**Members**\n\n";
  911. foreach $parameter (@{$args{'parameterlist'}}) {
  912. ($parameter =~ /^#/) && next;
  913. my $parameter_name = $parameter;
  914. $parameter_name =~ s/\[.*//;
  915. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  916. $type = $args{'parametertypes'}{$parameter};
  917. print_lineno($parameterdesc_start_lines{$parameter_name});
  918. print $lineprefix . "``" . $parameter . "``\n";
  919. $lineprefix = " ";
  920. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  921. $lineprefix = " ";
  922. print "\n";
  923. }
  924. print "\n";
  925. $lineprefix = $oldprefix;
  926. output_section_rst(@_);
  927. }
  928. ## none mode output functions
  929. sub output_function_none(%) {
  930. }
  931. sub output_enum_none(%) {
  932. }
  933. sub output_typedef_none(%) {
  934. }
  935. sub output_struct_none(%) {
  936. }
  937. sub output_blockhead_none(%) {
  938. }
  939. ##
  940. # generic output function for all types (function, struct/union, typedef, enum);
  941. # calls the generated, variable output_ function name based on
  942. # functype and output_mode
  943. sub output_declaration {
  944. no strict 'refs';
  945. my $name = shift;
  946. my $functype = shift;
  947. my $func = "output_${functype}_$output_mode";
  948. return if (defined($nosymbol_table{$name}));
  949. if (($output_selection == OUTPUT_ALL) ||
  950. (($output_selection == OUTPUT_INCLUDE ||
  951. $output_selection == OUTPUT_EXPORTED) &&
  952. defined($function_table{$name})) ||
  953. ($output_selection == OUTPUT_INTERNAL &&
  954. !($functype eq "function" && defined($function_table{$name}))))
  955. {
  956. &$func(@_);
  957. $section_counter++;
  958. }
  959. }
  960. ##
  961. # generic output function - calls the right one based on current output mode.
  962. sub output_blockhead {
  963. no strict 'refs';
  964. my $func = "output_blockhead_" . $output_mode;
  965. &$func(@_);
  966. $section_counter++;
  967. }
  968. ##
  969. # takes a declaration (struct, union, enum, typedef) and
  970. # invokes the right handler. NOT called for functions.
  971. sub dump_declaration($$) {
  972. no strict 'refs';
  973. my ($prototype, $file) = @_;
  974. my $func = "dump_" . $decl_type;
  975. &$func(@_);
  976. }
  977. sub dump_union($$) {
  978. dump_struct(@_);
  979. }
  980. sub dump_struct($$) {
  981. my $x = shift;
  982. my $file = shift;
  983. my $decl_type;
  984. my $members;
  985. my $type = qr{struct|union};
  986. # For capturing struct/union definition body, i.e. "{members*}qualifiers*"
  987. my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned};
  988. my $definition_body = qr{\{(.*)\}\s*$qualifiers*};
  989. my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;};
  990. if ($x =~ /($type)\s+(\w+)\s*$definition_body/) {
  991. $decl_type = $1;
  992. $declaration_name = $2;
  993. $members = $3;
  994. } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) {
  995. $decl_type = $1;
  996. $declaration_name = $3;
  997. $members = $2;
  998. }
  999. if ($members) {
  1000. if ($identifier ne $declaration_name) {
  1001. emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n");
  1002. return;
  1003. }
  1004. # ignore members marked private:
  1005. $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
  1006. $members =~ s/\/\*\s*private:.*//gosi;
  1007. # strip comments:
  1008. $members =~ s/\/\*.*?\*\///gos;
  1009. # strip attributes
  1010. $members =~ s/\s*$attribute/ /gi;
  1011. $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos;
  1012. $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos;
  1013. $members =~ s/\s*__counted_by_(le|be)\s*\([^;]*\)/ /gos;
  1014. $members =~ s/\s*__packed\s*/ /gos;
  1015. $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos;
  1016. $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;
  1017. $members =~ s/\s*____cacheline_aligned/ /gos;
  1018. # unwrap struct_group():
  1019. # - first eat non-declaration parameters and rewrite for final match
  1020. # - then remove macro, outer parens, and trailing semicolon
  1021. $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos;
  1022. $members =~ s/\bstruct_group_attr\s*\(([^,]*,){2}/STRUCT_GROUP(/gos;
  1023. $members =~ s/\bstruct_group_tagged\s*\(([^,]*),([^,]*),/struct $1 $2; STRUCT_GROUP(/gos;
  1024. $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos;
  1025. $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos;
  1026. my $args = qr{([^,)]+)};
  1027. # replace DECLARE_BITMAP
  1028. $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos;
  1029. $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos;
  1030. $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
  1031. # replace DECLARE_HASHTABLE
  1032. $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
  1033. # replace DECLARE_KFIFO
  1034. $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos;
  1035. # replace DECLARE_KFIFO_PTR
  1036. $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos;
  1037. # replace DECLARE_FLEX_ARRAY
  1038. $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos;
  1039. #replace DEFINE_DMA_UNMAP_ADDR
  1040. $members =~ s/DEFINE_DMA_UNMAP_ADDR\s*\($args\)/dma_addr_t $1/gos;
  1041. #replace DEFINE_DMA_UNMAP_LEN
  1042. $members =~ s/DEFINE_DMA_UNMAP_LEN\s*\($args\)/__u32 $1/gos;
  1043. my $declaration = $members;
  1044. # Split nested struct/union elements as newer ones
  1045. while ($members =~ m/$struct_members/) {
  1046. my $newmember;
  1047. my $maintype = $1;
  1048. my $ids = $4;
  1049. my $content = $3;
  1050. foreach my $id(split /,/, $ids) {
  1051. $newmember .= "$maintype $id; ";
  1052. $id =~ s/[:\[].*//;
  1053. $id =~ s/^\s*\**(\S+)\s*/$1/;
  1054. foreach my $arg (split /;/, $content) {
  1055. next if ($arg =~ m/^\s*$/);
  1056. if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) {
  1057. # pointer-to-function
  1058. my $type = $1;
  1059. my $name = $2;
  1060. my $extra = $3;
  1061. next if (!$name);
  1062. if ($id =~ m/^\s*$/) {
  1063. # anonymous struct/union
  1064. $newmember .= "$type$name$extra; ";
  1065. } else {
  1066. $newmember .= "$type$id.$name$extra; ";
  1067. }
  1068. } else {
  1069. my $type;
  1070. my $names;
  1071. $arg =~ s/^\s+//;
  1072. $arg =~ s/\s+$//;
  1073. # Handle bitmaps
  1074. $arg =~ s/:\s*\d+\s*//g;
  1075. # Handle arrays
  1076. $arg =~ s/\[.*\]//g;
  1077. # The type may have multiple words,
  1078. # and multiple IDs can be defined, like:
  1079. # const struct foo, *bar, foobar
  1080. # So, we remove spaces when parsing the
  1081. # names, in order to match just names
  1082. # and commas for the names
  1083. $arg =~ s/\s*,\s*/,/g;
  1084. if ($arg =~ m/(.*)\s+([\S+,]+)/) {
  1085. $type = $1;
  1086. $names = $2;
  1087. } else {
  1088. $newmember .= "$arg; ";
  1089. next;
  1090. }
  1091. foreach my $name (split /,/, $names) {
  1092. $name =~ s/^\s*\**(\S+)\s*/$1/;
  1093. next if (($name =~ m/^\s*$/));
  1094. if ($id =~ m/^\s*$/) {
  1095. # anonymous struct/union
  1096. $newmember .= "$type $name; ";
  1097. } else {
  1098. $newmember .= "$type $id.$name; ";
  1099. }
  1100. }
  1101. }
  1102. }
  1103. }
  1104. $members =~ s/$struct_members/$newmember/;
  1105. }
  1106. # Ignore other nested elements, like enums
  1107. $members =~ s/(\{[^\{\}]*\})//g;
  1108. create_parameterlist($members, ';', $file, $declaration_name);
  1109. check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
  1110. # Adjust declaration for better display
  1111. $declaration =~ s/([\{;])/$1\n/g;
  1112. $declaration =~ s/\}\s+;/};/g;
  1113. # Better handle inlined enums
  1114. do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);
  1115. my @def_args = split /\n/, $declaration;
  1116. my $level = 1;
  1117. $declaration = "";
  1118. foreach my $clause (@def_args) {
  1119. $clause =~ s/^\s+//;
  1120. $clause =~ s/\s+$//;
  1121. $clause =~ s/\s+/ /;
  1122. next if (!$clause);
  1123. $level-- if ($clause =~ m/(\})/ && $level > 1);
  1124. if (!($clause =~ m/^\s*#/)) {
  1125. $declaration .= "\t" x $level;
  1126. }
  1127. $declaration .= "\t" . $clause . "\n";
  1128. $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
  1129. }
  1130. output_declaration($declaration_name,
  1131. 'struct',
  1132. {'struct' => $declaration_name,
  1133. 'module' => $modulename,
  1134. 'definition' => $declaration,
  1135. 'parameterlist' => \@parameterlist,
  1136. 'parameterdescs' => \%parameterdescs,
  1137. 'parametertypes' => \%parametertypes,
  1138. 'sectionlist' => \@sectionlist,
  1139. 'sections' => \%sections,
  1140. 'purpose' => $declaration_purpose,
  1141. 'type' => $decl_type
  1142. });
  1143. } else {
  1144. print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
  1145. ++$errors;
  1146. }
  1147. }
  1148. sub show_warnings($$) {
  1149. my $functype = shift;
  1150. my $name = shift;
  1151. return 0 if (defined($nosymbol_table{$name}));
  1152. return 1 if ($output_selection == OUTPUT_ALL);
  1153. if ($output_selection == OUTPUT_EXPORTED) {
  1154. if (defined($function_table{$name})) {
  1155. return 1;
  1156. } else {
  1157. return 0;
  1158. }
  1159. }
  1160. if ($output_selection == OUTPUT_INTERNAL) {
  1161. if (!($functype eq "function" && defined($function_table{$name}))) {
  1162. return 1;
  1163. } else {
  1164. return 0;
  1165. }
  1166. }
  1167. if ($output_selection == OUTPUT_INCLUDE) {
  1168. if (defined($function_table{$name})) {
  1169. return 1;
  1170. } else {
  1171. return 0;
  1172. }
  1173. }
  1174. die("Please add the new output type at show_warnings()");
  1175. }
  1176. sub dump_enum($$) {
  1177. my $x = shift;
  1178. my $file = shift;
  1179. my $members;
  1180. # ignore members marked private:
  1181. $x =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
  1182. $x =~ s/\/\*\s*private:.*}/}/gosi;
  1183. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1184. # strip #define macros inside enums
  1185. $x =~ s@#\s*((define|ifdef|if)\s+|endif)[^;]*;@@gos;
  1186. if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) {
  1187. $declaration_name = $2;
  1188. $members = $1;
  1189. } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) {
  1190. $declaration_name = $1;
  1191. $members = $2;
  1192. }
  1193. if ($members) {
  1194. if ($identifier ne $declaration_name) {
  1195. if ($identifier eq "") {
  1196. emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n");
  1197. } else {
  1198. emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n");
  1199. }
  1200. return;
  1201. }
  1202. $declaration_name = "(anonymous)" if ($declaration_name eq "");
  1203. my %_members;
  1204. $members =~ s/\s+$//;
  1205. $members =~ s/\([^;]*?[\)]//g;
  1206. foreach my $arg (split ',', $members) {
  1207. $arg =~ s/^\s*(\w+).*/$1/;
  1208. push @parameterlist, $arg;
  1209. if (!$parameterdescs{$arg}) {
  1210. $parameterdescs{$arg} = $undescribed;
  1211. if (show_warnings("enum", $declaration_name)) {
  1212. emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n");
  1213. }
  1214. }
  1215. $_members{$arg} = 1;
  1216. }
  1217. while (my ($k, $v) = each %parameterdescs) {
  1218. if (!exists($_members{$k})) {
  1219. if (show_warnings("enum", $declaration_name)) {
  1220. emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n");
  1221. }
  1222. }
  1223. }
  1224. output_declaration($declaration_name,
  1225. 'enum',
  1226. {'enum' => $declaration_name,
  1227. 'module' => $modulename,
  1228. 'parameterlist' => \@parameterlist,
  1229. 'parameterdescs' => \%parameterdescs,
  1230. 'sectionlist' => \@sectionlist,
  1231. 'sections' => \%sections,
  1232. 'purpose' => $declaration_purpose
  1233. });
  1234. } else {
  1235. print STDERR "${file}:$.: error: Cannot parse enum!\n";
  1236. ++$errors;
  1237. }
  1238. }
  1239. my $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x;
  1240. my $typedef_ident = qr { \*?\s*(\w\S+)\s* }x;
  1241. my $typedef_args = qr { \s*\((.*)\); }x;
  1242. my $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x;
  1243. my $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x;
  1244. sub dump_typedef($$) {
  1245. my $x = shift;
  1246. my $file = shift;
  1247. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1248. # Parse function typedef prototypes
  1249. if ($x =~ $typedef1 || $x =~ $typedef2) {
  1250. $return_type = $1;
  1251. $declaration_name = $2;
  1252. my $args = $3;
  1253. $return_type =~ s/^\s+//;
  1254. if ($identifier ne $declaration_name) {
  1255. emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n");
  1256. return;
  1257. }
  1258. create_parameterlist($args, ',', $file, $declaration_name);
  1259. output_declaration($declaration_name,
  1260. 'function',
  1261. {'function' => $declaration_name,
  1262. 'typedef' => 1,
  1263. 'module' => $modulename,
  1264. 'functiontype' => $return_type,
  1265. 'parameterlist' => \@parameterlist,
  1266. 'parameterdescs' => \%parameterdescs,
  1267. 'parametertypes' => \%parametertypes,
  1268. 'sectionlist' => \@sectionlist,
  1269. 'sections' => \%sections,
  1270. 'purpose' => $declaration_purpose
  1271. });
  1272. return;
  1273. }
  1274. while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
  1275. $x =~ s/\(*.\)\s*;$/;/;
  1276. $x =~ s/\[*.\]\s*;$/;/;
  1277. }
  1278. if ($x =~ /typedef.*\s+(\w+)\s*;/) {
  1279. $declaration_name = $1;
  1280. if ($identifier ne $declaration_name) {
  1281. emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n");
  1282. return;
  1283. }
  1284. output_declaration($declaration_name,
  1285. 'typedef',
  1286. {'typedef' => $declaration_name,
  1287. 'module' => $modulename,
  1288. 'sectionlist' => \@sectionlist,
  1289. 'sections' => \%sections,
  1290. 'purpose' => $declaration_purpose
  1291. });
  1292. } else {
  1293. print STDERR "${file}:$.: error: Cannot parse typedef!\n";
  1294. ++$errors;
  1295. }
  1296. }
  1297. sub save_struct_actual($) {
  1298. my $actual = shift;
  1299. # strip all spaces from the actual param so that it looks like one string item
  1300. $actual =~ s/\s*//g;
  1301. $struct_actual = $struct_actual . $actual . " ";
  1302. }
  1303. sub create_parameterlist($$$$) {
  1304. my $args = shift;
  1305. my $splitter = shift;
  1306. my $file = shift;
  1307. my $declaration_name = shift;
  1308. my $type;
  1309. my $param;
  1310. # temporarily replace commas inside function pointer definition
  1311. my $arg_expr = qr{\([^\),]+};
  1312. while ($args =~ /$arg_expr,/) {
  1313. $args =~ s/($arg_expr),/$1#/g;
  1314. }
  1315. foreach my $arg (split($splitter, $args)) {
  1316. # strip comments
  1317. $arg =~ s/\/\*.*\*\///;
  1318. # ignore argument attributes
  1319. $arg =~ s/\sPOS0?\s/ /;
  1320. # strip leading/trailing spaces
  1321. $arg =~ s/^\s*//;
  1322. $arg =~ s/\s*$//;
  1323. $arg =~ s/\s+/ /;
  1324. if ($arg =~ /^#/) {
  1325. # Treat preprocessor directive as a typeless variable just to fill
  1326. # corresponding data structures "correctly". Catch it later in
  1327. # output_* subs.
  1328. push_parameter($arg, "", "", $file);
  1329. } elsif ($arg =~ m/\(.+\)\s*\(/) {
  1330. # pointer-to-function
  1331. $arg =~ tr/#/,/;
  1332. $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/;
  1333. $param = $1;
  1334. $type = $arg;
  1335. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1336. save_struct_actual($param);
  1337. push_parameter($param, $type, $arg, $file, $declaration_name);
  1338. } elsif ($arg =~ m/\(.+\)\s*\[/) {
  1339. # array-of-pointers
  1340. $arg =~ tr/#/,/;
  1341. $arg =~ m/[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)/;
  1342. $param = $1;
  1343. $type = $arg;
  1344. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1345. save_struct_actual($param);
  1346. push_parameter($param, $type, $arg, $file, $declaration_name);
  1347. } elsif ($arg) {
  1348. $arg =~ s/\s*:\s*/:/g;
  1349. $arg =~ s/\s*\[/\[/g;
  1350. my @args = split('\s*,\s*', $arg);
  1351. if ($args[0] =~ m/\*/) {
  1352. $args[0] =~ s/(\*+)\s*/ $1/;
  1353. }
  1354. my @first_arg;
  1355. if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
  1356. shift @args;
  1357. push(@first_arg, split('\s+', $1));
  1358. push(@first_arg, $2);
  1359. } else {
  1360. @first_arg = split('\s+', shift @args);
  1361. }
  1362. unshift(@args, pop @first_arg);
  1363. $type = join " ", @first_arg;
  1364. foreach $param (@args) {
  1365. if ($param =~ m/^(\*+)\s*(.*)/) {
  1366. save_struct_actual($2);
  1367. push_parameter($2, "$type $1", $arg, $file, $declaration_name);
  1368. } elsif ($param =~ m/(.*?):(\w+)/) {
  1369. if ($type ne "") { # skip unnamed bit-fields
  1370. save_struct_actual($1);
  1371. push_parameter($1, "$type:$2", $arg, $file, $declaration_name)
  1372. }
  1373. } else {
  1374. save_struct_actual($param);
  1375. push_parameter($param, $type, $arg, $file, $declaration_name);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. sub push_parameter($$$$$) {
  1382. my $param = shift;
  1383. my $type = shift;
  1384. my $org_arg = shift;
  1385. my $file = shift;
  1386. my $declaration_name = shift;
  1387. if (($anon_struct_union == 1) && ($type eq "") &&
  1388. ($param eq "}")) {
  1389. return; # ignore the ending }; from anon. struct/union
  1390. }
  1391. $anon_struct_union = 0;
  1392. $param =~ s/[\[\)].*//;
  1393. if ($type eq "" && $param =~ /\.\.\.$/)
  1394. {
  1395. if (!$param =~ /\w\.\.\.$/) {
  1396. # handles unnamed variable parameters
  1397. $param = "...";
  1398. } elsif ($param =~ /\w\.\.\.$/) {
  1399. # for named variable parameters of the form `x...`, remove the dots
  1400. $param =~ s/\.\.\.$//;
  1401. }
  1402. if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
  1403. $parameterdescs{$param} = "variable arguments";
  1404. }
  1405. }
  1406. elsif ($type eq "" && ($param eq "" or $param eq "void"))
  1407. {
  1408. $param="void";
  1409. $parameterdescs{void} = "no arguments";
  1410. }
  1411. elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
  1412. # handle unnamed (anonymous) union or struct:
  1413. {
  1414. $type = $param;
  1415. $param = "{unnamed_" . $param . "}";
  1416. $parameterdescs{$param} = "anonymous\n";
  1417. $anon_struct_union = 1;
  1418. }
  1419. elsif ($param =~ "__cacheline_group" )
  1420. # handle cache group enforcing variables: they do not need be described in header files
  1421. {
  1422. return; # ignore __cacheline_group_begin and __cacheline_group_end
  1423. }
  1424. # warn if parameter has no description
  1425. # (but ignore ones starting with # as these are not parameters
  1426. # but inline preprocessor statements);
  1427. # Note: It will also ignore void params and unnamed structs/unions
  1428. if (!defined $parameterdescs{$param} && $param !~ /^#/) {
  1429. $parameterdescs{$param} = $undescribed;
  1430. if (show_warnings($type, $declaration_name) && $param !~ /\./) {
  1431. emit_warning("${file}:$.", "Function parameter or struct member '$param' not described in '$declaration_name'\n");
  1432. }
  1433. }
  1434. # strip spaces from $param so that it is one continuous string
  1435. # on @parameterlist;
  1436. # this fixes a problem where check_sections() cannot find
  1437. # a parameter like "addr[6 + 2]" because it actually appears
  1438. # as "addr[6", "+", "2]" on the parameter list;
  1439. # but it's better to maintain the param string unchanged for output,
  1440. # so just weaken the string compare in check_sections() to ignore
  1441. # "[blah" in a parameter string;
  1442. ###$param =~ s/\s*//g;
  1443. push @parameterlist, $param;
  1444. $org_arg =~ s/\s\s+/ /g;
  1445. $parametertypes{$param} = $org_arg;
  1446. }
  1447. sub check_sections($$$$$) {
  1448. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_;
  1449. my @sects = split ' ', $sectcheck;
  1450. my @prms = split ' ', $prmscheck;
  1451. my $err;
  1452. my ($px, $sx);
  1453. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  1454. foreach $sx (0 .. $#sects) {
  1455. $err = 1;
  1456. foreach $px (0 .. $#prms) {
  1457. $prm_clean = $prms[$px];
  1458. $prm_clean =~ s/\[.*\]//;
  1459. $prm_clean =~ s/$attribute//i;
  1460. # ignore array size in a parameter string;
  1461. # however, the original param string may contain
  1462. # spaces, e.g.: addr[6 + 2]
  1463. # and this appears in @prms as "addr[6" since the
  1464. # parameter list is split at spaces;
  1465. # hence just ignore "[..." for the sections check;
  1466. $prm_clean =~ s/\[.*//;
  1467. ##$prm_clean =~ s/^\**//;
  1468. if ($prm_clean eq $sects[$sx]) {
  1469. $err = 0;
  1470. last;
  1471. }
  1472. }
  1473. if ($err) {
  1474. if ($decl_type eq "function") {
  1475. emit_warning("${file}:$.",
  1476. "Excess function parameter " .
  1477. "'$sects[$sx]' " .
  1478. "description in '$decl_name'\n");
  1479. } elsif (($decl_type eq "struct") or
  1480. ($decl_type eq "union")) {
  1481. emit_warning("${file}:$.",
  1482. "Excess $decl_type member " .
  1483. "'$sects[$sx]' " .
  1484. "description in '$decl_name'\n");
  1485. }
  1486. }
  1487. }
  1488. }
  1489. ##
  1490. # Checks the section describing the return value of a function.
  1491. sub check_return_section {
  1492. my $file = shift;
  1493. my $declaration_name = shift;
  1494. my $return_type = shift;
  1495. # Ignore an empty return type (It's a macro)
  1496. # Ignore functions with a "void" return type. (But don't ignore "void *")
  1497. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  1498. return;
  1499. }
  1500. if (!defined($sections{$section_return}) ||
  1501. $sections{$section_return} eq "")
  1502. {
  1503. emit_warning("${file}:$.",
  1504. "No description found for return value of " .
  1505. "'$declaration_name'\n");
  1506. }
  1507. }
  1508. ##
  1509. # takes a function prototype and the name of the current file being
  1510. # processed and spits out all the details stored in the global
  1511. # arrays/hashes.
  1512. sub dump_function($$) {
  1513. my $prototype = shift;
  1514. my $file = shift;
  1515. my $func_macro = 0;
  1516. print_lineno($new_start_line);
  1517. $prototype =~ s/^static +//;
  1518. $prototype =~ s/^extern +//;
  1519. $prototype =~ s/^asmlinkage +//;
  1520. $prototype =~ s/^inline +//;
  1521. $prototype =~ s/^__inline__ +//;
  1522. $prototype =~ s/^__inline +//;
  1523. $prototype =~ s/^__always_inline +//;
  1524. $prototype =~ s/^noinline +//;
  1525. $prototype =~ s/^__FORTIFY_INLINE +//;
  1526. $prototype =~ s/__init +//;
  1527. $prototype =~ s/__init_or_module +//;
  1528. $prototype =~ s/__deprecated +//;
  1529. $prototype =~ s/__flatten +//;
  1530. $prototype =~ s/__meminit +//;
  1531. $prototype =~ s/__must_check +//;
  1532. $prototype =~ s/__weak +//;
  1533. $prototype =~ s/__sched +//;
  1534. $prototype =~ s/_noprof//;
  1535. $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
  1536. $prototype =~ s/__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//;
  1537. $prototype =~ s/__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +//;
  1538. $prototype =~ s/DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)/$1, $2/;
  1539. my $define = $prototype =~ s/^#\s*define\s+//; #ak added
  1540. $prototype =~ s/__attribute_const__ +//;
  1541. $prototype =~ s/__attribute__\s*\(\(
  1542. (?:
  1543. [\w\s]++ # attribute name
  1544. (?:\([^)]*+\))? # attribute arguments
  1545. \s*+,? # optional comma at the end
  1546. )+
  1547. \)\)\s+//x;
  1548. # Yes, this truly is vile. We are looking for:
  1549. # 1. Return type (may be nothing if we're looking at a macro)
  1550. # 2. Function name
  1551. # 3. Function parameters.
  1552. #
  1553. # All the while we have to watch out for function pointer parameters
  1554. # (which IIRC is what the two sections are for), C types (these
  1555. # regexps don't even start to express all the possibilities), and
  1556. # so on.
  1557. #
  1558. # If you mess with these regexps, it's a good idea to check that
  1559. # the following functions' documentation still comes out right:
  1560. # - parport_register_device (function pointer parameters)
  1561. # - atomic_set (macro)
  1562. # - pci_match_device, __copy_to_user (long return type)
  1563. my $name = qr{[a-zA-Z0-9_~:]+};
  1564. my $prototype_end1 = qr{[^\(]*};
  1565. my $prototype_end2 = qr{[^\{]*};
  1566. my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)};
  1567. my $type1 = qr{[\w\s]+};
  1568. my $type2 = qr{$type1\*+};
  1569. if ($define && $prototype =~ m/^()($name)\s+/) {
  1570. # This is an object-like macro, it has no return type and no parameter
  1571. # list.
  1572. # Function-like macros are not allowed to have spaces between
  1573. # declaration_name and opening parenthesis (notice the \s+).
  1574. $return_type = $1;
  1575. $declaration_name = $2;
  1576. $func_macro = 1;
  1577. } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ ||
  1578. $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ ||
  1579. $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) {
  1580. $return_type = $1;
  1581. $declaration_name = $2;
  1582. my $args = $3;
  1583. create_parameterlist($args, ',', $file, $declaration_name);
  1584. } else {
  1585. emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n");
  1586. return;
  1587. }
  1588. if ($identifier ne $declaration_name) {
  1589. emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n");
  1590. return;
  1591. }
  1592. my $prms = join " ", @parameterlist;
  1593. check_sections($file, $declaration_name, "function", $sectcheck, $prms);
  1594. # This check emits a lot of warnings at the moment, because many
  1595. # functions don't have a 'Return' doc section. So until the number
  1596. # of warnings goes sufficiently down, the check is only performed in
  1597. # -Wreturn mode.
  1598. # TODO: always perform the check.
  1599. if ($Wreturn && !$func_macro) {
  1600. check_return_section($file, $declaration_name, $return_type);
  1601. }
  1602. # The function parser can be called with a typedef parameter.
  1603. # Handle it.
  1604. if ($return_type =~ /typedef/) {
  1605. output_declaration($declaration_name,
  1606. 'function',
  1607. {'function' => $declaration_name,
  1608. 'typedef' => 1,
  1609. 'module' => $modulename,
  1610. 'functiontype' => $return_type,
  1611. 'parameterlist' => \@parameterlist,
  1612. 'parameterdescs' => \%parameterdescs,
  1613. 'parametertypes' => \%parametertypes,
  1614. 'sectionlist' => \@sectionlist,
  1615. 'sections' => \%sections,
  1616. 'purpose' => $declaration_purpose,
  1617. 'func_macro' => $func_macro
  1618. });
  1619. } else {
  1620. output_declaration($declaration_name,
  1621. 'function',
  1622. {'function' => $declaration_name,
  1623. 'module' => $modulename,
  1624. 'functiontype' => $return_type,
  1625. 'parameterlist' => \@parameterlist,
  1626. 'parameterdescs' => \%parameterdescs,
  1627. 'parametertypes' => \%parametertypes,
  1628. 'sectionlist' => \@sectionlist,
  1629. 'sections' => \%sections,
  1630. 'purpose' => $declaration_purpose,
  1631. 'func_macro' => $func_macro
  1632. });
  1633. }
  1634. }
  1635. sub reset_state {
  1636. $function = "";
  1637. %parameterdescs = ();
  1638. %parametertypes = ();
  1639. @parameterlist = ();
  1640. %sections = ();
  1641. @sectionlist = ();
  1642. $sectcheck = "";
  1643. $struct_actual = "";
  1644. $prototype = "";
  1645. $state = STATE_NORMAL;
  1646. $inline_doc_state = STATE_INLINE_NA;
  1647. }
  1648. sub tracepoint_munge($) {
  1649. my $file = shift;
  1650. my $tracepointname = 0;
  1651. my $tracepointargs = 0;
  1652. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  1653. $tracepointname = $1;
  1654. }
  1655. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  1656. $tracepointname = $1;
  1657. }
  1658. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  1659. $tracepointname = $2;
  1660. }
  1661. $tracepointname =~ s/^\s+//; #strip leading whitespace
  1662. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  1663. $tracepointargs = $1;
  1664. }
  1665. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  1666. emit_warning("${file}:$.", "Unrecognized tracepoint format: \n".
  1667. "$prototype\n");
  1668. } else {
  1669. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  1670. $identifier = "trace_$identifier";
  1671. }
  1672. }
  1673. sub syscall_munge() {
  1674. my $void = 0;
  1675. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's
  1676. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  1677. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  1678. $void = 1;
  1679. ## $prototype = "long sys_$1(void)";
  1680. }
  1681. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  1682. if ($prototype =~ m/long (sys_.*?),/) {
  1683. $prototype =~ s/,/\(/;
  1684. } elsif ($void) {
  1685. $prototype =~ s/\)/\(void\)/;
  1686. }
  1687. # now delete all of the odd-number commas in $prototype
  1688. # so that arg types & arg names don't have a comma between them
  1689. my $count = 0;
  1690. my $len = length($prototype);
  1691. if ($void) {
  1692. $len = 0; # skip the for-loop
  1693. }
  1694. for (my $ix = 0; $ix < $len; $ix++) {
  1695. if (substr($prototype, $ix, 1) eq ',') {
  1696. $count++;
  1697. if ($count % 2 == 1) {
  1698. substr($prototype, $ix, 1) = ' ';
  1699. }
  1700. }
  1701. }
  1702. }
  1703. sub process_proto_function($$) {
  1704. my $x = shift;
  1705. my $file = shift;
  1706. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1707. if ($x =~ /^#/ && $x !~ /^#\s*define/) {
  1708. # do nothing
  1709. } elsif ($x =~ /([^\{]*)/) {
  1710. $prototype .= $1;
  1711. }
  1712. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  1713. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  1714. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1715. $prototype =~ s@^\s+@@gos; # strip leading spaces
  1716. # Handle prototypes for function pointers like:
  1717. # int (*pcs_config)(struct foo)
  1718. $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos;
  1719. if ($prototype =~ /SYSCALL_DEFINE/) {
  1720. syscall_munge();
  1721. }
  1722. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  1723. $prototype =~ /DEFINE_SINGLE_EVENT/)
  1724. {
  1725. tracepoint_munge($file);
  1726. }
  1727. dump_function($prototype, $file);
  1728. reset_state();
  1729. }
  1730. }
  1731. sub process_proto_type($$) {
  1732. my $x = shift;
  1733. my $file = shift;
  1734. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  1735. $x =~ s@^\s+@@gos; # strip leading spaces
  1736. $x =~ s@\s+$@@gos; # strip trailing spaces
  1737. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  1738. if ($x =~ /^#/) {
  1739. # To distinguish preprocessor directive from regular declaration later.
  1740. $x .= ";";
  1741. }
  1742. while (1) {
  1743. if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
  1744. if( length $prototype ) {
  1745. $prototype .= " "
  1746. }
  1747. $prototype .= $1 . $2;
  1748. ($2 eq '{') && $brcount++;
  1749. ($2 eq '}') && $brcount--;
  1750. if (($2 eq ';') && ($brcount == 0)) {
  1751. dump_declaration($prototype, $file);
  1752. reset_state();
  1753. last;
  1754. }
  1755. $x = $3;
  1756. } else {
  1757. $prototype .= $x;
  1758. last;
  1759. }
  1760. }
  1761. }
  1762. sub map_filename($) {
  1763. my $file;
  1764. my ($orig_file) = @_;
  1765. if (defined($ENV{'SRCTREE'})) {
  1766. $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
  1767. } else {
  1768. $file = $orig_file;
  1769. }
  1770. if (defined($source_map{$file})) {
  1771. $file = $source_map{$file};
  1772. }
  1773. return $file;
  1774. }
  1775. sub process_export_file($) {
  1776. my ($orig_file) = @_;
  1777. my $file = map_filename($orig_file);
  1778. if (!open(IN,"<$file")) {
  1779. print STDERR "Error: Cannot open file $file\n";
  1780. ++$errors;
  1781. return;
  1782. }
  1783. while (<IN>) {
  1784. if (/$export_symbol/) {
  1785. next if (defined($nosymbol_table{$2}));
  1786. $function_table{$2} = 1;
  1787. }
  1788. if (/$export_symbol_ns/) {
  1789. next if (defined($nosymbol_table{$2}));
  1790. $function_table{$2} = 1;
  1791. }
  1792. }
  1793. close(IN);
  1794. }
  1795. #
  1796. # Parsers for the various processing states.
  1797. #
  1798. # STATE_NORMAL: looking for the /** to begin everything.
  1799. #
  1800. sub process_normal() {
  1801. if (/$doc_start/o) {
  1802. $state = STATE_NAME; # next line is always the function name
  1803. $in_doc_sect = 0;
  1804. $declaration_start_line = $. + 1;
  1805. }
  1806. }
  1807. #
  1808. # STATE_NAME: Looking for the "name - description" line
  1809. #
  1810. sub process_name($$) {
  1811. my $file = shift;
  1812. my $descr;
  1813. if (/$doc_block/o) {
  1814. $state = STATE_DOCBLOCK;
  1815. $contents = "";
  1816. $new_start_line = $.;
  1817. if ( $1 eq "" ) {
  1818. $section = $section_intro;
  1819. } else {
  1820. $section = $1;
  1821. }
  1822. } elsif (/$doc_decl/o) {
  1823. $identifier = $1;
  1824. my $is_kernel_comment = 0;
  1825. my $decl_start = qr{$doc_com};
  1826. # test for pointer declaration type, foo * bar() - desc
  1827. my $fn_type = qr{\w+\s*\*\s*};
  1828. my $parenthesis = qr{\(\w*\)};
  1829. my $decl_end = qr{[-:].*};
  1830. if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) {
  1831. $identifier = $1;
  1832. }
  1833. if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) {
  1834. $decl_type = $1;
  1835. $identifier = $2;
  1836. $is_kernel_comment = 1;
  1837. }
  1838. # Look for foo() or static void foo() - description; or misspelt
  1839. # identifier
  1840. elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||
  1841. /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) {
  1842. $identifier = $1;
  1843. $decl_type = 'function';
  1844. $identifier =~ s/^define\s+//;
  1845. $is_kernel_comment = 1;
  1846. }
  1847. $identifier =~ s/\s+$//;
  1848. $state = STATE_BODY;
  1849. # if there's no @param blocks need to set up default section
  1850. # here
  1851. $contents = "";
  1852. $section = $section_default;
  1853. $new_start_line = $. + 1;
  1854. if (/[-:](.*)/) {
  1855. # strip leading/trailing/multiple spaces
  1856. $descr= $1;
  1857. $descr =~ s/^\s*//;
  1858. $descr =~ s/\s*$//;
  1859. $descr =~ s/\s+/ /g;
  1860. $declaration_purpose = $descr;
  1861. $state = STATE_BODY_MAYBE;
  1862. } else {
  1863. $declaration_purpose = "";
  1864. }
  1865. if (!$is_kernel_comment) {
  1866. emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_");
  1867. $state = STATE_NORMAL;
  1868. }
  1869. if (($declaration_purpose eq "") && $Wshort_desc) {
  1870. emit_warning("${file}:$.", "missing initial short description on line:\n$_");
  1871. }
  1872. if ($identifier eq "" && $decl_type ne "enum") {
  1873. emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_");
  1874. $state = STATE_NORMAL;
  1875. }
  1876. if ($verbose) {
  1877. print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n";
  1878. }
  1879. } else {
  1880. emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n");
  1881. $state = STATE_NORMAL;
  1882. }
  1883. }
  1884. #
  1885. # STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment.
  1886. #
  1887. sub process_body($$) {
  1888. my $file = shift;
  1889. if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) {
  1890. dump_section($file, $section, $contents);
  1891. $section = $section_default;
  1892. $new_start_line = $.;
  1893. $contents = "";
  1894. }
  1895. if (/$doc_sect/i) { # case insensitive for supported section names
  1896. $in_doc_sect = 1;
  1897. $newsection = $1;
  1898. $newcontents = $2;
  1899. # map the supported section names to the canonical names
  1900. if ($newsection =~ m/^description$/i) {
  1901. $newsection = $section_default;
  1902. } elsif ($newsection =~ m/^context$/i) {
  1903. $newsection = $section_context;
  1904. } elsif ($newsection =~ m/^returns?$/i) {
  1905. $newsection = $section_return;
  1906. } elsif ($newsection =~ m/^\@return$/) {
  1907. # special: @return is a section, not a param description
  1908. $newsection = $section_return;
  1909. }
  1910. if (($contents ne "") && ($contents ne "\n")) {
  1911. if (!$in_doc_sect && $Wcontents_before_sections) {
  1912. emit_warning("${file}:$.", "contents before sections\n");
  1913. }
  1914. dump_section($file, $section, $contents);
  1915. $section = $section_default;
  1916. }
  1917. $in_doc_sect = 1;
  1918. $state = STATE_BODY;
  1919. $contents = $newcontents;
  1920. $new_start_line = $.;
  1921. while (substr($contents, 0, 1) eq " ") {
  1922. $contents = substr($contents, 1);
  1923. }
  1924. if ($contents ne "") {
  1925. $contents .= "\n";
  1926. }
  1927. $section = $newsection;
  1928. $leading_space = undef;
  1929. } elsif (/$doc_end/) {
  1930. if (($contents ne "") && ($contents ne "\n")) {
  1931. dump_section($file, $section, $contents);
  1932. $section = $section_default;
  1933. $contents = "";
  1934. }
  1935. # look for doc_com + <text> + doc_end:
  1936. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  1937. emit_warning("${file}:$.", "suspicious ending line: $_");
  1938. }
  1939. $prototype = "";
  1940. $state = STATE_PROTO;
  1941. $brcount = 0;
  1942. $new_start_line = $. + 1;
  1943. } elsif (/$doc_content/) {
  1944. if ($1 eq "") {
  1945. if ($section eq $section_context) {
  1946. dump_section($file, $section, $contents);
  1947. $section = $section_default;
  1948. $contents = "";
  1949. $new_start_line = $.;
  1950. $state = STATE_BODY;
  1951. } else {
  1952. if ($section ne $section_default) {
  1953. $state = STATE_BODY_WITH_BLANK_LINE;
  1954. } else {
  1955. $state = STATE_BODY;
  1956. }
  1957. $contents .= "\n";
  1958. }
  1959. } elsif ($state == STATE_BODY_MAYBE) {
  1960. # Continued declaration purpose
  1961. chomp($declaration_purpose);
  1962. $declaration_purpose .= " " . $1;
  1963. $declaration_purpose =~ s/\s+/ /g;
  1964. } else {
  1965. my $cont = $1;
  1966. if ($section =~ m/^@/ || $section eq $section_context) {
  1967. if (!defined $leading_space) {
  1968. if ($cont =~ m/^(\s+)/) {
  1969. $leading_space = $1;
  1970. } else {
  1971. $leading_space = "";
  1972. }
  1973. }
  1974. $cont =~ s/^$leading_space//;
  1975. }
  1976. $contents .= $cont . "\n";
  1977. }
  1978. } else {
  1979. # i dont know - bad line? ignore.
  1980. emit_warning("${file}:$.", "bad line: $_");
  1981. }
  1982. }
  1983. #
  1984. # STATE_PROTO: reading a function/whatever prototype.
  1985. #
  1986. sub process_proto($$) {
  1987. my $file = shift;
  1988. if (/$doc_inline_oneline/) {
  1989. $section = $1;
  1990. $contents = $2;
  1991. if ($contents ne "") {
  1992. $contents .= "\n";
  1993. dump_section($file, $section, $contents);
  1994. $section = $section_default;
  1995. $contents = "";
  1996. }
  1997. } elsif (/$doc_inline_start/) {
  1998. $state = STATE_INLINE;
  1999. $inline_doc_state = STATE_INLINE_NAME;
  2000. } elsif ($decl_type eq 'function') {
  2001. process_proto_function($_, $file);
  2002. } else {
  2003. process_proto_type($_, $file);
  2004. }
  2005. }
  2006. #
  2007. # STATE_DOCBLOCK: within a DOC: block.
  2008. #
  2009. sub process_docblock($$) {
  2010. my $file = shift;
  2011. if (/$doc_end/) {
  2012. dump_doc_section($file, $section, $contents);
  2013. $section = $section_default;
  2014. $contents = "";
  2015. $function = "";
  2016. %parameterdescs = ();
  2017. %parametertypes = ();
  2018. @parameterlist = ();
  2019. %sections = ();
  2020. @sectionlist = ();
  2021. $prototype = "";
  2022. $state = STATE_NORMAL;
  2023. } elsif (/$doc_content/) {
  2024. if ( $1 eq "" ) {
  2025. $contents .= $blankline;
  2026. } else {
  2027. $contents .= $1 . "\n";
  2028. }
  2029. }
  2030. }
  2031. #
  2032. # STATE_INLINE: docbook comments within a prototype.
  2033. #
  2034. sub process_inline($$) {
  2035. my $file = shift;
  2036. # First line (state 1) needs to be a @parameter
  2037. if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
  2038. $section = $1;
  2039. $contents = $2;
  2040. $new_start_line = $.;
  2041. if ($contents ne "") {
  2042. while (substr($contents, 0, 1) eq " ") {
  2043. $contents = substr($contents, 1);
  2044. }
  2045. $contents .= "\n";
  2046. }
  2047. $inline_doc_state = STATE_INLINE_TEXT;
  2048. # Documentation block end */
  2049. } elsif (/$doc_inline_end/) {
  2050. if (($contents ne "") && ($contents ne "\n")) {
  2051. dump_section($file, $section, $contents);
  2052. $section = $section_default;
  2053. $contents = "";
  2054. }
  2055. $state = STATE_PROTO;
  2056. $inline_doc_state = STATE_INLINE_NA;
  2057. # Regular text
  2058. } elsif (/$doc_content/) {
  2059. if ($inline_doc_state == STATE_INLINE_TEXT) {
  2060. $contents .= $1 . "\n";
  2061. # nuke leading blank lines
  2062. if ($contents =~ /^\s*$/) {
  2063. $contents = "";
  2064. }
  2065. } elsif ($inline_doc_state == STATE_INLINE_NAME) {
  2066. $inline_doc_state = STATE_INLINE_ERROR;
  2067. emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_");
  2068. }
  2069. }
  2070. }
  2071. sub process_file($) {
  2072. my $file;
  2073. my ($orig_file) = @_;
  2074. $file = map_filename($orig_file);
  2075. if (!open(IN_FILE,"<$file")) {
  2076. print STDERR "Error: Cannot open file $file\n";
  2077. ++$errors;
  2078. return;
  2079. }
  2080. $. = 1;
  2081. $section_counter = 0;
  2082. while (<IN_FILE>) {
  2083. while (!/^ \*/ && s/\\\s*$//) {
  2084. $_ .= <IN_FILE>;
  2085. }
  2086. # Replace tabs by spaces
  2087. while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
  2088. # Hand this line to the appropriate state handler
  2089. if ($state == STATE_NORMAL) {
  2090. process_normal();
  2091. } elsif ($state == STATE_NAME) {
  2092. process_name($file, $_);
  2093. } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE ||
  2094. $state == STATE_BODY_WITH_BLANK_LINE) {
  2095. process_body($file, $_);
  2096. } elsif ($state == STATE_INLINE) { # scanning for inline parameters
  2097. process_inline($file, $_);
  2098. } elsif ($state == STATE_PROTO) {
  2099. process_proto($file, $_);
  2100. } elsif ($state == STATE_DOCBLOCK) {
  2101. process_docblock($file, $_);
  2102. }
  2103. }
  2104. # Make sure we got something interesting.
  2105. if (!$section_counter && $output_mode ne "none") {
  2106. if ($output_selection == OUTPUT_INCLUDE) {
  2107. emit_warning("${file}:1", "'$_' not found\n")
  2108. for keys %function_table;
  2109. } else {
  2110. emit_warning("${file}:1", "no structured comments found\n");
  2111. }
  2112. }
  2113. close IN_FILE;
  2114. }
  2115. if ($output_mode eq "rst") {
  2116. get_sphinx_version() if (!$sphinx_major);
  2117. }
  2118. $kernelversion = get_kernel_version();
  2119. # generate a sequence of code that will splice in highlighting information
  2120. # using the s// operator.
  2121. for (my $k = 0; $k < @highlights; $k++) {
  2122. my $pattern = $highlights[$k][0];
  2123. my $result = $highlights[$k][1];
  2124. # print STDERR "scanning pattern:$pattern, highlight:($result)\n";
  2125. $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
  2126. }
  2127. # Read the file that maps relative names to absolute names for
  2128. # separate source and object directories and for shadow trees.
  2129. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2130. my ($relname, $absname);
  2131. while(<SOURCE_MAP>) {
  2132. chop();
  2133. ($relname, $absname) = (split())[0..1];
  2134. $relname =~ s:^/+::;
  2135. $source_map{$relname} = $absname;
  2136. }
  2137. close(SOURCE_MAP);
  2138. }
  2139. if ($output_selection == OUTPUT_EXPORTED ||
  2140. $output_selection == OUTPUT_INTERNAL) {
  2141. push(@export_file_list, @ARGV);
  2142. foreach (@export_file_list) {
  2143. chomp;
  2144. process_export_file($_);
  2145. }
  2146. }
  2147. foreach (@ARGV) {
  2148. chomp;
  2149. process_file($_);
  2150. }
  2151. if ($verbose && $errors) {
  2152. print STDERR "$errors errors\n";
  2153. }
  2154. if ($verbose && $warnings) {
  2155. print STDERR "$warnings warnings\n";
  2156. }
  2157. if ($Werror && $warnings) {
  2158. print STDERR "$warnings warnings as Errors\n";
  2159. exit($warnings);
  2160. } else {
  2161. exit($output_mode eq "none" ? 0 : $errors)
  2162. }
  2163. __END__
  2164. =head1 OPTIONS
  2165. =head2 Output format selection (mutually exclusive):
  2166. =over 8
  2167. =item -man
  2168. Output troff manual page format.
  2169. =item -rst
  2170. Output reStructuredText format. This is the default.
  2171. =item -none
  2172. Do not output documentation, only warnings.
  2173. =back
  2174. =head2 Output format modifiers
  2175. =head3 reStructuredText only
  2176. =over 8
  2177. =item -sphinx-version VERSION
  2178. Use the ReST C domain dialect compatible with a specific Sphinx Version.
  2179. If not specified, kernel-doc will auto-detect using the sphinx-build version
  2180. found on PATH.
  2181. =back
  2182. =head2 Output selection (mutually exclusive):
  2183. =over 8
  2184. =item -export
  2185. Only output documentation for the symbols that have been exported using
  2186. EXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE.
  2187. =item -internal
  2188. Only output documentation for the symbols that have NOT been exported using
  2189. EXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE.
  2190. =item -function NAME
  2191. Only output documentation for the given function or DOC: section title.
  2192. All other functions and DOC: sections are ignored.
  2193. May be specified multiple times.
  2194. =item -nosymbol NAME
  2195. Exclude the specified symbol from the output documentation.
  2196. May be specified multiple times.
  2197. =back
  2198. =head2 Output selection modifiers:
  2199. =over 8
  2200. =item -no-doc-sections
  2201. Do not output DOC: sections.
  2202. =item -export-file FILE
  2203. Specify an additional FILE in which to look for EXPORT_SYMBOL information.
  2204. To be used with -export or -internal.
  2205. May be specified multiple times.
  2206. =back
  2207. =head3 reStructuredText only
  2208. =over 8
  2209. =item -enable-lineno
  2210. Enable output of .. LINENO lines.
  2211. =back
  2212. =head2 Other parameters:
  2213. =over 8
  2214. =item -h, -help
  2215. Print this help.
  2216. =item -v
  2217. Verbose output, more warnings and other information.
  2218. =item -Werror
  2219. Treat warnings as errors.
  2220. =back
  2221. =cut