forked from osmocom/wireshark
wslua: Port make-init-lua to Python3
Port the script that creates init.lua to Python3. The generated init.lua removes one newline and adds another, otherwise the output is identical to the Perl version. Ping #18152.pespin/osmux-wip
parent
ae3010cabe
commit
4153af1dc7
|
@ -48,7 +48,7 @@ epan/wslua/CMakeLists.txt. You also have to add the module name into
|
|||
docbook/user-guide.xml and docbook/wsluarm.xml, and the source files into
|
||||
docbook/CMakeLists.txt, to get it to be generated in the user guide.
|
||||
|
||||
Another Perl script is used as well, called 'make-init-lua.pl', which
|
||||
Another Python3 script is used as well, called 'make-init-lua.py', which
|
||||
generates the init.lua script. A large part of it deals with exposing #define
|
||||
values into the Lua global table, or sub-tables. Unfortunately not all of
|
||||
them are put in sub-tables, which means the global Lua table is quite polluted
|
||||
|
@ -59,7 +59,7 @@ all have a common 'PI_' prefix should be an indicator they can be put in a
|
|||
table named PI, or PacketInfo. Just because C-code doesn't have namespaces,
|
||||
doesn't mean Lua can't. This has now been fixed, and the PI_* names are now in
|
||||
two separate subtables of a table named 'expert', as 'expert.group' and
|
||||
'expert.severity' subtables. Follow that model in 'make-init-lua.pl'.
|
||||
'expert.severity' subtables. Follow that model in 'make-init-lua.py'.
|
||||
|
||||
|
||||
Due to those documentation and registration scripts, you MUST follow some very
|
||||
|
|
|
@ -362,7 +362,7 @@ void proto_report_dissector_bug(const char *format, ...)
|
|||
* bit, required for FT_UINT_STRING and for UCS-2 and UTF-16 strings)
|
||||
* and the bottom bit (which we ignore for now so that programs that
|
||||
* pass TRUE for the encoding just do ASCII). (The encodings are given
|
||||
* directly as even numbers in hex, so that make-init-lua.pl can just
|
||||
* directly as even numbers in hex, so that make-init-lua.py can just
|
||||
* turn them into numbers for use in init.lua.)
|
||||
*
|
||||
* We don't yet process ASCII and UTF-8 differently. Ultimately, for
|
||||
|
@ -655,7 +655,7 @@ void proto_report_dissector_bug(const char *format, ...)
|
|||
#define FIELD_DISPLAY_E_MASK 0xFF
|
||||
|
||||
/*
|
||||
* Note that this enum values are parsed in make-init-lua.pl so make sure
|
||||
* Note that this enum values are parsed in make-init-lua.py so make sure
|
||||
* any changes here still makes valid entries in init.lua.
|
||||
* XXX The script requires the equals sign.
|
||||
*/
|
||||
|
@ -896,7 +896,7 @@ typedef proto_node proto_item;
|
|||
* the bottom up.
|
||||
*/
|
||||
|
||||
/* do not modify the PI_SEVERITY_MASK name - it's used by make-init-lua.pl */
|
||||
/* do not modify the PI_SEVERITY_MASK name - it's used by make-init-lua.py */
|
||||
/* expert severities */
|
||||
#define PI_SEVERITY_MASK 0x00F00000 /**< mask usually for internal use only! */
|
||||
/** Packet comment */
|
||||
|
@ -910,7 +910,7 @@ typedef proto_node proto_item;
|
|||
/** Serious problems, e.g. a malformed packet */
|
||||
#define PI_ERROR 0x00800000
|
||||
|
||||
/* do not modify the PI_GROUP_MASK name - it's used by make-init-lua.pl */
|
||||
/* do not modify the PI_GROUP_MASK name - it's used by make-init-lua.py */
|
||||
/* expert "event groups" */
|
||||
#define PI_GROUP_MASK 0xFF000000 /**< mask usually for internal use only! */
|
||||
/** The protocol field has a bad checksum, usually uses PI_WARN severity */
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
* XXX - stats should be able to register additional menu groups, although
|
||||
* the question then would be "in what order should they appear in the menu?"
|
||||
*
|
||||
* NOTE: the enum below is parsed by epan/wslua/make-init-lua.pl in order
|
||||
* NOTE: the enum below is parsed by epan/wslua/make-init-lua.py in order
|
||||
* to generate usable values for Lua scripts to use, so they can add to
|
||||
* the menus in the GUI. The perl script's regex is such that the following
|
||||
* prefixes must only appear once in this list:
|
||||
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
*/
|
||||
|
||||
/*! Statistics groups. Used for UI menu layout. */
|
||||
/* This is parsed by make-init-lua.pl, so we can't do anything fancy here. */
|
||||
/* This is parsed by make-init-lua.py, so we can't do anything fancy here. */
|
||||
typedef enum register_stat_group_e {
|
||||
REGISTER_PACKET_ANALYZE_GROUP_UNSORTED, /*!< Unsorted packet analysis */
|
||||
REGISTER_ANALYZE_GROUP_CONVERSATION_FILTER, /*!< Conversation filters. Unused? */
|
||||
|
|
|
@ -104,13 +104,12 @@ add_custom_command(
|
|||
|
||||
add_custom_command(
|
||||
OUTPUT init.lua
|
||||
COMMAND ${PERL_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/make-init-lua.pl
|
||||
${CMAKE_SOURCE_DIR}
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/make-init-lua.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/template-init.lua
|
||||
> init.lua
|
||||
init.lua
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/make-init-lua.pl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/make-init-lua.py
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/template-init.lua
|
||||
${CMAKE_SOURCE_DIR}/epan/ftypes/ftypes.h
|
||||
${CMAKE_SOURCE_DIR}/wiretap/wtap.h
|
||||
|
|
|
@ -1,259 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# make-init-lua.pl
|
||||
#
|
||||
# create the init.lua file based on a template (stdin)
|
||||
#
|
||||
# (c) 2006, Luis E. Garcia Onatnon <luis@ontanon.org>
|
||||
#
|
||||
# Wireshark - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Copyright 2004 Gerald Combs
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
use strict;
|
||||
|
||||
my $WSROOT = shift;
|
||||
|
||||
die "'$WSROOT' is not a directory" unless -d $WSROOT;
|
||||
|
||||
my $wtap_encaps_table = '';
|
||||
my $wtap_tsprecs_table = '';
|
||||
my $wtap_commenttypes_table = '';
|
||||
my $ft_types_table = '';
|
||||
my $frametypes_table = '';
|
||||
my $wtap_rec_types_table = '';
|
||||
my $wtap_presence_flags_table = '';
|
||||
my $bases_table = '';
|
||||
my $encodings = '';
|
||||
my $expert_pi = '';
|
||||
my $expert_pi_tbl = '';
|
||||
my $expert_pi_severity = '';
|
||||
my $expert_pi_group = '';
|
||||
my $menu_groups = '';
|
||||
|
||||
my %replacements = %{{
|
||||
WTAP_ENCAPS => \$wtap_encaps_table,
|
||||
WTAP_TSPRECS => \$wtap_tsprecs_table,
|
||||
WTAP_COMMENTTYPES => \$wtap_commenttypes_table,
|
||||
FT_TYPES => \$ft_types_table,
|
||||
FT_FRAME_TYPES => \$frametypes_table,
|
||||
WTAP_REC_TYPES => \$wtap_rec_types_table,
|
||||
WTAP_PRESENCE_FLAGS => \$wtap_presence_flags_table,
|
||||
BASES => \$bases_table,
|
||||
ENCODINGS => \$encodings,
|
||||
EXPERT => \$expert_pi,
|
||||
EXPERT_TABLE => \$expert_pi_tbl,
|
||||
MENU_GROUPS => \$menu_groups,
|
||||
}};
|
||||
|
||||
|
||||
#
|
||||
# load template
|
||||
#
|
||||
my $template = '';
|
||||
my $template_filename = shift;
|
||||
|
||||
open TEMPLATE, "< $template_filename" or die "could not open '$template_filename': $!";
|
||||
$template .= $_ while(<TEMPLATE>);
|
||||
close TEMPLATE;
|
||||
|
||||
#
|
||||
# Extract values from wiretap/wtap.h:
|
||||
#
|
||||
# WTAP_FILE_ values
|
||||
# WTAP_ENCAP_ values
|
||||
# WTAP_HAS_ values
|
||||
#
|
||||
|
||||
$wtap_encaps_table = "-- Wiretap encapsulations XXX\nwtap_encaps = {\n";
|
||||
$wtap_tsprecs_table = "-- Wiretap timestamp precision types\nwtap_tsprecs = {\n";
|
||||
$wtap_commenttypes_table = "-- Wiretap file comment types\nwtap_comments = {\n";
|
||||
$wtap_rec_types_table = "-- Wiretap record_types\nwtap_rec_types = {\n";
|
||||
$wtap_presence_flags_table = "-- Wiretap presence flags\nwtap_presence_flags = {\n";
|
||||
|
||||
open WTAP_H, "< $WSROOT/wiretap/wtap.h" or die "cannot open '$WSROOT/wiretap/wtap.h': $!";
|
||||
|
||||
while(<WTAP_H>) {
|
||||
if ( /^#define WTAP_ENCAP_([A-Z0-9_]+)\s+(-?\d+)/ ) {
|
||||
$wtap_encaps_table .= "\t[\"$1\"] = $2,\n";
|
||||
}
|
||||
|
||||
if ( /^#define WTAP_TSPREC_([A-Z0-9_]+)\s+(\d+)/ ) {
|
||||
$wtap_tsprecs_table .= "\t[\"$1\"] = $2,\n";
|
||||
}
|
||||
|
||||
if ( /^#define WTAP_COMMENT_([A-Z0-9_]+)\s+(0x\d+)/ ) {
|
||||
$wtap_commenttypes_table .= "\t[\"$1\"] = $2,\n";
|
||||
}
|
||||
|
||||
if ( /^#define REC_TYPE_([A-Z0-9_]+)\s+(\d+)\s+\/\*\*<([^\*]+)\*\// ) {
|
||||
$wtap_rec_types_table .= "\t[\"$1\"] = $2, --$3\n";
|
||||
}
|
||||
|
||||
if ( /^#define WTAP_HAS_([A-Z0-9_]+)\s+(0x\d+)\s+\/\*\*<([^\*]+)\*\// ) {
|
||||
my $num = hex($2);
|
||||
$wtap_presence_flags_table .= "\t[\"$1\"] = $num, --$3\n";
|
||||
}
|
||||
}
|
||||
|
||||
$wtap_encaps_table =~ s/,\n$/\n}\nwtap = wtap_encaps -- for bw compatibility\n/msi;
|
||||
$wtap_tsprecs_table =~ s/,\n$/\n}\n/msi;
|
||||
$wtap_commenttypes_table =~ s/,\n$/\n}\n/msi;
|
||||
# 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;
|
||||
# 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;
|
||||
|
||||
#
|
||||
# Extract values from epan/ftypes/ftypes.h:
|
||||
#
|
||||
# values from enum fttype
|
||||
#
|
||||
|
||||
$ft_types_table = "-- Field Types\nftypes = {\n";
|
||||
$frametypes_table = "-- Field Type FRAMENUM Types\nframetype = {\n";
|
||||
|
||||
my $ftype_num = 0;
|
||||
my $frametypes_num = 0;
|
||||
|
||||
open FTYPES_H, "< $WSROOT/epan/ftypes/ftypes.h" or die "cannot open '$WSROOT/epan/ftypes/ftypes.h': $!";
|
||||
while(<FTYPES_H>) {
|
||||
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*,/ ) {
|
||||
$ft_types_table .= "\t[\"$1\"] = $ftype_num,\n";
|
||||
$ftype_num++;
|
||||
}
|
||||
}
|
||||
close FTYPES_H;
|
||||
|
||||
$ft_types_table =~ s/,\n$/\n}\n/msi;
|
||||
$frametypes_table =~ s/,\n$/\n}\n/msi;
|
||||
|
||||
#
|
||||
# Extract values from epan/proto.h:
|
||||
#
|
||||
# values from enum base
|
||||
# #defines for encodings and expert group and severity levels
|
||||
#
|
||||
|
||||
$bases_table = "-- Display Bases\nbase = {\n";
|
||||
$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";
|
||||
|
||||
open PROTO_H, "< $WSROOT/epan/proto.h" or die "cannot open '$WSROOT/epan/proto.h': $!";
|
||||
|
||||
my $in_severity = 0;
|
||||
my $prev_comment;
|
||||
my $skip_this = 0;
|
||||
|
||||
while(<PROTO_H>) {
|
||||
$skip_this = 0;
|
||||
|
||||
if (/^\s+(?:BASE|SEP|ABSOLUTE_TIME)_([A-Z_]+)[ ]*=[ ]*([0-9]+)[,\s]+(?:\/\*\*< (.*?) \*\/)?/) {
|
||||
$bases_table .= "\t[\"$1\"] = $2, -- $3\n";
|
||||
}
|
||||
|
||||
if (/^#define\s+BASE_(RANGE_STRING)[ ]*((?:0x)?[0-9]+)[ ]+(?:\/\*\*< (.*?) \*\/)?/) {
|
||||
# Handle BASE_RANGE_STRING
|
||||
my $num = hex($2);
|
||||
$bases_table .= "\t[\"$1\"] = $num, -- $3\n";
|
||||
}
|
||||
|
||||
if (/^#define\s+BASE_(UNIT_STRING)[ ]*((?:0x)?[0-9]+)[ ]+(?:\/\*\*< (.*?) \*\/)?/) {
|
||||
# Handle BASE_UNIT_STRING as a valid base value in Lua
|
||||
my $num = hex($2);
|
||||
$bases_table .= "\t[\"$1\"] = $num, -- $3\n";
|
||||
}
|
||||
|
||||
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
|
||||
$expert_pi .= "$name = $value\n";
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
if ( /^.define\s+(ENC_[A-Z0-9_]+)\s+((0x)?[0-9A-Fa-f]+)/ ) {
|
||||
my ($name, $value) = ($1, hex($2));
|
||||
$encodings .= "$name = $value\n";
|
||||
}
|
||||
}
|
||||
close PROTO_H;
|
||||
|
||||
#
|
||||
# Extract values from stat_groups.h:
|
||||
#
|
||||
# MENU_X_X values for register_stat_group_t
|
||||
#
|
||||
|
||||
$menu_groups .= "-- menu groups for register_menu\n";
|
||||
my $menu_i = 0;
|
||||
|
||||
open STAT_GROUPS, "< $WSROOT/epan/stat_groups.h" or die "cannot open '$WSROOT/epan/stat_groups.h': $!";
|
||||
my $in_stat_group_enum = 0;
|
||||
while(<STAT_GROUPS>) {
|
||||
# need to skip matching words in comments, and get to the enum
|
||||
if (/^typedef enum register_stat_group_e \{/) { $in_stat_group_enum = 1; }
|
||||
if (/^\} register_stat_group_t\;/) { $in_stat_group_enum = 0; }
|
||||
# the problem here is we need to pick carefully, so we don't break existing scripts
|
||||
if ($in_stat_group_enum && /REGISTER_([A-Z0-9_]+)_GROUP_([A-Z0-9_]+),? /) {
|
||||
$menu_groups .= "MENU_$1_$2 = $menu_i\n";
|
||||
$menu_groups =~ s/_NONE//;
|
||||
$menu_i++;
|
||||
}
|
||||
}
|
||||
close STAT_GROUPS;
|
||||
|
||||
$menu_groups .= <<'FIN';
|
||||
-- Old / deprecated menu groups. These shoudn't be used in new code.
|
||||
MENU_ANALYZE_UNSORTED = MENU_PACKET_ANALYZE_UNSORTED
|
||||
MENU_ANALYZE_CONVERSATION = MENU_ANALYZE_CONVERSATION_FILTER
|
||||
MENU_STAT_CONVERSATION = MENU_STAT_CONVERSATION_LIST
|
||||
MENU_STAT_ENDPOINT = MENU_STAT_ENDPOINT_LIST
|
||||
MENU_STAT_RESPONSE = MENU_STAT_RESPONSE_TIME
|
||||
MENU_STAT_UNSORTED = MENU_PACKET_STAT_UNSORTED
|
||||
FIN
|
||||
|
||||
$bases_table .= "}\n";
|
||||
$encodings .= "\n";
|
||||
$expert_pi .= "\n";
|
||||
$expert_pi_severity .= "\t},\n";
|
||||
$expert_pi_group .= "\t},\n";
|
||||
$expert_pi_tbl .= $expert_pi_group . $expert_pi_severity . "}\n\n";
|
||||
|
||||
for my $key (keys %replacements) {
|
||||
$template =~ s/%$key%/${$replacements{$key}}/msig;
|
||||
}
|
||||
|
||||
|
||||
print $template;
|
|
@ -0,0 +1,199 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# make-init-lua.py
|
||||
#
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Based on make-init-lua.pl by Luis E. Garcia Onatnon <luis.ontanon@gmail.com>
|
||||
#
|
||||
# Wireshark - Network traffic analyzer
|
||||
# By Gerald Combs <gerald@wireshark.org>
|
||||
# Copyright 1998 Gerald Combs
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
|
||||
from enum import Enum
|
||||
from string import Template
|
||||
|
||||
class ExpertState(Enum):
|
||||
NONE = 0
|
||||
IN_GROUP = 1
|
||||
IN_SEVERITY = 2
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Generate the registration macros for Lua code.")
|
||||
parser.add_argument("template", metavar='template', help="template file")
|
||||
parser.add_argument("output", metavar='output', help="output file")
|
||||
args = parser.parse_args()
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
src_root = os.path.join(this_dir, '..', '..')
|
||||
|
||||
replacements = {
|
||||
'WTAP_ENCAPS': '-- Wiretap encapsulations XXX\nwtap_encaps = {',
|
||||
'WTAP_TSPRECS': '-- Wiretap timestamp precision types\nwtap_tsprecs = {',
|
||||
'WTAP_COMMENT_TYPES': '-- Wiretap file comment types\nwtap_comments = {',
|
||||
'FT_TYPES': '-- Field Types\nftypes = {',
|
||||
'FT_FRAME_TYPES': '-- Field Type FRAMENUM Types\nframetype = {',
|
||||
'WTAP_REC_TYPES': '-- Wiretap record_types\nwtap_rec_types = {',
|
||||
'WTAP_PRESENCE_FLAGS': '-- Wiretap presence flags\nwtap_presence_flags = {',
|
||||
'BASES': '-- Display Bases\nbase = {',
|
||||
'ENCODINGS': '-- Encodings',
|
||||
'EXPERT': '-- Expert flags and facilities (deprecated - see \'expert\' table below)',
|
||||
'EXPERT_TABLE': '-- Expert flags and facilities\nexpert = {',
|
||||
'MENU_GROUPS': '-- menu groups for register_menu',
|
||||
}
|
||||
|
||||
with open(args.template, encoding='utf-8') as tmpl_f:
|
||||
template = Template(tmpl_f.read())
|
||||
|
||||
wtap_encaps = []
|
||||
wtap_tsprecs = []
|
||||
wtap_comment_types = []
|
||||
wtap_rec_types = []
|
||||
wtap_presence_flags = []
|
||||
with open(os.path.join(src_root, 'wiretap', 'wtap.h'), encoding='utf-8') as wtap_f:
|
||||
for line in wtap_f:
|
||||
m = re.search(r'#define WTAP_ENCAP_([A-Z0-9_]+)\s+(-?\d+)', line)
|
||||
if m:
|
||||
wtap_encaps.append(f'\n\t["{m.group(1)}"] = {m.group(2)}')
|
||||
|
||||
m = re.search(r'#define WTAP_TSPREC_([A-Z0-9_]+)\s+(\d+)', line)
|
||||
if m:
|
||||
wtap_tsprecs.append(f'\n\t["{m.group(1)}"] = {m.group(2)}')
|
||||
|
||||
m = re.search(r'#define WTAP_COMMENT_([A-Z0-9_]+)\s+(0x\d+)', line)
|
||||
if m:
|
||||
wtap_comment_types.append(f'\n\t["{m.group(1)}"] = {m.group(2)}')
|
||||
|
||||
m = re.search(r'#define REC_TYPE_([A-Z0-9_]+)\s+(\d+)\s+\/\*\*<([^\*]+)\*\/', line)
|
||||
if m:
|
||||
wtap_rec_types.append(f'\n\t["{m.group(1)}"] = {m.group(2)}, --{m.group(3)}')
|
||||
|
||||
m = re.search(r'#define WTAP_HAS_([A-Z0-9_]+)\s+(0x\d+)\s+\/\*\*<([^\*]+)\*\/', line)
|
||||
if m:
|
||||
wtap_presence_flags.append(f'\n\t["{m.group(1)}"] = {int(m.group(2), 16)}, --{m.group(3)}')
|
||||
|
||||
replacements['WTAP_ENCAPS'] += ','.join(wtap_encaps) + '\n}\nwtap = wtap_encaps -- for bw compatibility\n'
|
||||
replacements['WTAP_TSPRECS'] += ','.join(wtap_tsprecs) + '\n}\n'
|
||||
replacements['WTAP_COMMENT_TYPES'] += ','.join(wtap_comment_types) + '\n}\n'
|
||||
replacements['WTAP_REC_TYPES'] += ''.join(wtap_rec_types) + '\n}\n'
|
||||
replacements['WTAP_PRESENCE_FLAGS'] += ''.join(wtap_presence_flags) + '\n}\n'
|
||||
|
||||
frametypes = []
|
||||
ftypes = []
|
||||
with open(os.path.join(src_root, 'epan', 'ftypes', 'ftypes.h'), encoding='utf-8') as ftypes_f:
|
||||
for line in ftypes_f:
|
||||
m = re.match(r'\s+FT_FRAMENUM_([A-Z0-9a-z_]+)\s*,', line)
|
||||
if m:
|
||||
idx = len(frametypes)
|
||||
frametypes.append(f'\n\t["{m.group(1)}"] = {idx}');
|
||||
continue
|
||||
|
||||
m = re.match(r'\s+FT_([A-Z0-9a-z_]+)\s*,', line)
|
||||
if m:
|
||||
idx = len(ftypes)
|
||||
ftypes.append(f'\n\t["{m.group(1)}"] = {idx}');
|
||||
|
||||
replacements['FT_TYPES'] += ','.join(ftypes) + '\n}\n'
|
||||
replacements['FT_FRAME_TYPES'] += ','.join(frametypes) + '\n}\n'
|
||||
|
||||
|
||||
bases = []
|
||||
encodings = []
|
||||
expert = []
|
||||
expert_group = []
|
||||
expert_severity = []
|
||||
expert_state = ExpertState.NONE
|
||||
prev_comment = ''
|
||||
with open(os.path.join(src_root, 'epan', 'proto.h'), encoding='utf-8') as proto_f:
|
||||
for line in proto_f:
|
||||
skip_this = False
|
||||
|
||||
m = re.match(r'\s+(?:BASE|SEP|ABSOLUTE_TIME)_([A-Z_]+)[ ]*=[ ]*([0-9]+)[,\s]+(?:\/\*\*< (.*?) \*\/)?', line)
|
||||
if m:
|
||||
bases.append(f'\n\t["{m.group(1)}"] = {m.group(2)}, -- {m.group(3)}')
|
||||
|
||||
m = re.match(r'#define\s+BASE_(RANGE_STRING)[ ]*((?:0x)?[0-9]+)[ ]+(?:\/\*\*< (.*?) \*\/)?', line)
|
||||
if m:
|
||||
# Handle BASE_RANGE_STRING
|
||||
bases.append(f'\n\t["{m.group(1)}"] = {int(m.group(2), 16)}, -- {m.group(3)}')
|
||||
|
||||
m = re.match(r'^#define\s+BASE_(UNIT_STRING)[ ]*((?:0x)?[0-9]+)[ ]+(?:\/\*\*< (.*?) \*\/)?', line)
|
||||
if m:
|
||||
# Handle BASE_UNIT_STRING as a valid base value in Lua
|
||||
bases.append(f'\n\t["{m.group(1)}"] = {int(m.group(2), 16)}, -- {m.group(3)}')
|
||||
|
||||
if re.match(r'#define\s+PI_GROUP_MASK ', line):
|
||||
expert_state = ExpertState.IN_GROUP
|
||||
skip_this = True
|
||||
|
||||
if re.match(r'.define\s+PI_SEVERITY_MASK ', line):
|
||||
expert_state = ExpertState.IN_SEVERITY
|
||||
skip_this = True
|
||||
|
||||
m = re.search(r'/\*\* (.*?) \*\/', line)
|
||||
if m:
|
||||
prev_comment = m.group(1)
|
||||
|
||||
m = re.match(r'#define\s+(PI_([A-Z_]+))\s+((0x)?[0-9A-Fa-f]+)', line)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
abbr = m.group(2)
|
||||
value = int(m.group(3), 16)
|
||||
|
||||
# I'm keeping this here for backwards-compatibility
|
||||
expert.append(f'\n{name} = {value}')
|
||||
|
||||
if not skip_this and expert_state == ExpertState.IN_GROUP:
|
||||
expert_group.append(f'\n\t\t-- {prev_comment}\n\t\t["{abbr}"] = {value},')
|
||||
elif not skip_this and expert_state == ExpertState.IN_SEVERITY:
|
||||
expert_severity.append(f'\n\t\t-- {prev_comment}\n\t\t["{abbr}"] = {value},')
|
||||
|
||||
m = re.match(r'^.define\s+(ENC_[A-Z0-9_]+)\s+((0x)?[0-9A-Fa-f]+)', line)
|
||||
if m:
|
||||
encodings.append(f'\n{m.group(1)} = {int(m.group(2), 16)}')
|
||||
|
||||
menu_groups = []
|
||||
in_stat_group_enum = False
|
||||
with open(os.path.join(src_root, 'epan', 'stat_groups.h'), encoding='utf-8') as stat_groups_f:
|
||||
for line in stat_groups_f:
|
||||
# need to skip matching words in comments, and get to the enum
|
||||
if re.match(r'^typedef enum register_stat_group_e \{', line):
|
||||
in_stat_group_enum = True
|
||||
elif re.match('^\} register_stat_group_t\;/', line):
|
||||
in_stat_group_enum = False
|
||||
# the problem here is we need to pick carefully, so we don't break existing scripts
|
||||
if in_stat_group_enum:
|
||||
m = re.search('REGISTER_([A-Z0-9_]+)_GROUP_([A-Z0-9_]+),? ', line)
|
||||
if m:
|
||||
idx = len(menu_groups)
|
||||
menu_groups.append(f'\nMENU_{m.group(1)}_{m.group(2)} = {idx}')
|
||||
|
||||
replacements['BASES'] += ''.join(bases) + '\n}\n'
|
||||
replacements['ENCODINGS'] += ''.join(encodings) + '\n\n'
|
||||
replacements['EXPERT'] += ''.join(expert) + '\n\n'
|
||||
replacements['EXPERT_TABLE'] += '\n\t-- Expert event groups\n\tgroup = {'
|
||||
replacements['EXPERT_TABLE'] += ''.join(expert_group) + '\n\t},'
|
||||
replacements['EXPERT_TABLE'] += '\n\t-- Expert severity levels\n\tseverity = {'
|
||||
replacements['EXPERT_TABLE'] += ''.join(expert_severity) + '\n\t},\n}\n'
|
||||
replacements['MENU_GROUPS'] += ''.join(menu_groups) + '\n\n'
|
||||
replacements['MENU_GROUPS'] += '''\
|
||||
-- Old / deprecated menu groups. These shoudn't be used in new code.
|
||||
MENU_ANALYZE_UNSORTED = MENU_PACKET_ANALYZE_UNSORTED
|
||||
MENU_ANALYZE_CONVERSATION = MENU_ANALYZE_CONVERSATION_FILTER
|
||||
MENU_STAT_CONVERSATION = MENU_STAT_CONVERSATION_LIST
|
||||
MENU_STAT_ENDPOINT = MENU_STAT_ENDPOINT_LIST
|
||||
MENU_STAT_RESPONSE = MENU_STAT_RESPONSE_TIME
|
||||
MENU_STAT_UNSORTED = MENU_PACKET_STAT_UNSORTED
|
||||
'''
|
||||
|
||||
with open(args.output, mode='w', encoding='utf-8') as out_f:
|
||||
out_f.write(template.substitute(replacements))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -76,7 +76,7 @@ function package.prepend_path(name)
|
|||
package.path = name .. sep .. "?.lua;" .. package.path
|
||||
end
|
||||
|
||||
%WTAP_ENCAPS%
|
||||
${WTAP_ENCAPS}
|
||||
|
||||
--
|
||||
-- Generate the wtap_filetypes items for file types, for backwards
|
||||
|
@ -90,31 +90,31 @@ end
|
|||
--
|
||||
wtap_filetypes = get_wtap_filetypes()
|
||||
|
||||
%WTAP_TSPRECS%
|
||||
${WTAP_TSPRECS}
|
||||
|
||||
%WTAP_COMMENTTYPES%
|
||||
${WTAP_COMMENT_TYPES}
|
||||
|
||||
%FT_TYPES%
|
||||
${FT_TYPES}
|
||||
|
||||
-- the following table is since 2.0
|
||||
%FT_FRAME_TYPES%
|
||||
${FT_FRAME_TYPES}
|
||||
|
||||
-- the following table is since 1.12
|
||||
%WTAP_REC_TYPES%
|
||||
${WTAP_REC_TYPES}
|
||||
|
||||
-- the following table is since 1.11.3
|
||||
%WTAP_PRESENCE_FLAGS%
|
||||
${WTAP_PRESENCE_FLAGS}
|
||||
|
||||
%BASES%
|
||||
${BASES}
|
||||
|
||||
%ENCODINGS%
|
||||
${ENCODINGS}
|
||||
|
||||
%EXPERT%
|
||||
${EXPERT}
|
||||
|
||||
-- the following table is since 1.11.3
|
||||
%EXPERT_TABLE%
|
||||
${EXPERT_TABLE}
|
||||
|
||||
%MENU_GROUPS%
|
||||
${MENU_GROUPS}
|
||||
|
||||
-- the possible values for Pinfo's p2p_dir attribute
|
||||
P2P_DIR_UNKNOWN = -1
|
||||
|
|
Loading…
Reference in New Issue