Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 578f7af1 authored by rswindell's avatar rswindell

Add an optional mode (K_* flag) argument to sbbs_t::getkeys() and by extension,

JS's console.getkeys(). If no mode value is specified, K_UPPER is the default
behavior (same as before). *.getkeys() currently only recognizes the following
mode flags:
- K_UPPER
- K_NOECHO
- K_NOCRLF

K_NONE (0) is also a valid value.
parent 43c4dbed
......@@ -430,11 +430,9 @@ bool sbbs_t::noyes(const char *str)
/* If 'keys' is NULL, *any* non-numeric key is valid input. */
/* 'max' is non-zero, allow that a decimal number input up to that size */
/* and return the value OR'd with 0x80000000. */
/* 'str' should contain uppercase characters only. When a valid key is hit, */
/* it is echoed (upper case) and is the return value. */
/* Called from quite a few functions */
/* default mode value is K_UPPER */
/****************************************************************************/
long sbbs_t::getkeys(const char *keys, ulong max)
long sbbs_t::getkeys(const char *keys, ulong max, long mode)
{
char str[81];
uchar ch,n=0,c=0;
......@@ -442,21 +440,23 @@ long sbbs_t::getkeys(const char *keys, ulong max)
if(keys != NULL) {
SAFECOPY(str,keys);
strupr(str);
}
while(online) {
ch=getkey(K_UPPER);
ch=getkey(mode);
if(max && ch>0x7f) /* extended ascii chars are digits to isdigit() */
continue;
if(sys_status&SS_ABORT) { /* return -1 if Ctrl-C hit */
attr(LIGHTGRAY);
CRLF;
if(!(mode&(K_NOECHO|K_NOCRLF))) {
attr(LIGHTGRAY);
CRLF;
}
lncntr=0;
return(-1);
}
if(ch && !n && ((keys == NULL && !isdigit(ch)) || (strchr(str,ch)))) { /* return character if in string */
if(ch > ' ') {
outchar(ch);
if(!(mode&K_NOECHO))
outchar(ch);
if(useron.misc&COLDKEYS) {
while(online && !(sys_status&SS_ABORT)) {
c=getkey(0);
......@@ -464,30 +464,38 @@ long sbbs_t::getkeys(const char *keys, ulong max)
break;
}
if(sys_status&SS_ABORT) {
CRLF;
if(!(mode&(K_NOECHO|K_NOCRLF))) {
CRLF;
}
return(-1);
}
if(c==BS || c==DEL) {
backspace();
if(!(mode&K_NOECHO))
backspace();
continue;
}
}
attr(LIGHTGRAY);
CRLF;
if(!(mode&(K_NOECHO|K_NOCRLF))) {
attr(LIGHTGRAY);
CRLF;
}
lncntr=0;
}
return(ch);
}
if(ch==CR && max) { /* return 0 if no number */
attr(LIGHTGRAY);
CRLF;
if(!(mode&(K_NOECHO|K_NOCRLF))) {
attr(LIGHTGRAY);
CRLF;
}
lncntr=0;
if(n)
return(i|0x80000000L); /* return number plus high bit */
return(0);
}
if((ch==BS || ch==DEL) && n) {
backspace();
if(!(mode&K_NOECHO))
backspace();
i/=10;
n--;
}
......@@ -495,10 +503,13 @@ long sbbs_t::getkeys(const char *keys, ulong max)
i*=10;
n++;
i+=ch&0xf;
outchar(ch);
if(!(mode&K_NOECHO))
outchar(ch);
if(i*10>max && !(useron.misc&COLDKEYS)) {
attr(LIGHTGRAY);
CRLF;
if(!(mode&(K_NOECHO|K_NOCRLF))) {
attr(LIGHTGRAY);
CRLF;
}
lncntr=0;
return(i|0x80000000L);
}
......
......@@ -674,7 +674,8 @@ js_getkeys(JSContext *cx, uintN argc, jsval *arglist)
char key[2];
uintN i;
int32 val;
uint32 maxnum=~0;
uint32 maxnum = 0;
long mode = K_UPPER;
sbbs_t* sbbs;
JSString* js_str=NULL;
char* cstr=NULL;
......@@ -687,8 +688,12 @@ js_getkeys(JSContext *cx, uintN argc, jsval *arglist)
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i])) {
if(!JS_ValueToInt32(cx,argv[i],(int32*)&maxnum))
if(!JS_ValueToInt32(cx, argv[i], &val))
return JS_FALSE;
if(maxnum == 0)
maxnum = val;
else
mode = val;
continue;
}
if(JSVAL_IS_STRING(argv[i])) {
......@@ -699,8 +704,11 @@ js_getkeys(JSContext *cx, uintN argc, jsval *arglist)
}
}
if(maxnum == 0)
maxnum = ~0;
rc=JS_SUSPENDREQUEST(cx);
val=sbbs->getkeys(cstr,maxnum);
val=sbbs->getkeys(cstr, maxnum, mode);
FREE_AND_NULL(cstr);
JS_RESUMEREQUEST(cx, rc);
......@@ -1857,7 +1865,7 @@ static jsSyncMethodSpec js_console_functions[] = {
,JSDOCSTR("get a number between 1 and <i>maxnum</i> from the user with a default value of <i>default</i>")
,310
},
{"getkeys", js_getkeys, 1, JSTYPE_NUMBER, JSDOCSTR("[keys] [,maxnum]")
{"getkeys", js_getkeys, 1, JSTYPE_NUMBER, JSDOCSTR("[keys] [,maxnum] [,mode=<tt>K_UPPER</tt>]")
,JSDOCSTR("get one key from of a list of valid command <i>keys</i> (any key, if not specified), "
"or a number between 1 and <i>maxnum</i>")
,310
......
......@@ -745,7 +745,7 @@ public:
/* getkey.cpp */
char getkey(long mode); /* Waits for a key hit local or remote */
long getkeys(const char *str, ulong max);
long getkeys(const char *str, ulong max, long mode = K_NONE);
void ungetkey(char ch); /* Places 'ch' into the input buffer */
char question[MAX_TEXTDAT_ITEM_LEN+1];
bool yesno(const char *str);
......
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