2025-10-03 18:09:00 +02:00
|
|
|
#!/usr/bin/env python3
|
2025-10-03 16:17:33 +02:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
|
2017-03-25 21:31:16 -04:00
|
|
|
import sys
|
|
|
|
|
|
2025-10-03 18:09:00 +02:00
|
|
|
def defines(file):
|
2017-03-25 21:31:16 -04:00
|
|
|
lines = iter(open(file).read().splitlines())
|
|
|
|
|
for line in lines:
|
|
|
|
|
if line.startswith('#define SD_MESSAGE') and '_STR ' not in line:
|
|
|
|
|
if line.endswith('\\'):
|
|
|
|
|
line = line[:-1] + next(lines)
|
2025-10-03 18:09:00 +02:00
|
|
|
_, name, value = line.split()
|
|
|
|
|
assert 'SD_' in name
|
|
|
|
|
assert 'SD_ID128_MAKE' in value
|
|
|
|
|
yield name, value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(includefile, docfile, *headers):
|
|
|
|
|
# Collects all messages from all headers and saves the sorted list back to
|
|
|
|
|
# headers[0]. Writes includefile (C) and docfile (rst).
|
|
|
|
|
|
|
|
|
|
# Collect all messages into a single sorted, deduplicated list
|
|
|
|
|
defs = sum((list(defines(file)) for file in headers), start=[])
|
|
|
|
|
defs = sorted(set(defs))
|
|
|
|
|
|
|
|
|
|
with open(includefile, 'wt') as out:
|
|
|
|
|
print(f'Writing {out.name}…')
|
|
|
|
|
for name, value in defs:
|
|
|
|
|
print(f'add_id(m, "{name}", {name}) JOINER', file=out)
|
|
|
|
|
|
|
|
|
|
with open(headers[0], 'wt') as out:
|
|
|
|
|
print(f'Writing {out.name}…')
|
|
|
|
|
for name, value in defs:
|
|
|
|
|
print(f'#define {name} {value}', file=out)
|
|
|
|
|
|
|
|
|
|
old = open(docfile).read().splitlines()
|
|
|
|
|
|
|
|
|
|
with open(docfile, 'wt') as out:
|
|
|
|
|
print(f'Writing {out.name}…')
|
|
|
|
|
for line in old:
|
|
|
|
|
print(line, file=out)
|
|
|
|
|
if 'autogenerated' in line:
|
|
|
|
|
break
|
|
|
|
|
for name, value in defs:
|
|
|
|
|
print(f' .. autoattribute:: systemd.id128.{name}', file=out)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
includefile = sys.argv[1]
|
|
|
|
|
docfile = sys.argv[2]
|
|
|
|
|
headers = sys.argv[3:]
|
|
|
|
|
process(includefile, docfile, *headers)
|