Wrapper_folder.pl

来源:互联网 发布:数据生成图表 编辑:程序博客网 时间:2024/05/16 19:37
 

#!perl
$|=1;

SET_ENVIRONMENT:{ #to set the environment defined in the environment file: this file should be put in the same folder of the script
use FindBin '$Bin'; #find the folder where the script is saved
push(@INC, "$Bin"); #put the folder of the script in the list of INC
require "ENVIRONMENT.pm";

eval { #the unnecessary environment variables are put in comments
$CYGWIN_path=$ENVIRONMENT::CYGWIN_path or die "No CYGWIN_path\n";
#$DVW_path=$ENVIRONMENT::DVW_path or die "No DVW_path\n";
$WRAP_path=$ENVIRONMENT::WRAP_path or die "No WRAP_path\n";
#@wrap_filter_ok=@ENVIRONMENT::wrap_filter_ok or die "No wrap_filter_ok\n";
#@wrap_filter_nok=@ENVIRONMENT::wrap_filter_nok or die "No wrap_filter_nok\n";
}; #end of eval

if ($@) {print "Error while setting the environment in ENVIRONMENT.pm: $@...Press ENTER to continue...";<STDIN>;exit;}
} #end of SET_ENVIRONMENT

$exit_code=0;

if ($#ARGV == 0) { #one arguments: the file
 $path=$ARGV[0];
 if ($path =~ m%([\\\/](\w+\.(\w+)))$%) { $path =~ s%$1%%;} #delete the name of the file from the path if the argument is a file
 chdir  "$path"; #the argument is the name of a folder
} else {die "Error: Wrong number of argument. A folder needs to be specified";}

@draw_files=glob "aol_*_draw.c";
print "The files found are: @draw_files\n"; #for_debug

foreach $file (@draw_files) {
print "\n","*"x 30,"\nProcessing of $file\n","*"x 30,"\n"; #for_log
 
$layer_name = $file;$layer_name =~ s/aol_(\w+)_draw.c/$1/; #retrieve the name of the layer_name
print "The name of the layer is: $layer_name\n"; #for_debug

print "\n","*"x 65,"\nSGLWrapper.sh . $layer_name 1\n","*"x 65,"\n";
$exit_code += system("$CYGWIN_path/sh.exe $WRAP_path . $layer_name 1");
rename("WRAP/results/SGLWrap.c","WRAP/results/SGLWrap_$layer_name.c") || die "Can't rename SGLWrap.c to SGLWrap_$layer_name.c: $!";
&filter_wrap("WRAP/results/SGLWrap_$layer_name.c");

}#end of foreach

if ($exit_code >0) {print "\nError while running Display Viewer\nPress ENTER to continue... ($exit_code)\n";<STDIN>;}


#-----------------------------------------------------------------------------------------------------------------------
{#-----------------------------------------------------subroutines-------------------------------------------------------
sub filter_wrap { #filter the results of the wrapper arg1=name of the file
my $file=$_[0];

%wrap_filter = (); #the hash table with the elements non filtered having a value set to 1
foreach (@wrap_filter_ok) {$wrap_filter{$_}=1;}
foreach (@wrap_filter_nok) {$wrap_filter{$_}=0;}
&print_hash("function sgl","ok=1 nok=0",%wrap_filter); #for_debug

open WRAP_C, "<$file" or die "Error while opening $file ($!)\n";
$temporary_file=""; #the temporary buffer to copy the file
$line=0; #the number of the line read
while (<WRAP_C>) { #opening the file
 ++$line;
 if ((m%(sgl\w+)\(%) and ($wrap_filter{$1} != 1)) { $_="";} #the line is deleted if the sgl function is not in the list
 $temporary_file= $temporary_file . $_;
} #end of while

$new_file=$file;$new_file =~ s%\.c%_filtered\.c%;
open WRAP_C, ">$new_file" or die "Error while opening $newfile for modification($!)\n";
print WRAP_C $temporary_file;
close WRAP_C;
} #end of filter_wrap

sub print_hash { #print Hash Table: arg1=name of keys, arg2=name of values, arg3=hash table
my ($tab1,$tab2,%hash)=@_;
my @keys=sort keys %hash;
print "\n","-" x 150,"\n\n";
printf("%-35s \t %-20s\n", $tab1, $tab2);
printf("%-35s \t %-20s\n", "-"x 20, "-" x 20);
foreach (@keys) {
   printf("%-35s \t    %-17s\n", $_, $hash{$_});
} #end of foreach
print "\n","-" x 150, "\n";
} #end of subroutines to print hash tables

}#end of subroutines
#---------------------------------------------------------------------------------------------------------------------------------

原创粉丝点击