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