diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-11-30 12:19:09 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-04 10:46:02 -0500 |
commit | 4ff97ae07c9b7beed4c8c9bf965e2ba679d05a20 (patch) | |
tree | 0da71115777e19d64138c2221afa15d99a96c440 | |
parent | 08aa09e15d11f260f8c0fc6c10cb38b83e369d33 (diff) | |
download | rockbox-4ff97ae07c.tar.gz rockbox-4ff97ae07c.zip |
settings: More settings ID to pointer conversions
Convert cfg_int_to_string(), cfg_to_string(), settings_write_config().
Change-Id: Icb72d2ff874cf90ffe5fe14878aece0a53f6bd18
-rw-r--r-- | apps/gui/option_select.c | 4 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 2 | ||||
-rw-r--r-- | apps/settings.c | 81 | ||||
-rw-r--r-- | apps/settings.h | 4 |
4 files changed, 39 insertions, 52 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 4687367fba..afd97e418b 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -117,7 +117,6 @@ const char *option_get_valuestring(const struct settings_list *setting, { if (setting->flags & F_CHOICETALKS) { - int setting_id; const struct choice_setting *info = setting->choice_setting; if (info->talks[(int)temp_var] < LANG_LAST_INDEX_IN_ARRAY) { @@ -125,8 +124,7 @@ const char *option_get_valuestring(const struct settings_list *setting, } else { - find_setting(setting->setting, &setting_id); - cfg_int_to_string(setting_id, (int)temp_var, buffer, buf_len); + cfg_int_to_string(setting, (int)temp_var, buffer, buf_len); } } else diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 874eff3809..39f1e3b4db 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -1442,7 +1442,7 @@ const char *get_token_value(struct gui_wps *gwps, goto gtv_ret_numeric_tag_info; } } - cfg_to_string(token->value.i,buf,buf_size); + cfg_to_string(s, buf, buf_size); numeric_buf = buf; goto gtv_ret_numeric_tag_info; } diff --git a/apps/settings.c b/apps/settings.c index d8e4af1460..256c71267c 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -401,17 +401,16 @@ bool settings_load_config(const char* file, bool apply) /** Writing to a config file and saving settings **/ -bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) +bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len) { - int flags = settings[setting_id].flags; - const char* start = settings[setting_id].cfg_vals; + const char* start = setting->cfg_vals; char* end = NULL; int count = 0; - if ((flags&F_T_MASK)==F_T_INT && - flags&F_TABLE_SETTING) + if ((setting->flags & F_T_MASK) == F_T_INT && + (setting->flags & F_TABLE_SETTING)) { - const int *value = settings[setting_id].table_setting->values; + const int *value = setting->table_setting->values; while (start) { end = strchr(start,','); @@ -455,20 +454,19 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len) return true; } -bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) +void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len) { - switch (settings[i].flags&F_T_MASK) + switch (setting->flags & F_T_MASK) { case F_T_CUSTOM: - settings[i].custom_setting->write_to_cfg(settings[i].setting, - buf, buf_len); + setting->custom_setting->write_to_cfg(setting->setting, buf, buf_len); break; case F_T_INT: case F_T_UINT: #ifdef HAVE_LCD_COLOR - if (settings[i].flags&F_RGB) + if (setting->flags & F_RGB) { - int colour = *(int*)settings[i].setting; + int colour = *(int*)setting->setting; snprintf(buf,buf_len,"%02x%02x%02x", (int)RGB_UNPACK_RED(colour), (int)RGB_UNPACK_GREEN(colour), @@ -476,57 +474,50 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len) } else #endif - if (settings[i].cfg_vals == NULL) + if (setting->cfg_vals == NULL) { - snprintf(buf,buf_len,"%d",*(int*)settings[i].setting); + snprintf(buf, buf_len, "%d", *(int*)setting->setting); } else { - if (cfg_int_to_string(i, *(int*)settings[i].setting, - buf, buf_len) == false) - { - snprintf(buf,buf_len,"%d",*(int*)settings[i].setting); - } - else - return false; + if (!cfg_int_to_string(setting, *(int*)setting->setting, + buf, buf_len)) + snprintf(buf, buf_len, "%d", *(int*)setting->setting); } break; case F_T_BOOL: - cfg_int_to_string(i, - *(bool*)settings[i].setting==false?0:1, buf, buf_len); + cfg_int_to_string(setting, *(bool*)setting->setting, buf, buf_len); break; case F_T_CHARPTR: case F_T_UCHARPTR: - if (((char*)settings[i].setting)[0] - && settings[i].filename_setting->prefix) + { + char *value = setting->setting; + const struct filename_setting *fs = setting->filename_setting; + if (value[0] && fs->prefix) { - if (((char*)settings[i].setting)[0] == '-') + if (value[0] == '-') { buf[0] = '-'; buf[1] = '\0'; } else { - snprintf(buf,buf_len,"%s%s%s", - settings[i].filename_setting->prefix, - (char*)settings[i].setting, - settings[i].filename_setting->suffix); + snprintf(buf, buf_len, "%s%s%s", + fs->prefix, value, fs->suffix); } } else { - int len = MIN(buf_len, settings[i].filename_setting->max_len); - strmemccpy(buf,(char*)settings[i].setting,len); + strmemccpy(buf, value, buf_len); } break; + } } /* switch () */ - return true; } -static bool is_changed(int setting_id) +static bool is_changed(const struct settings_list *setting) { - const struct settings_list *setting = &settings[setting_id]; switch (setting->flags&F_T_MASK) { case F_T_CUSTOM: @@ -574,40 +565,38 @@ static bool settings_write_config(const char* filename, int options) "http://www.rockbox.org\r\n\r\n", rbversion); for(i=0; i<nb_settings; i++) { - if (settings[i].cfg_name == NULL) - continue; - value[0] = '\0'; - if (settings[i].flags & F_DEPRECATED) + const struct settings_list *setting = &settings[i]; + if (!setting->cfg_name || (setting->flags & F_DEPRECATED)) continue; switch (options) { case SETTINGS_SAVE_CHANGED: - if (!is_changed(i)) + if (!is_changed(setting)) continue; break; case SETTINGS_SAVE_SOUND: - if ((settings[i].flags&F_SOUNDSETTING) == 0) + if (!(setting->flags & F_SOUNDSETTING)) continue; break; case SETTINGS_SAVE_THEME: - if ((settings[i].flags&F_THEMESETTING) == 0) + if (!(setting->flags & F_THEMESETTING)) continue; break; #ifdef HAVE_RECORDING case SETTINGS_SAVE_RECPRESETS: - if ((settings[i].flags&F_RECSETTING) == 0) + if (!(setting->flags & F_RECSETTING)) continue; break; #endif case SETTINGS_SAVE_EQPRESET: - if ((settings[i].flags&F_EQSETTING) == 0) + if (!(setting->flags & F_EQSETTING)) continue; break; } - cfg_to_string(i, value, MAX_PATH); - fdprintf(fd,"%s: %s\r\n",settings[i].cfg_name,value); + cfg_to_string(setting, value, MAX_PATH); + fdprintf(fd,"%s: %s\r\n",setting->cfg_name,value); } /* for(...) */ close(fd); return true; diff --git a/apps/settings.h b/apps/settings.h index 5d1237b1a5..75a346e223 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -265,9 +265,9 @@ enum optiontype { INT, BOOL }; const struct settings_list* find_setting(const void* variable, int *id); const struct settings_list* find_setting_by_cfgname(const char* name, int *id); -bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len); +bool cfg_int_to_string(const struct settings_list *setting, int val, char* buf, int buf_len); bool cfg_string_to_int(const struct settings_list *setting, int* out, const char* str); -bool cfg_to_string(int setting_id, char* buf, int buf_len); +void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len); bool copy_filename_setting(char *buf, size_t buflen, const char *input, const struct filename_setting *fs); bool set_bool_options(const char* string, const bool* variable, |