#!/usr/bin/perl -w
# (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit)
# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
# (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc)
# Licensed under the terms of the GNU GPL License version 2
use strict;
my $P = $0;
$P =~ s@.*/@@g;
my $V = '0.06';
use Getopt::Long qw(:config no_auto_abbrev);
my $quiet = 0;
my $tree = 1;
my $chk_signoff = 1;
my $chk_patch = 1;
my $tst_type = 0;
GetOptions(
'q|quiet' => \$quiet,
'tree!' => \$tree,
'signoff!' => \$chk_signoff,
'patch!' => \$chk_patch,
'test-type!' => \$tst_type,
) or exit;
my $exit = 0;
if ($#ARGV < 0) {
print "usage: $P [options] patchfile\n";
print "version: $V\n";
print "options: -q => quiet\n";
print " --no-tree => run without a kernel tree\n";
exit(1);
}
if ($tree && !top_of_kernel_tree()) {
print "Must be run from the top-level dir. of a kernel tree\n";
exit(2);
}
my @dep_includes = ();
my @dep_functions = ();
my $removal = 'Documentation/feature-removal-schedule.txt';
if ($tree && -f $removal) {
open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n";
while (<REMOVE>) {
if (/^Files:\s+(.*\S)/) {
for my $file (split(/[, ]+/, $1)) {
if ($file =~ m@include/(.*)@) {
push(@dep_includes, $1);
}
}
} elsif (/^Funcs:\s+(.*\S)/) {
for my $func (split(/[, ]+/, $1)) {
push(@dep_functions, $func);
}
}
}
}
my @rawlines = ();
while (<>) {
chomp;
push(@rawlines, $_);
if (eof(ARGV)) {
if (!process($ARGV, @rawlines)) {
$exit = 1;
}
@rawlines = ();
}
}
exit($exit);
sub top_of_kernel_tree {
if ((-f "COPYING") && (-f "CREDITS") && (-f "Kbuild") &&
(-f "MAINTAINERS") && (-f "Makefile") && (-f "README") &&
(-d "Documentation") && (-d "arch") && (-d "include") &&
(-d "drivers") && (-d "fs") && (-d "init") && (-d "ipc") &&
(-d "kernel") && (-d "lib") && (-d "scripts")) {
return 1;
}
return 0;
}
sub expand_tabs {
my ($str) = @_;
my $res = '';
my $n = 0;
for my $c (split(//, $str)) {
if ($c eq "\t") {
$res .= ' ';
$n++;
for (; ($n % 8) != 0; $n++) {
$res .= ' ';
}
next;
}
$res .= $c;
$n++;
}
return $res;
}
sub line_stats {
my ($line) = @_;
# Drop the diff line leader and expand tabs
$line =~ s/^.//;
$line = expand_tabs($line);
# Pick the indent from the front of the line.
my ($white) = ($line =~ /^(\s*)/);
return (length($line), length($white));
}
sub sanitise_line {
my ($line) = @_;
my $res = '';
my $l = '';
my $quote = '';
foreach my $c (split(//, $line)) {
if ($l ne "\\" && ($c eq "'" || $c eq '"')) {
if ($quote eq '') {
$quote = $c;
$res .= $c;
$l =