winucase_convert.pl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/perl -w
  2. #
  3. # winucase_convert.pl -- convert "Windows 8 Upper Case Mapping Table.txt" to
  4. # a two-level set of C arrays.
  5. #
  6. # Copyright 2013: Jeff Layton <jlayton@redhat.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. while(<>) {
  22. next if (!/^0x(..)(..)\t0x(....)\t/);
  23. $firstchar = hex($1);
  24. $secondchar = hex($2);
  25. $uppercase = hex($3);
  26. $top[$firstchar][$secondchar] = $uppercase;
  27. }
  28. for ($i = 0; $i < 256; $i++) {
  29. next if (!$top[$i]);
  30. printf("static const wchar_t t2_%2.2x[256] = {", $i);
  31. for ($j = 0; $j < 256; $j++) {
  32. if (($j % 8) == 0) {
  33. print "\n\t";
  34. } else {
  35. print " ";
  36. }
  37. printf("0x%4.4x,", $top[$i][$j] ? $top[$i][$j] : 0);
  38. }
  39. print "\n};\n\n";
  40. }
  41. printf("static const wchar_t *const toplevel[256] = {", $i);
  42. for ($i = 0; $i < 256; $i++) {
  43. if (($i % 8) == 0) {
  44. print "\n\t";
  45. } elsif ($top[$i]) {
  46. print " ";
  47. } else {
  48. print " ";
  49. }
  50. if ($top[$i]) {
  51. printf("t2_%2.2x,", $i);
  52. } else {
  53. print "NULL,";
  54. }
  55. }
  56. print "\n};\n\n";