Move some code from retroarch.c over to menu_driver.c

This commit is contained in:
twinaphex 2021-09-09 15:22:12 +02:00
parent 6c79cebc6e
commit 28389d30e8
4 changed files with 118 additions and 113 deletions

View File

@ -23,6 +23,7 @@
#include <retro_timers.h>
#include "menu_driver.h"
#include "menu_cbs.h"
#include "../list_special.h"
#include "../tasks/tasks_internal.h"
#ifdef HAVE_LANGEXTRA
@ -2363,3 +2364,98 @@ enum menu_driver_id_type menu_driver_set_id(
return MENU_DRIVER_ID_UNKNOWN;
}
const char *config_get_menu_driver_options(void)
{
return char_list_new_special(STRING_LIST_MENU_DRIVERS, NULL);
}
bool menu_entries_search_push(const char *search_term)
{
size_t i;
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
char search_term_clipped[MENU_SEARCH_FILTER_MAX_LENGTH];
search_term_clipped[0] = '\0';
/* Sanity check + verify whether we have reached
* the maximum number of allowed search terms */
if (!search ||
string_is_empty(search_term) ||
(search->size >= MENU_SEARCH_FILTER_MAX_TERMS))
return false;
/* Check whether search term already exists
* > Note that we clip the input search term
* to MENU_SEARCH_FILTER_MAX_LENGTH characters
* *before* comparing existing entries */
strlcpy(search_term_clipped, search_term,
sizeof(search_term_clipped));
for (i = 0; i < search->size; i++)
{
if (string_is_equal(search_term_clipped,
search->terms[i]))
return false;
}
/* Add search term */
strlcpy(search->terms[search->size], search_term_clipped,
sizeof(search->terms[search->size]));
search->size++;
return true;
}
bool menu_entries_search_pop(void)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
/* Do nothing if list of search terms is empty */
if (!search ||
(search->size == 0))
return false;
/* Remove last item from the list */
search->size--;
search->terms[search->size][0] = '\0';
return true;
}
menu_search_terms_t *menu_entries_search_get_terms(void)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
if (!search ||
(search->size == 0))
return NULL;
return search;
}
void menu_entries_search_append_terms_string(char *s, size_t len)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
if (search &&
(search->size > 0) &&
s)
{
size_t current_len = strlen_size(s, len);
size_t i;
/* If buffer is already 'full', nothing
* further can be added */
if (current_len >= len)
return;
s += current_len;
len -= current_len;
for (i = 0; i < search->size; i++)
{
strlcat(s, " > ", len);
strlcat(s, search->terms[i], len);
}
}
}

View File

@ -781,6 +781,17 @@ void menu_display_common_image_upload(
enum menu_driver_id_type menu_driver_set_id(
const char *driver_name);
/**
* config_get_menu_driver_options:
*
* Get an enumerated list of all menu driver names,
* separated by '|'.
*
* Returns: string listing of all menu driver names,
* separated by '|'.
**/
const char *config_get_menu_driver_options(void);
bool generic_menu_init_list(struct menu_state *menu_st,
settings_t *settings);

View File

@ -195,11 +195,17 @@ bool menu_entries_append_enum(file_list_t *list,
bool menu_entries_ctl(enum menu_entries_ctl_state state, void *data);
bool menu_entries_search_push(const char *search_term);
bool menu_entries_search_pop(void);
menu_search_terms_t *menu_entries_search_get_terms(void);
/* Convenience function: Appends list of current
* search terms to specified string */
void menu_entries_search_append_terms_string(char *s, size_t len);
menu_search_terms_t *menu_entries_search_get_terms_internal(void);
/* Searches current menu list for specified 'needle'
* string. If string is found, returns true and sets
* 'idx' to the matching list entry index. */

View File

@ -2349,7 +2349,7 @@ bool menu_entries_ctl(enum menu_entries_ctl_state state, void *data)
return true;
}
static menu_search_terms_t *menu_entries_search_get_terms_internal(void)
menu_search_terms_t *menu_entries_search_get_terms_internal(void)
{
struct rarch_state *p_rarch = &rarch_st;
struct menu_state *menu_st = &p_rarch->menu_driver_state;
@ -2368,99 +2368,6 @@ static menu_search_terms_t *menu_entries_search_get_terms_internal(void)
return &cbs->search;
}
bool menu_entries_search_push(const char *search_term)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
char search_term_clipped[MENU_SEARCH_FILTER_MAX_LENGTH];
size_t i;
search_term_clipped[0] = '\0';
/* Sanity check + verify whether we have reached
* the maximum number of allowed search terms */
if (!search ||
string_is_empty(search_term) ||
(search->size >= MENU_SEARCH_FILTER_MAX_TERMS))
return false;
/* Check whether search term already exists
* > Note that we clip the input search term
* to MENU_SEARCH_FILTER_MAX_LENGTH characters
* *before* comparing existing entries */
strlcpy(search_term_clipped, search_term,
sizeof(search_term_clipped));
for (i = 0; i < search->size; i++)
{
if (string_is_equal(search_term_clipped,
search->terms[i]))
return false;
}
/* Add search term */
strlcpy(search->terms[search->size], search_term_clipped,
sizeof(search->terms[search->size]));
search->size++;
return true;
}
bool menu_entries_search_pop(void)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
/* Do nothing if list of search terms is empty */
if (!search ||
(search->size == 0))
return false;
/* Remove last item from the list */
search->size--;
search->terms[search->size][0] = '\0';
return true;
}
menu_search_terms_t *menu_entries_search_get_terms(void)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
if (!search ||
(search->size == 0))
return NULL;
return search;
}
/* Convenience function: Appends list of current
* search terms to specified string */
void menu_entries_search_append_terms_string(char *s, size_t len)
{
menu_search_terms_t *search = menu_entries_search_get_terms_internal();
if (search &&
(search->size > 0) &&
s)
{
size_t current_len = strlen_size(s, len);
size_t i;
/* If buffer is already 'full', nothing
* further can be added */
if (current_len >= len)
return;
s += current_len;
len -= current_len;
for (i = 0; i < search->size; i++)
{
strlcat(s, " > ", len);
strlcat(s, search->terms[i], len);
}
}
}
/* Searches current menu list for specified 'needle'
* string. If string is found, returns true and sets
* 'idx' to the matching list entry index. */
@ -2475,10 +2382,10 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
char needle_char = 0;
size_t i;
if (!list ||
string_is_empty(needle) ||
!idx)
goto end;
if ( !list
|| string_is_empty(needle)
|| !idx)
return match_found;
/* Check if we are searching for a single
* Latin alphabet character */
@ -2558,7 +2465,6 @@ bool menu_entries_list_search(const char *needle, size_t *idx)
}
}
end:
return match_found;
}
@ -2626,20 +2532,6 @@ void menu_display_handle_wallpaper_upload(
MENU_IMAGE_WALLPAPER);
}
/**
* config_get_menu_driver_options:
*
* Get an enumerated list of all menu driver names,
* separated by '|'.
*
* Returns: string listing of all menu driver names,
* separated by '|'.
**/
const char *config_get_menu_driver_options(void)
{
return char_list_new_special(STRING_LIST_MENU_DRIVERS, NULL);
}
#ifdef HAVE_COMPRESSION
/* This function gets called at first startup on Android/iOS
* when we need to extract the APK contents/zip file. This