mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 20:51:47 +00:00
Create RARCH_DRIVER_CTL_FIND_INDEX
This commit is contained in:
parent
668373f9f8
commit
2cbb18b4e4
@ -737,9 +737,16 @@ static void audio_driver_setup_rewind(void)
|
||||
|
||||
static bool find_audio_driver(void)
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
int i = find_driver_index("audio_driver", settings->audio.driver);
|
||||
drv.label = "audio_driver";
|
||||
drv.s = settings->audio.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
current_audio = (const audio_driver_t*)audio_driver_find_handle(i);
|
||||
|
@ -90,8 +90,16 @@ const char* config_get_camera_driver_options(void)
|
||||
|
||||
void find_camera_driver(void)
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
int i = find_driver_index("camera_driver", settings->camera.driver);
|
||||
|
||||
drv.label = "camera_driver";
|
||||
drv.s = settings->camera.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
camera_driver = (const camera_driver_t*)camera_driver_find_handle(i);
|
||||
|
16
driver.c
16
driver.c
@ -120,7 +120,7 @@ static const void *find_driver_nonempty(const char *label, int i,
|
||||
}
|
||||
|
||||
/**
|
||||
* find_driver_index:
|
||||
* driver_find_index:
|
||||
* @label : string of driver type to be found.
|
||||
* @drv : identifier of driver to be found.
|
||||
*
|
||||
@ -129,7 +129,7 @@ static const void *find_driver_nonempty(const char *label, int i,
|
||||
* Returns: -1 if no driver based on @label and @drv found, otherwise
|
||||
* index number of the driver found in the array.
|
||||
**/
|
||||
int find_driver_index(const char * label, const char *drv)
|
||||
static int driver_find_index(const char * label, const char *drv)
|
||||
{
|
||||
unsigned i;
|
||||
char str[256];
|
||||
@ -165,7 +165,7 @@ static bool driver_find_first(const char *label, char *s, size_t len)
|
||||
**/
|
||||
static bool driver_find_prev(const char *label, char *s, size_t len)
|
||||
{
|
||||
int i = find_driver_index(label, s);
|
||||
int i = driver_find_index(label, s);
|
||||
if (i > 0)
|
||||
find_driver_nonempty(label, i - 1, s, len);
|
||||
else
|
||||
@ -187,7 +187,7 @@ static bool driver_find_prev(const char *label, char *s, size_t len)
|
||||
**/
|
||||
bool driver_find_next(const char *label, char *s, size_t len)
|
||||
{
|
||||
int i = find_driver_index(label, s);
|
||||
int i = driver_find_index(label, s);
|
||||
if (i >= 0 && !string_is_equal(s, "null"))
|
||||
find_driver_nonempty(label, i + 1, s, len);
|
||||
else
|
||||
@ -496,6 +496,14 @@ bool driver_ctl(enum driver_ctl_state state, void *data)
|
||||
return false;
|
||||
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(drv->label, drv->s);
|
||||
return true;
|
||||
}
|
||||
case RARCH_DRIVER_CTL_NONE:
|
||||
default:
|
||||
break;
|
||||
|
20
driver.h
20
driver.h
@ -207,14 +207,18 @@ enum driver_ctl_state
|
||||
|
||||
RARCH_DRIVER_CTL_FIND_PREV,
|
||||
|
||||
RARCH_DRIVER_CTL_FIND_NEXT
|
||||
RARCH_DRIVER_CTL_FIND_NEXT,
|
||||
|
||||
/* Find index of the driver, based on @label. */
|
||||
RARCH_DRIVER_CTL_FIND_INDEX
|
||||
|
||||
};
|
||||
|
||||
typedef struct driver_ctx_info
|
||||
{
|
||||
const char *label;
|
||||
char *s;
|
||||
size_t len;
|
||||
ssize_t len;
|
||||
} driver_ctx_info_t;
|
||||
|
||||
|
||||
@ -233,18 +237,6 @@ typedef struct driver_ctx_info
|
||||
* Typically, if a driver intends to make use of this, it should
|
||||
* set this to true at the end of its 'init' function. */
|
||||
|
||||
/**
|
||||
* find_driver_index:
|
||||
* @label : string of driver type to be found.
|
||||
* @drv : identifier of driver to be found.
|
||||
*
|
||||
* Find index of the driver, based on @label.
|
||||
*
|
||||
* Returns: -1 if no driver based on @label and @drv found, otherwise
|
||||
* index number of the driver found in the array.
|
||||
**/
|
||||
int find_driver_index(const char * label, const char *drv);
|
||||
|
||||
bool driver_ctl(enum driver_ctl_state state, void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -235,6 +235,7 @@ const char* config_get_video_driver_options(void)
|
||||
static bool find_video_driver(void)
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
#if defined(HAVE_OPENGL) && defined(HAVE_FBO)
|
||||
@ -255,7 +256,13 @@ static bool find_video_driver(void)
|
||||
RARCH_WARN("Frontend supports get_video_driver() but did not specify one.\n");
|
||||
}
|
||||
|
||||
i = find_driver_index("video_driver", settings->video.driver);
|
||||
drv.label = "video_driver";
|
||||
drv.s = settings->video.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
current_video = (video_driver_t*)video_driver_find_handle(i);
|
||||
else
|
||||
|
@ -737,9 +737,16 @@ bool input_driver_ctl(enum rarch_input_ctl_state state, void *data)
|
||||
return false;
|
||||
case RARCH_INPUT_CTL_FIND_DRIVER:
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
int i = find_driver_index("input_driver",
|
||||
settings->input.driver);
|
||||
|
||||
drv.label = "input_driver";
|
||||
drv.s = settings->input.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
current_input = (const input_driver_t*)input_driver_find_handle(i);
|
||||
|
@ -85,8 +85,16 @@ const char* config_get_location_driver_options(void)
|
||||
|
||||
void find_location_driver(void)
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
int i = find_driver_index("location_driver", settings->location.driver);
|
||||
|
||||
drv.label = "location_driver";
|
||||
drv.s = settings->location.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
location_driver = (const location_driver_t*)location_driver_find_handle(i);
|
||||
|
@ -105,9 +105,17 @@ const char *config_get_menu_driver_options(void)
|
||||
|
||||
void find_menu_driver(void)
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
int i = find_driver_index("menu_driver", settings->menu.driver);
|
||||
drv.label = "menu_driver";
|
||||
drv.s = settings->menu.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
menu_driver_ctx = (const menu_ctx_driver_t*)menu_driver_find_handle(i);
|
||||
else
|
||||
|
@ -89,8 +89,16 @@ const char* config_get_record_driver_options(void)
|
||||
|
||||
void find_record_driver(void)
|
||||
{
|
||||
int i;
|
||||
driver_ctx_info_t drv;
|
||||
settings_t *settings = config_get_ptr();
|
||||
int i = find_driver_index("record_driver", settings->record.driver);
|
||||
|
||||
drv.label = "record_driver";
|
||||
drv.s = settings->record.driver;
|
||||
|
||||
driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);
|
||||
|
||||
i = drv.len;
|
||||
|
||||
if (i >= 0)
|
||||
recording_driver = (const record_driver_t*)record_driver_find_handle(i);
|
||||
|
Loading…
x
Reference in New Issue
Block a user