Hi,
I am trying to extract some directive filags in a build output file. I want to extract all the flags starting with -D and ending with a blank. For Ex:
cc -g -mcpu=800 -type -nostdinc -DFLAG1 -DFLAG2-float -fno-builtin
cc -g -mcpu=800 -type -nostdinc -DFLAG1 -D_FLAG2 -fvolatile -fno-built
+in -I
So my flags are -DFLAG1, -DFLAG2, -D_FLAG2. That means I pick all the flags and keep in an array where no flag repeats. For this my code is
#!/usr/local/bin/perl
$file = shift @ARGV;
chomp $file;
open(BUILD,"$file") || die "File $file not found \n!";
@recs = <BUILD>;
$count = 0;
foreach(@recs)
{
$str = m/.\-D/;
if ($str)
{
@flags = split(" ",$_);
}
foreach (@flags)
{
$str2 = m/^\-D/;
if ($str2)
{
$finalflags[$count] = $_;
$count++;
}
}
}
@sortflags = sort @finalflags;
foreach(@sortflags)
{
print"$_\n";
}
But my problem is it finds repetition of flags. i.e -DFLAG1, -DFLAG2, -DFLAG!, -D_FLAG2.
Finally I wrote a shell script like this:
rm out1.txt
rm final.txt
perl dir.pl > out1.txt
#tells the flags repeated
uniq -d out1.txt > final.txt
#tells uniq flags
uniq -u out1.txt >> final.txt
My all flags will be in final.txt which are -DFLAG1, -DFLAG2, -D_FLAG2.
I know that this can be written in better manner. I tried to grep like:
if ($found = grep(/\b$_\b/,@finalflags)
donot store inarray
else
store in array
But could not succeed. I know that code can be better than this. Can you pl. give your ideas?
Thanks
Ashok