unihan2cns.pl 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/local/bin/perl -w
  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. use IO::File;
  6. my(%tagtofilemap);
  7. $tagtofilemap{"kCNS1986-1" } = IO::File->new("|sort> cns1986p1.txt")
  8. or die "cannot open cns1986p1.txt";
  9. $tagtofilemap{"kCNS1986-2" } = IO::File->new("|sort> cns1986p2.txt")
  10. or die "cannot open cns1986p2.txt";
  11. $tagtofilemap{"kCNS1986-E" } = IO::File->new("|sort> cns1986p14.txt")
  12. or die "cannot open cns1986p14.txt";
  13. $tagtofilemap{"kCNS1992-1" } = IO::File->new("|sort> cns1992p1.txt")
  14. or die "cannot open cns1992p1.txt";
  15. $tagtofilemap{"kCNS1992-2" } = IO::File->new("|sort> cns1992p2.txt")
  16. or die "cannot open cns1992p2.txt";
  17. $tagtofilemap{"kCNS1992-3" } = IO::File->new("|sort> cns1992p3.txt")
  18. or die "cannot open cns1992p3.txt";
  19. $tagtofilemap{"kIRG_TSource-1" } = IO::File->new("|sort> cnsIRGTp1.txt")
  20. or die "cannot open cnsIRGTp1.txt";
  21. $tagtofilemap{"kIRG_TSource-2" } = IO::File->new("|sort> cnsIRGTp2.txt")
  22. or die "cannot open cnsIRGTp2.txt";
  23. $tagtofilemap{"kIRG_TSource-3" } = IO::File->new("|sort> cnsIRGTp3.txt")
  24. or die "cannot open cnsIRGTp3.txt";
  25. $tagtofilemap{"kIRG_TSource-4" } = IO::File->new("|sort> cnsIRGTp4.txt")
  26. or die "cannot open cnsIRGTp4.txt";
  27. $tagtofilemap{"kIRG_TSource-5" } = IO::File->new("|sort> cnsIRGTp5.txt")
  28. or die "cannot open cnsIRGTp5.txt";
  29. $tagtofilemap{"kIRG_TSource-6" } = IO::File->new("|sort> cnsIRGTp6.txt")
  30. or die "cannot open cnsIRGTp6.txt";
  31. $tagtofilemap{"kIRG_TSource-7" } = IO::File->new("|sort> cnsIRGTp7.txt")
  32. or die "cannot open cnsIRGTp7.txt";
  33. $tagtofilemap{"kIRG_TSource-F" } = IO::File->new("|sort> cnsIRGTp15.txt")
  34. or die "cannot open cnsIRGTp15.txt";
  35. $tagtofilemap{"kIRG_TSource-3ExtB" } = IO::File->new("|sort> cnsIRGTp3ExtB.txt")
  36. or die "cannot open cnsIRGTp3ExtB.txt";
  37. $tagtofilemap{"kIRG_TSource-4ExtB" } = IO::File->new("|sort> cnsIRGTp4ExtB.txt")
  38. or die "cannot open cnsIRGTp4ExtB.txt";
  39. $tagtofilemap{"kIRG_TSource-5ExtB" } = IO::File->new("|sort> cnsIRGTp5ExtB.txt")
  40. or die "cannot open cnsIRGTp5ExtB.txt";
  41. $tagtofilemap{"kIRG_TSource-6ExtB" } = IO::File->new("|sort> cnsIRGTp6ExtB.txt")
  42. or die "cannot open cnsIRGTp6ExtB.txt";
  43. $tagtofilemap{"kIRG_TSource-7ExtB" } = IO::File->new("|sort> cnsIRGTp7ExtB.txt")
  44. or die "cannot open cnsIRGTp7ExtB.txt";
  45. $tagtofilemap{"kIRG_TSource-FExtB" } = IO::File->new("|sort> cnsIRGTp15ExtB.txt")
  46. or die "cannot open cnsIRGTp15ExtB.txt";
  47. $nonhan = IO::File->new("< nonhan.txt")
  48. or die "cannot open nonhan.txt";
  49. while(defined($line = $nonhan->getline()))
  50. {
  51. $tagtofilemap{"kCNS1986-1"}->print($line);
  52. $tagtofilemap{"kCNS1992-1"}->print($line);
  53. $tagtofilemap{"kIRG_TSource-1"}->print($line);
  54. }
  55. while(<STDIN>)
  56. {
  57. if(/^U/)
  58. {
  59. chop();
  60. ($u,$tag,$value) = split(/\t/,$_);
  61. if($tag =~ m/(kCNS|kIRG_TSource)/)
  62. {
  63. ($pnum, $cvalue) = split(/-/,$value);
  64. $tagkey = $tag . "-" . $pnum;
  65. if(length($u) > 6) {
  66. $tagkey .= "ExtB";
  67. }
  68. $fd = $tagtofilemap{$tagkey};
  69. if(length($u) > 6) {
  70. $mapping = substr($u,3,4); # trunkcate 0x2 from 0x2abcd
  71. } else {
  72. $mapping = substr($u,2,4); # trunkcate 0x from 0xabcd
  73. }
  74. $fd->print("0x" . $cvalue . "\t0x" . $mapping . "\t# <CJK>\n");
  75. }
  76. }
  77. }