decryption works, but addid doesn't because of unique pointer layers
[wireshark-sm.git] / tools / make-enums.py
blob74274313747d63ea1cd135e286fe35341e1c8c30
1 #!/usr/bin/env python3
3 # Copyright 2021, João Valverde <j@v6e.pt>
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 1998 Gerald Combs
9 # SPDX-License-Identifier: GPL-2.0-or-later
12 # Uses pyclibrary to parse C headers for enums and integer macro
13 # definitions. Exports that data to a C file for the introspection API.
15 # Requires: https://github.com/MatthieuDartiailh/pyclibrary
18 import os
19 import sys
20 import argparse
21 from pyclibrary import CParser
23 def parse_files(infiles, outfile):
25 print("Input: {}".format(infiles))
26 print("Output: '{}'".format(outfile))
28 parser = CParser(infiles)
30 source = """\
32 * Wireshark - Network traffic analyzer
33 * By Gerald Combs <gerald@wireshark.org>
34 * Copyright 1998 Gerald Combs
36 * SPDX-License-Identifier: GPL-2.0-or-later
38 * Generated automatically from %s. It can be re-created by running
39 * "tools/make-enums.py" from the top source directory.
41 * It is fine to edit this file by hand. Particularly if a symbol
42 * disappears from the API it can just be removed here. There is no
43 * requirement to re-run the generator script.
46 """ % (os.path.basename(sys.argv[0]))
48 for f in infiles:
49 source += '#include <{}>\n'.format(f)
51 source += """
52 #define ENUM(arg) { #arg, arg }
54 static ws_enum_t const all_enums[] = {
55 """
57 definitions = parser.defs['values']
58 symbols = list(definitions.keys())
59 symbols.sort()
61 for s in symbols:
62 if isinstance(definitions[s], int):
63 source += ' ENUM({}),\n'.format(s)
65 source += """\
66 { NULL, 0 },
68 """
70 try:
71 fh = open(outfile, 'w')
72 except OSError:
73 sys.exit('Unable to write ' + outfile + '.\n')
75 fh.write(source)
76 fh.close()
78 epan_files = [
79 "epan/address.h",
80 "epan/ipproto.h",
81 "epan/proto.h",
82 "epan/ftypes/ftypes.h",
83 "epan/stat_groups.h",
85 parse_files(epan_files, "epan/introspection-enums.c")
87 wtap_files = [
88 "wiretap/wtap.h",
90 parse_files(wtap_files, "wiretap/introspection-enums.c")
93 # Editor modelines - https://www.wireshark.org/tools/modelines.html
95 # Local variables:
96 # c-basic-offset: 4
97 # indent-tabs-mode: nil
98 # End:
100 # vi: set shiftwidth=4 expandtab:
101 # :indentSize=4:noTabs=true: