ITK/Release 4/Wrapping/Tasks/WrapITKModular: Difference between revisions

From KitwarePublic
< ITK‎ | Release 4‎ | Wrapping‎ | Tasks
Jump to navigationJump to search
Line 6: Line 6:
  #!/usr/bin/perl  
  #!/usr/bin/perl  
  require 5.004;
  require 5.004;
  $fname = "Ashish_AllWrapFiles.txt";
  $outname = "Ashish_ModFiles.txt";
  $input = "Ashish_wrapfiles.txt";
  $merged = "Ashish_Mapping.txt";
  $output = "Ashish_headerfiles.txt";
  # First, prepare the input file
  $mapping = "Ashish_mapping.txt";
  open(FILE2, ">$fname") || die "Could not open $fname\n";
  system("find . -name \*\.wrap -print >> $fname")  == 0 || die "system error $?";  
# First, prepare the input INPUT
open(FILE2, ">$input") || die "Could not open $input\n";
  system("find . -name \*\.wrap -print >> $input")  == 0 || die "system error $?";  
  close(FILE2);
  close(FILE2);
   
   
  # Next, process and write it in the output file
  # Next, process and write it in the output INPUT
  open(FILE, "$fname") || die "Could not open $fname\n";
  open(INPUT, "$input") || die "Could not open $input\n";
  open (OUTPUT, ">$outname") || die "Could not open $outname\n";
  open (OUTPUT, ">$output") || die "Could not open $output\n";
   
   
  #$pattern = '^\.\/Wrapping\/WrapITK\/Libraries\/(\w*)\/(\w*)\.wrap';
  #$pattern = '^\.\/Wrapping\/WrapITK\/Libraries\/(\w*)\/(\w*)\.wrap';
Line 22: Line 24:
   
   
   
   
  while ($line = <FILE>) {  
  while ($line = <INPUT>) {  
     chomp($line);
     chomp($line);
     if($line=~/$pattern/)  {
     if($line=~/$pattern/)  {
Line 40: Line 42:
  }  
  }  
  close(OUTPUT);
  close(OUTPUT);
  close(FILE);
  close(INPUT);
   
   
  # Merge two files line by line
  # Merge two files line by line
  open (OUTPUT, "$outname") || die "Could not open $outname\n";
  open (OUTPUT, "$output") || die "Could not open $output\n";
  open (MERGED, ">$merged") || die "Could not open $outname\n";
  open (MAPPING, ">$mapping") || die "Could not open $output\n";
  open (FILE, "$fname") || die "Could not open $fname\n";
  open (INPUT, "$input") || die "Could not open $input\n";
   
   
  while ($line = <FILE>) {  
  while ($line = <INPUT>) {  
     $line2 = <OUTPUT>;
     $line2 = <OUTPUT>;
     chomp($line);
     print MAPPING $line, " => ", $line2, "\n";
    print MERGED $line, " => ", $line2;
}
  }
close(OUTPUT);
close(INPUT);
close(MAPPING);
# git move the wrap files to the corresponding folders
$log = "Ashish_Log.txt";
open (LOG, ">$log") || die "Could not open $log\n";
open (OUTPUT, "$output") || die "Could not open $output\n";
open (INPUT, "$input") || die "Could not open $input\n";
while ($line = <INPUT>) {
        $line2 = <OUTPUT>;
        if($line2 =~ /^\<No Mapping available\>$/) {
            ; # do nothing
        }
        else { # move files
            chomp($line);
            $line2 =~ s/\n/,/g;
            $line2 =~ s/\s/,/g;
            $line2 =~ s/,$//; # get rid of last comma
            $line2 =~ s/^\.\///g;
            @temp = split(/\//, $line2);
            pop(@temp); pop(@temp);
            $rootdir = `pwd`;chomp($rootdir);
            $libdir = "$rootdir/Wrapping/WrapITK/Libraries";
            $t = $libdir;
            while($sdir = shift(@temp)) {
                if (-d "$t/$sdir") {
                    $t = "$t/$sdir";
                    next;
                }
                else {
                    system("mkdir $t/$sdir") ==0 || die "Could not create directory $sdir of $t\n";
                    $t = "$t/$sdir";
                }
            }
            system("cp $line $t/") == 0 || die "Could not copy INPUT:$line to directory:$t\n";
        }
  }
   
   
close(LOG);
  close(OUTPUT);
  close(OUTPUT);
  close(FILE);
  close(INPUT);
close(MERGED);

Revision as of 22:09, 5 June 2011

Modular WrapITK

Mapping of files

Script used to obtain the mapping

#!/usr/bin/perl 
require 5.004;

$input = "Ashish_wrapfiles.txt";
$output = "Ashish_headerfiles.txt";
$mapping = "Ashish_mapping.txt";

# First, prepare the input INPUT
open(FILE2, ">$input") || die "Could not open $input\n";
system("find . -name \*\.wrap -print >> $input")  == 0 || die "system error $?"; 
close(FILE2);

# Next, process and write it in the output INPUT
open(INPUT, "$input") || die "Could not open $input\n";
open (OUTPUT, ">$output") || die "Could not open $output\n";

#$pattern = '^\.\/Wrapping\/WrapITK\/Libraries\/(\w*)\/(\w*)\.wrap';
$pattern = '^\.\/(((\w*)\/)+)(\w*)\.wrap';


while ($line = <INPUT>) { 
    chomp($line);
    if($line=~/$pattern/)  {
        #(@output) = `find . -iname \'$4.h\' -print`;
        #$out = pop(@output);
        $out = `find . -iname \'$4.h\' -print`;
        #chomp($out);
        $out =~ s/\n/,/g;
        $out =~ s/,$//; # get rid of last comma
        if($out) {
            print OUTPUT "$out\n";

        } else {
            print OUTPUT "<No Mapping available>\n";
        }
    }
} 
close(OUTPUT);
close(INPUT);

# Merge two files line by line
open (OUTPUT, "$output") || die "Could not open $output\n";
open (MAPPING, ">$mapping") || die "Could not open $output\n";
open (INPUT, "$input") || die "Could not open $input\n";

while ($line = <INPUT>) { 
    $line2 = <OUTPUT>;
    print MAPPING $line, " => ", $line2, "\n";
} 
close(OUTPUT);
close(INPUT);
close(MAPPING);

# git move the wrap files to the corresponding folders
$log = "Ashish_Log.txt";
open (LOG, ">$log") || die "Could not open $log\n";
open (OUTPUT, "$output") || die "Could not open $output\n";
open (INPUT, "$input") || die "Could not open $input\n";

while ($line = <INPUT>) { 
        $line2 = <OUTPUT>;
        if($line2 =~ /^\<No Mapping available\>$/) {
            ; # do nothing
        }
        else { # move files
            chomp($line);
            $line2 =~ s/\n/,/g;
            $line2 =~ s/\s/,/g;
            $line2 =~ s/,$//; # get rid of last comma
            $line2 =~ s/^\.\///g;
            @temp = split(/\//, $line2);
            pop(@temp); pop(@temp);
            $rootdir = `pwd`;chomp($rootdir);
            $libdir = "$rootdir/Wrapping/WrapITK/Libraries";
            $t = $libdir;
            while($sdir = shift(@temp)) {
                if (-d "$t/$sdir") {
                    $t = "$t/$sdir";
                    next;
                }
                else {
                    system("mkdir $t/$sdir") ==0 || die "Could not create directory $sdir of $t\n";
                    $t = "$t/$sdir";
                }
            }
            system("cp $line $t/") == 0 || die "Could not copy INPUT:$line to directory:$t\n";
        }
}

close(LOG);
close(OUTPUT);
close(INPUT);