2 eval 'exec perl -wS $0 ${1+"$@"}'
5 # This file is part of the LibreOffice project.
7 # This Source Code Form is subject to the terms of the Mozilla Public
8 # License, v. 2.0. If a copy of the MPL was not distributed with this
9 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 # This file incorporates work covered by the following license notice:
13 # Licensed to the Apache Software Foundation (ASF) under one or more
14 # contributor license agreements. See the NOTICE file distributed
15 # with this work for additional information regarding copyright
16 # ownership. The ASF licenses this file to you under the Apache
17 # License, Version 2.0 (the "License"); you may not use this file
18 # except in compliance with the License. You may obtain a copy of
19 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 # licinserter.pl - create license entries in extension description.xml
32 print STDERR
"\nCreate extension descriptions with license-text entries\n";
33 print STDERR
"matching the language activated.\n";
34 print STDERR
"\nUsage:\n";
35 print STDERR
"\t$0 [--langsplit] infile \"naming pattern\" destination\n\n";
36 print STDERR
"\nExample:\n\n";
37 print STDERR
"$0 description.xml dir/license_xxx.txt outdir/description.xml\n\n";
38 print STDERR
"Creates \"someoutdir/description.xml\" with the license file entries like\n\"dir/license_en.US.txt\" ";
39 print STDERR
"for all languages found in the WITH_LANG environment\nvariable\n\n\n";
40 print STDERR
"Example2:\n\n";
41 print STDERR
"$0 --langsplit description.xml dir/license_xxx.txt someoutdir\n\n";
42 print STDERR
"Creates \"someoutdir/<language>/description.xml\" with one license file entry\n\"somedir/license_<language>.txt\" ";
43 print STDERR
"for all languages found in the WITH_LANG\nenvironment variable.\n\nNOTE: when using --langsplit \"destination\" needs to be a directory\n";
46 if ( $ARGV[0] =~ /^-/ ) {
47 $langswitch = shift @ARGV;
48 if ( $langswitch ne "--langsplit" ) {
52 if ( ! -d
$ARGV[2] ) {
53 print STDERR
"\nERROR - $ARGV[2] is not directory\n";
65 open INFILE
,$ARGV[0] or die "oops - no such file $ARGV[0]!\n";
67 my @inlines = <INFILE
>;
72 # Empty or unset WITH_LANG environment variable is set to default en-US.
73 # When WITH_LANG is set but does not contain en-US then that is prepended.
74 my $WithLang = $ENV{WITH_LANG
};
75 if ( ! defined $WithLang || $WithLang eq "")
79 elsif ($WithLang !~ /\ben-US\b/)
81 $WithLang = "en-US " . $WithLang;
85 if ( $langswitch eq "" ) {
87 foreach my $i (@inlines) {
88 if ( $i =~ /license-text/ ) {
91 foreach my $code ( split(/\s+/,$WithLang) ) {
94 $name =~ s/xxx/$code/;
95 $ii =~ s/isocode/$code/g;
96 $ii =~ s?licensefile?
$name?g
;
97 push @outlines, "$ii\n";
100 push @outlines, "$i\n";
103 open OUTFILE
, ">$ARGV[2]" or die "ooops - can't open $ARGV[2] for writing\n";
104 print OUTFILE
@outlines;
105 close OUTFILE
or die "ooops - can't write to $ARGV[2]\n";
108 my $outname = basename
($ARGV[0],());
109 foreach my $code ( split(/\s+/,$ENV{WITH_LANG
}) ) {
111 foreach my $i (@inlines) {
112 if ( $i =~ /license-text/ ) {
116 $name =~ s/xxx/$code/;
117 $ii =~ s/isocode/$code/g;
118 $ii =~ s?licensefile?
$name?g
;
119 push @outlines, "$ii\n";
121 push @outlines, "$i\n";
124 mkdir "$ARGV[2]/$code";
125 open OUTFILE
, ">$ARGV[2]/$code/$outname" or die "ooops - can't open $ARGV[2]/$code/$outname for writing\n";
126 print OUTFILE
@outlines;
127 close OUTFILE
or die "ooops - can't write to $ARGV[2]/$code/$outname\n";