Fix a typo.
[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 libethereal.
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 else
58         cat <<"EOF" >>${outfile}-tmp
59 #include "register.h"
60 void
61 register_all_protocols(void)
62 {
63 EOF
64 fi
65
66 #
67 # Build code to call all the protocol registration routines.
68 #
69 for f in "$@"
70 do
71         if [ -f $f ]
72         then
73                 srcfile=$f
74         else
75                 srcfile=$srcdir/$f
76         fi
77         grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
78 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
79 for f in "$@"
80 do
81         if [ -f $f ]
82         then
83                 srcfile=$f
84         else
85                 srcfile=$srcdir/$f
86         fi
87         grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
88 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
89 echo '}' >>${outfile}-tmp
90
91 #
92 # Build code to call all the protocol handoff registration routines.
93 #
94 if [ "$registertype" = plugin ]
95 then
96         cat <<"EOF" >>${outfile}-tmp
97 G_MODULE_EXPORT void
98 plugin_reg_handoff(void)
99 {
100 EOF
101 else
102         cat <<"EOF" >>${outfile}-tmp
103 void
104 register_all_protocol_handoffs(void)
105 {
106 EOF
107 fi
108 for f in "$@"
109 do
110         if [ -f $f ]
111         then
112                 srcfile=$f
113         else
114                 srcfile=$srcdir/$f
115         fi
116         grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
117 done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
118 for f in "$@"
119 do
120         if [ -f $f ]
121         then
122                 srcfile=$f
123         else
124                 srcfile=$srcdir/$f
125         fi
126         grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
127 done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
128 echo '}' >>${outfile}-tmp
129 if [ "$registertype" = plugin ]
130 then
131         echo '#endif' >>${outfile}-tmp
132 fi
133 mv ${outfile}-tmp ${outfile}