Be a little less picky about EAPOL packet lengths. Someone sent in a
[obnox/wireshark/wip.git] / tools / make-dissector-reg
1 #! /bin/sh
2
3 #
4 # $Id$
5 #
6
7 #
8 # The first argument is the directory in which the source files live.
9 #
10 srcdir="$1"
11 shift
12
13 #
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.
17 #
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
29 fi
30
31 #
32 # All subsequent arguments are the files to scan.
33 #
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 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #include <gmodule.h>
45
46 #include "moduleinfo.h"
47
48 #ifndef ENABLE_STATIC
49 G_MODULE_EXPORT const gchar version[] = VERSION;
50
51 /* Start the functions we need for the plugin stuff */
52
53 G_MODULE_EXPORT void
54 plugin_register (void)
55 {
56 EOF
57 #
58 # Build code to call all the protocol registration routines.
59 #
60 for f in "$@"
61 do
62         if [ -f $f ]
63         then
64                 srcfile=$f
65         else
66                 srcfile=$srcdir/$f
67         fi
68         grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
69 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
70 for f in "$@"
71 do
72         if [ -f $f ]
73         then
74                 srcfile=$f
75         else
76                 srcfile=$srcdir/$f
77         fi
78         grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
79 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
80 else
81         cat <<"EOF" >>${outfile}-tmp
82 #include "register.h"
83 void
84 register_all_protocols(register_cb cb, gpointer client_data)
85 {
86 EOF
87 #
88 # Build code to call all the protocol registration routines.
89 #
90 for f in "$@"
91 do
92         if [ -f $f ]
93         then
94                 srcfile=$f
95         else
96                 srcfile=$srcdir/$f
97         fi
98         grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
99 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
100 for f in "$@"
101 do
102         if [ -f $f ]
103         then
104                 srcfile=$f
105         else
106                 srcfile=$srcdir/$f
107         fi
108         grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
109 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
110
111 fi
112 echo '}' >>${outfile}-tmp
113
114
115 #
116 # Build code to call all the protocol handoff registration routines.
117 #
118 if [ "$registertype" = plugin ]
119 then
120         cat <<"EOF" >>${outfile}-tmp
121 G_MODULE_EXPORT void
122 plugin_reg_handoff(void)
123 {
124 EOF
125 for f in "$@"
126 do
127         if [ -f $f ]
128         then
129                 srcfile=$f
130         else
131                 srcfile=$srcdir/$f
132         fi
133         grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
134 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
135 for f in "$@"
136 do
137         if [ -f $f ]
138         then
139                 srcfile=$f
140         else
141                 srcfile=$srcdir/$f
142         fi
143         grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
144 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
145 else
146         cat <<"EOF" >>${outfile}-tmp
147 void
148 register_all_protocol_handoffs(register_cb cb, gpointer client_data)
149 {
150 EOF
151 for f in "$@"
152 do
153         if [ -f $f ]
154         then
155                 srcfile=$f
156         else
157                 srcfile=$srcdir/$f
158         fi
159         grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
160 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
161 for f in "$@"
162 do
163         if [ -f $f ]
164         then
165                 srcfile=$f
166         else
167                 srcfile=$srcdir/$f
168         fi
169         grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
170 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
171 fi
172 echo '}' >>${outfile}-tmp
173 if [ "$registertype" = plugin ]
174 then
175         echo '#endif' >>${outfile}-tmp
176 else 
177         cat <<"EOF" >>${outfile}-tmp
178 gulong register_count(void)
179 {
180 EOF
181         proto_regs=`grep RA_REGISTER ${outfile}-tmp | wc -l`
182         handoff_regs=`grep RA_HANDOFF ${outfile}-tmp | wc -l`
183         echo "  return $proto_regs + $handoff_regs;" >>${outfile}-tmp
184         echo '}' >>${outfile}-tmp
185 fi
186 mv ${outfile}-tmp ${outfile}