3
# Copyright (c) 2001-2011, PostgreSQL Global Development Group
5
# src/backend/utils/mb/Unicode/UCS_to_most.pl
7
# Generate UTF-8 <--> character 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 the map files from the organization's ftp site.
12
# ftp://www.unicode.org/Public/MAPPINGS/
13
# We assume the file include three tab-separated columns:
14
# source character set code in hex
16
# # and Unicode name (not used in this script)
21
'WIN866' => 'CP866.TXT',
22
'WIN874' => 'CP874.TXT',
23
'WIN1250' => 'CP1250.TXT',
24
'WIN1251' => 'CP1251.TXT',
25
'WIN1252' => 'CP1252.TXT',
26
'WIN1253' => 'CP1253.TXT',
27
'WIN1254' => 'CP1254.TXT',
28
'WIN1255' => 'CP1255.TXT',
29
'WIN1256' => 'CP1256.TXT',
30
'WIN1257' => 'CP1257.TXT',
31
'WIN1258' => 'CP1258.TXT',
32
'ISO8859_2' => '8859-2.TXT',
33
'ISO8859_3' => '8859-3.TXT',
34
'ISO8859_4' => '8859-4.TXT',
35
'ISO8859_5' => '8859-5.TXT',
36
'ISO8859_6' => '8859-6.TXT',
37
'ISO8859_7' => '8859-7.TXT',
38
'ISO8859_8' => '8859-8.TXT',
39
'ISO8859_9' => '8859-9.TXT',
40
'ISO8859_10' => '8859-10.TXT',
41
'ISO8859_13' => '8859-13.TXT',
42
'ISO8859_14' => '8859-14.TXT',
43
'ISO8859_15' => '8859-15.TXT',
44
'ISO8859_16' => '8859-16.TXT',
45
'KOI8R' => 'KOI8-R.TXT',
46
'KOI8U' => 'KOI8-U.TXT',
49
'JOHAB' => 'JOHAB.TXT',
52
@charsets = keys(filename);
53
@charsets = @ARGV if scalar(@ARGV);
54
foreach $charset (@charsets) {
57
# first, generate UTF8-> charset table
59
$in_file = $filename{$charset};
61
open( FILE, $in_file ) || die( "cannot open $in_file" );
70
( $c, $u, $rest ) = split;
73
if( $code >= 0x80 && $ucs >= 0x0080){
74
$utf = &ucs2utf($ucs);
75
if( $array{ $utf } ne "" ){
76
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs;
80
$array{ $utf } = $code;
85
$file = lc("utf8_to_${charset}.map");
86
open( FILE, "> $file" ) || die( "cannot open $file" );
87
print FILE "static pg_utf_to_local ULmap${charset}[ $count ] = {\n";
89
for $index ( sort {$a <=> $b} keys( %array ) ){
90
$code = $array{ $index };
93
printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
95
printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
103
# then generate character set code ->UTF8 table
105
open( FILE, $in_file ) || die( "cannot open $in_file" );
114
( $c, $u, $rest ) = split;
117
if($code >= 0x80 && $ucs >= 0x0080){
118
$utf = &ucs2utf($ucs);
119
if( $array{ $code } ne "" ){
120
printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs;
124
$array{ $code } = $utf;
129
$file = lc("${charset}_to_utf8.map");
130
open( FILE, "> $file" ) || die( "cannot open $file" );
131
print FILE "static pg_local_to_utf LUmap${charset}[ $count ] = {\n";
132
for $index ( sort {$a <=> $b} keys( %array ) ){
133
$utf = $array{ $index };
136
printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
138
printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;