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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4 wakaba 1.2 =head1 NAME
5    
6     tbl2ucm --- PETBL/1.0 -> ucm converter
7    
8     =cut
9    
10 wakaba 1.1 my @l;
11     my %i;
12     while (<>) {
13     if (/^0x([0-9A-F]+)\tU\+([0-9A-F]+)\t([^\t]*)\t# ?(.*)/) {
14     push @l, {local => hex $1, ucs => hex $2, comment => $4};
15     my $info = $3;
16     if ($info =~ /<->/) { $l[-1]->{fallback} = 0 }
17     elsif ($info =~ /<-/) { $l[-1]->{fallback} = 1 }
18     elsif ($info =~ /->/) { $l[-1]->{fallback} = 3 }
19 wakaba 1.3 } elsif (/^#\?o ([a-z0-9:_<>-]+)="(.+)"/) {
20     my ($n,$v) = ($1,$2); $v =~ s/\\(.)/$1/g;
21     $i{$n} = $i{$n} ? $i{$n} . "\t" . $v : $v;
22     } elsif (/^## ([a-z0-9:_<>-]+)\t(.+)/) {
23     $i{$1} = $i{$1} ? $i{$1} . "\t" . $2 : $2;
24 wakaba 1.1 }
25     }
26    
27     @l = sort { $a->{ucs} <=> $b->{ucs} || $a->{fallback} <=> $b->{fallback} || $a->{local} <=> $b->{local} } @l;
28    
29     print <<EOH;
30     #
31     <code_set_name> "@{[ $i{'ucm:code_set_name'} || $i{name} ]}"
32     @{[&{sub{
33     my $s = '';
34 wakaba 1.3 for (sort split /\t/, lc $i{'ucm:code_set_alias'}) {
35 wakaba 1.1 $s .= sprintf '<code_set_alias> "%s"%s', $_, "\n";
36     }
37     $s;
38     }}]}<mb_cur_min> @{[ $i{'ucm:mb_cur_min'} || 1 ]}
39     <mb_cur_max> @{[ $i{'ucm:mb_cur_max'} || 1 ]}
40     <subchar> @{[&{sub{
41 wakaba 1.3 my $s = uc ($i{'ucm:subchar'}||$i{'<-ucs-substition'}||$i{substition} || '0x3F');
42 wakaba 1.1 $s =~ s/^[0\\]X/\\x/;
43     $s =~ s/^\\x([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])/\\x$1\\x$2/;
44     $s;
45     }}]}
46     #
47     CHARMAP
48     EOH
49    
50     for (@l) {
51     printf q{<U%04X> \x%02X |%d # %s}, $_->{ucs}, $_->{local}, $_->{fallback}, $_->{comment}."\n";
52     }
53    
54     print "END CHARMAP\n";
55 wakaba 1.2
56    
57     =head1 SEE ALSO
58    
59     perlunicode, enc2xs, tbr2tbl.pl
60    
61     =head1 AUTHOR
62    
63     Nanashi-san
64    
65     =head1 LICENSE
66    
67     Copyright 2002 AUTHOR
68    
69     This library is free software; you can redistribute it
70     and/or modify it under the same terms as Perl itself.
71    
72     AUTHOR does NOT claim any right to the data generated by
73     this script. License of generated data fully depends
74     author of source data.
75    
76     =cut
77    
78 wakaba 1.3 1; ## $Date: 2002/10/05 01:34:55 $
79 wakaba 1.2 ### tbl2ucm.pl ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24