summaryrefslogtreecommitdiff
path: root/lib9p/linux-errno.h.gen
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/linux-errno.h.gen')
-rwxr-xr-xlib9p/linux-errno.h.gen34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib9p/linux-errno.h.gen b/lib9p/linux-errno.h.gen
new file mode 100755
index 0000000..b896384
--- /dev/null
+++ b/lib9p/linux-errno.h.gen
@@ -0,0 +1,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:])