~russellmcc/libvterm/libvterm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl

use strict;
use warnings;

my ( $encname ) = $ARGV[0] =~ m{/([^/.]+).tbl}
   or die "Cannot parse encoding name out of $ARGV[0]\n";

print <<"EOF";
static const struct StaticTableEncoding encoding_$encname = {
  { .decode = &decode_table },
  {
EOF

while( <> ) {
   s/\s*#.*//; # strip comment

   s{^(\d+)/(\d+)}{sprintf "[0x%02x]", $1*16 + $2}e; # Convert 3/1 to [0x31]
   s{"(.)"}{sprintf "0x%04x", ord $1}e;              # Convert "A" to 0x41
   s{U\+}{0x};                                       # Convert U+0041 to 0x0041

   s{$}{,}; # append comma

   print "    $_";
}

print <<"EOF";
  }
};
EOF