1: 2eval 'exec perl -wS $0 ${1+"$@"}' 3 if 0; 4#************************************************************************* 5# 6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7# 8# Copyright 2000, 2010 Oracle and/or its affiliates. 9# 10# OpenOffice.org - a multi-platform office productivity suite 11# 12# This file is part of OpenOffice.org. 13# 14# OpenOffice.org is free software: you can redistribute it and/or modify 15# it under the terms of the GNU Lesser General Public License version 3 16# only, as published by the Free Software Foundation. 17# 18# OpenOffice.org is distributed in the hope that it will be useful, 19# but WITHOUT ANY WARRANTY; without even the implied warranty of 20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21# GNU Lesser General Public License version 3 for more details 22# (a copy is included in the LICENSE file that accompanied this code). 23# 24# You should have received a copy of the GNU Lesser General Public License 25# version 3 along with OpenOffice.org. If not, see 26# <http://www.openoffice.org/license.html> 27# for a copy of the LGPLv3 License. 28# 29#************************************************************************* 30 31# 32# licinserter.pl - create license entries in extension description.xml 33# 34 35use File::Basename; 36 37my $langswitch; 38 39sub usage() 40{ 41 print STDERR "\nCreate extension descriptions with license-text entries\n"; 42 print STDERR "matching the language activated.\n"; 43 print STDERR "\nUsage:\n"; 44 print STDERR "\t$0 [--langsplit] infile \"naming pattern\" destination\n\n"; 45 print STDERR "\nExample:\n\n"; 46 print STDERR "$0 description.xml dir/license_xxx.txt outdir/description.xml\n\n"; 47 print STDERR "Creates \"someoutdir/description.xml\" with the license file entries like\n\"dir/license_en.US.txt\" "; 48 print STDERR "for all languages found in the WITH_LANG environment\nvariable\n\n\n"; 49 print STDERR "Example2:\n\n"; 50 print STDERR "$0 --langsplit description.xml dir/license_xxx.txt someoutdir\n\n"; 51 print STDERR "Creates \"someoutdir/<language>/description.xml\" with one license file entry\n\"somedir/license_<language>.txt\" "; 52 print STDERR "for all languages found in the WITH_LANG\nenvironment variable.\n\nNOTE: when using --langsplit \"destination\" needs to be a directory\n"; 53} 54 55if ( $ARGV[0] =~ /^-/ ) { 56 $langswitch = shift @ARGV; 57 if ( $langswitch ne "--langsplit" ) { 58 usage(); 59 exit 1; 60 } 61 if ( ! -d $ARGV[2] ) { 62 print STDERR "\nERROR - $ARGV[2] is not directory\n"; 63 usage(); 64 exit 2; 65 } 66} 67 68if ( $#ARGV != 2 ) { 69 print "zzz\n"; 70 usage(); 71 exit 1; 72} 73 74open INFILE,$ARGV[0] or die "oops - no such file $ARGV[0]!\n"; 75 76my @inlines = <INFILE>; 77close INFILE; 78 79chomp @inlines; 80 81# Empty or unset WITH_LANG environment variable is set to default en-US. 82# When WITH_LANG is set but does not contain en-US then that is prepended. 83my $WithLang = $ENV{WITH_LANG}; 84if ( ! defined $WithLang || $WithLang eq "") 85{ 86 $WithLang = "en-US"; 87} 88elsif ($WithLang !~ /\ben-US\b/) 89{ 90 $WithLang = "en-US " . $WithLang; 91} 92 93 94if ( $langswitch eq "" ) { 95 my @outlines; 96 foreach my $i (@inlines) { 97 if ( $i =~ /license-text/ ) { 98 my $ii; 99 my $name; 100 foreach my $code ( split(/\s+/,$WithLang) ) { 101 $ii = $i; 102 $name = $ARGV[1]; 103 $name =~ s/xxx/$code/; 104 $ii =~ s/isocode/$code/g; 105 $ii =~ s?licensefile?$name?g; 106 push @outlines, "$ii\n"; 107 } 108 } else { 109 push @outlines, "$i\n"; 110 } 111 } 112 open OUTFILE, ">$ARGV[2]" or die "ooops - can't open $ARGV[2] for writing\n"; 113 print OUTFILE @outlines; 114 close OUTFILE or die "ooops - can't write to $ARGV[2]\n"; 115} else { 116 my @outlines; 117 my $outname = basename($ARGV[0],()); 118 foreach my $code ( split(/\s+/,$ENV{WITH_LANG}) ) { 119 @outlines=(); 120 foreach my $i (@inlines) { 121 if ( $i =~ /license-text/ ) { 122 my $name; 123 my $ii = $i; 124 $name = $ARGV[1]; 125 $name =~ s/xxx/$code/; 126 $ii =~ s/isocode/$code/g; 127 $ii =~ s?licensefile?$name?g; 128 push @outlines, "$ii\n"; 129 } else { 130 push @outlines, "$i\n"; 131 } 132 } 133 mkdir "$ARGV[2]/$code"; 134 open OUTFILE, ">$ARGV[2]/$code/$outname" or die "ooops - can't open $ARGV[2]/$code/$outname for writing\n"; 135 print OUTFILE @outlines; 136 close OUTFILE or die "ooops - can't write to $ARGV[2]/$code/$outname\n"; 137 } 138} 139