#!/usr/local/bin/perl # # Search for function that take in at least one float argument and uses "sum" as a variable # Some problem with "ls /cavs/hse/ies/d002/isip/users/srinivas/tools/class/math/matrix/MatrixU* (say MatrixUllong)" # Hangs there!!! $file_ext = '.cc'; $dir = "/cavs/hse/ies/d002/isip/users/srinivas/tools/class/"; chop($dir); &searchDirectory($dir); sub searchDirectory { local($dir); local(@lines_in_ls); local($line_in_ls); #Commented ones are used as global variables # local(@lines_in_file); # local($line_in_file); local($line_in_file2); # local($i); # local($j); # local($file_length); local($num_curly); local($file); local($full_file_name); local($subdir); $dir = $_[0]; # check for permission if(-x $dir) { # search this directory @lines_in_ls = `cd $dir; ls -l`; foreach $line_in_ls (@lines_in_ls) { $line_in_ls =~ /\s+(\S+)$/; $file = $1; if ($file =~ /$file_ext$/) { $full_file_name = $dir."/".$file; open(INFO, $full_file_name); # Open the file @lines_in_file = ; # Read it into an array $file_length = $#lines_in_file; for ($i=0; $i < $file_length; ++$i) { $line_in_file = $lines_in_file[$i]; $num_curly = 1; $sum_not_detected = 1; $j = $i; if (line_is_a_float_function()) { do { if (++$i < $file_length) { $line_in_file2 = $lines_in_file[$i]; if ($sum_not_detected) { if ($line_in_file2 =~ /[^a-zA-Z0-9]sum\s*[^\(]/) { #"sum" should occur as a whole word variable and not a function print "$lines_in_file[$j]\n"; $sum_not_detected = 0; } } if ($line_in_file2 =~ /\{/) { #If and elsifs to cancel out { and } ++$num_curly; } elsif ($line_in_file2 =~ /\}/) { --$num_curly; } } }while ($num_curly); } } close(INFO); } } } # search any sub directories @lines_in_ls = `cd $dir; ls -l`; print "Searching in $dir\n"; foreach $line_in_ls (@lines_in_ls) { if($line_in_ls =~ /^d/) { $line_in_ls =~ /\s+(\S+)$/; $subdir = $dir."/".$1; &searchDirectory($subdir); } } } sub line_is_a_float_function { #To find if a line defines a function and takes one Float/float type argument # local($line_in_file); local($argument); # local $i = $_0; # $line_in_file = lines_in_file[]; $a = "hi"; $b = "bye"; $a .= $b; if ($line_in_file =~ /^([a-zA-Z_]+\s+)+[a-zA-Z_:]+\((.*)$/) { #To see if the line can be a function's first line $argument = $2; while ( $argument !~ /\)/) { # To account for argument splitting over multiple lines if (++$i < $file_length) { $line_in_file = $lines_in_file[$i]; $line_in_file =~ /^\s*(.*)$/; $argument .= $1; } else { return 0; } } if ($argument =~ /F|float/) { return 1; } else { return 0; } } else { return 0; } }