From 1b40c1944db445c1de1c47ffd8cd426167f488e8 Mon Sep 17 00:00:00 2001 From: Dan Luedtke Date: Sun, 12 Aug 2012 10:46:15 +0200 Subject: scripts/kernel-doc: added support for html5 New output option html5 writes validating HTML5 and adds CSS classes ready to be selected by third-party stylesheets. HTML ids have been added to block-level elements "article" for direct reference of particular objects via URL. Signed-off-by: Dan Luedtke Acked-by: Randy Dunlap Signed-off-by: Michal Marek --- scripts/kernel-doc | 273 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 266 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 9b0c0b8b4ab4..97e037aa97a7 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -6,6 +6,7 @@ use strict; ## Copyright (C) 2000, 1 Tim Waugh ## ## Copyright (C) 2001 Simon Huggins ## ## Copyright (C) 2005-2012 Randy Dunlap ## +## Copyright (C) 2012 Dan Luedtke ## ## ## ## #define enhancements by Armin Kuster ## ## Copyright (c) 2000 MontaVista Software, Inc. ## @@ -35,6 +36,8 @@ use strict; # Small fixes (like spaces vs. \s in regex) # -- Tim Jansen +# 25/07/2012 - Added support for HTML5 +# -- Dan Luedtke # # This will read a 'c' file and scan for embedded comments in the @@ -44,12 +47,16 @@ use strict; # Note: This only supports 'c'. # usage: -# kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ] -# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile +# kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ] +# [ -no-doc-sections ] +# [ -function funcname [ -function funcname ...] ] +# c file(s)s > outputfile # or -# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile +# [ -nofunction funcname [ -function funcname ...] ] +# c file(s)s > outputfile # -# Set output format using one of -docbook -html -text or -man. Default is man. +# Set output format using one of -docbook -html -html5 -text or -man. +# Default is man. # The -list format is for internal use by docproc. # # -no-doc-sections @@ -182,6 +189,14 @@ my $local_lt = "\\\\\\\\lt:"; my $local_gt = "\\\\\\\\gt:"; my $blankline_html = $local_lt . "p" . $local_gt; # was "

" +# html version 5 +my %highlights_html5 = ( $type_constant, "\$1", + $type_func, "\$1", + $type_struct_xml, "\$1", + $type_env, "\$1", + $type_param, "\$1" ); +my $blankline_html5 = $local_lt . "br /" . $local_gt; + # XML, docbook format my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1\$2", $type_constant, "\$1", @@ -309,6 +324,10 @@ while ($ARGV[0] =~ m/^-(.*)/) { $output_mode = "html"; %highlights = %highlights_html; $blankline = $blankline_html; + } elsif ($cmd eq "-html5") { + $output_mode = "html5"; + %highlights = %highlights_html5; + $blankline = $blankline_html5; } elsif ($cmd eq "-man") { $output_mode = "man"; %highlights = %highlights_man; @@ -351,10 +370,11 @@ while ($ARGV[0] =~ m/^-(.*)/) { # continue execution near EOF; sub usage { - print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n"; + print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n"; print " [ -no-doc-sections ]\n"; print " [ -function funcname [ -function funcname ...] ]\n"; print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; + print " [ -v ]\n"; print " c source file(s) > outputfile\n"; print " -v : verbose output, more warnings & other info listed\n"; exit 1; @@ -448,7 +468,8 @@ sub output_highlight { # confess "output_highlight got called with no args?\n"; # } - if ($output_mode eq "html" || $output_mode eq "xml") { + if ($output_mode eq "html" || $output_mode eq "html5" || + $output_mode eq "xml") { $contents = local_unescape($contents); # convert data read & converted thru xml_escape() into &xyz; format: $contents =~ s/\\\\\\/\&/g; @@ -458,6 +479,11 @@ sub output_highlight { die $@ if $@; # print STDERR "contents af:$contents\n"; +# strip whitespaces when generating html5 + if ($output_mode eq "html5") { + $contents =~ s/^\s+//; + $contents =~ s/\s+$//; + } foreach $line (split "\n", $contents) { if ($line eq ""){ print $lineprefix, local_unescape($blankline); @@ -473,7 +499,7 @@ sub output_highlight { } } -#output sections in html +# output sections in html sub output_section_html(%) { my %args = %{$_[0]}; my $section; @@ -633,6 +659,239 @@ sub output_blockhead_html(%) { print "


\n"; } +# output sections in html5 +sub output_section_html5(%) { + my %args = %{$_[0]}; + my $section; + + foreach $section (@{$args{'sectionlist'}}) { + print "
\n"; + print "

$section

\n"; + print "

\n"; + output_highlight($args{'sections'}{$section}); + print "

\n"; + print "
\n"; + } +} + +# output enum in html5 +sub output_enum_html5(%) { + my %args = %{$_[0]}; + my ($parameter); + my $count; + my $html5id; + + $html5id = $args{'enum'}; + $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; + print "
"; + print "

enum " . $args{'enum'} . "

\n"; + print "
    \n"; + print "
  1. "; + print "enum "; + print "" . $args{'enum'} . " {"; + print "
  2. \n"; + $count = 0; + foreach $parameter (@{$args{'parameterlist'}}) { + print "
  3. "; + print "" . $parameter . ""; + if ($count != $#{$args{'parameterlist'}}) { + $count++; + print ","; + } + print "
  4. \n"; + } + print "
  5. };
  6. \n"; + print "
\n"; + + print "
\n"; + print "

Constants

\n"; + print "
\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + print "
" . $parameter . "
\n"; + print "
"; + output_highlight($args{'parameterdescs'}{$parameter}); + print "
\n"; + } + print "
\n"; + print "
\n"; + output_section_html5(@_); + print "
\n"; +} + +# output typedef in html5 +sub output_typedef_html5(%) { + my %args = %{$_[0]}; + my ($parameter); + my $count; + my $html5id; + + $html5id = $args{'typedef'}; + $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; + print "
\n"; + print "

typedef " . $args{'typedef'} . "

\n"; + + print "
    \n"; + print "
  1. "; + print "typedef "; + print "" . $args{'typedef'} . ""; + print "
  2. \n"; + print "
\n"; + output_section_html5(@_); + print "
\n"; +} + +# output struct in html5 +sub output_struct_html5(%) { + my %args = %{$_[0]}; + my ($parameter); + my $html5id; + + $html5id = $args{'struct'}; + $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; + print "
\n"; + print "
\n"; + print "

" . $args{'type'} . " " . $args{'struct'} . "

"; + print "

". $args{'purpose'} . "

\n"; + print "
\n"; + print "
    \n"; + print "
  1. "; + print "" . $args{'type'} . " "; + print "" . $args{'struct'} . " {"; + print "
  2. \n"; + foreach $parameter (@{$args{'parameterlist'}}) { + print "
  3. "; + if ($parameter =~ /^#/) { + print "" . $parameter ."\n"; + print "
  4. \n"; + next; + } + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + $type = $args{'parametertypes'}{$parameter}; + if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { + # pointer-to-function + print "$1 "; + print "$parameter"; + print ") "; + print "($2);"; + } elsif ($type =~ m/^(.*?)\s*(:.*)/) { + # bitfield + print "$1 "; + print "$parameter"; + print "$2;"; + } else { + print "$type "; + print "$parameter;"; + } + print "\n"; + } + print "
  5. };
  6. \n"; + print "
\n"; + + print "
\n"; + print "

Members

\n"; + print "
\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + ($parameter =~ /^#/) && next; + + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + print "
" . $parameter . "
\n"; + print "
"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + print "
\n"; + } + print "
\n"; + print "
\n"; + output_section_html5(@_); + print "
\n"; +} + +# output function in html5 +sub output_function_html5(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + my $html5id; + + $html5id = $args{'function'}; + $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; + print "
\n"; + print "
\n"; + print "

" . $args{'function'} . "

"; + print "

" . $args{'purpose'} . "

\n"; + print "
\n"; + print "
    \n"; + print "
  1. "; + print "" . $args{'functiontype'} . " "; + print "" . $args{'function'} . " ("; + print "
  2. "; + $count = 0; + foreach $parameter (@{$args{'parameterlist'}}) { + print "
  3. "; + $type = $args{'parametertypes'}{$parameter}; + if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { + # pointer-to-function + print "$1 "; + print "$parameter"; + print ") "; + print "($2)"; + } else { + print "$type "; + print "$parameter"; + } + if ($count != $#{$args{'parameterlist'}}) { + $count++; + print ","; + } + print "
  4. \n"; + } + print "
  5. )
  6. \n"; + print "
\n"; + + print "
\n"; + print "

Arguments

\n"; + print "

\n"; + print "

\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + print "
" . $parameter . "
\n"; + print "
"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + print "
\n"; + } + print "
\n"; + print "
\n"; + output_section_html5(@_); + print "
\n"; +} + +# output DOC: block header in html5 +sub output_blockhead_html5(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + my $html5id; + + foreach $section (@{$args{'sectionlist'}}) { + $html5id = $section; + $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; + print "
\n"; + print "

$section

\n"; + print "

\n"; + output_highlight($args{'sections'}{$section}); + print "

\n"; + } + print "
\n"; +} + sub output_section_xml(%) { my %args = %{$_[0]}; my $section; -- cgit v1.2.3