update dev300-m58
[ooovba.git] / solenv / bin / licinserter.pl
blobf86d6737d635807d8391fb08033b1a7cecb441c0
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: licinserter.pl,v $
14 # $Revision: 1.4 $
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
39 use File::Basename;
41 my $langswitch;
43 sub usage()
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" ) {
62 usage();
63 exit 1;
65 if ( ! -d $ARGV[2] ) {
66 print STDERR "\nERROR - $ARGV[2] is not directory\n";
67 usage();
68 exit 2;
72 if ( $#ARGV != 2 ) {
73 print "zzz\n";
74 usage();
75 exit 1;
78 open INFILE,$ARGV[0] or die "oops - no such file $ARGV[0]!\n";
80 my @inlines = <INFILE>;
81 close INFILE;
83 chomp @inlines;
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 "")
90 $WithLang = "en-US";
92 elsif ($WithLang !~ /\ben-US\b/)
94 $WithLang = "en-US " . $WithLang;
98 if ( $langswitch eq "" ) {
99 my @outlines;
100 foreach my $i (@inlines) {
101 if ( $i =~ /license-text/ ) {
102 my $ii;
103 my $name;
104 foreach my $code ( split(/\s+/,$WithLang) ) {
105 $ii = $i;
106 $name = $ARGV[1];
107 $name =~ s/xxx/$code/;
108 $ii =~ s/isocode/$code/g;
109 $ii =~ s?licensefile?$name?g;
110 push @outlines, "$ii\n";
112 } else {
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";
119 } else {
120 my @outlines;
121 my $outname = basename($ARGV[0],());
122 foreach my $code ( split(/\s+/,$ENV{WITH_LANG}) ) {
123 @outlines=();
124 foreach my $i (@inlines) {
125 if ( $i =~ /license-text/ ) {
126 my $name;
127 my $ii = $i;
128 $name = $ARGV[1];
129 $name =~ s/xxx/$code/;
130 $ii =~ s/isocode/$code/g;
131 $ii =~ s?licensefile?$name?g;
132 push @outlines, "$ii\n";
133 } else {
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";