aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kernel-doc
diff options
context:
space:
mode:
authorJani Nikula <jani.nikula@intel.com>2016-05-29 04:35:28 -0400
committerJani Nikula <jani.nikula@intel.com>2016-05-30 06:39:03 -0400
commitf624adef3d0b9975076c1ba7549b81ed19e34437 (patch)
treeae4daa883a857b6ec178d1b9371ca9fe9f68889c /scripts/kernel-doc
parentcddfe325afedb67a15fbe1a91e82ffed40236413 (diff)
kernel-doc: limit the "section header:" detection to a select few
kernel-doc currently identifies anything matching "section header:" (specifically a string of word characters and spaces followed by a colon) as a new section in the documentation comment, and renders the section header accordingly. Unfortunately, this turns all uses of colon into sections, mostly unintentionally. Considering the output, erroneously creating sections when not intended is always worse than erroneously not creating sections when intended. For example, a line with "http://example.com" turns into a "http" heading followed by "//example.com" in normal text style, which is quite ugly. OTOH, "WARNING: Beware of the Leopard" is just fine even if "WARNING" does not turn into a heading. It is virtually impossible to change all the kernel-doc comments, either way. The compromise is to pick the most commonly used and depended on section headers (with variants) and accept them as section headers. The accepted section headers are, case insensitive: * description: * context: * return: * returns: Additionally, case sensitive: * @return: All of the above are commonly used in the kernel-doc comments, and will result in worse output if not identified as section headers. Also, kernel-doc already has some special handling for all of them, so there's nothing particularly controversial in adding more special treatment for them. While at it, improve the whitespace handling surrounding section names. Do not consider the whitespace as part of the name. Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Diffstat (limited to 'scripts/kernel-doc')
-rwxr-xr-xscripts/kernel-doc19
1 files changed, 17 insertions, 2 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 425a94be04f6..20136564f264 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -401,7 +401,8 @@ my $doc_end = '\*/';
401my $doc_com = '\s*\*\s*'; 401my $doc_com = '\s*\*\s*';
402my $doc_com_body = '\s*\* ?'; 402my $doc_com_body = '\s*\* ?';
403my $doc_decl = $doc_com . '(\w+)'; 403my $doc_decl = $doc_com . '(\w+)';
404my $doc_sect = $doc_com . '(\@?[\w\s]+):(.*)'; 404# @params and a strictly limited set of supported section names
405my $doc_sect = $doc_com . '\s*(\@\w+|description|context|returns?)\s*:(.*)';
405my $doc_content = $doc_com_body . '(.*)'; 406my $doc_content = $doc_com_body . '(.*)';
406my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 407my $doc_block = $doc_com . 'DOC:\s*(.*)?';
407my $doc_inline_start = '^\s*/\*\*\s*$'; 408my $doc_inline_start = '^\s*/\*\*\s*$';
@@ -417,6 +418,8 @@ my $sectcheck;
417my $struct_actual; 418my $struct_actual;
418 419
419my $contents = ""; 420my $contents = "";
421
422# the canonical section names. see also $doc_sect above.
420my $section_default = "Description"; # default section 423my $section_default = "Description"; # default section
421my $section_intro = "Introduction"; 424my $section_intro = "Introduction";
422my $section = $section_default; 425my $section = $section_default;
@@ -2798,10 +2801,22 @@ sub process_file($) {
2798 $state = STATE_NORMAL; 2801 $state = STATE_NORMAL;
2799 } 2802 }
2800 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 2803 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
2801 if (/$doc_sect/o) { 2804 if (/$doc_sect/i) { # case insensitive for supported section names
2802 $newsection = $1; 2805 $newsection = $1;
2803 $newcontents = $2; 2806 $newcontents = $2;
2804 2807
2808 # map the supported section names to the canonical names
2809 if ($newsection =~ m/^description$/i) {
2810 $newsection = $section_default;
2811 } elsif ($newsection =~ m/^context$/i) {
2812 $newsection = $section_context;
2813 } elsif ($newsection =~ m/^returns?$/i) {
2814 $newsection = $section_return;
2815 } elsif ($newsection =~ m/^\@return$/) {
2816 # special: @return is a section, not a param description
2817 $newsection = $section_return;
2818 }
2819
2805 if (($contents ne "") && ($contents ne "\n")) { 2820 if (($contents ne "") && ($contents ne "\n")) {
2806 if (!$in_doc_sect && $verbose) { 2821 if (!$in_doc_sect && $verbose) {
2807 print STDERR "${file}:$.: warning: contents before sections\n"; 2822 print STDERR "${file}:$.: warning: contents before sections\n";