Fix bug 9732: ' Lua: recent commit changed some MENU_ key names in init.lua'

A recent fix (made by me) for bug 9707, in Change-Id:
If4ee1906aa60dd37366cf2ef9bc4168e0ea024b6, made the perl regex grab too much
of the menu name.  It changed MENU_STAT_CONVERSATION, MENU_STAT_RESPONSE, and
MENU_ANALYZE_CONVERSATION's key names into their longer C-code names.  Ugh.

The fix for this is a bit brittle, but I think it's impractical to avoid it
being brittle, due to needing to support legacy Lua scripts.  I put comments
in stat_menu.h to warn of the danger.

Change-Id: I41408e9d4f5b5bd73e2871fccabff81c7cbd242d
Reviewed-on: https://code.wireshark.org/review/140
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
This commit is contained in:
Hadriel Kaplan 2014-02-07 14:23:41 -05:00 committed by Alexis La Goutte
parent 8d7b6001bb
commit 991bd3d7e1
3 changed files with 23 additions and 2 deletions

View File

@ -146,8 +146,12 @@ $menu_groups .= "-- menu groups for register_menu\n";
my $menu_i = 0;
open STAT_MENU, "< $WSROOT/stat_menu.h" or die "cannot open '$WSROOT/stat_menu.h': $!";
my $foundit = 0;
while(<STAT_MENU>) {
if (/REGISTER_([A-Z]+)_GROUP_([A-Z_]+)/) {
# need to skip matching words in comments, and get to the enum
if (/^typedef enum {/) { $foundit = 1; }
# the problem here is we need to pick carefully, so we don't break existing scripts
if ($foundit && /REGISTER_([A-Z]+)_GROUP_(CONVERSATION|RESPONSE|[A-Z_]+)/) {
$menu_groups .= "MENU_$1_$2 = $menu_i\n";
$menu_groups =~ s/_NONE//;
$menu_i++;

View File

@ -84,7 +84,11 @@ WSLUA_FUNCTION wslua_register_menu(lua_State* L) { /* Register a menu item in o
MENU_STAT_CONVERSATION (Statistics/Conversation List),
MENU_STAT_ENDPOINT (Statistics/Endpoint List),
MENU_STAT_RESPONSE (Statistics/Service Response Time),
MENU_STAT_TELEPHONY (Telephony), MENU_ANALYZE (Analyze),
MENU_STAT_TELEPHONY (Telephony),
MENU_STAT_TELEPHONY_GSM (Telephony/GSM),
MENU_STAT_TELEPHONY_LTE (Telephony/LTE),
MENU_STAT_TELEPHONY_SCTP (Telephony/SCTP),
MENU_ANALYZE (Analyze),
MENU_ANALYZE_CONVERSATION (Analyze/Conversation Filter),
MENU_TOOLS_UNSORTED (Tools). (number) */

View File

@ -39,6 +39,19 @@ 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
* 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:
* REGISTER_ANALYZE_GROUP_CONVERSATION
* REGISTER_STAT_GROUP_CONVERSATION
* REGISTER_STAT_GROUP_RESPONSE
* In other words, because there is a REGISTER_STAT_GROUP_RESPONSE_TIME, you cannot
* add a REGISTER_STAT_GROUP_RESPONSE nor a REGISTER_STAT_GROUP_RESPONSE_FOOBAR
* because they use the same "REGISTER_STAT_GROUP_RESPONSE" prefix.
* Also, do NOT change the names in the enum - you can add, but not remove.
* If you do, legacy scripts will break. (which is why the perl script regex isn't better)
*/
/** The menu group this stat should be registered in. */