1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use 5.7.3; |
4 |
|
5 |
=head1 NAME |
6 |
|
7 |
tbl2pm --- Perl module generator from (completed) PETBL |
8 |
table file |
9 |
|
10 |
=head1 DESCRIPTION |
11 |
|
12 |
This script generates dumped perl module file of convertion |
13 |
table used with Encode::Table module. |
14 |
|
15 |
=head1 USAGE |
16 |
|
17 |
$ ./tbl2pm.pl table.tbl > table.pm |
18 |
|
19 |
=cut |
20 |
|
21 |
require Encode; |
22 |
my %T; |
23 |
my %option; |
24 |
while (<>) { |
25 |
if (/^((?:0x|[0-9A-Za-z]+[+-])[0-9A-F]+)\tU\+([0-9A-F]+)\t/) { |
26 |
$T{ $1 } = hex $2; |
27 |
} elsif (/^#\?o ([A-Za-z0-9-]+)="((?:[^"\\]|\\.)+)"/) { |
28 |
my ($n,$v) = ($1,$2); $n =~ tr/-/_/; $v =~ s/\\(.)/$1/g; $option{$n} = $v; |
29 |
} |
30 |
} |
31 |
|
32 |
require 'internal.pl'; |
33 |
$option{offset} ||= &internal::cp_start (%option) || $internal::cp_start{ $option{charset_name} || $option{table_name} }; |
34 |
if ($option{map_internal}) { |
35 |
eval qq{\$option{map_internal} = sub { $option{map_internal} }} or die $@; |
36 |
} else { |
37 |
$option{map_internal} = sub { |
38 |
my $c = shift; $c =~ s/0x//; $c = hex $c; |
39 |
($option{charset_dimension} > 1 ? |
40 |
(int ($c / 0x100) - $option{_start}) * $option{charset_chars} : 0) |
41 |
+ (($c % 0x100) - $option{_start}) + $option{offset}; |
42 |
}; |
43 |
} |
44 |
|
45 |
my (@T, @U); |
46 |
$option{_start} = $option{charset_chars} == 94 ? 0x21 : 0x20; |
47 |
@U = sort { $a->[0] <=> $b->[0] } |
48 |
map { [ &{$option{map_internal}} ($_), $T{ $_ } ] } keys %T; |
49 |
|
50 |
my $tbl = ''; |
51 |
my $pack = ''; |
52 |
for (@U) { |
53 |
for ($_->[0], $_->[1]) { |
54 |
$_ = chr $_; |
55 |
Encode::_utf8_off ($_); |
56 |
$tbl .= $_; |
57 |
$pack .= 'a' . length ($_); |
58 |
} |
59 |
} |
60 |
|
61 |
print <<EOH; |
62 |
## This file is auto-generated (at @{[ sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3,2,1,0] ]}). |
63 |
## Do not edit by hand! |
64 |
|
65 |
=head1 NAME |
66 |
|
67 |
Encode::Table::$option{table_name} --- Convertion tables |
68 |
used with Encode::Table, C<$option{table_name}_to_ucs> |
69 |
and C<ucs_to_$option{table_name}> |
70 |
|
71 |
=head1 TABLES |
72 |
|
73 |
=over 4 |
74 |
|
75 |
=item $option{table_name}_to_ucs |
76 |
|
77 |
Convertion table of $option{table_name} -> ucs |
78 |
|
79 |
=item ucs_to_$option{table_name} |
80 |
|
81 |
Convertion table of ucs -> $option{table_name} |
82 |
|
83 |
=back |
84 |
|
85 |
=head1 SEE ALSO |
86 |
|
87 |
Encode::Table |
88 |
|
89 |
=head1 LICENSE |
90 |
|
91 |
See source table of this module. (It may be named as |
92 |
C<$option{table_name}.tbr>.) |
93 |
|
94 |
=cut |
95 |
|
96 |
package Encode::Table::$option{table_name}; |
97 |
use strict; |
98 |
our \$VERSION = q(@{[sprintf '%04d.%02d%02d', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]]}); |
99 |
|
100 |
## These tables are embeded in binary, so that your editor |
101 |
## might break the data or might hang up. |
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
# |
112 |
|
113 |
our %L2U = map {Encode::_utf8_on (\$_) if length \$_ > 1; \$_} unpack |
114 |
(q{$pack}, <<'END'); |
115 |
EOH |
116 |
|
117 |
print $tbl,"\nEND\n"; |
118 |
|
119 |
print <<EOH; |
120 |
our %U2L = reverse %L2U; |
121 |
sub import { |
122 |
\$Encode::Table::TABLE{$option{table_name}_to_ucs} = \\%L2U; |
123 |
\$Encode::Table::TABLE{ucs_to_$option{table_name}} = \\%U2L; |
124 |
} |
125 |
1; |
126 |
### $option{table_name}.pm ends here |
127 |
EOH |
128 |
|
129 |
|
130 |
=head1 SEE ALSO |
131 |
|
132 |
Encode::Table, internal.pl |
133 |
|
134 |
=head1 AUTHOR |
135 |
|
136 |
Nanashi-san |
137 |
|
138 |
=head1 LICENSE |
139 |
|
140 |
Copyright 2002 AUTHOR |
141 |
|
142 |
This library is free software; you can redistribute it |
143 |
and/or modify it under the same terms as Perl itself. |
144 |
|
145 |
AUTHOR does NOT claim any right to the data generated by |
146 |
this script. License of generated data fully depends |
147 |
author of source data. |
148 |
|
149 |
=cut |
150 |
|
151 |
1; ## $Date: 2002/12/12 07:45:17 $ |
152 |
### tbl2pm.pl ends here |