Skip to content

Commit

Permalink
Build encoding tables from textual descriptions rather than hardcoded…
Browse files Browse the repository at this point in the history
… lines of C
  • Loading branch information
leonerd committed Jul 27, 2010
1 parent 0c741e0 commit 1b7cbc6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions .bzrignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ t/test
t/suites.h
t/externs.h
t/harness
src/encoding/*.inc
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 1 addition & 6 deletions src/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/encoding/uk.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2/1 = "£"
30 changes: 30 additions & 0 deletions tbl2inc_c.pl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1b7cbc6

Please sign in to comment.