HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / wslua / make-init-lua.pl
blob878faf542b860b1799a2dc16e09115b5cf13174a
1 #!/usr/bin/perl
3 # make-init-lua.pl
5 # create the init.lua file based on a template (stdin)
7 # (c) 2006, Luis E. Garcia Onatnon <luis@ontanon.org>
9 # $Id$
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.
29 use strict;
31 my $WSROOT = shift;
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 = '';
38 my $bases_table = '';
39 my $encodings = '';
40 my $expert_pi = '';
41 my $menu_groups = '';
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,
51 }};
55 # load template
57 my $template = '';
58 my $template_filename = shift;
60 open TEMPLATE, "< $template_filename" or die "could not open '$template_filename': $!";
61 $template .= $_ while(<TEMPLATE>);
62 close TEMPLATE;
65 # Extract values from wiretap/wtap.h:
67 # WTAP_FILE_ values
68 # WTAP_ENCAP_ values
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': $!";
76 while(<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";
97 my $ftype_num = 0;
99 open FTYPES_H, "< $WSROOT/epan/ftypes/ftypes.h" or die "cannot open '$WSROOT/epan/ftypes/ftypes.h': $!";
100 while(<FTYPES_H>) {
101 if ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) {
102 $ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
103 $ftype_num++;
106 close FTYPES_H;
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";
121 my $base_num = 0;
123 open PROTO_H, "< $WSROOT/epan/proto.h" or die "cannot open '$WSROOT/epan/proto.h': $!";
124 while(<PROTO_H>) {
125 if (/^\s+BASE_([A-Z_]+),/ ) {
126 $bases_table .= "\t[\"$1\"] = $base_num,\n";
127 $base_num++;
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";
140 close PROTO_H;
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";
149 my $menu_i = 0;
151 open STAT_MENU, "< $WSROOT/stat_menu.h" or die "cannot open '$WSROOT/stat_menu.h': $!";
152 while(<STAT_MENU>) {
153 if (/REGISTER_([A-Z]+)_GROUP_([A-Z]+)/) {
154 $menu_groups .= "MENU_$1_$2 = $menu_i\n";
155 $menu_groups =~ s/_NONE//;
156 $menu_i++;
159 close STAT_MENU;
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;
171 print $template;