diff options
| author | Jonathan Corbet <corbet@lwn.net> | 2018-02-05 16:36:33 -0500 |
|---|---|---|
| committer | Jonathan Corbet <corbet@lwn.net> | 2018-02-15 15:11:23 -0500 |
| commit | 3cac2bc41d1b4c51a1f31059bf65f4dc7cfb35f5 (patch) | |
| tree | cd50d1907ed9282aa78b9cae77e651b24318196a /scripts/kernel-doc | |
| parent | 07048d13136bc068efb20e1d3e372577c2ef6906 (diff) | |
docs: kernel-doc: Move STATE_NAME processing into its own function
Move this code out of process_file() in the name of readability and
maintainability.
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'scripts/kernel-doc')
| -rwxr-xr-x | scripts/kernel-doc | 137 |
1 files changed, 72 insertions, 65 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 65150b7c8472..a27c7016f72d 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
| @@ -1793,13 +1793,81 @@ sub process_normal() { | |||
| 1793 | } | 1793 | } |
| 1794 | } | 1794 | } |
| 1795 | 1795 | ||
| 1796 | # | ||
| 1797 | # STATE_NAME: Looking for the "name - description" line | ||
| 1798 | # | ||
| 1799 | sub process_name($$) { | ||
| 1800 | my $file = shift; | ||
| 1801 | my $identifier; | ||
| 1802 | my $descr; | ||
| 1803 | |||
| 1804 | if (/$doc_block/o) { | ||
| 1805 | $state = STATE_DOCBLOCK; | ||
| 1806 | $contents = ""; | ||
| 1807 | $new_start_line = $. + 1; | ||
| 1808 | |||
| 1809 | if ( $1 eq "" ) { | ||
| 1810 | $section = $section_intro; | ||
| 1811 | } else { | ||
| 1812 | $section = $1; | ||
| 1813 | } | ||
| 1814 | } | ||
| 1815 | elsif (/$doc_decl/o) { | ||
| 1816 | $identifier = $1; | ||
| 1817 | if (/\s*([\w\s]+?)\s*-/) { | ||
| 1818 | $identifier = $1; | ||
| 1819 | } | ||
| 1796 | 1820 | ||
| 1821 | $state = STATE_BODY; | ||
| 1822 | # if there's no @param blocks need to set up default section | ||
| 1823 | # here | ||
| 1824 | $contents = ""; | ||
| 1825 | $section = $section_default; | ||
| 1826 | $new_start_line = $. + 1; | ||
| 1827 | if (/-(.*)/) { | ||
| 1828 | # strip leading/trailing/multiple spaces | ||
| 1829 | $descr= $1; | ||
| 1830 | $descr =~ s/^\s*//; | ||
| 1831 | $descr =~ s/\s*$//; | ||
| 1832 | $descr =~ s/\s+/ /g; | ||
| 1833 | $declaration_purpose = $descr; | ||
| 1834 | $state = STATE_BODY_MAYBE; | ||
| 1835 | } else { | ||
| 1836 | $declaration_purpose = ""; | ||
| 1837 | } | ||
| 1838 | |||
| 1839 | if (($declaration_purpose eq "") && $verbose) { | ||
| 1840 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; | ||
| 1841 | print STDERR $_; | ||
| 1842 | ++$warnings; | ||
| 1843 | } | ||
| 1844 | |||
| 1845 | if ($identifier =~ m/^struct/) { | ||
| 1846 | $decl_type = 'struct'; | ||
| 1847 | } elsif ($identifier =~ m/^union/) { | ||
| 1848 | $decl_type = 'union'; | ||
| 1849 | } elsif ($identifier =~ m/^enum/) { | ||
| 1850 | $decl_type = 'enum'; | ||
| 1851 | } elsif ($identifier =~ m/^typedef/) { | ||
| 1852 | $decl_type = 'typedef'; | ||
| 1853 | } else { | ||
| 1854 | $decl_type = 'function'; | ||
| 1855 | } | ||
| 1856 | |||
| 1857 | if ($verbose) { | ||
| 1858 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; | ||
| 1859 | } | ||
| 1860 | } else { | ||
| 1861 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", | ||
| 1862 | " - I thought it was a doc line\n"; | ||
| 1863 | ++$warnings; | ||
| 1864 | $state = STATE_NORMAL; | ||
| 1865 | } | ||
| 1866 | } | ||
| 1797 | 1867 | ||
| 1798 | sub process_file($) { | 1868 | sub process_file($) { |
| 1799 | my $file; | 1869 | my $file; |
| 1800 | my $identifier; | ||
| 1801 | my $func; | 1870 | my $func; |
| 1802 | my $descr; | ||
| 1803 | my $initial_section_counter = $section_counter; | 1871 | my $initial_section_counter = $section_counter; |
| 1804 | my ($orig_file) = @_; | 1872 | my ($orig_file) = @_; |
| 1805 | my $leading_space; | 1873 | my $leading_space; |
| @@ -1823,69 +1891,8 @@ sub process_file($) { | |||
| 1823 | while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; | 1891 | while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; |
| 1824 | if ($state == STATE_NORMAL) { | 1892 | if ($state == STATE_NORMAL) { |
| 1825 | process_normal(); | 1893 | process_normal(); |
| 1826 | } elsif ($state == STATE_NAME) {# this line is the function name (always) | 1894 | } elsif ($state == STATE_NAME) { |
| 1827 | if (/$doc_block/o) { | 1895 | process_name($file, $_); |
| 1828 | $state = STATE_DOCBLOCK; | ||
| 1829 | $contents = ""; | ||
| 1830 | $new_start_line = $. + 1; | ||
| 1831 | |||
| 1832 | if ( $1 eq "" ) { | ||
| 1833 | $section = $section_intro; | ||
| 1834 | } else { | ||
| 1835 | $section = $1; | ||
| 1836 | } | ||
| 1837 | } | ||
| 1838 | elsif (/$doc_decl/o) { | ||
| 1839 | $identifier = $1; | ||
| 1840 | if (/\s*([\w\s]+?)\s*-/) { | ||
| 1841 | $identifier = $1; | ||
| 1842 | } | ||
| 1843 | |||
| 1844 | $state = STATE_BODY; | ||
| 1845 | # if there's no @param blocks need to set up default section | ||
| 1846 | # here | ||
| 1847 | $contents = ""; | ||
| 1848 | $section = $section_default; | ||
| 1849 | $new_start_line = $. + 1; | ||
| 1850 | if (/-(.*)/) { | ||
| 1851 | # strip leading/trailing/multiple spaces | ||
| 1852 | $descr= $1; | ||
| 1853 | $descr =~ s/^\s*//; | ||
| 1854 | $descr =~ s/\s*$//; | ||
| 1855 | $descr =~ s/\s+/ /g; | ||
| 1856 | $declaration_purpose = $descr; | ||
| 1857 | $state = STATE_BODY_MAYBE; | ||
| 1858 | } else { | ||
| 1859 | $declaration_purpose = ""; | ||
| 1860 | } | ||
| 1861 | |||
| 1862 | if (($declaration_purpose eq "") && $verbose) { | ||
| 1863 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; | ||
| 1864 | print STDERR $_; | ||
| 1865 | ++$warnings; | ||
| 1866 | } | ||
| 1867 | |||
| 1868 | if ($identifier =~ m/^struct/) { | ||
| 1869 | $decl_type = 'struct'; | ||
| 1870 | } elsif ($identifier =~ m/^union/) { | ||
| 1871 | $decl_type = 'union'; | ||
| 1872 | } elsif ($identifier =~ m/^enum/) { | ||
| 1873 | $decl_type = 'enum'; | ||
| 1874 | } elsif ($identifier =~ m/^typedef/) { | ||
| 1875 | $decl_type = 'typedef'; | ||
| 1876 | } else { | ||
| 1877 | $decl_type = 'function'; | ||
| 1878 | } | ||
| 1879 | |||
| 1880 | if ($verbose) { | ||
| 1881 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; | ||
| 1882 | } | ||
| 1883 | } else { | ||
| 1884 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", | ||
| 1885 | " - I thought it was a doc line\n"; | ||
| 1886 | ++$warnings; | ||
| 1887 | $state = STATE_NORMAL; | ||
| 1888 | } | ||
| 1889 | } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { | 1896 | } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { |
| 1890 | if (/$doc_sect/i) { # case insensitive for supported section names | 1897 | if (/$doc_sect/i) { # case insensitive for supported section names |
| 1891 | $newsection = $1; | 1898 | $newsection = $1; |
