# HG changeset patch # User Andreas Weber # Date 1442913904 -7200 # Node ID bb09279e5c994f7d6417c32bbd9a0823a4c93b8b # Parent bf6c4433ed5f1a9a408659a6b243d2cc8363fe1c menu.m: Fix bug #45988, return 0 if the dialog is aborted or invalid selection diff -r bf6c4433ed5f -r bb09279e5c99 scripts/miscellaneous/menu.m --- a/scripts/miscellaneous/menu.m Tue Sep 22 01:38:40 2015 -0700 +++ b/scripts/miscellaneous/menu.m Tue Sep 22 11:25:04 2015 +0200 @@ -30,7 +30,8 @@ ## or as a cell array of strings. ## ## The return value @var{choice} is the number of the option selected by the -## user counting from 1. +## user counting from 1 or 0 if the user aborts the dialog or makes an invalid +## selection. ## ## This function is useful for interactive programs. There is no limit to the ## number of options that may be passed in, but it may be confusing to present @@ -58,7 +59,7 @@ [choice, ok] = listdlg ("Name", "menu", "PromptString", title, "ListString", varargin, "SelectionMode", "Single"); if (! ok) - choice = 1; + choice = 0; endif else # console menu ## Force pending output to appear before the menu. @@ -82,6 +83,7 @@ choice = sscanf (s, "%d"); if (! isscalar (choice) || choice < 1 || choice > nopt) printf ("\nerror: input invalid or out of range\n\n"); + choice = 0; else break; endif