浏览代码

kernel-doc: don't mangle whitespace in Example section

A section with the name "Example" (case-insensitive) has a special meaning
to kernel-doc.  These sections are output using mono-type fonts.  However,
leading whitespace is stripped, thus robbing a lot of meaning from this,
as indented code examples will be mangled.

This patch preserves the leading whitespace for "Example" sections.  More
accurately, it preserves it for all sections, but removes it later if the
section isn't an "Example" section.

Signed-off-by: Daniel Santos <daniel.santos@pobox.com>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Cc: Michal Marek <mmarek@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Daniel Santos 13 年之前
父节点
当前提交
12ae677933
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      scripts/kernel-doc

+ 7 - 2
scripts/kernel-doc

@@ -281,9 +281,10 @@ my $doc_special = "\@\%\$\&";
 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
 my $doc_end = '\*/';
 my $doc_end = '\*/';
 my $doc_com = '\s*\*\s*';
 my $doc_com = '\s*\*\s*';
+my $doc_com_body = '\s*\* ?';
 my $doc_decl = $doc_com . '(\w+)';
 my $doc_decl = $doc_com . '(\w+)';
 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
 my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
-my $doc_content = $doc_com . '(.*)';
+my $doc_content = $doc_com_body . '(.*)';
 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
 my $doc_block = $doc_com . 'DOC:\s*(.*)?';
 
 
 my %constants;
 my %constants;
@@ -460,6 +461,9 @@ sub output_highlight {
 #   print STDERR "contents af:$contents\n";
 #   print STDERR "contents af:$contents\n";
 
 
     foreach $line (split "\n", $contents) {
     foreach $line (split "\n", $contents) {
+	if (! $output_preformatted) {
+	    $line =~ s/^\s*//;
+	}
 	if ($line eq ""){
 	if ($line eq ""){
 	    if (! $output_preformatted) {
 	    if (! $output_preformatted) {
 		print $lineprefix, local_unescape($blankline);
 		print $lineprefix, local_unescape($blankline);
@@ -2085,7 +2089,7 @@ sub process_file($) {
 		    $descr= $1;
 		    $descr= $1;
 		    $descr =~ s/^\s*//;
 		    $descr =~ s/^\s*//;
 		    $descr =~ s/\s*$//;
 		    $descr =~ s/\s*$//;
-		    $descr =~ s/\s+/ /;
+		    $descr =~ s/\s+/ /g;
 		    $declaration_purpose = xml_escape($descr);
 		    $declaration_purpose = xml_escape($descr);
 		    $in_purpose = 1;
 		    $in_purpose = 1;
 		} else {
 		} else {
@@ -2177,6 +2181,7 @@ sub process_file($) {
 		    # Continued declaration purpose
 		    # Continued declaration purpose
 		    chomp($declaration_purpose);
 		    chomp($declaration_purpose);
 		    $declaration_purpose .= " " . xml_escape($1);
 		    $declaration_purpose .= " " . xml_escape($1);
+		    $declaration_purpose =~ s/\s+/ /g;
 		} else {
 		} else {
 		    $contents .= $1 . "\n";
 		    $contents .= $1 . "\n";
 		}
 		}