fix-casts.sh

Tue, 21 Jul 2009 23:45:49 +0000

author
Etan Reisner <deryni@pidgin.im>
date
Tue, 21 Jul 2009 23:45:49 +0000
changeset 27927
b62ae35b71ed
parent 24975
7abe1341dc45
permissions
-rwxr-xr-x

merge of '8a058554f86508b8aff7b45367184ff0b4cd3adc'
and 'f0bc9d8b23450915a67513356ecd0c56eb185fd4'

#!/bin/sh

if [ $# -eq 0 ]; then
	echo "Usage: `basename "$0"` PurpleFoo..."
	echo
	echo "This script searches the *current working directory* and replaces casts"
	echo "with GObject-style type checking and casting macros."
	echo 'For example, "(PurpleBuddy *)b" becomes "PURPLE_BUDDY(b)".'
	exit 0
fi

for struct in $* ; do
	cast=`echo $struct | sed "s|[A-Z]|_\0|g" | tr "a-z" "A-Z" | sed "s|^_||"`
	for file in `grep -rl "([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)" . --include=*.c --exclude=purple-client-bindings.c` ; do
		sed -i "s|([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)[[:space:]]*(|$cast(|g" $file
		sed -i "s|([[:space:]]*$struct[[:space:]]*\*[[:space:]]*)[[:space:]]*\([^(][^,);]*\)|$cast(\1)|g" $file
	done
done

mercurial