2 eval 'exec perl -wS $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: licinserter.pl,v $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
36 # licinserter.pl - create license entries in extension description.xml
45 print STDERR
"\nCreate extension descriptions with license-text entries\n";
46 print STDERR
"matching the language activated.\n";
47 print STDERR
"\nUsage:\n";
48 print STDERR
"\t$0 [--langsplit] infile \"naming pattern\" destination\n\n";
49 print STDERR
"\nExample:\n\n";
50 print STDERR
"$0 description.xml dir/license_xxx.txt outdir/description.xml\n\n";
51 print STDERR
"Creates \"someoutdir/description.xml\" with the license file entries like\n\"dir/license_en.US.txt\" ";
52 print STDERR
"for all languages found in the WITH_LANG environment\nvariable\n\n\n";
53 print STDERR
"Example2:\n\n";
54 print STDERR
"$0 --langsplit description.xml dir/license_xxx.txt someoutdir\n\n";
55 print STDERR
"Creates \"someoutdir/<language>/description.xml\" with one license file entry\n\"somedir/license_<language>.txt\" ";
56 print STDERR
"for all languages found in the WITH_LANG\nenvironment variable.\n\nNOTE: when using --langsplit \"destination\" needs to be a directory\n";
59 if ( $ARGV[0] =~ /^-/ ) {
60 $langswitch = shift @ARGV;
61 if ( $langswitch ne "--langsplit" ) {
65 if ( ! -d
$ARGV[2] ) {
66 print STDERR
"\nERROR - $ARGV[2] is not directory\n";
78 open INFILE
,$ARGV[0] or die "oops - no such file $ARGV[0]!\n";
80 my @inlines = <INFILE
>;
85 # Empty or unset WITH_LANG environment variable is set to default en-US.
86 # When WITH_LANG is set but does not contain en-US then that is prepended.
87 my $WithLang = $ENV{WITH_LANG
};
88 if ( ! defined $WithLang || $WithLang eq "")
92 elsif ($WithLang !~ /\ben-US\b/)
94 $WithLang = "en-US " . $WithLang;
98 if ( $langswitch eq "" ) {
100 foreach my $i (@inlines) {
101 if ( $i =~ /license-text/ ) {
104 foreach my $code ( split(/\s+/,$WithLang) ) {
107 $name =~ s/xxx/$code/;
108 $ii =~ s/isocode/$code/g;
109 $ii =~ s?licensefile?
$name?g
;
110 push @outlines, "$ii\n";
113 push @outlines, "$i\n";
116 open OUTFILE
, ">$ARGV[2]" or die "ooops - can't open $ARGV[2] for writing\n";
117 print OUTFILE
@outlines;
118 close OUTFILE
or die "ooops - can't write to $ARGV[2]\n";
121 my $outname = basename
($ARGV[0],());
122 foreach my $code ( split(/\s+/,$ENV{WITH_LANG
}) ) {
124 foreach my $i (@inlines) {
125 if ( $i =~ /license-text/ ) {
129 $name =~ s/xxx/$code/;
130 $ii =~ s/isocode/$code/g;
131 $ii =~ s?licensefile?
$name?g
;
132 push @outlines, "$ii\n";
134 push @outlines, "$i\n";
137 mkdir "$ARGV[2]/$code";
138 open OUTFILE
, ">$ARGV[2]/$code/$outname" or die "ooops - can't open $ARGV[2]/$code/$outname for writing\n";
139 print OUTFILE
@outlines;
140 close OUTFILE
or die "ooops - can't write to $ARGV[2]/$code/$outname\n";