Skip to content

Commit

Permalink
unicode: Generate nls files for the codepage tables.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Julliard <[email protected]>
  • Loading branch information
julliard committed Feb 11, 2020
1 parent 42a30a6 commit fb316c3
Show file tree
Hide file tree
Showing 70 changed files with 217 additions and 97 deletions.
93 changes: 1 addition & 92 deletions dlls/ntdll/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,88 +432,6 @@ static NTSTATUS open_nls_data_file( ULONG type, ULONG id, HANDLE *file )
}


static USHORT *build_cptable( const union cptable *src, SIZE_T *size )
{
unsigned int i, leadbytes = 0;
USHORT *data, *ptr;

*size = 13 + 1 + 256 + 1 + 1 + 1;
if (src->info.char_size == 2)
{
for (i = leadbytes = 0; i < 256; i++) if (src->dbcs.cp2uni_leadbytes[i]) leadbytes++;
*size += 256 + 256 * leadbytes;
*size += 65536;
*size *= sizeof(USHORT);
}
else
{
if (src->sbcs.cp2uni_glyphs != src->sbcs.cp2uni) *size += 256;
*size *= sizeof(USHORT);
*size += 65536;
}
if (!(data = RtlAllocateHeap( GetProcessHeap(), 0, *size ))) return NULL;
ptr = data;
ptr[0] = 0x0d;
ptr[1] = src->info.codepage;
ptr[2] = src->info.char_size;
ptr[3] = (src->info.def_char & 0xff00 ?
RtlUshortByteSwap( src->info.def_char ) : src->info.def_char);
ptr[4] = src->info.def_unicode_char;

if (src->info.char_size == 2)
{
USHORT off = src->dbcs.cp2uni_leadbytes[src->info.def_char >> 8] * 256;
ptr[5] = src->dbcs.cp2uni[off + (src->info.def_char & 0xff)];

ptr[6] = src->dbcs.uni2cp_low[src->dbcs.uni2cp_high[src->info.def_unicode_char >> 8]
+ (src->info.def_unicode_char & 0xff)];

ptr += 7;
memcpy( ptr, src->dbcs.lead_bytes, 12 );
ptr += 6;
*ptr++ = 256 + 3 + (leadbytes + 1) * 256;
for (i = 0; i < 256; i++) *ptr++ = (src->dbcs.cp2uni_leadbytes[i] ? 0 : src->dbcs.cp2uni[i]);
*ptr++ = 0;
for (i = 0; i < 12; i++) if (!src->dbcs.lead_bytes[i]) break;
*ptr++ = i / 2;
for (i = 0; i < 256; i++) *ptr++ = 256 * src->dbcs.cp2uni_leadbytes[i];
for (i = 0; i < leadbytes; i++, ptr += 256)
memcpy( ptr, src->dbcs.cp2uni + 256 * (i + 1), 256 * sizeof(USHORT) );
*ptr++ = 4;
for (i = 0; i < 65536; i++)
ptr[i] = src->dbcs.uni2cp_low[src->dbcs.uni2cp_high[i >> 8] + (i & 0xff)];
}
else
{
char *uni2cp;

ptr[5] = src->sbcs.cp2uni[src->info.def_char];
ptr[6] = src->sbcs.uni2cp_low[src->sbcs.uni2cp_high[src->info.def_unicode_char >> 8]
+ (src->info.def_unicode_char & 0xff)];

ptr += 7;
memset( ptr, 0, 12 );
ptr += 6;
*ptr++ = 256 + 3 + (src->sbcs.cp2uni_glyphs != src->sbcs.cp2uni ? 256 : 0);
memcpy( ptr, src->sbcs.cp2uni, 256 * sizeof(USHORT) );
ptr += 256;
if (src->sbcs.cp2uni_glyphs != src->sbcs.cp2uni)
{
*ptr++ = 256;
memcpy( ptr, src->sbcs.cp2uni_glyphs, 256 * sizeof(USHORT) );
ptr += 256;
}
else *ptr++ = 0;
*ptr++ = 0;
*ptr++ = 0;
uni2cp = (char *)ptr;
for (i = 0; i < 65536; i++)
uni2cp[i] = src->sbcs.uni2cp_low[src->sbcs.uni2cp_high[i >> 8] + (i & 0xff)];
}
return data;
}


