~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/perl
 
2
#
 
3
# Copyright (c) 2001-2011, PostgreSQL Global Development Group
 
4
#
 
5
# src/backend/utils/mb/Unicode/UCS_to_EUC_KR.pl
 
6
#
 
7
# Generate UTF-8 <--> EUC_KR 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 OLD5601.TXT from
 
12
# the organization's ftp site.
 
13
#
 
14
# OLD5601.TXT format:
 
15
#                KSC5601 code in hex
 
16
#                UCS-2 code in hex
 
17
#                # and Unicode name (not used in this script)
 
18
 
 
19
require "ucs2utf.pl";
 
20
 
 
21
# first generate UTF-8 --> EUC_KR table
 
22
 
 
23
$in_file = "KSX1001.TXT";
 
24
 
 
25
open( FILE, $in_file ) || die( "cannot open $in_file" );
 
26
 
 
27
while( <FILE> ){
 
28
        chop;
 
29
        if( /^#/ ){
 
30
                next;
 
31
        }
 
32
        ( $c, $u, $rest ) = split;
 
33
        $ucs = hex($u);
 
34
        $code = hex($c);
 
35
        if( $code >= 0x80 && $ucs >= 0x0080 ){
 
36
                $utf = &ucs2utf($ucs);
 
37
                if( $array{ $utf } ne "" ){
 
38
                        printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs;
 
39
                        next;
 
40
                }
 
41
                $count++;
 
42
 
 
43
                $array{ $utf } = ($code | 0x8080);
 
44
        }
 
45
}
 
46
close( FILE );
 
47
 
 
48
#
 
49
# first, generate UTF8 --> EUC_KR table
 
50
#
 
51
 
 
52
$file = "utf8_to_euc_kr.map";
 
53
open( FILE, "> $file" ) || die( "cannot open $file" );
 
54
print FILE "static pg_utf_to_local ULmapEUC_KR[ $count ] = {\n";
 
55
 
 
56
for $index ( sort {$a <=> $b} keys( %array ) ){
 
57
        $code = $array{ $index };
 
58
        $count--;
 
59
        if( $count == 0 ){
 
60
                printf FILE "  {0x%04x, 0x%04x}\n", $index, $code;
 
61
        } else {
 
62
                printf FILE "  {0x%04x, 0x%04x},\n", $index, $code;
 
63
        }
 
64
}
 
65
 
 
66
print FILE "};\n";
 
67
close(FILE);
 
68
 
 
69
#
 
70
# then generate EUC_JP --> UTF8 table
 
71
#
 
72
reset 'array';
 
73
 
 
74
open( FILE, $in_file ) || die( "cannot open $in_file" );
 
75
 
 
76
while( <FILE> ){
 
77
        chop;
 
78
        if( /^#/ ){
 
79
                next;
 
80
        }
 
81
        ( $c, $u, $rest ) = split;
 
82
        $ucs = hex($u);
 
83
        $code = hex($c);
 
84
        if( $code >= 0x80 && $ucs >= 0x0080 ){
 
85
                $utf = &ucs2utf($ucs);
 
86
                if( $array{ $code } ne "" ){
 
87
                        printf STDERR "Warning: duplicate code: %04x\n",$ucs;
 
88
                        next;
 
89
                }
 
90
                $count++;
 
91
 
 
92
                $code |= 0x8080;
 
93
                $array{ $code } = $utf;
 
94
        }
 
95
}
 
96
close( FILE );
 
97
 
 
98
$file = "euc_kr_to_utf8.map";
 
99
open( FILE, "> $file" ) || die( "cannot open $file" );
 
100
print FILE "static pg_local_to_utf LUmapEUC_KR[ $count ] = {\n";
 
101
for $index ( sort {$a <=> $b} keys( %array ) ){
 
102
        $utf = $array{ $index };
 
103
        $count--;
 
104
        if( $count == 0 ){
 
105
                printf FILE "  {0x%04x, 0x%04x}\n", $index, $utf;
 
106
        } else {
 
107
                printf FILE "  {0x%04x, 0x%04x},\n", $index, $utf;
 
108
        }
 
109
}
 
110
 
 
111
print FILE "};\n";
 
112
close(FILE);