#!../../perl -w
BEGIN {
- @INC = '../../lib';
- $ENV{PATH} .= ';../..' if $^O eq 'MSWin32';
+ unshift @INC, qw(../../lib ../../../lib);
+ $ENV{PATH} .= ';../..;../../..' if $^O eq 'MSWin32';
}
use strict;
use Getopt::Std;
my @orig_ARGV = @ARGV;
my $perforce = '$Id$';
-
sub encode_U
{
# UTF-8 encode long hand - only covers part of perl's range
my $uv = shift;
- if ($uv < 0x80)
- {
- return chr($uv)
- }
- if ($uv < 0x800)
- {
- return chr(($uv >> 6) | 0xC0).
- chr(($uv & 0x3F) | 0x80);
- }
- return chr(($uv >> 12) | 0xE0).
- chr((($uv >> 6) & 0x3F) | 0x80).
- chr(($uv & 0x3F) | 0x80);
+ # chr() works in native space so convert value from table
+ # into that space before using chr().
+ my $ch = chr(utf8::unicode_to_native($uv));
+ # Now get core perl to encode that the way it likes.
+ utf8::encode($ch);
+ return $ch;
}
sub encode_S
eval "\@ARGV = map(glob(\$_),\@ARGV)" if ($^O eq 'MSWin32');
my %opt;
-getopts('qo:f:n:',\%opt);
+getopts('qOo:f:n:',\%opt);
my $cname = (exists $opt{'o'}) ? $opt{'o'} : shift(@ARGV);
chmod(0666,$cname) if -f $cname && !-w $cname;
open(C,">$cname") || die "Cannot open $cname:$!";
my $dname = $cname;
-$dname =~ s/(\.[^\.]*)?$/.def/;
+$dname =~ s/(\.[^\.]*)?$/_def.h/;
my ($doC,$doEnc,$doUcm,$doPet);
/*
!!!!!!! DO NOT EDIT THIS FILE !!!!!!!
This file was autogenerated by:
- $^X $0 $cname @orig_ARGV
- (Repository $perforce)
+ $^X $0 @orig_ARGV
*/
END
}
print C "#define U8 U8\n";
}
print C "#include \"encode.h\"\n";
+
}
elsif ($cname =~ /\.enc$/)
{
my %encoding;
my %strings;
+my $saved = 0;
+my $subsave = 0;
+my $strings = 0;
sub cmp_name
{
foreach my $enc (sort cmp_name @encfiles)
{
my ($name,$sfx) = $enc =~ /^.*?([\w-]+)\.(enc|ucm)$/;
- $name = delete $opt{'n'} if exists $opt{'n'};
+ $name = $opt{'n'} if exists $opt{'n'};
if (open(E,$enc))
{
if ($sfx eq 'enc')
if ($doC)
{
+ print STDERR "Writing compiled form\n";
foreach my $name (sort cmp_name keys %encoding)
{
my ($e2u,$u2e,$erep,$min_el,$max_el) = @{$encoding{$name}};
my $sym = "${enc}_encoding";
$sym =~ s/\W+/_/g;
print H "extern encode_t $sym;\n";
- print D " Encode_Define(aTHX_ &$sym);\n";
+ print D " Encode_XSEncoding(aTHX_ &$sym);\n";
}
if ($cname =~ /(\w+)\.xs$/)
{
my $mod = $1;
+ print C <<'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);
+}
+
+END
+
print C "\nMODULE = Encode::$mod\tPACKAGE = Encode::$mod\n\n";
print C "BOOT:\n{\n";
print C "#include \"$dname\"\n";
}
close(D);
close(H);
+ printf STDERR "%d bytes in string tables\n",$strings;
+ printf STDERR "%d bytes (%.3g%%) saved spotting duplicates\n",$saved,100*$saved/$strings if $saved;
+ printf STDERR "%d bytes (%.3g%%) saved using substrings\n",$subsave,100*$subsave/$strings if $subsave;
}
elsif ($doEnc)
{
close(C);
+
sub compile_ucm
{
my ($fh,$name) = @_;
}
else
{
- # $name = lc($cs);
+ $name = $cs unless exists $opt{'n'};
}
my $erep;
my $urep;
push(@byte,$1) while $attr{'subchar'} =~ /\G\\x([0-9a-f]+)/icg;
$erep = join('',map(chr(hex($_)),@byte));
}
- print "Scanning $name ($cs)\n";
+ print "Reading $name ($cs)\n";
my $nfb = 0;
my $hfb = 0;
while (<$fh>)
}
}
+
+
sub outstring
{
my ($fh,$name,$s) = @_;
my $sym = $strings{$s};
- unless ($sym)
+ if ($sym)
{
- foreach my $o (keys %strings)
- {
- my $i = index($o,$s);
- if ($i >= 0)
- {
- $sym = $strings{$o};
- $sym .= sprintf("+0x%02x",$i) if ($i);
- return $sym;
- }
- }
+ $saved += length($s);
+ }
+ else
+ {
+ if ($opt{'O'}) {
+ foreach my $o (keys %strings)
+ {
+ my $i = index($o,$s);
+ if ($i >= 0)
+ {
+ $sym = $strings{$o};
+ $sym .= sprintf("+0x%02x",$i) if ($i);
+ $subsave += length($s);
+ $strings{$s} = $sym;
+ return $sym;
+ }
+ }
+ }
$strings{$s} = $sym = $name;
+ $strings += length($s);
printf $fh "\nstatic const U8 %s[%d] =\n",$name,length($s);
# Do in chunks of 16 chars to constrain line length
# Assumes ANSI C adjacent string litteral concatenation
my @uname;
sub char_names
{
- my $s = do "unicode/Name.pl";
+ my $s = do "unicore/Name.pl";
+ die "char_names: unicore/Name.pl: $!\n" unless defined $s;
pos($s) = 0;
while ($s =~ /\G([0-9a-f]+)\t([0-9a-f]*)\t(.*?)\s*\n/igc)
{
sub output_ucm
{
my ($fh,$name,$h,$rep,$min_el,$max_el) = @_;
- print $fh "# Written $perforce\n# $0 @orig_ARGV\n" unless $opt{'q'};
+ print $fh "# $0 @orig_ARGV\n" unless $opt{'q'};
print $fh "<code_set_name> \"$name\"\n";
char_names();
if (defined $min_el)