Skip to content

Instantly share code, notes, and snippets.

@Orc
Last active March 30, 2019 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Orc/f2a36789ae0fa58eec44eec2083fed6d to your computer and use it in GitHub Desktop.
Save Orc/f2a36789ae0fa58eec44eec2083fed6d to your computer and use it in GitHub Desktop.
orphans: a q&d shell script to look for orphan functions in my code
#! /bin/sh
#
# Find functions that are defined but not referenced in a body of C code
test -f tags || ctags -M *.c
test -f tags || exit 1
FILES=`awk -F' ' '{print $2}' < tags | sort |uniq`
trap "rm -f functions called" 0 1 2 3 5 9
rm -f functions called intermediate
awk -F' ' '{print $1}' < tags > functions
( echo main
for x in $FILES "$@"; do
sed -e 's/(/(@ /g' $x | \
tr '@' '\n' | \
sed -n \
-e 's/^.*[^a-zA-Z0-9_]\([a-zA-Z_][a-zA-Z0-9_]*\)(.*/\1/p'
done ) | sort | uniq | fgrep -f functions > called
fgrep -v -f called functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment