From 2154ebce84c6cf376e7183e8c5f7ad0e17aead97 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 13 Jun 2002 07:06:19 +0000 Subject: a useful script for finding global variables or functions that could be static very very slow ... I leave it as an exercise for the reader to make this O(n) instead of O(n^2) (This used to be commit 7c035d473c7175163ad5db0373ed2fe6c739b968) --- source3/script/findstatic.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 source3/script/findstatic.sh (limited to 'source3/script/findstatic.sh') diff --git a/source3/script/findstatic.sh b/source3/script/findstatic.sh new file mode 100755 index 0000000000..39c57a46f7 --- /dev/null +++ b/source3/script/findstatic.sh @@ -0,0 +1,59 @@ +#!/bin/sh +# find a list of fns and variables in the code that could be static +# Andrew Tridgell + +# rather linux specific, but that doesn't matter in this case +# also very slow (order is N^2) but fast enough for this project + +declare -a FNS + +for f in $@; do + echo "Checking in $f" + T_FNS=`nm $f | grep ' T ' | cut -d' ' -f3` + C_FNS=`nm $f | egrep ' [DC] ' | cut -d' ' -f3` + if [ "$T_FNS" = "" -a "$C_FNS" = "" ]; then + echo "No public functions or data in $f" + continue + fi + for fn in $T_FNS; do + if [ $fn = "main" ]; then + continue + fi + found=0 + for f2 in $@; do + if [ $f != $f2 ]; then + FNS2=`nm $f2 | egrep ' U ' | awk '{print $2}'` + for fn2 in $FNS2; do + if [ $fn2 = $fn ]; then + found=1 + break + fi + done + fi + done + if [ $found = 0 ]; then + echo "Global function $fn is unique to $f" + fi + done + + for fn in $C_FNS; do + if [ $fn = "main" ]; then + continue + fi + found=0 + for f2 in $@; do + if [ $f != $f2 ]; then + FNS2=`nm $f2 | grep ' U ' | awk '{print $2}'` + for fn2 in $FNS2; do + if [ $fn2 = $fn ]; then + found=1 + break + fi + done + fi + done + if [ $found = 0 ]; then + echo "Global variable $fn is unique to $f" + fi + done +done -- cgit