1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#!/usr/bin/perl
use strict;
##########################################
# MAIN #
##########################################
#Block Declare: GLOBAL
#---SCALAR
my($path,$hslinc,$rlist,$file);
#---ARRAYS
my @variables;
#Get input
$path = $ARGV[0];
#print "\nPATH is $path";
print "Beginning scan...\n";
$hslinc = "\/vobs\/per\/hsp\/HSL\/INC\/";
#print 'HSLINC is '.$hslinc;
#print "\n";
$rlist = "\/vobs\/per\/hsp\/HSL\/INC\/rlist.log";
#print 'RLIST is '.$rlist;
#print "\n";
print "Listing commons...\n";
&list_commons($path);
print "List done.\n";
print "Checking commons.\n";
&check_commons;
print "Check done.\n";
##########################################
# list_commons #
# role; lists all commons in HSLINC #
# input: none #
# output: none #
##########################################
sub list_commons{
#Input parameters:
#a folder to scan containing include files
#Block Declare:
#---SCALAR
my($line,$var,$find,$long);
print "---entering list_commons\n";
#---ARRAYS
#Go to input directory
if(-d $path){
chdir($path) ||
die "Sorry, I cannot cd to $path.\n";
#Scan folder
print "\n---entering $path\n";
foreach $file (<*.h>)
{
#Open current file
open(FILTMP,"$file") ||die "Sorry, I cannot read $file.\n";
print "---entering $file in the FOREACH statement\n";
#print "$file \n";
while (<FILTMP>)
{
print "+++reading the current file : $file\n";
#print "$_\n";
$line = $_;
chomp($line);
#DEBUG
print "$line\n";
#Selecting commons lines
if ($line=~/COMMON\b/)
{
if (!($line=~/\!/))
{
print "---SELECTING COMMONS\n";
#Filter of $line for spaces and others unused strings
$line =~s/COMMON\///g;
my $long=length($line);
my $ind=index($line,"/");
$line=substr($line,$ind+1,$long);
print "2222 $line\n";
# $long=length($line);
# $find=index($line,"(");
# $line=substr($line,$find,$);
#print "step 1 $line\n";
# my $find2=index($line,")");
# $line=substr($line,$find,$);
#DEBUG
print "33333 $line \n";
#Treatment for array declarations
$line=~s/\((.*)\)//g;
print "4444 $line\n";
#DEBUG
#print "After filter : $line \n";
@variables = (@variables,split(',',$line));
}
}
if ($line =~/\$/){
s/ \s*//g;
s/\$//g;
$line=~s/\((.*)\)//g;
print "5555 $line \n";
#print "$_ \n" ;
@variables = (@variables,split(',',$line));
}
elsif ($line =~/\&/)
{
s/ \s*//g;
s/\&//g;
$line=~s/\((.*)\)//g;
print "6666 $line\n";
#print "$_\n" ;
@variables = (@variables,split(',',$line));
}
}
close(FILTMP);
}
# foreach my $v (@variables)
# {
# print "$v\n";
# }
}
else
{
print "$path is not a directory\n";
}
}
##########################################
# check_commons #
# role; lists all commons in HSLINC #
# input: none #
# output: none #
##########################################
sub check_commons{
print "\n\n\n\n\n\n\n\n";
print "---CHECK COMMONS\n";
my($var);
chdir($hslinc);
open(RLIST,'>'.$rlist);
print RLIST "CHECK COMMONS\n\n";
close(RLIST);
open(RLIST,'>>'.$rlist);
foreach $var (@variables){
chomp($var);
print "\n#####################################\n";
print "\nProcessing search for $var\n";
print "#####################################\n\n";
system("grep -w \"$var\" *h >> $rlist");
}
close(RLIST);
} |