2006-09-25 01:09:00 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# make-init-lua.pl
|
|
|
|
#
|
2013-05-29 13:03:52 +00:00
|
|
|
# create the init.lua file based on a template (stdin)
|
2006-09-25 01:09:00 +00:00
|
|
|
#
|
2008-08-05 21:03:46 +00:00
|
|
|
# (c) 2006, Luis E. Garcia Onatnon <luis@ontanon.org>
|
2006-09-25 01:09:00 +00:00
|
|
|
#
|
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 2004 Gerald Combs
|
|
|
|
#
|
2018-03-06 14:31:02 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2010-05-28 11:48:29 +00:00
|
|
|
my $WSROOT = shift;
|
2008-04-14 21:16:32 +00:00
|
|
|
|
2010-05-28 11:48:29 +00:00
|
|
|
die "'$WSROOT' is not a directory" unless -d $WSROOT;
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
my $wtap_encaps_table = '';
|
2014-09-29 02:32:33 +00:00
|
|
|
my $wtap_tsprecs_table = '';
|
2014-03-18 17:21:51 +00:00
|
|
|
my $wtap_commenttypes_table = '';
|
2006-09-25 01:09:00 +00:00
|
|
|
my $ft_types_table = '';
|
2015-11-14 21:29:32 +00:00
|
|
|
my $frametypes_table = '';
|
2014-05-24 18:28:30 +00:00
|
|
|
my $wtap_rec_types_table = '';
|
2014-03-18 17:21:51 +00:00
|
|
|
my $wtap_presence_flags_table = '';
|
2006-09-25 01:09:00 +00:00
|
|
|
my $bases_table = '';
|
2012-05-14 00:49:05 +00:00
|
|
|
my $encodings = '';
|
2006-09-25 01:09:00 +00:00
|
|
|
my $expert_pi = '';
|
2014-03-25 22:11:05 +00:00
|
|
|
my $expert_pi_tbl = '';
|
|
|
|
my $expert_pi_severity = '';
|
|
|
|
my $expert_pi_group = '';
|
2006-09-27 17:12:42 +00:00
|
|
|
my $menu_groups = '';
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
my %replacements = %{{
|
|
|
|
WTAP_ENCAPS => \$wtap_encaps_table,
|
2014-09-29 02:32:33 +00:00
|
|
|
WTAP_TSPRECS => \$wtap_tsprecs_table,
|
2014-03-18 17:21:51 +00:00
|
|
|
WTAP_COMMENTTYPES => \$wtap_commenttypes_table,
|
2006-09-25 01:09:00 +00:00
|
|
|
FT_TYPES => \$ft_types_table,
|
2015-11-14 21:29:32 +00:00
|
|
|
FT_FRAME_TYPES => \$frametypes_table,
|
2014-05-24 18:28:30 +00:00
|
|
|
WTAP_REC_TYPES => \$wtap_rec_types_table,
|
2014-03-18 17:21:51 +00:00
|
|
|
WTAP_PRESENCE_FLAGS => \$wtap_presence_flags_table,
|
2008-04-25 19:04:52 +00:00
|
|
|
BASES => \$bases_table,
|
2012-05-14 00:49:05 +00:00
|
|
|
ENCODINGS => \$encodings,
|
2008-04-25 19:04:52 +00:00
|
|
|
EXPERT => \$expert_pi,
|
2014-03-25 22:11:05 +00:00
|
|
|
EXPERT_TABLE => \$expert_pi_tbl,
|
2008-04-25 19:04:52 +00:00
|
|
|
MENU_GROUPS => \$menu_groups,
|
2006-09-25 01:09:00 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# load template
|
|
|
|
#
|
|
|
|
my $template = '';
|
2008-04-14 21:16:32 +00:00
|
|
|
my $template_filename = shift;
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2008-04-15 12:22:25 +00:00
|
|
|
open TEMPLATE, "< $template_filename" or die "could not open '$template_filename': $!";
|
2008-04-14 21:16:32 +00:00
|
|
|
$template .= $_ while(<TEMPLATE>);
|
|
|
|
close TEMPLATE;
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
#
|
2012-05-14 00:49:05 +00:00
|
|
|
# Extract values from wiretap/wtap.h:
|
|
|
|
#
|
2013-05-29 06:50:28 +00:00
|
|
|
# WTAP_FILE_ values
|
2012-05-14 00:49:05 +00:00
|
|
|
# WTAP_ENCAP_ values
|
2014-03-18 17:21:51 +00:00
|
|
|
# WTAP_HAS_ values
|
2006-09-25 01:09:00 +00:00
|
|
|
#
|
|
|
|
|
2013-05-29 13:03:52 +00:00
|
|
|
$wtap_encaps_table = "-- Wiretap encapsulations XXX\nwtap_encaps = {\n";
|
2014-09-29 02:32:33 +00:00
|
|
|
$wtap_tsprecs_table = "-- Wiretap timestamp precision types\nwtap_tsprecs = {\n";
|
2014-03-18 17:21:51 +00:00
|
|
|
$wtap_commenttypes_table = "-- Wiretap file comment types\nwtap_comments = {\n";
|
2014-05-24 18:28:30 +00:00
|
|
|
$wtap_rec_types_table = "-- Wiretap record_types\nwtap_rec_types = {\n";
|
2014-03-18 17:21:51 +00:00
|
|
|
$wtap_presence_flags_table = "-- Wiretap presence flags\nwtap_presence_flags = {\n";
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2008-04-15 12:22:25 +00:00
|
|
|
open WTAP_H, "< $WSROOT/wiretap/wtap.h" or die "cannot open '$WSROOT/wiretap/wtap.h': $!";
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
while(<WTAP_H>) {
|
2014-01-31 07:57:37 +00:00
|
|
|
if ( /^#define WTAP_ENCAP_([A-Z0-9_]+)\s+(-?\d+)/ ) {
|
2006-09-25 01:09:00 +00:00
|
|
|
$wtap_encaps_table .= "\t[\"$1\"] = $2,\n";
|
|
|
|
}
|
2013-05-29 06:50:28 +00:00
|
|
|
|
2014-09-29 02:32:33 +00:00
|
|
|
if ( /^#define WTAP_TSPREC_([A-Z0-9_]+)\s+(\d+)/ ) {
|
|
|
|
$wtap_tsprecs_table .= "\t[\"$1\"] = $2,\n";
|
|
|
|
}
|
|
|
|
|
2014-03-18 17:21:51 +00:00
|
|
|
if ( /^#define WTAP_COMMENT_([A-Z0-9_]+)\s+(0x\d+)/ ) {
|
|
|
|
$wtap_commenttypes_table .= "\t[\"$1\"] = $2,\n";
|
|
|
|
}
|
|
|
|
|
2014-05-24 18:28:30 +00:00
|
|
|
if ( /^#define REC_TYPE_([A-Z0-9_]+)\s+(\d+)\s+\/\*\*<([^\*]+)\*\// ) {
|
|
|
|
$wtap_rec_types_table .= "\t[\"$1\"] = $2, --$3\n";
|
|
|
|
}
|
|
|
|
|
2014-03-18 17:21:51 +00:00
|
|
|
if ( /^#define WTAP_HAS_([A-Z0-9_]+)\s+(0x\d+)\s+\/\*\*<([^\*]+)\*\// ) {
|
|
|
|
my $num = hex($2);
|
|
|
|
$wtap_presence_flags_table .= "\t[\"$1\"] = $num, --$3\n";
|
|
|
|
}
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
|
2013-05-29 15:52:25 +00:00
|
|
|
$wtap_encaps_table =~ s/,\n$/\n}\nwtap = wtap_encaps -- for bw compatibility\n/msi;
|
2014-09-29 02:32:33 +00:00
|
|
|
$wtap_tsprecs_table =~ s/,\n$/\n}\n/msi;
|
2014-03-18 17:21:51 +00:00
|
|
|
$wtap_commenttypes_table =~ s/,\n$/\n}\n/msi;
|
2014-05-24 18:28:30 +00:00
|
|
|
# wtap_rec_types_table has comments at the end (not a comma),
|
|
|
|
# but Lua doesn't care about extra commas so leave it in
|
|
|
|
$wtap_rec_types_table =~ s/\n$/\n}\n/msi;
|
2014-03-18 17:21:51 +00:00
|
|
|
# wtap_presence_flags_table has comments at the end (not a comma),
|
|
|
|
# but Lua doesn't care about extra commas so leave it in
|
|
|
|
$wtap_presence_flags_table =~ s/\n$/\n}\n/msi;
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
#
|
2012-05-14 00:49:05 +00:00
|
|
|
# Extract values from epan/ftypes/ftypes.h:
|
|
|
|
#
|
|
|
|
# values from enum fttype
|
2006-09-25 01:09:00 +00:00
|
|
|
#
|
|
|
|
|
2017-03-14 09:17:09 +00:00
|
|
|
$ft_types_table = "-- Field Types\nftypes = {\n";
|
|
|
|
$frametypes_table = "-- Field Type FRAMENUM Types\nframetype = {\n";
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
my $ftype_num = 0;
|
2015-11-14 21:29:32 +00:00
|
|
|
my $frametypes_num = 0;
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2008-04-15 12:22:25 +00:00
|
|
|
open FTYPES_H, "< $WSROOT/epan/ftypes/ftypes.h" or die "cannot open '$WSROOT/epan/ftypes/ftypes.h': $!";
|
2006-09-25 01:09:00 +00:00
|
|
|
while(<FTYPES_H>) {
|
2015-11-14 21:29:32 +00:00
|
|
|
if ( /^\s+FT_FRAMENUM_([A-Z0-9a-z_]+)\s*,/ ) {
|
|
|
|
$frametypes_table .= "\t[\"$1\"] = $frametypes_num,\n";
|
|
|
|
$frametypes_num++;
|
|
|
|
} elsif ( /^\s+FT_([A-Z0-9a-z_]+)\s*,/ ) {
|
2006-09-25 01:09:00 +00:00
|
|
|
$ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
|
|
|
|
$ftype_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close FTYPES_H;
|
|
|
|
|
|
|
|
$ft_types_table =~ s/,\n$/\n}\n/msi;
|
2015-11-14 21:29:32 +00:00
|
|
|
$frametypes_table =~ s/,\n$/\n}\n/msi;
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
#
|
2012-05-14 00:49:05 +00:00
|
|
|
# Extract values from epan/proto.h:
|
|
|
|
#
|
|
|
|
# values from enum base
|
|
|
|
# #defines for encodings and expert group and severity levels
|
2006-09-25 01:09:00 +00:00
|
|
|
#
|
|
|
|
|
2017-03-14 09:17:09 +00:00
|
|
|
$bases_table = "-- Display Bases\nbase = {\n";
|
2014-03-25 22:11:05 +00:00
|
|
|
$encodings = "-- Encodings\n";
|
|
|
|
$expert_pi = "-- Expert flags and facilities (deprecated - see 'expert' table below)\n";
|
|
|
|
$expert_pi_tbl = "-- Expert flags and facilities\nexpert = {\n";
|
|
|
|
$expert_pi_severity = "\t-- Expert severity levels\n\tseverity = {\n";
|
|
|
|
$expert_pi_group = "\t-- Expert event groups\n\tgroup = {\n";
|
2006-09-25 01:09:00 +00:00
|
|
|
|
2008-04-15 12:22:25 +00:00
|
|
|
open PROTO_H, "< $WSROOT/epan/proto.h" or die "cannot open '$WSROOT/epan/proto.h': $!";
|
2014-03-25 22:11:05 +00:00
|
|
|
|
|
|
|
my $in_severity = 0;
|
|
|
|
my $prev_comment;
|
|
|
|
my $skip_this = 0;
|
|
|
|
|
2006-09-25 01:09:00 +00:00
|
|
|
while(<PROTO_H>) {
|
2014-03-25 22:11:05 +00:00
|
|
|
$skip_this = 0;
|
|
|
|
|
2017-03-15 08:30:37 +00:00
|
|
|
if (/^\s+(?:BASE|STR|SEP)_([A-Z_]+)[ ]*=[ ]*([0-9]+)[,\s]+(?:\/\*\*< (.*?) \*\/)?/) {
|
|
|
|
$bases_table .= "\t[\"$1\"] = $2, -- $3\n";
|
2008-04-25 19:04:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-14 19:14:13 +00:00
|
|
|
if (/^#define\s+BASE_(RANGE_STRING)[ ]*((?:0x)?[0-9]+)[ ]+(?:\/\*\*< (.*?) \*\/)?/) {
|
|
|
|
# Handle BASE_RANGE_STRING
|
|
|
|
my $num = hex($2);
|
|
|
|
$bases_table .= "\t[\"$1\"] = $num, -- $3\n";
|
|
|
|
}
|
|
|
|
|
2017-03-15 08:30:37 +00:00
|
|
|
if (/^#define\s+BASE_(UNIT_STRING)[ ]*((?:0x)?[0-9]+)[ ]+(?:\/\*\*< (.*?) \*\/)?/) {
|
2016-12-17 09:08:54 +00:00
|
|
|
# Handle BASE_UNIT_STRING as a valid base value in Lua
|
|
|
|
my $num = hex($2);
|
2017-03-15 08:30:37 +00:00
|
|
|
$bases_table .= "\t[\"$1\"] = $num, -- $3\n";
|
2016-12-18 18:03:44 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 22:11:05 +00:00
|
|
|
if (/^.define\s+PI_SEVERITY_MASK /) {
|
|
|
|
$in_severity = 1;
|
|
|
|
$skip_this = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/^.define\s+PI_GROUP_MASK /) {
|
|
|
|
$in_severity = 2;
|
|
|
|
$skip_this = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($in_severity && /\/\*\* (.*?) \*\//) {
|
|
|
|
$prev_comment = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( /^.define\s+(PI_([A-Z_]+))\s+((0x)?[0-9A-Fa-f]+)/ ) {
|
|
|
|
my ($name, $abbr, $value) = ($1, $2, hex($3));
|
|
|
|
# I'm keeping this here for backwards-compatibility
|
2008-04-25 19:04:52 +00:00
|
|
|
$expert_pi .= "$name = $value\n";
|
2014-03-25 22:11:05 +00:00
|
|
|
|
|
|
|
if (!$skip_this && $in_severity == 1) {
|
|
|
|
$expert_pi_severity .= "\t\t-- $prev_comment\n";
|
|
|
|
$expert_pi_severity .= "\t\t\[\"$abbr\"\] = $value,\n";
|
|
|
|
}
|
|
|
|
elsif (!$skip_this && $in_severity == 2) {
|
|
|
|
$expert_pi_group .= "\t\t-- $prev_comment\n";
|
|
|
|
$expert_pi_group .= "\t\t\[\"$abbr\"\] = $value,\n";
|
|
|
|
}
|
2008-04-25 19:04:52 +00:00
|
|
|
}
|
2012-05-14 00:49:05 +00:00
|
|
|
|
|
|
|
if ( /^.define\s+(ENC_[A-Z0-9_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
|
|
|
|
my ($name, $value) = ($1, hex($2));
|
|
|
|
$encodings .= "$name = $value\n";
|
|
|
|
}
|
2006-09-25 01:09:00 +00:00
|
|
|
}
|
|
|
|
close PROTO_H;
|
|
|
|
|
2017-03-15 08:21:18 +00:00
|
|
|
#
|
|
|
|
# Extract values from time_fmt.h:
|
|
|
|
#
|
|
|
|
# ABSOLUTE_TIME_XXX values for absolute time bases
|
|
|
|
#
|
|
|
|
|
|
|
|
my $absolute_time_num = 0;
|
|
|
|
|
|
|
|
open TIME_FMT_H, "< $WSROOT/epan/time_fmt.h" or die "cannot open '$WSROOT/epan/time_fmt.h': $!";
|
|
|
|
while(<TIME_FMT_H>) {
|
|
|
|
if (/^\s+ABSOLUTE_TIME_([A-Z_]+)[ ]*=[ ]*([0-9]+)[,\s]+(?:\/\* (.*?) \*\/)?/) {
|
|
|
|
$bases_table .= "\t[\"$1\"] = $2, -- $3\n";
|
|
|
|
$absolute_time_num = $2 + 1;
|
|
|
|
} elsif (/^\s+ABSOLUTE_TIME_([A-Z_]+)[,\s]+(?:\/\* (.*?) \*\/)?/) {
|
|
|
|
$bases_table .= "\t[\"$1\"] = $absolute_time_num, -- $2\n";
|
|
|
|
$absolute_time_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close TIME_FTM_H;
|
|
|
|
|
2012-05-14 00:49:05 +00:00
|
|
|
#
|
2014-07-03 20:30:12 +00:00
|
|
|
# Extract values from stat_groups.h:
|
2012-05-14 00:49:05 +00:00
|
|
|
#
|
|
|
|
# MENU_X_X values for register_stat_group_t
|
|
|
|
#
|
2006-09-27 17:12:42 +00:00
|
|
|
|
2008-04-25 19:04:52 +00:00
|
|
|
$menu_groups .= "-- menu groups for register_menu\n";
|
2006-09-27 17:12:42 +00:00
|
|
|
my $menu_i = 0;
|
|
|
|
|
2014-07-03 20:30:12 +00:00
|
|
|
open STAT_GROUPS, "< $WSROOT/epan/stat_groups.h" or die "cannot open '$WSROOT/epan/stat_groups.h': $!";
|
2014-02-07 19:23:41 +00:00
|
|
|
my $foundit = 0;
|
2014-07-03 20:30:12 +00:00
|
|
|
while(<STAT_GROUPS>) {
|
2014-02-07 19:23:41 +00:00
|
|
|
# need to skip matching words in comments, and get to the enum
|
2015-06-22 22:27:11 +00:00
|
|
|
if (/^typedef enum \{/) { $foundit = 1; }
|
2014-02-07 19:23:41 +00:00
|
|
|
# the problem here is we need to pick carefully, so we don't break existing scripts
|
2019-01-28 15:03:21 +00:00
|
|
|
if ($foundit && /REGISTER_([A-Z]+)_GROUP_(CONVERSATION|RESPONSE|ENDPOINT|[A-Z0-9_]+)/) {
|
2008-04-25 19:04:52 +00:00
|
|
|
$menu_groups .= "MENU_$1_$2 = $menu_i\n";
|
|
|
|
$menu_groups =~ s/_NONE//;
|
|
|
|
$menu_i++;
|
|
|
|
}
|
2006-09-27 17:12:42 +00:00
|
|
|
}
|
2014-07-03 20:30:12 +00:00
|
|
|
close STAT_GROUPS;
|
2006-09-27 17:12:42 +00:00
|
|
|
|
|
|
|
|
2017-03-15 08:30:37 +00:00
|
|
|
$bases_table .= "}\n";
|
|
|
|
$encodings .= "\n";
|
2014-03-25 22:11:05 +00:00
|
|
|
$expert_pi .= "\n";
|
|
|
|
$expert_pi_severity .= "\t},\n";
|
|
|
|
$expert_pi_group .= "\t},\n";
|
|
|
|
$expert_pi_tbl .= $expert_pi_group . $expert_pi_severity . "}\n\n";
|
2006-09-25 01:09:00 +00:00
|
|
|
|
|
|
|
for my $key (keys %replacements) {
|
|
|
|
$template =~ s/%$key%/${$replacements{$key}}/msig;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print $template;
|