(Drivers) Cleanup unused `add_null_entries` parameter

Null driver entries will be now handled at the UI level.
This commit is contained in:
Hugo Hromic 2020-07-06 19:54:45 +01:00
parent c985dcc84d
commit 103d5dbf45
1 changed files with 55 additions and 193 deletions

View File

@ -10532,7 +10532,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
core_info_list_t *core_info_list = NULL;
const core_info_t *core_info = NULL;
struct string_list *s = string_list_new();
bool add_null_entries = true;
if (!s || !len)
goto error;
@ -10545,19 +10544,12 @@ struct string_list *string_list_new_special(enum string_list_type type,
case STRING_LIST_MENU_DRIVERS:
#ifdef HAVE_MENU
for (i = 0; menu_ctx_drivers[i]; i++)
{
if (menu_ctx_drivers[i])
{
const char *opt = menu_ctx_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
}
break;
#endif
case STRING_LIST_CAMERA_DRIVERS:
@ -10566,10 +10558,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = camera_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10580,10 +10568,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = bluetooth_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10595,10 +10579,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = wifi_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10609,10 +10589,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = location_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10622,10 +10598,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = audio_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10635,10 +10607,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = audio_resampler_driver_find_ident(i);
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10648,10 +10616,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = video_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10661,10 +10625,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = input_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10675,10 +10635,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = hid_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
#endif
@ -10689,10 +10645,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = joypad_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10702,10 +10654,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = record_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -10715,10 +10663,6 @@ struct string_list *string_list_new_special(enum string_list_type type,
const char *opt = midi_drivers[i]->ident;
*len += strlen(opt) + 1;
if (!add_null_entries)
add_null_entries = (i == 0) || !string_is_equal(opt, "null");
if (add_null_entries)
string_list_append(s, opt, attr);
}
break;
@ -33620,194 +33564,131 @@ static void camera_driver_find_driver(struct rarch_state *p_rarch)
* pointer to driver.
**/
static const void *find_driver_nonempty(
bool add_null_entries,
const char *label, int i,
char *s, size_t len)
{
bool add_entry = add_null_entries;
if (string_is_equal(label, "camera_driver"))
{
if (camera_drivers[i])
{
const char *ident = camera_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return camera_drivers[i];
}
}
}
else if (string_is_equal(label, "location_driver"))
{
if (location_drivers[i])
{
const char *ident = location_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return location_drivers[i];
}
}
}
#ifdef HAVE_MENU
else if (string_is_equal(label, "menu_driver"))
{
if (menu_ctx_drivers[i])
{
const char *ident = menu_ctx_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return menu_ctx_drivers[i];
}
}
}
#endif
else if (string_is_equal(label, "input_driver"))
{
if (input_drivers[i])
{
const char *ident = input_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return input_drivers[i];
}
}
}
else if (string_is_equal(label, "input_joypad_driver"))
{
if (joypad_drivers[i])
{
const char *ident = joypad_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return joypad_drivers[i];
}
}
}
else if (string_is_equal(label, "video_driver"))
{
if (video_drivers[i])
{
const char *ident = video_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return video_drivers[i];
}
}
}
else if (string_is_equal(label, "audio_driver"))
{
if (audio_drivers[i])
{
const char *ident = audio_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return audio_drivers[i];
}
}
}
else if (string_is_equal(label, "record_driver"))
{
if (record_drivers[i])
{
const char *ident = record_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return record_drivers[i];
}
}
}
else if (string_is_equal(label, "midi_driver"))
{
if (midi_driver_find_handle(i))
{
const char *ident = midi_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return midi_drivers[i];
}
}
}
else if (string_is_equal(label, "audio_resampler_driver"))
{
if (audio_resampler_driver_find_handle(i))
{
const char *ident = audio_resampler_driver_find_ident(i);
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return audio_resampler_driver_find_handle(i);
}
}
}
else if (string_is_equal(label, "bluetooth_driver"))
{
if (bluetooth_drivers[i])
{
const char *ident = bluetooth_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return bluetooth_drivers[i];
}
}
}
else if (string_is_equal(label, "wifi_driver"))
{
if (wifi_drivers[i])
{
const char *ident = wifi_drivers[i]->ident;
if (!add_entry)
add_entry = i == 0 || !string_is_equal(ident, "null");
if (add_entry)
{
strlcpy(s, ident, len);
return wifi_drivers[i];
}
}
}
return NULL;
}
@ -33822,8 +33703,7 @@ static const void *find_driver_nonempty(
* Returns: -1 if no driver based on @label and @drv found, otherwise
* index number of the driver found in the array.
**/
static int driver_find_index(bool add_null_entries,
const char * label, const char *drv)
static int driver_find_index(const char *label, const char *drv)
{
unsigned i;
char str[256];
@ -33831,8 +33711,7 @@ static int driver_find_index(bool add_null_entries,
str[0] = '\0';
for (i = 0;
find_driver_nonempty(add_null_entries,
label, i, str, sizeof(str)) != NULL; i++)
find_driver_nonempty(label, i, str, sizeof(str)) != NULL; i++)
{
if (string_is_empty(str))
break;
@ -33851,15 +33730,12 @@ static int driver_find_index(bool add_null_entries,
*
* Find last driver in driver array.
**/
static bool driver_find_last(
bool add_null_entries,
const char *label, char *s, size_t len)
static bool driver_find_last(const char *label, char *s, size_t len)
{
unsigned i;
for (i = 0;
find_driver_nonempty(add_null_entries,
label, i, s, len) != NULL; i++)
find_driver_nonempty(label, i, s, len) != NULL; i++)
{}
if (i)
@ -33867,7 +33743,7 @@ static bool driver_find_last(
else
i = 0;
find_driver_nonempty(add_null_entries, label, i, s, len);
find_driver_nonempty(label, i, s, len);
return true;
}
@ -33879,17 +33755,13 @@ static bool driver_find_last(
*
* Find previous driver in driver array.
**/
static bool driver_find_prev(
bool add_null_entries,
const char *label, char *s, size_t len)
static bool driver_find_prev(const char *label, char *s, size_t len)
{
int i = driver_find_index(add_null_entries, label, s);
int i = driver_find_index(label, s);
if (i > 0)
{
find_driver_nonempty(
add_null_entries,
label, i - 1, s, len);
find_driver_nonempty(label, i - 1, s, len);
return true;
}
@ -33906,17 +33778,13 @@ static bool driver_find_prev(
*
* Find next driver in driver array.
**/
static bool driver_find_next(
bool add_null_entries,
const char *label, char *s, size_t len)
static bool driver_find_next(const char *label, char *s, size_t len)
{
int i = driver_find_index(add_null_entries, label, s);
int i = driver_find_index(label, s);
if (i >= 0 && string_is_not_equal(s, "null"))
{
find_driver_nonempty(
add_null_entries,
label, i + 1, s, len);
find_driver_nonempty(label, i + 1, s, len);
return true;
}
@ -34328,7 +34196,6 @@ static void retroarch_deinit_drivers(struct rarch_state *p_rarch)
bool driver_ctl(enum driver_ctl_state state, void *data)
{
struct rarch_state *p_rarch = &rarch_st;
bool add_null_entries = true;
switch (state)
{
@ -34345,8 +34212,7 @@ bool driver_ctl(enum driver_ctl_state state, void *data)
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
if (!drv)
return false;
find_driver_nonempty(add_null_entries,
drv->label, 0, drv->s, drv->len);
find_driver_nonempty(drv->label, 0, drv->s, drv->len);
}
break;
case RARCH_DRIVER_CTL_FIND_LAST:
@ -34354,32 +34220,28 @@ bool driver_ctl(enum driver_ctl_state state, void *data)
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
if (!drv)
return false;
return driver_find_last(add_null_entries,
drv->label, drv->s, drv->len);
return driver_find_last(drv->label, drv->s, drv->len);
}
case RARCH_DRIVER_CTL_FIND_PREV:
{
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
if (!drv)
return false;
return driver_find_prev(add_null_entries,
drv->label, drv->s, drv->len);
return driver_find_prev(drv->label, drv->s, drv->len);
}
case RARCH_DRIVER_CTL_FIND_NEXT:
{
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
if (!drv)
return false;
return driver_find_next(add_null_entries,
drv->label, drv->s, drv->len);
return driver_find_next(drv->label, drv->s, drv->len);
}
case RARCH_DRIVER_CTL_FIND_INDEX:
{
driver_ctx_info_t *drv = (driver_ctx_info_t*)data;
if (!drv)
return false;
drv->len = driver_find_index(add_null_entries,
drv->label, drv->s);
drv->len = driver_find_index(drv->label, drv->s);
}
break;
case RARCH_DRIVER_CTL_NONE: