2294 lines · 62.4 KB · Text
RawDownload
	}	$text =~ s/\&/\\\\\\amp;/g;	$text =~ s/\</\\\\\\lt;/g;	$text =~ s/\>/\\\\\\gt;/g;	return $text;} # convert local escape strings to html# local escape strings look like:  '\\\\menmonic:' (that's 4 backslashes)sub local_unescape($) {	my $text = shift;	if (($output_mode eq "text") || ($output_mode eq "man")) {		return $text;	}	$text =~ s/\\\\\\\\lt:/</g;	$text =~ s/\\\\\\\\gt:/>/g;	return $text;} sub process_file($) {    my $file;    my $identifier;    my $func;    my $descr;    my $in_purpose = 0;    my $initial_section_counter = $section_counter;     if (defined($ENV{'SRCTREE'})) {	$file = "$ENV{'SRCTREE'}" . "/" . "@_";    }    else {	$file = "@_";    }    if (defined($source_map{$file})) {	$file = $source_map{$file};    }     if (!open(IN,"<$file")) {	print STDERR "Error: Cannot open file $file\n";	++$errors;	return;    }     $. = 1;     $section_counter = 0;    while (<IN>) {	if ($state == 0) {	    if (/$doc_start/o) {		$state = 1;		# next line is always the function name		$in_doc_sect = 0;	    }	} elsif ($state == 1) {	# this line is the function name (always)	    if (/$doc_block/o) {		$state = 4;		$contents = "";		if ( $1 eq "" ) {			$section = $section_intro;		} else {			$section = $1;		}	    }	    elsif (/$doc_decl/o) {		$identifier = $1;		if (/\s*([\w\s]+?)\s*-/) {		    $identifier = $1;		} 		$state = 2;		if (/-(.*)/) {		    # strip leading/trailing/multiple spaces		    $descr= $1;		    $descr =~ s/^\s*//;		    $descr =~ s/\s*$//;		    $descr =~ s/\s+/ /;		    $declaration_purpose = xml_escape($descr);		    $in_purpose = 1;		} else {		    $declaration_purpose = "";		} 		if (($declaration_purpose eq "") && $verbose) {			print STDERR "Warning(${file}:$.): missing initial short description on line:\n";			print STDERR $_;			++$warnings;		} 		if ($identifier =~ m/^struct/) {		    $decl_type = 'struct';		} elsif ($identifier =~ m/^union/) {		    $decl_type = 'union';		} elsif ($identifier =~ m/^enum/) {		    $decl_type = 'enum';		} elsif ($identifier =~ m/^typedef/) {		    $decl_type = 'typedef';		} else {		    $decl_type = 'function';		} 		if ($verbose) {		    print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";		}	    } else {		print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",		" - I thought it was a doc line\n";		++$warnings;		$state = 0;	    }	} elsif ($state == 2) {	# look for head: lines, and include content	    if (/$doc_sect/o) {		$newsection = $1;		$newcontents = $2; 		if (($contents ne "") && ($contents ne "\n")) {		    if (!$in_doc_sect && $verbose) {			print STDERR "Warning(${file}:$.): contents before sections\n";			++$warnings;		    }		    dump_section($file, $section, xml_escape($contents));		    $section = $section_default;		} 		$in_doc_sect = 1;		$in_purpose = 0;		$contents = $newcontents;		if ($contents ne "") {		    while ((substr($contents, 0, 1) eq " ") ||			substr($contents, 0, 1) eq "\t") {			    $contents = substr($contents, 1);		    }		    $contents .= "\n";		}		$section = $newsection;	    } elsif (/$doc_end/) { 		if (($contents ne "") && ($contents ne "\n")) {		    dump_section($file, $section, xml_escape($contents));		    $section = $section_default;		    $contents = "";		}		# look for doc_com + <text> + doc_end:		if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {		    print STDERR "Warning(${file}:$.): suspicious ending line: $_";		    ++$warnings;		} 		$prototype = "";		$state = 3;		$brcount = 0;#		print STDERR "end of doc comment, looking for prototype\n";	    } elsif (/$doc_content/) {		# miguel-style comment kludge, look for blank lines after		# @parameter line to signify start of description		if ($1 eq "") {		    if ($section =~ m/^@/ || $section eq $section_context) {			dump_section($file, $section, xml_escape($contents));			$section = $section_default;			$contents = "";		    } else {			$contents .= "\n";		    }		    $in_purpose = 0;		} elsif ($in_purpose == 1) {		    # Continued declaration purpose		    chomp($declaration_purpose);		    $declaration_purpose .= " " . xml_escape($1);		} else {		    $contents .= $1 . "\n";		}	    } else {		# i dont know - bad line?  ignore.		print STDERR "Warning(${file}:$.): bad line: $_";		++$warnings;	    }	} elsif ($state == 3) {	# scanning for function '{' (end of prototype)	    if ($decl_type eq 'function') {		process_state3_function($_, $file);	    } else {		process_state3_type($_, $file);	    }	} elsif ($state == 4) {		# Documentation block		if (/$doc_block/) {			dump_doc_section($file, $section, xml_escape($contents));			$contents = "";			$function = "";			%constants = ();			%parameterdescs = ();			%parametertypes = ();			@parameterlist = ();			%sections = ();			@sectionlist = ();			$prototype = "";			if ( $1 eq "" ) {				$section = $section_intro;			} else {				$section = $1;			}		}		elsif (/$doc_end/)		{			dump_doc_section($file, $section, xml_escape($contents));			$contents = "";			$function = "";			%constants = ();			%parameterdescs = ();			%parametertypes = ();			@parameterlist = ();			%sections = ();			@sectionlist = ();			$prototype = "";			$state = 0;		}		elsif (/$doc_content/)		{			if ( $1 eq "" )			{				$contents .= $blankline;			}			else			{				$contents .= $1 . "\n";			}		}	}    }    if ($initial_section_counter == $section_counter) {	print STDERR "Warning(${file}): no structured comments found\n";	if ($output_mode eq "xml") {	    # The template wants at least one RefEntry here; make one.	    print "<refentry>\n";	    print " <refnamediv>\n";	    print "  <refname>\n";	    print "   ${file}\n";	    print "  </refname>\n";	    print "  <refpurpose>\n";	    print "   Document generation inconsistency\n";	    print "  </refpurpose>\n";	    print " </refnamediv>\n";	    print " <refsect1>\n";	    print "  <title>\n";	    print "   Oops\n";	    print "  </title>\n";	    print "  <warning>\n";	    print "   <para>\n";	    print "    The template for this document tried to insert\n";	    print "    the structured comment from the file\n";	    print "    <filename>${file}</filename> at this point,\n";	    print "    but none was found.\n";	    print "    This dummy section is inserted to allow\n";	    print "    generation to continue.\n";	    print "   </para>\n";	    print "  </warning>\n";	    print " </refsect1>\n";	    print "</refentry>\n";	}    }}  $kernelversion = get_kernel_version(); # generate a sequence of code that will splice in highlighting information# using the s// operator.foreach my $pattern (keys %highlights) {#   print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";    $dohighlight .=  "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";} # Read the file that maps relative names to absolute names for# separate source and object directories and for shadow trees.if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {	my ($relname, $absname);	while(<SOURCE_MAP>) {		chop();		($relname, $absname) = (split())[0..1];		$relname =~ s:^/+::;		$source_map{$relname} = $absname;	}	close(SOURCE_MAP);} foreach (@ARGV) {    chomp;    process_file($_);}if ($verbose && $errors) {  print STDERR "$errors errors\n";}if ($verbose && $warnings) {  print STDERR "$warnings warnings\n";} exit($errors);

Lines 2001–2294 of 2294. Previous lines