#if !defined(__APPLE__) && !defined(__ANDROID__) /* these platforms always use UTF-8 */

/* charset to codepage map, sorted by name */
Expand Down Expand Up @@ -896,16 +814,7 @@ NTSTATUS WINAPI NtGetNlsSectionPtr( ULONG type, ULONG id, void *unknown, void **
HANDLE file;
NTSTATUS status;

if ((status = open_nls_data_file( type, id, &file )))
{
/* FIXME: special case for codepage table, generate it from the libwine data */
if (type == NLS_SECTION_CODEPAGE)
{
const union cptable *table = wine_cp_get_table( id );
if (table && (*ptr = build_cptable( table, size ))) return STATUS_SUCCESS;
}
return status;
}
if ((status = open_nls_data_file( type, id, &file ))) return status;

if ((status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileEndOfFileInformation )))
goto done;
Expand Down
65 changes: 65 additions & 0 deletions loader/wine.inf.in
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,71 @@ winebus.inf
winehid.inf

[NlsFiles]
c_037.nls
c_10000.nls
c_10001.nls
c_10002.nls
c_10003.nls
c_10004.nls
c_10005.nls
c_10006.nls
c_10007.nls
c_10008.nls
c_10010.nls
c_10017.nls
c_10021.nls
c_10029.nls
c_10079.nls
c_10081.nls
c_10082.nls
c_1026.nls
c_1250.nls
c_1251.nls
c_1252.nls
c_1253.nls
c_1254.nls
c_1255.nls
c_1256.nls
c_1257.nls
c_1258.nls
c_1361.nls
c_20127.nls
c_20866.nls
c_20932.nls
c_21866.nls
c_28591.nls
c_28592.nls
c_28593.nls
c_28594.nls
c_28595.nls
c_28596.nls
c_28597.nls
c_28598.nls
c_28599.nls
c_28603.nls
c_28605.nls
c_437.nls
c_500.nls
c_737.nls
c_775.nls
c_850.nls
c_852.nls
c_855.nls
c_857.nls
c_860.nls
c_861.nls
c_862.nls
c_863.nls
c_864.nls
c_865.nls
c_866.nls
c_869.nls
c_874.nls
c_875.nls
c_932.nls
c_936.nls
c_949.nls
c_950.nls
l_intl.nls

