| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
my ( $encname ) = $ARGV[0] =~ m{/([^/.]+).tbl} |
| 7 |
or die "Cannot parse encoding name out of $ARGV[0]\n"; |
| 8 |
|
| 9 |
print <<"EOF"; |
| 10 |
static const struct StaticTableEncoding encoding_$encname = { |
| 11 |
{ .decode = &decode_table }, |
| 12 |
{ |
| 13 |
EOF |
| 14 |
|
| 15 |
while( <> ) { |
| 16 |
s/\s*#.*//; # strip comment |
| 17 |
|
| 18 |
s{^(\d+)/(\d+)}{sprintf "[0x%02x]", $1*16 + $2}e; # Convert 3/1 to [0x31] |
| 19 |
s{"(.)"}{sprintf "0x%04x", ord $1}e; # Convert "A" to 0x41 |
| 20 |
s{U\+}{0x}; # Convert U+0041 to 0x0041 |
| 21 |
|
| 22 |
s{$}{,}; # append comma |
| 23 |
|
| 24 |
print " $_"; |
| 25 |
} |
| 26 |
|
| 27 |
print <<"EOF"; |
| 28 |
} |
| 29 |
}; |
| 30 |
EOF |