0d6ebc9c458b40eb628529de871477cdb8d7fff8
3 # This script generates sbcsdat.c (the data for all the SBCSes) from its
4 # source form sbcs.dat.
7 $outfile = "sbcsdat.c";
10 open BAR
, ">$outfile";
14 print " * sbcsdat.c - data definitions for single-byte character sets.\n";
16 print " * Generated by sbcsgen.pl from sbcs.dat.\n";
17 print " * You should edit those files rather than editing this one.\n";
20 print "#ifndef ENUM_CHARSETS\n";
22 print "#include \"charset.h\"\n";
23 print "#include \"internal.h\"\n";
26 my $charsetname = undef;
29 my @charsetnames = ();
33 if (/^charset (.*)$/) {
36 } elsif (/^[0-9a-fA-FX]/) {
37 push @vals, map { $_ eq "XXXX" ?
-1 : hex $_ } split / +/, $_;
38 if (scalar @vals > 256) {
39 die "$infile:$.: charset $charsetname has more than 256 values\n";
40 } elsif (scalar @vals == 256) {
41 &outcharset
($charsetname, @vals);
42 push @charsetnames, $charsetname;
49 print "#else /* ENUM_CHARSETS */\n";
52 foreach $i (@charsetnames) {
53 print "ENUM_CHARSET($i)\n";
57 print "#endif /* ENUM_CHARSETS */\n";
60 my ($name, @vals) = @_;
61 my ($prefix, $i, @sorted);
63 print "static const sbcs_data data_$name = {\n";
67 for ($i = 0; $i < 256; $i++) {
69 printf "%sERROR ", $prefix;
71 printf "%s0x%04x", $prefix, $vals[$i];
72 push @sorted, [$i, $vals[$i]];
81 @sorted = sort { $a->[1] <=> $b->[1] } @sorted;
83 for ($i = 0; $i < scalar @sorted; $i++) {
84 printf "%s0x%02x", $prefix, $sorted[$i]->[0];
91 printf "\n },\n %d\n", scalar @sorted;
93 print "const charset_spec charset_$name = {\n" .
94 " $name, read_sbcs, write_sbcs, &data_$name\n};\n\n";