summaryrefslogtreecommitdiff
path: root/utils/tt2code
blob: e747bc5fc5c98a9c127776ad18385eb639b76fac (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl -W

print <<END;
/*
 * This file is part of NetSurf, http://netsurf.sourceforge.net/
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2003 James Bursa <bursa\@users.sourceforge.net>
 */
 
#include "netsurf/utils/utils.h"

void unicode_transliterate(unsigned int c, char **r)
{
	char *s = *r;
	switch (c) {

END

LINE: while (<>) {
	chomp;
	next if m/^%/;
	next if m/^ *$/;

	m/^<U([0-9A-F]{4})> /g or die "invalid line '$_'";
	$z = $1;
	next if (hex($z) < 256);

	SUBST: while (m/\G"?((<U([0-9A-F]{4})>)*)"?;?/g) {
		next if $& eq '';
		$m = $1;
		if ($m eq '') {
			print "case 0x$z: break;\n";
			next;
		}
		chop $m;
		@s = split /></, substr $m, 1;
		foreach $s (@s) {
			$s = substr $s, 1;
			next SUBST if 255 < hex($s);
		}

		print "case 0x$z: ";
		foreach $s (@s) {
			print "*s++ = 0x$s; ";
		}
		print "break;\n";
		next LINE;
	}
}

print <<END;

default: *s++ = '?'; break;
	}

	*r = s;
}
END