Kaydet (Commit) 46a97708 authored tarafından Tim Retout's avatar Tim Retout

installer: Use hashref for replace_all_ziplistvariables_in_rtffile

Also rewrite implementation of installer::scpzipfiles variable
replacement functions, and add test case.

Change-Id: Ic4548b9df8c50cbf2d3049052c637e859542a1e8
üst 89303460
...@@ -1644,7 +1644,7 @@ sub main { ...@@ -1644,7 +1644,7 @@ sub main {
{ {
my $licensefilesource = installer::windows::idtglobal::get_rtflicensefilesource($onelanguage, $includepatharrayref_lang); my $licensefilesource = installer::windows::idtglobal::get_rtflicensefilesource($onelanguage, $includepatharrayref_lang);
my $licensefile = installer::files::read_file($licensefilesource); my $licensefile = installer::files::read_file($licensefilesource);
installer::scpzipfiles::replace_all_ziplistvariables_in_rtffile($licensefile, $allvariablesarrayref, $onelanguage, $loggingdir); installer::scpzipfiles::replace_all_ziplistvariables_in_rtffile($licensefile, $allvariableshashref);
my $controltablename = $languageidtdir . $installer::globals::separator . "Control.idt"; my $controltablename = $languageidtdir . $installer::globals::separator . "Control.idt";
my $controltable = installer::files::read_file($controltablename); my $controltable = installer::files::read_file($controltablename);
installer::windows::idtglobal::add_licensefile_to_database($licensefile, $controltable); installer::windows::idtglobal::add_licensefile_to_database($licensefile, $controltable);
......
...@@ -39,60 +39,26 @@ use installer::systemactions; ...@@ -39,60 +39,26 @@ use installer::systemactions;
sub replace_all_ziplistvariables_in_file sub replace_all_ziplistvariables_in_file
{ {
my ( $fileref, $variableshashref ) = @_; my ( $fileref, $variablesref ) = @_;
for ( my $i = 0; $i <= $#{$fileref}; $i++ ) for my $line ( @{$fileref} )
{ {
my $line = ${$fileref}[$i]; $line =~ s/\$\{(\w+)\}/$variablesref->{$1}/eg;
if ( $line =~ /^.*\$\{\w+\}.*$/ ) # only occurrence of ${abc}
{
my $key;
foreach $key (keys %{$variableshashref})
{
my $value = $variableshashref->{$key};
$key = '${' . $key . '}';
$line =~ s/\Q$key\E/$value/g;
${$fileref}[$i] = $line;
}
}
} }
} }
######################################################################################## ########################################################################################
# Replacing all zip list variables in rtf files. In rtf files # Replacing all zip list variables in rtf files.
# the brackets are masked.
######################################################################################## ########################################################################################
sub replace_all_ziplistvariables_in_rtffile sub replace_all_ziplistvariables_in_rtffile
{ {
my ( $fileref, $variablesref, $onelanguage, $loggingdir ) = @_; my ( $fileref, $variablesref ) = @_;
for ( my $i = 0; $i <= $#{$fileref}; $i++ ) for my $line ( @{$fileref} )
{ {
my $line = ${$fileref}[$i]; # In rtf files the braces are backslash-escaped.
$line =~ s/\$\\\{(\w+)\\\}/$variablesref->{$1}/eg;
if ( $line =~ /^.*\$\\\{\w+\\\}.*$/ ) # only occurrence of $\{abc\}
{
for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
{
my $variableline = ${$variablesref}[$j];
my ($key, $value);
if ( $variableline =~ /^\s*([\w-]+?)\s+(.*?)\s*$/ )
{
$key = $1;
$value = $2;
$key = '$\{' . $key . '\}';
}
$line =~ s/\Q$key\E/$value/g;
${$fileref}[$i] = $line;
}
}
} }
} }
......
# Version: MPL 1.1 / GPLv3+ / LGPLv3+
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License or as specified alternatively below. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# Major Contributor(s):
# [ Copyright (C) 2012 Tim Retout <tim@retout.co.uk> (initial developer) ]
#
# All Rights Reserved.
#
# For minor contributions see the git repository.
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
# instead of those above.
use strict;
use warnings;
use lib '.';
use Test::More;
use installer::scpzipfiles;
my $vars = { foo => "bar" };
my %lines;
my $i = 0;
while (<DATA>) {
push @{ $lines{$i++ % 3} }, $_;
}
my @file1 = @{ $lines{0} };
my @file2 = @{ $lines{0} };
installer::scpzipfiles::replace_all_ziplistvariables_in_file(\@file1, $vars);
installer::scpzipfiles::replace_all_ziplistvariables_in_rtffile(\@file2, $vars);
is_deeply(\@file1, $lines{1}, 'replace_all_ziplistvariables_in_file works');
is_deeply(\@file2, $lines{2}, 'replace_all_ziplistvariables_in_rtffile works');
done_testing();
__DATA__
This is a test
This is a test
This is a test
A test of ${foo} replacement ${foo}.
A test of bar replacement bar.
A test of ${foo} replacement ${foo}.
A test of RTF $\{foo\} replacement $\{foo\}.
A test of RTF $\{foo\} replacement $\{foo\}.
A test of RTF bar replacement bar.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment