From 103d5dbf456e40166d26cd004e2b4b2627151f3c Mon Sep 17 00:00:00 2001 From: Hugo Hromic Date: Mon, 6 Jul 2020 19:54:45 +0100 Subject: [PATCH] (Drivers) Cleanup unused `add_null_entries` parameter Null driver entries will be now handled at the UI level. --- retroarch.c | 248 ++++++++++++---------------------------------------- 1 file changed, 55 insertions(+), 193 deletions(-) diff --git a/retroarch.c b/retroarch.c index b9b5ee6ea6..51aa5e3b9d 100644 --- a/retroarch.c +++ b/retroarch.c @@ -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; @@ -10546,17 +10545,10 @@ struct string_list *string_list_new_special(enum string_list_type type, #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; + 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); - } + string_list_append(s, opt, attr); } break; #endif @@ -10566,11 +10558,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_BLUETOOTH_DRIVERS: @@ -10580,11 +10568,7 @@ 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); + string_list_append(s, opt, attr); } break; #endif @@ -10595,11 +10579,7 @@ 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); + string_list_append(s, opt, attr); } break; #endif @@ -10609,11 +10589,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_AUDIO_DRIVERS: @@ -10622,11 +10598,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_AUDIO_RESAMPLER_DRIVERS: @@ -10635,11 +10607,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_VIDEO_DRIVERS: @@ -10648,11 +10616,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_INPUT_DRIVERS: @@ -10661,11 +10625,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_INPUT_HID_DRIVERS: @@ -10675,11 +10635,7 @@ 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); + string_list_append(s, opt, attr); } #endif break; @@ -10689,11 +10645,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_RECORD_DRIVERS: @@ -10702,11 +10654,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_MIDI_DRIVERS: @@ -10715,11 +10663,7 @@ 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); + string_list_append(s, opt, attr); } break; case STRING_LIST_SUPPORTED_CORES_PATHS: @@ -33620,25 +33564,17 @@ 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]; - } + strlcpy(s, ident, len); + return camera_drivers[i]; } } else if (string_is_equal(label, "location_driver")) @@ -33646,14 +33582,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return location_drivers[i]; } } #ifdef HAVE_MENU @@ -33662,14 +33593,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return menu_ctx_drivers[i]; } } #endif @@ -33678,14 +33604,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return input_drivers[i]; } } else if (string_is_equal(label, "input_joypad_driver")) @@ -33693,14 +33614,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return joypad_drivers[i]; } } else if (string_is_equal(label, "video_driver")) @@ -33708,14 +33624,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return video_drivers[i]; } } else if (string_is_equal(label, "audio_driver")) @@ -33723,14 +33634,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return audio_drivers[i]; } } else if (string_is_equal(label, "record_driver")) @@ -33738,14 +33644,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return record_drivers[i]; } } else if (string_is_equal(label, "midi_driver")) @@ -33753,14 +33654,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return midi_drivers[i]; } } else if (string_is_equal(label, "audio_resampler_driver")) @@ -33768,14 +33664,9 @@ static const void *find_driver_nonempty( 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); - } + strlcpy(s, ident, len); + return audio_resampler_driver_find_handle(i); } } else if (string_is_equal(label, "bluetooth_driver")) @@ -33783,14 +33674,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return bluetooth_drivers[i]; } } else if (string_is_equal(label, "wifi_driver")) @@ -33798,14 +33684,9 @@ static const void *find_driver_nonempty( 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]; - } + strlcpy(s, ident, len); + return wifi_drivers[i]; } } @@ -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: