public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <lrodriguez@atheros.com>
To: Joe Perches <joe@perches.com>
Cc: Luis Rodriguez <Luis.Rodriguez@atheros.com>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"devel@driverdev.osuosl.org" <devel@driverdev.osuosl.org>
Subject: Re: [PATCH] scripts: add typdef removal tool
Date: Thu, 13 Aug 2009 22:29:15 -0700	[thread overview]
Message-ID: <20090814052915.GD28524@mosca> (raw)
In-Reply-To: <1250033655.8895.631.camel@Joe-Laptop.home>

On Tue, Aug 11, 2009 at 04:34:15PM -0700, Joe Perches wrote:
> On Tue, 2009-08-11 at 15:51 -0700, Luis R. Rodriguez wrote:
> > If you are porting drivers and need to remove tydpefs you can use
> > this to help you port the driver quicker.
> 
> > +     # This replaces the typdef declaration for a simple struct declaration - style 1
> > +     perl -i -e "local $/; while(<>) { s/\btypedef\s+struct\s+_$from\s*\{([\d\D]+?)\}\s*struct\s+$to\b[^;]*;/struct $to \{\1\};/g; print; }" $1
> > +
> > +     # This replaces the typdef declaration for a simple struct declaration - style 2
> > +     perl -i -e "local $/; while(<>) { s/\btypedef\s+struct\s+$to\s*\{([\d\D]+?)\}\s*$from\b[^;]*;/struct $to \{\1\};/g; print; }" $1
> > +
> > +     # This replaces the typdef usages with simple structs
> > +     sed -r -i -e "s/\b$from\b/struct $to/g" $1
> > +     sed -r -i -e "s/\bP$from\b/struct $to \*/g" $1
> > +     sed -r -i -e "s/struct $to\s*\*\s*\b/struct $to \*/g" $1
> > +     sed -r -i -e "s/\(struct $to\s*\*\)\s*/\(struct $to \*\)/g" $1
> 
> Hi Luis.
> 
> A couple of comments:
> 
> In the comments "typdef" should be "typedef".

Fixed.

> I believe the sed statements need to be run before the perl statements.

OK, swapped it around.

> Another common microsoft form is
> 
>         typedef struct tagFOO {
>                 members
>         } FOO [, *PFOO [, **PPFOO ];
> 
> So maybe perl statement 1 could be:
> 
> s/\btypedef\s+struct\s+$to\s*(_{0,1}|tag)$from etc
> 
> and another sed statement might be:
> 
> sed -r -i -e "s/\(struct $to\s*\*\s*\*\s*\)\s*/\(struct $to \*\*\)/g" $1

Yeah I just spotted another form:

typedef struct whatever {
	members
} FOO;

So we need to ignore 'whatever', I've tested this. I'll send a v2 with this and
addressing the other comments you've made.

Mind sending these as a patch on top of the script?

> Maybe you could test this against next:drivers/staging/hv/ to see
> how well this works.

I'm testing against some ar9271 driver I'm porting but I get a chance
I'll test it hv, not sure if I will though. Feel free to do so though
and let me know how it goes.

  Luis

      reply	other threads:[~2009-08-14  5:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-11 22:51 [PATCH] scripts: add typdef removal tool Luis R. Rodriguez
2009-08-11 23:34 ` Joe Perches
2009-08-14  5:29   ` Luis R. Rodriguez [this message]

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=20090814052915.GD28524@mosca \
    --to=lrodriguez@atheros.com \
    --cc=Luis.Rodriguez@atheros.com \
    --cc=akpm@linux-foundation.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.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