summaryrefslogtreecommitdiffstats
path: root/tools/generate-gperfs.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /tools/generate-gperfs.py
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/generate-gperfs.py')
-rwxr-xr-xtools/generate-gperfs.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/generate-gperfs.py b/tools/generate-gperfs.py
new file mode 100755
index 0000000..3887bb6
--- /dev/null
+++ b/tools/generate-gperfs.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# pylint: disable=unbalanced-tuple-unpacking,consider-using-f-string,consider-using-with
+
+"""
+Generate %-from-name.gperf from %-list.txt
+"""
+
+import sys
+
+if __name__ == '__main__':
+ if len(sys.argv) != 4:
+ sys.exit(f'Usage: {sys.argv[0]} name prefix file')
+
+ name, prefix, file = sys.argv[1:]
+
+ print("""\
+%{
+#if __GNUC__ >= 7
+_Pragma("GCC diagnostic ignored \\"-Wimplicit-fallthrough\\"")
+#endif
+%}""")
+ print(f"""\
+struct {name}_name {{ const char* name; int id; }};
+%null-strings
+%%""")
+
+ for line in open(file):
+ print("{0}, {1}{0}".format(line.rstrip(), prefix))