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