summaryrefslogtreecommitdiff
path: root/build/conv.pl
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-09-04 17:01:17 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-09-04 17:01:17 +0000
commit0f01495d34c2cefeb3a78e0646edbde076f8558c (patch)
treea60e0267a691c3fd61d2ca237148d663c1dc58de /build/conv.pl
parentd5bf11e5b58b3ff5a523257d2729e54790cdda24 (diff)
downloadlibparserutils-0f01495d34c2cefeb3a78e0646edbde076f8558c.tar.gz
libparserutils-0f01495d34c2cefeb3a78e0646edbde076f8558c.tar.bz2
Perl script to convert Unicode mapping tables to C structures
svn path=/trunk/libparserutils/; revision=5234
Diffstat (limited to 'build/conv.pl')
-rwxr-xr-xbuild/conv.pl49
1 files changed, 49 insertions, 0 deletions
diff --git a/build/conv.pl b/build/conv.pl
new file mode 100755
index 0000000..314b73f
--- /dev/null
+++ b/build/conv.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+# Convert Unicode mapping tables to C structures
+# Input files may be found at http://unicode.org/Public/MAPPINGS
+#
+# Usage: conv.pl <input_file>
+
+die "Usage: conv.pl <input_file>\n" if (scalar(@ARGV) != 1);
+
+my @table;
+
+open MAP, "<$ARGV[0]" or die "Failed opening $ARGV[0]: $!\n";
+
+while (<MAP>) {
+ next if (/^#/);
+
+ my @parts = split(/\s+/);
+
+ # Ignore ASCII part
+ next if (hex($parts[0]) < 0x80);
+
+ # Convert undefined entries to U+FFFF
+ if ($parts[1] =~ /^#/) {
+ push(@table, "0xFFFF");
+ } else {
+ push(@table, $parts[1]);
+ }
+}
+
+close MAP;
+
+# You'll have to go through and fix up the structure name
+print "static uint32_t ${ARGV[0]}[128] = {\n\t";
+
+my $count = 0;
+foreach my $item (@table) {
+ print "$item, ";
+ $count++;
+
+ if ($count % 8 == 0 && $count != 128) {
+ print "\n\t";
+ }
+}
+
+print "\n};\n\n";
+