Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 021d254

Browse files
committed
Make all unicode perl scripts to use strict, rearrange logic for clarity.
The loops were a bit difficult to understand, due to breaking out of them early. Also fix things that perlcritic complained about. Daniel Gustafsson
1 parent 81c5272 commit 021d254

12 files changed

+102
-108
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
# UCS-2 code in hex
2525
# # and Unicode name (not used in this script)
2626

27-
28-
require "convutils.pm";
27+
use strict;
28+
require convutils;
2929

3030
# Load BIG5.TXT
3131
my $all = &read_source("BIG5.TXT");

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
# where the "u" field is the Unicode code point in hex,
1414
# and the "b" field is the hex byte sequence for GB18030
1515

16-
require "convutils.pm";
16+
use strict;
17+
require convutils;
1718

1819
# Read the input
1920

20-
$in_file = "gb-18030-2000.xml";
21+
my $in_file = "gb-18030-2000.xml";
2122

22-
open(FILE, $in_file) || die("cannot open $in_file");
23+
open(my $in, '<', $in_file) || die("cannot open $in_file");
2324

2425
my @mapping;
2526

26-
while (<FILE>)
27+
while (<$in>)
2728
{
2829
next if (!m/<a u="([0-9A-F]+)" b="([0-9A-F ]+)"/);
29-
$u = $1;
30-
$c = $2;
30+
my ($u, $c) = ($1, $2);
3131
$c =~ s/ //g;
32-
$ucs = hex($u);
33-
$code = hex($c);
32+
my $ucs = hex($u);
33+
my $code = hex($c);
3434

3535
# The GB-18030 character set, which we use as the source, contains
3636
# a lot of extra characters on top of the GB2312 character set that
@@ -71,6 +71,6 @@
7171
direction => 'both'
7272
}
7373
}
74-
close(FILE);
74+
close($in);
7575

7676
print_tables("EUC_CN", \@mapping);

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

+19-25
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
# Generate UTF-8 <--> EUC_JIS_2004 code conversion tables from
88
# "euc-jis-2004-std.txt" (http://x0213.org)
99

10-
require "convutils.pm";
10+
use strict;
11+
require convutils;
1112

1213
# first generate UTF-8 --> EUC_JIS_2004 table
1314

14-
$in_file = "euc-jis-2004-std.txt";
15+
my $in_file = "euc-jis-2004-std.txt";
1516

16-
open(FILE, $in_file) || die("cannot open $in_file");
17+
open(my $in, '<', $in_file) || die("cannot open $in_file");
1718

1819
my @all;
1920

20-
while ($line = <FILE>)
21+
while (my $line = <$in>)
2122
{
2223
if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/)
2324
{
24-
$c = $1;
25-
$u1 = $2;
26-
$u2 = $3;
27-
$rest = "U+" . $u1 . "+" . $u2 . $4;
28-
$code = hex($c);
29-
$ucs1 = hex($u1);
30-
$ucs2 = hex($u2);
25+
# combined characters
26+
my ($c, $u1, $u2) = ($1, $2, $3);
27+
my $rest = "U+" . $u1 . "+" . $u2 . $4;
28+
my $code = hex($c);
29+
my $ucs1 = hex($u1);
30+
my $ucs2 = hex($u2);
3131

3232
push @all, { direction => 'both',
3333
ucs => $ucs1,
@@ -38,22 +38,16 @@
3838
}
3939
elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/)
4040
{
41-
$c = $1;
42-
$u = $2;
43-
$rest = "U+" . $u . $3;
44-
}
45-
else
46-
{
47-
next;
48-
}
49-
50-
$ucs = hex($u);
51-
$code = hex($c);
41+
# non-combined characters
42+
my ($c, $u, $rest) = ($1, $2, "U+" . $2 . $3);
43+
my $ucs = hex($u);
44+
my $code = hex($c);
5245

53-
next if ($code < 0x80 && $ucs < 0x80);
46+
next if ($code < 0x80 && $ucs < 0x80);
5447

55-
push @all, { direction => 'both', ucs => $ucs, code => $code, comment => $rest };
48+
push @all, { direction => 'both', ucs => $ucs, code => $code, comment => $rest };
49+
}
5650
}
57-
close(FILE);
51+
close($in);
5852

