Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 61826
b: refs/heads/master
c: cb3ed5b
h: refs/heads/master
v: v3
  • Loading branch information
H. Peter Anvin authored and Sam Ravnborg committed Jul 16, 2007
1 parent a5964b2 commit 3e66187
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d72e5edbf4d13adfe489e9e6114a4922891ddcb2
refs/heads/master: cb3ed5b7e09c6c0462e396d55e3fecc0980a333a
54 changes: 52 additions & 2 deletions trunk/scripts/cleanfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use bytes;
use File::Basename;

#
# Default options
$max_width = 79;

# Clean up space-tab sequences, either by removing spaces or
# replacing them with tabs.
sub clean_space_tabs($)
Expand Down Expand Up @@ -48,9 +50,49 @@ sub clean_space_tabs($)
return $lo;
}

# Compute the visual width of a string
sub strwidth($) {
no bytes; # Tab alignment depends on characters

my($li) = @_;
my($c, $i);
my $pos = 0;
my $mlen = 0;

for ($i = 0; $i < length($li); $i++) {
$c = substr($li,$i,1);
if ($c eq "\t") {
$pos = ($pos+8) & ~7;
} elsif ($c eq "\n") {
$mlen = $pos if ($pos > $mlen);
$pos = 0;
} else {
$pos++;
}
}

$mlen = $pos if ($pos > $mlen);
return $mlen;
}

$name = basename($0);

foreach $f ( @ARGV ) {
@files = ();

while (defined($a = shift(@ARGV))) {
if ($a =~ /^-/) {
if ($a eq '-width' || $a eq '-w') {
$max_width = shift(@ARGV)+0;
} else {
print STDERR "Usage: $name [-width #] files...\n";
exit 1;
}
} else {
push(@files, $a);
}
}

foreach $f ( @files ) {
print STDERR "$name: $f\n";

if (! -f $f) {
Expand Down Expand Up @@ -90,8 +132,10 @@ foreach $f ( @ARGV ) {

@blanks = ();
@lines = ();
$lineno = 0;

while ( defined($line = <FILE>) ) {
$lineno++;
$in_bytes += length($line);
$line =~ s/[ \t\r]*$//; # Remove trailing spaces
$line = clean_space_tabs($line);
Expand All @@ -107,6 +151,12 @@ foreach $f ( @ARGV ) {
@blanks = ();
$blank_bytes = 0;
}

$l_width = strwidth($line);
if ($max_width && $l_width > $max_width) {
print STDERR
"$f:$lineno: line exceeds $max_width characters ($l_width)\n";
}
}

# Any blanks at the end of the file are discarded
Expand Down
58 changes: 55 additions & 3 deletions trunk/scripts/cleanpatch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use bytes;
use File::Basename;

#
# Default options
$max_width = 79;

# Clean up space-tab sequences, either by removing spaces or
# replacing them with tabs.
sub clean_space_tabs($)
Expand Down Expand Up @@ -48,9 +50,49 @@ sub clean_space_tabs($)
return $lo;
}

# Compute the visual width of a string
sub strwidth($) {
no bytes; # Tab alignment depends on characters

my($li) = @_;
my($c, $i);
my $pos = 0;
my $mlen = 0;

for ($i = 0; $i < length($li); $i++) {
$c = substr($li,$i,1);
if ($c eq "\t") {
$pos = ($pos+8) & ~7;
} elsif ($c eq "\n") {
$mlen = $pos if ($pos > $mlen);
$pos = 0;
} else {
$pos++;
}
}

$mlen = $pos if ($pos > $mlen);
return $mlen;
}

$name = basename($0);

foreach $f ( @ARGV ) {
@files = ();

while (defined($a = shift(@ARGV))) {
if ($a =~ /^-/) {
if ($a eq '-width' || $a eq '-w') {
$max_width = shift(@ARGV)+0;
} else {
print STDERR "Usage: $name [-width #] files...\n";
exit 1;
}
} else {
push(@files, $a);
}
}

foreach $f ( @files ) {
print STDERR "$name: $f\n";

if (! -f $f) {
Expand Down Expand Up @@ -86,17 +128,20 @@ foreach $f ( @ARGV ) {

$in_bytes = 0;
$out_bytes = 0;
$lineno = 0;

@lines = ();

$in_hunk = 0;
$err = 0;

while ( defined($line = <FILE>) ) {
$lineno++;
$in_bytes += length($line);

if (!$in_hunk) {
if ($line =~ /^\@\@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)\s\@\@/) {
if ($line =~
/^\@\@\s+\-([0-9]+),([0-9]+)\s+\+([0-9]+),([0-9]+)\s\@\@/) {
$minus_lines = $2;
$plus_lines = $4;
if ($minus_lines || $plus_lines) {
Expand All @@ -117,6 +162,13 @@ foreach $f ( @ARGV ) {
$text =~ s/[ \t\r]*$//; # Remove trailing spaces
$text = clean_space_tabs($text);

$l_width = strwidth($text);
if ($max_width && $l_width > $max_width) {
print STDERR
"$f:$lineno: adds line exceeds $max_width ",
"characters ($l_width)\n";
}

push(@hunk_lines, '+'.$text);
} elsif ($line =~ /^\-/) {
$minus_lines--;
Expand Down

0 comments on commit 3e66187

Please sign in to comment.