2503 lines · 65.9 KB · Text
RawDownload
#  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/$function_pointer/) {	    # pointer-to-function	    print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n";	} else {	    $type =~ s/([^\*])$/$1 /;	    print ".BI \"" . $parenth . $type . "\" " . " \"" . $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'}}) {	next if (defined($nosymbol_table{$section})); 	if ($output_selection != OUTPUT_INCLUDE) {	    print ".. _$section:\n\n";	    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 = "";    my $is_macro = 0;     if ($sphinx_major < 3) {	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  ``";	    $is_macro = 1;	} else {	    print ".. c:function:: ";	}    } else {	if ($args{'typedef'} || $args{'functiontype'} eq "") {	    $is_macro = 1;	    print ".. c:macro:: ". $args{'function'} . "\n\n";	} else {	    print ".. c:function:: ";	} 	if ($args{'typedef'}) {	    print_lineno($declaration_start_line);	    print "   **Typedef**: ";	    $lineprefix = "";	    output_highlight_rst($args{'purpose'});	    $start = "\n\n**Syntax**\n\n  ``";	} else {	    print "``" if ($is_macro);	}    }    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/$function_pointer/) {	    # pointer-to-function	    print $1 . $parameter . ") (" . $2 . ")";	} else {	    print $type;	}    }    if ($is_macro) {	print ")``\n\n";    } else {	print ")\n\n";    }    if (!$args{'typedef'}) {	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``\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;     if ($sphinx_major < 3) {	my $name = "enum " . $args{'enum'};	print "\n\n.. c:type:: " . $name . "\n\n";    } else {	my $name = $args{'enum'};	print "\n\n.. c:enum:: " . $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;     if ($sphinx_major < 3) {	$name = "typedef " . $args{'typedef'};    } else {	$name = $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;     if ($sphinx_major < 3) {	my $name = $args{'type'} . " " . $args{'struct'};	print "\n\n.. c:type:: " . $name . "\n\n";    } else {	my $name = $args{'struct'};	if ($args{'type'} eq 'union') {	    print "\n\n.. c:union:: " . $name . "\n\n";	} else {	    print "\n\n.. c:struct:: " . $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 = "  ";    foreach $parameter (@{$args{'parameterlist'}}) {	($parameter =~ /^#/) && next; 	my $parameter_name = $parameter;	$parameter_name =~ s/\[.*//; 	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;	$type = $args{'parametertypes'}{$parameter};        print_lineno($parameterdesc_start_lines{$parameter_name});	print "``" . $parameter . "``\n";

Lines 501–1000 of 2503. Previous lines