[warning control patch] simple cases

DJ Delorie dj@redhat.com
Wed May 18 19:34:00 GMT 2005


> | Oh, right.  Are we still limiting ourselves to 80 columns?
> 
> Yes :-)

There are some (1,329 in gcc/*.[ch]) long lines in the existing
sources.  I'm attaching a short perl script I wrote to find them, in
case anyone wants to work on making us conform.

I'll resubmit my patches shortly.

------------------------------ ./long-lines ------------------------------
#!/usr/bin/perl
# -*- perl -*-

use Text::Tabs;
$tabstop = 8;

$col = 80;

while ($ARGV[0] =~ /^-/) {
    $opt = shift;
    if ($opt =~ /-(\d+)/) {
	$col = $1;
    }
    $num = 1 if $opt eq "-n";
    $all = 1 if $opt eq "-a";
    $header = 1 if $opt eq "-h";
    $summary = 1 if $opt eq "-s";
}

if ($ARGV[0]) {
    for $file (@ARGV) {
	&scan($file);
    }
} else {
    &scan("<stdin>");
}

sub scan {
    my ($file) = @_;
    open(F, $file);
    $line = 0;

    if ($header) {
	$fheader = "------ $file ------\n";
    } else {
	$fheader = '';
    }

    while (<F>) {
	$line ++ if $num;
	chomp;
	$_ = expand($_);
	if (length ($_) > $col) {
	    print $fheader; $fheader = '';
	    printf("%06d:", $line) if $num;
	    print substr($_, 0, $col);
	    print "\033[31m";
	    print substr($_, $col);
	    print "\033[0m\n";
	    $longlines ++;
	} elsif ($all) {
	    print $fheader; $fheader = '';
	    printf("%06d:", $line) if $num;
	    print;
	    print "\n";
	}
	$totallines++;
    }
}

if ($summary && $totallines > 0) {
    printf("%d long lines out of %d (%.1f %%)\n",
	   $longlines, $totallines, 100 * $longlines / $totallines);
}
    



More information about the Gcc-patches mailing list