name change
[obnox/wireshark/wip.git] / plugins / lua / make-init-lua.pl
1 #!/usr/bin/perl
2 # create the init.lua file based on a template (stdin) 
3 #
4 # $Id$
5 #
6 # Wireshark - Network traffic analyzer
7 # By Gerald Combs <gerald@wireshark.org>
8 # Copyright 2004 Gerald Combs
9 #
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.
14 #
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.
19 #
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.
23
24 use strict;
25
26 my $wtap_encaps_table = '';
27 my $ft_types_table = '';
28 my $bases_table = '';
29 my $expert_pi = '';
30
31 my %replacements = %{{
32     WTAP_ENCAPS => \$wtap_encaps_table,
33     FT_TYPES => \$ft_types_table,
34         BASES => \$bases_table,
35         EXPERT => \$expert_pi,
36 }};
37
38
39 #
40 # load template
41 #
42 my $template = '';
43 $template .= $_ while(<>);
44
45
46 #
47 # make wiretap encapusulation table 
48 #
49
50 $wtap_encaps_table = "-- Wiretap encapsulations\nwtap = {\n";
51
52 open WTAP_H, "< ../../wiretap/wtap.h";
53
54 while(<WTAP_H>) {
55     if ( /^#define WTAP_ENCAP_([A-Z0-9_]+)\s+(\d+)/ ) {
56         $wtap_encaps_table .= "\t[\"$1\"] = $2,\n";
57     }
58 }
59
60 $wtap_encaps_table =~ s/,\n$/\n}\n/msi;
61
62 #
63 # enum fttype
64 #
65
66 $ft_types_table = " -- Field Types\nftypes = {\n";
67
68 my $ftype_num = 0;
69
70 open FTYPES_H, "< ../../epan/ftypes/ftypes.h";
71 while(<FTYPES_H>) {
72     if ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) {
73         $ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
74         $ftype_num++;
75     }
76 }
77 close FTYPES_H;
78
79 $ft_types_table =~ s/,\n$/\n}\n/msi;
80
81
82
83 #
84 # enum base
85 #
86
87 $bases_table = "-- Display Bases\n base = {\n";
88 $expert_pi = "-- Expert flags and facilities\n";
89
90 my $base_num = 0;
91
92 open PROTO_H, "< ../../epan/proto.h";
93 while(<PROTO_H>) {
94         if (/^\s+BASE_([A-Z_]+),/ ) {
95                 $bases_table .= "\t[\"$1\"] = $base_num,\n";
96                 $base_num++;
97         }
98         
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";
102         }
103 }
104 close PROTO_H;
105
106 $bases_table .= "}\n\n";
107 $expert_pi .= "\n\n";
108
109
110 #
111 # replace macros
112 #
113
114 for my $key (keys %replacements) {
115     $template =~ s/%$key%/${$replacements{$key}}/msig;
116 }
117
118
119 print $template;