Skip to content
Snippets Groups Projects
Commit ca770865 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix random menu/display file selection when some files can't be displayed

When one or more files that match the menu file pattern can't be displayed
(e.g. the user's terminal is not wide enough or there's any other menu file
open/read error), pick another random menu file and try displaying that one,
until either a menu file has been displayed successfully or all files
(matching the pattern) have been attempted.

For example, you have text/menu/random1.c80.msg and random2.msg, if the first
file (random1.c80.msg) is selected at random but the user's terminal isn't
at least 80 columns wide, another file will be picked at random. Since only
random2.msg remains in the list (matching the pattern "random*"), that's the
only file that will always be displayed.
parent 6c96d146
Branches
Tags
No related merge requests found
......@@ -388,11 +388,15 @@ bool sbbs_t::random_menu(const char *name, int mode, JSObject* obj)
strListDedupe(&names, /* case_sensitive: */ true);
bool result = false;
size_t count = strListCount(names);
if (count > 0) {
while (count > 0) {
size_t i = sbbs_random(count);
if (menu_exists(names[i], NULL, path)) {
result = menu(names[i], mode, obj);
if (result == true)
break;
}
strListFastDelete(names, i, 1);
--count;
}
strListFree(&names);
return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment