cpmap.pl revision b955672b950093ff7416d1269dd4d3b69983bd8f
af062818b47340eef15700d2f0211576ba3506eevboxsync# Generate code page .c files from ftp.unicode.org descriptions
af062818b47340eef15700d2f0211576ba3506eevboxsync# Copyright 2000 Alexandre Julliard
af062818b47340eef15700d2f0211576ba3506eevboxsync# This library is free software; you can redistribute it and/or
af062818b47340eef15700d2f0211576ba3506eevboxsync# modify it under the terms of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync# License as published by the Free Software Foundation; either
af062818b47340eef15700d2f0211576ba3506eevboxsync# version 2.1 of the License, or (at your option) any later version.
af062818b47340eef15700d2f0211576ba3506eevboxsync# This library is distributed in the hope that it will be useful,
af062818b47340eef15700d2f0211576ba3506eevboxsync# but WITHOUT ANY WARRANTY; without even the implied warranty of
af062818b47340eef15700d2f0211576ba3506eevboxsync# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync# Lesser General Public License for more details.
af062818b47340eef15700d2f0211576ba3506eevboxsync# You should have received a copy of the GNU Lesser General Public
af062818b47340eef15700d2f0211576ba3506eevboxsync# License along with this library; if not, write to the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync# other than GPL or LGPL is available it will apply instead, Sun elects to use only
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync# a choice of LGPL license versions is made available with the language indicating
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync# that LGPLv2 or any later version may be used, or where a choice of which version
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync# of the LGPL is applied is otherwise unspecified.
af062818b47340eef15700d2f0211576ba3506eevboxsync# base directory for ftp.unicode.org files
af062818b47340eef15700d2f0211576ba3506eevboxsync# UnicodeData file
af062818b47340eef15700d2f0211576ba3506eevboxsync$UNICODEDATA = $BASEDIR . "UNIDATA/UnicodeData.txt";
af062818b47340eef15700d2f0211576ba3506eevboxsync# Sort keys file
af062818b47340eef15700d2f0211576ba3506eevboxsync$SORTKEYS = "www.unicode.org/reports/tr10/allkeys.txt";
af062818b47340eef15700d2f0211576ba3506eevboxsync# Defaults mapping
af062818b47340eef15700d2f0211576ba3506eevboxsync# Default char for undefined mappings
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 37, "VENDORS/MICSFT/EBCDIC/CP037.TXT", 0, "IBM EBCDIC US Canada" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 424, "VENDORS/MISC/CP424.TXT", 0, "IBM EBCDIC Hebrew" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 437, "VENDORS/MICSFT/PC/CP437.TXT", 1, "OEM United States" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 500, "VENDORS/MICSFT/EBCDIC/CP500.TXT", 0, "IBM EBCDIC International" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 737, "VENDORS/MICSFT/PC/CP737.TXT", 1, "OEM Greek 437G" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 775, "VENDORS/MICSFT/PC/CP775.TXT", 1, "OEM Baltic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 850, "VENDORS/MICSFT/PC/CP850.TXT", 1, "OEM Multilingual Latin 1" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 852, "VENDORS/MICSFT/PC/CP852.TXT", 1, "OEM Slovak Latin 2" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 855, "VENDORS/MICSFT/PC/CP855.TXT", 1, "OEM Cyrillic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 857, "VENDORS/MICSFT/PC/CP857.TXT", 1, "OEM Turkish" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 860, "VENDORS/MICSFT/PC/CP860.TXT", 1, "OEM Portuguese" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 861, "VENDORS/MICSFT/PC/CP861.TXT", 1, "OEM Icelandic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 862, "VENDORS/MICSFT/PC/CP862.TXT", 1, "OEM Hebrew" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 863, "VENDORS/MICSFT/PC/CP863.TXT", 1, "OEM Canadian French" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 864, "VENDORS/MICSFT/PC/CP864.TXT", 0, "OEM Arabic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 865, "VENDORS/MICSFT/PC/CP865.TXT", 1, "OEM Nordic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 866, "VENDORS/MICSFT/PC/CP866.TXT", 1, "OEM Russian" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 869, "VENDORS/MICSFT/PC/CP869.TXT", 1, "OEM Greek" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 874, "VENDORS/MICSFT/PC/CP874.TXT", 1, "ANSI/OEM Thai" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 875, "VENDORS/MICSFT/EBCDIC/CP875.TXT", 0, "IBM EBCDIC Greek" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 878, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 932, "VENDORS/MICSFT/WINDOWS/CP932.TXT", 0, "ANSI/OEM Japanese Shift-JIS" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 936, "VENDORS/MICSFT/WINDOWS/CP936.TXT", 0, "ANSI/OEM Simplified Chinese GBK" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 949, "VENDORS/MICSFT/WINDOWS/CP949.TXT", 0, "ANSI/OEM Korean Unified Hangul" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 950, "VENDORS/MICSFT/WINDOWS/CP950.TXT", 0, "ANSI/OEM Traditional Chinese Big5" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1006, "VENDORS/MISC/CP1006.TXT", 0, "IBM Arabic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1026, "VENDORS/MICSFT/EBCDIC/CP1026.TXT", 0, "IBM EBCDIC Latin 5 Turkish" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1250, "VENDORS/MICSFT/WINDOWS/CP1250.TXT", 0, "ANSI Eastern Europe" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1251, "VENDORS/MICSFT/WINDOWS/CP1251.TXT", 0, "ANSI Cyrillic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1252, "VENDORS/MICSFT/WINDOWS/CP1252.TXT", 0, "ANSI Latin 1" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1253, "VENDORS/MICSFT/WINDOWS/CP1253.TXT", 0, "ANSI Greek" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1254, "VENDORS/MICSFT/WINDOWS/CP1254.TXT", 0, "ANSI Turkish" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1255, "VENDORS/MICSFT/WINDOWS/CP1255.TXT", 0, "ANSI Hebrew" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1256, "VENDORS/MICSFT/WINDOWS/CP1256.TXT", 0, "ANSI Arabic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1257, "VENDORS/MICSFT/WINDOWS/CP1257.TXT", 0, "ANSI Baltic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1258, "VENDORS/MICSFT/WINDOWS/CP1258.TXT", 0, "ANSI/OEM Viet Nam" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 1361, "OBSOLETE/EASTASIA/KSC/JOHAB.TXT", 0, "Korean Johab" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 10000, "VENDORS/MICSFT/MAC/ROMAN.TXT", 0, "Mac Roman" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 10006, "VENDORS/MICSFT/MAC/GREEK.TXT", 0, "Mac Greek" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 10007, "VENDORS/MICSFT/MAC/CYRILLIC.TXT", 0, "Mac Cyrillic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 10029, "VENDORS/MICSFT/MAC/LATIN2.TXT", 0, "Mac Latin 2" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 10079, "VENDORS/MICSFT/MAC/ICELAND.TXT", 0, "Mac Icelandic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 10081, "VENDORS/MICSFT/MAC/TURKISH.TXT", 0, "Mac Turkish" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 20866, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 20932, "OBSOLETE/EASTASIA/JIS/JIS0208.TXT", 0, "EUC-JP" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 21866, "VENDORS/MISC/KOI8-U.TXT", 0, "Ukrainian KOI8" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28591, "ISO8859/8859-1.TXT", 0, "ISO 8859-1 Latin 1" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28592, "ISO8859/8859-2.TXT", 0, "ISO 8859-2 Latin 2 (East European)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28593, "ISO8859/8859-3.TXT", 0, "ISO 8859-3 Latin 3 (South European)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28594, "ISO8859/8859-4.TXT", 0, "ISO 8859-4 Latin 4 (Baltic old)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28595, "ISO8859/8859-5.TXT", 0, "ISO 8859-5 Cyrillic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28596, "ISO8859/8859-6.TXT", 0, "ISO 8859-6 Arabic" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28597, "ISO8859/8859-7.TXT", 0, "ISO 8859-7 Greek" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28598, "ISO8859/8859-8.TXT", 0, "ISO 8859-8 Hebrew" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28599, "ISO8859/8859-9.TXT", 0, "ISO 8859-9 Latin 5 (Turkish)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28600, "ISO8859/8859-10.TXT", 0, "ISO 8859-10 Latin 6 (Nordic)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
af062818b47340eef15700d2f0211576ba3506eevboxsync [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
af062818b47340eef15700d2f0211576ba3506eevboxsync "Lu" => $ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
af062818b47340eef15700d2f0211576ba3506eevboxsync "Ll" => $ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
af062818b47340eef15700d2f0211576ba3506eevboxsync "Pi" => $ctype{"punct"}, # Punctuation, Initial quote
af062818b47340eef15700d2f0211576ba3506eevboxsync "Pf" => $ctype{"punct"}, # Punctuation, Final quote
af062818b47340eef15700d2f0211576ba3506eevboxsync# a few characters need additional categories that cannot be determined automatically
af062818b47340eef15700d2f0211576ba3506eevboxsync "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
af062818b47340eef15700d2f0211576ba3506eevboxsync "cntrl" => [ 0x070f, 0x180b, 0x180c, 0x180d, 0x180e, 0x200c, 0x200d,
af062818b47340eef15700d2f0211576ba3506eevboxsync 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
af062818b47340eef15700d2f0211576ba3506eevboxsync 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# main routine
af062818b47340eef15700d2f0211576ba3506eevboxsyncforeach $file (@allfiles) { HANDLE_FILE( @$file ); }
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# read in the defaults file
af062818b47340eef15700d2f0211576ba3506eevboxsync # first setup a few default mappings
af062818b47340eef15700d2f0211576ba3506eevboxsync print "Loading $DEFAULTS\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^\#/; # skip comments
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^$/; # skip empty lines
af062818b47340eef15700d2f0211576ba3506eevboxsync if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($#src > 0) { push @unicode_aliases, \@src; }
af062818b47340eef15700d2f0211576ba3506eevboxsync $dst = ($dst =~ /\'.\'/) ? ord substr($dst,1,1) : hex $dst;
af062818b47340eef15700d2f0211576ba3506eevboxsync die "Duplicate value" if defined($unicode_defaults[$src]);
af062818b47340eef15700d2f0211576ba3506eevboxsync die "Unrecognized line $_\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync # now build mappings from the decomposition field of the Unicode database
af062818b47340eef15700d2f0211576ba3506eevboxsync open UNICODEDATA or die "Cannot open $UNICODEDATA";
af062818b47340eef15700d2f0211576ba3506eevboxsync print "Loading $UNICODEDATA\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync # Decode the fields ...
af062818b47340eef15700d2f0211576ba3506eevboxsync $oldname, $comment, $upper, $lower, $title) = split /;/;
af062818b47340eef15700d2f0211576ba3506eevboxsync die "unknown category $cat" unless defined $categories{$cat};
af062818b47340eef15700d2f0211576ba3506eevboxsync die "unknown directionality $bidi" unless defined $directions{$bidi};
af062818b47340eef15700d2f0211576ba3506eevboxsync $category_table[$src] |= $ctype{"upper"}|$ctype{"alpha"};
af062818b47340eef15700d2f0211576ba3506eevboxsync $category_table[$src] |= $ctype{"lower"}|$ctype{"alpha"};
af062818b47340eef15700d2f0211576ba3506eevboxsync # copy the category and direction for everything between First/Last pairs
af062818b47340eef15700d2f0211576ba3506eevboxsync # decomposition of the form "<foo> 1234" -> use char if type is known
af062818b47340eef15700d2f0211576ba3506eevboxsync if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
af062818b47340eef15700d2f0211576ba3506eevboxsync # Single char decomposition in the compatibility range
af062818b47340eef15700d2f0211576ba3506eevboxsync elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
af062818b47340eef15700d2f0211576ba3506eevboxsync # decomposition "<compat> 0020 1234" -> combining accent
af062818b47340eef15700d2f0211576ba3506eevboxsync # decomposition contains only char values without prefix -> use first char
af062818b47340eef15700d2f0211576ba3506eevboxsync # store decomposition if it contains two chars
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
af062818b47340eef15700d2f0211576ba3506eevboxsync elsif ($decomp =~ /^(<[a-z]+>\s)*([0-9a-fA-F]+)$/ &&
af062818b47340eef15700d2f0211576ba3506eevboxsync (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd)))
af062818b47340eef15700d2f0211576ba3506eevboxsync # Single char decomposition in the compatibility range
af062818b47340eef15700d2f0211576ba3506eevboxsync next if defined($unicode_defaults[$src]); # may have been set in the defaults file
af062818b47340eef15700d2f0211576ba3506eevboxsync # check for loops
af062818b47340eef15700d2f0211576ba3506eevboxsync die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
af062818b47340eef15700d2f0211576ba3506eevboxsync last unless defined($unicode_defaults[$i]);
af062818b47340eef15700d2f0211576ba3506eevboxsync # patch the category of some special characters
af062818b47340eef15700d2f0211576ba3506eevboxsync foreach $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# parse the input file
af062818b47340eef15700d2f0211576ba3506eevboxsync my $name = shift;
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^\#/; # skip comments
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^$/; # skip empty lines
af062818b47340eef15700d2f0211576ba3506eevboxsync next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
af062818b47340eef15700d2f0211576ba3506eevboxsync if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
af062818b47340eef15700d2f0211576ba3506eevboxsync die "$name: Unrecognized line $_\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# fill input data for the 20127 (us-ascii) codepage
af062818b47340eef15700d2f0211576ba3506eevboxsync for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
af062818b47340eef15700d2f0211576ba3506eevboxsync for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# get a mapping including glyph chars for MB_USEGLYPHCHARS
af062818b47340eef15700d2f0211576ba3506eevboxsync $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
af062818b47340eef15700d2f0211576ba3506eevboxsync $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# build EUC-JP table from the JIS 0208 file
af062818b47340eef15700d2f0211576ba3506eevboxsync# FIXME: for proper EUC-JP we should probably read JIS 0212 too
af062818b47340eef15700d2f0211576ba3506eevboxsync# but this would require 3-byte DBCS characters
af062818b47340eef15700d2f0211576ba3506eevboxsync my $name = shift;
af062818b47340eef15700d2f0211576ba3506eevboxsync # ASCII chars
af062818b47340eef15700d2f0211576ba3506eevboxsync # JIS X 0201 right plane
af062818b47340eef15700d2f0211576ba3506eevboxsync # lead bytes
af062818b47340eef15700d2f0211576ba3506eevboxsync # undefined chars
af062818b47340eef15700d2f0211576ba3506eevboxsync # Shift-JIS compatibility
af062818b47340eef15700d2f0211576ba3506eevboxsync # Fix backslash conversion
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^\#/; # skip comments
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^$/; # skip empty lines
af062818b47340eef15700d2f0211576ba3506eevboxsync if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
af062818b47340eef15700d2f0211576ba3506eevboxsync die "$name: Unrecognized line $_\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# build the sort keys table
af062818b47340eef15700d2f0211576ba3506eevboxsync for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
af062818b47340eef15700d2f0211576ba3506eevboxsync open INPUT, "$SORTKEYS" or die "Cannot open $SORTKEYS";
af062818b47340eef15700d2f0211576ba3506eevboxsync print "Loading $SORTKEYS\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^\#/; # skip comments
af062818b47340eef15700d2f0211576ba3506eevboxsync next if /^$/; # skip empty lines
af062818b47340eef15700d2f0211576ba3506eevboxsync if (/^([0-9a-fA-F]+)\s+;\s+\[([*.])([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]+)\]/)
af062818b47340eef15700d2f0211576ba3506eevboxsync $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
af062818b47340eef15700d2f0211576ba3506eevboxsync if (/^([0-9a-fA-F]+\s+)+;\s+\[[*.]([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]+)\]/)
af062818b47340eef15700d2f0211576ba3506eevboxsync # multiple character sequence, ignored for now
af062818b47340eef15700d2f0211576ba3506eevboxsync die "$SORTKEYS: Unrecognized line $_\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync # compress the keys to 32 bit:
af062818b47340eef15700d2f0211576ba3506eevboxsync # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
af062818b47340eef15700d2f0211576ba3506eevboxsync $a cmp $b; } @sortkeys;
af062818b47340eef15700d2f0211576ba3506eevboxsync $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# build the sort keys table
af062818b47340eef15700d2f0211576ba3506eevboxsync # count the number of 256-key ranges that contain something
af062818b47340eef15700d2f0211576ba3506eevboxsync for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $keys[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the range offsets
af062818b47340eef15700d2f0211576ba3506eevboxsync open OUTPUT,">collation.c.new" or die "Cannot create collation.c";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf "Building collation.c\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* Unicode collation element table */\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* generated from %s */\n", $SORTKEYS;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const unsigned int collation_table[%d] =\n{\n", $ranges*256;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%08x", 0, @offsets );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the default values
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0, (0xffffffff) x 256 );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output all the key ranges
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT ",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# add default mappings once the file had been read
af062818b47340eef15700d2f0211576ba3506eevboxsync # Apply aliases
af062818b47340eef15700d2f0211576ba3506eevboxsync my $target = undef;
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined($target);
af062818b47340eef15700d2f0211576ba3506eevboxsync # At least one char of the alias set is defined, set the others to the same value
af062818b47340eef15700d2f0211576ba3506eevboxsync $uni2cp[$src] = $target unless defined($uni2cp[$src]);
af062818b47340eef15700d2f0211576ba3506eevboxsync # For every src -> target mapping in the defaults table,
af062818b47340eef15700d2f0211576ba3506eevboxsync # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
af062818b47340eef15700d2f0211576ba3506eevboxsync next if defined($uni2cp[$src]); # source has a definition already
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined($unicode_defaults[$src]); # no default for this char
af062818b47340eef15700d2f0211576ba3506eevboxsync # do a recursive mapping until we find a target char that is defined
af062818b47340eef15700d2f0211576ba3506eevboxsync defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
af062818b47340eef15700d2f0211576ba3506eevboxsync if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
af062818b47340eef15700d2f0211576ba3506eevboxsync # Add an identity mapping for all undefined chars
af062818b47340eef15700d2f0211576ba3506eevboxsync next if defined($cp2uni[$i]);
af062818b47340eef15700d2f0211576ba3506eevboxsync next if defined($uni2cp[$i]);
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump an array of integers
af062818b47340eef15700d2f0211576ba3506eevboxsync $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
af062818b47340eef15700d2f0211576ba3506eevboxsync $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump an SBCS mapping table
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the ascii->unicode table
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const WCHAR cp2uni[512] =\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "{\n%s", DUMP_ARRAY( "0x%04x", $DEF_CHAR, @cp2uni[0 .. 255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync DUMP_ARRAY( "0x%04x", $DEF_CHAR, get_glyphs_mapping(@cp2uni[0 .. 255]) );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const WCHAR cp2uni[256] =\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", $DEF_CHAR, @cp2uni[0 .. 255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync # count the number of unicode->ascii subtables that contain something
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $uni2cp[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # output all the subtables into a single array
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const unsigned char uni2cp_low[%d] =\n{\n", $subtables*256;
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%02x", $DEF_CHAR, @uni2cp[($i<<8) .. ($i<<8)+255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, ($DEF_CHAR) x 256 );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output a table of the offsets of the subtables in the previous array
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($filled[$i]) { push @offsets, $pos; $pos += 256; }
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @offsets );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the code page descriptor
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const struct sbcs_table cptable_%03d =\n{\n", $codepage;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($has_glyphs) { printf OUTPUT " cp2uni + 256,\n"; }
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump a DBCS mapping table
af062818b47340eef15700d2f0211576ba3506eevboxsync my $i, $x, $y;
af062818b47340eef15700d2f0211576ba3506eevboxsync # build a list of lead bytes that are actually used
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the ascii->unicode table for the single byte chars
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "{\n%s,\n", DUMP_ARRAY( "0x%04x", $DEF_CHAR, @cp2uni[0 .. 255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the default table for unused lead bytes
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 0, ($DEF_CHAR) x 256 );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the ascii->unicode table for each DBCS lead byte
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " /* lead byte %02x */\n", $lblist[$y];
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", $DEF_CHAR, @cp2uni[$base .. $base+255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT ($y < $#lblist) ? ",\n" : "\n};\n\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the lead byte subtables offsets
af062818b47340eef15700d2f0211576ba3506eevboxsync for ($x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
af062818b47340eef15700d2f0211576ba3506eevboxsync # increment all lead bytes offset to take into account the unused table
af062818b47340eef15700d2f0211576ba3506eevboxsync for ($x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const unsigned char cp2uni_leadbytes[256] =\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, @offsets );
af062818b47340eef15700d2f0211576ba3506eevboxsync # count the number of unicode->ascii subtables that contain something
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $uni2cp[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # output all the subtables into a single array
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const unsigned short uni2cp_low[%d] =\n{\n", $subtables*256;
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless $filled[$y];
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " /* 0x%02x00 .. 0x%02xff */\n", $y, $y;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", $DEF_CHAR, @uni2cp[($y<<8) .. ($y<<8)+255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, ($DEF_CHAR) x 256 );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output a table of the offsets of the subtables in the previous array
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($filled[$y]) { push @offsets, $pos; $pos += 256; }
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @offsets );
af062818b47340eef15700d2f0211576ba3506eevboxsync # output the code page descriptor
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const struct dbcs_table cptable_%03d =\n{\n", $codepage;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump the list of defined lead byte ranges
af062818b47340eef15700d2f0211576ba3506eevboxsync if (!defined $list[$i]) { printf OUTPUT "0x%02x, ", $i-1; $on = 0; }
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($list[$i]) { printf OUTPUT "0x%02x, ", $i; $on = 1; }
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump the case mapping tables
af062818b47340eef15700d2f0211576ba3506eevboxsync open OUTPUT,">casemap.c.new" or die "Cannot create casemap.c";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf "Building casemap.c\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync DUMP_CASE_TABLE( "wine_casemap_lower", @tolower_table );
af062818b47340eef15700d2f0211576ba3506eevboxsync DUMP_CASE_TABLE( "wine_casemap_upper", @toupper_table );
af062818b47340eef15700d2f0211576ba3506eevboxsync DUMP_CASE_TABLE( "wine_digitmap", @digitmap_table );
af062818b47340eef15700d2f0211576ba3506eevboxsync DUMP_CASE_TABLE( "wine_compatmap", @compatmap_table );
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump a case mapping table
af062818b47340eef15700d2f0211576ba3506eevboxsync # count the number of sub tables that contain something
af062818b47340eef15700d2f0211576ba3506eevboxsync # also compute the low and upper populated bounds
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $table[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync $upperbounds[$index] = 0xff - $lowerbounds[$index];
af062818b47340eef15700d2f0211576ba3506eevboxsync # Collapse blocks upwards if possible
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($upperbounds[$index - 1] > $lowerbounds[$index])
af062818b47340eef15700d2f0211576ba3506eevboxsync # dump the table
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 256, @filled );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 256 );
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT ",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
af062818b47340eef15700d2f0211576ba3506eevboxsync @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump the ctype tables
af062818b47340eef15700d2f0211576ba3506eevboxsync open OUTPUT,">wctype.c.new" or die "Cannot create wctype.c";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf "Building wctype.c\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync # add the direction in the high 4 bits of the category
af062818b47340eef15700d2f0211576ba3506eevboxsync # try to merge table rows
af062818b47340eef15700d2f0211576ba3506eevboxsync my $rowtxt = sprintf "%04x" x 256, @category_table[($row<<8)..($row<<8)+255];
af062818b47340eef15700d2f0211576ba3506eevboxsync # reuse an existing row
af062818b47340eef15700d2f0211576ba3506eevboxsync # create a new row
af062818b47340eef15700d2f0211576ba3506eevboxsync push @array, @category_table[($row<<8)..($row<<8)+255];
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const unsigned short wine_wctype_table[%d] =\n{\n", $#array+1;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# dump the char composition tables
af062818b47340eef15700d2f0211576ba3506eevboxsync open OUTPUT,">compose.c.new" or die "Cannot create compose.c";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf "Building compose.c\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync ######### composition table
af062818b47340eef15700d2f0211576ba3506eevboxsync # count how many different second chars we have
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # build the table of second chars and offsets
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # terminator with last position
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const WCHAR unicode_compose_table[0x%x] =\n{\n", 2*$pos;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT " /* second chars + offsets */\n%s", DUMP_ARRAY( "0x%04x", 0, @table );
af062818b47340eef15700d2f0211576ba3506eevboxsync # build the table of first chars and mappings
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync my @list = sort { $a->[0] <=> $b->[0] } @{$filled[$i]};
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT ",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY( "0x%04x", 0, @table );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "\n};\n\nconst unsigned int unicode_compose_table_size = %d;\n\n", $count;
af062818b47340eef15700d2f0211576ba3506eevboxsync ######### decomposition table
af062818b47340eef15700d2f0211576ba3506eevboxsync # first determine all the 16-char subsets that contain something
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless defined $decomp_table[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # now count the 256-char subsets that contain something
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # add the index offsets to the subsets positions
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync # dump the main index
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "const WCHAR unicode_decompose_table[%d] =\n", $total;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
af062818b47340eef15700d2f0211576ba3506eevboxsync # dump the second-level indexes
af062818b47340eef15700d2f0211576ba3506eevboxsync for ($j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
af062818b47340eef15700d2f0211576ba3506eevboxsync # dump the 16-char subsets
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 32 );
af062818b47340eef15700d2f0211576ba3506eevboxsync next unless $filled[$i];
af062818b47340eef15700d2f0211576ba3506eevboxsync $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
af062818b47340eef15700d2f0211576ba3506eevboxsync $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# read an input file and generate the corresponding .c file
af062818b47340eef15700d2f0211576ba3506eevboxsync my ($codepage,$filename,$has_glyphs,$comment) = @_;
af062818b47340eef15700d2f0211576ba3506eevboxsync # symbol codepage file is special
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($codepage == 20932) { READ_JIS0208_FILE($MAPPREFIX . $filename); }
af062818b47340eef15700d2f0211576ba3506eevboxsync elsif ($codepage == 20127) { fill_20127_codepage(); }
af062818b47340eef15700d2f0211576ba3506eevboxsync # hack: 0x00a5 must map to backslash in Shift-JIS
af062818b47340eef15700d2f0211576ba3506eevboxsync open OUTPUT,">$output.new" or die "Cannot create $output";
af062818b47340eef15700d2f0211576ba3506eevboxsync printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
af062818b47340eef15700d2f0211576ba3506eevboxsync # dump all tables
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* generated from %s */\n", $MAPPREFIX . $filename;
af062818b47340eef15700d2f0211576ba3506eevboxsync printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
af062818b47340eef15700d2f0211576ba3506eevboxsync if ($#lead_bytes == -1) { DUMP_SBCS_TABLE( $codepage, $has_glyphs, $comment ); }
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# save a file if modified
af062818b47340eef15700d2f0211576ba3506eevboxsync my $file = shift;
af062818b47340eef15700d2f0211576ba3506eevboxsync if (-f $file && !system "cmp $file $file.new >/dev/null")
af062818b47340eef15700d2f0211576ba3506eevboxsync unlink "$file.new";
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# output the list of codepage tables into the cptable.c file
af062818b47340eef15700d2f0211576ba3506eevboxsync push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
af062818b47340eef15700d2f0211576ba3506eevboxsync push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
af062818b47340eef15700d2f0211576ba3506eevboxsync push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
af062818b47340eef15700d2f0211576ba3506eevboxsync################################################################
af062818b47340eef15700d2f0211576ba3506eevboxsync# replace the contents of a file between ### cpmap ### marks
af062818b47340eef15700d2f0211576ba3506eevboxsync my $name = shift;
af062818b47340eef15700d2f0211576ba3506eevboxsync last if /\#\#\# cpmap begin \#\#\#/;
af062818b47340eef15700d2f0211576ba3506eevboxsync if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
af062818b47340eef15700d2f0211576ba3506eevboxsync open(FILE,">$name.new") or die "Can't modify $name";