/[suikacvs]/perl/lib/Encode/Table/tool/tbl2pm.pl
Suika

Contents of /perl/lib/Encode/Table/tool/tbl2pm.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Thu Dec 12 07:45:17 2002 UTC (21 years, 11 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +4 -5 lines
File MIME type: text/plain
*** empty log message ***

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24