Re: [PATCH] scripts: add typdef removal tool

From: Joe Perches
Date: Tue Aug 11 2009 - 19:35:02 EST


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".

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

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

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

cheers, Joe

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/