C-Analyzer
view release on metacpan or search on metacpan
lib/C/Analyzer.pm view on Meta::CPAN
system($prep_str);
}
print "\n";
@$$cfiles = ();
return ( \@ppfiles );
}
#################### subroutine header begin ####################
=head2 identifyFunctionsAndCalls
Usage : identifyFunctionsAndCalls()
Purpose : initial preperation for parsing each C file to identify
functions and calls
Returns : none
Argument : reference to list of preprocessor files, options and folder
names.
Throws : None
Comment : None
See Also :
None
=cut
#################### subroutine header end ####################
sub identifyFunctionsAndCalls() {
my ( $ppfiles, $opt, $folder ) = @_;
my $fun_calls;
foreach my $ppfile (@$$ppfiles) {
$fun_calls = parseCFile( \$ppfile, \$$opt, \$$folder );
updateHashTable( \$fun_calls );
}
return;
}
#################### subroutine header begin ####################
=head2 parseCFile
Usage : parseCFile()
Purpose : Parser module to identify functions and calls in C files.
Returns : reference to array of funs and calls.
Argument : reference to filename, options and foldername
Throws : None
Comment : None
See Also :
None
=cut
#################### subroutine header end ####################
sub parseCFile() {
my ( $infile, $opt_s, $FolderName ) = shift;
my @t_funs_calls = ();
my @pplines = ();
my $OpenCount = 0;
my $CloseCount = 0;
my $lno = 0;
my $fragment;
my $filename;
my $fun;
open( PPFILE, "<$$infile" ) || die("Cannot open input file $$infile\n");
@pplines = <PPFILE>;
close(PPFILE);
foreach my $ppfile (@pplines) {
$lno++;
$ppfile =~ s/\".*\(.*\"/ /g;
if ( $ppfile =~ /^\#\s*([0-9]+)\s*\"(.*)\s*\"/ ) {
$lno = $1;
$lno--;
$filename = trim($2);
next;
}
while ( $ppfile =~ /(\w+)\s*\(/g ) {
my $t_fun = $1;
$t_fun = trim($t_fun);
if ( ( $t_fun eq "if" )
|| ( $t_fun eq "for" )
|| ( $t_fun eq "while" )
|| ( $t_fun eq "switch" )
|| ( $t_fun eq "case" )
|| ( $t_fun eq "int" )
|| ( $t_fun eq "char" )
|| ( $t_fun eq "flaot" )
|| ( $t_fun eq "double" )
|| ( $t_fun eq "long" )
|| ( $t_fun eq "short" )
|| ( $t_fun eq "bit" )
|| ( $t_fun eq "unsigned" )
|| ( $t_fun eq "return" ) )
{
next;
}
if ($opt_s) {
my $filelength = length($FolderName);
$fragment = substr $filename, $filelength;
$fragment = "." . "$fragment";
if ( $t_fun eq "" ) {
;
}
else {
$fun = "$t_fun" . "($lno, $fragment)";
}
}
else {
if ( $t_fun eq "" ) {
print;
}
else {
$fun = "$t_fun" . "($lno, $filename)";
}
}
push( @t_funs_calls, $fun );
$fragment = "";
}
while ( $ppfile =~ /(;)/g ) {
push( @t_funs_calls, $1 );
}
while ( $ppfile =~ /({)/g ) {
$OpenCount++;
push( @t_funs_calls, $1 );
}
while ( $ppfile =~ /(})/g ) {
$CloseCount++;
push( @t_funs_calls, $1 );
}
}
return ( \@t_funs_calls );
}
#################### subroutine header begin ####################
=head2 updateHashTable
Usage : updateHashTable()
Purpose : updates function wise calls hash table
Returns : reference to hash table containing functions and calls
Argument : None
Throws : None
Comment : None
See Also :
None
=cut
#################### subroutine header end ####################
sub updateHashTable() {
my $fun_calls = shift;
my $OpenCount = 0;
my $CloseCount = 0;
my $function;
my $FUNCTIONFOUND = 0;
my $item = -1;
my $titem;
my $cnt1 = 0;
my $call;
my $fun_remain;
foreach my $x (@$$fun_calls) {
$item++;
if ( $x eq "{" ) {
$OpenCount++;
}
if ( $x eq "}" ) {
$CloseCount++;
}
if ( !defined( @$$fun_calls[$item] )
|| !defined( @$$fun_calls[ $item + 1 ] ) )
{
next;
}
$titem = $item + 1;
( run in 0.679 second using v1.01-cache-2.11-cpan-b16cb0d3907 )