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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Sun Oct 13 02:31:06 2002 UTC (22 years, 1 month ago) by wakaba
Branch: MAIN
File MIME type: text/plain
2002-10-13  Wakaba <w@suika.fam.cx>

	* esr2pm.pl: New script.  (Thanks to Nanashi-san.)

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     =head1 NEMA
5    
6     esr2pm.pl --- Simple Encode module generator
7    
8     =cut
9    
10     my %ReplaceText = &ReplaceText;
11     my %Info;
12     my $mode = 0;
13     my $section = '';
14     my %item;
15     while (<>) {
16     if ($mode == 1) { ## In a block
17     if (/^\}$/) {
18     $item{ModuleName} ||= $item{Name};
19     $item{ModuleName} =~ s/[^0-9A-Za-z_]/_/g;
20     push @{ $Info{encoding} }, {%item};
21     $mode = 0; %item = ();
22     } elsif (/^(.+):$/) {
23     $section = $1;
24     } elsif (/^\t(.+)$/) {
25     my $l = $1;
26     if ($section == 'Encode' || $section == 'Decode') {
27     if ($l =~ /^->(.+)$/) {
28     $l = qq(my \$e = Encode::find_encoding (q($1))->__clone;\n\$e->{_encode_mapping} = 0;\n\$s = \$e->encode (\$s););
29     } elsif ($l =~ /^<-(.+)$/) {
30     $l = qq(my \$e = Encode::find_encoding (q($1))->__clone;\n\$e->{_decode_mapping} = 0;\n\$s = \$e->decode (\$s););
31     } elsif ($l =~ /^(?:<=|=>)(.+)$/) {
32     $l = qq(\$s = Encode::Table::convert (\$s, [qw($1)], \%tblopt) if \$tbl;);
33     } elsif ($l =~ /^utf8:o(n|ff)$/) {
34     $l = qq(Encode::_utf8_o$1 (\$s););
35     } elsif ($l =~ /^use:table:(.+)$/) {
36     $l = qq(eval q(use Encode::Table::$1) unless \$Encode::Table::$1::VERSION;);
37     } elsif ($l =~ /^use:(.+)$/) {
38     $l = qq(eval q(use $1) unless \$$1::VERSION;);
39     }
40     }
41     if ($item{$section}) {
42     $item{$section} .= "\n".$l;
43     } else {
44     $item{$section} = $l;
45     }
46     }
47     } else { ## Out of blocks
48     if (/^\{$/) {
49     $mode = 1;
50     } elsif (/^(.+):$/) {
51     $section = $1;
52     } elsif (/^\t(.*)$/) {
53     my $t = $1;
54     if ($Info{$section}) {
55     $Info{$section} .= "\n".$t;
56     } else {
57     $Info{$section} = $t;
58     }
59     }
60     }
61     }
62     $ReplaceText{MYSELF} = qq(Encode::$Info{Name});
63    
64     print <<EOH;
65     ## This file is auto-generated (at @{[ sprintf '%04d-%02d-%02dT%02d:%02d:%02dZ', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3,2,1,0] ]}).
66     ## Do not edit by hand!
67    
68     =head1 NAME
69    
70     $ReplaceText{MYSELF} --- $Info{ShortDescription}
71     @{[ $Info{'POD:DESCRIPTION'} ? qq{=head1 DESCRIPTION
72    
73     $Info{'POD:DESCRIPTION'}} : '']}
74     =cut
75    
76     package $ReplaceText{MYSELF};
77     use 5.7.3;
78     use strict;
79     our \$VERSION = q(@{[sprintf '%04d.%02d%02d', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]]});
80    
81     =head1 ENCODINGS
82     @{[ $Info{'POD:ENCODING:PREAMBLE'} ? qq(
83     $Info{'POD:ENCODING:PREAMBLE'}
84     ) : '']}
85     =over 8
86    
87     =cut
88    
89     EOH
90    
91     for my $encode (@{ $Info{encoding} }) {
92     for my $ED (qw/Encode Decode/) {
93     my $ed = lc $ED;
94     if ($encode->{$ED} =~ /Encode::Table/) {
95     $encode->{$ED} = q/require Encode::Table;
96     my $tbl = defined $obj->{_/.$ed.q/_mapping} ? $obj->{_/.$ed.q/_mapping} : 1;
97     my %tblopt = (-autoload => defined $obj->{_/.$ed.q/_mapping_autoload} ? $obj->{_/.$ed.q/_mapping_autoload} : 1);
98     /.$encode->{$ED};
99     }
100     $encode->{$ED} =~ s/\n/\n /g;
101     }
102     print <<EOH;
103    
104     package Encode::$Info{Name}::$encode->{ModuleName};
105     our \$VERSION = \$Encode::$Info{Name}::VERSION;
106     use base qw(Encode::Encoding);
107     __PACKAGE__->Define (qw/$encode->{Name} $encode->{Alias}/);
108    
109     =item $encode->{Name}
110    
111     $encode->{Description}@{[ $encode->{Alias} ? '
112     (Alias: ' . join (', ', split /\s+/, $encode->{Alias}) . ')' : '' ]}
113    
114     =cut
115    
116     sub encode (\$\$;\$) {
117     my (\$obj, \$s, \$chk) = \@_;
118     $encode->{Encode}
119     \$_[1] = '' if \$chk;
120     return \$s;
121     }
122    
123     sub decode (\$\$;\$) {
124     my (\$obj, \$s, \$chk) = \@_;
125     $encode->{Decode}
126     \$_[1] = '' if \$chk;
127     return \$s;
128     }
129    
130     EOH
131     }
132    
133     print <<EOH;
134    
135     =back
136     @{[ $Info{'POD:ENCODING:POSTAMBLE'} ? qq(
137     $Info{'POD:ENCODING:POSTAMBLE'}
138     ) : '']}
139     =cut
140    
141     sub Encode::Encoding::__clone (\$) {
142     my \$self = shift;
143     bless {%\$self}, ref \$self;
144     }
145    
146     EOH
147    
148     for my $name (qw/EXAMPLE/, 'SEE ALSO', 'TO DO', qw/AUTHORS LICENSE/) {
149     if ($Info{qq(POD:$name)}) {
150     $Info{qq(POD:$name)} =~ s/%%([A-Za-z0-9_]+)%%/$ReplaceText{$1}/g;
151     print <<EOH;
152     =head1 $name
153    
154     $Info{qq(POD:$name)}
155    
156     EOH
157     }
158     }
159    
160     print <<EOH;
161     =cut
162    
163     1;
164     EOH
165    
166     sub ReplaceText () {
167     my %RT = (
168     GNUGPL2 => q{This program is free software; you can redistribute it and/or modify
169     it under the terms of the GNU General Public License as published by
170     the Free Software Foundation; either version 2 of the License, or
171     (at your option) any later version.
172    
173     This program is distributed in the hope that it will be useful,
174     but WITHOUT ANY WARRANTY; without even the implied warranty of
175     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
176     GNU General Public License for more details.
177    
178     You should have received a copy of the GNU General Public License
179     along with this program; see the file COPYING. If not, write to
180     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
181     Boston, MA 02111-1307, USA.},
182     PerlLicense => q{This library is free software; you can redistribute it
183     and/or modify it under the same terms as Perl itself.},
184     ReferenceIANAREG => q([IANAREG] "CHARACTER SETS", IANA <http://www.iana.org/>,
185     <http://www.iana.org/assignments/character-sets>.
186     The charset registry for IETF <http://www.ietf.org/> standards.),
187     ReferenceJISX0208_1997 => q(JIS X 0208:1997, "7-bit and 8-bit double byte coded Kanji
188     set for information interchange", Japan Industrial Standards
189     Committee (JISC) <http://www.jisc.go.jp/>, 1997.),
190     ReferenceJISX0213_2000 => q(JIS X 0213:2000, "7-bit and 8-bit double byte coded extended Kanji
191     sets for information interchange", Japan Industrial Standards
192     Committee (JISC) <http://www.jisc.go.jp/>, 2000.),
193     YEAR => (gmtime)[5]+1900,
194     );
195     %RT;
196     }
197    
198     =head1 SEE ALSO
199    
200     L<Encode>, L<Encode::Table>
201    
202     =head1 LICENSE
203    
204     Copyright 2002 Wakaba <w@suika.fam.cx>
205    
206     This library is free software; you can redistribute it
207     and/or modify it under the same terms as Perl itself.
208    
209     Note that modules generated by this script should be
210     licensed by the licenser of source file so that copyright
211     holder of this script does not claim any right to them.
212    
213     =cut
214    
215     # $Date: $
216     ### esr2pm.pl ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24