Bump version to 24.04.3.4
[LibreOffice.git] / cli_ure / source / scripts / subst_template.pl
blobb3f90fef6d9b1143a39e35a1bc1395d99f8baab8
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 .
19 use warnings;
20 use strict;
21 use diagnostics;
23 sub trim;
24 sub readRedirectionValues($);
26 my $usage =
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) {
40 print $usage;
41 exit -1;
45 my %redirectionValue = readRedirectionValues($ARGV[1]);
46 #print "|$_| |$redirectionValue{$_}|\n", for keys %redirectionValue;
49 #Read config file in which we will replace the versions
50 $/ = undef;
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
63 print CONFIG $templ;
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;
75 while (<REDIR>)
77 chomp;
78 my $trimmed;
79 #Skip empty lines
80 if (length($trimmed = trim($_)) == 0) {
81 next;
84 #Skip comment symbol: #
85 if ($trimmed =~ /^#/) {
86 next;
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";
94 exit -1;
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";
102 exit -1;
105 #Check if we have duplicate key names
106 for (keys %redirectionValues) {
107 if ( $name eq $_) {
108 print "Error: Values in $ARGV[1] are not correct. The name $_ is not unique.\n";
109 exit -1;
113 $redirectionValues{$name} = $value;
115 return %redirectionValues;
118 sub trim($)
120 my $string = shift;
121 $string =~ s/^\s+//;
122 $string =~ s/\s+$//;
123 return $string;