aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kernel-doc
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/kernel-doc')
-rwxr-xr-xscripts/kernel-doc296
1 files changed, 286 insertions, 10 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 8fd107a3fac4..46e7aff80d1a 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -6,6 +6,7 @@ use strict;
6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7## Copyright (C) 2001 Simon Huggins ## 7## Copyright (C) 2001 Simon Huggins ##
8## Copyright (C) 2005-2012 Randy Dunlap ## 8## Copyright (C) 2005-2012 Randy Dunlap ##
9## Copyright (C) 2012 Dan Luedtke ##
9## ## 10## ##
10## #define enhancements by Armin Kuster <akuster@mvista.com> ## 11## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11## Copyright (c) 2000 MontaVista Software, Inc. ## 12## Copyright (c) 2000 MontaVista Software, Inc. ##
@@ -35,6 +36,8 @@ use strict;
35# Small fixes (like spaces vs. \s in regex) 36# Small fixes (like spaces vs. \s in regex)
36# -- Tim Jansen <tim@tjansen.de> 37# -- Tim Jansen <tim@tjansen.de>
37 38
39# 25/07/2012 - Added support for HTML5
40# -- Dan Luedtke <mail@danrl.de>
38 41
39# 42#
40# This will read a 'c' file and scan for embedded comments in the 43# This will read a 'c' file and scan for embedded comments in the
@@ -44,12 +47,16 @@ use strict;
44# Note: This only supports 'c'. 47# Note: This only supports 'c'.
45 48
46# usage: 49# usage:
47# kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ] 50# kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ]
48# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile 51# [ -no-doc-sections ]
52# [ -function funcname [ -function funcname ...] ]
53# c file(s)s > outputfile
49# or 54# or
50# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile 55# [ -nofunction funcname [ -function funcname ...] ]
56# c file(s)s > outputfile
51# 57#
52# Set output format using one of -docbook -html -text or -man. Default is man. 58# Set output format using one of -docbook -html -html5 -text or -man.
59# Default is man.
53# The -list format is for internal use by docproc. 60# The -list format is for internal use by docproc.
54# 61#
55# -no-doc-sections 62# -no-doc-sections
@@ -182,6 +189,14 @@ my $local_lt = "\\\\\\\\lt:";
182my $local_gt = "\\\\\\\\gt:"; 189my $local_gt = "\\\\\\\\gt:";
183my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 190my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
184 191
192# html version 5
193my %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>",
194 $type_func, "<span class=\"func\">\$1</span>",
195 $type_struct_xml, "<span class=\"struct\">\$1</span>",
196 $type_env, "<span class=\"env\">\$1</span>",
197 $type_param, "<span class=\"param\">\$1</span>" );
198my $blankline_html5 = $local_lt . "br /" . $local_gt;
199
185# XML, docbook format 200# XML, docbook format
186my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", 201my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
187 $type_constant, "<constant>\$1</constant>", 202 $type_constant, "<constant>\$1</constant>",
@@ -230,6 +245,7 @@ my $dohighlight = "";
230 245
231my $verbose = 0; 246my $verbose = 0;
232my $output_mode = "man"; 247my $output_mode = "man";
248my $output_preformatted = 0;
233my $no_doc_sections = 0; 249my $no_doc_sections = 0;
234my %highlights = %highlights_man; 250my %highlights = %highlights_man;
235my $blankline = $blankline_man; 251my $blankline = $blankline_man;
@@ -280,9 +296,10 @@ my $doc_special = "\@\%\$\&";
280my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 296my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
281my $doc_end = '\*/'; 297my $doc_end = '\*/';
282my $doc_com = '\s*\*\s*'; 298my $doc_com = '\s*\*\s*';
299my $doc_com_body = '\s*\* ?';
283my $doc_decl = $doc_com . '(\w+)'; 300my $doc_decl = $doc_com . '(\w+)';
284my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 301my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
285my $doc_content = $doc_com . '(.*)'; 302my $doc_content = $doc_com_body . '(.*)';
286my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 303my $doc_block = $doc_com . 'DOC:\s*(.*)?';
287 304
288my %constants; 305my %constants;
@@ -309,6 +326,10 @@ while ($ARGV[0] =~ m/^-(.*)/) {
309 $output_mode = "html"; 326 $output_mode = "html";
310 %highlights = %highlights_html; 327 %highlights = %highlights_html;
311 $blankline = $blankline_html; 328 $blankline = $blankline_html;
329 } elsif ($cmd eq "-html5") {
330 $output_mode = "html5";
331 %highlights = %highlights_html5;
332 $blankline = $blankline_html5;
312 } elsif ($cmd eq "-man") { 333 } elsif ($cmd eq "-man") {
313 $output_mode = "man"; 334 $output_mode = "man";
314 %highlights = %highlights_man; 335 %highlights = %highlights_man;
@@ -351,10 +372,11 @@ while ($ARGV[0] =~ m/^-(.*)/) {
351# continue execution near EOF; 372# continue execution near EOF;
352 373
353sub usage { 374sub usage {
354 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n"; 375 print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n";
355 print " [ -no-doc-sections ]\n"; 376 print " [ -no-doc-sections ]\n";
356 print " [ -function funcname [ -function funcname ...] ]\n"; 377 print " [ -function funcname [ -function funcname ...] ]\n";
357 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 378 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
379 print " [ -v ]\n";
358 print " c source file(s) > outputfile\n"; 380 print " c source file(s) > outputfile\n";
359 print " -v : verbose output, more warnings & other info listed\n"; 381 print " -v : verbose output, more warnings & other info listed\n";
360 exit 1; 382 exit 1;
@@ -448,7 +470,8 @@ sub output_highlight {
448# confess "output_highlight got called with no args?\n"; 470# confess "output_highlight got called with no args?\n";
449# } 471# }
450 472
451 if ($output_mode eq "html" || $output_mode eq "xml") { 473 if ($output_mode eq "html" || $output_mode eq "html5" ||
474 $output_mode eq "xml") {
452 $contents = local_unescape($contents); 475 $contents = local_unescape($contents);
453 # convert data read & converted thru xml_escape() into &xyz; format: 476 # convert data read & converted thru xml_escape() into &xyz; format:
454 $contents =~ s/\\\\\\/\&/g; 477 $contents =~ s/\\\\\\/\&/g;
@@ -458,9 +481,19 @@ sub output_highlight {
458 die $@ if $@; 481 die $@ if $@;
459# print STDERR "contents af:$contents\n"; 482# print STDERR "contents af:$contents\n";
460 483
484# strip whitespaces when generating html5
485 if ($output_mode eq "html5") {
486 $contents =~ s/^\s+//;
487 $contents =~ s/\s+$//;
488 }
461 foreach $line (split "\n", $contents) { 489 foreach $line (split "\n", $contents) {
490 if (! $output_preformatted) {
491 $line =~ s/^\s*//;
492 }
462 if ($line eq ""){ 493 if ($line eq ""){
463 print $lineprefix, local_unescape($blankline); 494 if (! $output_preformatted) {
495 print $lineprefix, local_unescape($blankline);
496 }
464 } else { 497 } else {
465 $line =~ s/\\\\\\/\&/g; 498 $line =~ s/\\\\\\/\&/g;
466 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 499 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
@@ -473,7 +506,7 @@ sub output_highlight {
473 } 506 }
474} 507}
475 508
476#output sections in html 509# output sections in html
477sub output_section_html(%) { 510sub output_section_html(%) {
478 my %args = %{$_[0]}; 511 my %args = %{$_[0]};
479 my $section; 512 my $section;
@@ -633,6 +666,239 @@ sub output_blockhead_html(%) {
633 print "<hr>\n"; 666 print "<hr>\n";
634} 667}
635 668
669# output sections in html5
670sub output_section_html5(%) {
671 my %args = %{$_[0]};
672 my $section;
673
674 foreach $section (@{$args{'sectionlist'}}) {
675 print "<section>\n";
676 print "<h1>$section</h1>\n";
677 print "<p>\n";
678 output_highlight($args{'sections'}{$section});
679 print "</p>\n";
680 print "</section>\n";
681 }
682}
683
684# output enum in html5
685sub output_enum_html5(%) {
686 my %args = %{$_[0]};
687 my ($parameter);
688 my $count;
689 my $html5id;
690
691 $html5id = $args{'enum'};
692 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
693 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
694 print "<h1>enum " . $args{'enum'} . "</h1>\n";
695 print "<ol class=\"code\">\n";
696 print "<li>";
697 print "<span class=\"keyword\">enum</span> ";
698 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
699 print "</li>\n";
700 $count = 0;
701 foreach $parameter (@{$args{'parameterlist'}}) {
702 print "<li class=\"indent\">";
703 print "<span class=\"param\">" . $parameter . "</span>";
704 if ($count != $#{$args{'parameterlist'}}) {
705 $count++;
706 print ",";
707 }
708 print "</li>\n";
709 }
710 print "<li>};</li>\n";
711 print "</ol>\n";
712
713 print "<section>\n";
714 print "<h1>Constants</h1>\n";
715 print "<dl>\n";
716 foreach $parameter (@{$args{'parameterlist'}}) {
717 print "<dt>" . $parameter . "</dt>\n";
718 print "<dd>";
719 output_highlight($args{'parameterdescs'}{$parameter});
720 print "</dd>\n";
721 }
722 print "</dl>\n";
723 print "</section>\n";
724 output_section_html5(@_);
725 print "</article>\n";
726}
727
728# output typedef in html5
729sub output_typedef_html5(%) {
730 my %args = %{$_[0]};
731 my ($parameter);
732 my $count;
733 my $html5id;
734
735 $html5id = $args{'typedef'};
736 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
737 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
738 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
739
740 print "<ol class=\"code\">\n";
741 print "<li>";
742 print "<span class=\"keyword\">typedef</span> ";
743 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
744 print "</li>\n";
745 print "</ol>\n";
746 output_section_html5(@_);
747 print "</article>\n";
748}
749
750# output struct in html5
751sub output_struct_html5(%) {
752 my %args = %{$_[0]};
753 my ($parameter);
754 my $html5id;
755
756 $html5id = $args{'struct'};
757 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
758 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
759 print "<hgroup>\n";
760 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
761 print "<h2>". $args{'purpose'} . "</h2>\n";
762 print "</hgroup>\n";
763 print "<ol class=\"code\">\n";
764 print "<li>";
765 print "<span class=\"type\">" . $args{'type'} . "</span> ";
766 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
767 print "</li>\n";
768 foreach $parameter (@{$args{'parameterlist'}}) {
769 print "<li class=\"indent\">";
770 if ($parameter =~ /^#/) {
771 print "<span class=\"param\">" . $parameter ."</span>\n";
772 print "</li>\n";
773 next;
774 }
775 my $parameter_name = $parameter;
776 $parameter_name =~ s/\[.*//;
777
778 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
779 $type = $args{'parametertypes'}{$parameter};
780 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
781 # pointer-to-function
782 print "<span class=\"type\">$1</span> ";
783 print "<span class=\"param\">$parameter</span>";
784 print "<span class=\"type\">)</span> ";
785 print "(<span class=\"args\">$2</span>);";
786 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
787 # bitfield
788 print "<span class=\"type\">$1</span> ";
789 print "<span class=\"param\">$parameter</span>";
790 print "<span class=\"bits\">$2</span>;";
791 } else {
792 print "<span class=\"type\">$type</span> ";
793 print "<span class=\"param\">$parameter</span>;";
794 }
795 print "</li>\n";
796 }
797 print "<li>};</li>\n";
798 print "</ol>\n";
799
800 print "<section>\n";
801 print "<h1>Members</h1>\n";
802 print "<dl>\n";
803 foreach $parameter (@{$args{'parameterlist'}}) {
804 ($parameter =~ /^#/) && next;
805
806 my $parameter_name = $parameter;
807 $parameter_name =~ s/\[.*//;
808
809 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
810 print "<dt>" . $parameter . "</dt>\n";
811 print "<dd>";
812 output_highlight($args{'parameterdescs'}{$parameter_name});
813 print "</dd>\n";
814 }
815 print "</dl>\n";
816 print "</section>\n";
817 output_section_html5(@_);
818 print "</article>\n";
819}
820
821# output function in html5
822sub output_function_html5(%) {
823 my %args = %{$_[0]};
824 my ($parameter, $section);
825 my $count;
826 my $html5id;
827
828 $html5id = $args{'function'};
829 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
830 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
831 print "<hgroup>\n";
832 print "<h1>" . $args{'function'} . "</h1>";
833 print "<h2>" . $args{'purpose'} . "</h2>\n";
834 print "</hgroup>\n";
835 print "<ol class=\"code\">\n";
836 print "<li>";
837 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
838 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
839 print "</li>";
840 $count = 0;
841 foreach $parameter (@{$args{'parameterlist'}}) {
842 print "<li class=\"indent\">";
843 $type = $args{'parametertypes'}{$parameter};
844 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
845 # pointer-to-function
846 print "<span class=\"type\">$1</span> ";
847 print "<span class=\"param\">$parameter</span>";
848 print "<span class=\"type\">)</span> ";
849 print "(<span class=\"args\">$2</span>)";
850 } else {
851 print "<span class=\"type\">$type</span> ";
852 print "<span class=\"param\">$parameter</span>";
853 }
854 if ($count != $#{$args{'parameterlist'}}) {
855 $count++;
856 print ",";
857 }
858 print "</li>\n";
859 }
860 print "<li>)</li>\n";
861 print "</ol>\n";
862
863 print "<section>\n";
864 print "<h1>Arguments</h1>\n";
865 print "<p>\n";
866 print "<dl>\n";
867 foreach $parameter (@{$args{'parameterlist'}}) {
868 my $parameter_name = $parameter;
869 $parameter_name =~ s/\[.*//;
870
871 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
872 print "<dt>" . $parameter . "</dt>\n";
873 print "<dd>";
874 output_highlight($args{'parameterdescs'}{$parameter_name});
875 print "</dd>\n";
876 }
877 print "</dl>\n";
878 print "</section>\n";
879 output_section_html5(@_);
880 print "</article>\n";
881}
882
883# output DOC: block header in html5
884sub output_blockhead_html5(%) {
885 my %args = %{$_[0]};
886 my ($parameter, $section);
887 my $count;
888 my $html5id;
889
890 foreach $section (@{$args{'sectionlist'}}) {
891 $html5id = $section;
892 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
893 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
894 print "<h1>$section</h1>\n";
895 print "<p>\n";
896 output_highlight($args{'sections'}{$section});
897 print "</p>\n";
898 }
899 print "</article>\n";
900}
901
636sub output_section_xml(%) { 902sub output_section_xml(%) {
637 my %args = %{$_[0]}; 903 my %args = %{$_[0]};
638 my $section; 904 my $section;
@@ -643,10 +909,12 @@ sub output_section_xml(%) {
643 print "<title>$section</title>\n"; 909 print "<title>$section</title>\n";
644 if ($section =~ m/EXAMPLE/i) { 910 if ($section =~ m/EXAMPLE/i) {
645 print "<informalexample><programlisting>\n"; 911 print "<informalexample><programlisting>\n";
912 $output_preformatted = 1;
646 } else { 913 } else {
647 print "<para>\n"; 914 print "<para>\n";
648 } 915 }
649 output_highlight($args{'sections'}{$section}); 916 output_highlight($args{'sections'}{$section});
917 $output_preformatted = 0;
650 if ($section =~ m/EXAMPLE/i) { 918 if ($section =~ m/EXAMPLE/i) {
651 print "</programlisting></informalexample>\n"; 919 print "</programlisting></informalexample>\n";
652 } else { 920 } else {
@@ -949,10 +1217,12 @@ sub output_blockhead_xml(%) {
949 } 1217 }
950 if ($section =~ m/EXAMPLE/i) { 1218 if ($section =~ m/EXAMPLE/i) {
951 print "<example><para>\n"; 1219 print "<example><para>\n";
1220 $output_preformatted = 1;
952 } else { 1221 } else {
953 print "<para>\n"; 1222 print "<para>\n";
954 } 1223 }
955 output_highlight($args{'sections'}{$section}); 1224 output_highlight($args{'sections'}{$section});
1225 $output_preformatted = 0;
956 if ($section =~ m/EXAMPLE/i) { 1226 if ($section =~ m/EXAMPLE/i) {
957 print "</para></example>\n"; 1227 print "</para></example>\n";
958 } else { 1228 } else {
@@ -1028,10 +1298,12 @@ sub output_function_gnome {
1028 print "<simplesect>\n <title>$section</title>\n"; 1298 print "<simplesect>\n <title>$section</title>\n";
1029 if ($section =~ m/EXAMPLE/i) { 1299 if ($section =~ m/EXAMPLE/i) {
1030 print "<example><programlisting>\n"; 1300 print "<example><programlisting>\n";
1301 $output_preformatted = 1;
1031 } else { 1302 } else {
1032 } 1303 }
1033 print "<para>\n"; 1304 print "<para>\n";
1034 output_highlight($args{'sections'}{$section}); 1305 output_highlight($args{'sections'}{$section});
1306 $output_preformatted = 0;
1035 print "</para>\n"; 1307 print "</para>\n";
1036 if ($section =~ m/EXAMPLE/i) { 1308 if ($section =~ m/EXAMPLE/i) {
1037 print "</programlisting></example>\n"; 1309 print "</programlisting></example>\n";
@@ -2046,6 +2318,9 @@ sub process_file($) {
2046 2318
2047 $section_counter = 0; 2319 $section_counter = 0;
2048 while (<IN>) { 2320 while (<IN>) {
2321 while (s/\\\s*$//) {
2322 $_ .= <IN>;
2323 }
2049 if ($state == 0) { 2324 if ($state == 0) {
2050 if (/$doc_start/o) { 2325 if (/$doc_start/o) {
2051 $state = 1; # next line is always the function name 2326 $state = 1; # next line is always the function name
@@ -2073,7 +2348,7 @@ sub process_file($) {
2073 $descr= $1; 2348 $descr= $1;
2074 $descr =~ s/^\s*//; 2349 $descr =~ s/^\s*//;
2075 $descr =~ s/\s*$//; 2350 $descr =~ s/\s*$//;
2076 $descr =~ s/\s+/ /; 2351 $descr =~ s/\s+/ /g;
2077 $declaration_purpose = xml_escape($descr); 2352 $declaration_purpose = xml_escape($descr);
2078 $in_purpose = 1; 2353 $in_purpose = 1;
2079 } else { 2354 } else {
@@ -2165,6 +2440,7 @@ sub process_file($) {
2165 # Continued declaration purpose 2440 # Continued declaration purpose
2166 chomp($declaration_purpose); 2441 chomp($declaration_purpose);
2167 $declaration_purpose .= " " . xml_escape($1); 2442 $declaration_purpose .= " " . xml_escape($1);
2443 $declaration_purpose =~ s/\s+/ /g;
2168 } else { 2444 } else {
2169 $contents .= $1 . "\n"; 2445 $contents .= $1 . "\n";
2170 } 2446 }