-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunicode-tool.py
executable file
·44 lines (30 loc) · 1.05 KB
/
unicode-tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python3
import sys
if len(sys.argv) == 1:
print('usage: ./unicode-tool.py FILE', file=sys.stderr)
print(file=sys.stderr)
print('FILE format: [NAME::STRING|# comment...]\\n...', file=sys.stderr)
sys.exit(1)
f = open(sys.argv[1], 'r')
data = f.read().split('\n')
f.close()
print('### Generated by unicode-tool.')
print()
print()
for line in data:
if line == '' or line.startswith('#'):
continue
name = line.split('::')[0]
value = line.split('::')[1].replace('\\:\\:', '::').replace('\\\\', '\\')
print('# ``' + value + '``')
G_value = bytes(value + '\0', encoding='utf-8')
# (gnu-version of string)
print('/alloc G_' + name + '[' + str(len(G_value)) + ']')
for i in range(len(G_value)):
print(str(G_value[i]) + ' ({G_' + name + '} ' + str(i) + ' +) =')
# (xmtwolime-version of string)
print('/alloc X_' + name + '[' + str(len(value) + 1) + ']')
for i in range(len(value)):
print(str(ord(value[i])) + ' ({X_' + name + '} ' + str(i) + ' +) =')
print('0 ({X_' + name + '} ' + str((len(value) + 1) - 1) + ' +) =')
print()