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