blob: b896384e31fb11167e5c3131699023ebbe27efef (
plain)
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
|
#!/usr/bin/env python
def print_errnos(txtlists: list[str]) -> None:
print(
f"/* 9p/linux-errno.h - Generated by `./9p/linux-errno.h.gen {' '.join(txtlists)}`. DO NOT EDIT! */"
)
errnos: dict[str, tuple[int, str]] = {}
for txtlist in sys.argv[1:]:
with open(txtlist, "r") as fh:
for line in fh:
if line.startswith("#"):
print(f"/* {line[1:].strip()} */")
continue
_num, name, desc = line.split(maxsplit=2)
num = int(_num)
desc = desc.strip()
errnos[name] = (num, desc)
print()
print("#ifndef _9P_LINUX_ERRNO_H_")
print("#define _9P_LINUX_ERRNO_H_")
print()
namelen = max(len(name) for name in errnos.keys())
numlen = max(len(str(num)) for (num, desc) in errnos.values())
for name in errnos:
print(f"#define LINUX_{name.ljust(namelen)} {str(errnos[name][0]).rjust(numlen)} /* {errnos[name][1]} */")
print()
print("#endif /* _9P_LINUX_ERRNO_H_ */")
if __name__ == "__main__":
import sys
print_errnos(sys.argv[1:])
|