/[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.2 - (hide annotations) (download)
Mon Oct 14 06:56:53 2002 UTC (22 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.1: +12 -3 lines
File MIME type: text/plain
2002-10-14  Nanashi-san

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

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 wakaba 1.2 } elsif (/^\t(.*)$/) {
25 wakaba 1.1 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 wakaba 1.2 @{[ $Info{'POD:DESCRIPTION'} ? qq{
72     =head1 DESCRIPTION
73 wakaba 1.1
74     $Info{'POD:DESCRIPTION'}} : '']}
75 wakaba 1.2
76 wakaba 1.1 =cut
77    
78     package $ReplaceText{MYSELF};
79     use 5.7.3;
80     use strict;
81     our \$VERSION = q(@{[sprintf '%04d.%02d%02d', (gmtime)[5]+1900, (gmtime)[4]+1, (gmtime)[3]]});
82    
83     =head1 ENCODINGS
84     @{[ $Info{'POD:ENCODING:PREAMBLE'} ? qq(
85     $Info{'POD:ENCODING:PREAMBLE'}
86     ) : '']}
87     =over 8
88    
89     =cut
90    
91     EOH
92    
93     for my $encode (@{ $Info{encoding} }) {
94     for my $ED (qw/Encode Decode/) {
95     my $ed = lc $ED;
96     if ($encode->{$ED} =~ /Encode::Table/) {
97     $encode->{$ED} = q/require Encode::Table;
98     my $tbl = defined $obj->{_/.$ed.q/_mapping} ? $obj->{_/.$ed.q/_mapping} : 1;
99     my %tblopt = (-autoload => defined $obj->{_/.$ed.q/_mapping_autoload} ? $obj->{_/.$ed.q/_mapping_autoload} : 1);
100     /.$encode->{$ED};
101     }
102     $encode->{$ED} =~ s/\n/\n /g;
103     }
104     print <<EOH;
105    
106     package Encode::$Info{Name}::$encode->{ModuleName};
107     our \$VERSION = \$Encode::$Info{Name}::VERSION;
108     use base qw(Encode::Encoding);
109     __PACKAGE__->Define (qw/$encode->{Name} $encode->{Alias}/);
110    
111     =item $encode->{Name}
112    
113     $encode->{Description}@{[ $encode->{Alias} ? '
114     (Alias: ' . join (', ', split /\s+/, $encode->{Alias}) . ')' : '' ]}
115    
116     =cut
117    
118     sub encode (\$\$;\$) {
119     my (\$obj, \$s, \$chk) = \@_;
120     $encode->{Encode}
121     \$_[1] = '' if \$chk;
122     return \$s;
123     }
124    
125     sub decode (\$\$;\$) {
126     my (\$obj, \$s, \$chk) = \@_;
127     $encode->{Decode}
128     \$_[1] = '' if \$chk;
129     return \$s;
130     }
131    
132     EOH
133     }
134    
135     print <<EOH;
136    
137     =back
138     @{[ $Info{'POD:ENCODING:POSTAMBLE'} ? qq(
139     $Info{'POD:ENCODING:POSTAMBLE'}
140     ) : '']}
141     =cut
142    
143     sub Encode::Encoding::__clone (\$) {
144     my \$self = shift;
145     bless {%\$self}, ref \$self;
146     }
147    
148     EOH
149    
150     for my $name (qw/EXAMPLE/, 'SEE ALSO', 'TO DO', qw/AUTHORS LICENSE/) {
151     if ($Info{qq(POD:$name)}) {
152     $Info{qq(POD:$name)} =~ s/%%([A-Za-z0-9_]+)%%/$ReplaceText{$1}/g;
153     print <<EOH;
154     =head1 $name
155    
156     $Info{qq(POD:$name)}
157    
158     EOH
159     }
160     }
161    
162     print <<EOH;
163     =cut
164    
165     1;
166     EOH
167    
168     sub ReplaceText () {
169     my %RT = (
170     GNUGPL2 => q{This program is free software; you can redistribute it and/or modify
171     it under the terms of the GNU General Public License as published by
172     the Free Software Foundation; either version 2 of the License, or
173     (at your option) any later version.
174    
175     This program is distributed in the hope that it will be useful,
176     but WITHOUT ANY WARRANTY; without even the implied warranty of
177     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
178     GNU General Public License for more details.
179    
180     You should have received a copy of the GNU General Public License
181     along with this program; see the file COPYING. If not, write to
182     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
183     Boston, MA 02111-1307, USA.},
184     PerlLicense => q{This library is free software; you can redistribute it
185     and/or modify it under the same terms as Perl itself.},
186     ReferenceIANAREG => q([IANAREG] "CHARACTER SETS", IANA <http://www.iana.org/>,
187     <http://www.iana.org/assignments/character-sets>.
188     The charset registry for IETF <http://www.ietf.org/> standards.),
189 wakaba 1.2 ReferenceJISX0212_1995 => q(JIS X 0221-1995, "Universal multi-octet coded character
190     set (UCS)", Japan Industrial Standards Committee
191     <http://www.jisc.go.jp/>, 1995. IDT with ISO/IEC 10646-1:1993
192     but three additional appendixes.),
193 wakaba 1.1 ReferenceJISX0208_1997 => q(JIS X 0208:1997, "7-bit and 8-bit double byte coded Kanji
194     set for information interchange", Japan Industrial Standards
195     Committee (JISC) <http://www.jisc.go.jp/>, 1997.),
196     ReferenceJISX0213_2000 => q(JIS X 0213:2000, "7-bit and 8-bit double byte coded extended Kanji
197     sets for information interchange", Japan Industrial Standards
198     Committee (JISC) <http://www.jisc.go.jp/>, 2000.),
199 wakaba 1.2 ReferenceRFC1468 => q(RFC 1468, "Japanese Character Encoding for Internet Messages",
200     J. Murai, et al, IETF <http://www.ietf.org/>, June 1993.
201     <urn:ietf:rfc:1468>.),
202 wakaba 1.1 YEAR => (gmtime)[5]+1900,
203     );
204     %RT;
205     }
206    
207     =head1 SEE ALSO
208    
209     L<Encode>, L<Encode::Table>
210    
211     =head1 LICENSE
212    
213     Copyright 2002 Wakaba <w@suika.fam.cx>
214    
215     This library is free software; you can redistribute it
216     and/or modify it under the same terms as Perl itself.
217    
218     Note that modules generated by this script should be
219     licensed by the licenser of source file so that copyright
220     holder of this script does not claim any right to them.
221    
222     =cut
223    
224 wakaba 1.2 # $Date: 2002/10/13 02:31:06 $
225 wakaba 1.1 ### esr2pm.pl ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24