diff options
author | Guy Harris <guy@alum.mit.edu> | 2006-04-19 09:26:16 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2006-04-19 09:26:16 +0000 |
commit | 008d0d6c0062c83706d53ce43e71402888ce5e44 (patch) | |
tree | af8470060a1a23c6a878f26f9c12b5578a95e9b3 /tools | |
parent | 2301071bda6f0e18ee24bb2a017c14faa88f3fdc (diff) |
Have make-reg-dotc and make-reg-dotc.py generate either a register.c for
libetheral or a plugin.c for a plugin, rather than having plugin.c for a
dissector call the routines from register.c. This means we don't ahve
multiple register_all_protocols() and register_all_protocol_handoffs()
routines, and that all the plugin boilerplate is automatically
generated.
svn path=/trunk/; revision=17903
Diffstat (limited to 'tools')
-rw-r--r-- | tools/make-reg-dotc | 67 | ||||
-rw-r--r-- | tools/make-reg-dotc.py | 81 |
2 files changed, 125 insertions, 23 deletions
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() |