[WineSourceDirs]
Expand Down
65 changes: 65 additions & 0 deletions nls/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
SOURCES = \
c_037.nls \
c_10000.nls \
c_10001.nls \
c_10002.nls \
c_10003.nls \
c_10004.nls \
c_10005.nls \
c_10006.nls \
c_10007.nls \
c_10008.nls \
c_10010.nls \
c_10017.nls \
c_10021.nls \
c_10029.nls \
c_10079.nls \
c_10081.nls \
c_10082.nls \
c_1026.nls \
c_1250.nls \
c_1251.nls \
c_1252.nls \
c_1253.nls \
c_1254.nls \
c_1255.nls \
c_1256.nls \
c_1257.nls \
c_1258.nls \
c_1361.nls \
c_20127.nls \
c_20866.nls \
c_20932.nls \
c_21866.nls \
c_28591.nls \
c_28592.nls \
c_28593.nls \
c_28594.nls \
c_28595.nls \
c_28596.nls \
c_28597.nls \
c_28598.nls \
c_28599.nls \
c_28603.nls \
c_28605.nls \
c_437.nls \
c_500.nls \
c_737.nls \
c_775.nls \
c_850.nls \
c_852.nls \
c_855.nls \
c_857.nls \
c_860.nls \
c_861.nls \
c_862.nls \
c_863.nls \
c_864.nls \
c_865.nls \
c_866.nls \
c_869.nls \
c_874.nls \
c_875.nls \
c_932.nls \
c_936.nls \
c_949.nls \
c_950.nls \
l_intl.nls
Binary file added nls/c_037.nls
Binary file not shown.
Binary file added nls/c_10000.nls
Binary file not shown.
Binary file added nls/c_10001.nls
Binary file not shown.
Binary file added nls/c_10002.nls
Binary file not shown.
Binary file added nls/c_10003.nls
Binary file not shown.
Binary file added nls/c_10004.nls
Binary file not shown.
Binary file added nls/c_10005.nls
Binary file not shown.
Binary file added nls/c_10006.nls
Binary file not shown.
Binary file added nls/c_10007.nls
Binary file not shown.
Binary file added nls/c_10008.nls
Binary file not shown.
Binary file added nls/c_10010.nls
Binary file not shown.
Binary file added nls/c_10017.nls
Binary file not shown.
Binary file added nls/c_10021.nls
Binary file not shown.
Binary file added nls/c_10029.nls
Binary file not shown.
Binary file added nls/c_10079.nls
Binary file not shown.
Binary file added nls/c_10081.nls
Binary file not shown.
Binary file added nls/c_10082.nls
Binary file not shown.
Binary file added nls/c_1026.nls
Binary file not shown.
Binary file added nls/c_1250.nls
Binary file not shown.
Binary file added nls/c_1251.nls
Binary file not shown.
Binary file added nls/c_1252.nls
Binary file not shown.
Binary file added nls/c_1253.nls
Binary file not shown.
Binary file added nls/c_1254.nls
Binary file not shown.
Binary file added nls/c_1255.nls
Binary file not shown.
Binary file added nls/c_1256.nls
Binary file not shown.
Binary file added nls/c_1257.nls
Binary file not shown.
Binary file added nls/c_1258.nls
Binary file not shown.
Binary file added nls/c_1361.nls
Binary file not shown.
Binary file added nls/c_20127.nls
Binary file not shown.
Binary file added nls/c_20866.nls
Binary file not shown.
Binary file added nls/c_20932.nls
Binary file not shown.
Binary file added nls/c_21866.nls
Binary file not shown.
Binary file added nls/c_28591.nls
Binary file not shown.
Binary file added nls/c_28592.nls
Binary file not shown.
Binary file added nls/c_28593.nls
Binary file not shown.
Binary file added nls/c_28594.nls
Binary file not shown.
Binary file added nls/c_28595.nls
Binary file not shown.
Binary file added nls/c_28596.nls
Binary file not shown.
Binary file added nls/c_28597.nls
Binary file not shown.
Binary file added nls/c_28598.nls
Binary file not shown.
Binary file added nls/c_28599.nls
Binary file not shown.
Binary file added nls/c_28603.nls
Binary file not shown.
Binary file added nls/c_28605.nls
Binary file not shown.
Binary file added nls/c_437.nls
Binary file not shown.
Binary file added nls/c_500.nls
Binary file not shown.
Binary file added nls/c_737.nls
Binary file not shown.
Binary file added nls/c_775.nls
Binary file not shown.
Binary file added nls/c_850.nls
Binary file not shown.
Binary file added nls/c_852.nls
Binary file not shown.
Binary file added nls/c_855.nls
Binary file not shown.
Binary file added nls/c_857.nls
Binary file not shown.
Binary file added nls/c_860.nls
Binary file not shown.
Binary file added nls/c_861.nls
Binary file not shown.
Binary file added nls/c_862.nls
Binary file not shown.
Binary file added nls/c_863.nls
Binary file not shown.
Binary file added nls/c_864.nls
Binary file not shown.
Binary file added nls/c_865.nls
Binary file not shown.
Binary file added nls/c_866.nls
Binary file not shown.
Binary file added nls/c_869.nls
Binary file not shown.
Binary file added nls/c_874.nls
Binary file not shown.
Binary file added nls/c_875.nls
Binary file not shown.
Binary file added nls/c_932.nls
Binary file not shown.
Binary file added nls/c_936.nls
Binary file not shown.
Binary file added nls/c_949.nls
Binary file not shown.
Binary file added nls/c_950.nls
Binary file not shown.
13 changes: 10 additions & 3 deletions tools/make_makefiles
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,17 @@ sub update_makefiles(@)

sub update_wine_inf()
{
my @lines;

push @lines, "[NlsFiles]", @nls_files, "\n";
my @lines = ("[NlsFiles]", @nls_files, "\n" );
replace_in_file "loader/wine.inf.in", '^\[NlsFiles\]', '^$', join( "\n", @lines );

my @codepages = grep /c_\d+\.nls/, @nls_files;
@lines = ( "[Nls]" );
foreach my $cp (sort { $a <=> $b; } map { /c_(\d+)\.nls/ && $1; } @codepages)
{
push @lines, sprintf "HKLM,System\\CurrentControlSet\\Control\\Nls\\Codepage,\"%u\",,\"c_%03u.nls\"", $cp, $cp;
}
push @lines, "\n";
replace_in_file "loader/wine.inf.in", '^\[Nls\]', '^$', join( "\n", @lines );
}

my $git_dir = $ENV{GIT_DIR} || ".git";
Expand Down
78 changes: 76 additions & 2 deletions tools/make_unicode
Original file line number Diff line number Diff line change
Expand Up @@ -1054,14 +1054,76 @@ sub dump_dbcs_table($$$$@)
}


################################################################
# dump an SBCS mapping table in binary format
sub dump_binary_sbcs_table($)
{
my $codepage = shift;

my @header = ( 13, $codepage, 1, $default_char, $default_wchar, $cp2uni[$default_char], $uni2cp[$default_wchar] );
my $wc_offset = 256 + 3 + (@glyph2uni ? 256 : 0);

print OUTPUT pack "S<*", @header;
print OUTPUT pack "C12", (0) x 12;
print OUTPUT pack "S<*", $wc_offset, map { $_ || 0; } @cp2uni[0 .. 255];

if (@glyph2uni)
{
print OUTPUT pack "S<*", 256, get_glyphs_mapping(@cp2uni[0 .. 255]);
}
else
{
print OUTPUT pack "S<*", 0;
}

print OUTPUT pack "S<*", 0, 0;

print OUTPUT pack "C*", map { defined $_ ? $_ : $default_char; } @uni2cp[0 .. 65535];
}


################################################################
# dump a DBCS mapping table in binary format
sub dump_binary_dbcs_table($)
{
my $codepage = shift;
my @lb_ranges = get_lb_ranges();
my @header = ( 13, $codepage, 2, $default_char, $default_wchar, $cp2uni[$default_char], $uni2cp[$default_wchar] );

my @offsets = (0) x 256;
my $pos = 0;
foreach my $i (@lead_bytes)
{
$offsets[$i] = ($pos += 256);
$cp2uni[$i] = 0;
}

my $wc_offset = 256 + 3 + 256 * (1 + scalar @lead_bytes);

print OUTPUT pack "S<*", @header;
print OUTPUT pack "C12", @lb_ranges, 0 x 12;
print OUTPUT pack "S<*", $wc_offset, map { $_ || 0; } @cp2uni[0 .. 255];
print OUTPUT pack "S<*", 0, scalar @lb_ranges / 2, @offsets;

foreach my $i (@lead_bytes)
{
my $base = $i << 8;
print OUTPUT pack "S<*", map { defined $_ ? $_ : $default_wchar; } @cp2uni[$base .. $base + 255];
}

print OUTPUT pack "S<", 4;
print OUTPUT pack "S<*", map { defined $_ ? $_ : $default_char; } @uni2cp[0 .. 65535];
}


################################################################
# get the list of defined lead byte ranges
sub get_lb_ranges()
{
my @list = ();
my @ranges = ();
my $i = 0;
foreach $i (@lead_bytes) { $list[$i] = 1; }

foreach my $i (@lead_bytes) { $list[$i] = 1; }
my $on = 0;
for (my $i = 0; $i < 256; $i++)
{
Expand Down Expand Up @@ -2350,6 +2412,18 @@ sub output_codepage_file($$$)
else { dump_dbcs_table( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges() ); }
close OUTPUT;
save_file($output);

# same thing in binary format

$output = sprintf "nls/c_%03d.nls", $codepage;
open OUTPUT,">$output.new" or die "Cannot create $output";

printf "Building %s\n", $output;
if (!@lead_bytes) { dump_binary_sbcs_table( $codepage ); }
else { dump_binary_dbcs_table( $codepage ); }

close OUTPUT;
save_file($output);
}

################################################################
Expand Down

0 comments on commit fb316c3

Please sign in to comment.