MSWSP: make printing of type optional in str_CBaseStorageVariant()
[wireshark-wip.git] / tools / make-dissector-reg
blob6233561c4af121868d0afe7561a5d97e800efdf6
1 #! /bin/sh
4 # $Id$
8 # The first argument is the directory in which the source files live.
10 srcdir="$1"
11 shift
14 # The second argument is either "plugin" or "dissectors"; if it's
15 # "plugin", we build a plugin.c for a plugin, and if it's
16 # "dissectors", we build a register.c for libwireshark.
18 registertype="$1"
19 shift
20 if [ "$registertype" = plugin ]
21 then
22 outfile="plugin.c"
23 elif [ "$registertype" = dissectors ]
24 then
25 outfile="register.c"
26 else
27 echo "Unknown output type '$registertype'" 1>&2
28 exit 1
32 # All subsequent arguments are the files to scan.
34 rm -f ${outfile}-tmp
35 echo '/* Do not modify this file. */' >${outfile}-tmp
36 echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp
37 if [ "$registertype" = plugin ]
38 then
39 cat <<"EOF" >>${outfile}-tmp
40 #include "config.h"
42 #include <gmodule.h>
44 #include "moduleinfo.h"
45 /* plugins are DLLs */
46 #define WS_BUILD_DLL
47 #include "ws_symbol_export.h"
49 #ifndef ENABLE_STATIC
50 WS_DLL_PUBLIC_DEF const gchar version[] = VERSION;
52 /* Start the functions we need for the plugin stuff */
54 WS_DLL_PUBLIC_DEF void
55 plugin_register (void)
57 EOF
59 # Build code to call all the protocol registration routines.
61 for f in "$@"
63 if [ -f $f ]
64 then
65 srcfile=$f
66 else
67 srcfile=$srcdir/$f
69 grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
70 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
71 for f in "$@"
73 if [ -f $f ]
74 then
75 srcfile=$f
76 else
77 srcfile=$srcdir/$f
79 grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
80 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
81 else
82 cat <<"EOF" >>${outfile}-tmp
83 #include "register.h"
84 void
85 register_all_protocols(register_cb cb, gpointer client_data)
87 EOF
89 # Build code to call all the protocol registration routines.
91 for f in "$@"
93 if [ -f $f ]
94 then
95 srcfile=$f
96 else
97 srcfile=$srcdir/$f
99 grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
100 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
101 for f in "$@"
103 if [ -f $f ]
104 then
105 srcfile=$f
106 else
107 srcfile=$srcdir/$f
109 grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
110 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
113 echo '}' >>${outfile}-tmp
117 # Build code to call all the protocol handoff registration routines.
119 if [ "$registertype" = plugin ]
120 then
121 cat <<"EOF" >>${outfile}-tmp
122 WS_DLL_PUBLIC_DEF void
123 plugin_reg_handoff(void)
126 for f in "$@"
128 if [ -f $f ]
129 then
130 srcfile=$f
131 else
132 srcfile=$srcdir/$f
134 grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
135 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
136 for f in "$@"
138 if [ -f $f ]
139 then
140 srcfile=$f
141 else
142 srcfile=$srcdir/$f
144 grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
145 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
146 else
147 cat <<"EOF" >>${outfile}-tmp
148 void
149 register_all_protocol_handoffs(register_cb cb, gpointer client_data)
152 for f in "$@"
154 if [ -f $f ]
155 then
156 srcfile=$f
157 else
158 srcfile=$srcdir/$f
160 grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
161 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
162 for f in "$@"
164 if [ -f $f ]
165 then
166 srcfile=$f
167 else
168 srcfile=$srcdir/$f
170 grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
171 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
173 echo '}' >>${outfile}-tmp
174 if [ "$registertype" = plugin ]
175 then
176 echo '#endif' >>${outfile}-tmp
177 else
178 cat <<"EOF" >>${outfile}-tmp
179 gulong register_count(void)
182 proto_regs=`grep RA_REGISTER ${outfile}-tmp | wc -l`
183 handoff_regs=`grep RA_HANDOFF ${outfile}-tmp | wc -l`
184 echo " return $proto_regs + $handoff_regs;" >>${outfile}-tmp
185 echo '}' >>${outfile}-tmp
188 # Only overwrite outfile if it differs from newly generated file
189 diff ${outfile}-tmp ${outfile} >/dev/null || mv ${outfile}-tmp ${outfile}