1#!/usr/bin/perl 2#************************************************************************* 3# 4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5# 6# Copyright 2000, 2011 Oracle and/or its affiliates. 7# 8# OpenOffice.org - a multi-platform office productivity suite 9# 10# This file is part of OpenOffice.org. 11# 12# OpenOffice.org is free software: you can redistribute it and/or modify 13# it under the terms of the GNU Lesser General Public License version 3 14# only, as published by the Free Software Foundation. 15# 16# OpenOffice.org is distributed in the hope that it will be useful, 17# but WITHOUT ANY WARRANTY; without even the implied warranty of 18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19# GNU Lesser General Public License version 3 for more details 20# (a copy is included in the LICENSE file that accompanied this code). 21# 22# You should have received a copy of the GNU Lesser General Public License 23# version 3 along with OpenOffice.org. If not, see 24# <http://www.openoffice.org/license.html> 25# for a copy of the LGPLv3 License. 26# 27#************************************************************************* 28 29parse_args(); 30execute_args(); 31exit(0); 32 33my $source = undef; 34my $dest = undef; 35my @languages = undef; 36 37sub parse_args 38{ 39 # at most two arguments 40 explain(), exit(100) if ( $#ARGV > 1 ); 41 42 # destination file is the second argument, if present 43 $dest = $ARGV[1] if ( $#ARGV > 0 ); 44 45 # source file is the first argument if present 46 if ( $#ARGV > -1 ) 47 { 48 $source = $ARGV[0]; 49 if ( ! -f $source ) 50 { 51 print STDERR "$source is not a valid file, aborting"; 52 exit(101); 53 } 54 } 55 56 # check which languages to use 57 my $languages = $ENV{WITH_LANG}; 58 if ( ( ! defined $languages ) || ( "$languages" eq "" ) ) 59 { 60 print STDERR "$0: WITH_LANG not set or empty, defaulting to 'en-US'\n"; 61 $languages = "en-US"; 62 } 63 @languages = split ( ' ', $languages ); 64} 65 66sub execute_args 67{ 68 my @description = (); 69 if ( defined $source ) 70 { 71 open SOURCE, "$source" || die "could not open $source: $?\n"; 72 @description = <SOURCE>; 73 close SOURCE; 74 } 75 else 76 { 77 @description = <STDIN>; 78 } 79 80 if ( defined $dest ) 81 { 82 open DEST, ">$dest" || die "could not open $dest for writing: $?\n"; 83 } 84 85 foreach (@description) 86 { 87 chomp; s/\r//; 88 89 if ( /\#LANG\#/ ) 90 { 91 foreach $lang ( @languages ) 92 { 93 my $transformed = $_; 94 $transformed =~ s/\#LANG#/$lang/g; 95 if ( defined $dest ) 96 { 97 print DEST "$transformed\n"; 98 } 99 else 100 { 101 print STDOUT "$transformed\n"; 102 } 103 } 104 } 105 else 106 { 107 if ( defined $dest ) 108 { 109 print DEST "$_\n"; 110 } 111 else 112 { 113 print STDOUT "$_\n"; 114 } 115 } 116 } 117 118 close DEST if ( defined $dest ); 119} 120 121# explains the program's usage 122sub explain 123{ 124 print STDOUT "usage:\n"; 125 print STDOUT " $0 [<description_file> [<output_file>]]\n"; 126 print STDOUT " transforms the given extension description file\n"; 127 print STDOUT "\n"; 128 print STDOUT " If <output_file> is not given, STDOUT is used.\n"; 129 print STDOUT " If <description_file> is not given, STDIN is used.\n"; 130 print STDOUT "\n"; 131 print STDOUT " The following transformations are done at the moment:\n"; 132 print STDOUT " - duplicate all lines containing #LANG#, for ever token of \$WITH_LANG\n"; 133 print STDOUT " replacing every occurance of \$LANG with a token\n"; 134 print STDOUT "\n"; 135 print STDOUT " And yes, the functionality of this script should be\n"; 136 print STDOUT " - moved to solenv/inc/tg_ext.mk\n"; 137 print STDOUT " - implemented as XSLT, to be much less error-prone\n"; 138} 139