]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/tools/misc/src/com/ibm/icu/dev/tool/translit/varsub.bat
go
[Dictionary.git] / jars / icu4j-4_4_2-src / tools / misc / src / com / ibm / icu / dev / tool / translit / varsub.bat
1 #/**\r
2 # *******************************************************************************\r
3 # * Copyright (C) 2001-2004, International Business Machines Corporation and    *\r
4 # * others. All Rights Reserved.                                                *\r
5 # *******************************************************************************\r
6 # */\r
7 \r
8 @rem = '--*-Perl-*--\r
9 @echo off\r
10 if "%OS%" == "Windows_NT" goto WinNT\r
11 perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9\r
12 goto endofperl\r
13 :WinNT\r
14 perl -x -S "%0" %*\r
15 if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl\r
16 if %errorlevel% == 9009 echo You do not have Perl in your PATH.\r
17 goto endofperl\r
18 @rem ';\r
19 #!perl\r
20 #line 14\r
21 \r
22 # Usage: perl varsub.bat [-n|-nr] <infile> <outfile>\r
23 #\r
24 # Substitutes variables into rules and deletes variable definition\r
25 # statements.  Variables that expand to UnicodeSets are NOT\r
26 # substituted.\r
27 #\r
28 #  -n   Afterwards, run native2ascii -encoding UTF8\r
29 #  -nr  Afterwards, run native2ascii -encoding UTF8 -reverse\r
30 \r
31 $N2A = 0;\r
32 \r
33 $IN = shift;\r
34 if ($IN =~ /^-n/) {\r
35     $N2A = 1;\r
36     $N2Aoption = ($IN eq '-nr') ? " -reverse " : "";\r
37     $IN = shift;\r
38 }\r
39 $OUT = shift;\r
40 \r
41 if (!($IN && $OUT)) {\r
42     die "Usage: $0 [-n|-nr] <infile> <outfile>";\r
43 }\r
44 \r
45 open(IN) or die "Can't open $IN: $!";\r
46 open(OUT, ">$OUT") or die "Can't open $OUT: $!";\r
47 \r
48 while (<IN>) {\r
49     if (/^\s*\$([a-zA-Z0-9_]+)\s*=\s*([^;\#]+)\s*;\s*(\#.*)?$/) {\r
50         # This looks like a variable definition\r
51         my ($var, $def) = ($1, $2);\r
52         # Don't substitute UnicodeSet vars\r
53         if ($def !~ /^\[/) {\r
54             if (exists $VAR{$var}) {\r
55                 print STDERR "Error: Duplicate definition of $var\n";\r
56             } else {\r
57                 $VAR{$var} = $def;\r
58             }\r
59             next;\r
60         }\r
61     }\r
62     \r
63     # Do variable substitutions, and output line\r
64     foreach my $var (keys %VAR) {\r
65         my $def = $VAR{$var};\r
66         s/\$$var\b/$def/g;\r
67     }\r
68     print OUT;\r
69 }\r
70 \r
71 close(OUT);\r
72 close(IN);\r
73 \r
74 if ($N2A) {\r
75     `native2ascii -encoding UTF8 $N2Aoption $OUT $OUT.native2ascii`;\r
76     unlink $OUT;\r
77     rename "$OUT.native2ascii", $OUT;\r
78 }\r
79 \r
80 __END__\r
81 :endofperl\r