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
|
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
import re
import shlex
import subprocess
import sys
OVERRIDES = {
'autoneg' : 'autonegotiation',
}
mode, cpp, header = sys.argv[1:]
xml = mode == '--xml'
command = [*shlex.split(cpp), '-include', header, '-']
out = subprocess.check_output(command, stdin=subprocess.DEVNULL, universal_newlines=True)
lines = iter(out.splitlines())
for line in lines:
if line.startswith('enum ethtool_link_mode_bit_indices {'):
break
entries = []
for line in lines:
if line.startswith('}'):
break
# ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0,
m = re.match(r'^\s*(ETHTOOL_LINK_MODE_((\d*).*)_BIT)\s*=\s*(\d+),', line)
if not m:
continue
enum, name, speed, value = m.groups()
name = name.lower().replace('_', '-')
name = OVERRIDES.get(name, name)
duplex = name.split('-')[-1].lower()
if duplex not in {'half', 'full'}:
duplex = ''
entries += [(enum, name, speed, value, duplex)]
if xml:
print(' <tbody>')
entries.sort(key=lambda entry: (int(entry[2]) if entry[2] else 1e20, entry[4], entry[1], entry[3]))
for enum, name, speed, value, duplex in entries:
if xml:
print(f'''\
<row><entry><option>{name}</option></entry>
<entry>{speed}</entry><entry>{duplex}</entry></row>
''')
else:
enum = f'[{enum}]'
print(f' {enum:50} = "{name}",')
if xml:
print(' </tbody>')
assert len(entries) >= 99
|