]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/tools/misc/src/com/ibm/icu/dev/tool/translit/genIndexFilters.bat
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / tools / misc / src / com / ibm / icu / dev / tool / translit / genIndexFilters.bat
1 #/**
2 # *******************************************************************************
3 # * Copyright (C) 2002-2004, International Business Machines Corporation and    *
4 # * others. All Rights Reserved.                                                *
5 # *******************************************************************************
6 # */
7 @rem = '--*-Perl-*--
8 @echo off
9 if "%OS%" == "Windows_NT" goto WinNT
10 perl -W -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
11 goto endofperl
12 :WinNT
13 perl -W -x -S "%0" %*
14 if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
15 if %errorlevel% == 9009 echo You do not have Perl in your PATH.
16 goto endofperl
17 @rem ';
18 #!perl
19 #line 14
20
21 # This perl script updates the filters in the transliterator index file.
22 # It does so in a dumb way:
23 #
24 #  Latin-X   NFD lower
25 #  X-Latin   NFD
26 #
27 # For transliterators using NFKD, or not using Lower in this way, you
28 # will have to hand-edit the index file.
29 #
30 # This script writes a new index file.  The new file has to then be
31 # hand-edited and checked before use; it contains comments indicating
32 # old lines that were replaced.
33 #
34 # Alan Liu 11/29/01
35
36 use Getopt::Long;
37
38 my $DIR = "../../text/resources";
39 my $CLASSES = "../../../../../classes";
40
41 #GetOptions('dir=s' => \$DIR,
42 #           'id=s' => \$ID,
43 #           '<>' => \&usage) || die;
44
45 #usage() if (@ARGV);
46
47 #$ID =~ s/-/_/;
48 if (! -d $DIR) {
49     print STDERR "$DIR is not a directory\n";
50     usage();
51 }
52
53 #sub usage {
54 #    my $me = $0;
55 #    $me =~ s|.+[/\\]||;
56 #    print "Usage: $me [-dir <dir>] [-id <id>]\n";
57 #    print " --dir <dir> Specify the directory containing the\n";
58 #    print "             Transliterator_*.txt files\n";
59 #    print " --id <id>   Specify a single ID to transform, e.g.\n";
60 #    print "             Fullwidth-Halfwidth\n";
61 #    die;
62 #}
63
64 convertIndex();
65
66 ######################################################################
67 # Convert the index file from Java to C format
68 # Assume lines are of the form:
69 #   <ID>:alias:<FILTER>;<REMAINDER>
70 # <REMAINDER> can be
71 #   Lower;NFX;...
72 #   NFX;Lower;...
73 #   NFX;...
74 sub convertIndex {
75     $IN = "Transliterator_index.txt";
76     $OUT = "$IN.new";
77     open(IN, "$DIR/$IN") or die;
78     open(OUT, ">$DIR/$OUT") or die;
79     
80     while (<IN>) {
81         # Look for lines that are aliases with NF*
82         if (/^([^:]+):alias:(\[.+?);\s*((NF[^\s]*?)\s*;.+)$/i) {
83             my $id = $1;
84             my $oldset = $2;
85             my $remainder = $3;
86             my $NFXD = $4;
87             my $lower = '';
88             # Check for Lower
89             # If it comes before NF* then adjust accordingly
90             if (/^([^:]+):alias:(\[.+?);\s*(Lower\s*;.+)$/i) {
91                 $lower = 'lower';
92                 if (length($2) < length($oldset)) {
93                     $oldset = $2;
94                     $remainder = $3;
95                 }
96             }
97             print STDERR "$id $NFXD $lower\n";
98             my $set = getSourceSet($id, $NFXD, $lower);
99             $_ = "$id:alias:$set;$remainder\n";
100         }
101         print OUT;
102     }
103
104     close(IN);
105     close(OUT);
106     print STDERR "Wrote $DIR/$OUT\n";
107 }
108
109 ######################################################################
110 # Get the source set (call out to Java), optionally with a closure.
111 sub getSourceSet {
112     my $ID = shift;
113     my $NFXD = shift;
114     my $lower = shift;
115     my $set = `java -classpath $CLASSES com.ibm.tools.translit.genIndexFilters $ID $NFXD $lower`;
116     chomp($set);
117     $set;
118 }
119
120 __END__
121 :endofperl