5953
print_tables("EUC_JIS_2004", \@all, 1);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# organization's ftp site.
1313

1414
use strict;
15-
require "convutils.pm";
15+
require convutils;
1616

1717
# Load JIS0212.TXT
1818
my $jis0212 = &read_source("JIS0212.TXT");

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# UCS-2 code in hex
1717
# # and Unicode name (not used in this script)
1818

19-
require "convutils.pm";
19+
use strict;
20+
require convutils;
2021

2122
# Load the source file.
2223

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
# UCS-2 code in hex
1818
# # and Unicode name (not used in this script)
1919

20-
require "convutils.pm";
20+
use strict;
21+
require convutils;
2122

2223
my $mapping = &read_source("CNS11643.TXT");
2324

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
# where the "u" field is the Unicode code point in hex,
1414
# and the "b" field is the hex byte sequence for GB18030
1515

16-
require "convutils.pm";
16+
use strict;
17+
require convutils;
1718

1819
# Read the input
1920

20-
$in_file = "gb-18030-2000.xml";
21+
my $in_file = "gb-18030-2000.xml";
2122

22-
open(FILE, $in_file) || die("cannot open $in_file");
23+
open(my $in, '<', $in_file) || die("cannot open $in_file");
2324

2425
my @mapping;
2526

26-
while (<FILE>)
27+
while (<$in>)
2728
{
2829
next if (!m/<a u="([0-9A-F]+)" b="([0-9A-F ]+)"/);
29-
$u = $1;
30-
$c = $2;
30+
my ($u, $c) = ($1, $2);
3131
$c =~ s/ //g;
32-
$ucs = hex($u);
33-
$code = hex($c);
32+
my $ucs = hex($u);
33+
my $code = hex($c);
3434
if ($code >= 0x80 && $ucs >= 0x0080)
3535
{
3636
push @mapping, {
@@ -40,6 +40,6 @@
4040
}
4141
}
4242
}
43-
close(FILE);
43+
close($in);
4444

4545
print_tables("GB18030", \@mapping);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# UCS-2 code in hex
1616
# # and Unicode name (not used in this script)
1717

18-
require "convutils.pm";
18+
use strict;
19+
require convutils;
1920

2021
# Load the source file.
2122

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

+39-44
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
# Generate UTF-8 <--> SHIFT_JIS_2004 code conversion tables from
88
# "sjis-0213-2004-std.txt" (http://x0213.org)
99

10-
require "convutils.pm";
10+
use strict;
11+
require convutils;
1112

1213
# first generate UTF-8 --> SHIFT_JIS_2004 table
1314

14-
$in_file = "sjis-0213-2004-std.txt";
15+
my $in_file = "sjis-0213-2004-std.txt";
1516

16-
open(FILE, $in_file) || die("cannot open $in_file");
17+
open(my $in, '<', $in_file) || die("cannot open $in_file");
1718

1819
my @mapping;
1920

