File: tbl2inc_c.pl

package info (click to toggle)
golang-github-ddevault-go-libvterm 0.0~git20190526.b7d861d-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 752 kB
  • sloc: ansic: 5,945; perl: 194; makefile: 113
file content (30 lines) | stat: -rw-r--r-- 622 bytes parent folder | download | duplicates (4)
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