mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Erez Zadok <ezk@cs.sunysb.edu>
To: torvalds@linux-foundation.org, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Erez Zadok <ezk@cs.sunysb.edu>
Subject: [PATCH 3/3] New script to check coding-style compliance on multiple regular files
Date: Fri, 28 Sep 2007 17:32:02 -0400	[thread overview]
Message-ID: <1191015124866-git-send-email-ezk@cs.sunysb.edu> (raw)
In-Reply-To: <11910151223214-git-send-email-ezk@cs.sunysb.edu>

The script calls checkpatch.pl on each file, and formats any error messages
to comply with standard compiler error messages:

	file_name:line_number:error_message

This is particularly useful when run from within a text editor which can
parse these error messages and show the user a buffer with the file in
question, placing the cursor on the offending line (e.g., Emacs's "M-x
next-error" command, bound by default to C-x `).

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
---
 scripts/check-coding-standards.pl |   59 +++++++++++++++++++++++++++++++++++++
 1 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100755 scripts/check-coding-standards.pl

diff --git a/scripts/check-coding-standards.pl b/scripts/check-coding-standards.pl
new file mode 100755
index 0000000..a1ba597
--- /dev/null
+++ b/scripts/check-coding-standards.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/perl -w
+# (c) 2007, Erez Zadok <ezk@cs.sunysb.edu>
+# Licensed under the terms of the GNU GPL License version 2
+#
+# Check one more more files for compliance with coding standards.
+# Outputs standard compiler-error format, one error per line, as follows
+#	filename:lineno:errormsg
+# This standard error message can be parsed by various tools, including
+# Emacs's M-x next-error
+#
+# Usage: check-coding-standards.pl file [files...]
+
+
+if (!defined($ARGV[0])) {
+    printf("Usage: $0 file [files...]\n");
+    exit(1);
+}
+
+$msg="";
+$lineno=0;
+foreach $file (@ARGV) {
+    die "$file: $!" unless (-f $file);
+    open(FILE, "diff -u /dev/null $file | perl scripts/checkpatch.pl --no-signoff - |") || die "$file: $!";
+    while (($line = <FILE>)) {
+	chop $line;
+	next if ($line =~ /^$/);
+	if ($line =~ /^ERROR: /) {
+	    $msg = $line;
+	    next;
+	}
+	if ($line =~ /^WARNING: /) {
+	    $msg = $line;
+	    next;
+	}
+	if ($line =~ /^CHECK: /) {
+	    $msg = $line;
+	    next;
+	}
+	if ($line =~ /^#/) {
+	    $lineno = (split(/:/, $line))[3];
+	    next;
+	}
+	if ($line =~ /^\+/) {
+	    if ($lineno > 0) {
+		printf(STDOUT "%s:%d:%s\n", $file, $lineno, $msg);
+		$msg="";
+		$lineno=0;
+	    }
+	    next;
+	}
+	next if ($line =~ /^\s+\^/);
+	next if ($line =~ /^Your patch has style problems, please review/);
+	next if ($line =~ /^are false positives report them to the/);
+	next if ($line =~ /^CHECKPATCH in MAINTAINERS/);
+	next if ($line =~ /^Your patch has no obvious style problems/);
+	die "unknown output from checkpatch: $line: $.";
+    }
+    close(FILE);
+}
-- 
1.5.2.2


  parent reply	other threads:[~2007-09-28 21:32 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-28 21:31 [PATCH] 0/3 coding standards documentation/code updates Erez Zadok
2007-09-28 21:32 ` [PATCH 1/3] CodingStyle updates Erez Zadok
2007-09-28 21:46   ` Randy Dunlap
2007-09-29 14:43   ` Shawn Bohrer
2007-09-29 15:59   ` Scott Preece
2007-09-29 18:01   ` Randy Dunlap
2007-09-29 18:29     ` Sam Ravnborg
2007-09-29 20:21       ` [OT] kbuild syntax extension for ccflags and asflags (was: [PATCH 1/3] CodingStyle updates) Ingo Oeser
2007-09-29 20:24         ` Sam Ravnborg
2007-09-28 21:32 ` [PATCH 2/3] Update usage string for checkpatch.pl Erez Zadok
2007-09-28 21:32 ` Erez Zadok [this message]
2007-09-29 10:10   ` [PATCH 3/3] New script to check coding-style compliance on multiple regular files Sam Ravnborg
2007-09-29 18:18 ` [PATCH] 0/3 coding standards documentation/code updates Linus Torvalds
2007-09-29 19:56   ` J. Bruce Fields
2007-09-29 20:14     ` Randy Dunlap
2007-09-30  2:06     ` Theodore Tso
2007-09-30  3:28       ` Erez Zadok
2007-09-29 21:56   ` Robert P. J. Day
2007-09-30  0:23   ` Erez Zadok
2007-09-30  0:49     ` Linus Torvalds
2007-09-30  4:01       ` Erez Zadok
2007-09-30 17:40         ` Mark Lord
2007-09-30 17:59           ` Randy Dunlap
2007-09-30  2:24   ` Valdis.Kletnieks
2007-09-30  3:00     ` Linus Torvalds
2007-09-30  3:29       ` Valdis.Kletnieks
2007-09-30  3:35         ` Linus Torvalds
2007-09-30 17:57         ` Theodore Tso
2007-09-30  3:27     ` Al Viro
2007-09-30  3:39       ` Valdis.Kletnieks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1191015124866-git-send-email-ezk@cs.sunysb.edu \
    --to=ezk@cs.sunysb.edu \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome