diff --git a/.bzrignore b/.bzrignore index 2891493a..a257efae 100644 --- a/.bzrignore +++ b/.bzrignore @@ -2,3 +2,4 @@ t/test t/suites.h t/externs.h t/harness +src/encoding/*.inc diff --git a/Makefile b/Makefile index d8110a1c..4d8f61ea 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ CFILES=$(wildcard src/*.c) OFILES=$(CFILES:.c=.o) HFILES=$(wildcard include/*.h) +TBLFILES=$(wildcard src/encoding/*.tbl) +INCFILES=$(TBLFILES:.tbl=.inc) + HFILES_INT=$(wildcard src/*.h) $(HFILES) LIBPIECES=vterm parser encoding state input pen unicode @@ -32,6 +35,11 @@ libvterm.so: $(addprefix src/, $(addsuffix .o, $(LIBPIECES))) src/%.o: src/%.c $(HFILES_INT) gcc -fPIC -o $@ -c $< $(CCFLAGS) +src/encoding/%.inc: src/encoding/%.tbl + perl -C tbl2inc_c.pl $< >$@ + +src/encoding.o: $(INCFILES) + # Need first to cancel the implict rule %.o: %.c diff --git a/src/encoding.c b/src/encoding.c index c0a4a7ad..0bf82455 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -197,12 +197,7 @@ static int decode_table(VTermEncoding *enc, uint32_t cp[], int *cpi, int cplen, return 1; } -static const struct StaticTableEncoding encoding_uk = { - { .decode = &decode_table }, - { - ['$'] = 0x00a3, - } -}; +#include "encoding/uk.inc" static struct { VTermEncodingType type; diff --git a/src/encoding/uk.tbl b/src/encoding/uk.tbl new file mode 100644 index 00000000..70f99815 --- /dev/null +++ b/src/encoding/uk.tbl @@ -0,0 +1 @@ +2/1 = "£" diff --git a/tbl2inc_c.pl b/tbl2inc_c.pl new file mode 100644 index 00000000..38c99635 --- /dev/null +++ b/tbl2inc_c.pl @@ -0,0 +1,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