2286 lines · 62.6 KB · Text
RawDownload
	$parameterdescs{$name} = $contents;	$sectcheck = $sectcheck . $name . " ";        $parameterdesc_start_lines{$name} = $new_start_line;        $new_start_line = 0;    } else {	if (defined($sections{$name}) && ($sections{$name} ne "")) {	    # Only warn on user specified duplicate section names.	    if ($name ne $section_default) {		print STDERR "${file}:$.: warning: duplicate section name '$name'\n";		++$warnings;	    }	    $sections{$name} .= $contents;	} else {	    $sections{$name} = $contents;	    push @sectionlist, $name;            $section_start_lines{$name} = $new_start_line;            $new_start_line = 0;	}    }} ### dump DOC: section after checking that it should go out#sub dump_doc_section {    my $file = shift;    my $name = shift;    my $contents = join "\n", @_;     if ($no_doc_sections) {        return;    }     if (($output_selection == OUTPUT_ALL) ||	($output_selection == OUTPUT_INCLUDE &&	 defined($function_table{$name})) ||	($output_selection == OUTPUT_EXCLUDE &&	 !defined($function_table{$name})))    {	dump_section($file, $name, $contents);	output_blockhead({'sectionlist' => \@sectionlist,			  'sections' => \%sections,			  'module' => $modulename,			  'content-only' => ($output_selection != OUTPUT_ALL), });    }} ### output function## parameterdescs, a hash.#  function => "function name"#  parameterlist => @list of parameters#  parameterdescs => %parameter descriptions#  sectionlist => @list of sections#  sections => %section descriptions# sub output_highlight {    my $contents = join "\n",@_;    my $line; #   DEBUG#   if (!defined $contents) {#	use Carp;#	confess "output_highlight got called with no args?\n";#   } #   print STDERR "contents b4:$contents\n";    eval $dohighlight;    die $@ if $@;#   print STDERR "contents af:$contents\n";     foreach $line (split "\n", $contents) {	if (! $output_preformatted) {	    $line =~ s/^\s*//;	}	if ($line eq ""){	    if (! $output_preformatted) {		print $lineprefix, $blankline;	    }	} else {	    if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {		print "\\&$line";	    } else {		print $lineprefix, $line;	    }	}	print "\n";    }} ### output function in mansub output_function_man(%) {    my %args = %{$_[0]};    my ($parameter, $section);    my $count;     print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";     print ".SH NAME\n";    print $args{'function'} . " \\- " . $args{'purpose'} . "\n";     print ".SH SYNOPSIS\n";    if ($args{'functiontype'} ne "") {	print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";    } else {	print ".B \"" . $args{'function'} . "\n";    }    $count = 0;    my $parenth = "(";    my $post = ",";    foreach my $parameter (@{$args{'parameterlist'}}) {	if ($count == $#{$args{'parameterlist'}}) {	    $post = ");";	}	$type = $args{'parametertypes'}{$parameter};	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {	    # pointer-to-function	    print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";	} else {	    $type =~ s/([^\*])$/$1 /;	    print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";	}	$count++;	$parenth = "";    }     print ".SH ARGUMENTS\n";    foreach $parameter (@{$args{'parameterlist'}}) {	my $parameter_name = $parameter;	$parameter_name =~ s/\[.*//; 	print ".IP \"" . $parameter . "\" 12\n";	output_highlight($args{'parameterdescs'}{$parameter_name});    }    foreach $section (@{$args{'sectionlist'}}) {	print ".SH \"", uc $section, "\"\n";	output_highlight($args{'sections'}{$section});    }} ### output enum in mansub output_enum_man(%) {    my %args = %{$_[0]};    my ($parameter, $section);    my $count;     print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";     print ".SH NAME\n";    print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";     print ".SH SYNOPSIS\n";    print "enum " . $args{'enum'} . " {\n";    $count = 0;    foreach my $parameter (@{$args{'parameterlist'}}) {	print ".br\n.BI \"    $parameter\"\n";	if ($count == $#{$args{'parameterlist'}}) {	    print "\n};\n";	    last;	}	else {	    print ", \n.br\n";	}	$count++;    }     print ".SH Constants\n";    foreach $parameter (@{$args{'parameterlist'}}) {	my $parameter_name = $parameter;	$parameter_name =~ s/\[.*//; 	print ".IP \"" . $parameter . "\" 12\n";	output_highlight($args{'parameterdescs'}{$parameter_name});    }    foreach $section (@{$args{'sectionlist'}}) {	print ".SH \"$section\"\n";	output_highlight($args{'sections'}{$section});    }} ### output struct in mansub output_struct_man(%) {    my %args = %{$_[0]};    my ($parameter, $section);     print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";     print ".SH NAME\n";    print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";     my $declaration = $args{'definition'};    $declaration =~ s/\t/  /g;    $declaration =~ s/\n/"\n.br\n.BI \"/g;    print ".SH SYNOPSIS\n";    print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";    print ".BI \"$declaration\n};\n.br\n\n";     print ".SH Members\n";    foreach $parameter (@{$args{'parameterlist'}}) {	($parameter =~ /^#/) && next; 	my $parameter_name = $parameter;	$parameter_name =~ s/\[.*//; 	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;	print ".IP \"" . $parameter . "\" 12\n";	output_highlight($args{'parameterdescs'}{$parameter_name});    }    foreach $section (@{$args{'sectionlist'}}) {	print ".SH \"$section\"\n";	output_highlight($args{'sections'}{$section});    }} ### output typedef in mansub output_typedef_man(%) {    my %args = %{$_[0]};    my ($parameter, $section);     print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";     print ".SH NAME\n";    print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";     foreach $section (@{$args{'sectionlist'}}) {	print ".SH \"$section\"\n";	output_highlight($args{'sections'}{$section});    }} sub output_blockhead_man(%) {    my %args = %{$_[0]};    my ($parameter, $section);    my $count;     print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";     foreach $section (@{$args{'sectionlist'}}) {	print ".SH \"$section\"\n";	output_highlight($args{'sections'}{$section});    }} ### output in restructured text# ## This could use some work; it's used to output the DOC: sections, and# starts by putting out the name of the doc section itself, but that tends# to duplicate a header already in the template file.#sub output_blockhead_rst(%) {    my %args = %{$_[0]};    my ($parameter, $section);     foreach $section (@{$args{'sectionlist'}}) {	if ($output_selection != OUTPUT_INCLUDE) {	    print "**$section**\n\n";	}        print_lineno($section_start_lines{$section});	output_highlight_rst($args{'sections'}{$section});	print "\n";    }} ## Apply the RST highlights to a sub-block of text.#sub highlight_block($) {    # The dohighlight kludge requires the text be called $contents    my $contents = shift;    eval $dohighlight;    die $@ if $@;    return $contents;} ## Regexes used only here.#my $sphinx_literal = '^[^.].*::$';my $sphinx_cblock = '^\.\.\ +code-block::'; sub output_highlight_rst {    my $input = join "\n",@_;    my $output = "";    my $line;    my $in_literal = 0;    my $litprefix;    my $block = "";     foreach $line (split "\n",$input) {	#	# If we're in a literal block, see if we should drop out	# of it.  Otherwise pass the line straight through unmunged.	#	if ($in_literal) {	    if (! ($line =~ /^\s*$/)) {		#		# If this is the first non-blank line in a literal		# block we need to figure out what the proper indent is.		#		if ($litprefix eq "") {		    $line =~ /^(\s*)/;		    $litprefix = '^' . $1;		    $output .= $line . "\n";		} elsif (! ($line =~ /$litprefix/)) {		    $in_literal = 0;		} else {		    $output .= $line . "\n";		}	    } else {		$output .= $line . "\n";	    }	}	#	# Not in a literal block (or just dropped out)	#	if (! $in_literal) {	    $block .= $line . "\n";	    if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) {		$in_literal = 1;		$litprefix = "";		$output .= highlight_block($block);		$block = ""	    }	}    }     if ($block) {	$output .= highlight_block($block);    }    foreach $line (split "\n", $output) {	print $lineprefix . $line . "\n";    }} sub output_function_rst(%) {    my %args = %{$_[0]};    my ($parameter, $section);    my $oldprefix = $lineprefix;    my $start = "";     if ($args{'typedef'}) {	print ".. c:type:: ". $args{'function'} . "\n\n";	print_lineno($declaration_start_line);	print "   **Typedef**: ";	$lineprefix = "";	output_highlight_rst($args{'purpose'});	$start = "\n\n**Syntax**\n\n  ``";    } else {	print ".. c:function:: ";    }    if ($args{'functiontype'} ne "") {	$start .= $args{'functiontype'} . " " . $args{'function'} . " (";    } else {	$start .= $args{'function'} . " (";    }    print $start;     my $count = 0;    foreach my $parameter (@{$args{'parameterlist'}}) {	if ($count ne 0) {	    print ", ";	}	$count++;	$type = $args{'parametertypes'}{$parameter}; 	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {	    # pointer-to-function	    print $1 . $parameter . ") (" . $2 . ")";	} else {	    print $type . " " . $parameter;	}    }    if ($args{'typedef'}) {	print ");``\n\n";    } else {	print ")\n\n";	print_lineno($declaration_start_line);	$lineprefix = "   ";	output_highlight_rst($args{'purpose'});	print "\n";    }     print "**Parameters**\n\n";    $lineprefix = "  ";    foreach $parameter (@{$args{'parameterlist'}}) {	my $parameter_name = $parameter;	$parameter_name =~ s/\[.*//;	$type = $args{'parametertypes'}{$parameter}; 	if ($type ne "") {	    print "``$type $parameter``\n";	} else {	    print "``$parameter``\n";	}         print_lineno($parameterdesc_start_lines{$parameter_name}); 	if (defined($args{'parameterdescs'}{$parameter_name}) &&	    $args{'parameterdescs'}{$parameter_name} ne $undescribed) {	    output_highlight_rst($args{'parameterdescs'}{$parameter_name});	} else {	    print "  *undescribed*\n";	}	print "\n";    }     $lineprefix = $oldprefix;    output_section_rst(@_);} sub output_section_rst(%) {    my %args = %{$_[0]};    my $section;    my $oldprefix = $lineprefix;    $lineprefix = "";     foreach $section (@{$args{'sectionlist'}}) {	print "**$section**\n\n";        print_lineno($section_start_lines{$section});	output_highlight_rst($args{'sections'}{$section});	print "\n";    }    print "\n";    $lineprefix = $oldprefix;} sub output_enum_rst(%) {    my %args = %{$_[0]};    my ($parameter);    my $oldprefix = $lineprefix;    my $count;    my $name = "enum " . $args{'enum'};     print "\n\n.. c:type:: " . $name . "\n\n";    print_lineno($declaration_start_line);    $lineprefix = "   ";    output_highlight_rst($args{'purpose'});    print "\n";     print "**Constants**\n\n";    $lineprefix = "  ";    foreach $parameter (@{$args{'parameterlist'}}) {	print "``$parameter``\n";	if ($args{'parameterdescs'}{$parameter} ne $undescribed) {	    output_highlight_rst($args{'parameterdescs'}{$parameter});	} else {	    print "  *undescribed*\n";	}	print "\n";    }     $lineprefix = $oldprefix;    output_section_rst(@_);} sub output_typedef_rst(%) {    my %args = %{$_[0]};    my ($parameter);    my $oldprefix = $lineprefix;    my $name = "typedef " . $args{'typedef'};     print "\n\n.. c:type:: " . $name . "\n\n";    print_lineno($declaration_start_line);    $lineprefix = "   ";    output_highlight_rst($args{'purpose'});    print "\n";     $lineprefix = $oldprefix;    output_section_rst(@_);} sub output_struct_rst(%) {    my %args = %{$_[0]};    my ($parameter);    my $oldprefix = $lineprefix;    my $name = $args{'type'} . " " . $args{'struct'};     print "\n\n.. c:type:: " . $name . "\n\n";    print_lineno($declaration_start_line);    $lineprefix = "   ";    output_highlight_rst($args{'purpose'});    print "\n";     print "**Definition**\n\n";    print "::\n\n";    my $declaration = $args{'definition'};    $declaration =~ s/\t/  /g;    print "  " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration  };\n\n";     print "**Members**\n\n";    $lineprefix = "  ";

Lines 501–1000 of 2286. Previous lines