script to cleanup remove extra space and (void)

Max Okumoto okumoto at home
Tue Nov 23 21:55:19 PST 2004


Hi Douwe,

I wrote a script to remove those unwanted spaces and (void) casts.
Since you suggested removing the (void) casts from the make code
I thought you might want it too.
				Max Okumoto

# Abstract: Fix some problems in 'C' src files.
#       o remove space between function name and parameters.
#       o remove (void) cast
#
# Output from nm of the final binary executable is used to generate
# a /bin/ed script, which fixes the problems.  The final executable
# is used because it should have most of the symbols.  CPP macros of
# course are not found in the executable, thus they are not handled.
#
# fix_style.sh binary [srcfiles]
#!/bin/sh
#
# Abstract: Fix some problems in 'C' src files.
#	o remove space between function name and parameters.
#	o remove (void) cast
#
# Output from nm of the final binary executable is used to generate
# a /bin/ed script, which fixes the problems.  The final executable
# is used because it should have most of the symbols.  CPP macros of
# course are not found in the executable, thus they are not handled.
#
# fix_style.sh binary [srcfiles]
#

OBJECT_FILE=obj/make
OBJECT_FILE=$1
shift;

nm $OBJECT_FILE | sort -u | awk '
END { printf "w\nq\n"; }
{
	if (($2 == "T") || ($2 == "t")) {
		# "[tab|space]funcname (" -> "[tab|space]funcname("
		printf "g/\\([\t ]\\)%s (/s//\\1%s(/g\n", $3, $3;
		# "^funcname (" -> "funcname("
		printf "g/^%s (/s//%s(/g\n", $3, $3;

		# "(void)[tab|space]funcname(" -> "[tab|space]funcname("
		printf "g/(void)\\([\t ]\\)%s(/s//\\1%s(/g\n", $3, $3;
		# "(void)funcname(" -> "funcname("
		printf "g/(void)%s(/s//%s(/g\n", $3, $3;
	}
}' > /tmp/$USER.editscript.$$

for file in "$@"; do
	echo -n "$file "
	ed -s $file < /tmp/$USER.editscript.$$
done
echo

rm /tmp/$USER.editscript.$$




More information about the Kernel mailing list