aboutsummaryrefslogtreecommitdiffstats
path: root/make-reg-dotc.py
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>2001-01-11 07:21:35 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>2001-01-11 07:21:35 +0000
commitf9838e0b03e12b423df9604326b8a5b05c50a742 (patch)
tree52f0bba323bf911f778dda1b35d11362d649e9da /make-reg-dotc.py
parentb7a0290c6664d2cea87fc8324b7f4afe1d430851 (diff)
downloadwireshark-f9838e0b03e12b423df9604326b8a5b05c50a742.tar.gz
wireshark-f9838e0b03e12b423df9604326b8a5b05c50a742.tar.bz2
wireshark-f9838e0b03e12b423df9604326b8a5b05c50a742.zip
Add a python script which has the same functionality as the shell
script 'make-reg-dotc'. It is used only in the Win32 build because the make-reg-dotc shell script is *so* sloooooooooow on Win32, due to the multiple processes (grep, grep, sed) launched multiple times for each source file. By putting all the text-mangling logic into a single Python script, only one process is launched, and the source files are read only once. It's *a lot* faster... seconds instead of minutes. svn path=/trunk/; revision=2873
Diffstat (limited to 'make-reg-dotc.py')
-rwxr-xr-xmake-reg-dotc.py115
1 files changed, 115 insertions, 0 deletions
diff --git a/make-reg-dotc.py b/make-reg-dotc.py
new file mode 100755
index 0000000000..09c1c8fa85
--- /dev/null
+++ b/make-reg-dotc.py
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+#
+# Looks for registration routines in the protocol dissectors,
+# and assembles C code to call all the routines.
+#
+# This is a Python version of the make-reg-dotc shell script.
+# Running the shell script on Win32 is very very slow because of
+# all the process-launching that goes on --- multiple greps and
+# seds for each input file. I wrote this python version so that
+# less processes would have to be started.
+#
+# $Id: make-reg-dotc.py,v 1.1 2001/01/11 07:21:35 gram Exp $
+
+import os
+import sys
+import re
+
+tmp_filename = "register.c-tmp"
+final_filename = "register.c"
+
+#
+# The first argument is the directory in which the source files live.
+#
+srcdir = sys.argv[1]
+
+#
+# All subsequent arguments are the files to scan.
+#
+files = sys.argv[2:]
+
+reg_code = open(tmp_filename, "w")
+
+reg_code.write("/* Do not modify this file. */\n")
+reg_code.write("/* It is created automatically by the Makefile. */\n")
+reg_code.write('#include "register.h"\n')
+
+# Create the proper list of filenames
+filenames = []
+for file in files:
+ filenames.append("%s/%s" % (srcdir, file))
+
+
+# Look through all files, applying the regex to each line.
+# If the pattern matches, save the "symbol" section to the
+# appropriate array.
+proto_reg = []
+handoff_reg = []
+
+# For those that don't know Python, r"" indicates a raw string,
+# devoid of Python escapes.
+proto_regex0 = r"^(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+proto_regex1 = r"void\s+(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+handoff_regex0 = r"^(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+handoff_regex1 = r"void\s+(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+# This table drives the pattern-matching and symbol-harvesting
+patterns = [
+ ( proto_reg, re.compile(proto_regex0) ),
+ ( proto_reg, re.compile(proto_regex1) ),
+ ( handoff_reg, re.compile(handoff_regex0) ),
+ ( handoff_reg, re.compile(handoff_regex1) ),
+ ]
+
+# Grep
+for filename in filenames:
+ file = open(filename)
+# 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")
+ list = action[0]
+ list.append(symbol)
+ file.close()
+
+# Sort the lists to make them pretty
+proto_reg.sort()
+handoff_reg.sort()
+
+# Make register_all_protocols()
+reg_code.write("void register_all_protocols(void) {\n")
+
+for symbol in proto_reg:
+ line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
+ reg_code.write(line)
+
+reg_code.write("}\n")
+
+
+# Make register_all_protocol_handoffs()
+reg_code.write("void register_all_protocol_handoffs(void) {\n")
+
+for symbol in handoff_reg:
+ line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
+ reg_code.write(line)
+
+reg_code.write("}\n")
+
+# Close the file
+reg_code.close()
+
+# Remove the old final_file if it exists.
+try:
+ os.stat(final_filename)
+ os.remove(final_filename)
+except OSError:
+ pass
+
+# Move from tmp file to final file
+os.rename(tmp_filename, final_filename)
+
+