File: generate-gperfs.py

package info (click to toggle)
systemd 259.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 113,388 kB
  • sloc: ansic: 727,211; xml: 121,125; python: 36,732; sh: 34,990; cpp: 946; makefile: 278; awk: 102; lisp: 13; sed: 1
file content (35 lines) | stat: -rwxr-xr-x 1,030 bytes parent folder | download | duplicates (2)
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
35
#!/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 [includes...]')

    name, prefix, file, *includes = sys.argv[1:]
    includes = [f"#include {i}" for i in includes]

    # Older versions of python don't allow backslashes
    # in f-strings so use chr(10) for newlines and chr(92)
    # for backslashes instead as a workaround.
    print(f"""\
%{{
_Pragma("GCC diagnostic ignored {chr(92)}"-Wimplicit-fallthrough{chr(92)}"")
#if __GNUC__ >= 15
_Pragma("GCC diagnostic ignored {chr(92)}"-Wzero-as-null-pointer-constant{chr(92)}"")
#endif
{chr(10).join(includes)}
%}}""")
    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))