Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. # Convert Unicode mapping tables to C structures
  7. # Input files may be found at http://unicode.org/Public/MAPPINGS
  8. #
  9. # Usage: conv.pl <input_file>
  10.  
  11. die "Usage: conv.pl <input_file>\n" if (scalar(@ARGV) != 1);
  12.  
  13. my @table;
  14.  
  15. open MAP, "<$ARGV[0]" or die "Failed opening $ARGV[0]: $!\n";
  16.  
  17. while (<MAP>) {
  18.         next if (/^#/);
  19.  
  20.         my @parts = split(/\s+/);
  21.  
  22.         # Ignore ASCII part
  23.         next if (hex($parts[0]) < 0x80);
  24.  
  25.         # Convert undefined entries to U+FFFF
  26.         if ($parts[1] =~ /^#/) {
  27.                 push(@table, "0xFFFF");
  28.         } else {
  29.                 push(@table, $parts[1]);
  30.         }
  31. }
  32.  
  33. close MAP;
  34.  
  35. # You'll have to go through and fix up the structure name
  36. print "static uint32_t ${ARGV[0]}[128] = {\n\t";
  37.  
  38. my $count = 0;
  39. foreach my $item (@table) {
  40.         print "$item, ";
  41.         $count++;
  42.  
  43.         if ($count % 8 == 0 && $count != 128) {
  44.                 print "\n\t";
  45.         }
  46. }
  47.  
  48. print "\n};\n\n";
  49.  
  50.