diff options
| author | Jonathan Corbet <corbet@lwn.net> | 2016-05-12 09:15:37 -0400 |
|---|---|---|
| committer | Jonathan Corbet <corbet@lwn.net> | 2016-05-14 11:56:30 -0400 |
| commit | c0d1b6ee780ab16f16cdbe046aa9c83a2a31f9e2 (patch) | |
| tree | 737c3e42809e25b2702a6a4196e01242a47cb4d3 /scripts | |
| parent | fadc0b31cba0bb56bce1a3259cc60e4d7ee67333 (diff) | |
kernel-doc: produce RestructuredText output
If given the -rst flag, output will now be in RestructuredText. Various
glitches to be worked out yet.
In the end I decided not to use RST section headings within the kerneldoc
comments. gpu.tmpl already has headings five levels deep; adding more is
not going to bring clarity.
This is really just Jani Nikula's asciidoc change with the serial numbers
filed off. It's a hack job that doubtless needs a lot of cleaning up.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/kernel-doc | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 29fd5cabb657..0ad1fb0e3031 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
| @@ -55,6 +55,7 @@ Output format selection (mutually exclusive): | |||
| 55 | -html5 Output HTML5 format. | 55 | -html5 Output HTML5 format. |
| 56 | -list Output symbol list format. This is for use by docproc. | 56 | -list Output symbol list format. This is for use by docproc. |
| 57 | -man Output troff manual page format. This is the default. | 57 | -man Output troff manual page format. This is the default. |
| 58 | -rst Output reStructuredText format. | ||
| 58 | -text Output plain text format. | 59 | -text Output plain text format. |
| 59 | 60 | ||
| 60 | Output selection (mutually exclusive): | 61 | Output selection (mutually exclusive): |
| @@ -203,6 +204,8 @@ my $type_param = '\@(\w+)'; | |||
| 203 | my $type_struct = '\&((struct\s*)*[_\w]+)'; | 204 | my $type_struct = '\&((struct\s*)*[_\w]+)'; |
| 204 | my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; | 205 | my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; |
| 205 | my $type_env = '(\$\w+)'; | 206 | my $type_env = '(\$\w+)'; |
| 207 | my $type_enum_full = '\&(enum)\s*([_\w]+)'; | ||
| 208 | my $type_struct_full = '\&(struct)\s*([_\w]+)'; | ||
| 206 | 209 | ||
| 207 | # Output conversion substitutions. | 210 | # Output conversion substitutions. |
| 208 | # One for each output format | 211 | # One for each output format |
| @@ -268,6 +271,17 @@ my @highlights_text = ( | |||
| 268 | ); | 271 | ); |
| 269 | my $blankline_text = ""; | 272 | my $blankline_text = ""; |
| 270 | 273 | ||
| 274 | # rst-mode | ||
| 275 | my @highlights_rst = ( | ||
| 276 | [$type_constant, "``\$1``"], | ||
| 277 | [$type_func, "\\:c\\:func\\:`\$1`"], | ||
| 278 | [$type_struct_full, "\\:ref\\:`\$1 \$2`"], | ||
| 279 | [$type_enum_full, "\\:ref\\:`\$1 \$2`"], | ||
| 280 | [$type_struct, "\\:ref\\:`struct \$1`"], | ||
| 281 | [$type_param, "**\$1**"] | ||
| 282 | ); | ||
| 283 | my $blankline_rst = "\n"; | ||
| 284 | |||
| 271 | # list mode | 285 | # list mode |
| 272 | my @highlights_list = ( | 286 | my @highlights_list = ( |
| 273 | [$type_constant, "\$1"], | 287 | [$type_constant, "\$1"], |
| @@ -404,6 +418,10 @@ while ($ARGV[0] =~ m/^-(.*)/) { | |||
| 404 | $output_mode = "text"; | 418 | $output_mode = "text"; |
| 405 | @highlights = @highlights_text; | 419 | @highlights = @highlights_text; |
| 406 | $blankline = $blankline_text; | 420 | $blankline = $blankline_text; |
| 421 | } elsif ($cmd eq "-rst") { | ||
| 422 | $output_mode = "rst"; | ||
| 423 | @highlights = @highlights_rst; | ||
| 424 | $blankline = $blankline_rst; | ||
| 407 | } elsif ($cmd eq "-docbook") { | 425 | } elsif ($cmd eq "-docbook") { |
| 408 | $output_mode = "xml"; | 426 | $output_mode = "xml"; |
| 409 | @highlights = @highlights_xml; | 427 | @highlights = @highlights_xml; |
| @@ -1704,6 +1722,209 @@ sub output_blockhead_text(%) { | |||
| 1704 | } | 1722 | } |
| 1705 | } | 1723 | } |
| 1706 | 1724 | ||
| 1725 | ## | ||
| 1726 | # output in restructured text | ||
| 1727 | # | ||
| 1728 | |||
| 1729 | # | ||
| 1730 | # This could use some work; it's used to output the DOC: sections, and | ||
| 1731 | # starts by putting out the name of the doc section itself, but that tends | ||
| 1732 | # to duplicate a header already in the template file. | ||
| 1733 | # | ||
| 1734 | sub output_blockhead_rst(%) { | ||
| 1735 | my %args = %{$_[0]}; | ||
| 1736 | my ($parameter, $section); | ||
| 1737 | |||
| 1738 | foreach $section (@{$args{'sectionlist'}}) { | ||
| 1739 | print "**$section**\n\n"; | ||
| 1740 | output_highlight_rst($args{'sections'}{$section}); | ||
| 1741 | print "\n"; | ||
| 1742 | } | ||
| 1743 | } | ||
| 1744 | |||
| 1745 | sub output_highlight_rst { | ||
| 1746 | my $contents = join "\n",@_; | ||
| 1747 | my $line; | ||
| 1748 | |||
| 1749 | # undo the evil effects of xml_escape() earlier | ||
| 1750 | $contents = xml_unescape($contents); | ||
| 1751 | |||
| 1752 | eval $dohighlight; | ||
| 1753 | die $@ if $@; | ||
| 1754 | |||
| 1755 | foreach $line (split "\n", $contents) { | ||
| 1756 | if ($line eq "") { | ||
| 1757 | print $lineprefix, $blankline; | ||
| 1758 | } else { | ||
| 1759 | $line =~ s/\\\\\\/\&/g; | ||
| 1760 | print $lineprefix, $line; | ||
| 1761 | } | ||
| 1762 | print "\n"; | ||
| 1763 | } | ||
| 1764 | } | ||
| 1765 | |||
| 1766 | sub output_function_rst(%) { | ||
| 1767 | my %args = %{$_[0]}; | ||
| 1768 | my ($parameter, $section); | ||
| 1769 | my $start; | ||
| 1770 | |||
| 1771 | print ".. c:function:: "; | ||
| 1772 | if ($args{'functiontype'} ne "") { | ||
| 1773 | $start = $args{'functiontype'} . " " . $args{'function'} . " ("; | ||
| 1774 | } else { | ||
| 1775 | $start = $args{'function'} . " ("; | ||
| 1776 | } | ||
| 1777 | print $start; | ||
| 1778 | |||
| 1779 | my $count = 0; | ||
| 1780 | foreach my $parameter (@{$args{'parameterlist'}}) { | ||
| 1781 | if ($count ne 0) { | ||
| 1782 | print ", "; | ||
| 1783 | } | ||
| 1784 | $count++; | ||
| 1785 | $type = $args{'parametertypes'}{$parameter}; | ||
| 1786 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | ||
| 1787 | # pointer-to-function | ||
| 1788 | print $1 . $parameter . ") (" . $2; | ||
| 1789 | } else { | ||
| 1790 | print $type . " " . $parameter; | ||
| 1791 | } | ||
| 1792 | } | ||
| 1793 | print ")\n\n " . $args{'purpose'} . "\n\n"; | ||
| 1794 | |||
| 1795 | print ":Parameters:\n\n"; | ||
| 1796 | foreach $parameter (@{$args{'parameterlist'}}) { | ||
| 1797 | my $parameter_name = $parameter; | ||
| 1798 | #$parameter_name =~ s/\[.*//; | ||
| 1799 | $type = $args{'parametertypes'}{$parameter}; | ||
| 1800 | |||
| 1801 | if ($type ne "") { | ||
| 1802 | print " ``$type $parameter``\n"; | ||
| 1803 | } else { | ||
| 1804 | print " ``$parameter``\n"; | ||
| 1805 | } | ||
| 1806 | if ($args{'parameterdescs'}{$parameter_name} ne $undescribed) { | ||
| 1807 | my $oldprefix = $lineprefix; | ||
| 1808 | $lineprefix = " "; | ||
| 1809 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | ||
| 1810 | $lineprefix = $oldprefix; | ||
| 1811 | } else { | ||
| 1812 | print "\n _undescribed_\n"; | ||
| 1813 | } | ||
| 1814 | print "\n"; | ||
| 1815 | } | ||
| 1816 | output_section_rst(@_); | ||
| 1817 | } | ||
| 1818 | |||
| 1819 | sub output_section_rst(%) { | ||
| 1820 | my %args = %{$_[0]}; | ||
| 1821 | my $section; | ||
| 1822 | my $oldprefix = $lineprefix; | ||
| 1823 | $lineprefix = " "; | ||
| 1824 | |||
| 1825 | foreach $section (@{$args{'sectionlist'}}) { | ||
| 1826 | print ":$section:\n\n"; | ||
| 1827 | output_highlight_rst($args{'sections'}{$section}); | ||
| 1828 | print "\n"; | ||
| 1829 | } | ||
| 1830 | print "\n"; | ||
| 1831 | $lineprefix = $oldprefix; | ||
| 1832 | } | ||
| 1833 | |||
| 1834 | sub output_enum_rst(%) { | ||
| 1835 | my %args = %{$_[0]}; | ||
| 1836 | my ($parameter); | ||
| 1837 | my $count; | ||
| 1838 | |||
| 1839 | my $name = "enum " . $args{'enum'}; | ||
| 1840 | print ".. _" . $name . ":\n\n"; | ||
| 1841 | print "**$name**\n\n"; | ||
| 1842 | print " " . $args{'purpose'} . "\n\n"; | ||
| 1843 | |||
| 1844 | print "..\n\n:Constants:\n\n"; | ||
| 1845 | my $oldprefix = $lineprefix; | ||
| 1846 | $lineprefix = " "; | ||
| 1847 | foreach $parameter (@{$args{'parameterlist'}}) { | ||
| 1848 | print " `$parameter`\n"; | ||
| 1849 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { | ||
| 1850 | output_highlight_rst($args{'parameterdescs'}{$parameter}); | ||
| 1851 | } else { | ||
| 1852 | print " undescribed\n"; | ||
| 1853 | } | ||
| 1854 | print "\n"; | ||
| 1855 | } | ||
| 1856 | $lineprefix = $oldprefix; | ||
| 1857 | output_section_rst(@_); | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | sub output_typedef_rst(%) { | ||
| 1861 | my %args = %{$_[0]}; | ||
| 1862 | my ($parameter); | ||
| 1863 | my $count; | ||
| 1864 | my $name = "typedef " . $args{'typedef'}; | ||
| 1865 | |||
| 1866 | print "**$name**\n\n"; | ||
| 1867 | print $args{'purpose'} . "\n\n"; | ||
| 1868 | |||
| 1869 | output_section_rst(@_); | ||
| 1870 | } | ||
| 1871 | |||
| 1872 | sub output_struct_rst(%) { | ||
| 1873 | my %args = %{$_[0]}; | ||
| 1874 | my ($parameter); | ||
| 1875 | my $name = $args{'type'} . " " . $args{'struct'}; | ||
| 1876 | |||
| 1877 | print ".. _" . $name . ":\n\n"; | ||
| 1878 | print "**$name**\n\n"; | ||
| 1879 | print " " . $args{'purpose'} . "\n\n"; | ||
| 1880 | |||
| 1881 | print ":Definition:\n\n"; | ||
| 1882 | print " ::\n\n"; | ||
| 1883 | print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; | ||
| 1884 | foreach $parameter (@{$args{'parameterlist'}}) { | ||
| 1885 | if ($parameter =~ /^#/) { | ||
| 1886 | print " " . "$parameter\n"; | ||
| 1887 | next; | ||
| 1888 | } | ||
| 1889 | |||
| 1890 | my $parameter_name = $parameter; | ||
| 1891 | $parameter_name =~ s/\[.*//; | ||
| 1892 | |||
| 1893 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | ||
| 1894 | $type = $args{'parametertypes'}{$parameter}; | ||
| 1895 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | ||
| 1896 | # pointer-to-function | ||
| 1897 | print " $1 $parameter) ($2);\n"; | ||
| 1898 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | ||
| 1899 | # bitfield | ||
| 1900 | print " $1 $parameter$2;\n"; | ||
| 1901 | } else { | ||
| 1902 | print " " . $type . " " . $parameter . ";\n"; | ||
| 1903 | } | ||
| 1904 | } | ||
| 1905 | print " };\n\n"; | ||
| 1906 | |||
| 1907 | print ":Members:\n\n"; | ||
| 1908 | foreach $parameter (@{$args{'parameterlist'}}) { | ||
| 1909 | ($parameter =~ /^#/) && next; | ||
| 1910 | |||
| 1911 | my $parameter_name = $parameter; | ||
| 1912 | $parameter_name =~ s/\[.*//; | ||
| 1913 | |||
| 1914 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | ||
| 1915 | $type = $args{'parametertypes'}{$parameter}; | ||
| 1916 | print " `$type $parameter`" . "\n"; | ||
| 1917 | my $oldprefix = $lineprefix; | ||
| 1918 | $lineprefix = " "; | ||
| 1919 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | ||
| 1920 | $lineprefix = $oldprefix; | ||
| 1921 | print "\n"; | ||
| 1922 | } | ||
| 1923 | print "\n"; | ||
| 1924 | output_section_rst(@_); | ||
| 1925 | } | ||
| 1926 | |||
| 1927 | |||
| 1707 | ## list mode output functions | 1928 | ## list mode output functions |
| 1708 | 1929 | ||
| 1709 | sub output_function_list(%) { | 1930 | sub output_function_list(%) { |
| @@ -2405,6 +2626,18 @@ sub xml_escape($) { | |||
| 2405 | return $text; | 2626 | return $text; |
| 2406 | } | 2627 | } |
| 2407 | 2628 | ||
| 2629 | # xml_unescape: reverse the effects of xml_escape | ||
| 2630 | sub xml_unescape($) { | ||
| 2631 | my $text = shift; | ||
| 2632 | if (($output_mode eq "text") || ($output_mode eq "man")) { | ||
| 2633 | return $text; | ||
| 2634 | } | ||
| 2635 | $text =~ s/\\\\\\amp;/\&/g; | ||
| 2636 | $text =~ s/\\\\\\lt;/</g; | ||
| 2637 | $text =~ s/\\\\\\gt;/>/g; | ||
| 2638 | return $text; | ||
| 2639 | } | ||
| 2640 | |||
| 2408 | # convert local escape strings to html | 2641 | # convert local escape strings to html |
| 2409 | # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) | 2642 | # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) |
| 2410 | sub local_unescape($) { | 2643 | sub local_unescape($) { |
