1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00
putty-source/charset/sbcsgen.pl
Simon Tatham ad2bbc52a4 First draft of Unicode support in pterm. It's pretty complete: it
does UTF-8 copy and paste (falling back to normal strings if
necessary), it understands X font encodings and translates things
accordingly so that if you have a Unicode font you can ask for
virtually any single-byte encoding and get it (Mac-Roman pterm,
anyone?), and so on. There's work left to be done (wide fonts for
CJK spring to mind), but I reckon this is a pretty good start.

[originally from svn r2395]
2002-12-31 12:20:34 +00:00

96 lines
2.2 KiB
Perl

#!/usr/bin/env perl -w
# This script generates sbcsdat.c (the data for all the SBCSes) from its
# source form sbcs.dat.
$infile = "sbcs.dat";
$outfile = "sbcsdat.c";
open FOO, $infile;
open BAR, ">$outfile";
select BAR;
print "/*\n";
print " * sbcsdat.c - data definitions for single-byte character sets.\n";
print " *\n";
print " * Generated by sbcsgen.pl from sbcs.dat.\n";
print " * You should edit those files rather than editing this one.\n";
print " */\n";
print "\n";
print "#ifndef ENUM_CHARSETS\n";
print "\n";
print "#include \"charset.h\"\n";
print "#include \"internal.h\"\n";
print "\n";
my $charsetname = undef;
my @vals = ();
my @charsetnames = ();
while (<FOO>) {
chomp;
if (/^charset (.*)$/) {
$charsetname = $1;
@vals = ();
} elsif (/^[0-9a-fA-FX]/) {
push @vals, map { $_ eq "XXXX" ? -1 : hex $_ } split / +/, $_;
if (scalar @vals > 256) {
die "$infile:$.: charset $charsetname has more than 256 values\n";
} elsif (scalar @vals == 256) {
&outcharset($charsetname, @vals);
push @charsetnames, $charsetname;
$charsetname = undef;
@vals = ();
}
}
}
print "#else /* ENUM_CHARSETS */\n";
print "\n";
foreach $i (@charsetnames) {
print "ENUM_CHARSET($i)\n";
}
print "\n";
print "#endif /* ENUM_CHARSETS */\n";
sub outcharset($@) {
my ($name, @vals) = @_;
my ($prefix, $i, @sorted);
print "static const sbcs_data data_$name = {\n";
print " {\n";
$prefix = " ";
@sorted = ();
for ($i = 0; $i < 256; $i++) {
if ($vals[$i] < 0) {
printf "%sERROR ", $prefix;
} else {
printf "%s0x%04x", $prefix, $vals[$i];
push @sorted, [$i, $vals[$i]];
}
if ($i % 8 == 7) {
$prefix = ",\n ";
} else {
$prefix = ", ";
}
}
print "\n },\n {\n";
@sorted = sort { $a->[1] <=> $b->[1] } @sorted;
$prefix = " ";
for ($i = 0; $i < scalar @sorted; $i++) {
printf "%s0x%02x", $prefix, $sorted[$i]->[0];
if ($i % 8 == 7) {
$prefix = ",\n ";
} else {
$prefix = ", ";
}
}
printf "\n },\n %d\n", scalar @sorted;
print "};\n";
print "const charset_spec charset_$name = {\n" .
" $name, read_sbcs, write_sbcs, &data_$name\n};\n\n";
}