20-
while ($line = <FILE>)
21+
while (my $line = <$in>)
2122
{
2223
if ($line =~ /^0x(.*)[ \t]*U\+(.*)\+(.*)[ \t]*#(.*)$/)
2324
{
24-
$c = $1;
25-
$u1 = $2;
26-
$u2 = $3;
27-
$rest = "U+" . $u1 . "+" . $u2 . $4;
28-
$code = hex($c);
29-
$ucs1 = hex($u1);
30-
$ucs2 = hex($u2);
25+
# combined characters
26+
my ($c, $u1, $u2) = ($1, $2, $3);
27+
my $rest = "U+" . $u1 . "+" . $u2 . $4;
28+
my $code = hex($c);
29+
my $ucs1 = hex($u1);
30+
my $ucs2 = hex($u2);
3131

3232
push @mapping, {
3333
code => $code,
@@ -40,42 +40,37 @@
4040
}
4141
elsif ($line =~ /^0x(.*)[ \t]*U\+(.*)[ \t]*#(.*)$/)
4242
{
43-
$c = $1;
44-
$u = $2;
45-
$rest = "U+" . $u . $3;
46-
}
47-
else
48-
{
49-
next;
50-
}
43+
# non-combined characters
44+
my ($c, $u, $rest) = ($1, $2, "U+" . $2 . $3);
45+
my $ucs = hex($u);
46+
my $code = hex($c);
47+
my $direction;
5148

52-
$ucs = hex($u);
53-
$code = hex($c);
49+
if ($code < 0x80 && $ucs < 0x80)
50+
{
51+
next;
52+
}
53+
elsif ($code < 0x80)
54+
{
55+
$direction = 'from_unicode';
56+
}
57+
elsif ($ucs < 0x80)
58+
{
59+
$direction = 'to_unicode';
60+
}
61+
else
62+
{
63+
$direction = 'both';
64+
}
5465

55-
if ($code < 0x80 && $ucs < 0x80)
56-
{
57-
next;
58-
}
59-
elsif ($code < 0x80)
60-
{
61-
$direction = 'from_unicode';
62-
}
63-
elsif ($ucs < 0x80)
64-
{
65-
$direction = 'to_unicode';
66-
}
67-
else
68-
{
69-
$direction = 'both';
66+
push @mapping, {
67+
code => $code,
68+
ucs => $ucs,
69+
comment => $rest,
70+
direction => $direction
71+
};
7072
}
71-
72-
push @mapping, {
73-
code => $code,
74-
ucs => $ucs,
75-
comment => $rest,
76-
direction => $direction
77-
};
7873
}
79-
close(FILE);
74+
close($in);
8075

8176
print_tables("SHIFT_JIS_2004", \@mapping, 1);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# ftp site.
1212

1313
use strict;
14-
require "convutils.pm";
14+
require convutils;
1515

1616
my $charset = read_source("CP932.TXT");
1717

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
# where the "u" field is the Unicode code point in hex,
1414
# and the "b" field is the hex byte sequence for UHC
1515

16-
require "convutils.pm";
16+
use strict;
17+
require convutils;
1718

1819
# Read the input
1920

20-
$in_file = "windows-949-2000.xml";
21+
my $in_file = "windows-949-2000.xml";
2122

22-
open(FILE, $in_file) || die("cannot open $in_file");
23+
open(my $in, '<', $in_file) || die("cannot open $in_file");
2324

2425
my @mapping;
2526

26-
while (<FILE>)
27+
while (<$in>)
2728
{
2829
next if (!m/<a u="([0-9A-F]+)" b="([0-9A-F ]+)"/);
29-
$u = $1;
30-
$c = $2;
30+
my ($u, $c) = ($1, $2);
3131
$c =~ s/ //g;
32-
$ucs = hex($u);
33-
$code = hex($c);
32+
my $ucs = hex($u);
33+
my $code = hex($c);
3434

3535
next if ($code == 0x0080 || $code == 0x00FF);
3636

@@ -43,7 +43,7 @@
4343
}
4444
}
4545
}
46-
close(FILE);
46+
close($in);
4747

4848
# One extra character that's not in the source file.
4949
push @mapping, { direction => 'both', code => 0xa2e8, ucs => 0x327e, comment => 'CIRCLED HANGUL IEUNG U' };

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
# UCS-2 code in hex
1616
# # and Unicode name (not used in this script)
1717

18-
require "convutils.pm";
18+
use strict;
19+
require convutils;
1920

20-
%filename = (
21+
my %filename = (
2122
'WIN866' => 'CP866.TXT',
2223
'WIN874' => 'CP874.TXT',
2324
'WIN1250' => 'CP1250.TXT',
@@ -46,9 +47,10 @@
4647
'KOI8U' => 'KOI8-U.TXT',
4748
'GBK' => 'CP936.TXT');
4849

49-
@charsets = keys(%filename);
50-
@charsets = @ARGV if scalar(@ARGV);
51-
foreach $charset (@charsets)
50+
# make maps for all encodings if not specified
51+
my @charsets = (scalar(@ARGV) > 0) ? @ARGV : keys(%filename);
52+
53+
foreach my $charset (@charsets)
5254
{
5355
my $mapping = &read_source($filename{$charset});
5456

0 commit comments

Comments
 (0)