~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

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

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/perl
 
2
#
 
3
# Copyright (c) 2001-2005, PostgreSQL Global Development Group
 
4
#
 
5
# $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/UCS_to_WIN874.pl,v 1.5 2005-01-01 20:44:18 tgl Exp $
 
6
#
 
7
# Generate UTF-8 <--> WIN874 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 --> WIN949 table
 
22
 
 
23
$in_file = "CP874.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 unicode: %04x\n",$ucs;
 
39
                        next;
 
40
                }
 
41
                $count++;
 
42
 
 
43
                $array{ $utf } = $code;
 
44
        }
 
45
}
 
46
close( FILE );
 
47
 
 
48
#
 
49
# first, generate UTF8 --> WIN874 table
 
50
#
 
51
 
 
52
$file = "utf8_to_win874.map";
 
53
open( FILE, "> $file" ) || die( "cannot open $file" );
 
54
print FILE "static pg_utf_to_local ULmapWIN874[ $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 WIN874 --> 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
                $array{ $code } = $utf;
 
93
        }
 
94
}
 
95
close( FILE );
 
96
 
 
97
$file = "win874_to_utf8.map";
 
98
open( FILE, "> $file" ) || die( "cannot open $file" );
 
99
print FILE "static pg_local_to_utf LUmapWIN874[ $count ] = {\n";
 
100
for $index ( sort {$a <=> $b} keys( %array ) ){
 
101
        $utf = $array{ $index };
 
102
        $count--;
 
103
        if( $count == 0 ){
 
104
                printf FILE "  {0x%04x, 0x%04x}\n", $index, $utf;
 
105
        } else {
 
106
                printf FILE "  {0x%04x, 0x%04x},\n", $index, $utf;
 
107
        }
 
108
}
 
109
 
 
110
print FILE "};\n";
 
111
close(FILE);