DragonFly BSD
DragonFly kernel List (threaded) for 2004-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

script to cleanup remove extra space and (void)


From: Max Okumoto <okumoto@home>
Date: Tue, 23 Nov 2004 21:55:19 -0800
Cc: virtus@xxxxxxxxxx

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


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]