diff -r 22486c9c7b15 -r 378360dbbdba sbsv1/abld/e32util/epocaif.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbsv1/abld/e32util/epocaif.pl Wed Jun 30 11:35:58 2010 +0800 @@ -0,0 +1,512 @@ +# Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# Wrapper to support the EPOC AIF Compiler +# +# + + +use FindBin; # for FindBin::Bin +use File::Copy; # for copy() +use Cwd; # for cwd +use File::Basename; # for basename() + +my $PerlBinPath; # fully qualified pathname of the directory containing this script +my $curdrive="x"; # will be initialised when first needed + +# establish the path to the Perl binaries +BEGIN { + require 5.005_03; # check user has a version of perl that will cope + $PerlBinPath = $FindBin::Bin; # X:/epoc32/tools + $PerlBinPath =~ s/\//\\/g; # X:\epoc32\tools +} +use lib $PerlBinPath; +use E32Variant; # for variant specific macros +use Pathutl; +use Preprocessor; + +sub print_usage + { +#........1.........2.........3.........4.........5.........6.........7..... + print <=4) or die("* Dump file too short\n"); +my $uid=(unpack('V', $data))[0]; +undef($data); +undef($numberOfBytesRead); +close(DUMP_OF_RESOURCE_1) or die("* Can't close dump file\n"); + +#------------------------------------------------------- +# Produce the AIF file from the RSC and MBM files +# + +my $uidcrc = "uidcrc.exe 0x101fb032 0 ".sprintf('0x%08x', $uid)." $tmpdir\\out.aif"; +my $uidcrc_xip = "uidcrc.exe 0x101fb032 0 ".sprintf('0x%08x', $uid)." $tmpdir\\out_xip.aif"; + +print "* $uidcrc\n" if ($opt_v); +system($uidcrc); +if ($? != 0) + { + print "* UIDCRC failed\n"; + exit 1; + } +if ($xipaif ne 0) + { + print "* $uidcrc\n" if ($opt_v); + system($uidcrc_xip); + if ($? != 0) + { + print "* UIDCRC failed\n"; + exit 1; + } + } + + +open(OUT_AIF, ">> $tmpdir\\out.aif") or die("* Can't open temporary file\n"); +binmode(OUT_AIF); + +if ($xipaif ne 0) + { + open(OUTXIP_AIF, ">> $tmpdir\\out_xip.aif") or die("* Can't open temporary file\n"); + binmode(OUTXIP_AIF); + } + +print "* Writing length of the RSC-block\n" if ($opt_v); +my $lengthOfRscBlock=-s("$tmpdir\\aif.rsc"); +my $numberOfPaddingBytes=(4-($lengthOfRscBlock%4))%4; +print(OUT_AIF pack('V', $lengthOfRscBlock)); +if ($xipaif ne 0) + { + print(OUTXIP_AIF pack('V', $lengthOfRscBlock)); + } +print "* Appending the RSC-block\n" if ($opt_v); +&appendFile(\*OUT_AIF, "$tmpdir\\aif.rsc"); +if ($xipaif ne 0) + { + &appendFile(\*OUTXIP_AIF, "$tmpdir\\aif.rsc"); + } +# append any necessary padding bytes so that the file-offset of the start of the MBM-block is a multiple of 4-bytes +print(OUT_AIF ('_' x $numberOfPaddingBytes)); +if ($xipaif ne 0) + { + print(OUTXIP_AIF ('_' x $numberOfPaddingBytes)); + } +if (-e("$tmpdir\\aif.mbm")) + { + print "* Appending the MBM-block\n" if ($opt_v); + &appendFile(\*OUT_AIF, "$tmpdir\\aif.mbm"); + } +if (-e("$tmpdir\\aif_xip.mbm")) + { + print "* Appending the XIPMBM-block\n" if ($opt_v); + &appendFile(\*OUTXIP_AIF, "$tmpdir\\aif_xip.mbm"); + } + +close(OUT_AIF) or die("* Can't close temporary file\n"); +if ($xipaif ne 0) + { + close(OUTXIP_AIF) or die("* Can't close temporary file\n"); + } +print "* copy $tmpdir\\out.aif $TrgPath\n" if ($opt_v); +copy("$tmpdir\\out.aif", "$TrgPath"); +if ($xipaif ne 0) + { + my $basepath = &Path_Split('Path', $TrgPath); + my $ext=&Path_Split('Ext', $TrgPath); + my $basename = basename($TrgPath, $ext); + my $xip="_xip"; + print "* copy $tmpdir\\out_xip.aif $basepath$basename$xip$ext\n" if ($opt_v); + copy("$tmpdir\\out_xip.aif", "$basepath$basename$xip$ext"); + } +unlink("$tmpdir\\_dump_of_resource_*"); +unlink("$tmpdir\\aif.rsc"); +unlink("$tmpdir\\aif.mbm"); +unlink("$tmpdir\\out.aif"); +unlink("$tmpdir\\aif_xip.mbm"); +unlink("$tmpdir\\out_xip.aif"); +exit 0; + +#------------------------------------------------------- +# Subroutine: convert path into something acceptable to CPP.EXE +# + +sub quoted_path + { + my ($arg) = @_; + return "\"$arg\"" if ($arg !~ /^\\[^\\]/); # not an absolute path + if ($curdrive eq "x") + { + $curdrive=""; + $curdrive=$1 if (cwd =~ /^(.:)/); + } + return "\"$curdrive$arg\""; + } + +#------------------------------------------------------- +# Subroutine: Merge the rls strings in the rpp file specified +# +sub Merge_rls_string + { + my ($rppfile) = @_; + + my $line; + my $StringId; + my $key; + my $value; + my $StringToSubstitute; + my %ResourceString; + + print "* merging text strings to $rppfile\n" if ($opt_v); + + open NEWRPP, ">$rppfile.new" or die "* Can't write to $rppfile.new"; + open RPP, "$rppfile" or die "* Can't open $rppfile"; + + while ($line = ) { + while (($StringId, $StringToSubstitute)=each %ResourceString) + { + $line=~s/\b$StringId\b/$StringToSubstitute/g if ($line !~ /^rls_string/); + } + + # find quoted "" strings + if($line =~ /^rls_string\s+(\S+)\s+(.*$)/) + { + my $text = $2; + $key = $1; + $line=~s/(.*)/\/\/$1/; + my $substr_count = 0; + if(!exists $ResourceString{$key}) + { + SUBSTR: while (1) + { + # find quoted "" strings e.g. "hello" + if($text =~ /^(\s*\"(.*?\\.)*.*?\")/) + { + $value = $1; + $text = $'; + ++$substr_count; + } + + # find quoted '' strings. e.g. 'world' + elsif($text =~ /^(\s*\'(.*?\\.)*.*?\')/) + { + $value = $1; + $text = $'; + ++$substr_count; + } + + # find hex strings e.g. <0x34><0x45><0x65> + elsif($text =~ /^(\s*(<.*?>)+)/) + { + $value = $1; + $text = $'; + ++$substr_count; + } + + # find c comment e.g. /*hello world*/ (may exist between strings) + elsif($text =~ /^(\s*\/\*.*?\*\/)/) + { + $text = $'; + next SUBSTR; # ignore embedded comment + } + + # find c++ comment e.g. //hello world (may exist after strings) + elsif($text =~ /^(\s*\/\/.*$)/) + { + $text = $'; + next SUBSTR; # ignore trailing comment + } + + # exit search + else + { + if ($substr_count == 0) + { + warn("WARNING: rls_string $key either has incorrect syntax or no value\n"); + } + last SUBSTR; + } + $ResourceString{$key} .= $value; + } + } + } + print NEWRPP $line; + } + + close RPP; + close NEWRPP; + copy ("$rppfile.new", "$rppfile"); + unlink ("$rppfile.new"); + } + +#------------------------------------------------------- +# Subroutine: Append a file into the open (binary) file already opened +# +sub appendFile + { + my $fileHandleOfTarget=shift; + my $fileNameOfSource=shift; + open(SOURCE, "< $fileNameOfSource") or die("* Can't open $fileNameOfSource\n"); + binmode(SOURCE); + for (;;) + { + my $data; + my $numberOfBytesRead=read(SOURCE, $data, 1024); + defined($numberOfBytesRead) or die("* Can't read from $fileNameOfSource\n"); + if ($numberOfBytesRead==0) + { + last; + } + print($fileHandleOfTarget $data); + } + close(SOURCE) or die("* Can't close $fileNameOfSource\n"); + } +