Blame maint/extractfixme

Packit Service c5cf8c
#! /usr/bin/env perl
Packit Service c5cf8c
# -*- Mode: perl; -*-
Packit Service c5cf8c
# Tested with -w 10/28/05
Packit Service c5cf8c
# 
Packit Service c5cf8c
# Find the parse.sub routine.
Packit Service c5cf8c
my $maintdir = "./maint";
Packit Service c5cf8c
my $rootdir  = ".";
Packit Service c5cf8c
if ( ! -s "maint/parse.sub" ) {
Packit Service c5cf8c
    my $program = $0;
Packit Service c5cf8c
    $program =~ s/^.*[\/\\]//;
Packit Service c5cf8c
    if (-s "$program/parse.sub") {
Packit Service c5cf8c
	$maintdir = $program;
Packit Service c5cf8c
	$rootdir  = $program;
Packit Service c5cf8c
	$rootdir  =~ s/\/maint//g;
Packit Service c5cf8c
	print "Rootdir = $rootdir\n" if $debug;
Packit Service c5cf8c
    }
Packit Service c5cf8c
}
Packit Service c5cf8c
require "$maintdir/parse.sub";
Packit Service c5cf8c
Packit Service c5cf8c
$debug = 0;
Packit Service c5cf8c
$showfiles = 0;
Packit Service c5cf8c
$quiet = 0;
Packit Service c5cf8c
Packit Service c5cf8c
$textOutput = 1;
Packit Service c5cf8c
$htmlOutput = 0;
Packit Service c5cf8c
$htmlFullpage = 0;
Packit Service c5cf8c
Packit Service c5cf8c
# Strict is used to control checking of error message strings.
Packit Service c5cf8c
$gStrict = 0;
Packit Service c5cf8c
if (defined($ENV{"DEBUG_STRICT"})) { $gStrict = 1; }
Packit Service c5cf8c
Packit Service c5cf8c
# Check for special args
Packit Service c5cf8c
@files = ();
Packit Service c5cf8c
%skipFiles = ();
Packit Service c5cf8c
foreach $arg (@ARGV) {
Packit Service c5cf8c
    if ($arg =~ /^-showfiles/) { $showfiles = 1; }
Packit Service c5cf8c
    elsif( $arg =~ /-debug/) { $debug = 1; }
Packit Service c5cf8c
    elsif( $arg =~ /-quiet/) { $quiet = 1; }
Packit Service c5cf8c
    elsif( $arg =~ /-html/)  { $textOutput = 0; 
Packit Service c5cf8c
			       $htmlOutput = 1; $htmlFullpage = 1; }
Packit Service c5cf8c
    elsif( $arg =~ /-skip=(.*)/) { $skipFiles{$1} = 1; }
Packit Service c5cf8c
    else {
Packit Service c5cf8c
	print "Adding $arg to files\n" if $debug;
Packit Service c5cf8c
	if (-d $arg) {
Packit Service c5cf8c
	    # Add all .c files from directory $arg to the list of files 
Packit Service c5cf8c
	    # to process (this lets shorten the arg list)
Packit Service c5cf8c
	    @files = (@files, &ExpandDir( $arg ));
Packit Service c5cf8c
	}
Packit Service c5cf8c
	else {
Packit Service c5cf8c
	    $files[$#files+1] = $arg;
Packit Service c5cf8c
	}
Packit Service c5cf8c
    }
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
# Be nice to Windows
Packit Service c5cf8c
$eol = "\r\n";
Packit Service c5cf8c
if ($htmlOutput) {
Packit Service c5cf8c
    if ($htmlFullpage) {
Packit Service c5cf8c
	print STDOUT "<html><head><title>FIXME Items for MPICH</title></head>$eol";
Packit Service c5cf8c
	print STDOUT "<body bgcolor=\"ffffff\">$eol";
Packit Service c5cf8c
    }
Packit Service c5cf8c
    print STDOUT "$eol";
FileFIXME Note
Packit Service c5cf8c
}
Packit Service c5cf8c
# Process the definitions
Packit Service c5cf8c
foreach $file (@files) {
Packit Service c5cf8c
    print "$file\n" if $showfiles;
Packit Service c5cf8c
    &ProcessFile( $file );
Packit Service c5cf8c
}
Packit Service c5cf8c
if ($htmlOutput) {
Packit Service c5cf8c
    print STDOUT "$eol";
Packit Service c5cf8c
    if ($htmlFullpage) {
Packit Service c5cf8c
	print STDOUT "</body></html>$eol";
Packit Service c5cf8c
    }
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
#-----------------------------------------------------------------------------
Packit Service c5cf8c
# ROUTINES
Packit Service c5cf8c
# ----------------------------------------------------------------------------
Packit Service c5cf8c
Packit Service c5cf8c
# ==========================================================================
Packit Service c5cf8c
# Call this for each file
Packit Service c5cf8c
# This reads a C source or header file and adds does the following:
Packit Service c5cf8c
#   adds any generic message short names encountered to the hash generic_msgs.
Packit Service c5cf8c
#   adds any specific message short names encounter to the hash specific_msgs.
Packit Service c5cf8c
#   adds the filename to the hash generic_loc{msg} as the value (: separated)
Packit Service c5cf8c
#       and the same for hash specific_loc{msg}.
Packit Service c5cf8c
#   The last two are used to provide better error reporting.
Packit Service c5cf8c
#
Packit Service c5cf8c
$filename = "";    # Make global so that other routines can echo filename
Packit Service c5cf8c
$comment_line = "";
Packit Service c5cf8c
sub ProcessFile
Packit Service c5cf8c
{ 
Packit Service c5cf8c
    # Leave filename global for AddTest
Packit Service c5cf8c
    $filename = $_[0];
Packit Service c5cf8c
    open (FD, "<$filename" ) || die "Could not open $filename\n";
Packit Service c5cf8c
Packit Service c5cf8c
    while (<FD>) {
Packit Service c5cf8c
	# Look for /* FIXME
Packit Service c5cf8c
	while (/\/\*\s[Ff][Ii][Xx][Mm][Ee]/) {
Packit Service c5cf8c
	    $comment_line = "";
Packit Service c5cf8c
	    $_ = StripComments( FD, $_ );
Packit Service c5cf8c
	    # Comment is in $comment_line
Packit Service c5cf8c
	    $comment_line =~ s/\/\*\s*[Ff][Ii][Xx][Mm][Ee]:?\s*//;
Packit Service c5cf8c
	    $comment_line =~ s/\s*\*\///;
Packit Service c5cf8c
	    &PrintFIXME( $filename, $comment_line );
Packit Service c5cf8c
	}
Packit Service c5cf8c
    }		
Packit Service c5cf8c
    close FD;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
# Get all of the .c files from the named directory, including any subdirs
Packit Service c5cf8c
sub ExpandDir {
Packit Service c5cf8c
    my $dir = $_[0];
Packit Service c5cf8c
    my @otherdirs = ();
Packit Service c5cf8c
    my @files = ();
Packit Service c5cf8c
    opendir DIR, "$dir";
Packit Service c5cf8c
    for $filename (sort readdir DIR) {
Packit Service c5cf8c
	if ($filename =~ /^\./ || $filename eq ".svn") {
Packit Service c5cf8c
	    next;
Packit Service c5cf8c
	}
Packit Service c5cf8c
	elsif (-d "$dir/$filename") {
Packit Service c5cf8c
	    $otherdirs[$#otherdirs+1] = "$dir/$filename";
Packit Service c5cf8c
	}
Packit Service c5cf8c
	elsif ($filename =~ /(.*\.[chi])$/) {
Packit Service c5cf8c
	    # Test for both Unix- and Windows-style directory separators
Packit Service c5cf8c
	    if (!defined($skipFiles{"$dir/$filename"}) &&
Packit Service c5cf8c
		!defined($skipFiles{"dir\\$filename"})) {
Packit Service c5cf8c
		$files[$#files + 1] = "$dir/$filename";
Packit Service c5cf8c
	    }
Packit Service c5cf8c
	}
Packit Service c5cf8c
    }
Packit Service c5cf8c
    closedir DIR;
Packit Service c5cf8c
    # (almost) tail recurse on otherdirs (we've closed the directory handle,
Packit Service c5cf8c
    # so we don't need to worry about it anymore)
Packit Service c5cf8c
    foreach $dir (@otherdirs) {
Packit Service c5cf8c
	@files = (@files, &ExpandDir( $dir ) );
Packit Service c5cf8c
    }
Packit Service c5cf8c
    return @files;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
sub PrintFIXME {
Packit Service c5cf8c
    my ($filename, $comment_line ) = @_;
Packit Service c5cf8c
    
Packit Service c5cf8c
    # Some fixmes start with fixme - ; remove the - in that case.
Packit Service c5cf8c
    $comment_line =~ s/^\s*[:-]\s*//;
Packit Service c5cf8c
    if ($textOutput) {
Packit Service c5cf8c
	print STDOUT $filename . ":";
Packit Service c5cf8c
	foreach my $line (split(/\r?\n/,$comment_line)) {
Packit Service c5cf8c
	    # Remote any leading blanks or *
Packit Service c5cf8c
	    $line =~ s/^\s*//;
Packit Service c5cf8c
	    $line =~ s/^\*\s?//g;
Packit Service c5cf8c
	    print $line . "\n";
Packit Service c5cf8c
	}
Packit Service c5cf8c
    }
Packit Service c5cf8c
    elsif ($htmlOutput) {
Packit Service c5cf8c
	# HTMLify the line
Packit Service c5cf8c
	if ($comment_line =~ /--AMP--/) {
Packit Service c5cf8c
	    print STDERR "Comment line contains --AMP--\n";
Packit Service c5cf8c
	}
Packit Service c5cf8c
	else {
Packit Service c5cf8c
	    $comment_line =~ s/&/--AMP--amp;/g;
Packit Service c5cf8c
	    $comment_line =~ s/</--AMP--lt;/g;
Packit Service c5cf8c
	    $comment_line =~ s/>/--AMP--gt;/g;
Packit Service c5cf8c
	    $comment_line =~ s/--AMP--/&/;;
Packit Service c5cf8c
	}
Packit Service c5cf8c
	print STDOUT "$filename";
Packit Service c5cf8c
	my $nl = "";
Packit Service c5cf8c
	foreach my $line (split(/\r?\n/,$comment_line)) {
Packit Service c5cf8c
	    # Remote any leading blanks or *
Packit Service c5cf8c
	    $line =~ s/^\s*//;
Packit Service c5cf8c
	    $line =~ s/^\*\s?//g;
Packit Service c5cf8c
	    print $nl . $line;
Packit Service c5cf8c
	    $nl = "
$eol";
Packit Service c5cf8c
	}
Packit Service c5cf8c
	print STDOUT "
$eol"
Packit Service c5cf8c
    }
Packit Service c5cf8c
    else {
Packit Service c5cf8c
	print STDERR "Unknown output form\n";
Packit Service c5cf8c
	exit(1);
Packit Service c5cf8c
    }
Packit Service c5cf8c
}