2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 sub readRedirectionValues
($);
27 "Usage is: \n subst_template.pl configTemplate redirections policyConfig
29 configTemplate: The config file which is used for the policy assembly. It
30 contains place holders for the binding redirection.
32 redirections: file containing the values for oldVersion and newVersion tags
33 which are used in the BindingRedirect element of the config files.
35 policyConfig: Name of the file in which we want to write the config file.
39 if (scalar @ARGV < 3) {
45 my %redirectionValue = readRedirectionValues
($ARGV[1]);
46 #print "|$_| |$redirectionValue{$_}|\n", for keys %redirectionValue;
49 #Read config file in which we will replace the versions
51 open TEMPLATE
, $ARGV[0] or die $!;
52 my $templ = <TEMPLATE
>;
54 #Open the config file we are goint to write to
55 open CONFIG
, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
57 #No substitute the place holders for oldVersion and new Version in the config template with
58 #the values obtained from the redirections file
59 for (keys %redirectionValue) {
60 $templ=~ s/\b$_\b/$redirectionValue{$_}/;
62 #Write the config file
65 #Reads the key value pairs from the files, which name must be passed in
66 #the parameter. The file contains lines of the form name=value, for example
67 #CLI_TYPES_OLD_VERSION=1.1.0.0-1.1.1.0
68 sub readRedirectionValues
($)
70 #Read in the values for the version redirection
71 open REDIR
, $_[0] or die $!;
73 my %redirectionValues;
80 if (length($trimmed = trim
($_)) == 0) {
84 #Skip comment symbol: #
85 if ($trimmed =~ /^#/) {
89 my @lineParts = split /=/,$_;
91 #Check if we have valid name value pairs.
92 if (scalar @lineParts != 2) {
93 print "Error: Values in $ARGV[1] are not correct (Entries must have the form name=value). Invalid line: \n$_\n";
97 #Trim the strings and check if they still contain characters
98 my $name = trim
($lineParts[0]);
99 my $value = trim
($lineParts[1]);
100 if (length($name) == 0 || length($value) == 0) {
101 print "Error: Values in $ARGV[1] are not correct. Invalid line: \n$_\n";
105 #Check if we have duplicate key names
106 for (keys %redirectionValues) {
108 print "Error: Values in $ARGV[1] are not correct. The name $_ is not unique.\n";
113 $redirectionValues{$name} = $value;
115 return %redirectionValues;