summaryrefslogtreecommitdiff
path: root/ext/Encode/CN
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-02-16 16:06:00 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-02-16 16:06:00 +0000
commit0e567a6c2f13b1067ce2fdc0f21ff4e78c164191 (patch)
treeefad0789fa285273f7cf3fed7610b8488b08687a /ext/Encode/CN
parentab6ca9f42584e394b318813a606979492132f659 (diff)
downloadperl-0e567a6c2f13b1067ce2fdc0f21ff4e78c164191.tar.gz
Encode 0.40, from Dan Kogai.
p4raw-id: //depot/perl@14722
Diffstat (limited to 'ext/Encode/CN')
-rw-r--r--ext/Encode/CN/CN.pm8
-rw-r--r--ext/Encode/CN/Makefile.PL142
2 files changed, 150 insertions, 0 deletions
diff --git a/ext/Encode/CN/CN.pm b/ext/Encode/CN/CN.pm
new file mode 100644
index 0000000000..2aca19bd07
--- /dev/null
+++ b/ext/Encode/CN/CN.pm
@@ -0,0 +1,8 @@
+package Encode::CN;
+use Encode;
+our $VERSION = '0.02';
+use XSLoader;
+XSLoader::load('Encode::CN',$VERSION);
+
+1;
+__END__
diff --git a/ext/Encode/CN/Makefile.PL b/ext/Encode/CN/Makefile.PL
new file mode 100644
index 0000000000..37d19e0735
--- /dev/null
+++ b/ext/Encode/CN/Makefile.PL
@@ -0,0 +1,142 @@
+use 5.7.2;
+use strict;
+use ExtUtils::MakeMaker;
+
+my %tables = (EUC_CN => ['euc-cn.enc'],
+ GB2312 => ['gb2312.enc'],
+ GB12345 => ['gb12345.enc'],
+ CP936 => ['cp936.enc'],
+ );
+
+my $name = 'CN';
+
+WriteMakefile(
+ INC => "-I..",
+ NAME => 'Encode::'.$name,
+ VERSION_FROM => "$name.pm",
+ OBJECT => '$(O_FILES)',
+ 'dist' => {
+ COMPRESS => 'gzip -9f',
+ SUFFIX => 'gz',
+ DIST_DEFAULT => 'all tardist',
+ },
+ MAN3PODS => {},
+ # OS 390 winges about line numbers > 64K ???
+ XSOPT => '-nolinenumbers',
+ );
+
+package MY;
+
+sub post_initialize
+{
+ my ($self) = @_;
+ my %o;
+ my $x = $self->{'OBJ_EXT'};
+ # Add the table O_FILES
+ foreach my $e (keys %tables)
+ {
+ $o{$e.$x} = 1;
+ }
+ $o{"$name$x"} = 1;
+ $self->{'O_FILES'} = [sort keys %o];
+ my @files = ("$name.xs");
+ $self->{'C'} = ["$name.c"];
+ $self->{'H'} = [$self->catfile($self->updir,'encode.h')];
+ my %xs;
+ foreach my $table (keys %tables) {
+ push (@{$self->{'C'}},"$table.c");
+ # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
+ # get built.
+ foreach my $ext (qw($(OBJ_EXT) .c .h _def.h .fnm)) {
+ push (@files,$table.$ext);
+ }
+ }
+ $self->{'XS'} = { "$name.xs" => "$name.c" };
+ $self->{'clean'}{'FILES'} .= join(' ',@files);
+ open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
+ print XS <<'END';
+#include <EXTERN.h>
+#include <perl.h>
+#include <XSUB.h>
+#define U8 U8
+#include "../encode.h"
+END
+ foreach my $table (keys %tables) {
+ print XS qq[#include "${table}.h"\n];
+ }
+ print XS <<"END";
+
+static void
+Encode_XSEncoding(pTHX_ encode_t *enc)
+{
+ dSP;
+ HV *stash = gv_stashpv("Encode::XS", TRUE);
+ SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash);
+ int i = 0;
+ PUSHMARK(sp);
+ XPUSHs(sv);
+ while (enc->name[i])
+ {
+ const char *name = enc->name[i++];
+ XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
+ }
+ PUTBACK;
+ call_pv("Encode::define_encoding",G_DISCARD);
+ SvREFCNT_dec(sv);
+}
+
+MODULE = Encode::$name PACKAGE = Encode::$name
+BOOT:
+{
+END
+ foreach my $table (keys %tables) {
+ print XS qq[#include "${table}_def.h"\n];
+ }
+ print XS "}\n";
+ close(XS);
+ return "# Built $name.xs\n\n";
+}
+
+sub postamble
+{
+ my $self = shift;
+ my $dir = $self->catdir($self->updir,'Encode');
+ my $str = "# $name\$(OBJ_EXT) depends on .h and _def.h files not .c files - but all written by compile\n";
+ $str .= "$name.c : $name.xs ";
+ foreach my $table (keys %tables)
+ {
+ $str .= " $table.c";
+ }
+ $str .= "\n\n";
+ $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
+
+ my $compile = $self->catfile($self->updir,'compile');
+ foreach my $table (keys %tables)
+ {
+ my $numlines = 1;
+ my $lengthsofar = length($str);
+ my $continuator = '';
+ $str .= "$table.c : $compile Makefile.PL";
+ foreach my $file (@{$tables{$table}})
+ {
+ $str .= $continuator.' '.$self->catfile($dir,$file);
+ if ( length($str)-$lengthsofar > 128*$numlines )
+ {
+ $continuator .= " \\\n\t";
+ $numlines++;
+ } else {
+ $continuator = '';
+ }
+ }
+ $str .= "\n\t\$(PERL) $compile -o \$\@ -f $table.fnm\n\n";
+ open (FILELIST, ">$table.fnm")
+ || die "Could not open $table.fnm: $!";
+ foreach my $file (@{$tables{$table}})
+ {
+ print FILELIST $self->catfile($dir,$file) . "\n";
+ }
+ close(FILELIST);
+ }
+ return $str;
+}
+