diff options
-rw-r--r-- | epan/dissectors/Makefile.am | 37 | ||||
-rw-r--r-- | plugins/docsis/Makefile.am | 47 | ||||
-rw-r--r-- | plugins/docsis/plugin.c | 59 | ||||
-rw-r--r-- | tools/make-reg-dotc | 67 | ||||
-rw-r--r-- | tools/make-reg-dotc.py | 81 |
5 files changed, 172 insertions, 119 deletions
diff --git a/epan/dissectors/Makefile.am b/epan/dissectors/Makefile.am index 12f245178d..aeeed1dcb9 100644 --- a/epan/dissectors/Makefile.am +++ b/epan/dissectors/Makefile.am @@ -51,39 +51,44 @@ x11-declarations.h x11-register-info.h: $(PROC_X11_FIELDS) $(X11_FIELDS) $(PERL) $(PROC_X11_FIELDS) < $(X11_FIELDS) # -# Build "register.c", which contains a function "register_all_protocols()" -# that calls the register routines for all protocols. +# Build register.c, which contains a function register_all_protocols() +# that calls the register routines for all protocols and a function +# register_all_protocol_handoffs() that calls the handoff registration +# routines for all protocols. # -# We do this by grepping through sources. If that turns out to be too slow, +# We do this by scanning through sources. If that turns out to be too slow, # maybe we could just require every .o file to have an register routine # of a given name (packet-aarp.o -> proto_register_aarp, etc.). # -# Formatting conventions: The name of the proto_register_* routines must -# start in column zero, or must be preceded only by "void " starting in -# column zero, and must not be inside #if. +# Formatting conventions: The name of the proto_register_* routines an +# proto_reg_handoff_* routines must start in column zero, or must be +# preceded only by "void " starting in column zero, and must not be +# inside #if. # -# We assume that all dissector routines are in "packet-XXX.c" files. +# DISSECTOR_SRC is assumed to have all the files that need to be scanned. # # For some unknown reason, having a big "for" loop in the Makefile -# to scan all the "packet-XXX.c" files doesn't work with some "make"s; -# they seem to pass only the first few names in the list to the shell, -# for some reason. +# to scan all the files doesn't work with some "make"s; they seem to +# pass only the first few names in the list to the shell, for some +# reason. # -# Therefore, we have a script to generate the "register.c" file. +# Therefore, we have a script to generate the register.c file. # -# The first argument is the name of the file to write. -# The second argument is the directory in which the source files live. +# The first argument is the directory in which the source files live. +# The second argument is "dissectors", to indicate that we should build +# a register.c file for libethereal. # All subsequent arguments are the files to scan. # register.c: $(plugin_src) $(DISSECTOR_SRC) $(top_srcdir)/tools/make-reg-dotc \ $(top_srcdir)/tools/make-reg-dotc.py @if test -n $(PYTHON); then \ echo Making register.c with python ; \ - $(PYTHON) $(top_srcdir)/tools/make-reg-dotc.py $(srcdir) $(DISSECTOR_SRC) ; \ + $(PYTHON) $(top_srcdir)/tools/make-reg-dotc.py $(srcdir) \ + dissectors $(DISSECTOR_SRC) ; \ else \ echo Making register.c with shell script ; \ - $(top_srcdir)/tools/make-reg-dotc register.c $(srcdir) \ - $(plugin_src) $(DISSECTOR_SRC) ; \ + $(top_srcdir)/tools/make-reg-dotc $(srcdir) \ + $(plugin_src) dissectors $(DISSECTOR_SRC) ; \ fi # diff --git a/plugins/docsis/Makefile.am b/plugins/docsis/Makefile.am index d653db540f..d92815478d 100644 --- a/plugins/docsis/Makefile.am +++ b/plugins/docsis/Makefile.am @@ -31,7 +31,6 @@ plugindir = @plugindir@ plugin_LTLIBRARIES = docsis.la docsis_la_SOURCES = \ plugin.c \ - register.c \ moduleinfo.h \ $(DISSECTOR_SRC) \ $(DISSECTOR_INCLUDES) @@ -44,57 +43,63 @@ docsis_la_LIBADD = @PLUGIN_LIBS@ LIBS = # -# Build "register.c", which contains a function "register_all_protocols()" -# that calls the register routines for all protocols. +# Build plugin.c, which contains the plugin version[] string, a +# function plugin_register() that calls the register routines for all +# protocols, and a function plugin_reg_handoff() that calls the handoff +# registration routines for all protocols. # # We do this by scanning sources. If that turns out to be too slow, # maybe we could just require every .o file to have an register routine # of a given name (packet-aarp.o -> proto_register_aarp, etc.). # -# Formatting conventions: The name of the proto_register_* routines must -# start in column zero, or must be preceded only by "void " starting in -# column zero, and must not be inside #if. +# Formatting conventions: The name of the proto_register_* routines an +# proto_reg_handoff_* routines must start in column zero, or must be +# preceded only by "void " starting in column zero, and must not be +# inside #if. # # DISSECTOR_SRC is assumed to have all the files that need to be scanned. # # For some unknown reason, having a big "for" loop in the Makefile # to scan all the files doesn't work with some "make"s; they seem to -# pass only the first few names in the list to the shell, for some reason. +# pass only the first few names in the list to the shell, for some +# reason. # -# Therefore, we have a script to generate the "register.c" file. +# Therefore, we have a script to generate the plugin.c file. # -# The first argument is the name of the file to write. -# The second argument is the directory in which the source files live. +# The first argument is the directory in which the source files live. +# The second argument is "plugin", to indicate that we should build +# a plugin.c file for a plugin. # All subsequent arguments are the files to scan. # -register.c: $(DISSECTOR_SRC) $(top_srcdir)/tools/make-reg-dotc \ +plugin.c: $(DISSECTOR_SRC) $(top_srcdir)/tools/make-reg-dotc \ $(top_srcdir)/tools/make-reg-dotc.py @if test -n $(PYTHON); then \ - echo Making register.c with python ; \ - $(PYTHON) $(top_srcdir)/tools/make-reg-dotc.py $(srcdir) $(DISSECTOR_SRC) ; \ + echo Making plugin.c with python ; \ + $(PYTHON) $(top_srcdir)/tools/make-reg-dotc.py $(srcdir) \ + plugin $(DISSECTOR_SRC) ; \ else \ - echo Making register.c with shell script ; \ - $(top_srcdir)/tools/make-reg-dotc register.c $(srcdir) \ - $(plugin_src) $(DISSECTOR_SRC) ; \ + echo Making plugin.c with shell script ; \ + $(top_srcdir)/tools/make-reg-dotc $(srcdir) \ + $(plugin_src) plugin $(DISSECTOR_SRC) ; \ fi # -# Currently register.c can be included in the distribution because +# Currently plugin.c can be included in the distribution because # we always build all protocol dissectors. We used to have to check # whether or not to build the snmp dissector. If we again need to -# variably build something, making register.c non-portable, uncomment +# variably build something, making plugin.c non-portable, uncomment # the dist-hook line below. # -# Oh, yuk. We don't want to include "register.c" in the distribution, as +# Oh, yuk. We don't want to include "plugin.c" in the distribution, as # its contents depend on the configuration, and therefore we want it # to be built when the first "make" is done; however, Automake insists # on putting *all* source into the distribution. # # We work around this by having a "dist-hook" rule that deletes -# "register.c", so that "dist" won't pick it up. +# "plugin.c", so that "dist" won't pick it up. # #dist-hook: -# @rm -f $(distdir)/register.c +# @rm -f $(distdir)/plugin.c CLEANFILES = \ docsis \ diff --git a/plugins/docsis/plugin.c b/plugins/docsis/plugin.c deleted file mode 100644 index 602420cd8b..0000000000 --- a/plugins/docsis/plugin.c +++ /dev/null @@ -1,59 +0,0 @@ -/* plugin.c - * Standard plugin boilerplate - * - * $Id$ - * - * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@ethereal.com> - * Copyright 1998 Gerald Combs - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <gmodule.h> - -#include "moduleinfo.h" - -#ifndef ENABLE_STATIC -G_MODULE_EXPORT const gchar version[] = VERSION; - -/* Start the functions we need for the plugin stuff */ - -extern void register_all_protocols(void); -extern void register_all_protocol_handoffs(void); - -G_MODULE_EXPORT void -plugin_register (void) -{ - static gboolean registered = FALSE; - - /* register the new protocol, protocol fields, and subtrees */ - if (!registered) { - register_all_protocols(); - registered = TRUE; - } -} - -G_MODULE_EXPORT void -plugin_reg_handoff (void) -{ - register_all_protocol_handoffs(); -} - -#endif diff --git a/tools/make-reg-dotc b/tools/make-reg-dotc index a90019af05..b1b57e0ce2 100644 --- a/tools/make-reg-dotc +++ b/tools/make-reg-dotc @@ -5,30 +5,67 @@ # # -# The first argument is the output filename. +# The first argument is the directory in which the source files live. # - -outfile="$1" +srcdir="$1" shift # -# The second argument is the directory in which the source files live. +# The second argument is either "plugin" or "dissectors"; if it's +# "plugin", we build a plugin.c for a plugin, and if it's +# "dissectors", we build a register.c for libethereal. # -srcdir="$1" +registertype="$1" shift +if [ "$registertype" = plugin ] +then + outfile="plugin.c" +elif [ "$registertype" = dissectors ] + outfile="register.c" +else + echo "Unknown output type '$registertype'" 1>&2 + exit 1 +fi # # All subsequent arguments are the files to scan. # rm -f ${outfile}-tmp echo '/* Do not modify this file. */' >${outfile}-tmp -echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp -echo '#include "register.h"' >>${outfile}-tmp +echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp +if [ "$registertype" = plugin ] +then + cat <<"EOF" >>${outfile}-tmp +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <gmodule.h> +#include "register.h" + +#include "moduleinfo.h" + +#ifndef ENABLE_STATIC +G_MODULE_EXPORT const gchar version[] = VERSION; + +/* Start the functions we need for the plugin stuff */ + +G_MODULE_EXPORT void +plugin_register (void) +{ +EOF +else + cat <<"EOF" >>${outfile}-tmp +#include "register.h" +void +register_all_protocols(void) +{ +EOF +fi # # Build code to call all the protocol registration routines. # -echo 'void register_all_protocols(void) {' >>${outfile}-tmp for f in "$@" do if [ -f $f ] @@ -54,7 +91,19 @@ echo '}' >>${outfile}-tmp # # Build code to call all the protocol handoff registration routines. # -echo 'void register_all_protocol_handoffs(void) {' >>${outfile}-tmp +if [ "$registertype" = plugin ] +then + cat <<"EOF" >>${outfile}-tmp +G_MODULE_EXPORT void +plugin_reg_handoff(void) +{ +EOF +else + cat <<"EOF" >>${outfile}-tmp +void +register_all_protocol_handoffs(void) +{ +EOF for f in "$@" do if [ -f $f ] diff --git a/tools/make-reg-dotc.py b/tools/make-reg-dotc.py index 0ce7ed6029..9d6a232edb 100644 --- a/tools/make-reg-dotc.py +++ b/tools/make-reg-dotc.py @@ -15,24 +15,32 @@ 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. +# The second argument is either "plugin" or "dissectors"; if it's +# "plugin", we build a plugin.c for a plugin, and if it's +# "dissectors", we build a register.c for libethereal. # -files = sys.argv[2:] +registertype = sys.argv[2] +if registertype == "plugin": + tmp_filename = "plugin.c-tmp" + final_filename = "plugin.c" +elif registertype == "dissectors": + tmp_filename = "register.c-tmp" + final_filename = "register.c" +else: + print "Unknown output type '%s'" % registertype + sys.exit(1) + -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') +# +# All subsequent arguments are the files to scan. +# +files = sys.argv[3:] # Create the proper list of filenames filenames = [] @@ -83,8 +91,39 @@ for filename in filenames: proto_reg.sort() handoff_reg.sort() -# Make register_all_protocols() -reg_code.write("void register_all_protocols(void) {\n") +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") + +# Make the routine to register all protocols +if registertype == "plugin": + reg_code.write(""" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <gmodule.h> +#include "register.h" + +#include "moduleinfo.h" + +#ifndef ENABLE_STATIC +G_MODULE_EXPORT const gchar version[] = VERSION; + +/* Start the functions we need for the plugin stuff */ + +G_MODULE_EXPORT void +plugin_register (void) +{ +"""); +else: + reg_code.write(""" +#include "register.h" +void +register_all_protocols(void) +{ +"""); for symbol in proto_reg: line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) @@ -93,8 +132,19 @@ for symbol in proto_reg: reg_code.write("}\n") -# Make register_all_protocol_handoffs() -reg_code.write("void register_all_protocol_handoffs(void) {\n") +# Make the routine to register all protocol handoffs +if registertype == "plugin": + reg_code.write(""" +G_MODULE_EXPORT void +plugin_reg_handoff(void) +{ +"""); +else: + reg_code.write(""" +void +register_all_protocol_handoffs(void) +{ +"""); for symbol in handoff_reg: line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) @@ -102,6 +152,9 @@ for symbol in handoff_reg: reg_code.write("}\n") +if registertype == "plugin": + reg_code.write("#endif"); + # Close the file reg_code.close() |