2002-07-11 03:00:44 +00:00
|
|
|
#!/usr/bin/perl
|
2002-12-06 01:40:42 +00:00
|
|
|
# ********************************************************************
|
|
|
|
# * COPYRIGHT:
|
2003-06-03 20:58:22 +00:00
|
|
|
# * Copyright (c) 2002-2003, International Business Machines Corporation and
|
2002-12-06 01:40:42 +00:00
|
|
|
# * others. All Rights Reserved.
|
|
|
|
# ********************************************************************
|
2002-07-11 03:00:44 +00:00
|
|
|
|
|
|
|
# Script to generate the ICULocaleData.jar file. This file is
|
|
|
|
# part of icu4j. It is checked into CVS. It is generated from
|
|
|
|
# locale data in the icu4c project. See usage() notes (below)
|
|
|
|
# for more information.
|
|
|
|
|
2003-04-16 21:36:55 +00:00
|
|
|
# This script requires perl. For Win32, I recommend www.activestate.com.
|
2002-07-11 03:00:44 +00:00
|
|
|
|
|
|
|
# Alan Liu
|
|
|
|
|
2003-04-16 21:36:55 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2002-07-11 03:00:44 +00:00
|
|
|
use File::Path;
|
2002-07-11 03:40:04 +00:00
|
|
|
use File::Copy;
|
2002-07-11 03:00:44 +00:00
|
|
|
|
|
|
|
usage() unless (@ARGV >= 3);
|
|
|
|
my $ICU_ROOT = shift;
|
|
|
|
my $ICU4J_ROOT = shift;
|
|
|
|
my $ldVar = shift;
|
|
|
|
|
|
|
|
# Step 1. Run genrb.
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 1: Run genrb]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
my $genrb = "$ICU_ROOT/source/tools/genrb/genrb";
|
|
|
|
my $dataDir = "$ICU_ROOT/source/data/locales";
|
|
|
|
my $javaRootDir = "$dataDir/java";
|
|
|
|
my $pkg = "com/ibm/icu/impl/data";
|
|
|
|
my $javaDir = "$javaRootDir/$pkg";
|
|
|
|
chdir($dataDir);
|
|
|
|
mkpath($javaDir);
|
|
|
|
my $op = "$ldVar=$ICU_ROOT/source/common:$ICU_ROOT/source/i18n:$ICU_ROOT/source/tools/toolutil:$ICU_ROOT/source/data/out:$ICU_ROOT/source/data: $genrb -s. -d$javaDir -j -p com.ibm.icu.impl.data -b LocaleElements ";
|
2003-04-16 21:36:55 +00:00
|
|
|
print "{Command: $op*.txt}\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
print "Directory: $dataDir\n";
|
|
|
|
my @list;
|
|
|
|
if (@ARGV) {
|
|
|
|
@list = @ARGV;
|
|
|
|
foreach (@list) { $_ .= ".txt" unless (/\.txt$/i); }
|
|
|
|
} else {
|
|
|
|
@list = glob("*.txt");
|
|
|
|
}
|
|
|
|
my $count = 0;
|
|
|
|
my $errCount = 0;
|
|
|
|
foreach (sort @list) {
|
2003-04-16 21:36:55 +00:00
|
|
|
cmd("$op $_", " $_ ");
|
2002-07-11 03:00:44 +00:00
|
|
|
++$count;
|
|
|
|
}
|
|
|
|
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\nProcessed $count locale file(s)\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
|
|
|
|
# Step 2. Create LocaleElements_index.java.
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 2: Create LocaleElements_index.java]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
chdir("$ICU_ROOT/source/data/out/build");
|
|
|
|
cmd("$op res_index.txt");
|
|
|
|
chdir($javaDir);
|
|
|
|
my $f = "LocaleElements_index.java";
|
|
|
|
unlink $f if (-e $f);
|
|
|
|
rename "LocaleElements_res_index.java", $f;
|
|
|
|
patchIndex("LocaleElements_index.java");
|
|
|
|
|
|
|
|
# Step 3. Find %%ALIAS tags.
|
|
|
|
# Assume that it looks like this:
|
|
|
|
# public LocaleElements_no_NO_NY () {
|
|
|
|
# contents = new Object[][] {
|
|
|
|
# {
|
|
|
|
# "%%ALIAS",
|
|
|
|
# "nn_NO",
|
|
|
|
# },
|
|
|
|
# };
|
|
|
|
# }
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 3: Scan for %%ALIAS tags]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
print "Directory: $javaDir\n";
|
|
|
|
chdir($javaDir);
|
|
|
|
@list = glob("LocaleElements*.java");
|
|
|
|
my %aliases;
|
|
|
|
foreach my $file (sort @list) {
|
|
|
|
my $aliasOf = '';
|
|
|
|
open(IN, $file) or die;
|
|
|
|
while (<IN>) {
|
|
|
|
if (/^\s*\"\%\%ALIAS\"/) {
|
|
|
|
# This is an alias of the locale on the next line
|
|
|
|
$aliasOf = <IN>;
|
|
|
|
die "Can't parse $aliasOf" unless
|
|
|
|
($aliasOf =~ s/^\s*\"(.+?)\",\s*$/$1/);
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
|
|
|
|
if ($aliasOf) {
|
|
|
|
my $me = $file;
|
|
|
|
$me =~ s/^LocaleElements_(.+)\.java$/$1/i;
|
|
|
|
$aliases{$me} = $aliasOf;
|
|
|
|
print " $me is an alias of $aliasOf\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Step 4. Fix %%ALIAS tags.
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 4: Fix %%ALIAS tags]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
my %patched; # Record any locales that we patch
|
|
|
|
foreach my $loc (sort keys %aliases) {
|
|
|
|
# $loc is an alias of $aliases{$loc}
|
|
|
|
# Make $loc point to package private static _contents of $aliases{$loc}
|
|
|
|
my $aliasee = $aliases{$loc};
|
2003-04-16 21:36:55 +00:00
|
|
|
if (!exists($patched{$aliasee})) {
|
2002-07-11 03:00:44 +00:00
|
|
|
# Patch the alias
|
2002-07-12 05:18:15 +00:00
|
|
|
#patchAliasee($aliasee);
|
2002-07-11 03:00:44 +00:00
|
|
|
$patched{$aliasee} = 1;
|
|
|
|
}
|
|
|
|
patchAlias($loc, $aliasee);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Step 5. Patch transliteration resources.
|
|
|
|
# ICU resources have TransliterateLATIN but ICU4J resources expect Transliterate_LATIN
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 5: Patch transliteration resources]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
foreach my $file (sort @list) {
|
|
|
|
my $hasTrans = 0;
|
|
|
|
open(IN, $file) or die;
|
|
|
|
while (<IN>) {
|
|
|
|
# Ignore files that are already patched
|
|
|
|
if (/^\s*\"Transliterate[^_].*\"/) {
|
|
|
|
$hasTrans = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
|
|
|
|
patchTrans($file) if ($hasTrans);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Step 6. Compile .java files
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 6: Compile .java files]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
my $cmd = "javac -classpath $ICU4J_ROOT/classes:$javaRootDir:%CLASSPATH% $pkg/*.java";
|
|
|
|
chdir($javaRootDir);
|
|
|
|
print "Directory: $javaRootDir\n";
|
|
|
|
cmd($cmd);
|
|
|
|
|
2003-04-16 23:30:13 +00:00
|
|
|
# Step 7. Update .jar file. Do a "jar u" to update the existing file.
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[Step 7: Update .jar file]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
my $jarFile = "$ICU4J_ROOT/src/$pkg/ICULocaleData.jar";
|
2002-07-16 01:08:21 +00:00
|
|
|
my $filesToBePackaged= "$pkg/*.class $pkg/*.col $pkg/*.brk $pkg/*.utf8";
|
2003-04-16 21:36:55 +00:00
|
|
|
$cmd = "jar uf $jarFile $filesToBePackaged";
|
2002-07-11 03:00:44 +00:00
|
|
|
# Do jar command
|
|
|
|
print "Directory: $javaRootDir\n";
|
|
|
|
chdir($javaRootDir);
|
2002-07-11 03:40:04 +00:00
|
|
|
if(-e "$jarFile"){
|
|
|
|
if (! -e "$jarFile.orig") {
|
|
|
|
copy("$jarFile","$jarFile.orig");
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$jarFile ="$ICU_ROOT/source/data/locales/java/ICULocaleData.jar";
|
2002-07-16 01:08:21 +00:00
|
|
|
$cmd = "jar cvf $jarFile $filesToBePackaged";
|
2002-07-11 03:00:44 +00:00
|
|
|
}
|
2003-04-16 21:36:55 +00:00
|
|
|
cmd($cmd);
|
|
|
|
print " $jarFile updated\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
|
|
|
|
# Done!
|
2003-04-16 21:36:55 +00:00
|
|
|
print "\n[All done]\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
exit(0);
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Execute a command
|
|
|
|
# Param: Command
|
|
|
|
# Param: Display line, or '' to display command
|
|
|
|
sub cmd {
|
|
|
|
my $cmd = shift;
|
|
|
|
my $prompt = shift;
|
2003-04-16 21:36:55 +00:00
|
|
|
if ($prompt) {
|
|
|
|
print $prompt;
|
|
|
|
} else {
|
|
|
|
print "{Command: $cmd}..";
|
|
|
|
}
|
|
|
|
my_system($cmd);
|
2002-07-11 03:00:44 +00:00
|
|
|
my $exit_value = $? >> 8;
|
|
|
|
#my $signal_num = $? & 127;
|
|
|
|
#my $dumped_core = $? & 128;
|
|
|
|
if ($exit_value == 0) {
|
2003-04-16 21:36:55 +00:00
|
|
|
print "ok\n" unless ($prompt);
|
2002-07-11 03:00:44 +00:00
|
|
|
} else {
|
|
|
|
++$errCount;
|
|
|
|
print "ERROR ($exit_value)\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-16 21:36:55 +00:00
|
|
|
# A system()-like sub that does NOT ignore SIGINT
|
|
|
|
sub my_system {
|
|
|
|
my $pid = fork;
|
|
|
|
if (! defined $pid) {
|
|
|
|
return -1;
|
|
|
|
} elsif ($pid) {
|
|
|
|
return waitpid($pid, 0);
|
|
|
|
} else {
|
|
|
|
exec(@_) or exit $!;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-11 03:00:44 +00:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Patch the file that an %%ALIAS tag points to
|
|
|
|
sub patchAliasee {
|
|
|
|
my $loc = shift;
|
|
|
|
my $file = "LocaleElements_$loc.java";
|
|
|
|
my $omitNextBrace = 0;
|
|
|
|
open(IN, $file) or die;
|
|
|
|
open(OUT, ">$file.new") or die;
|
|
|
|
while (<IN>) {
|
2002-07-12 05:18:15 +00:00
|
|
|
#if (/^\s*data\s*=\s*new\s+Object/) {
|
|
|
|
# print OUT " super.contents = data;\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
# print OUT " };\n";
|
2002-07-12 05:18:15 +00:00
|
|
|
# print OUT ' static final Object[][] data =', "\n";
|
2002-07-11 03:00:44 +00:00
|
|
|
# s/^\s*contents\s*=\s*/ /;
|
|
|
|
# print OUT;
|
|
|
|
# } elsif (/^\s*\}\s*;/) {
|
|
|
|
# # Omit the "}" after this
|
|
|
|
# print OUT;
|
|
|
|
# $omitNextBrace = 1;
|
|
|
|
# } elsif ($omitNextBrace && /^\s*\}\s*$/) {
|
|
|
|
# # Omit it
|
|
|
|
# $omitNextBrace = 0;
|
|
|
|
# } else {
|
|
|
|
print OUT;
|
|
|
|
# }
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
close(OUT);
|
|
|
|
unlink($file);
|
|
|
|
rename("$file.new", $file);
|
|
|
|
print " $file patched (aliasee)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Patch the file that contains the %%ALIAS tag
|
|
|
|
sub patchAlias {
|
|
|
|
my $loc = shift;
|
|
|
|
my $aliasee = shift;
|
|
|
|
my $file = "LocaleElements_$loc.java";
|
|
|
|
open(IN, $file) or die;
|
|
|
|
open(OUT, ">$file.new") or die;
|
2002-07-12 05:18:15 +00:00
|
|
|
my $var = "static final Object";
|
2002-07-11 03:00:44 +00:00
|
|
|
while (<IN>) {
|
2002-07-12 05:18:15 +00:00
|
|
|
if(/$var/){
|
|
|
|
# Output our new data
|
|
|
|
print OUT " static final Object[][] data = LocaleElements_$aliasee.data;\n";
|
|
|
|
#consume the next 3 lines
|
2002-07-11 03:00:44 +00:00
|
|
|
<IN>;
|
|
|
|
<IN>;
|
|
|
|
<IN>;
|
2002-07-12 05:18:15 +00:00
|
|
|
<IN>;
|
2002-07-11 03:00:44 +00:00
|
|
|
<IN>;
|
|
|
|
} else {
|
|
|
|
print OUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
close(OUT);
|
|
|
|
unlink($file);
|
|
|
|
rename("$file.new", $file);
|
|
|
|
print " $file patched (alias)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Patch a file with a transliteration resource.
|
|
|
|
sub patchTrans {
|
|
|
|
my $file = shift;
|
|
|
|
open(IN, $file) or die;
|
|
|
|
open(OUT, ">$file.new") or die;
|
|
|
|
while (<IN>) {
|
|
|
|
# This should look like "TransliterateFOO" but if underscores
|
|
|
|
# have crept in, ignore them.
|
|
|
|
s/^(\s*\"Transliterate)_*(.+?\")/$1_$2/;
|
|
|
|
print OUT;
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
close(OUT);
|
|
|
|
unlink($file);
|
|
|
|
rename("$file.new", $file);
|
|
|
|
print " $file patched (trans)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
# Patch the index file, renaming res_index to index
|
|
|
|
sub patchIndex {
|
|
|
|
my $file = shift;
|
|
|
|
open(IN, $file) or die;
|
|
|
|
open(OUT, ">$file.new") or die;
|
|
|
|
while (<IN>) {
|
|
|
|
s/res_(index)/$1/;
|
|
|
|
print OUT;
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
close(OUT);
|
|
|
|
unlink($file);
|
|
|
|
rename("$file.new", $file);
|
|
|
|
print " $file patched (index)\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
sub usage {
|
|
|
|
print << "END";
|
|
|
|
Usage: genrbjar.pl <icu_root_dir> <icu4j_root_dir> <ld_path_variable_name> [<locale>+]
|
|
|
|
|
|
|
|
genrbjar creates the ICULocaleData.jar file in the icu4j project. It
|
|
|
|
uses locale data files in the icu4c directory and processes them with
|
|
|
|
genrb to generate Java source. It makes necessary edits to the Java
|
|
|
|
source, then compiles the Java to .class files, then creates a .jar
|
|
|
|
file. The ICULocaleData.jar file is created in its correct location
|
|
|
|
within the icu4j directory structure.
|
|
|
|
|
|
|
|
Optionally, one or more locales may be specified on the command line.
|
|
|
|
If this is done, only those locales will be processed. If no locales
|
|
|
|
are listed, all locales are processed.
|
|
|
|
|
|
|
|
Before running this tool, a JDK must be installed and the javac and
|
|
|
|
jar binaries for that JDK must be on the system path.
|
|
|
|
e.g:
|
2002-07-11 03:40:04 +00:00
|
|
|
i) on MacOSX: ./genrbjar.pl /Users/build/ICU_MACOSX/icu /Users/build/icu4j DYLD_LIBRARY_PATH
|
2002-07-11 03:00:44 +00:00
|
|
|
ii) on Linux: ./genrbjar.pl /Users/build/ICU_MACOSX/icu /Users/build/icu4j LD_LIBRARY_PATH
|
|
|
|
END
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__END__
|
|
|
|
:endofperl
|