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 $wtap_filetypes_table = '';
37 my $ft_types_table = '';
43 my %replacements = %{{
44 WTAP_ENCAPS
=> \
$wtap_encaps_table,
45 WTAP_FILETYPES
=> \
$wtap_filetypes_table,
46 FT_TYPES
=> \
$ft_types_table,
47 BASES
=> \
$bases_table,
48 ENCODINGS
=> \
$encodings,
49 EXPERT
=> \
$expert_pi,
50 MENU_GROUPS
=> \
$menu_groups,
58 my $template_filename = shift;
60 open TEMPLATE
, "< $template_filename" or die "could not open '$template_filename': $!";
61 $template .= $_ while(<TEMPLATE
>);
65 # Extract values from wiretap/wtap.h:
71 $wtap_encaps_table = "-- Wiretap encapsulations XXX\nwtap_encaps = {\n";
72 $wtap_filetypes_table = "-- Wiretap file types\nwtap_filetypes = {\n";
74 open WTAP_H
, "< $WSROOT/wiretap/wtap.h" or die "cannot open '$WSROOT/wiretap/wtap.h': $!";
77 if ( /^#define WTAP_ENCAP_([A-Z0-9_]+)\s+(\d+)/ ) {
78 $wtap_encaps_table .= "\t[\"$1\"] = $2,\n";
81 if ( /^#define WTAP_FILE_([A-Z0-9_]+)\s+(\d+)/ ) {
82 $wtap_filetypes_table .= "\t[\"$1\"] = $2,\n";
86 $wtap_encaps_table =~ s/,\n$/\n}\nwtap = wtap_encaps -- for bw compatibility\n/msi;
87 $wtap_filetypes_table =~ s/,\n$/\n}\n/msi;
90 # Extract values from epan/ftypes/ftypes.h:
92 # values from enum fttype
95 $ft_types_table = " -- Field Types\nftypes = {\n";
99 open FTYPES_H
, "< $WSROOT/epan/ftypes/ftypes.h" or die "cannot open '$WSROOT/epan/ftypes/ftypes.h': $!";
101 if ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) {
102 $ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
108 $ft_types_table =~ s/,\n$/\n}\n/msi;
111 # Extract values from epan/proto.h:
113 # values from enum base
114 # #defines for encodings and expert group and severity levels
117 $bases_table = "-- Display Bases\n base = {\n";
118 $encodings = "-- Encodings\n";
119 $expert_pi = "-- Expert flags and facilities\n";
123 open PROTO_H
, "< $WSROOT/epan/proto.h" or die "cannot open '$WSROOT/epan/proto.h': $!";
125 if (/^\s+BASE_([A-Z_]+),/ ) {
126 $bases_table .= "\t[\"$1\"] = $base_num,\n";
130 if ( /^.define\s+(PI_[A-Z_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
131 my ($name, $value) = ($1, hex($2));
132 $expert_pi .= "$name = $value\n";
135 if ( /^.define\s+(ENC_[A-Z0-9_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
136 my ($name, $value) = ($1, hex($2));
137 $encodings .= "$name = $value\n";
143 # Extract values from stat_menu.h:
145 # MENU_X_X values for register_stat_group_t
148 $menu_groups .= "-- menu groups for register_menu\n";
151 open STAT_MENU
, "< $WSROOT/stat_menu.h" or die "cannot open '$WSROOT/stat_menu.h': $!";
153 if (/REGISTER_([A-Z]+)_GROUP_([A-Z]+)/) {
154 $menu_groups .= "MENU_$1_$2 = $menu_i\n";
155 $menu_groups =~ s/_NONE//;
162 $bases_table .= "}\n\n";
163 $encodings .= "\n\n";
164 $expert_pi .= "\n\n";
166 for my $key (keys %replacements) {
167 $template =~ s/%$key%/${$replacements{$key}}/msig;