#!/usr/bin/perl # fincom v1.0 (26th October 2001) # # very simple (and crappy) perl script to find out what function is # called by a command and then where its located. # # uses lots of hacks. we're going for quick implementation here, not # Randal Schwartz approved perl. # # by Silver <silver@ewtoo.org> my $command = $ARGV[0]; if (!$command) { print "Usage: findcom <talker command>\n"; exit; } my $flag = 0; open(CLIST, "include/clist.h") || die "can't open clist.h: $!"; while(<CLIST>) { if (/ *{"(.+?)", (.+?),.+}/) { my $com = $1; my $func = $2; if ($com eq $command) { $flag = 1; my $where = find_location($func); print "\"$command\" calls '$func' which is in $where\n"; } } } close CLIST; print "Nothing found.\n" if (!$flag); exit; sub find_location { my $function = shift; open(OUTPUT, "egrep \"void $function\\(.+\" * -n -s |") || die "can't egrep: $!"; while(<OUTPUT>) { if (/(.+?\.c):(\d+):/) { close OUTPUT; return "$1 (line $2)"; } } close OUTPUT; }