blob: 527fc9829fcb2311489ff1c53ad55596d4ddfacb [file] [log] [blame]
Bram Moolenaare4f25e42017-07-07 11:54:15 +02001#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6my ( $encname ) = $ARGV[0] =~ m{/([^/.]+).tbl}
7 or die "Cannot parse encoding name out of $ARGV[0]\n";
8
9print <<"EOF";
10static const struct StaticTableEncoding encoding_$encname = {
11 {
12 NULL, /* init */
13 &decode_table /* decode */
14 },
15 {
16EOF
17
18my $row = 0;
19while( <> ) {
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
43while ($row < 128) {
44 print " 0x0, /* $row */\n";
45 ++$row;
46}
47
48print <<"EOF";
49 }
50};
51EOF