1#! /bin/sh 2 3# 4# $Id: make-dissector-reg 21716 2007-05-07 17:55:42Z gal $ 5# 6 7# 8# The first argument is the directory in which the source files live. 9# 10srcdir="$1" 11shift 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# 18registertype="$1" 19shift 20if [ "$registertype" = plugin ] 21then 22 outfile="plugin.c" 23elif [ "$registertype" = dissectors ] 24then 25 outfile="register.c" 26else 27 echo "Unknown output type '$registertype'" 1>&2 28 exit 1 29fi 30 31# 32# All subsequent arguments are the files to scan. 33# 34rm -f ${outfile}-tmp 35echo '/* Do not modify this file. */' >${outfile}-tmp 36echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp 37if [ "$registertype" = plugin ] 38then 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 49G_MODULE_EXPORT const gchar version[] = VERSION; 50 51/* Start the functions we need for the plugin stuff */ 52 53G_MODULE_EXPORT void 54plugin_register (void) 55{ 56EOF 57# 58# Build code to call all the protocol registration routines. 59# 60for f in "$@" 61do 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 ';' 69done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp 70for f in "$@" 71do 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 ';' 79done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp 80else 81 cat <<"EOF" >>${outfile}-tmp 82#include "register.h" 83void 84register_all_protocols(register_cb cb, gpointer client_data) 85{ 86EOF 87# 88# Build code to call all the protocol registration routines. 89# 90for f in "$@" 91do 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 ';' 99done | 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 100for f in "$@" 101do 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 ';' 109done | 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 111fi 112echo '}' >>${outfile}-tmp 113 114 115# 116# Build code to call all the protocol handoff registration routines. 117# 118if [ "$registertype" = plugin ] 119then 120 cat <<"EOF" >>${outfile}-tmp 121G_MODULE_EXPORT void 122plugin_reg_handoff(void) 123{ 124EOF 125for f in "$@" 126do 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 ';' 134done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp 135for f in "$@" 136do 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 ';' 144done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp 145else 146 cat <<"EOF" >>${outfile}-tmp 147void 148register_all_protocol_handoffs(register_cb cb, gpointer client_data) 149{ 150EOF 151for f in "$@" 152do 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 ';' 160done | 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 161for f in "$@" 162do 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 ';' 170done | 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 171fi 172echo '}' >>${outfile}-tmp 173if [ "$registertype" = plugin ] 174then 175 echo '#endif' >>${outfile}-tmp 176else 177 cat <<"EOF" >>${outfile}-tmp 178gulong register_count(void) 179{ 180EOF 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 185fi 186mv ${outfile}-tmp ${outfile} 187