3 # Copyright (c) 2007-2010, PostgreSQL Global Development Group
5 # $PostgreSQL: pgsql/src/backend/utils/mb/Unicode/UCS_to_GB18030.pl,v 1.7 2010/09/19 16:27:17 tgl Exp $
7 # Generate UTF-8 <--> GB18030 code conversion tables from
8 # "ISO10646-GB18030.TXT"
17 # first generate UTF-8 --> GB18030 table
19 $in_file = "ISO10646-GB18030.TXT";
21 open( FILE, $in_file ) || die( "cannot open $in_file" );
28 ( $u, $c, $rest ) = split;
31 if( $code >= 0x80 && $ucs >= 0x0080 ){
32 $utf = &ucs2utf($ucs);
33 if( $array{ $utf } ne "" ){
34 printf STDERR "Warning: duplicate UTF8: %04x\n",$ucs;
39 $array{ $utf } = $code;
46 # first, generate UTF8 --> GB18030 table
49 $file = "utf8_to_gb18030.map";
50 open( FILE, "> $file" ) || die( "cannot open $file" );
51 print FILE "static pg_utf_to_local ULmapGB18030[ $count ] = {\n";
53 for $index ( sort {$a <=> $b} keys( %array ) ){
54 $code = $array{ $index };
57 printf FILE " {0x%04x, 0x%04x}\n", $index, $code;
59 printf FILE " {0x%04x, 0x%04x},\n", $index, $code;
68 # then generate GB18030 --> UTF8 table
72 open( FILE, $in_file ) || die( "cannot open $in_file" );
79 ( $u, $c, $rest ) = split;
82 if( $code >= 0x80 && $ucs >= 0x0080 ){
83 $utf = &ucs2utf($ucs);
84 if( $array{ $code } ne "" ){
85 printf STDERR "Warning: duplicate code: %04x\n",$ucs;
90 $array{ $code } = $utf;
95 $file = "gb18030_to_utf8.map";
96 open( FILE, "> $file" ) || die( "cannot open $file" );
97 print FILE "static pg_local_to_utf LUmapGB18030[ $count ] = {\n";
98 for $index ( sort {$a <=> $b} keys( %array ) ){
99 $utf = $array{ $index };
102 printf FILE " {0x%04x, 0x%04x}\n", $index, $utf;
104 printf FILE " {0x%04x, 0x%04x},\n", $index, $utf;