Remove duplicated code to search for a setting by its cfg name
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30428 a1c6a512-1295-4272-9138-f99709370657
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 59c7e92..adac487 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -620,13 +620,8 @@
}
else
{
- /* Find the setting */
- for (i=0; i<nb_settings; i++)
- if (settings[i].cfg_name &&
- !strcmp(settings[i].cfg_name, temp))
- break;
#ifndef __PCTOOL__
- if (i == nb_settings)
+ if (find_setting_by_cfgname(temp, &i) == NULL)
return WPS_ERROR_INVALID_PARAM;
#endif
}
@@ -1148,14 +1143,10 @@
int p = param_no;
char *name = element->params[p++].data.text;
int j;
- /* Find the setting */
- for (j=0; j<nb_settings; j++)
- if (settings[j].cfg_name &&
- !strcmp(settings[j].cfg_name, name))
- break;
- if (j==nb_settings)
+
+ region->setting_data.setting = find_setting_by_cfgname(name, &j);
+ if (region->setting_data.setting == NULL)
return WPS_ERROR_INVALID_PARAM;
- region->setting_data.setting = (void*)&settings[j];
if (region->action == ACTION_SETTINGS_SET)
{
char* text;
diff --git a/apps/settings.c b/apps/settings.c
index 623bc5b..258face 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -1087,6 +1087,20 @@
}
return NULL;
}
+const struct settings_list* find_setting_by_cfgname(const char* name, int *id)
+{
+ int i;
+ for (i=0; i<nb_settings; i++)
+ {
+ if (settings[i].cfg_name &&
+ !strcmp(settings[i].cfg_name, name))
+ {
+ if (id) *id = i;
+ return &settings[i];
+ }
+ }
+ return NULL;
+}
bool set_bool(const char* string, const bool* variable )
{
diff --git a/apps/settings.h b/apps/settings.h
index 05965b3..f48dd5d 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -231,6 +231,7 @@
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_string_to_int(int setting_id, int* out, const char* str);
bool cfg_to_string(int setting_id, char* buf, int buf_len);