OSDN Git Service

ltj-unicode-ccfix.lua: catcode of ideographs, moved from ltj-unicode-ccfix.tex (cherr...
[luatex-ja/luatexja.git] / tool / ltj-unicode-ccfix_make2.pl
1 #!/usr/bin/env perl
2
3 # create ltj-unicode-ccfix.tex by processing Unicode data file
4 #       LineBreak.txt
5
6 # modified from unicode-char-prep.pl (part of the XeTeX typesetting system).
7 # original copyright is as follows:
8 #
9 # /****************************************************************************\
10 #  Part of the XeTeX typesetting system
11 #  Copyright (c) 1994-2008 by SIL International
12 #  Copyright (c) 2009 by Jonathan Kew
13
14 #  SIL Author(s): Jonathan Kew
15
16 # Permission is hereby granted, free of charge, to any person obtaining
17 # a copy of this software and associated documentation files (the
18 # "Software"), to deal in the Software without restriction, including
19 # without limitation the rights to use, copy, modify, merge, publish,
20 # distribute, sublicense, and/or sell copies of the Software, and to
21 # permit persons to whom the Software is furnished to do so, subject to
22 # the following conditions:
23
24 # The above copyright notice and this permission notice shall be
25 # included in all copies or substantial portions of the Software.
26
27 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 # NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
31 # FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
32 # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
35 # Except as contained in this notice, the name of the copyright holders
36 # shall not be used in advertising or otherwise to promote the sale,
37 # use or other dealings in this Software without prior written
38 # authorization from the copyright holders.
39 # \****************************************************************************/
40
41 die "usage: perl $0 LineBreak.txt > unicode-letters.tex\n"
42         unless $#ARGV == 0;
43
44 sub parse_unidata {
45         my (@u) = @_;
46         $lccode{$u[0]} = $u[13] if $u[13] ne '';
47         $lccode{$u[0]} = $u[0]  if $u[13] eq '' and ($u[2] =~ /^L/ or $u[12] ne '');
48         $uccode{$u[0]} = $u[12] if $u[12] ne '';
49         $uccode{$u[0]} = $u[0]  if $u[12] eq '' and ($u[2] =~ /^L/ or $u[13] ne '');
50         if ($u[2] =~ /^L/) {
51                 push(@letters, $u[0]);
52         }
53         elsif ($u[2] =~ /^M/) {
54                 push(@marks, $u[0]);
55         }
56         elsif (exists $lccode{$u[0]} or exists $uccode{$u[0]}) {
57                 push(@casesym, $u[0]);
58         }
59 }
60
61
62 my ($start, $end);
63 $date = `date`;
64 chomp $date;
65 print << "__EOT__";
66 -- Do not edit this file!
67 -- Created from LineBreak.txt by ltj-unicode-ccfix_make.pl on $date.
68 -- In case of errors, fix the Perl script instead.
69 __EOT__
70
71 %lineBreakClass = (
72         'ID' => 1,              # ideograph
73 );
74
75
76 print << '__EOT__';
77 if tex.getcatcode(0x6F22)==12 then
78   local tex_catcode = tex.setcatcode
79   local function set_letter(b,e)
80     for i=b,e do tex_catcode('global', i, 11) end
81   end
82
83 __EOT__
84
85 open LineBreak, $ARGV[0] or die "can't read $ARGV[0]";
86 while (<LineBreak>) {
87         chomp;
88         s/ *#.*//;
89         s/ +$//;
90         if (m/([0-9A-F]{4,6})(?:\.\.([0-9A-F]{4,6}))?;(..)/) {
91                 $s = $1;
92                 $e = $2;
93                 $lb = $3;
94                 $e = $s if $e eq '';
95                 if (exists $lineBreakClass{$lb}) {
96                         if ($lineBreakClass{$lb} == 1) {
97                                 # ideographs: set whole range to class 1
98                                 print "  set_letter(0x$s,0x$e)\n";
99                         }
100                 }
101         }
102 }
103 close LineBreak;
104
105 print << '__EOT__';
106
107 end
108
109 __EOT__