Convert the quick setup chapter to AsciiDoc and start converting its
[metze/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 #include "config.h"
41
42 #include <gmodule.h>
43
44 #include "moduleinfo.h"
45 /* plugins are DLLs */
46 #define WS_BUILD_DLL
47 #include "ws_symbol_export.h"
48
49 #ifndef ENABLE_STATIC
50 WS_DLL_PUBLIC_DEF const gchar version[] = VERSION;
51
52 /* Start the functions we need for the plugin stuff */
53
54 WS_DLL_PUBLIC_DEF void
55 plugin_register (void)
56 {
57 EOF
58 #
59 # Build code to call all the protocol registration routines.
60 #
61 for f in "$@"
62 do
63         if [ -f $f ]
64         then
65                 srcfile=$f
66         else
67                 srcfile=$srcdir/$f
68         fi
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 "$@"
72 do
73         if [ -f $f ]
74         then
75                 srcfile=$f
76         else
77                 srcfile=$srcdir/$f
78         fi
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)
86 {
87 EOF
88 #
89 # Build code to call all the protocol registration routines.
90 #
91 for f in "$@"
92 do
93         if [ -f $f ]
94         then
95                 srcfile=$f
96         else
97                 srcfile=$srcdir/$f
98         fi
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 "$@"
102 do
103         if [ -f $f ]
104         then
105                 srcfile=$f
106         else
107                 srcfile=$srcdir/$f
108         fi
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
111
112 fi
113 echo '}' >>${outfile}-tmp
114
115
116 #
117 # Build code to call all the protocol handoff registration routines.
118 #
119 if [ "$registertype" = plugin ]
120 then
121         cat <<"EOF" >>${outfile}-tmp
122 WS_DLL_PUBLIC_DEF void
123 plugin_reg_handoff(void)
124 {
125 EOF
126 for f in "$@"
127 do
128         if [ -f $f ]
129         then
130                 srcfile=$f
131         else
132                 srcfile=$srcdir/$f
133         fi
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 "$@"
137 do
138         if [ -f $f ]
139         then
140                 srcfile=$f
141         else
142                 srcfile=$srcdir/$f
143         fi
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)
150 {
151 EOF
152 for f in "$@"
153 do
154         if [ -f $f ]
155         then
156                 srcfile=$f
157         else
158                 srcfile=$srcdir/$f
159         fi
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 "$@"
163 do
164         if [ -f $f ]
165         then
166                 srcfile=$f
167         else
168                 srcfile=$srcdir/$f
169         fi
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
172 fi
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)
180 {
181 EOF
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
186 fi
187
188 # Only overwrite outfile if it differs from newly generated file
189 diff ${outfile}-tmp ${outfile} >/dev/null || mv ${outfile}-tmp ${outfile}
190