Computing.Net > Forums > Unix > Backtracing a function

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Backtracing a function

Reply to Message Icon

Name: ultimatix
Date: March 17, 2009 at 04:34:36 Pacific
OS: Windows XP
Subcategory: General
Comment:

I have a text file test.txt which contains :
inst_f1
inst_f2
inst_f3
inst_f4
.
.
.
.
inst_fn
where inst_f1.... inst_fn are particular function type used in a given cpp file
I have to read the file test.txt line by line
Suppose the First fn is inst_f1. I have to find the fn in which this fn is called from the cpp
and so on
for eg: the contents of cpp file are
void clas_name :: rvvd_inst_into_tabl
( void )
{
rvvd_call_tabl()
}
void clas_name :: rvvd_call_tabl
( void )
{
rvvd_chck_tabl()
}
void clas_name :: rvvd_chck_tabl
( void )
{
inst_f1()
}

So the flow would be
inst_f1 <<--- rvvd_chck_tabl <<---- rvvd_call_tabl <<----- rvvd_inst_into_tabl
and I have to keep all things dynamic ie ( Number of Fncs in test.txt will change for diff cpp class)

Your Suggestions appreciated

Thanks
-Ultimatix




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 18, 2009 at 12:15:03 Pacific
Reply:

Interesting problem ......

#!/bin/ksh

# reverse the cppfile
sed '1!G;h;$!d' cpp.file > tmp.cpp.file

mystring=""
ft=0
while read line
do
   # look for lines ending with ()
   if echo "$line"|egrep "\(\)$" > /dev/null
   then
       if [[ $ft -eq 0 ]]
       then
          ft=1
          mystring=${line}
       else
          mystring="${mystring} <<--- ${line}"
       fi
       continue
   fi

   # look for lines with ::
   if echo "$line"|egrep "::" > /dev/null
   then
       # 3rd field is the function
       set - $(IFS=":"; echo ${line})

       if [[ $ft -eq 0 ]]
       then
          ft=1
          mystring=$3
       else
          mystring="${mystring} <<--- $3}"
       fi
   fi
done < tmp.cpp.file
echo $mystring


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Backtracing a function

typeset inside a function www.computing.net/answers/unix/typeset-inside-a-function/5067.html

parsing a variable to a function www.computing.net/answers/unix/parsing-a-variable-to-a-function-/5613.html

Can I run a shell function in background www.computing.net/answers/unix/can-i-run-a-shell-function-in-background/2183.html