Newer
Older
for(i=0;i<numopts;i++) {
if(!JS_GetElement(cx, objarg, i, &val))
break;
JSVALUE_TO_RASTRING(cx, val, opt, &opt_sz, NULL);
if(JS_IsExceptionPending(cx)) {
if(title)
free(title);
}
else if(JS_GetClass(cx, objarg) == &js_uifc_list_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
dptr = &(p->cur);
bptr = &(p->bar);
left = p->left;
top = p->top;
width = p->width;
}
}
if(title == NULL || opts == NULL) {
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
} else {
rc=JS_SUSPENDREQUEST(cx);
JS_SET_RVAL(cx, arglist, INT_TO_JSVAL(uifc->list(mode,left,top,width,(int*)dptr,(int*)bptr,title,opts)));
JS_RESUMEREQUEST(cx, rc);
}
strListFree(&opts);
return(JS_TRUE);
}
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
static JSBool
js_uifc_scrn(JSContext *cx, uintN argc, jsval *arglist)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, 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)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, 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)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, 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)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* str;
char* org=NULL;
int32 left=0;
int32 top=0;
int32 width=0;
int32 maxlen=0;
int32 mode=0;
uifcapi_t* uifc;
uintN argn=0;
jsrefcount rc;
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))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &width))
return JS_FALSE;
if (!JS_ValueToInt32(cx, argv[argn++], &maxlen))
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++;
if(JS_IsExceptionPending(cx))
return JS_FALSE;
if(org==NULL)
return(JS_TRUE);
}
if(argn<argc && JSVAL_IS_OBJECT(argv[argn])) {
if((objarg = JSVAL_TO_OBJECT(argv[argn]))==NULL) {
free(org);
return(JS_FALSE);
}
if(JS_GetClass(cx, objarg) == &js_uifc_getstrxy_ctx_class) {
p = JS_GetPrivate(cx, objarg);
if (p != NULL) {
lastkey = &(p->lastkey);
}
}
}
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);
free(str);
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
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)
{
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* str;
char* title;
int32 left=0;
int32 top=0;
int32 width=0;
int32 height=0;
int32 mode=0;
int *cur = NULL;
int *bar = NULL;
uifcapi_t* uifc;
uintN argn=0;
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);
if(JS_IsExceptionPending(cx))
return JS_FALSE;
if(title==NULL)
return(JS_TRUE);
JSVALUE_TO_MSTRING(cx, argv[argn++], str, NULL);
if(JS_IsExceptionPending(cx)) {
free(title);
return JS_FALSE;
}
if(str==NULL) {
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) {
cur = &(p->cur);
bar = &(p->bar);
left = p->left;
top = p->top;
width = p->width;
height = p->height;
}
}
}
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);
}
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, "
},
{"bail", js_uifc_bail, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("uninitialize")
},
{"msg", js_uifc_msg, 1, JSTYPE_VOID, JSDOCSTR("string text")
,JSDOCSTR("print a message")
},
{"pop", js_uifc_pop, 1, JSTYPE_VOID, JSDOCSTR("[string text]")
,JSDOCSTR("popup (or down) a message")
{"input", js_uifc_input, 0, JSTYPE_STRING, JSDOCSTR("[number mode] [,number left] [,number top] [,string default] [,number maxlen] [,number kmode]")
,JSDOCSTR("prompt for a string input")
{"list", js_uifc_list, 0, JSTYPE_STRING, JSDOCSTR("[number mode,] string title, array options [,uifc.list.CTX object]")
,JSDOCSTR("select from a list of options.<br>"
"The context object can be created using new uifc.list.CTX() and if the same object is passed, allows WIN_SAV to work correctly.<br>"
"The context object has the following properties:<br>cur, bar, top, left, width"
)
{"showhelp", js_uifc_showhelp, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("Shows the current help text")
,317
},
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
{"scrn", js_uifc_scrn, 1, JSTYPE_BOOLEAN, JSDOCSTR("string text")
,JSDOCSTR("Fill the screen with the appropriate background attribute. string is the title for the application banner.")
,31802
},
{"showbuf", js_uifc_showbuf, 7, JSTYPE_VOID, JSDOCSTR("number mode, string title, string helpbuf [,uifc.showbuf.CTX object]")
,JSDOCSTR("Shows a scrollable text buffer - optionally parsing \"help markup codes\"<br>"
"The context object can be created using new uifc.showbuf.CTX() and if the same object is passed, allows WIN_SAV to work correctly.<br>"
"The context object has the following properties: cur, bar")
,31802
},
{"timedisplay", js_uifc_timedisplay, 0, JSTYPE_VOID, JSDOCSTR("[bool force = false]")
,JSDOCSTR("Updates time in upper left corner of screen with current time in ASCII/Unix format")
,31802
},
{"bottomline", js_uifc_bottomline, 1, JSTYPE_VOID, JSDOCSTR("number mode")
,JSDOCSTR("Displays the bottom line using the WIN_* mode flags")
,31802
},
{"getstrxy", js_uifc_getstrxy, 7, JSTYPE_STRING, JSDOCSTR("number left, number top, number width, number max, number mode[, string original][, uifc.getstrxy.CTX object]")
,JSDOCSTR("String input/exit box at a specified position"
"The context object can be created using new uifc.showbuf.CTX() and if the same object is passed, allows WIN_SAV to work correctly.<br>"
"The context object has the following properties: lastkey")
,31802
},
{0}
};
static JSBool js_uifc_resolve(JSContext *cx, JSObject *obj, jsid id)
jsval objval;
JSObject* tobj;
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval 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)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_list_ctx_class, js_list_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
if (name == NULL || strcmp(name, "showbuf") == 0) {
if(JS_GetProperty(cx, obj, "showbuf", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_showbuf_ctx_class, js_showbuf_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
if (name == NULL || strcmp(name, "getstrxy") == 0) {
if(JS_GetProperty(cx, obj, "getstrxy", &objval)) {
tobj = JSVAL_TO_OBJECT(objval);
if (tobj)
JS_InitClass(cx, tobj, NULL, &js_uifc_getstrxy_ctx_class, js_getstrxy_ctx_constructor, 0, NULL, NULL, NULL, NULL);
}
}
}
static JSBool js_uifc_enumerate(JSContext *cx, JSObject *obj)
{
static JSClass js_uifc_class = {
"UIFC" /* name */
,JSCLASS_HAS_PRIVATE /* flags */
,JS_PropertyStub /* addProperty */
,JS_PropertyStub /* delProperty */
,js_get /* getProperty */
,js_set /* setProperty */
,js_uifc_enumerate /* enumerate */
,js_uifc_resolve /* resolve */
,JS_ConvertStub /* convert */
};
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);
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);
}