merge the formfield patch from ooo-build
[ooovba.git] / javainstaller2 / src / Helpfiles / create_helpfiles.pl
blobc4d3ff2d5b1e0b922532e8155a84e478835e9a17
1 : # -*- perl -*-
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: create_helpfiles.pl,v $
14 # $Revision: 1.3 $
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 #*************************************************************************
35 # create java installer help files in html format for all languages defined in ulf file
37 use Cwd;
38 use File::Copy;
40 if( $#ARGV < 2 )
42 print <<ENDHELP;
43 USAGE: $0 <separator> <ulf_file_path> <outputpath>
44 <separator>: separator, used on the platform (slash or backslash)
45 <ulf_file_path>: path, in which the ulf file(s) can be found
46 <outputpath>: path, in which the help files will be created
47 ENDHELP
48 exit;
51 $separator = $ARGV[0];
52 $inputpath = $ARGV[1];
53 $outputpath = $ARGV[2];
55 $inputpath =~ s/\Q$separator\E\s*$//;
56 $outputpath =~ s/\Q$separator\E\s*$//;
58 if ( ! -d $outputpath ) { mkdir $outputpath; }
60 print "Separator: $separator \n";
61 print "Input path: $inputpath \n";
62 print "Output path: $outputpath \n";
64 my $localdir = cwd();
66 my $ulffilename = "setupstrings.ulf";
67 my $helpfilename = "helpfilenames.txt";
68 my $defaultlanguage = "en-US";
70 $ulffilename = $inputpath . $separator . $ulffilename;
71 my $ulffile = read_file($ulffilename);
73 my $helpfilenames = read_file($helpfilename);
74 my $allhelpfilenames = collect_helpfile_names($helpfilenames);
76 my $alllanguages = get_all_languages($ulffile);
77 my @allnewpropertyfiles = ();
79 for ( my $i = 0; $i <= $#{$allhelpfilenames}; $i++ )
81 my $helpfilename = ${$allhelpfilenames}[$i];
83 for ( my $j = 0; $j <= $#{$alllanguages}; $j++ )
85 my $language = ${$alllanguages}[$j];
87 # Creating content of help file
88 my $helpfilecontent = collect_helpfile_content($helpfilename, $ulffile, $language);
90 # Saving helpfile
91 my $savefilename = $helpfilename . "_" . $language . ".html";
92 $savefilename = $outputpath . $separator . $savefilename;
93 save_file($savefilename, $helpfilecontent);
95 if ( $language eq $defaultlanguage )
97 $savefilename = $helpfilename . ".html";
98 $savefilename = $outputpath . $separator . $savefilename;
99 save_file($savefilename, $helpfilecontent);
104 exit;
106 sub main::read_directory
108 my ($dir, $ext) = @_;
110 my @content = ();
111 my $direntry;
112 opendir(DIR, $dir);
114 foreach $direntry (readdir (DIR))
116 next if $direntry eq ".";
117 next if $direntry eq "..";
118 next if ( ! ( $direntry =~ /\.\Q$ext\E\s*$/ ));
120 # my $completeentry = $dir . $separator . $direntry;
121 # push(@content, $completeentry);
122 push(@content, $direntry);
125 closedir(DIR);
126 return \@content;
129 sub main::read_file
131 my ($filename) = @_;
133 open( IN, "<$filename" ) || die "cannot open $filename";
134 my @content = <IN>;
135 close( IN );
137 return \@content;
140 sub main::collect_helpfile_content
142 my ($helpfilename, $ulffile, $language) = @_;
144 my @helpfilecontent = ();
145 my $stringhash = create_string_hash($ulffile, $language);
147 # Collecting all strings for one html file.
148 # For "Prologue_de.html" all files need to begin with "STRING_PROLOGUE_X"
149 # The "X" is the ordering number.
151 my $basestring = "STRING_" . uc($helpfilename) . "_";
153 for ( my $i = 0; $i <= 10; $i++ ) # 10 strings possible for each html file
155 my $key = $basestring . $i;
156 if ( exists $stringhash->{$key} )
158 my $content = $stringhash->{$key} . "\n<p>\n";
159 push(@helpfilecontent, $content);
163 return \@helpfilecontent;
166 sub main::collect_helpfile_names
168 my ($helpfilecontent) = @_;
170 my @allhelpfiles = ();
172 for ( my $i = 0; $i <= $#{$helpfilecontent}; $i++ )
174 if ( ${$helpfilecontent}[$i] =~ /^\s*#/ ) { next; } # comment line
175 if ( ${$helpfilecontent}[$i] =~ /^\s*$/ ) { next; } # empty line
176 my $filename = ${$helpfilecontent}[$i];
177 $filename =~ s/\s//g;
178 push(@allhelpfiles, $filename);
181 return \@allhelpfiles;
184 sub main::get_all_languages
186 my ($ulffile) = @_;
188 my @languages = ();
189 my $record = 0;
191 for ( my $i = 0; $i <= $#{$ulffile}; $i++ )
193 if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record )) { last; }
194 if (( ${$ulffile}[$i] =~ /^\s*\[.*]\s*$/ ) && ( $record == 0 )) { $record = 1; }
196 if (( $record ) && ( ${$ulffile}[$i] =~ /^\s*(.+?)\s*\=/ ))
198 $language = $1;
199 push(@languages, $language);
203 my $languagestring = "";
204 for ( my $i = 0; $i <= $#languages; $i++ ) { $languagestring = $languagestring . $languages[$i] . ","; }
205 $languagestring =~ s/,\s*$//;
206 print "Languages: $languagestring\n";
208 return \@languages;
211 sub main::create_string_hash
213 my ($ulffile, $language) = @_;
215 my %stringhash = ();
216 my $key = "";
217 my $value_defined = 0;
219 for ( my $i = 0; $i <= $#{$ulffile}; $i++ )
221 if ( ${$ulffile}[$i] =~ /^\s*\[(.*)\]\s*$/ )
223 $key = $1;
224 $value_defined = 0;
227 if (( ${$ulffile}[$i] =~ /^\s*\Q$defaultlanguage\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined ))
229 $value = $1; # defaulting to english
230 $stringhash{$key} = $value;
233 if (( ${$ulffile}[$i] =~ /^\s*\Q$language\E\s*=\s*\"(.*)\"\s*$/ ) && ( ! $value_defined ))
235 $value = $1;
236 $stringhash{$key} = $value;
237 $value_defined = 1;
241 # additional replacement for ${LANGUAGE}, not defined in ulf file
242 my $languagekey = "LANGUAGE";
243 $stringhash{$languagekey} = $language;
245 # print_hash(\%stringhash);
247 return \%stringhash;
250 sub main::print_hash
252 my ( $hashref ) = @_;
254 print "Hash contains:\n";
256 my $key;
257 foreach $key (keys %{$hashref} ) { print "Key: $key, Value: $hashref->{$key}\n"; }
260 sub main::save_file
262 my ($filename, $filecontent) = @_;
264 if ( open( OUT, ">$filename" ) )
266 print OUT @{$filecontent};
267 close( OUT);
270 push(@allnewpropertyfiles, $filename);
271 print "Created file: $filename\n";