Perl script to find where functions is called in c
Hello,
I need to write a perl script to find where functions is called in c files..
The script should scan the file and find out the function names and then search to see where they are called...
Lets for now assume all functions are internal.
I don't know where to start
---------- Post updated at 06:10 AM ---------- Previous update was at 05:25 AM ----------
okay.. I managed to do it using this:
Now the problem is, I do not want to print the result, I want to write it in a certain part of the file.. for example, the h file has the format:
I want the result to be written infront of the "caller: " field.
Well, I use cscope, which is free. You need a state engine to parse C states, but you are only interested in locating calls and subroutines. You have to handle every C meta-character and expression correctly, so you know when you are in comments and quotations. Just assign the states numbers in an int or enum as you discover them. Beware advanced things like "XXX"\n"YYY" ( = "XXXYYY"), and \ at end of line! When you find a variable name, you need to decide if it is a call or a subroutine declaration or a non-subroutine declaration like int i. You have to worry about type names in typedefs and #defines, possibly in includes, so you must preprocess with cpp or cc -E and process the structured comments in that output that show where include file lines are. So easy, almost like writing a compiler!
I usually deal with such parsing tasks with a little state machine that normlizes the C into one string block with all white space down to one or zero spaces as allowed. The state machine parses bytes until the end of declaration, knowing when it is in comments and in quotes, and the depth of any (){}[] has cancelled down to 0. The block might get very big, so it might be good to abstract out whatever is in {}, as you must reparse inside {} to see what is declared there. The code needs to be preprocessed so macros are expanded, and the parser needs to keep track of the files and line numbers it is in via include: # line_number "file_name"
I want to find c function definition with pattern with shell script by checking condition for each line:
data_type
functionname(param_list){
....
}
I knew cscope or ctag is usable for this task, but if there any ways to do without using them.
I am thinking of checking line condition... (3 Replies)
In the below script i found that the alias mkdir_s is getting invoked from function configure() i.e the alias is kicking in.
#!/bin/bash -e
shopt -s expand_aliases
alias mkdir=mkdir_s
mkdir_s(){
if ]; then
return
else
/usr/bin/mkdir "$1"
return
fi
}
configure()
{
mkdir -p... (9 Replies)
I would like to use Perl in 'interactive' mode (kind off), starting it by
> perl -d -e 0;
But I need to have some function be read on loading.
Also, it should not be for anyone who starting Perl or use it any how.
I did try to search, but not much result.
I have try a file '.perldb':... (1 Reply)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
how?
there is html-page with:
<iframe>
<!--#exec cgi="perl-script"-->
</iframe>
so in that perl-script need to delegate the name of html-page
why? too lazy for ajax (3 Replies)
I want to write a shell script which traverses a cpp file.
Suppose there is function fncn_name6 .. which is called by fncn_name5
which in turn called by fncn_name4 and so on .. in a single cpp class.
ie
fncn_name1
{
fncn_name2
{
fncn_name3
}
{
fncn_name4
}
}
so fncn_name1 is... (2 Replies)
Hi,
First I will tell my objective of this function (function one).
I have a table for ex:
id passwd name
-- ------ -----
1 fdhgfs werwer
2 fsdfs sdfsdf
3 sdfs sdfsdf
4 fdsfs dssdf
. . .
.
.
.
The id, passwd and name are the arguments for another function say two. (1 Reply)
last week i started learning perl, so have limited skill and knowledge.
why isn't 'die' being called and the script exiting before the 'directory created' line?
if (! -d "$logdir") {
system "mkdir -p $logdir" || die print "\nERROR: release log directory creation failed - $logdir: $!\n";... (4 Replies)