bool config_args(int argc, char **argv) { for(int i = 1; i < argc; i++) { if(!util_strncmp(argv[i], "-h", 2)) { argv[i] += 2; fprintf(stdout, "Usage: (%s -h) or (%s -cConfigValue)\n", argv[0], argv[0]); return false; } else if(!util_strncmp(argv[i], "-c", 2)) { argv[i] += 2; const char *m = "c_autoSelect"; if(!util_strncmp(argv[i], m, strlen(m))) { argv[i] += strlen(m); config_set_int(c_autoSelect, util_atoi(argv[i])); } m = "c_noModify"; if(!util_strncmp(argv[i], m, strlen(m))) { argv[i] += strlen(m); config_set_int(c_noModify, util_atoi(argv[i])); } } } return true; }
static void grab_defaults (GtkWidget *w, gpointer data) { config_set_int ("/" CONFIG_FILE "/Statistics/country", selected_country); config_set_int ("/" CONFIG_FILE "/Statistics/game", selected_type); config_set_int ("/" CONFIG_FILE "/Statistics/page", gtk_notebook_get_current_page (GTK_NOTEBOOK (stat_notebook))); }
void AutoConfig::SaveSettings() { OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow()); if (recordingEncoder != Encoder::Stream) config_set_string(main->Config(), "SimpleOutput", "RecEncoder", GetEncoderId(recordingEncoder)); const char *quality = recordingQuality == Quality::High ? "Small" : "Stream"; config_set_string(main->Config(), "Output", "Mode", "Simple"); config_set_string(main->Config(), "SimpleOutput", "RecQuality", quality); config_set_int(main->Config(), "Video", "BaseCX", baseResolutionCX); config_set_int(main->Config(), "Video", "BaseCY", baseResolutionCY); config_set_int(main->Config(), "Video", "OutputCX", idealResolutionCX); config_set_int(main->Config(), "Video", "OutputCY", idealResolutionCY); if (fpsType != FPSType::UseCurrent) { config_set_uint(main->Config(), "Video", "FPSType", 0); config_set_string(main->Config(), "Video", "FPSCommon", std::to_string(idealFPSNum).c_str()); } main->ResetVideo(); main->ResetOutputs(); config_save_safe(main->Config(), "tmp", nullptr); }
static int bind_resolution_set(OptionBinding *b, int v) { if(v >= 0) { VideoMode *m = video.modes + v; config_set_int(CONFIG_VID_WIDTH, m->width); config_set_int(CONFIG_VID_HEIGHT, m->height); } return v; }
static void config_init() { for(int i = 0; i < c_numConfig; i++) config[i] = 0; init = true; config_set_int(c_autoSelect, c_autoSelectDefault); config_set_int(c_noModify, c_noModifyDefault); config_set_int(c_autoNoTexture, c_autoNoTextureDefault); config_set_int(c_hideDetail, c_hideDetailDefault); }
void config_get(char *file_path, config *conf) { /***********************************************/ /** Initialization of configuration variables **/ /***********************************************/ int i=0, j=0; conf->server_port=36000; strcpy(conf->server_address,"localhost"); for (i=0; i<HASH_TYPE_COUNT; i++) for (j=0; j<2; j++) conf->idp[i][j]=0; /************************/ /** Read existing file **/ /************************/ conf->nb_core = config_get_int(file_path, "NB_CORE"); config_get_string(file_path, "SERVER_ADDRESS", conf->server_address); conf->server_port = config_get_int(file_path, "SERVER_PORT"); conf->idp[HASH_TYPE_MD5][IDP_TYPE_CPU] = config_get_int(file_path, "IDP_MD5_CPU"); conf->idp[HASH_TYPE_MD5][IDP_TYPE_GPU] = config_get_int(file_path, "IDP_MD5_GPU"); /************************/ /** Confirm parameters **/ /************************/ printf("\nCore(s) available : %d\n", get_core_count()); conf->nb_core = ui_input_int("Number of core to use", conf->nb_core, 1, get_core_count()); ui_input_string("Server address", conf->server_address, conf->server_address); conf->server_port = ui_input_int("Server port", conf->server_port, 1, 65535); /*******************************/ /** Write preferences in file **/ /*******************************/ remove(file_path); config_set_int(file_path,"NB_CORE", conf->nb_core); config_set_string(file_path, "SERVER_ADDRESS", conf->server_address); config_set_int(file_path,"SERVER_PORT", conf->server_port); config_set_int(file_path, "IDP_MD5_CPU", conf->idp[HASH_TYPE_MD5][IDP_TYPE_CPU]); config_set_int(file_path, "IDP_MD5_GPU", conf->idp[HASH_TYPE_MD5][IDP_TYPE_GPU]); }
int main(int argc, char *argv[]) { parse_input(argc, argv); config_file_t *conf = config_file_new(g_in_path); if (!conf) { fprintf(stderr, "Couldn't open config file ...\n"); return 1; } const char *index_list[] = { "input_player1_joypad_index", "input_player2_joypad_index", "input_player3_joypad_index", "input_player4_joypad_index", "input_player5_joypad_index", "input_player6_joypad_index", "input_player7_joypad_index", "input_player8_joypad_index", }; config_set_int(conf, index_list[g_player - 1], g_joypad); get_binds(conf, g_player - 1, g_joypad); config_file_write(conf, g_out_path); config_file_free(conf); if (g_in_path) free(g_in_path); if (g_out_path) free(g_out_path); return 0; }
static void announce_player_cb(GtkToggleButton * widget, G_GNUC_UNUSED gpointer user_data) { gboolean announce_player = gtk_toggle_button_get_active(widget); config_set_int("settings/announce_player", announce_player); set_announce_player(announce_player); }
static void summary_color_cb(GtkToggleButton * widget, G_GNUC_UNUSED gpointer user_data) { gboolean color_summary = gtk_toggle_button_get_active(widget); config_set_int("settings/color_summary", color_summary); set_color_summary(color_summary); }
static void toggle_16_9_cb(GtkToggleButton * widget, G_GNUC_UNUSED gpointer user_data) { gboolean layout_16_9 = gtk_toggle_button_get_active(widget); config_set_int("settings/layout_16_9", layout_16_9); set_16_9_layout(layout_16_9); }
/* * A simple static test for the feature vectors */ int test_static() { int i, err = 0; fvec_t *f; test_printf("Extraction of feature vectors"); for (i = 0; tests[i].str; i++) { fvec_reset_delim(); config_set_string(&cfg, "features.ngram_delim", tests[i].dlm); config_set_int(&cfg, "features.ngram_len", tests[i].nlen); /* Extract features */ f = fvec_extract(tests[i].str, strlen(tests[i].str), "test"); /* Check for correct number of dimensions */ if (f->len != tests[i].len) { test_error("(%d) len %d != %d", i, f->len, tests[i].len); err++; } fvec_destroy(f); } test_return(err, i); return err; }
static void message_color_cb(GtkToggleButton * widget, G_GNUC_UNUSED gpointer user_data) { color_messages_enabled = gtk_toggle_button_get_active(widget); config_set_int("settings/color_messages", color_messages_enabled); log_set_func_message_color_enable(color_messages_enabled); }
static void show_legend_cb(GtkToggleButton * widget, G_GNUC_UNUSED gpointer user_data) { legend_page_enabled = gtk_toggle_button_get_active(widget); gui_show_legend_page(legend_page_enabled); config_set_int("settings/legend_page", legend_page_enabled); }
//=========================================================================== int varset_message(int tokencount, char *tokens[], bool from_core, module* caller) { int varnameidx; bool is_static; if (tokencount == 4) { varnameidx = 2; is_static = false; } else if (tokencount == 5 && !strcmp(tokens[2], "Static") ) { varnameidx = 3; is_static = true; } else return 1; int i = atoi(variables_get(tokens[varnameidx],"0", caller)); if ( config_set_int(tokens[varnameidx+1],&i) //Try reading it as an int || config_set_int_expr(tokens[varnameidx+1],&i) // Try calculating the string as an expression ) variables_set(is_static,tokens[varnameidx],i, caller); else variables_set(is_static, tokens[varnameidx], tokens[varnameidx+1], caller); return 0; }
/* * A simple stress test for the feature table */ int test_stress() { int i, j, err = 0; fvec_t *f; char buf[STR_LENGTH + 1]; test_printf("Stress test for feature vectors"); config_set_string(&cfg, "features.ngram_delim", "0"); ftable_init(); for (i = 0; i < STRESS_RUNS; i++) { config_set_int(&cfg, "features.ngram_len", rand() % 10 + 1); /* Create random key and string */ for (j = 0; j < STR_LENGTH; j++) buf[j] = rand() % 10 + '0'; buf[j] = 0; /* Extract features */ f = fvec_extract(buf, strlen(buf), "test"); /* Destroy features */ fvec_destroy(f); } ftable_destroy(); test_return(err, STRESS_RUNS); return err; }
void config_parse_commandline( const char* const* cmdline, unsigned int num ) { //TODO: Implement, format --section:key=value unsigned int arg; for( arg = 0; arg < num; ++arg ) { if( string_match_pattern( cmdline[arg], "--*:*=*" ) ) { unsigned int first_sep = string_find( cmdline[arg], ':', 0 ); unsigned int second_sep = string_find( cmdline[arg], '=', 0 ); if( ( first_sep != STRING_NPOS ) && ( second_sep != STRING_NPOS ) && ( first_sep < second_sep ) ) { unsigned int section_length = first_sep - 2; unsigned int end_pos = first_sep + 1; unsigned int key_length = second_sep - end_pos; const char* section_str = cmdline[arg] + 2; const char* key_str = pointer_offset_const( cmdline[arg], end_pos ); hash_t section = hash( section_str, section_length ); hash_t key = hash( key_str, key_length ); char* value = string_substr( cmdline[arg], second_sep + 1, STRING_NPOS ); char* set_value = value; unsigned int value_length = string_length( value ); if( !value_length ) config_set_string( section, key, "" ); else if( string_equal( value, "false" ) ) config_set_bool( section, key, false ); else if( string_equal( value, "true" ) ) config_set_bool( section, key, true ); else if( ( string_find( value, '.', 0 ) != STRING_NPOS ) && ( string_find_first_not_of( value, "0123456789.", 0 ) == STRING_NPOS ) && ( string_find( value, '.', string_find( value, '.', 0 ) + 1 ) == STRING_NPOS ) ) //Exactly one "." config_set_real( section, key, string_to_real( value ) ); else if( string_find_first_not_of( value, "0123456789", 0 ) == STRING_NPOS ) config_set_int( section, key, string_to_int64( value ) ); else { if( ( value_length > 1 ) && ( value[0] == '"' ) && ( value[ value_length - 1 ] == '"' ) ) { value[ value_length - 1 ] = 0; set_value = value + 1; config_set_string( section, key, set_value ); } else { config_set_string( section, key, value ); } } log_infof( HASH_CONFIG, "Config value from command line: %.*s:%.*s = %s", section_length, section_str, key_length, key_str, set_value ); string_deallocate( value ); } } } }
/* * A simple load and save test case */ int test_load_save() { int i, j, err = 0; fvec_t *f, *g; gzFile *z; test_printf("Loading and saving of feature vectors"); fvec_reset_delim(); config_set_string(&cfg, "features.ngram_delim", " "); config_set_int(&cfg, "features.ngram_len", 2); /* Create and save feature vectors */ z = gzopen(TEST_FILE, "wb9"); if (!z) { printf("Could not create file (ignoring)\n"); return FALSE; } for (i = 0; tests[i].str; i++) { f = fvec_extract(tests[i].str, strlen(tests[i].str), "test"); fvec_save(f, z); fvec_destroy(f); } gzclose(z); /* Load and compare feature vectors */ z = gzopen(TEST_FILE, "r"); for (i = 0; tests[i].str; i++) { f = fvec_extract(tests[i].str, strlen(tests[i].str), "test"); g = fvec_load(z); /* Check dimensions and values */ for (j = 0; j < f->len && j < g->len; j++) { if (f->dim[j] != g->dim[j]) { test_error("(%d) f->dim[%d] != g->dim[%d]", i, j, j); break; } if (fabs(f->val[j] - g->val[j]) > 10e-10) { test_error("(%d) f->val[%d] != g->val[%d]", i, j, j); break; } } err += (j < f->len || j < g->len); fvec_destroy(f); fvec_destroy(g); } gzclose(z); unlink(TEST_FILE); test_return(err, i); return err; }
int test_pos_ngrams() { int i, err = 0; fvec_t *f; /* Test for positional n-grams */ test_t t[] = { {"b b b b b", 3, 0, 1}, {"b b b b b", 3, 1, 3}, {"b b b b b", 2, 0, 1}, {"b b b b b", 2, 1, 4}, {NULL, 0, 0, 0} }; test_printf("Testing positional n-grams"); /* Hack to set delimiters */ config_set_string(&cfg, "features.granularity", "tokens"); config_set_string(&cfg, "features.token_delim", " "); fvec_delim_set(" "); for (i = 0; t[i].str; i++) { config_set_int(&cfg, "features.ngram_len", t[i].nlen); config_set_bool(&cfg, "features.ngram_pos", t[i].flag); config_set_int(&cfg, "features.pos_shift", 0); /* Extract features */ f = fvec_extract(t[i].str, strlen(t[i].str)); /* Check for correct number of dimensions */ if (f->len != t[i].len) { test_error("(%d) len %d != %d", i, f->len, t[i].len); err++; } fvec_destroy(f); } config_set_bool(&cfg, "features.ngram_pos", 0); test_return(err, i); return err; }
/** * cheat_manager_save: * @path : Path to cheats file (relative path). * * Saves cheats to file on disk. * * Returns: true (1) if successful, otherwise false (0). **/ bool cheat_manager_save(const char *path) { bool ret; unsigned i; config_file_t *conf = NULL; char buf[PATH_MAX_LENGTH] = {0}; char cheats_file[PATH_MAX_LENGTH] = {0}; settings_t *settings = config_get_ptr(); cheat_manager_t *handle = cheat_manager_state; fill_pathname_join(buf, settings->path.cheat_database, path, sizeof(buf)); fill_pathname_noext(cheats_file, buf, ".cht", sizeof(cheats_file)); conf = config_file_new(cheats_file); if (!conf) conf = config_file_new(NULL); if (!conf) return false; if (!handle) { config_file_free(conf); return false; } config_set_int(conf, "cheats", handle->size); for (i = 0; i < handle->size; i++) { char key[64] = {0}; char desc_key[256] = {0}; char code_key[256] = {0}; char enable_key[256] = {0}; snprintf(key, sizeof(key), "cheat%u", i); snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i); snprintf(code_key, sizeof(code_key), "cheat%u_code", i); snprintf(enable_key, sizeof(enable_key), "cheat%u_enable", i); if (handle->cheats[i].desc) config_set_string(conf, desc_key, handle->cheats[i].desc); else config_set_string(conf, desc_key, handle->cheats[i].code); config_set_string(conf, code_key, handle->cheats[i].code); config_set_bool(conf, enable_key, handle->cheats[i].state); } ret = config_file_write(conf, cheats_file); config_file_free(conf); return ret; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_networkmonitor_message //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int agenttype_networkmonitor_message(agent *a, int tokencount, char *tokens[]) { agenttype_networkmonitor_details *details = (agenttype_networkmonitor_details *) a->agentdetails; if (!stricmp("MonitorType", tokens[5]) && config_set_int(tokens[6],&details->monitor_types, 0,2)){ control_notify(a->controlptr,NOTIFY_NEEDUPDATE,NULL); } //No errors return 0; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //agenttype_bitmap_message //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int agenttype_bitmap_message(agent *a, int tokencount, char *tokens[]) { //Get the agent details agenttype_bitmap_details *details = (agenttype_bitmap_details *) a->agentdetails; if (details->is_icon && !stricmp("Size", tokens[5]) && config_set_int(tokens[6], &details->width, 1, 256)) { details->height = details->width; control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); return 0; } else if (details->filename && !stricmp("Scale", tokens[5]) && config_set_int(tokens[6], &details->scale, 1, 500)) { control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); return 0; } else if (!stricmp("Source", tokens[5])) { //Try to set the source char *parameterstring = new_string(tokens[6]); int setsource = agenttype_bitmaporicon_setsource(a, parameterstring); free_string(¶meterstring); if (setsource == 0) control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); return 0; } int i; if ( (!stricmp("VAlign", tokens[5])) && (-1 != (i = get_string_index(tokens[6], image_valigns))) ) { details->valign = i; control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); return 0; } else if (!stricmp("HAlign", tokens[5]) && (-1 != (i = get_string_index(tokens[6], image_haligns))) ) { details->halign = i; control_notify(a->controlptr, NOTIFY_NEEDUPDATE, NULL); return 0; } return 1; }
/** * shader_write_variable: * @conf : Preset file to read from. * @info : State tracker uniform info handle. * * Writes variable to shader preset file. **/ static void shader_write_variable(config_file_t *conf, const struct state_tracker_uniform_info *info) { char semantic_buf[64]; char wram_buf[64]; char input_slot_buf[64]; char mask_buf[64]; char equal_buf[64]; const char *id = info->id; semantic_buf[0] = wram_buf[0] = input_slot_buf[0] = mask_buf[0] = equal_buf[0] = '\0'; snprintf(semantic_buf, sizeof(semantic_buf), "%s_semantic", id); snprintf(wram_buf, sizeof(wram_buf), "%s_wram", id); snprintf(input_slot_buf, sizeof(input_slot_buf), "%s_input_slot", id); snprintf(mask_buf, sizeof(mask_buf), "%s_mask", id); snprintf(equal_buf, sizeof(equal_buf), "%s_equal", id); config_set_string(conf, semantic_buf, import_semantic_to_str(info->type)); config_set_hex(conf, mask_buf, info->mask); config_set_hex(conf, equal_buf, info->equal); switch (info->ram_type) { case RARCH_STATE_INPUT_SLOT1: config_set_int(conf, input_slot_buf, 1); break; case RARCH_STATE_INPUT_SLOT2: config_set_int(conf, input_slot_buf, 2); break; case RARCH_STATE_WRAM: config_set_hex(conf, wram_buf, info->addr); break; case RARCH_STATE_NONE: break; } }
bool btif_config_set_int(const char *section, const char *key, int value) { assert(config != NULL); assert(section != NULL); assert(key != NULL); pthread_mutex_lock(&lock); config_set_int(config, section, key, value); pthread_mutex_unlock(&lock); return true; }
bool btc_config_set_int(const char *section, const char *key, int value) { assert(config != NULL); assert(section != NULL); assert(key != NULL); osi_mutex_lock(&lock, OSI_MUTEX_MAX_TIMEOUT); config_set_int(config, section, key, value); osi_mutex_unlock(&lock); return true; }
static void silent_mode_cb(GtkToggleButton * widget, G_GNUC_UNUSED gpointer user_data) { GtkToggleButton *announce_button = user_data; gboolean silent_mode = gtk_toggle_button_get_active(widget); config_set_int("settings/silent_mode", silent_mode); set_silent_mode(silent_mode); gtk_toggle_button_set_inconsistent(announce_button, silent_mode); gtk_widget_set_sensitive(GTK_WIDGET(announce_button), !silent_mode); }
static void save_cwidget_geometry (GtkWidget *clist, struct clist_def *cldef) { char buf[256]; int i; g_snprintf (buf, 256, "/" CONFIG_FILE "/%s Geometry/", cldef->name); config_push_prefix (buf); for (i = 0; i < cldef->columns; i++) config_set_int (cldef->cols[i].name, GTK_CLIST (clist)->column[i].width); config_pop_prefix (); }
static void destroy_options_menu(MenuData *m) { bool change_vidmode = false; for(int i = 0; i < m->ecount; ++i) { OptionBinding *bind = bind_get(m, i); if(!bind) { continue; } if(bind->type == BT_Resolution && video_query_capability(VIDEO_CAP_CHANGE_RESOLUTION) == VIDEO_AVAILABLE) { if(bind->selected != -1) { VideoMode *mode = video.modes + bind->selected; config_set_int(CONFIG_VID_WIDTH, mode->width); config_set_int(CONFIG_VID_HEIGHT, mode->height); change_vidmode = true; } } bind_free(bind); free(bind); } if(change_vidmode) { video_set_mode( config_get_int(CONFIG_VID_DISPLAY), config_get_int(CONFIG_VID_WIDTH), config_get_int(CONFIG_VID_HEIGHT), config_get_int(CONFIG_FULLSCREEN), config_get_int(CONFIG_VID_RESIZABLE) ); } if(m->context) { OptionsMenuContext *ctx = m->context; free(ctx->data); free(ctx); } }
static void shader_write_scale_dim(config_file_t *conf, const char *dim, enum gfx_scale_type type, float scale, unsigned abs, unsigned i) { char key[64]; print_buf(key, "scale_type_%s%u", dim, i); config_set_string(conf, key, scale_type_to_str(type)); print_buf(key, "scale_%s%u", dim, i); if (type == RARCH_SCALE_ABSOLUTE) config_set_int(conf, key, abs); else config_set_float(conf, key, scale); }
void ui_done (void) { GtkCTreeNode *node; char cfgkey[128]; int expanded; GSList *list; struct master *m; save_cwidget_geometry (GTK_WIDGET (server_clist), &server_clist_def); save_cwidget_geometry (GTK_WIDGET (player_clist), &player_clist_def); save_cwidget_geometry (GTK_WIDGET (srvinf_ctree), &srvinf_clist_def); config_push_prefix ("/" CONFIG_FILE "/Main Window Geometry/"); config_set_int ("height", main_window->allocation.height); config_set_int ("width", main_window->allocation.width); config_set_int ("pane1", GTK_PANED (pane1_widget)->child1->allocation.width); config_set_int ("pane2", GTK_PANED (pane2_widget)->child1->allocation.height); config_set_int ("pane3", GTK_PANED (pane3_widget)->child1->allocation.width); config_pop_prefix (); config_clean_section ("/" CONFIG_FILE "/Source Tree"); for (list = master_groups; list; list = list->next) { m = (struct master *) list->data; if (m->isgroup) { node = gtk_ctree_find_by_row_data (GTK_CTREE (source_ctree), NULL, m); if (node) { gtk_ctree_get_node_info (GTK_CTREE (source_ctree), node, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &expanded); if (!expanded) { g_snprintf (cfgkey, 128, "/" CONFIG_FILE "/Source Tree/%s node collapsed=false", m->name); config_set_bool (cfgkey, TRUE - expanded); } } } } }
void device_set_config_int(char *s, int val) { device_config_t *config = current_device->config; while (config->type != -1) { if (!strcmp(s, config->name)) { config_set_int(current_device->name, s, val); return; } config++; } return; }