summaryrefslogtreecommitdiff
path: root/9p/linux-errno.h.gen
diff options
context:
space:
mode:
Diffstat (limited to '9p/linux-errno.h.gen')
-rwxr-xr-x9p/linux-errno.h.gen33
1 files changed, 33 insertions, 0 deletions
diff --git a/9p/linux-errno.h.gen b/9p/linux-errno.h.gen
new file mode 100755
index 0000000..749cd8e
--- /dev/null
+++ b/9p/linux-errno.h.gen
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+
+def print_errnos(txtlists: list[str]) -> None:
+ print(
+ f"/* Generated by `./9p/linux-errno.h.gen {' '.join(txtlists)}`. DO NOT EDIT! */"
+ )
+ errnos: dict[str, int] = {}
+ 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 = line.split(maxsplit=1)
+ num = int(_num)
+ name = name.strip()
+ errnos[name] = int(num)
+ namelen = max(len(name) for name in errnos.keys())
+ print()
+ print("#ifndef _9P_LINUX_ERRNO_H_")
+ print("#define _9P_LINUX_ERRNO_H_")
+ print()
+ for name in errnos:
+ print(f"#define LINUX_{name.ljust(namelen)} {errnos[name]}")
+ print()
+ print("#endif /* _9P_LINUX_ERRNO_H_ */")
+
+
+if __name__ == "__main__":
+ import sys
+
+ print_errnos(sys.argv[1:])