Commit 9ee640b8 authored by rswindell's avatar rswindell
Browse files

If sbbs_t::menu() is called with a menu file/code that includes wildcard...

If sbbs_t::menu() is called with a menu file/code that includes wildcard characters (? or *), do the random menu thing.
This is true for Baja MENU function and JS bbs.menu() as well as MENU/CONDMENU @-codes, so no longer need a bbs.random_menu() function (removed).
parent 9cfd2fd5
......@@ -1208,53 +1208,6 @@ js_menu(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
static JSBool
js_random_menu(JSContext *cx, uintN argc, jsval *arglist)
{
jsval *argv=JS_ARGV(cx, arglist);
JSString* str;
sbbs_t* sbbs;
jsrefcount rc;
char *menu;
int32 mode = P_NONE;
JSObject* obj = JS_GetScopeChain(cx);
if(!js_argc(cx, argc, 1))
return(JS_FALSE);
if((sbbs=js_GetPrivate(cx, JS_THIS_OBJECT(cx, arglist)))==NULL)
return(JS_FALSE);
str = JS_ValueToString(cx, argv[0]);
if (!str)
return(JS_FALSE);
uintN argn = 1;
if(argc > argn && JSVAL_IS_NUMBER(argv[argn])) {
if(!JS_ValueToInt32(cx,argv[argn], &mode))
return JS_FALSE;
argn++;
}
if(argc > argn && JSVAL_IS_OBJECT(argv[argn])) {
if((obj = JSVAL_TO_OBJECT(argv[argn])) == NULL)
return JS_FALSE;
argn++;
}
JSSTRING_TO_MSTRING(cx, str, menu, NULL);
if(!menu)
return JS_FALSE;
rc=JS_SUSPENDREQUEST(cx);
bool result = sbbs->random_menu(menu, mode, obj);
free(menu);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, result ? JSVAL_TRUE : JSVAL_FALSE);
return(JS_TRUE);
}
static JSBool
js_menu_exists(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -4488,15 +4441,10 @@ static jsSyncMethodSpec js_bbs_functions[] = {
{"menu", js_menu, 1, JSTYPE_BOOLEAN, JSDOCSTR("base_filename [,mode=<tt>P_NONE</tt>] [,object scope]")
,JSDOCSTR("display a menu file from the text/menu directory.<br>"
"See <tt>P_*</tt> in <tt>sbbsdefs.js</tt> for <i>mode</i> flags.<br>"
"When <i>scope</i> is specified, <tt>@JS:property@</tt> codes will expand the referenced property names.")
"When <i>scope</i> is specified, <tt>@JS:property@</tt> codes will expand the referenced property names.<br>"
"To display a randomly-chosen menu file, including wild-card (* or ?) characters in the <tt>base_filename</tt>.")
,310
},
{"random_menu", js_random_menu, 1, JSTYPE_BOOLEAN, JSDOCSTR("base_filepattern [,mode=<tt>P_NONE</tt>] [,object scope]")
,JSDOCSTR("display a randomly-chosen menu file from the text/menu directory.<br>"
"See <tt>P_*</tt> in <tt>sbbsdefs.js</tt> for <i>mode</i> flags.<br>"
"When <i>scope</i> is specified, <tt>@JS:property@</tt> codes will expand the referenced property names.")
,31800
},
{"menu_exists", js_menu_exists, 1, JSTYPE_BOOLEAN, JSDOCSTR("base_filename")
,JSDOCSTR("returns true if the referenced menu file exists (i.e. in the text/menu directory)")
,31700
......
......@@ -235,6 +235,8 @@ bool sbbs_t::printtail(const char* fname, int lines, long mode, long org_cols, J
/****************************************************************************/
/* Displays a menu file (e.g. from the text/menu directory) */
/* Pass a code including wildcards (* or ?) to display a randomly-chosen */
/* file matching the pattern in 'code' */
/****************************************************************************/
bool sbbs_t::menu(const char *code, long mode, JSObject* obj)
{
......@@ -242,6 +244,9 @@ bool sbbs_t::menu(const char *code, long mode, JSObject* obj)
const char *next= "msg";
const char *last = "asc";
if(strcspn(code, "*?") != strlen(code))
return random_menu(code, mode, obj);
sys_status&=~SS_ABORT;
if(menu_file[0])
SAFECOPY(path,menu_file);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment