sbsv1_os/e32toolp/e32util/copyfeaturevariants.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # copy A.X.aaa to B.X.bbb for all X (32 chars) when given A.aaa B.bbb
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 
       
    20 my $source = shift;
       
    21 my $target = shift;
       
    22 
       
    23 my $errs = 0;
       
    24 
       
    25 # copy invariant
       
    26 use File::Copy;
       
    27 if (-f $source)
       
    28 {
       
    29 	if (copy($source, $target))
       
    30 	{
       
    31 		print "copy $source $target\n";
       
    32 	}
       
    33 	else
       
    34 	{
       
    35 		print "ERROR: failed copy $source $target\n";
       
    36 		$errs++;
       
    37 	}
       
    38 }
       
    39 
       
    40 # now think about variants
       
    41 
       
    42 use File::Basename;
       
    43 my $srcDir = dirname($source);
       
    44 my $srcRoot = basename($source);
       
    45 my $srcExt = "";
       
    46 
       
    47 if ($srcRoot =~ /^(.+)\.([^\.]+)$/)
       
    48 {
       
    49 	$srcRoot = $1;
       
    50 	$srcExt = $2;
       
    51 }
       
    52 
       
    53 my $tgtRoot = $target;
       
    54 my $tgtExt = "";
       
    55 
       
    56 if ($tgtRoot =~ /^(.+)\.([^\.]+)$/)
       
    57 {
       
    58 	$tgtRoot = $1;
       
    59 	$tgtExt = $2;
       
    60 }
       
    61 
       
    62 opendir(DIR, $srcDir) or die("ERROR: cannot read directory $srcDir\n");
       
    63 
       
    64 # copy all variants
       
    65 while (my $file = readdir(DIR))
       
    66 {
       
    67 	if ($file =~ /^$srcRoot\.(\w{32})\.$srcExt$/i)
       
    68 	{
       
    69 		my $from = "$srcDir/$file";
       
    70 		my $into = "$tgtRoot.$1.$tgtExt";
       
    71 
       
    72 		if (copy($from, $into))
       
    73 		{
       
    74 			print "copy $from $into\n";
       
    75 		}
       
    76 		else
       
    77 		{
       
    78 			print "ERROR: failed copy $from $into\n";
       
    79 			$errs++;
       
    80 		}
       
    81 	}
       
    82 }
       
    83 
       
    84 exit 1 if (!closedir(DIR) || $errs > 0);
       
    85 exit 0;
       
    86