2 # create the init.lua file based on a template (stdin)
6 # Wireshark - Network traffic analyzer
7 # By Gerald Combs <gerald@wireshark.org>
8 # Copyright 2004 Gerald Combs
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 my $wtap_encaps_table = '';
27 my $ft_types_table = '';
31 my %replacements = %{{
32 WTAP_ENCAPS => \$wtap_encaps_table,
33 FT_TYPES => \$ft_types_table,
34 BASES => \$bases_table,
35 EXPERT => \$expert_pi,
43 $template .= $_ while(<>);
47 # make wiretap encapusulation table
50 $wtap_encaps_table = "-- Wiretap encapsulations\nwtap = {\n";
52 open WTAP_H, "< ../../wiretap/wtap.h";
55 if ( /^#define WTAP_ENCAP_([A-Z0-9_]+)\s+(\d+)/ ) {
56 $wtap_encaps_table .= "\t[\"$1\"] = $2,\n";
60 $wtap_encaps_table =~ s/,\n$/\n}\n/msi;
66 $ft_types_table = " -- Field Types\nftypes = {\n";
70 open FTYPES_H, "< ../../epan/ftypes/ftypes.h";
72 if ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) {
73 $ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
79 $ft_types_table =~ s/,\n$/\n}\n/msi;
87 $bases_table = "-- Display Bases\n base = {\n";
88 $expert_pi = "-- Expert flags and facilities\n";
92 open PROTO_H, "< ../../epan/proto.h";
94 if (/^\s+BASE_([A-Z_]+),/ ) {
95 $bases_table .= "\t[\"$1\"] = $base_num,\n";
99 if ( /^.define\s+(PI_[A-Z_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
100 my ($name, $value) = ($1, hex($2));
101 $expert_pi .= "$name = $value\n";
106 $bases_table .= "}\n\n";
107 $expert_pi .= "\n\n";
114 for my $key (keys %replacements) {
115 $template =~ s/%$key%/${$replacements{$key}}/msig;