aboutsummaryrefslogtreecommitdiffstats
path: root/tools/make-tap-reg.py
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2013-12-01 01:53:26 +0000
committerGerald Combs <gerald@wireshark.org>2013-12-01 01:53:26 +0000
commit4e2b6b13f6c71a81671fc4fb589f7919a81b931b (patch)
tree1c7ac3ed93df02422d03e751546cbaa0b5563e74 /tools/make-tap-reg.py
parentc02bbf98834fc5aced9de486232c21bd5855ba75 (diff)
Use 4-space (PEP 8) indentation. Add modelines.
svn path=/trunk/; revision=53685
Diffstat (limited to 'tools/make-tap-reg.py')
-rwxr-xr-xtools/make-tap-reg.py138
1 files changed, 75 insertions, 63 deletions
diff --git a/tools/make-tap-reg.py b/tools/make-tap-reg.py
index 76dbec7634..fa5ea743b1 100755
--- a/tools/make-tap-reg.py
+++ b/tools/make-tap-reg.py
@@ -47,16 +47,16 @@ srcdir = sys.argv[1]
#
registertype = sys.argv[2]
if registertype == "taps":
- tmp_filename = "wireshark-tap-register.c-tmp"
- final_filename = "wireshark-tap-register.c"
- cache_filename = "wireshark-tap-register-cache.pkl"
+ tmp_filename = "wireshark-tap-register.c-tmp"
+ final_filename = "wireshark-tap-register.c"
+ cache_filename = "wireshark-tap-register-cache.pkl"
elif registertype == "tshark-taps":
- tmp_filename = "tshark-tap-register.c-tmp"
- final_filename = "tshark-tap-register.c"
- cache_filename = "tshark-tap-register-cache.pkl"
+ tmp_filename = "tshark-tap-register.c-tmp"
+ final_filename = "tshark-tap-register.c"
+ cache_filename = "tshark-tap-register-cache.pkl"
else:
- print("Unknown output type '%s'" % registertype)
- sys.exit(1)
+ print("Unknown output type '%s'" % registertype)
+ sys.exit(1)
#
@@ -67,22 +67,22 @@ files = sys.argv[3:]
# Create the proper list of filenames
filenames = []
for file in files:
- if os.path.isfile(file):
- filenames.append(file)
- else:
- filenames.append("%s/%s" % (srcdir, file))
+ if os.path.isfile(file):
+ filenames.append(file)
+ else:
+ filenames.append("%s/%s" % (srcdir, file))
if len(filenames) < 1:
- print("No files found")
- sys.exit(1)
+ print("No files found")
+ sys.exit(1)
# Look through all files, applying the regex to each line.
# If the pattern matches, save the "symbol" section to the
# appropriate array.
regs = {
- 'tap_reg': [],
- }
+ 'tap_reg': [],
+ }
# For those that don't know Python, r"" indicates a raw string,
# devoid of Python escapes.
@@ -91,60 +91,60 @@ tap_regex1 = r"void\s+(?P<symbol>register_tap_listener_[_A-Za-z0-9]+)\s*\([^;]+$
# This table drives the pattern-matching and symbol-harvesting
patterns = [
- ( 'tap_reg', re.compile(tap_regex0) ),
- ( 'tap_reg', re.compile(tap_regex1) ),
- ]
+ ( 'tap_reg', re.compile(tap_regex0) ),
+ ( 'tap_reg', re.compile(tap_regex1) ),
+ ]
# Open our registration symbol cache
cache = None
if cache_filename:
- try:
- cache_file = open(cache_filename, 'rb')
- cache = pickle.load(cache_file)
- cache_file.close()
- except:
- cache = {}
+ try:
+ cache_file = open(cache_filename, 'rb')
+ cache = pickle.load(cache_file)
+ cache_file.close()
+ except:
+ cache = {}
# Grep
for filename in filenames:
- file = open(filename)
- cur_mtime = os.fstat(file.fileno())[ST_MTIME]
- if cache and filename in cache:
- cdict = cache[filename]
- if cur_mtime == cdict['mtime']:
-# print "Pulling %s from cache" % (filename)
- regs['tap_reg'].extend(cdict['tap_reg'])
- file.close()
- continue
- # We don't have a cache entry
- if cache is not None:
- cache[filename] = {
- 'mtime': cur_mtime,
- 'tap_reg': [],
- }
-# print "Searching %s" % (filename)
- for line in file.readlines():
- for action in patterns:
- regex = action[1]
- match = regex.search(line)
- if match:
- symbol = match.group("symbol")
- sym_type = action[0]
- regs[sym_type].append(symbol)
- if cache is not None:
-# print "Caching %s for %s: %s" % (sym_type, filename, symbol)
- cache[filename][sym_type].append(symbol)
- file.close()
+ file = open(filename)
+ cur_mtime = os.fstat(file.fileno())[ST_MTIME]
+ if cache and filename in cache:
+ cdict = cache[filename]
+ if cur_mtime == cdict['mtime']:
+# print "Pulling %s from cache" % (filename)
+ regs['tap_reg'].extend(cdict['tap_reg'])
+ file.close()
+ continue
+ # We don't have a cache entry
+ if cache is not None:
+ cache[filename] = {
+ 'mtime': cur_mtime,
+ 'tap_reg': [],
+ }
+# print "Searching %s" % (filename)
+ for line in file.readlines():
+ for action in patterns:
+ regex = action[1]
+ match = regex.search(line)
+ if match:
+ symbol = match.group("symbol")
+ sym_type = action[0]
+ regs[sym_type].append(symbol)
+ if cache is not None:
+# print "Caching %s for %s: %s" % (sym_type, filename, symbol)
+ cache[filename][sym_type].append(symbol)
+ file.close()
if cache is not None and cache_filename is not None:
- cache_file = open(cache_filename, 'wb')
- pickle.dump(cache, cache_file)
- cache_file.close()
+ cache_file = open(cache_filename, 'wb')
+ pickle.dump(cache, cache_file)
+ cache_file.close()
# Make sure we actually processed something
if len(regs['tap_reg']) < 1:
- print("No protocol registrations found")
- sys.exit(1)
+ print("No protocol registrations found")
+ sys.exit(1)
# Sort the lists to make them pretty
regs['tap_reg'].sort()
@@ -161,8 +161,8 @@ void register_all_tap_listeners(void) {
""");
for symbol in regs['tap_reg']:
- line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
- reg_code.write(line)
+ line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
+ reg_code.write(line)
reg_code.write("}\n")
@@ -172,10 +172,22 @@ reg_code.close()
# Remove the old final_file if it exists.
try:
- os.stat(final_filename)
- os.remove(final_filename)
+ os.stat(final_filename)
+ os.remove(final_filename)
except OSError:
- pass
+ pass
# Move from tmp file to final file
os.rename(tmp_filename, final_filename)
+
+#
+# Editor modelines - http://www.wireshark.org/tools/modelines.html
+#
+# Local variables:
+# c-basic-offset: 4
+# indent-tabs-mode: nil
+# End:
+#
+# vi: set shiftwidth=4 expandtab:
+# :indentSize=4:noTabs=true:
+#