Skip to content
Snippets Groups Projects
Commit 8482a03b authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Remove training whitespaces.

parent 4f087081
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1238 passed
/* js_uifc.c */
/* Synchronet "uifc" (user interface) object */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -32,16 +30,13 @@
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#ifndef JAVASCRIPT
#define JAVASCRIPT
#endif
#include "sbbs.h"
#include "uifc.h"
#include "ciolib.h"
#include "js_request.h"
struct list_ctx_private {
int cur;
int bar;
......@@ -49,7 +44,6 @@ struct list_ctx_private {
int top;
int width;
};
struct showbuf_ctx_private {
int cur;
int bar;
......@@ -58,11 +52,9 @@ struct showbuf_ctx_private {
int width;
int height;
};
struct getstrxy_ctx_private {
int lastkey;
};
enum {
PROP_CUR
,PROP_BAR
......@@ -72,19 +64,15 @@ enum {
,PROP_HEIGHT
,PROP_LASTKEY
};
static JSBool js_list_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
jsint tiny;
struct list_ctx_private* p;
if((p=(struct list_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_CUR:
*vp=INT_TO_JSVAL(p->cur);
......@@ -104,23 +92,18 @@ static JSBool js_list_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
}
return JS_TRUE;
}
static JSBool js_list_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
int32 i=0;
struct list_ctx_private* p;
if((p=(struct list_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_CUR:
p->cur=i;
......@@ -140,19 +123,15 @@ static JSBool js_list_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool stri
}
return JS_TRUE;
}
static JSBool js_showbuf_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
jsint tiny;
struct showbuf_ctx_private* p;
if((p=(struct showbuf_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_CUR:
*vp=INT_TO_JSVAL(p->cur);
......@@ -175,23 +154,18 @@ static JSBool js_showbuf_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *v
}
return JS_TRUE;
}
static JSBool js_showbuf_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
int32 i=0;
struct showbuf_ctx_private* p;
if((p=(struct showbuf_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_CUR:
p->cur=i;
......@@ -214,19 +188,15 @@ static JSBool js_showbuf_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool s
}
return JS_TRUE;
}
static JSBool js_getstrxy_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
jsint tiny;
struct getstrxy_ctx_private* p;
if((p=(struct getstrxy_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_LASTKEY:
*vp=INT_TO_JSVAL(p->lastkey);
......@@ -234,23 +204,18 @@ static JSBool js_getstrxy_ctx_get(JSContext *cx, JSObject *obj, jsid id, jsval *
}
return JS_TRUE;
}
static JSBool js_getstrxy_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
int32 i=0;
struct getstrxy_ctx_private* p;
if((p=(struct getstrxy_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_LASTKEY:
p->lastkey=i;
......@@ -258,7 +223,6 @@ static JSBool js_getstrxy_ctx_set(JSContext *cx, JSObject *obj, jsid id, JSBool
}
return JS_TRUE;
}
#ifdef BUILD_JSDOCS
static char* uifc_list_ctx_prop_desc[] = {
"Currently selected item"
......@@ -268,7 +232,6 @@ static char* uifc_list_ctx_prop_desc[] = {
,"forced width"
,NULL
};
static char* uifc_showbuf_ctx_prop_desc[] = {
"Currently selected item"
,"0-based Line number in the currently displayed set that is highlighted"
......@@ -278,51 +241,39 @@ static char* uifc_showbuf_ctx_prop_desc[] = {
,"forced height"
,NULL
};
static char* uifc_gotoxy_ctx_prop_desc[] = {
"Last pressed key"
,NULL
};
#endif
/* Destructor */
static void
static void
js_list_ctx_finalize(JSContext *cx, JSObject *obj)
{
struct list_ctx_private* p;
if((p=(struct list_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return;
free(p);
JS_SetPrivate(cx,obj,NULL);
}
static void
static void
js_showbuf_ctx_finalize(JSContext *cx, JSObject *obj)
{
struct showbuf_ctx_private* p;
if((p=(struct showbuf_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return;
free(p);
JS_SetPrivate(cx,obj,NULL);
}
static void
static void
js_getstrxy_ctx_finalize(JSContext *cx, JSObject *obj)
{
struct getstrxy_ctx_private* p;
if((p=(struct getstrxy_ctx_private*)JS_GetPrivate(cx,obj))==NULL)
return;
free(p);
JS_SetPrivate(cx,obj,NULL);
}
static JSClass js_uifc_list_ctx_class = {
"CTX" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
......@@ -335,7 +286,6 @@ static JSClass js_uifc_list_ctx_class = {
,JS_ConvertStub /* convert */
,js_list_ctx_finalize /* finalize */
};
static JSClass js_uifc_showbuf_ctx_class = {
"CTX" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
......@@ -348,7 +298,6 @@ static JSClass js_uifc_showbuf_ctx_class = {
,JS_ConvertStub /* convert */
,js_showbuf_ctx_finalize /* finalize */
};
static JSClass js_uifc_getstrxy_ctx_class = {
"CTX" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
......@@ -361,10 +310,8 @@ static JSClass js_uifc_getstrxy_ctx_class = {
,JS_ConvertStub /* convert */
,js_getstrxy_ctx_finalize /* finalize */
};
static jsSyncPropertySpec js_uifc_list_class_properties[] = {
/* name ,tinyid ,flags, ver */
{ "cur" ,PROP_CUR ,JSPROP_ENUMERATE, 317 },
{ "bar" ,PROP_BAR ,JSPROP_ENUMERATE, 317 },
{ "left" ,PROP_LEFT ,JSPROP_ENUMERATE, 31802 },
......@@ -372,28 +319,22 @@ static jsSyncPropertySpec js_uifc_list_class_properties[] = {
{ "width" ,PROP_WIDTH ,JSPROP_ENUMERATE, 31802 },
{0}
};
static jsSyncPropertySpec js_uifc_showbuf_class_properties[] = {
/* name ,tinyid ,flags, ver */
{ "cur" ,PROP_CUR ,JSPROP_ENUMERATE, 31802 },
{ "bar" ,PROP_BAR ,JSPROP_ENUMERATE, 31802 },
{0}
};
static jsSyncPropertySpec js_uifc_getstrxy_class_properties[] = {
/* name ,tinyid ,flags, ver */
{ "lastkey" ,PROP_LASTKEY ,JSPROP_ENUMERATE, 31802 },
{0}
};
/* Constructor */
static JSBool js_list_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj = JS_THIS_OBJECT(cx, arglist);
struct list_ctx_private* p;
obj = JS_NewObject(cx, &js_uifc_list_ctx_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if ((p = (struct list_ctx_private *)calloc(1, sizeof(struct list_ctx_private)))==NULL) {
......@@ -404,23 +345,18 @@ static JSBool js_list_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
JS_ReportError(cx, "JS_SetPrivate failed");
return JS_FALSE;
}
js_SyncResolve(cx, obj, NULL, js_uifc_list_class_properties, NULL, NULL, 0);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, obj, "Class used to retain UIFC list menu context", 317);
js_DescribeSyncConstructor(cx, obj, "To create a new UIFCListContext object: <tt>var ctx = new UIFCListContext();</tt>");
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_list_ctx_prop_desc, JSPROP_READONLY);
#endif
return JS_TRUE;
}
static JSBool js_showbuf_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj = JS_THIS_OBJECT(cx, arglist);
struct showbuf_ctx_private* p;
obj = JS_NewObject(cx, &js_uifc_showbuf_ctx_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if ((p = (struct showbuf_ctx_private *)calloc(1, sizeof(struct showbuf_ctx_private)))==NULL) {
......@@ -431,23 +367,18 @@ static JSBool js_showbuf_ctx_constructor(JSContext *cx, uintN argc, jsval *argli
JS_ReportError(cx, "JS_SetPrivate failed");
return JS_FALSE;
}
js_SyncResolve(cx, obj, NULL, js_uifc_showbuf_class_properties, NULL, NULL, 0);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, obj, "Class used to retain UIFC showbuf context", 317);
js_DescribeSyncConstructor(cx, obj, "To create a new UIFCShowbufContext object: <tt>var ctx = new UIFCShowbufContext();</tt>");
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_showbuf_ctx_prop_desc, JSPROP_READONLY);
#endif
return JS_TRUE;
}
static JSBool js_getstrxy_ctx_constructor(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj = JS_THIS_OBJECT(cx, arglist);
struct getstrxy_ctx_private* p;
obj = JS_NewObject(cx, &js_uifc_getstrxy_ctx_class, NULL, NULL);
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(obj));
if ((p = (struct getstrxy_ctx_private *)calloc(1, sizeof(struct getstrxy_ctx_private)))==NULL) {
......@@ -458,18 +389,14 @@ static JSBool js_getstrxy_ctx_constructor(JSContext *cx, uintN argc, jsval *argl
JS_ReportError(cx, "JS_SetPrivate failed");
return JS_FALSE;
}
js_SyncResolve(cx, obj, NULL, js_uifc_getstrxy_class_properties, NULL, NULL, 0);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, obj, "Class used to retain UIFC getstrxy context", 317);
js_DescribeSyncConstructor(cx, obj, "To create a new UIFCGetStrXYContext object: <tt>var ctx = new UIFCGetStrXYContext();</tt>");
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_showbuf_ctx_prop_desc, JSPROP_READONLY);
#endif
return JS_TRUE;
}
/* Properties */
enum {
PROP_INITIALIZED /* read-only */
......@@ -487,19 +414,15 @@ enum {
,PROP_LBCOLOR
,PROP_LIST_HEIGHT
};
static JSBool js_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
jsval idval;
jsint tiny;
uifcapi_t* uifc;
if((uifc=(uifcapi_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
switch(tiny) {
case PROP_INITIALIZED:
*vp=BOOLEAN_TO_JSVAL(uifc->initialized);
......@@ -544,23 +467,18 @@ static JSBool js_get(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
*vp=INT_TO_JSVAL(uifc->list_height);
break;
}
return(JS_TRUE);
}
static JSBool js_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval *vp)
{
jsval idval;
jsint tiny;
int32 i=0;
uifcapi_t* uifc;
if((uifc=(uifcapi_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
JS_IdToValue(cx, id, &idval);
tiny = JSVAL_TO_INT(idval);
if(tiny==PROP_CHANGES)
return JS_ValueToBoolean(cx,*vp,&uifc->changes);
else if(tiny==PROP_HELPBUF) {
......@@ -570,10 +488,8 @@ static JSBool js_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval
HANDLE_PENDING(cx, NULL);
return JS_TRUE;
}
if(!JS_ValueToInt32(cx, *vp, &i))
return JS_FALSE;
switch(tiny) {
case PROP_CHANGES:
uifc->changes=i;
......@@ -612,13 +528,10 @@ static JSBool js_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, jsval
uifc->lbclr=(char)i;
break;
}
return(JS_TRUE);
}
static jsSyncPropertySpec js_properties[] = {
/* name, tinyid, flags, ver */
{ "initialized", PROP_INITIALIZED, JSPROP_ENUMERATE|JSPROP_READONLY, 314 },
{ "mode", PROP_MODE, JSPROP_ENUMERATE, 314 },
{ "changes", PROP_CHANGES, JSPROP_ENUMERATE, 314 },
......@@ -635,7 +548,6 @@ static jsSyncPropertySpec js_properties[] = {
{ "lightbar_color", PROP_LBCOLOR, JSPROP_ENUMERATE, 314 },
{0}
};
#ifdef BUILD_JSDOCS
static char* uifc_prop_desc[] = {
"uifc has been initialized"
......@@ -655,25 +567,19 @@ static char* uifc_prop_desc[] = {
,NULL
};
#endif
/* Convenience functions */
static uifcapi_t* get_uifc(JSContext *cx, JSObject *obj)
{
uifcapi_t* uifc;
if((uifc=(uifcapi_t*)JS_GetPrivate(cx,obj))==NULL)
return(NULL);
if(!uifc->initialized) {
JS_ReportError(cx,"UIFC not initialized");
return(NULL);
}
return(uifc);
}
/* Methods */
static JSBool
js_uifc_init(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -685,19 +591,15 @@ js_uifc_init(JSContext *cx, uintN argc, jsval *arglist)
char* mode;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
if((uifc=(uifcapi_t*)JS_GetPrivate(cx,obj))==NULL)
return(JS_FALSE);
if(argc) {
JSVALUE_TO_MSTRING(cx, argv[0], title, NULL);
HANDLE_PENDING(cx, title);
if(title==NULL)
return(JS_TRUE);
}
if(argc>1) {
JSVALUE_TO_ASTRING(cx, argv[1], mode, 7, NULL);
if(mode != NULL) {
......@@ -721,7 +623,6 @@ js_uifc_init(JSContext *cx, uintN argc, jsval *arglist)
ciolib_mode=CIOLIB_MODE_SDL;
}
}
rc=JS_SUSPENDREQUEST(cx);
if(ciolib_mode==-1) {
if(uifcinix(uifc)) {
......@@ -737,7 +638,6 @@ js_uifc_init(JSContext *cx, uintN argc, jsval *arglist)
free(title);
return(JS_TRUE);
}
if(uifcini32(uifc)) {
JS_RESUMEREQUEST(cx, rc);
if(title != title_def)
......@@ -745,7 +645,6 @@ js_uifc_init(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
}
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
uifc->scrn(title);
if(title != title_def)
......@@ -753,43 +652,34 @@ js_uifc_init(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_bail(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
uifc->bail();
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_showhelp(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
uifc->showhelp();
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_msg(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -798,24 +688,19 @@ js_uifc_msg(JSContext *cx, uintN argc, jsval *arglist)
char* str = NULL;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
JSVALUE_TO_MSTRING(cx, argv[0], str, NULL);
HANDLE_PENDING(cx, str);
if(str==NULL)
return(JS_TRUE);
rc=JS_SUSPENDREQUEST(cx);
uifc->msg(str);
free(str);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_pop(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -824,17 +709,13 @@ js_uifc_pop(JSContext *cx, uintN argc, jsval *arglist)
char* str=NULL;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if(argc) {
JSVALUE_TO_MSTRING(cx, argv[0], str, NULL);
HANDLE_PENDING(cx, str);
}
rc=JS_SUSPENDREQUEST(cx);
uifc->pop(str);
if(str)
......@@ -842,7 +723,6 @@ js_uifc_pop(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -859,19 +739,16 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
uifcapi_t* uifc;
uintN argn=0;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&mode))
return(JS_FALSE);
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&left))
return(JS_FALSE);
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&top))
return(JS_FALSE);
if(argn<argc && JSVAL_IS_STRING(argv[argn])) {
......@@ -895,7 +772,7 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
}
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&maxlen)) {
if(prompt)
free(prompt);
......@@ -903,7 +780,7 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
free(org);
return(JS_FALSE);
}
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&kmode)) {
if(prompt)
free(prompt);
......@@ -911,10 +788,8 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
free(org);
return(JS_FALSE);
}
if(!maxlen)
maxlen=40;
if((str=(char*)malloc(maxlen+1))==NULL) {
if(prompt)
free(prompt);
......@@ -922,14 +797,11 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
free(org);
return(JS_FALSE);
}
memset(str,0,maxlen+1);
if(org) {
strncpy(str,org,maxlen);
free(org);
}
rc=JS_SUSPENDREQUEST(cx);
if(uifc->input(mode, left, top, prompt, str, maxlen, kmode)<0) {
JS_RESUMEREQUEST(cx, rc);
......@@ -942,14 +814,11 @@ js_uifc_input(JSContext *cx, uintN argc, jsval *arglist)
if(prompt)
free(prompt);
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx,str)));
if(str)
free(str);
return(JS_TRUE);
}
static JSBool
js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -975,13 +844,10 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
size_t opt_sz=0;
jsrefcount rc;
struct list_ctx_private *p;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
if(argn<argc && JSVAL_IS_NUMBER(argv[argn])
&& !JS_ValueToInt32(cx,argv[argn++],&mode))
return(JS_FALSE);
for(; argn<argc; argn++) {
......@@ -1034,7 +900,6 @@ js_uifc_list(JSContext *cx, uintN argc, jsval *arglist)
free(title);
return(JS_TRUE);
}
static JSBool
js_uifc_scrn(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1043,24 +908,19 @@ js_uifc_scrn(JSContext *cx, uintN argc, jsval *arglist)
char* str = NULL;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
JSVALUE_TO_MSTRING(cx, argv[0], str, NULL);
HANDLE_PENDING(cx, str);
if(str==NULL)
return(JS_TRUE);
rc=JS_SUSPENDREQUEST(cx);
uifc->scrn(str);
free(str);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_timedisplay(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1069,21 +929,16 @@ js_uifc_timedisplay(JSContext *cx, uintN argc, jsval *arglist)
JSBool force = JS_FALSE;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc > 0)
force = JSVAL_TO_BOOLEAN(argv[0]);
rc=JS_SUSPENDREQUEST(cx);
uifc->timedisplay(force);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_bottomline(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1092,25 +947,19 @@ js_uifc_bottomline(JSContext *cx, uintN argc, jsval *arglist)
int mode;
uifcapi_t* uifc;
jsrefcount rc;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc == 0) {
JS_ReportError(cx, "No mode specified");
return(JS_FALSE);
}
mode = JSVAL_TO_INT(argv[0]);
rc=JS_SUSPENDREQUEST(cx);
uifc->bottomline(mode);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
static JSBool
js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1129,17 +978,13 @@ js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
JSObject* objarg;
int *lastkey = NULL;
struct getstrxy_ctx_private *p;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc < 5) {
JS_ReportError(cx, "getstrxy requires at least five arguments");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[argn++], &left))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &top))
......@@ -1150,7 +995,6 @@ js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &mode))
return JS_FALSE;
if(argn<argc && JSVAL_IS_STRING(argv[argn])) {
JSVALUE_TO_MSTRING(cx, argv[argn], org, NULL);
argn++;
......@@ -1159,7 +1003,6 @@ js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
if(org==NULL)
return(JS_TRUE);
}
if(argn<argc && JSVAL_IS_OBJECT(argv[argn])) {
if((objarg = JSVAL_TO_OBJECT(argv[argn]))==NULL) {
free(org);
......@@ -1172,25 +1015,20 @@ js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
}
}
}
if(maxlen < 1) {
JS_ReportError(cx, "max length less than one");
free(org);
return JS_FALSE;
}
if((str=(char*)malloc(maxlen+1))==NULL) {
free(org);
return(JS_FALSE);
}
memset(str,0,maxlen+1);
if(org) {
strncpy(str,org,maxlen);
free(org);
}
rc=JS_SUSPENDREQUEST(cx);
if(uifc->getstrxy(left, top, width, str, maxlen, mode, lastkey)<0) {
JS_RESUMEREQUEST(cx, rc);
......@@ -1199,14 +1037,11 @@ js_uifc_getstrxy(JSContext *cx, uintN argc, jsval *arglist)
return(JS_TRUE);
}
JS_RESUMEREQUEST(cx, rc);
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx,str)));
if(str)
free(str);
return(JS_TRUE);
}
static JSBool
js_uifc_showbuf(JSContext *cx, uintN argc, jsval *arglist)
{
......@@ -1226,17 +1061,13 @@ js_uifc_showbuf(JSContext *cx, uintN argc, jsval *arglist)
jsrefcount rc;
JSObject* objarg;
struct showbuf_ctx_private *p;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
if((uifc=get_uifc(cx,obj))==NULL)
return(JS_FALSE);
if (argc < 3) {
JS_ReportError(cx, "showbuf requires at least three arguments");
return JS_FALSE;
}
if (!JS_ValueToInt32(cx, argv[argn++], &mode))
return JS_FALSE;
JSVALUE_TO_MSTRING(cx, argv[argn++], title, NULL);
......@@ -1253,14 +1084,12 @@ js_uifc_showbuf(JSContext *cx, uintN argc, jsval *arglist)
free(title);
return(JS_TRUE);
}
if(argn<argc && JSVAL_IS_OBJECT(argv[argn])) {
if((objarg = JSVAL_TO_OBJECT(argv[argn]))==NULL) {
free(title);
free(str);
return(JS_FALSE);
}
if(JS_GetClass(cx, objarg) == &js_uifc_list_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
......@@ -1273,37 +1102,29 @@ js_uifc_showbuf(JSContext *cx, uintN argc, jsval *arglist)
}
}
}
rc=JS_SUSPENDREQUEST(cx);
uifc->showbuf(mode, left, top, width, height,title, str, cur, bar);
JS_RESUMEREQUEST(cx, rc);
free(title);
free(str);
return(JS_TRUE);
}
/* Destructor */
static void
static void
js_finalize(JSContext *cx, JSObject *obj)
{
uifcapi_t* p;
if((p=(uifcapi_t*)JS_GetPrivate(cx,obj))==NULL)
return;
free(p);
JS_SetPrivate(cx,obj,NULL);
}
static jsSyncMethodSpec js_functions[] = {
{"init", js_uifc_init, 1, JSTYPE_BOOLEAN, JSDOCSTR("string title [, string mode]")
,JSDOCSTR("initialize. <tt>mode</tt> is a string representing the desired conio mode... one of STDIO, AUTO, "
"X, CURSES, ANSI, CONIO, or SDL.")
,314
},
},
{"bail", js_uifc_bail, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("uninitialize")
,314
......@@ -1357,24 +1178,20 @@ static jsSyncMethodSpec js_functions[] = {
},
{0}
};
static JSBool js_uifc_resolve(JSContext *cx, JSObject *obj, jsid id)
{
char* name=NULL;
JSBool ret;
jsval objval;
JSObject* tobj;
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
JS_IdToValue(cx, id, &idval);
if(JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx, name);
}
}
ret=js_SyncResolve(cx, obj, name, js_properties, js_functions, NULL, 0);
if (name == NULL || strcmp(name, "list") == 0) {
if(JS_GetProperty(cx, obj, "list", &objval)) {
......@@ -1401,12 +1218,10 @@ static JSBool js_uifc_resolve(JSContext *cx, JSObject *obj, jsid id)
free(name);
return ret;
}
static JSBool js_uifc_enumerate(JSContext *cx, JSObject *obj)
{
return(js_uifc_resolve(cx, obj, JSID_VOID));
}
static JSClass js_uifc_class = {
"UIFC" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
......@@ -1419,31 +1234,23 @@ static JSClass js_uifc_class = {
,JS_ConvertStub /* convert */
,js_finalize /* finalize */
};
JSObject* js_CreateUifcObject(JSContext* cx, JSObject* parent)
{
JSObject* obj;
uifcapi_t* api;
if((obj = JS_DefineObject(cx, parent, "uifc", &js_uifc_class, NULL
,JSPROP_ENUMERATE|JSPROP_READONLY))==NULL)
return(NULL);
if((api=(uifcapi_t*)malloc(sizeof(uifcapi_t)))==NULL)
return(NULL);
memset(api,0,sizeof(uifcapi_t));
api->size=sizeof(uifcapi_t);
api->esc_delay=25;
if(!JS_SetPrivate(cx, obj, api)) /* Store a pointer to uifcapi_t */
return(NULL);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx,obj,"User InterFaCe object - used for jsexec menus" ,314);
js_CreateArrayOfStrings(cx, obj, "_property_desc_list", uifc_prop_desc, JSPROP_READONLY);
#endif
return(obj);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment