3
# Copyright (c) 2001-2005, PostgreSQL Global Development Group
5
# $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/UCS_to_cyrillic.pl,v 1.6 2005-01-01 20:44:18 tgl Exp $
7
# Generate UTF-8 <--> ISO8859 code conversion tables from
8
# map files provided by Unicode organization.
9
# Unfortunately it is prohibited by the organization
10
# to distribute the map files. So if you try to use this script,
11
# you have to obtain "8859-[2-5].TXT" from the organization's ftp site.
12
# We assume the file include three tab-separated columns:
13
# ISO/IEC 8859 code in hex
15
# # and Unicode name (not used in this script)
18
%filename = ('KOI8R'=>'koi8-r.txt',
19
'WIN1251'=>'cp1251.txt',
21
@charsets = ('KOI8R','ALT','WIN1251');
22
foreach $charset (@charsets) {
25
# first, generate UTF8->ISO8859 table
27
$in_file = $filename{$charset};
29
open( FILE, $in_file ) || die( "cannot open $in_file" );
38
( $c, $u, $rest ) = split;
42
$utf = &ucs2utf($ucs);
43
if( $array{ $utf } ne "" ){
44
printf STDERR "Warning: duplicate unicode: %04x\n",$ucs;
48
$array{ $utf } = $code;
53
$file = "utf8_to_${charset}.map";
54
open( FILE, "> $file" ) || die( "cannot open $file" );
55
print FILE "static pg_utf_to_local ULmap_${charset}[ $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 ISO885->UTF8 table
73
open( FILE, $in_file ) || die( "cannot open $in_file" );
82
( $c, $u, $rest ) = split;
86
$utf = &ucs2utf($ucs);
87
if( $array{ $utf } ne "" ){
88
printf STDERR "Warning: duplicate unicode: %04x\n",$ucs;
92
$array{ $code } = $utf;
97
$file = "${charset}_to_utf8.map";
98
open( FILE, "> $file" ) || die( "cannot open $file" );
99
print FILE "static pg_local_to_utf LUmap${charset}[ $count ] = {\n";
100
for $index ( sort {$a <=> $b} keys( %array ) ){
101
$utf = $array{ $index };
104
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
106
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;