mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Use string_split_noalloc instead of string_split
This commit is contained in:
parent
01e5ec94bb
commit
fe5307c4ac
@ -58,7 +58,6 @@ void free_xkb(void)
|
||||
|
||||
int init_xkb(int fd, size_t size)
|
||||
{
|
||||
char *map_str = NULL;
|
||||
mod_map_idx = (xkb_mod_index_t *)calloc(
|
||||
MOD_MAP_SIZE, sizeof(xkb_mod_index_t));
|
||||
|
||||
@ -77,7 +76,7 @@ int init_xkb(int fd, size_t size)
|
||||
{
|
||||
if (fd >= 0)
|
||||
{
|
||||
map_str = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
char *map_str = (char*)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (map_str == MAP_FAILED)
|
||||
goto error;
|
||||
|
||||
@ -87,30 +86,33 @@ int init_xkb(int fd, size_t size)
|
||||
}
|
||||
else
|
||||
{
|
||||
struct string_list *list = NULL;
|
||||
struct string_list list = {0};
|
||||
struct xkb_rule_names rule = {0};
|
||||
settings_t *settings = config_get_ptr();
|
||||
const char *input_keyboard_layout = settings->arrays.input_keyboard_layout;
|
||||
const char *input_keyboard_layout =
|
||||
settings->arrays.input_keyboard_layout;
|
||||
|
||||
rule.rules = "evdev";
|
||||
|
||||
string_list_initialize(&list);
|
||||
|
||||
if (*input_keyboard_layout)
|
||||
{
|
||||
list = string_split(input_keyboard_layout, ":");
|
||||
if (list)
|
||||
if (string_split_noalloc(&list, input_keyboard_layout, ":"))
|
||||
{
|
||||
if (list->size >= 2)
|
||||
rule.variant = list->elems[1].data;
|
||||
if (list->size >= 1)
|
||||
rule.layout = list->elems[0].data;
|
||||
if (list.size >= 1)
|
||||
{
|
||||
rule.layout = list.elems[0].data;
|
||||
if (list.size >= 2)
|
||||
rule.variant = list.elems[1].data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xkb_map = xkb_keymap_new_from_names(xkb_ctx,
|
||||
&rule, XKB_MAP_COMPILE_NO_FLAGS);
|
||||
|
||||
if (list)
|
||||
string_list_free(list);
|
||||
string_list_deinitialize(&list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ static bool task_overlay_load_desc(
|
||||
bool ret = true;
|
||||
bool by_pixel = false;
|
||||
char *key = NULL;
|
||||
struct string_list *list = NULL;
|
||||
struct string_list list = {0};
|
||||
const char *x = NULL;
|
||||
const char *y = NULL;
|
||||
const char *box = NULL;
|
||||
@ -157,26 +157,25 @@ static bool task_overlay_load_desc(
|
||||
goto end;
|
||||
}
|
||||
|
||||
list = string_split(overlay, ", ");
|
||||
|
||||
if (!list)
|
||||
string_list_initialize(&list);
|
||||
if (!string_split_noalloc(&list, overlay, ", "))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split overlay desc.\n");
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (list->size < 6)
|
||||
if (list.size < 6)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Overlay desc is invalid. Requires at least 6 tokens.\n");
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
key = list->elems[0].data;
|
||||
x = list->elems[1].data;
|
||||
y = list->elems[2].data;
|
||||
box = list->elems[3].data;
|
||||
key = list.elems[0].data;
|
||||
x = list.elems[1].data;
|
||||
y = list.elems[2].data;
|
||||
box = list.elems[3].data;
|
||||
|
||||
desc->retro_key_idx = 0;
|
||||
BIT256_CLEAR_ALL(desc->button_mask);
|
||||
@ -269,8 +268,8 @@ static bool task_overlay_load_desc(
|
||||
break;
|
||||
}
|
||||
|
||||
desc->range_x = (float)strtod(list->elems[4].data, NULL) * width_mod;
|
||||
desc->range_y = (float)strtod(list->elems[5].data, NULL) * height_mod;
|
||||
desc->range_x = (float)strtod(list.elems[4].data, NULL) * width_mod;
|
||||
desc->range_y = (float)strtod(list.elems[5].data, NULL) * height_mod;
|
||||
|
||||
desc->mod_x = desc->x - desc->range_x;
|
||||
desc->mod_w = 2.0f * desc->range_x;
|
||||
@ -304,8 +303,7 @@ static bool task_overlay_load_desc(
|
||||
input_overlay->pos ++;
|
||||
|
||||
end:
|
||||
if (list)
|
||||
string_list_free(list);
|
||||
string_list_deinitialize(&list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -611,21 +609,25 @@ static void task_overlay_deferred_load(retro_task_t *task)
|
||||
if (config_get_array(conf, overlay->config.rect.key,
|
||||
overlay->config.rect.array, sizeof(overlay->config.rect.array)))
|
||||
{
|
||||
struct string_list *list = string_split(overlay->config.rect.array, ", ");
|
||||
struct string_list list = {0};
|
||||
|
||||
if (!list || list->size < 4)
|
||||
string_list_initialize(&list);
|
||||
|
||||
if ( !string_split_noalloc(
|
||||
&list, overlay->config.rect.array, ", ")
|
||||
|| list.size < 4)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n",
|
||||
overlay->config.rect.array);
|
||||
string_list_free(list);
|
||||
string_list_deinitialize(&list);
|
||||
goto error;
|
||||
}
|
||||
|
||||
overlay->x = (float)strtod(list->elems[0].data, NULL);
|
||||
overlay->y = (float)strtod(list->elems[1].data, NULL);
|
||||
overlay->w = (float)strtod(list->elems[2].data, NULL);
|
||||
overlay->h = (float)strtod(list->elems[3].data, NULL);
|
||||
string_list_free(list);
|
||||
overlay->x = (float)strtod(list.elems[0].data, NULL);
|
||||
overlay->y = (float)strtod(list.elems[1].data, NULL);
|
||||
overlay->w = (float)strtod(list.elems[2].data, NULL);
|
||||
overlay->h = (float)strtod(list.elems[3].data, NULL);
|
||||
string_list_deinitialize(&list);
|
||||
}
|
||||
|
||||
/* Assume for now that scaling center is in the middle.
|
||||
|
@ -787,25 +787,26 @@ extern "C" {
|
||||
|
||||
enum retro_language uwp_get_language(void)
|
||||
{
|
||||
string_list* split = NULL;
|
||||
auto lang = Windows::System::UserProfile::GlobalizationPreferences::Languages->GetAt(0);
|
||||
char lang_bcp[16] = { 0 };
|
||||
char lang_iso[16] = { 0 };
|
||||
auto lang = Windows::System::UserProfile::GlobalizationPreferences::Languages->GetAt(0);
|
||||
struct string_list split = {0};
|
||||
char lang_bcp[16] = {0};
|
||||
char lang_iso[16] = {0};
|
||||
|
||||
wcstombs(lang_bcp, lang->Data(), sizeof(lang_bcp));
|
||||
|
||||
/* Trying to convert BCP 47 language codes to ISO 639 ones */
|
||||
split = string_split(lang_bcp, "-");
|
||||
string_list_initialize(&split);
|
||||
string_split_noalloc(&split, lang_bcp, "-");
|
||||
|
||||
strlcat(lang_iso, split->elems[0].data, sizeof(lang_iso));
|
||||
strlcat(lang_iso, split.elems[0].data, sizeof(lang_iso));
|
||||
|
||||
if (split->size >= 2)
|
||||
if (split.size >= 2)
|
||||
{
|
||||
strlcat(lang_iso, "_", sizeof(lang_iso));
|
||||
strlcat(lang_iso, split->elems[split->size >= 3 ? 2 : 1].data,
|
||||
strlcat(lang_iso, split.elems[split.size >= 3 ? 2 : 1].data,
|
||||
sizeof(lang_iso));
|
||||
}
|
||||
free(split);
|
||||
string_list_deinitialize(&split);
|
||||
return rarch_get_language_from_iso(lang_iso);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user