3 # Looks for registration routines in the source files
4 # and assembles C code to call all the routines.
6 # SPDX-License-Identifier: GPL-2.0-or-later
14 * Do not modify this file. Changes will be overwritten.
16 * Generated automatically using \"make-regs.py\".
21 def gen_prototypes(funcs
):
24 output
+= "void {}(void);\n".format(f
)
27 def gen_array(funcs
, name
):
28 output
= "{}[] = {{\n".format(name
)
30 output
+= " {{ \"{0}\", {0} }},\n".format(f
)
31 output
+= " { NULL, NULL }\n};\n"
34 def scan_files(infiles
, regs
):
36 with
open(path
, 'r', encoding
='utf8') as f
:
38 for array
, regex
in regs
:
39 matches
= re
.findall(regex
, source
)
42 def make_dissectors(outfile
, infiles
):
44 protos_regex
= r
"void\s+(proto_register_[\w]+)\s*\(\s*void\s*\)\s*{"
46 handoffs_regex
= r
"void\s+(proto_reg_handoff_[\w]+)\s*\(\s*void\s*\)\s*{"
48 scan_files(infiles
, [(protos
, protos_regex
), (handoffs
, handoffs_regex
)])
51 sys
.exit("No protocol registrations found.")
58 #include "dissectors.h"
60 const unsigned long dissector_reg_proto_count = {0};
61 const unsigned long dissector_reg_handoff_count = {1};
63 """.format(len(protos
), len(handoffs
))
65 output
+= gen_prototypes(protos
)
67 output
+= gen_array(protos
, "dissector_reg_t const dissector_reg_proto")
69 output
+= gen_prototypes(handoffs
)
71 output
+= gen_array(handoffs
, "dissector_reg_t const dissector_reg_handoff")
73 with
open(outfile
, "w") as f
:
76 print("Found {0} registrations and {1} handoffs.".format(len(protos
), len(handoffs
)))
78 def make_wtap_modules(outfile
, infiles
):
80 wtap_modules_regex
= r
"void\s+(register_[\w]+)\s*\(\s*void\s*\)\s*{"
82 scan_files(infiles
, [(wtap_modules
, wtap_modules_regex
)])
84 if len(wtap_modules
) < 1:
85 sys
.exit("No wiretap registrations found.")
91 #include "wtap_modules.h"
93 const unsigned wtap_module_count = {0};
95 """.format(len(wtap_modules
))
97 output
+= gen_prototypes(wtap_modules
)
99 output
+= gen_array(wtap_modules
, "wtap_module_reg_t const wtap_module_reg")
101 with
open(outfile
, "w") as f
:
104 print("Found {0} registrations.".format(len(wtap_modules
)))
106 def make_taps(outfile
, infiles
):
108 taps_regex
= r
"void\s+(register_tap_listener_[\w]+)\s*\(\s*void\s*\)\s*{"
110 scan_files(infiles
, [(taps
, taps_regex
)])
113 sys
.exit("No tap registrations found.")
121 const unsigned long tap_reg_listener_count = {0};
123 """.format(len(taps
))
125 output
+= gen_prototypes(taps
)
127 output
+= gen_array(taps
, "tap_reg_t const tap_reg_listener")
129 with
open(outfile
, "w") as f
:
132 print("Found {0} registrations.".format(len(taps
)))
136 sys
.exit("Usage: {0} <dissectors|taps> <outfile> <infiles...|@filelist>\n".format(sys
.argv
[0]))
138 if __name__
== "__main__":
139 if len(sys
.argv
) < 4:
143 outfile
= sys
.argv
[2]
144 if sys
.argv
[3].startswith("@"):
145 with
open(sys
.argv
[3][1:]) as f
:
146 infiles
= [line
.strip() for line
in f
.readlines()]
148 infiles
= sys
.argv
[3:]
150 if mode
== "dissectors":
151 make_dissectors(outfile
, infiles
)
152 elif mode
== "wtap_modules":
153 make_wtap_modules(outfile
, infiles
)
155 make_taps(outfile
, infiles
)