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