1: # -*- perl -*- 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# create java installer help files in html format for all languages defined in ulf file 32 33use Cwd; 34use File::Copy; 35 36if( $#ARGV < 2 ) 37 { 38 print <<ENDHELP; 39USAGE: $0 <separator> <ulf_file_path> <outputpath> 40 <separator>: separator, used on the platform (slash or backslash) 41 <ulf_file_path>: path, in which the ulf file(s) can be found 42 <outputpath>: path, in which the help files will be created 43ENDHELP 44 exit; 45 } 46 47$separator = $ARGV[0]; 48$inputpath = $ARGV[1]; 49$outputpath = $ARGV[2]; 50 51$inputpath =~ s/\Q$separator\E\s*$//; 52$outputpath =~ s/\Q$separator\E\s*$//; 53 54if ( ! -d $outputpath ) { mkdir $outputpath; } 55 56print "Separator: $separator \n"; 57print "Input path: $inputpath \n"; 58print "Output path: $outputpath \n"; 59 60my $localdir = cwd(); 61 62my $ulffilename = "setupstrings.ulf"; 63my $helpfilename = "helpfilenames.txt"; 64my $defaultlanguage = "en-US"; 65 66$ulffilename = $inputpath . $separator . $ulffilename; 67my $ulffile = read_file($ulffilename); 68 69my $helpfilenames = read_file($helpfilename); 70my $allhelpfilenames = collect_helpfile_names($helpfilenames); 71 72my $alllanguages = get_all_languages($ulffile); 73my @allnewpropertyfiles = (); 74 75for ( my $i = 0; $i <= $#{$allhelpfilenames}; $i++ ) 76{ 77 my $helpfilename = ${$allhelpfilenames}[$i]; 78 79 for ( my $j = 0; $j <= $#{$alllanguages}; $j++ ) 80 { 81 my $language = ${$alllanguages}[$j]; 82 83 # Creating content of help file 84 my $helpfilecontent = collect_helpfile_content($helpfilename, $ulffile, $language); 85 86 # Saving helpfile 87 my $savefilename = $helpfilename . "_" . $language . ".html"; 88 $savefilename = $outputpath . $separator . $savefilename; 89 save_file($savefilename, $helpfilecontent); 90 91 if ( $language eq $defaultlanguage ) 92 { 93 $savefilename = $helpfilename . ".html"; 94 $savefilename = $outputpath . $separator . $savefilename; 95 save_file($savefilename, $helpfilecontent); 96 } 97 } 98} 99 100exit; 101 102sub main::read_directory 103{ 104 my ($dir, $ext) = @_; 105 106 my @content = (); 107 my $direntry; 108 opendir(DIR, $dir); 109 110 foreach $direntry (readdir (DIR)) 111 { 112 next if $direntry eq "."; 113 next if $direntry eq ".."; 114 next if ( ! ( $direntry =~ /\.\Q$ext\E\s*$/ )); 115 116 # my $completeentry = $dir . $separator . $direntry; 117 # push(@content, $completeentry); 118 push(@content, $direntry); 119 } 120 121 closedir(DIR); 122 return \@content; 123} 124 125sub main::read_file 126{ 127 my ($filename) = @_; 128 129 open( IN, "<$filename" ) || die "cannot open $filename"; 130 my @content = <IN>; 131 close( IN ); 132 133 return \@content; 134} 135 136sub main::collect_helpfile_content 137{ 138 my ($helpfilename, $ulffile, $language) = @_; 139 140 my @helpfilecontent = (); 141 my $stringhash = create_string_hash($ulffile, $language); 142 143 # Collecting all strings for one html file. 144 # For "Prologue_de.html" all files need to begin with "STRING_PROLOGUE_X" 145 # The "X" is the ordering number. 146 147 my $basestring = "STRING_" . uc($helpfilename) . "_"; 148 149 for ( my $i = 0; $i <= 10; $i++ ) # 10 strings possible for each html file 150 { 151 my $key = $basestring . $i; 152 if ( exists $stringhash->{$key} ) 153 { 154 my $content = $stringhash->{$key} . "\n<p>\n"; 155 push(@helpfilecontent, $content); 156 } 157 } 158 159 return \@helpfilecontent; 160} 161 162sub main::collect_helpfile_names 163{ 164 my ($helpfilecontent) = @_; 165 166 my @allhelpfiles = (); 167 168 for ( my $i = 0; $i <= $#{$helpfilecontent}; $i++ ) 169 { 170 if ( ${$helpfilecontent}[$i] =~ /^\s*#/ ) { next; } # comment line 171 if ( ${$helpfilecontent}[$i] =~ /^\s*$/ ) { next; } # empty line 172 my $filename = ${$helpfilecontent}[$i]; 173 $filename =~ s/\s//g; 174 push(@allhelpfiles, $filename); 175 } 176 177 return \@allhelpfiles; 178} 179 180sub main::get_all_languages 181{ 182 my ($ulffile) = @_; 183 184 my @languages = (); 185 my $record = 0; 186 187 for ( my $i = 0; $i <= $#{$ulffile}; $i++ ) 188 { 189 if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record )) { last; } 190 if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record == 0 )) { $record = 1; } 191 192 if (( $record ) && ( ${$ulffile}[$i] =~ /^\s*(.+?)\s*\=/ )) 193 { 194 $language = $1; 195 push(@languages, $language); 196 } 197 } 198 199 my $languagestring = ""; 200 for ( my $i = 0; $i <= $#languages; $i++ ) { $languagestring = $languagestring . $languages[$i] . ","; } 201 $languagestring =~ s/,\s*$//; 202 print "Languages: $languagestring\n"; 203 204 return \@languages; 205} 206 207sub main::create_string_hash 208{ 209 my ($ulffile, $language) = @_; 210 211 my %stringhash = (); 212 my $key = ""; 213 my $value_defined = 0; 214 215 for ( my $i = 0; $i <= $#{$ulffile}; $i++ ) 216 { 217 if ( ${$ulffile}[$i] =~ /^\s*\[(.*)\]\s*$/ ) 218 { 219 $key = $1; 220 $value_defined = 0; 221 } 222 223 if (( ${$ulffile}[$i] =~ /^\s*\Q$defaultlanguage\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined )) 224 { 225 $value = $1; # defaulting to english 226 $stringhash{$key} = $value; 227 } 228 229 if (( ${$ulffile}[$i] =~ /^\s*\Q$language\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined )) 230 { 231 $value = $1; 232 $stringhash{$key} = $value; 233 $value_defined = 1; 234 } 235 } 236 237 # additional replacement for ${LANGUAGE}, not defined in ulf file 238 my $languagekey = "LANGUAGE"; 239 $stringhash{$languagekey} = $language; 240 241 # print_hash(\%stringhash); 242 243 return \%stringhash; 244} 245 246sub main::print_hash 247{ 248 my ( $hashref ) = @_; 249 250 print "Hash contains:\n"; 251 252 my $key; 253 foreach $key (keys %{$hashref} ) { print "Key: $key, Value: $hashref->{$key}\n"; } 254} 255 256sub main::save_file 257{ 258 my ($filename, $filecontent) = @_; 259 260 if ( open( OUT, ">$filename" ) ) 261 { 262 print OUT @{$filecontent}; 263 close( OUT); 264 } 265 266 push(@allnewpropertyfiles, $filename); 267 print "Created file: $filename\n"; 268} 269