3
# Copyright (c) 2001-2005, PostgreSQL Global Development Group
5
# $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/UCS_to_GBK.pl,v 1.5 2005-01-01 20:44:18 tgl Exp $
8
# Generate UTF-8 <--> GBK code conversion tables from
9
# map files provided by Unicode organization.
10
# Unfortunately it is prohibited by the organization
11
# to distribute the map files. So if you try to use this script,
12
# you have to obtain CP936.TXT from
13
# the organization's ftp site.
18
# # and Unicode name (not used in this script)
22
# first generate UTF-8 --> GBK table
24
$in_file = "CP936.TXT";
26
open( FILE, $in_file ) || die( "cannot open $in_file" );
33
( $c, $u, $rest ) = split;
36
if( $code >= 0x80 && $ucs >= 0x0080 ){
37
$utf = &ucs2utf($ucs);
38
if( $array{ $utf } ne "" ){
39
printf STDERR "Warning: duplicate unicode: %04x\n",$ucs;
44
$array{ $utf } = $code;
50
# first, generate UTF8 --> WIN949 table
53
$file = "utf8_to_gbk.map";
54
open( FILE, "> $file" ) || die( "cannot open $file" );
55
print FILE "static pg_utf_to_local ULmapGBK[ $count ] = {\n";
57
for $index ( sort {$a <=> $b} keys( %array ) ){
58
$code = $array{ $index };
61
printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
63
printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
71
# then generate WIN936 --> UTF8 table
75
open( FILE, $in_file ) || die( "cannot open $in_file" );
82
( $c, $u, $rest ) = split;
85
if( $code >= 0x80 && $ucs >= 0x0080 ){
86
$utf = &ucs2utf($ucs);
87
if( $array{ $code } ne "" ){
88
printf STDERR "Warning: duplicate code: %04x\n",$ucs;
93
$array{ $code } = $utf;
98
$file = "gbk_to_utf8.map";
99
open( FILE, "> $file" ) || die( "cannot open $file" );
100
print FILE "static pg_local_to_utf LUmapGBK[ $count ] = {\n";
101
for $index ( sort {$a <=> $b} keys( %array ) ){
102
$utf = $array{ $index };
105
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
107
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;