Debian Codegraph @

src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl

raw
1 #! /usr/bin/perl
2 #
3 # Copyright (c) 2007-2025, PostgreSQL Global Development Group
4 #
5 # src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl
6 #
7 # Generate UTF-8 <--> EUC_JIS_2004 code conversion tables from
8 # "euc-jis-2004-std.txt" (http://x0213.org)
9
10 use strict;
11 use warnings FATAL => 'all';
12
13 use convutils;
14
15 my $this_script = 'src/backend/utils/mb/Unicode/UCS_to_EUC_JIS_2004.pl';
16
17 # first generate UTF-8 --> EUC_JIS_2004 table
18
19 my $in_file = "euc-jis-2004-std.txt";
20
21 open(my $in, '<', $in_file) || die("cannot open $in_file");
22
23 my @all;
24
25 while (my $line = <$in>)
26 {
27 if ($line =~ /^0x(\w+)\s*U\+(\w+)\+(\w+)\s*#\s*(\S.*)?\s*$/)
28 {
29
30 # combined characters
31 my ($c, $u1, $u2) = ($1, $2, $3);
32 # The "\t \t" below is just to avoid insubstantial diffs.
33 my $rest = "U+" . $u1 . "+" . $u2 . "\t \t" . $4;
34 my $code = hex($c);
35 my $ucs1 = hex($u1);
36 my $ucs2 = hex($u2);
37
38 push @all,
39 {
40 direction => BOTH,
41 ucs => $ucs1,
42 ucs_second => $ucs2,
43 code => $code,
44 comment => $rest,
45 f => $in_file,
46 l => $.
47 };
48 }
49 elsif ($line =~ /^0x(\w+)\s*U\+(\w+)\s*#\s*(\S.*)?\s*$/)
50 {
51
52 # non-combined characters
53 my ($c, $u, $rest) = ($1, $2, "U+" . $2 . $3);
54 my $ucs = hex($u);
55 my $code = hex($c);
56
57 next if ($code < 0x80 && $ucs < 0x80);
58
59 push @all,
60 {
61 direction => BOTH,
62 ucs => $ucs,
63 code => $code,
64 comment => $rest,
65 f => $in_file,
66 l => $.
67 };
68 }
69 }
70 close($in);
71
72 print_conversion_tables($this_script, "EUC_JIS_2004", \@all);