I have a list of software funtions in tcl code. Some of these functions call other functions. I want to build a tree structure of all called functions.
Right now I list all the functions into a file then read this file so that I can cat each function and grep for EXECUTE (command that calls another function) within each function.
cat fileNameFunctions |xargs -1| while FUNC
do
cat $FUNC |grep EXECUTE > INPUT
done
Using sed several times, I clean up the output until all I have is 2 columns. The first is the calling function and the second is the called function. one line for each time a function is called. I generate a file called INPUT that looks like this (without comments):
A B (A calls B 3 times within the A function)
A B
A B
B L
C D
D E (D calls both E and F within the D function)
D F
F P
I would eventually like to create a file that contains:
A B L (A calls B calls L)
A B L
A B L
C D E (C calls D calls E)
C D F P (C calls D calls F calls P )
(notice that this is expanded from the one above because D calls 2 functions)
D E
D F P
F P
I can collapse the ouput file above by importing within excel and doing a unique sort.
I just want to get a file that has all the called functions starting with my primary functions (first column)
Now I want to generate a further list of secondary called functions. I have done something like this. ( INPUT1 = INPUT = INPUT2)
cat INPUT |xargs -n 2| while read FUNCA FUNCB
do
cat INPUT1 |xargs -n 2| while read FUNC1 FUNC2
do
cat INPUT2 |xargs -n 2| while read FUNC3 FUNC4
do
if($FUNCB == FUNC3 ) then
echo "$FUNC1 \t$FUNC2 \tFUNC4" >> OUTPUT
else
fi
done
done
done
I think the logic will work, but the 'if statement' does nothing. What is wrong with my if statement?
Also, can anyone think of a cleaner way to do this? I can iterate the logic above and get the job done so it is secondary.
Sorry, am a newbi and don't know perl or anything beside unix scripts, and only a few of those, as you see
.
Thanks in advance.