Add script and region constants

These are extracted from the Universal Interfaces Script.h file.
This commit is contained in:
Dietrich Epp 2022-03-15 12:07:16 -04:00
parent 8713cb96aa
commit 7bc44f4a5a
4 changed files with 185 additions and 0 deletions

5
scripts/README.md Normal file
View File

@ -0,0 +1,5 @@
# Mac OS Region Definitions
This folder contains the script and region definitions for the Mac OS toolbox.
These constants are extracted from the `Script.h` file in Universal Interfaces.

44
scripts/extract.py Normal file
View File

@ -0,0 +1,44 @@
"""Extract script and region constants from Script.h."""
import csv
import re
import sys
from typing import List, Tuple
Item = Tuple[str, int]
def index_of(data: List[Item], key: str) -> int:
for i, (name, _) in enumerate(data):
if name == key:
return i
raise ValueError('missing value: {!r}'.format(key))
def slice(data: List[Item], first: str, last: str) -> List[Item]:
return data[index_of(data, first):index_of(data, last)+1]
def write_csv(fname: str, data: List[Item]) -> None:
with open(fname, 'w') as fp:
w = csv.writer(fp)
w.writerow(['Name', 'Value'])
for item in data:
w.writerow(item)
def main(argv: List[str]) -> None:
if len(argv) != 1:
print('usage: script_gen.py <Script.h>', file=sys.stderr)
raise SystemExit(2)
with open(argv[0], 'rb') as fp:
data = fp.read()
scripts: List[Item] = []
regions: List[Item] = []
for item in re.finditer(rb'^\s*(\w+)\s*=\s*(\d+)', data, re.MULTILINE):
name, value = item.groups()
if name.startswith(b'sm'):
scripts.append((name.decode('ASCII'), int(value)))
elif name.startswith(b'ver'):
regions.append((name.decode('ASCII'), int(value)))
write_csv('script.csv', slice(scripts, 'smRoman', 'smUninterp'))
write_csv('region.csv', slice(regions, 'verUS', 'verGreenland'))
if __name__ == '__main__':
main(sys.argv[1:])

101
scripts/region.csv Normal file
View File

@ -0,0 +1,101 @@
Name,Value
verUS,0
verFrance,1
verBritain,2
verGermany,3
verItaly,4
verNetherlands,5
verFlemish,6
verSweden,7
verSpain,8
verDenmark,9
verPortugal,10
verFrCanada,11
verNorway,12
verIsrael,13
verJapan,14
verAustralia,15
verArabic,16
verFinland,17
verFrSwiss,18
verGrSwiss,19
verGreece,20
verIceland,21
verMalta,22
verCyprus,23
verTurkey,24
verYugoCroatian,25
verNetherlandsComma,26
verBelgiumLuxPoint,27
verCanadaComma,28
verCanadaPoint,29
vervariantPortugal,30
vervariantNorway,31
vervariantDenmark,32
verIndiaHindi,33
verPakistanUrdu,34
verTurkishModified,35
verItalianSwiss,36
verInternational,37
verRomania,39
verGreecePoly,40
verLithuania,41
verPoland,42
verHungary,43
verEstonia,44
verLatvia,45
verSami,46
verFaroeIsl,47
verIran,48
verRussia,49
verIreland,50
verKorea,51
verChina,52
verTaiwan,53
verThailand,54
verScriptGeneric,55
verCzech,56
verSlovak,57
verFarEastGeneric,58
verMagyar,59
verBengali,60
verByeloRussian,61
verUkraine,62
verGreeceAlt,64
verSerbian,65
verSlovenian,66
verMacedonian,67
verCroatia,68
verGermanReformed,70
verBrazil,71
verBulgaria,72
verCatalonia,73
verMultilingual,74
verScottishGaelic,75
verManxGaelic,76
verBreton,77
verNunavut,78
verWelsh,79
verIrishGaelicScript,81
verEngCanada,82
verBhutan,83
verArmenian,84
verGeorgian,85
verSpLatinAmerica,86
verTonga,88
verFrenchUniversal,91
verAustria,92
verGujarati,94
verPunjabi,95
verIndiaUrdu,96
verVietnam,97
verFrBelgium,98
verUzbek,99
verSingapore,100
verNynorsk,101
verAfrikaans,102
verEsperanto,103
verMarathi,104
verTibetan,105
verNepal,106
verGreenland,107
1 Name Value
2 verUS 0
3 verFrance 1
4 verBritain 2
5 verGermany 3
6 verItaly 4
7 verNetherlands 5
8 verFlemish 6
9 verSweden 7
10 verSpain 8
11 verDenmark 9
12 verPortugal 10
13 verFrCanada 11
14 verNorway 12
15 verIsrael 13
16 verJapan 14
17 verAustralia 15
18 verArabic 16
19 verFinland 17
20 verFrSwiss 18
21 verGrSwiss 19
22 verGreece 20
23 verIceland 21
24 verMalta 22
25 verCyprus 23
26 verTurkey 24
27 verYugoCroatian 25
28 verNetherlandsComma 26
29 verBelgiumLuxPoint 27
30 verCanadaComma 28
31 verCanadaPoint 29
32 vervariantPortugal 30
33 vervariantNorway 31
34 vervariantDenmark 32
35 verIndiaHindi 33
36 verPakistanUrdu 34
37 verTurkishModified 35
38 verItalianSwiss 36
39 verInternational 37
40 verRomania 39
41 verGreecePoly 40
42 verLithuania 41
43 verPoland 42
44 verHungary 43
45 verEstonia 44
46 verLatvia 45
47 verSami 46
48 verFaroeIsl 47
49 verIran 48
50 verRussia 49
51 verIreland 50
52 verKorea 51
53 verChina 52
54 verTaiwan 53
55 verThailand 54
56 verScriptGeneric 55
57 verCzech 56
58 verSlovak 57
59 verFarEastGeneric 58
60 verMagyar 59
61 verBengali 60
62 verByeloRussian 61
63 verUkraine 62
64 verGreeceAlt 64
65 verSerbian 65
66 verSlovenian 66
67 verMacedonian 67
68 verCroatia 68
69 verGermanReformed 70
70 verBrazil 71
71 verBulgaria 72
72 verCatalonia 73
73 verMultilingual 74
74 verScottishGaelic 75
75 verManxGaelic 76
76 verBreton 77
77 verNunavut 78
78 verWelsh 79
79 verIrishGaelicScript 81
80 verEngCanada 82
81 verBhutan 83
82 verArmenian 84
83 verGeorgian 85
84 verSpLatinAmerica 86
85 verTonga 88
86 verFrenchUniversal 91
87 verAustria 92
88 verGujarati 94
89 verPunjabi 95
90 verIndiaUrdu 96
91 verVietnam 97
92 verFrBelgium 98
93 verUzbek 99
94 verSingapore 100
95 verNynorsk 101
96 verAfrikaans 102
97 verEsperanto 103
98 verMarathi 104
99 verTibetan 105
100 verNepal 106
101 verGreenland 107

35
scripts/script.csv Normal file
View File

@ -0,0 +1,35 @@
Name,Value
smRoman,0
smJapanese,1
smTradChinese,2
smKorean,3
smArabic,4
smHebrew,5
smGreek,6
smCyrillic,7
smRSymbol,8
smDevanagari,9
smGurmukhi,10
smGujarati,11
smOriya,12
smBengali,13
smTamil,14
smTelugu,15
smKannada,16
smMalayalam,17
smSinhalese,18
smBurmese,19
smKhmer,20
smThai,21
smLao,22
smGeorgian,23
smArmenian,24
smSimpChinese,25
smTibetan,26
smMongolian,27
smEthiopic,28
smGeez,28
smCentralEuroRoman,29
smVietnamese,30
smExtArabic,31
smUninterp,32
1 Name Value
2 smRoman 0
3 smJapanese 1
4 smTradChinese 2
5 smKorean 3
6 smArabic 4
7 smHebrew 5
8 smGreek 6
9 smCyrillic 7
10 smRSymbol 8
11 smDevanagari 9
12 smGurmukhi 10
13 smGujarati 11
14 smOriya 12
15 smBengali 13
16 smTamil 14
17 smTelugu 15
18 smKannada 16
19 smMalayalam 17
20 smSinhalese 18
21 smBurmese 19
22 smKhmer 20
23 smThai 21
24 smLao 22
25 smGeorgian 23
26 smArmenian 24
27 smSimpChinese 25
28 smTibetan 26
29 smMongolian 27
30 smEthiopic 28
31 smGeez 28
32 smCentralEuroRoman 29
33 smVietnamese 30
34 smExtArabic 31
35 smUninterp 32