1cdf0e10cSrcweir: # -*- perl -*- 2cdf0e10cSrcweireval 'exec perl -wS $0 ${1+"$@"}' 3cdf0e10cSrcweir if 0; 4*7e90fac2SAndrew Rist#************************************************************** 5*7e90fac2SAndrew Rist# 6*7e90fac2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 7*7e90fac2SAndrew Rist# or more contributor license agreements. See the NOTICE file 8*7e90fac2SAndrew Rist# distributed with this work for additional information 9*7e90fac2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 10*7e90fac2SAndrew Rist# to you under the Apache License, Version 2.0 (the 11*7e90fac2SAndrew Rist# "License"); you may not use this file except in compliance 12*7e90fac2SAndrew Rist# with the License. You may obtain a copy of the License at 13*7e90fac2SAndrew Rist# 14*7e90fac2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 15*7e90fac2SAndrew Rist# 16*7e90fac2SAndrew Rist# Unless required by applicable law or agreed to in writing, 17*7e90fac2SAndrew Rist# software distributed under the License is distributed on an 18*7e90fac2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 19*7e90fac2SAndrew Rist# KIND, either express or implied. See the License for the 20*7e90fac2SAndrew Rist# specific language governing permissions and limitations 21*7e90fac2SAndrew Rist# under the License. 22*7e90fac2SAndrew Rist# 23*7e90fac2SAndrew Rist#************************************************************** 24*7e90fac2SAndrew Rist 25*7e90fac2SAndrew Rist 26cdf0e10cSrcweir 27cdf0e10cSrcweir# create java installer help files in html format for all languages defined in ulf file 28cdf0e10cSrcweir 29cdf0e10cSrcweiruse Cwd; 30cdf0e10cSrcweiruse File::Copy; 31cdf0e10cSrcweir 32cdf0e10cSrcweirif( $#ARGV < 2 ) 33cdf0e10cSrcweir { 34cdf0e10cSrcweir print <<ENDHELP; 35cdf0e10cSrcweirUSAGE: $0 <separator> <ulf_file_path> <outputpath> 36cdf0e10cSrcweir <separator>: separator, used on the platform (slash or backslash) 37cdf0e10cSrcweir <ulf_file_path>: path, in which the ulf file(s) can be found 38cdf0e10cSrcweir <outputpath>: path, in which the help files will be created 39cdf0e10cSrcweirENDHELP 40cdf0e10cSrcweir exit; 41cdf0e10cSrcweir } 42cdf0e10cSrcweir 43cdf0e10cSrcweir$separator = $ARGV[0]; 44cdf0e10cSrcweir$inputpath = $ARGV[1]; 45cdf0e10cSrcweir$outputpath = $ARGV[2]; 46cdf0e10cSrcweir 47cdf0e10cSrcweir$inputpath =~ s/\Q$separator\E\s*$//; 48cdf0e10cSrcweir$outputpath =~ s/\Q$separator\E\s*$//; 49cdf0e10cSrcweir 50cdf0e10cSrcweirif ( ! -d $outputpath ) { mkdir $outputpath; } 51cdf0e10cSrcweir 52cdf0e10cSrcweirprint "Separator: $separator \n"; 53cdf0e10cSrcweirprint "Input path: $inputpath \n"; 54cdf0e10cSrcweirprint "Output path: $outputpath \n"; 55cdf0e10cSrcweir 56cdf0e10cSrcweirmy $localdir = cwd(); 57cdf0e10cSrcweir 58cdf0e10cSrcweirmy $ulffilename = "setupstrings.ulf"; 59cdf0e10cSrcweirmy $helpfilename = "helpfilenames.txt"; 60cdf0e10cSrcweirmy $defaultlanguage = "en-US"; 61cdf0e10cSrcweir 62cdf0e10cSrcweir$ulffilename = $inputpath . $separator . $ulffilename; 63cdf0e10cSrcweirmy $ulffile = read_file($ulffilename); 64cdf0e10cSrcweir 65cdf0e10cSrcweirmy $helpfilenames = read_file($helpfilename); 66cdf0e10cSrcweirmy $allhelpfilenames = collect_helpfile_names($helpfilenames); 67cdf0e10cSrcweir 68cdf0e10cSrcweirmy $alllanguages = get_all_languages($ulffile); 69cdf0e10cSrcweirmy @allnewpropertyfiles = (); 70cdf0e10cSrcweir 71cdf0e10cSrcweirfor ( my $i = 0; $i <= $#{$allhelpfilenames}; $i++ ) 72cdf0e10cSrcweir{ 73cdf0e10cSrcweir my $helpfilename = ${$allhelpfilenames}[$i]; 74cdf0e10cSrcweir 75cdf0e10cSrcweir for ( my $j = 0; $j <= $#{$alllanguages}; $j++ ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir my $language = ${$alllanguages}[$j]; 78cdf0e10cSrcweir 79cdf0e10cSrcweir # Creating content of help file 80cdf0e10cSrcweir my $helpfilecontent = collect_helpfile_content($helpfilename, $ulffile, $language); 81cdf0e10cSrcweir 82cdf0e10cSrcweir # Saving helpfile 83cdf0e10cSrcweir my $savefilename = $helpfilename . "_" . $language . ".html"; 84cdf0e10cSrcweir $savefilename = $outputpath . $separator . $savefilename; 85cdf0e10cSrcweir save_file($savefilename, $helpfilecontent); 86cdf0e10cSrcweir 87cdf0e10cSrcweir if ( $language eq $defaultlanguage ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir $savefilename = $helpfilename . ".html"; 90cdf0e10cSrcweir $savefilename = $outputpath . $separator . $savefilename; 91cdf0e10cSrcweir save_file($savefilename, $helpfilecontent); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir} 95cdf0e10cSrcweir 96cdf0e10cSrcweirexit; 97cdf0e10cSrcweir 98cdf0e10cSrcweirsub main::read_directory 99cdf0e10cSrcweir{ 100cdf0e10cSrcweir my ($dir, $ext) = @_; 101cdf0e10cSrcweir 102cdf0e10cSrcweir my @content = (); 103cdf0e10cSrcweir my $direntry; 104cdf0e10cSrcweir opendir(DIR, $dir); 105cdf0e10cSrcweir 106cdf0e10cSrcweir foreach $direntry (readdir (DIR)) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir next if $direntry eq "."; 109cdf0e10cSrcweir next if $direntry eq ".."; 110cdf0e10cSrcweir next if ( ! ( $direntry =~ /\.\Q$ext\E\s*$/ )); 111cdf0e10cSrcweir 112cdf0e10cSrcweir # my $completeentry = $dir . $separator . $direntry; 113cdf0e10cSrcweir # push(@content, $completeentry); 114cdf0e10cSrcweir push(@content, $direntry); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir closedir(DIR); 118cdf0e10cSrcweir return \@content; 119cdf0e10cSrcweir} 120cdf0e10cSrcweir 121cdf0e10cSrcweirsub main::read_file 122cdf0e10cSrcweir{ 123cdf0e10cSrcweir my ($filename) = @_; 124cdf0e10cSrcweir 125cdf0e10cSrcweir open( IN, "<$filename" ) || die "cannot open $filename"; 126cdf0e10cSrcweir my @content = <IN>; 127cdf0e10cSrcweir close( IN ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir return \@content; 130cdf0e10cSrcweir} 131cdf0e10cSrcweir 132cdf0e10cSrcweirsub main::collect_helpfile_content 133cdf0e10cSrcweir{ 134cdf0e10cSrcweir my ($helpfilename, $ulffile, $language) = @_; 135cdf0e10cSrcweir 136cdf0e10cSrcweir my @helpfilecontent = (); 137cdf0e10cSrcweir my $stringhash = create_string_hash($ulffile, $language); 138cdf0e10cSrcweir 139cdf0e10cSrcweir # Collecting all strings for one html file. 140cdf0e10cSrcweir # For "Prologue_de.html" all files need to begin with "STRING_PROLOGUE_X" 141cdf0e10cSrcweir # The "X" is the ordering number. 142cdf0e10cSrcweir 143cdf0e10cSrcweir my $basestring = "STRING_" . uc($helpfilename) . "_"; 144cdf0e10cSrcweir 145cdf0e10cSrcweir for ( my $i = 0; $i <= 10; $i++ ) # 10 strings possible for each html file 146cdf0e10cSrcweir { 147cdf0e10cSrcweir my $key = $basestring . $i; 148cdf0e10cSrcweir if ( exists $stringhash->{$key} ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir my $content = $stringhash->{$key} . "\n<p>\n"; 151cdf0e10cSrcweir push(@helpfilecontent, $content); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir return \@helpfilecontent; 156cdf0e10cSrcweir} 157cdf0e10cSrcweir 158cdf0e10cSrcweirsub main::collect_helpfile_names 159cdf0e10cSrcweir{ 160cdf0e10cSrcweir my ($helpfilecontent) = @_; 161cdf0e10cSrcweir 162cdf0e10cSrcweir my @allhelpfiles = (); 163cdf0e10cSrcweir 164cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$helpfilecontent}; $i++ ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir if ( ${$helpfilecontent}[$i] =~ /^\s*#/ ) { next; } # comment line 167cdf0e10cSrcweir if ( ${$helpfilecontent}[$i] =~ /^\s*$/ ) { next; } # empty line 168cdf0e10cSrcweir my $filename = ${$helpfilecontent}[$i]; 169cdf0e10cSrcweir $filename =~ s/\s//g; 170cdf0e10cSrcweir push(@allhelpfiles, $filename); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir return \@allhelpfiles; 174cdf0e10cSrcweir} 175cdf0e10cSrcweir 176cdf0e10cSrcweirsub main::get_all_languages 177cdf0e10cSrcweir{ 178cdf0e10cSrcweir my ($ulffile) = @_; 179cdf0e10cSrcweir 180cdf0e10cSrcweir my @languages = (); 181cdf0e10cSrcweir my $record = 0; 182cdf0e10cSrcweir 183cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$ulffile}; $i++ ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record )) { last; } 186cdf0e10cSrcweir if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record == 0 )) { $record = 1; } 187cdf0e10cSrcweir 188cdf0e10cSrcweir if (( $record ) && ( ${$ulffile}[$i] =~ /^\s*(.+?)\s*\=/ )) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir $language = $1; 191cdf0e10cSrcweir push(@languages, $language); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir my $languagestring = ""; 196cdf0e10cSrcweir for ( my $i = 0; $i <= $#languages; $i++ ) { $languagestring = $languagestring . $languages[$i] . ","; } 197cdf0e10cSrcweir $languagestring =~ s/,\s*$//; 198cdf0e10cSrcweir print "Languages: $languagestring\n"; 199cdf0e10cSrcweir 200cdf0e10cSrcweir return \@languages; 201cdf0e10cSrcweir} 202cdf0e10cSrcweir 203cdf0e10cSrcweirsub main::create_string_hash 204cdf0e10cSrcweir{ 205cdf0e10cSrcweir my ($ulffile, $language) = @_; 206cdf0e10cSrcweir 207cdf0e10cSrcweir my %stringhash = (); 208cdf0e10cSrcweir my $key = ""; 209cdf0e10cSrcweir my $value_defined = 0; 210cdf0e10cSrcweir 211cdf0e10cSrcweir for ( my $i = 0; $i <= $#{$ulffile}; $i++ ) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if ( ${$ulffile}[$i] =~ /^\s*\[(.*)\]\s*$/ ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir $key = $1; 216cdf0e10cSrcweir $value_defined = 0; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir if (( ${$ulffile}[$i] =~ /^\s*\Q$defaultlanguage\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined )) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir $value = $1; # defaulting to english 222cdf0e10cSrcweir $stringhash{$key} = $value; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir if (( ${$ulffile}[$i] =~ /^\s*\Q$language\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined )) 226cdf0e10cSrcweir { 227cdf0e10cSrcweir $value = $1; 228cdf0e10cSrcweir $stringhash{$key} = $value; 229cdf0e10cSrcweir $value_defined = 1; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir # additional replacement for ${LANGUAGE}, not defined in ulf file 234cdf0e10cSrcweir my $languagekey = "LANGUAGE"; 235cdf0e10cSrcweir $stringhash{$languagekey} = $language; 236cdf0e10cSrcweir 237cdf0e10cSrcweir # print_hash(\%stringhash); 238cdf0e10cSrcweir 239cdf0e10cSrcweir return \%stringhash; 240cdf0e10cSrcweir} 241cdf0e10cSrcweir 242cdf0e10cSrcweirsub main::print_hash 243cdf0e10cSrcweir{ 244cdf0e10cSrcweir my ( $hashref ) = @_; 245cdf0e10cSrcweir 246cdf0e10cSrcweir print "Hash contains:\n"; 247cdf0e10cSrcweir 248cdf0e10cSrcweir my $key; 249cdf0e10cSrcweir foreach $key (keys %{$hashref} ) { print "Key: $key, Value: $hashref->{$key}\n"; } 250cdf0e10cSrcweir} 251cdf0e10cSrcweir 252cdf0e10cSrcweirsub main::save_file 253cdf0e10cSrcweir{ 254cdf0e10cSrcweir my ($filename, $filecontent) = @_; 255cdf0e10cSrcweir 256cdf0e10cSrcweir if ( open( OUT, ">$filename" ) ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir print OUT @{$filecontent}; 259cdf0e10cSrcweir close( OUT); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir push(@allnewpropertyfiles, $filename); 263cdf0e10cSrcweir print "Created file: $filename\n"; 264cdf0e10cSrcweir} 265