History

docs: kernel-doc: Move STATE_BODY processing to a separate function

Also group the pseudo-global $leading_space variable with its peers.

Jonathan Corbet committed 8 years ago

Commit d742f241 parent 3cac2bc1 file · +101 −92Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/kernel-doc+101−92
@@ -336,6 +336,7 @@ use constant { · 335 unmodified lines
336336 };
337337 my $state;
338338 my $in_doc_sect;
339+my $leading_space;
339340
340341 # Inline documentation state
341342 use constant {
@@ -1865,12 +1866,110 @@ sub process_name($$) { · 1523 unmodified lines
18651866 }
18661867 }
18671868
1869+
1870+#
1871+# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment.
1872+#
1873+sub process_body($$) {
1874+ my $file = shift;
1875+
1876+ if (/$doc_sect/i) { # case insensitive for supported section names
1877+ $newsection = $1;
1878+ $newcontents = $2;
1879+
1880+ # map the supported section names to the canonical names
1881+ if ($newsection =~ m/^description$/i) {
1882+ $newsection = $section_default;
1883+ } elsif ($newsection =~ m/^context$/i) {
1884+ $newsection = $section_context;
1885+ } elsif ($newsection =~ m/^returns?$/i) {
1886+ $newsection = $section_return;
1887+ } elsif ($newsection =~ m/^\@return$/) {
1888+ # special: @return is a section, not a param description
1889+ $newsection = $section_return;
1890+ }
1891+
1892+ if (($contents ne "") && ($contents ne "\n")) {
1893+ if (!$in_doc_sect && $verbose) {
1894+ print STDERR "${file}:$.: warning: contents before sections\n";
1895+ ++$warnings;
1896+ }
1897+ dump_section($file, $section, $contents);
1898+ $section = $section_default;
1899+ }
1900+
1901+ $in_doc_sect = 1;
1902+ $state = STATE_BODY;
1903+ $contents = $newcontents;
1904+ $new_start_line = $.;
1905+ while (substr($contents, 0, 1) eq " ") {
1906+ $contents = substr($contents, 1);
1907+ }
1908+ if ($contents ne "") {
1909+ $contents .= "\n";
1910+ }
1911+ $section = $newsection;
1912+ $leading_space = undef;
1913+ } elsif (/$doc_end/) {
1914+ if (($contents ne "") && ($contents ne "\n")) {
1915+ dump_section($file, $section, $contents);
1916+ $section = $section_default;
1917+ $contents = "";
1918+ }
1919+ # look for doc_com + <text> + doc_end:
1920+ if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
1921+ print STDERR "${file}:$.: warning: suspicious ending line: $_";
1922+ ++$warnings;
1923+ }
1924+
1925+ $prototype = "";
1926+ $state = STATE_PROTO;
1927+ $brcount = 0;
1928+ } elsif (/$doc_content/) {
1929+ # miguel-style comment kludge, look for blank lines after
1930+ # @parameter line to signify start of description
1931+ if ($1 eq "") {
1932+ if ($section =~ m/^@/ || $section eq $section_context) {
1933+ dump_section($file, $section, $contents);
1934+ $section = $section_default;
1935+ $contents = "";
1936+ $new_start_line = $.;
1937+ } else {
1938+ $contents .= "\n";
1939+ }
1940+ $state = STATE_BODY;
1941+ } elsif ($state == STATE_BODY_MAYBE) {
1942+ # Continued declaration purpose
1943+ chomp($declaration_purpose);
1944+ $declaration_purpose .= " " . $1;
1945+ $declaration_purpose =~ s/\s+/ /g;
1946+ } else {
1947+ my $cont = $1;
1948+ if ($section =~ m/^@/ || $section eq $section_context) {
1949+ if (!defined $leading_space) {
1950+ if ($cont =~ m/^(\s+)/) {
1951+ $leading_space = $1;
1952+ } else {
1953+ $leading_space = "";
1954+ }
1955+ }
1956+ $cont =~ s/^$leading_space//;
1957+ }
1958+ $contents .= $cont . "\n";
1959+ }
1960+ } else {
1961+ # i dont know - bad line? ignore.
1962+ print STDERR "${file}:$.: warning: bad line: $_";
1963+ ++$warnings;
1964+ }
1965+}
1966+
1967+
18681968 sub process_file($) {
18691969 my $file;
18701970 my $func;
18711971 my $initial_section_counter = $section_counter;
18721972 my ($orig_file) = @_;
1873− my $leading_space;
18741973
18751974 $file = map_filename($orig_file);
18761975
@@ -1894,97 +1993,7 @@ sub process_file($) { · 17 unmodified lines
18941993 } elsif ($state == STATE_NAME) {
18951994 process_name($file, $_);
18961995 } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) {
1897− if (/$doc_sect/i) { # case insensitive for supported section names
1898− $newsection = $1;
1899− $newcontents = $2;
1900−
1901− # map the supported section names to the canonical names
1902− if ($newsection =~ m/^description$/i) {
1903− $newsection = $section_default;
1904− } elsif ($newsection =~ m/^context$/i) {
1905− $newsection = $section_context;
1906− } elsif ($newsection =~ m/^returns?$/i) {
1907− $newsection = $section_return;
1908− } elsif ($newsection =~ m/^\@return$/) {
1909− # special: @return is a section, not a param description
1910− $newsection = $section_return;
1911− }
1912−
1913− if (($contents ne "") && ($contents ne "\n")) {
1914− if (!$in_doc_sect && $verbose) {
1915− print STDERR "${file}:$.: warning: contents before sections\n";
1916− ++$warnings;
1917− }
1918− dump_section($file, $section, $contents);
1919− $section = $section_default;
1920− }
1921−
1922− $in_doc_sect = 1;
1923− $state = STATE_BODY;
1924− $contents = $newcontents;
1925− $new_start_line = $.;
1926− while (substr($contents, 0, 1) eq " ") {
1927− $contents = substr($contents, 1);
1928− }
1929− if ($contents ne "") {
1930− $contents .= "\n";
1931− }
1932− $section = $newsection;
1933− $leading_space = undef;
1934− } elsif (/$doc_end/) {
1935− if (($contents ne "") && ($contents ne "\n")) {
1936− dump_section($file, $section, $contents);
1937− $section = $section_default;
1938− $contents = "";
1939− }
1940− # look for doc_com + <text> + doc_end:
1941− if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
1942− print STDERR "${file}:$.: warning: suspicious ending line: $_";
1943− ++$warnings;
1944− }
1945−
1946− $prototype = "";
1947− $state = STATE_PROTO;
1948− $brcount = 0;
1949−# print STDERR "end of doc comment, looking for prototype\n";
1950− } elsif (/$doc_content/) {
1951− # miguel-style comment kludge, look for blank lines after
1952− # @parameter line to signify start of description
1953− if ($1 eq "") {
1954− if ($section =~ m/^@/ || $section eq $section_context) {
1955− dump_section($file, $section, $contents);
1956− $section = $section_default;
1957− $contents = "";
1958− $new_start_line = $.;
1959− } else {
1960− $contents .= "\n";
1961− }
1962− $state = STATE_BODY;
1963− } elsif ($state == STATE_BODY_MAYBE) {
1964− # Continued declaration purpose
1965− chomp($declaration_purpose);
1966− $declaration_purpose .= " " . $1;
1967− $declaration_purpose =~ s/\s+/ /g;
1968− } else {
1969− my $cont = $1;
1970− if ($section =~ m/^@/ || $section eq $section_context) {
1971− if (!defined $leading_space) {
1972− if ($cont =~ m/^(\s+)/) {
1973− $leading_space = $1;
1974− } else {
1975− $leading_space = "";
1976− }
1977− }
1978−
1979− $cont =~ s/^$leading_space//;
1980− }
1981− $contents .= $cont . "\n";
1982− }
1983− } else {
1984− # i dont know - bad line? ignore.
1985− print STDERR "${file}:$.: warning: bad line: $_";
1986− ++$warnings;
1987− }
1996+ process_body($file, $_);
19881997 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
19891998 # First line (state 1) needs to be a @parameter
19901999 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t