/[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.2 - (hide annotations) (download)
Sat Oct 5 01:34:55 2002 UTC (22 years, 2 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +46 -6 lines
File MIME type: text/plain
2002-10-05  Nanashi-san

	* Table.pm: New module.
	(Commited by Wakaba <w@suika.fam.cx>.)

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     if (/^0x([0-9A-F][0-9A-F][0-9A-F][0-9A-F])\tU\+([0-9A-F]+)\t/) {
26     $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     [ (int ($_ / 0x100) - $option{_start}) * $option{charset_chars}
40     + (($_ % 0x100) - $option{_start}) + $option{offset},
41     $T{ $_ } ]
42     } keys %T;
43    
44     my $tbl = '';
45     my $pack = '';
46     for (@U) {
47     for ($_->[0], $_->[1]) {
48     $_ = chr $_; $_ = $_ eq "\\" ? "\\\\" : $_ eq q(') ? q(\') : $_;
49     Encode::_utf8_off ($_);
50     $tbl .= $_;
51     $pack .= 'a' . length ($_);
52     }
53     }
54    
55     print <<EOH;
56     ## This file is auto-generated (at @{[ sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3,2,1,0] ]}).
57     ## Do not edit by hand!
58    
59     =head1 NAME
60    
61     Encode::Table::$option{table_name} --- Convertion tables
62     used with Encode::Table, C<$option{table_name}_to_ucs>
63     and C<ucs_to_$option{table_name}>
64    
65     =head1 TABLES
66    
67     =over 4
68    
69     =item $option{table_name}_to_ucs
70    
71     Convertion table of $option{table_name} -> ucs
72    
73     =item ucs_to_$option{table_name}
74    
75     Convertion table of ucs -> $option{table_name}
76    
77     =back
78    
79     =head1 SEE ALSO
80    
81     Encode::Table
82    
83     =head1 LICENSE
84    
85     See source table of this module. (It may be named as
86     C<$option{table_name}.tbr>.)
87    
88     =cut
89    
90     package Encode::Table::$option{table_name};
91     use strict;
92 wakaba 1.2 use vars qw/%L2U %U2L \$VERSION/;
93     \$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.2 %L2U = map {Encode::_utf8_on (\$_); \$_} unpack
109     (q{$pack}, <<'END');
110 wakaba 1.1 EOH
111    
112     print $tbl,"\nEND\n";
113    
114     print <<EOH;
115     %U2L = reverse %L2U;
116     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     1; ## $Date: 2002/10/05 00:25:14 $
147 wakaba 1.1 ### tbl2pm.pl ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24