public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Roland Dreier <rdreier@cisco.com>, general@lists.openfabrics.org
Subject: [RFC PATCH] - scripts/CodingStyle_sizeof - standardize sizeof and [PATCH] drivers/infiniband - standardize sizeof(foo)
Date: Tue, 01 Jul 2008 09:49:46 -0700	[thread overview]
Message-ID: <1214930986.26073.40.camel@localhost> (raw)

[-- Attachment #1: Type: text/plain, Size: 2101 bytes --]

Scripts could be used to generate CodingStyle patches
in reviewable units.

For instance, kernel source has multiple style uses of sizeof

sizeof(foo)
sizeof foo
sizeof (foo)

Perhaps Julia Lawall semantic patches might work better,
but this script might help standardize on the CodingStyle
preferred sizeof(foo).

It's an imperfect tool.  Any patch generated by a tool
(yes, I just called myself a tool..:) must be inspected
and verified before being applied.

A sample patch of drivers_infiniband.patch generated by
$ scripts/CodingStyle_sizeof drivers/infiniband
is also attached as bz2

Signed-off-by: Joe Perches <joe@perches.com>
---
 scripts/CodingStyle_sizeof |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/scripts/CodingStyle_sizeof b/scripts/CodingStyle_sizeof
new file mode 100755
index 0000000..7f2444f
--- /dev/null
+++ b/scripts/CodingStyle_sizeof
@@ -0,0 +1,33 @@
+#!/bin/bash
+if [ $# -ne 1 ] ; then
+    echo "$0 takes 1 argument: directory|file"
+    exit
+fi
+if [[ ! -f $1 && ! -d $1 ]] ; then
+    echo "Directory or file: $1 not found"
+    exit
+fi
+if [ -d $1 ] ; then
+    findfile="find $1 -name \"*.[ch]\""
+else
+    findfile="ls $1"
+fi
+patchfile=$1.patch
+patchfile=${patchfile//\//_}
+git checkout $1
+for file in $(eval $findfile) ; do
+    sed -r -i -e 's/\bsizeof\s+([^\(][^ ;,]+)\s*/sizeof\(\1\)/g' $file
+    sed -r -i -e 's/\bsizeof\s+/sizeof/g' $file
+done
+git diff -p --stat $1 > $patchfile
+# fixup the generated diff
+# add space between close paren and (brace, assign, arithmetic or logical test)
+sed -r -i -e 's/^\+(.*)\)([\{\=\+\*\/\<\>\|\!\&\?\-])/\+\1\) \2/g' $patchfile
+# remove space between ') ->' added by sed above
+sed -r -i -e 's/^\+(.*)\) ->/\+\1\)->/g' $patchfile
+# fix declaration with sizeof brackets ie: char foo[sizeof("bar")];
+sed -r -i -e 's/^\+(.*)\[(.*)\((.*)\]\)/\+\1\[\2\(\3\)\]/g' $patchfile
+# fix sizeof array element ie: sizeof(foo->bar[n])
+sed -r -i -e 's/^\+(.*)sizeof\((.*)\[(.*)\)\]/\+\1sizeof\(\2\[\3\]\)/g' $patchfile
+git checkout $1
+patch -p1 < $patchfile


[-- Attachment #2: drivers_infiniband.patch.bz2 --]
[-- Type: application/x-bzip, Size: 37502 bytes --]

             reply	other threads:[~2008-07-01 17:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-01 16:49 Joe Perches [this message]
2008-07-01 17:57 ` [RFC PATCH] - scripts/CodingStyle_sizeof - standardize sizeof and [PATCH] drivers/infiniband - standardize sizeof(foo) Roland Dreier
2008-07-01 17:37   ` Joe Perches
2008-07-01 19:21   ` [ofa-general] " Dotan Barak

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=1214930986.26073.40.camel@localhost \
    --to=joe@perches.com \
    --cc=general@lists.openfabrics.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.com \
    /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