static JSBool js_createMultiOpt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { js_setting_group_t *jsg = JS_GetPrivate(cx, obj); const char *id; const char *title; JSObject *func; JSObject *optlist; JSBool persistent = JS_FALSE; if(!JS_ConvertArguments(cx, argc, argv, "ssoo/b", &id, &title, &optlist, &func, &persistent)) return JS_FALSE; js_setting_t *jss = jss_create(cx, obj, id, rval, func, jsg, persistent); if(jss == NULL) return JS_FALSE; char **options = NULL; JSIdArray *opts, *opt; int i; char *defvalue = NULL; if((opts = JS_Enumerate(cx, optlist)) != NULL) { for(i = 0; i < opts->length; i++) { jsval name, value, id, title, def; if(!JS_IdToValue(cx, opts->vector[i], &name) || !JSVAL_IS_INT(name) || !JS_GetElement(cx, optlist, JSVAL_TO_INT(name), &value) || !JSVAL_IS_OBJECT(value) || (opt = JS_Enumerate(cx, JSVAL_TO_OBJECT(value))) == NULL) continue; if(opt->length >= 2 && JS_GetElement(cx, JSVAL_TO_OBJECT(value), 0, &id) && JS_GetElement(cx, JSVAL_TO_OBJECT(value), 1, &title)) { if(opt->length < 3 || !JS_GetElement(cx, JSVAL_TO_OBJECT(value), 2, &def)) def = JSVAL_FALSE; const char *k = JS_GetStringBytes(JS_ValueToString(cx, id)); if(def == JSVAL_TRUE) mystrset(&defvalue, k); strvec_addp(&options, k); strvec_addp(&options, JS_GetStringBytes(JS_ValueToString(cx, title))); } JS_DestroyIdArray(cx, opt); } JS_DestroyIdArray(cx, opts); } rstr_t *r = NULL; if(persistent && jsg->jsg_kv_url) r = kv_url_opt_get_rstr(jsg->jsg_kv_url, KVSTORE_DOMAIN_PLUGIN, id); jss->jss_s = setting_create(SETTING_MULTIOPT, jsg->jsg_root, SETTINGS_INITIAL_UPDATE | jsg->jsg_settings_flags, SETTING_TITLE_CSTR(title), SETTING_COURIER(js_global_pc), SETTING_CALLBACK(js_store_update_string, jss), SETTING_VALUE(r ? rstr_get(r) : defvalue), SETTING_OPTION_LIST(options), SETTING_HTSMSG_CUSTOM_SAVER(id, jsg->jsg_store, js_setting_group_save, jsg), NULL); strvec_free(options); rstr_release(r); jss->jss_cx = NULL; return JS_TRUE; }
void parse_opts(int argc, char **argv) { const char *argv0 = argv[0]; argv++; argc--; gconf.showtime_shell_fd = -1; while(argc > 0) { if(!strcmp(argv[0], "-h") || !strcmp(argv[0], "--help")) { printf(APPNAMEUSER" %s\n" "Copyright (C) 2007-2015 Lonelycoder AB\n" "\n" "Usage: %s [options] [<url>]\n" "\n" " Options:\n" " -h, --help - This help text.\n" " -d - Enable debug output.\n" " --no-ui - Start without UI.\n" " --fullscreen - Start in fullscreen mode.\n" " --libav-log - Print libav log messages.\n" " --with-standby - Enable system standby.\n" " --with-poweroff - Enable system power-off.\n" " -s <path> - Non-default settings path.\n" " --ui <ui> - Use specified user interface.\n" " -L <ip:host> - Send log messages to remote <ip:host>.\n" " --syslog - Send log messages to syslog.\n" #if ENABLE_STDIN " --stdin - Listen on stdin for events.\n" #endif " -v <view> - Use specific view for <url>.\n" " --cache <path> - Set path for cache [%s].\n" " --persistent <path> - Set path for persistent stuff [%s].\n" #if ENABLE_HTTPSERVER " --disable-upnp - Disable UPNP/DLNA stack.\n" #endif " --disable-sd - Disable service discovery (mDNS, etc).\n" " -p - Path to plugin directory to load\n" " Intended for plugin development\n" " --plugin-repo - URL to plugin repository\n" " Intended for plugin development\n" " -j <path> Load javascript file\n" " --skin <skin> Select skin (for GLW ui)\n" "\n" " URL is any URL-type supported, " "e.g., \"file:///...\"\n" "\n", htsversion_full, argv0, gconf.cache_path, gconf.persistent_path); exit(0); argc--; argv++; } else if(!strcmp(argv[0], "-d")) { gconf.trace_level = TRACE_DEBUG; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--libav-log")) { gconf.libavlog = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--debug-glw")) { gconf.debug_glw = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--show-usage-events")) { gconf.show_usage_events = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--no-ui")) { gconf.noui = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--fullscreen")) { gconf.fullscreen = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--syslog")) { gconf.trace_to_syslog = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--stdin")) { gconf.listen_on_stdin = 1; argc -= 1; argv += 1; continue; #if ENABLE_HTTPSERVER } else if(!strcmp(argv[0], "--disable-upnp")) { gconf.disable_upnp = 1; argc -= 1; argv += 1; continue; #endif } else if(!strcmp(argv[0], "--disable-sd")) { gconf.disable_sd = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--disable-upgrades")) { gconf.disable_upgrades = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--with-standby")) { gconf.can_standby = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--with-poweroff")) { gconf.can_poweroff = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--with-logout")) { gconf.can_logout = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--with-openshell")) { gconf.can_open_shell = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--without-exit")) { gconf.can_not_exit = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "--with-restart")) { gconf.can_restart = 1; argc -= 1; argv += 1; continue; } else if(!strcmp(argv[0], "-p") && argc > 1) { strvec_addp(&gconf.devplugins,argv[1]); argc -= 2; argv += 2; continue; } else if(!strcmp(argv[0], "--plugin-repo") && argc > 1) { gconf.plugin_repo = argv[1]; argc -= 2; argv += 2; continue; } else if(!strcmp(argv[0], "--bypass-ecmascript-acl")) { gconf.bypass_ecmascript_acl = 1; argc -= 1; argv += 1; } else if(!strcmp(argv[0], "--ecmascript") && argc > 1) { gconf.load_ecmascript = argv[1]; argc -= 2; argv += 2; continue; } else if (!strcmp(argv[0], "-v") && argc > 1) { gconf.initial_view = argv[1]; argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--cache") && argc > 1) { mystrset(&gconf.cache_path, argv[1]); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--persistent") && argc > 1) { mystrset(&gconf.persistent_path, argv[1]); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--ui") && argc > 1) { mystrset(&gconf.ui, argv[1]); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--skin") && argc > 1) { mystrset(&gconf.skin, argv[1]); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--upgrade-path") && argc > 1) { mystrset(&gconf.upgrade_path, argv[1]); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--showtime-shell-fd") && argc > 1) { gconf.showtime_shell_fd = atoi(argv[1]); argc -= 2; argv += 2; } else if (!strcmp(argv[0], "--proxy") && argc > 1) { char *x = mystrdupa(argv[1]); char *pstr = strchr(x, ':'); if(pstr != NULL) { *pstr++ = 0; gconf.proxy_port = atoi(pstr); } else { gconf.proxy_port = 1080; } snprintf(gconf.proxy_host, sizeof(gconf.proxy_host), "%s", x); printf("Proxy set to %s:%d\n", gconf.proxy_host, gconf.proxy_port); argc -= 2; argv += 2; #ifdef __APPLE__ /* ignore -psn argument, process serial number */ } else if(!strncmp(argv[0], "-psn", 4)) { argc -= 1; argv += 1; continue; #endif } else break; } if(argc > 0) gconf.initial_url = argv[0]; }