5 # Converts the cxref.function output file into a format that can display
6 # a simple tree structure
8 # Warning: This is my first perl program. It can probably be improved on !
10 # This file Copyright 2000 Ian A. Gilmour.
11 # (ian@igilmour.freeserve.co.uk / ian.gilmour.ffei.co.uk)
13 # It may be distributed under the GNU Public License, version 2, or
14 # any higher version. See section COPYING of the GNU Public license
15 # for conditions under which this file may be redistributed.
26 # generates the tree going down
27 # i.e. displays which functions are called by the given function
30 my
$func_reqd = $_[0];
32 if ($level > $max_level) {
38 for ($z=0; $z < ($level-1)*3; $z++) {
43 if (defined
($functions{$func_reqd})) {
44 print
"$func_reqd() \t[$file{$func_reqd}]";
45 if($scope{$func_reqd}==2) {
48 if ($fshown{$func_reqd}) {
49 print
" \t...referenced above\n";
52 $fshown{$func_reqd} = 1;
54 for (my
$y=0; $y <= $fcount{$func_reqd}; $y++) {
55 find_func
($fcalls{$func_reqd}[$y]);
59 if (!defined
($fundefshown{$func_reqd})) {
60 print
"$func_reqd() \t[undefined]\n";
61 $fundefshown{$func_reqd} = 1;
63 print
"$func_reqd() \t[undefined] \t...referenced above\n";
70 # generates the tree going up
71 # i.e finds which functions call the specified function
73 sub find_called_func
{
74 my
$func_reqd = $_[0];
76 if ($level <= $max_level) {
82 foreach my
$func (keys
%functions
) {
83 if (defined
($fcount{$func})) {
84 for (my
$y=0; $y <= $fcount{$func}; $y++) {
85 if ($func_reqd eq
$fcalls{$func}[$y]) {
88 print
"+- $func_reqd()\n";
91 for (my
$z=0; $z > (($level)*3); $z--) {
95 print
"$functions{$func} \t[$file{$func}]";
96 if($scope{$func}==1) {
100 print
" \t...referenced above\n";
104 find_called_func
($functions{$func});
113 print
"$func_reqd() not referenced.\n";
118 die
"Usage: $0 cxref_function_file root_function max_level\n".
119 "max_level +ve for functions called by specified function\n".
120 "max_level -ve for functions that call specified function\n" if($#ARGV==-1);
122 if (defined
($ARGV[2])) {
123 $max_level = $ARGV[2];
126 if (defined
($ARGV[1])) {
130 open
(FUNCTION
,"<$ARGV[0]") || die
"Cannot open $ARGV[0]\n";
132 # read all function names in once to set up database
139 ($file,$function,$scope,@calls
)=split(/ /);
141 if((defined
($scope)) && (($scope==2) ||
($scope==1))) {
142 $scope{$function}="$scope";
143 $functions{$function}="$function";
144 $file{$function}="$file";
145 if (defined
(@calls
)) {
146 $fcalls{$function} = [@calls
];
147 $fcount{$function} = $#calls;
148 $fshown{$function} = 0;
150 $fcount{$function} = -1;
157 # now display reqd info....
159 if ($max_level >= 0) {
160 print
"Looking for functions that $func() calls...\n";
163 print
"Looking for functions that call $func()...\n";
164 find_called_func
($func);