-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmold-export-rtf.py
executable file
·69 lines (52 loc) · 1.69 KB
/
mold-export-rtf.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
sources = []
for root, _, files in os.walk(sys.argv[1]):
for file in files:
full = Path(root, file)
fullname = str(full)
if not fullname.endswith(('.cc', '.h')):
continue
elif fullname.startswith(('third-party', 'macho')):
continue
elif 'arch' in fullname and 'x86' not in fullname:
continue
elif 'win32' in fullname or 'source-all' in fullname:
continue
elif 'objdir/' in fullname:
continue
sources.append(full)
def file_priority(filename):
if filename.endswith('.h'):
if 'mold.h' in filename:
p = 0
else:
p = 10
else:
p = 100
if filename.startswith('elf/'):
p += 1
return p
sources = sorted(sources, key=lambda x: (file_priority(str(x)), x))
print('File count:', len(sources))
def cat_n(lines):
for i, line in enumerate(lines):
sline = line.lstrip()
spaces = len(line) - len(sline)
yield f'{i + 1:4d} {" " * (spaces // 2)}{sline}'
with open('source-all.cc', 'w') as w:
w.write('/*\n')
for i, source in enumerate(sources):
loc = len(source.read_text().splitlines())
w.write(f' {i + 1}: {str(source).upper()} ({loc} LOC)\n')
w.write('*/\n')
w.write('\n')
for i, source in enumerate(sources):
lines = source.read_text().splitlines()
lines = list(cat_n(lines))
N = 60
lines = ['', '/* ' + '#' * 60,
f' {i + 1} / {len(sources)}: ' + str(source).upper(), ' ' + '#' * 60 + ' */', ''] + lines + ['']
w.write('\n'.join(lines))