public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: Amerigo Wang <xiyou.wangcong@gmail.com>
Cc: "Luis R. Rodriguez" <lrodriguez@atheros.com>,
	Nicolas Palix <npalix@diku.dk>,
	linux-kernel@vger.kernel.org,
	Yoann Padioleau <yoann.padioleau@gmail.com>,
	Julia Lawall <julia@diku.dk>, Joe Perches <joe@perches.com>,
	devel@driverdev.osuosl.org, akpm@linux-foundation.org
Subject: Re: [PATCH v2] scripts: add typdef removal tool
Date: Fri, 21 Aug 2009 10:48:51 +0200	[thread overview]
Message-ID: <4A8E5F73.6010904@gmail.com> (raw)
In-Reply-To: <20090817060203.GL5039@cr0.nay.redhat.com>

Hi!

On 08/17/2009 08:02 AM, Amerigo Wang wrote:
...
>> --- /dev/null
>> +++ b/scripts/remove-typedef
>> @@ -0,0 +1,70 @@
>> +#!/bin/bash
>> +#
>> +# Copyright 2009 Joe Perches <joe@perches.com>
>> +# Copyright 2009 Luis R. Rodriguez <mcgrof@gmail.com>
>> +#
>> +# Lets you remove typedefs from C/header files.
>> +#
>> +# We do simple sed substituation for logical places where you would

substitution

>> +function remove_typedef()
>> +{
>> +	if [ ! -f $1 ]; then
>> +		return;
>> +	fi
>> +
>> +	# This replaces the typedef 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

Could that be one sed with multiple -e's?

>> +	# This replaces the typedef declaration for a simple struct declaration - style 0
>> +	perl -i -e "local $/; while(<>) { s/\btypedef\s+struct\s+([\d\D]+?)\s*\{([\d\D]+?)\}\s*struct\s+$to\b[^;]*;/struct $to \{\2\};/g; print; }" $1

This is safe until bash devs start to use $/ as something. It should be
escaped.

>> +	# This replaces the typedef 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 typedef 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

And possibly one
perl -ipe "BEGIN { \$/ = '' };
	s/x/y/g;
	s/y/z/g;"
?

Or do the sed work by perl too?

>> +}
>> +
>> +if [[ $# -lt 3 ]]; then

Could that be [ ] instead of [[ ]]?

>> +	usage
>> +fi
>> +
>> +from=$1
>> +to=$2
>> +shift
>> +echo "Converting typedef $from to struct $to"
>> +
>> +while shift; do
>> +	REM_PATH=$1
>> +
>> +	if [ -z $REM_PATH ]; then
>> +		continue;
>> +	fi
>> +
>> +	if [ ! -d $REM_PATH ]; then
>> +		echo "No directory $REM_PATH";
>> +		continue;
>> +	fi
>> +
>> +	for i in $(find $REM_PATH -type f -name *.c); do
>> +		remove_typedef $i
>> +	done
>> +
>> +	for i in $(find $REM_PATH -type f -name *.h); do
>> +		remove_typedef $i
>> +	done
> 
> These two 'find's can be merged:
> 
>   find $REM_PATH -type f -name '*.c' -o -name '*.h'

Yes, please enclose those wildcards into ''. Also REM_PATH can be with
spaces, use "" for it, $i and $1 etc.

  reply	other threads:[~2009-08-21  8:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-14  5:39 [PATCH v2] scripts: add typdef removal tool Luis R. Rodriguez
2009-08-17  6:02 ` Amerigo Wang
2009-08-21  8:48   ` Jiri Slaby [this message]
2009-08-23 13:09     ` Matthias Urlichs
2009-08-23 16:06       ` Américo Wang
2009-08-23 13:22   ` Matthias Urlichs
2009-08-23 16:04     ` Américo Wang
2009-08-23 17:59     ` Jiri Slaby
2009-08-25 14:35       ` Matthias Urlichs
2010-09-19  8:19 ` Pekka Enberg
2010-09-19  8:49   ` Joe Perches
2010-09-19  9:30     ` Pekka Enberg
2010-09-19 15:03       ` Luis R. Rodriguez

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=4A8E5F73.6010904@gmail.com \
    --to=jirislaby@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=joe@perches.com \
    --cc=julia@diku.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrodriguez@atheros.com \
    --cc=npalix@diku.dk \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yoann.padioleau@gmail.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