summaryrefslogtreecommitdiff
path: root/v4l/scripts/check.pl
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2007-12-10 16:34:26 -0200
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-12-10 16:34:26 -0200
commitcdac3fcffa086178870fd6f48bc828d0ca878905 (patch)
treee644df98480774f3d5f839cae907845221454e7f /v4l/scripts/check.pl
parentdb762262e6462dc271dbd1bb302f727ef6caa44c (diff)
parent555a3965e83ee2a24df89423a301b802d0a54c5e (diff)
downloadmediapointer-dvb-s2-cdac3fcffa086178870fd6f48bc828d0ca878905.tar.gz
mediapointer-dvb-s2-cdac3fcffa086178870fd6f48bc828d0ca878905.tar.bz2
merge: http://www.linuxtv.org/hg/~hverkuil/v4l-dvb
From: Mauro Carvalho Chehab <mchehab@infradead.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'v4l/scripts/check.pl')
-rwxr-xr-xv4l/scripts/check.pl118
1 files changed, 118 insertions, 0 deletions
diff --git a/v4l/scripts/check.pl b/v4l/scripts/check.pl
new file mode 100755
index 000000000..4958e281b
--- /dev/null
+++ b/v4l/scripts/check.pl
@@ -0,0 +1,118 @@
+#!/usr/bin/perl
+use Getopt::Std;
+use strict;
+
+my $c_syntax=0;
+my $fmt="--emacs";
+
+my %opt;
+
+sub usage ($)
+{
+ my $name = shift;
+ printf "Usage: %s [<args>] [<file>]\n".
+ "\t-c\tc style\n".
+ "\t-e\emacs style (default)\n".
+ "\t-t\terse style (default)\n".
+ "\t<file>\tfile name to open. If file not specified, uses hg diff\n\n", $name;
+
+ exit -1;
+}
+
+if (not getopts('cet',\%opt) or defined $opt{'h'}) {
+ usage($0);
+}
+
+my $cmd=shift;
+
+if ($opt{'c'}) {
+ $c_syntax=1;
+}
+
+if ($opt{'t'}) {
+ $fmt="--terse";
+ $c_syntax=0;
+}
+
+if ($cmd) {
+ $cmd="diff -upr /dev/null $cmd";
+} else {
+ $cmd="hg diff";
+}
+
+my $checkpatch=$ENV{CHECKPATCH};
+
+if (!$checkpatch) {
+ $checkpatch="/lib/modules/`uname -r`/build/scripts/checkpatch.pl";
+}
+
+my $cp_version;
+open IN,"$checkpatch|";
+while (<IN>) {
+ tr/A-Z/a-z/;
+ if (m/version\s*:\s*([\d\.]+)/) {
+ $cp_version = $1;
+ }
+}
+close IN;
+
+my $intree_checkpatch = "scripts/checkpatch.pl --no-tree";
+if (!open IN,"$intree_checkpatch|") {
+ $intree_checkpatch = "v4l/".$intree_checkpatch;
+ open IN,"$intree_checkpatch|";
+}
+while (<IN>) {
+ tr/A-Z/a-z/;
+ if (m/version\s*:\s*([\d\.]+)/) {
+ if ($1 > $cp_version) {
+ print "# WARNING: $checkpatch version $cp_version is\n"
+ ."# older than $intree_checkpatch version"
+ ." $1.\n# Using in-tree one.\n#\n";
+ $cp_version = $1;
+ $checkpatch = $intree_checkpatch;
+ }
+ }
+}
+close IN;
+
+open IN,"$cmd | $checkpatch -q --nosignoff $fmt -|";
+
+my $err="";
+my $errline="";
+my $file="";
+my $ln_numb;
+
+my $pwd=`pwd`;
+$pwd =~ s|/[^/]+\n$||;
+
+sub print_err()
+{
+ if ($err) {
+ printf STDERR "%s/%s: In '%s':\n", $pwd, $file, $errline;
+ printf STDERR "%s/%s:%d: %s\n", $pwd, $file, $ln_numb, $err;
+ $err="";
+ }
+}
+
+if ($c_syntax == 0) {
+ while (<IN>) {
+ s|^#[\d]+:\s*FILE:\s*|../|;
+ print "$_";
+ }
+} else {
+ while (<IN>) {
+ if (m/^\+(.*)\n/) {
+ $errline=$1;
+ } elsif (m/^\#\s*[\d]+\s*:\s*FILE:\s*([^\:]+)\:([\d]+)/) {
+ $file=$1;
+ $ln_numb=$2;
+ } elsif (m/^\-\s*\:\d+\:\s*(.*)\n/) {
+ print_err();
+ $err = $1;
+ $err =~ s/WARNING/warning/;
+ }
+# print "# $_";
+ }
+}
+close IN;
+print_err();