jis0212tojdx.pl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/user/local/bin/perl
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. sub jis0212tonum()
  6. {
  7. my($jis0212) = (@_);
  8. my($first,$second,$jnum);
  9. $first = hex(substr($jis0212,2,2));
  10. $second = hex(substr($jis0212,4,2));
  11. $jnum = (($first - 0x21) * 94);
  12. $jnum += $second - 0x21 ;
  13. return $jnum;
  14. }
  15. @map = {};
  16. sub readtable()
  17. {
  18. open(JIS0212, "<JIS0212") || die "cannot open JIS0212";
  19. while(<JIS0212>)
  20. {
  21. if(! /^#/) {
  22. ($j, $u, $r) = split(/\t/,$_);
  23. if(length($j) > 4)
  24. {
  25. $n = &jis0212tonum($j);
  26. $map{$n} = $u;
  27. }
  28. }
  29. }
  30. }
  31. ## add eudc to $map here
  32. sub printtable()
  33. {
  34. for($i=0;$i<94;$i++)
  35. {
  36. printf ( "/* 0x%2XXX */\n", ( $i + 0x21));
  37. printf " ";
  38. for($j=0;$j<94;$j++)
  39. {
  40. if("" == ($map{($i * 94 + $j)}))
  41. {
  42. print "0xFFFD,"
  43. }
  44. else
  45. {
  46. print $map{($i * 94 + $j)} . ",";
  47. }
  48. if( 7 == (($j + 1) % 8))
  49. {
  50. printf "/* 0x%2X%1X%1X*/\n", $i+0x21, 2+($j/16), (6==($j%16))?0:8;
  51. }
  52. }
  53. printf " /* 0x%2X%1X%1X*/\n", $i+0x21, 2+($j/16),(6==($j%16))?0:8;
  54. }
  55. }
  56. &readtable();
  57. &printtable();