From 701e262d3d622898279167ba909da631ac460bc1 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Wed, 30 Nov 2022 14:50:18 +0000 Subject: [PATCH] settings: Remove setting ID return from find_setting() Now that all users have replaced setting IDs with direct pointers, find_setting() and friends don't need to return an ID value. Change-Id: I8c5c31bb68d3bca5350d43538335265a55fd5517 --- apps/gui/skin_engine/skin_parser.c | 6 ++--- apps/gui/skin_engine/skin_touchsupport.c | 2 +- apps/menu.c | 8 +++--- apps/menus/recording_menu.c | 20 +++++++-------- apps/plugin.c | 12 ++++----- apps/plugin.h | 18 ++++++-------- apps/plugins/lib/playback_control.c | 6 ++--- apps/plugins/rockboy/menu.c | 2 +- apps/plugins/xworld/sys.c | 2 +- apps/settings.c | 31 ++++++++++-------------- apps/settings.h | 4 +-- apps/settings_list.c | 6 ++--- apps/shortcuts.c | 2 +- apps/talk.c | 2 +- docs/PLUGIN_API | 2 +- 15 files changed, 56 insertions(+), 67 deletions(-) diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 435bad9e1f..ad5fa48756 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -823,7 +823,7 @@ static int parse_setting_and_lang(struct skin_element *element, else { #ifndef __PCTOOL__ - const struct settings_list *setting = find_setting_by_cfgname(temp, NULL); + const struct settings_list *setting = find_setting_by_cfgname(temp); if (!setting) return WPS_ERROR_INVALID_PARAM; @@ -1158,7 +1158,7 @@ static int parse_progressbar_tag(struct skin_element* element, param++; text = SKINOFFSETTOPTR(skin_buffer, param->data.text); #ifndef __PCTOOL__ - pb->setting = find_setting_by_cfgname(text, NULL); + pb->setting = find_setting_by_cfgname(text); if (!pb->setting) return WPS_ERROR_INVALID_PARAM; #endif @@ -1548,7 +1548,7 @@ static int touchregion_setup_setting(struct skin_element *element, int param_no, #ifndef __PCTOOL__ int p = param_no; char *name = get_param_text(element, p++); - const struct settings_list *setting = find_setting_by_cfgname(name, NULL); + const struct settings_list *setting = find_setting_by_cfgname(name); if (!setting) return WPS_ERROR_INVALID_PARAM; diff --git a/apps/gui/skin_engine/skin_touchsupport.c b/apps/gui/skin_engine/skin_touchsupport.c index 27b82e6608..b952709562 100644 --- a/apps/gui/skin_engine/skin_touchsupport.c +++ b/apps/gui/skin_engine/skin_touchsupport.c @@ -300,7 +300,7 @@ int skin_get_touchaction(struct gui_wps *gwps, int* edge_offset) case ACTION_TOUCH_REPMODE: /* cycle the repeat mode setting */ { const struct settings_list *rep_setting = - find_setting(&global_settings.repeat_mode, NULL); + find_setting(&global_settings.repeat_mode); option_select_next_val(rep_setting, false, true); audio_flush_and_reload_tracks(); returncode = ACTION_REDRAW; diff --git a/apps/menu.c b/apps/menu.c index f317f579a4..df2284be12 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -147,7 +147,7 @@ static const char* get_menu_item_name(int selected_item, type = (menu->flags&MENU_TYPE_MASK); if ((type == MT_SETTING) || (type == MT_SETTING_W_TEXT)) { - const struct settings_list *v = find_setting(menu->variable, NULL); + const struct settings_list *v = find_setting(menu->variable); if (v) return str(v->lang_id); else return "Not Done yet!"; @@ -356,14 +356,12 @@ void do_setting_from_menu(const struct menu_item_ex *temp, struct viewport parent[NB_SCREENS]) { char *title; - int setting_id; if (!temp) { panicf("do_setting_from_menu, NULL pointer"); return; } - const struct settings_list *setting = - find_setting(temp->variable, &setting_id); + const struct settings_list *setting = find_setting(temp->variable); if ((temp->flags&MENU_TYPE_MASK) == MT_SETTING_W_TEXT) title = temp->callback_and_desc->desc; @@ -523,7 +521,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected, ID2P(LANG_RESET_SETTING)); const struct menu_item_ex *context_menu; const struct settings_list *setting = - find_setting(temp->variable, NULL); + find_setting(temp->variable); #ifdef HAVE_QUICKSCREEN if (is_setting_quickscreenable(setting)) context_menu = &quickscreen_able_option; diff --git a/apps/menus/recording_menu.c b/apps/menus/recording_menu.c index 5439c861f4..4d9f24d643 100644 --- a/apps/menus/recording_menu.c +++ b/apps/menus/recording_menu.c @@ -462,30 +462,30 @@ int rectrigger(void) /* TODO: what to do if there is < 4 lines on the screen? */ settings[TRIGGER_MODE] = - find_setting(&global_settings.rec_trigger_mode, NULL); + find_setting(&global_settings.rec_trigger_mode); settings[TRIGGER_TYPE] = - find_setting(&global_settings.rec_trigger_type, NULL); + find_setting(&global_settings.rec_trigger_type); settings[PRERECORD_TIME] = - find_setting(&global_settings.rec_prerecord_time, NULL); + find_setting(&global_settings.rec_prerecord_time); settings[START_DURATION] = - find_setting(&global_settings.rec_start_duration, NULL); + find_setting(&global_settings.rec_start_duration); settings[STOP_POSTREC] = - find_setting(&global_settings.rec_stop_postrec, NULL); + find_setting(&global_settings.rec_stop_postrec); settings[STOP_GAP] = - find_setting(&global_settings.rec_stop_gap, NULL); + find_setting(&global_settings.rec_stop_gap); if (global_settings.peak_meter_dbfs) /* show the dB settings */ { settings[START_THRESHOLD] = - find_setting(&global_settings.rec_start_thres_db, NULL); + find_setting(&global_settings.rec_start_thres_db); settings[STOP_THRESHOLD] = - find_setting(&global_settings.rec_stop_thres_db, NULL); + find_setting(&global_settings.rec_stop_thres_db); } else { settings[START_THRESHOLD] = - find_setting(&global_settings.rec_start_thres_linear, NULL); + find_setting(&global_settings.rec_start_thres_linear); settings[STOP_THRESHOLD] = - find_setting(&global_settings.rec_stop_thres_linear, NULL); + find_setting(&global_settings.rec_stop_thres_linear); } gui_synclist_init(&lists, trigger_get_name, settings, false, 2, vp); gui_synclist_set_nb_items(&lists, TRIG_OPTION_COUNT*2); diff --git a/apps/plugin.c b/apps/plugin.c index f0667b7e9d..feba0f2cfc 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -669,10 +669,13 @@ static const struct plugin_api rockbox_api = { tagcache_retrieve, tagcache_search_finish, tagcache_get_numeric, -#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) + tagcache_get_stat, +#if defined(HAVE_TC_RAMCACHE) + tagcache_is_in_ram, +#if defined(HAVE_DIRCACHE) tagcache_fill_tags, #endif - tagcache_get_stat, +#endif #endif /* HAVE_TAGCACHE */ #ifdef HAVE_ALBUMART @@ -820,11 +823,6 @@ static const struct plugin_api rockbox_api = { /* new stuff at the end, sort into place next time the API gets incompatible */ -#ifdef HAVE_TAGCACHE -#ifdef HAVE_TC_RAMCACHE - tagcache_is_in_ram, -#endif -#endif }; static int plugin_buffer_handle; diff --git a/apps/plugin.h b/apps/plugin.h index e2a821bb57..62d8371e7d 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -157,12 +157,12 @@ int plugin_open(const char *plugin, const char *parameter); #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 256 +#define PLUGIN_API_VERSION 257 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define PLUGIN_MIN_API_VERSION 255 +#define PLUGIN_MIN_API_VERSION 257 /* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */ @@ -766,10 +766,13 @@ struct plugin_api { int tag, char *buf, long size); void (*tagcache_search_finish)(struct tagcache_search *tcs); long (*tagcache_get_numeric)(const struct tagcache_search *tcs, int tag); -#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) + struct tagcache_stat* (*tagcache_get_stat)(void); +#if defined(HAVE_TC_RAMCACHE) + bool (*tagcache_is_in_ram)(void); +#if defined(HAVE_DIRCACHE) bool (*tagcache_fill_tags)(struct mp3entry *id3, const char *filename); #endif - struct tagcache_stat* (*tagcache_get_stat)(void); +#endif #endif /* HAVE_TAGCACHE */ #ifdef HAVE_ALBUMART @@ -824,7 +827,7 @@ struct plugin_api { /* options */ const struct settings_list* (*get_settings_list)(int*count); - const struct settings_list* (*find_setting)(const void* variable, int *id); + const struct settings_list* (*find_setting)(const void* variable); int (*settings_save)(void); bool (*option_screen)(const struct settings_list *setting, struct viewport parent[NB_SCREENS], @@ -946,11 +949,6 @@ struct plugin_api { #endif /* new stuff at the end, sort into place next time the API gets incompatible */ -#ifdef HAVE_TAGCACHE -#ifdef HAVE_TC_RAMCACHE - bool (*tagcache_is_in_ram)(void); -#endif -#endif }; /* plugin header */ diff --git a/apps/plugins/lib/playback_control.c b/apps/plugins/lib/playback_control.c index a7f5b8baff..3e97916400 100644 --- a/apps/plugins/lib/playback_control.c +++ b/apps/plugins/lib/playback_control.c @@ -65,21 +65,21 @@ static bool nexttrack(void) static bool volume(void) { const struct settings_list* vol = - rb->find_setting(&rb->global_settings->volume, NULL); + rb->find_setting(&rb->global_settings->volume); return rb->option_screen((struct settings_list*)vol, parentvp, false, "Volume"); } static bool shuffle(void) { const struct settings_list* shuffle = - rb->find_setting(&rb->global_settings->playlist_shuffle, NULL); + rb->find_setting(&rb->global_settings->playlist_shuffle); return rb->option_screen((struct settings_list*)shuffle, parentvp, false, "Shuffle"); } static bool repeat_mode(void) { const struct settings_list* repeat = - rb->find_setting(&rb->global_settings->repeat_mode, NULL); + rb->find_setting(&rb->global_settings->repeat_mode); int old_repeat = rb->global_settings->repeat_mode; rb->option_screen((struct settings_list*)repeat, parentvp, false, "Repeat"); diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c index caa8d499cb..7fd7aabdc8 100644 --- a/apps/plugins/rockboy/menu.c +++ b/apps/plugins/rockboy/menu.c @@ -428,7 +428,7 @@ static void do_opt_menu(void) options.dirty=1; /* Assume that the settings have been changed */ struct viewport *parentvp = NULL; - const struct settings_list* vol = rb->find_setting(&rb->global_settings->volume, NULL); + const struct settings_list* vol = rb->find_setting(&rb->global_settings->volume); while(!done) { diff --git a/apps/plugins/xworld/sys.c b/apps/plugins/xworld/sys.c index ece9d87b66..e20322258d 100644 --- a/apps/plugins/xworld/sys.c +++ b/apps/plugins/xworld/sys.c @@ -286,7 +286,7 @@ static void do_sound_settings(struct System* sys) case 2: { const struct settings_list* vol = - rb->find_setting(&rb->global_settings->volume, NULL); + rb->find_setting(&rb->global_settings->volume); rb->option_screen((struct settings_list*)vol, NULL, false, "Volume"); break; } diff --git a/apps/settings.c b/apps/settings.c index e60b1b5f1a..c19a0b9b65 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -335,7 +335,6 @@ bool settings_load_config(const char* file, bool apply) { logf("%s()\r\n", __func__); const struct settings_list *setting; - int index; int fd; char line[128]; char* name; @@ -351,7 +350,7 @@ bool settings_load_config(const char* file, bool apply) if (!settings_parseline(line, &name, &value)) continue; - setting = find_setting_by_cfgname(name, &index); + setting = find_setting_by_cfgname(name); if (!setting) continue; @@ -1158,36 +1157,32 @@ void settings_reset(void) } /** Changing setting values **/ -const struct settings_list* find_setting(const void* variable, int *id) +const struct settings_list* find_setting(const void* variable) { - int i; - for(i=0;isetting == variable) + return setting; } + return NULL; } -const struct settings_list* find_setting_by_cfgname(const char* name, int *id) +const struct settings_list* find_setting_by_cfgname(const char* name) { - int i; logf("Searching for Setting: '%s'",name); - for (i=0; icfg_name && !strcasecmp(setting->cfg_name, name)) { logf("Found, flags: %s", debug_get_flags(settings[i].flags)); - if (id) *id = i; - return &settings[i]; + return setting; } } logf("Setting: '%s' Not Found!",name); + return NULL; } diff --git a/apps/settings.h b/apps/settings.h index 1c298d8330..1ad1923c73 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -263,8 +263,8 @@ void settings_display(void); 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); +const struct settings_list* find_setting(const void* variable); +const struct settings_list* find_setting_by_cfgname(const char* name); 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); void cfg_to_string(const struct settings_list *setting, char* buf, int buf_len); diff --git a/apps/settings_list.c b/apps/settings_list.c index 2ff4258c54..1bf8b4202f 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -600,7 +600,7 @@ static void qs_load_from_cfg(void *var, char *value) if (*value == '-') *item = NULL; else - *item = find_setting_by_cfgname(value, NULL); + *item = find_setting_by_cfgname(value); } static char* qs_write_to_cfg(void *var, char *buf, int buf_len) @@ -613,14 +613,14 @@ static char* qs_write_to_cfg(void *var, char *buf, int buf_len) static bool qs_is_changed(void* var, void* defaultval) { - const struct settings_list *defaultsetting = find_setting(defaultval, NULL); + const struct settings_list *defaultsetting = find_setting(defaultval); return var != defaultsetting; } static void qs_set_default(void* var, void* defaultval) { - *(const struct settings_list **)var = find_setting(defaultval, NULL); + *(const struct settings_list **)var = find_setting(defaultval); } #endif #ifdef HAVE_TOUCHSCREEN diff --git a/apps/shortcuts.c b/apps/shortcuts.c index cf372ce023..82e4a359bf 100644 --- a/apps/shortcuts.c +++ b/apps/shortcuts.c @@ -342,7 +342,7 @@ static int readline_cb(int n, char *buf, void *parameters) strmemccpy(sc->u.path, value, MAX_PATH); break; case SHORTCUT_SETTING: - sc->u.setting = find_setting_by_cfgname(value, NULL); + sc->u.setting = find_setting_by_cfgname(value); break; case SHORTCUT_TIME: #if CONFIG_RTC diff --git a/apps/talk.c b/apps/talk.c index c3a1148df4..65368e973f 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -1488,7 +1488,7 @@ void talk_setting(const void *global_settings_variable) const struct settings_list *setting; if (!global_settings.talk_menu) return; - setting = find_setting(global_settings_variable, NULL); + setting = find_setting(global_settings_variable); if (setting == NULL) return; if (setting->lang_id) diff --git a/docs/PLUGIN_API b/docs/PLUGIN_API index 834b3522be..29a7829b32 100644 --- a/docs/PLUGIN_API +++ b/docs/PLUGIN_API @@ -1759,7 +1759,7 @@ void semaphore_wait(struct semaphore *s) \param s \description -const struct settings_list* find_setting(const void* variable, int *id) +const struct settings_list* find_setting(const void* variable) \group options \param variable \param id