3 # Wireshark - Network traffic analyzer
4 # By Gerald Combs <gerald@wireshark.org>
5 # Copyright 1998 Gerald Combs
7 # SPDX-License-Identifier: GPL-2.0-or-later
9 convert-proto-init.py - Remove explicit init of proto variables.
20 def convert_file(file):
23 with
open(file, 'r') as f
:
25 # Match the following proto, header field, expert info and subtree variables:
27 # static int proto_a = -1;
30 # static int hf_proto_a_value_1 = -1;
31 # int hf_proto_a_value_2 = - 1;
32 # int hf_proto_a_value_3=-1;
33 # /* static int hf_proto_a_unused_1 = -1; */
35 # static gint ett_proto_a_tree_1=-1;
36 # gint ett_proto_a_tree_2 = -1; /* A comment. */
38 # static expert_field ei_proto_a_expert_1 = EI_INIT;
40 lines
= re
.sub(r
'^((?://\s*|/[*]+\s*)?(?:static\s*| )?(?:g?int|expert_field)\s*(?:proto|hf|ett|ei)_[\w_]+)\s*=\s*(?:-\s*1|EI_INIT)\s*', r
'\1', lines
, flags
=re
.MULTILINE
)
41 except IsADirectoryError
:
42 sys
.stderr
.write(f
'{file} is a directory.\n')
44 except UnicodeDecodeError:
45 sys
.stderr
.write(f
"{file} isn't valid UTF-8.\n")
48 sys
.stderr
.write(f
'Unable to open {file}.\n')
51 with
open(file, 'w') as f
:
53 print(f
'Converted {file}')
56 parser
= argparse
.ArgumentParser(description
='Initialize static proto values to 0.')
57 parser
.add_argument('files', metavar
='FILE', nargs
='*')
58 args
= parser
.parse_args()
61 if platform
.system() == 'Windows':
62 for arg
in args
.files
:
63 files
+= glob
.glob(arg
)
72 if __name__
== "__main__":