e0ecb78f8126b582e7453e6c6bbd0eccf290f22a
[m17n/m17n-db.git] / CASED.awk
1 # CASED.awk -- awk script to generate CASED.tab
2 # Copyright (C) 2005
3 #   National Institute of Advanced Industrial Science and Technology (AIST)
4 #   Registration Number H15PRO112
5
6 # This file is part of the m17n database; a sub-part of the m17n
7 # library.
8
9 # The m17n library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1 of
12 # the License, or (at your option) any later version.
13
14 # The m17n library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with the m17n library; if not, write to the Free
21 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # 02111-1307, USA.
23
24 BEGIN {
25   tohex["0"] = 1;
26   tohex["1"] = 2;
27   tohex["2"] = 3;
28   tohex["3"] = 4;
29   tohex["4"] = 5;
30   tohex["5"] = 6;
31   tohex["6"] = 7;
32   tohex["7"] = 8;
33   tohex["8"] = 9;
34   tohex["9"] = 10;
35   tohex["A"] = 11;
36   tohex["B"] = 12;
37   tohex["C"] = 13;
38   tohex["D"] = 14;
39   tohex["E"] = 15;
40   tohex["F"] = 16;
41   tohex["a"] = 11;
42   tohex["b"] = 12;
43   tohex["c"] = 13;
44   tohex["d"] = 14;
45   tohex["e"] = 15;
46   tohex["f"] = 16;
47
48   FILE = 1;
49   FS = ";";
50 }
51
52 function decode_hex(str, idx) {
53   n = 0;
54   len = length(str);
55   for (i = idx; i <= len; i++)
56     {
57       c = tohex[substr (str, i, 1)];
58       if (c == 0)
59         break;
60       n = n * 16 + c - 1;
61     }
62   return n;
63 }
64
65 function single (str, bit) {
66 i = decode_hex (str, 1);
67 if (cased[i] != bit)
68      cased[i] += bit;
69      }
70
71 function range (str, bit) {
72 end = decode_hex (str, index (str, "..") + 2);
73 for (i = decode_hex (str, 1); i <= end; i++)
74      if (cased[i] != bit)
75      cased[i] += bit;
76      }
77
78 FILE == 1 && /^[^#]/ {
79                 if ($3 ~ /L[ltu]/) single ($1, 1);
80                 else if ($3 ~ /Mn|Me|Cf|Lm|Sk/) range ($1, 2);
81                 }
82
83 /^# PropList-.+\.txt/ {
84 FILE = 2;
85 }
86
87 FILE == 2 && /^[^#;]+; *Other_(Upp|Low)ercase/ {
88 if (index ($1, ".")) range ($1, 1);
89 else single ($1, 1);
90 }
91
92 /^# WordBreakProperty-.+\.txt/ {
93 FILE = 3;
94 }
95
96 FILE == 3 && /^[^#;]+; *MidLetter/ {
97 if (index ($1, ".")) range ($1, 2);
98 else single ($1, 2);
99 }
100
101 END {
102 for (i in cased)
103      printf ("0x%X %d\n", i, cased[i]);
104      }