-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.py
More file actions
28 lines (21 loc) · 913 Bytes
/
tables.py
File metadata and controls
28 lines (21 loc) · 913 Bytes
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
import os
import string
HERE = os.path.dirname(os.path.realpath(__file__))
assert os.path.exists(HERE) and os.path.isdir(HERE)
DIR = os.path.join(HERE, 'include/ebrew/cpp')
assert os.path.exists(DIR) and os.path.isdir(DIR)
def main():
with open(os.path.join(DIR, 'char-table.h'), 'w', encoding = 'utf-8') as f:
for i in sorted(string.ascii_letters + string.digits + "=()[]{}<>+-*/%^&_=:./;!~#,", key=ord):
ones = '1' * ord(i)
f.write(f'#define len_to_char_{ones}0 {i}\n')
with open(os.path.join(DIR, 'int-table.h'), 'w', encoding = 'utf-8') as f:
f.write(f'#define int_0 (0)\n')
for i in range(1, 256):
f.write(f'#define int_{i} (1, int_{i-1})\n')
def clean():
for f in (os.path.join(DIR, 'char-table.h'), os.path.join(DIR, 'int-table.h')):
if os.path.exists(f):
os.unlink(f)
if __name__ == '__main__':
main()