Bram Moolenaar | e4f25e4 | 2017-07-07 11:54:15 +0200 | [diff] [blame] | 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 | { |
| 12 | NULL, /* init */ |
| 13 | &decode_table /* decode */ |
| 14 | }, |
| 15 | { |
| 16 | EOF |
| 17 | |
| 18 | my $row = 0; |
| 19 | while( <> ) { |
| 20 | s/\s*#.*//; # strip comment |
| 21 | |
| 22 | if ($_ =~ m{^\d+/\d+}) { |
| 23 | my ($up, $low) = ($_ =~ m{^(\d+)/(\d+)}); |
| 24 | my $thisrow = $up * 16 + $low; |
| 25 | while ($row < $thisrow) { |
| 26 | print " 0x0, /* $row */\n"; |
| 27 | ++$row; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | s{^(\d+)/(\d+)}{""}e; # Remove 3/1 |
| 32 | s{ = }{""}e; # Remove " = " |
| 33 | s{"(.)"}{sprintf "0x%04x", ord $1}e; # Convert "A" to 0x41 |
| 34 | s{U\+}{0x}; # Convert U+0041 to 0x0041 |
| 35 | |
| 36 | s{$}{, /* $row */}; # append comma and index |
| 37 | |
| 38 | print " $_"; |
| 39 | |
| 40 | ++$row; |
| 41 | } |
| 42 | |
| 43 | while ($row < 128) { |
| 44 | print " 0x0, /* $row */\n"; |
| 45 | ++$row; |
| 46 | } |
| 47 | |
| 48 | print <<"EOF"; |
| 49 | } |
| 50 | }; |
| 51 | EOF |