5 # create the init.lua file based on a template (stdin)
7 # (c) 2006, Luis E. Garcia Onatnon <luis@ontanon.org>
11 # Wireshark - Network traffic analyzer
12 # By Gerald Combs <gerald@wireshark.org>
13 # Copyright 2004 Gerald Combs
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 die "'$WSROOT' is not a directory" unless -d $WSROOT;
35 my $wtap_encaps_table = '';
36 my $ft_types_table = '';
42 my %replacements = %{{
43 WTAP_ENCAPS => \$wtap_encaps_table,
44 FT_TYPES => \$ft_types_table,
45 BASES => \$bases_table,
46 ENCODINGS => \$encodings,
47 EXPERT => \$expert_pi,
48 MENU_GROUPS => \$menu_groups,
56 my $template_filename = shift;
58 open TEMPLATE, "< $template_filename" or die "could not open '$template_filename': $!";
59 $template .= $_ while(<TEMPLATE>);
63 # Extract values from wiretap/wtap.h:
68 $wtap_encaps_table = "-- Wiretap encapsulations\nwtap = {\n";
70 open WTAP_H, "< $WSROOT/wiretap/wtap.h" or die "cannot open '$WSROOT/wiretap/wtap.h': $!";
73 if ( /^#define WTAP_ENCAP_([A-Z0-9_]+)\s+(\d+)/ ) {
74 $wtap_encaps_table .= "\t[\"$1\"] = $2,\n";
78 $wtap_encaps_table =~ s/,\n$/\n}\n/msi;
81 # Extract values from epan/ftypes/ftypes.h:
83 # values from enum fttype
86 $ft_types_table = " -- Field Types\nftypes = {\n";
90 open FTYPES_H, "< $WSROOT/epan/ftypes/ftypes.h" or die "cannot open '$WSROOT/epan/ftypes/ftypes.h': $!";
92 if ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) {
93 $ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
99 $ft_types_table =~ s/,\n$/\n}\n/msi;
102 # Extract values from epan/proto.h:
104 # values from enum base
105 # #defines for encodings and expert group and severity levels
108 $bases_table = "-- Display Bases\n base = {\n";
109 $encodings = "-- Encodings\n";
110 $expert_pi = "-- Expert flags and facilities\n";
114 open PROTO_H, "< $WSROOT/epan/proto.h" or die "cannot open '$WSROOT/epan/proto.h': $!";
116 if (/^\s+BASE_([A-Z_]+),/ ) {
117 $bases_table .= "\t[\"$1\"] = $base_num,\n";
121 if ( /^.define\s+(PI_[A-Z_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
122 my ($name, $value) = ($1, hex($2));
123 $expert_pi .= "$name = $value\n";
126 if ( /^.define\s+(ENC_[A-Z0-9_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
127 my ($name, $value) = ($1, hex($2));
128 $encodings .= "$name = $value\n";
134 # Extract values from stat_menu.h:
136 # MENU_X_X values for register_stat_group_t
139 $menu_groups .= "-- menu groups for register_menu\n";
142 open STAT_MENU, "< $WSROOT/stat_menu.h" or die "cannot open '$WSROOT/stat_menu.h': $!";
144 if (/REGISTER_([A-Z]+)_GROUP_([A-Z]+)/) {
145 $menu_groups .= "MENU_$1_$2 = $menu_i\n";
146 $menu_groups =~ s/_NONE//;
153 $bases_table .= "}\n\n";
154 $encodings .= "\n\n";
155 $expert_pi .= "\n\n";
157 for my $key (keys %replacements) {
158 $template =~ s/%$key%/${$replacements{$key}}/msig;