Skip to content

Commit

Permalink
Cleanup core_info_get_name - reuse core_info_list_iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed Feb 7, 2016
1 parent c7b9625 commit eb33197
Showing 1 changed file with 35 additions and 56 deletions.
91 changes: 35 additions & 56 deletions core_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ static void core_info_list_free(core_info_list_t *core_info_list)
free(core_info_list);
}

static config_file_t *core_info_list_iterate(struct string_list *contents, size_t i)
{
char info_path_base[PATH_MAX_LENGTH];
char info_path[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();

if (!contents->elems[i].data)
return NULL;

fill_pathname_base(info_path_base, contents->elems[i].data,
sizeof(info_path_base));
path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
char *substr = strrchr(info_path_base, '_');
if (substr)
*substr = '\0';
#endif

strlcat(info_path_base, ".info", sizeof(info_path_base));

fill_pathname_join(info_path, (*settings->libretro_info_path) ?
settings->libretro_info_path : settings->libretro_directory,
info_path_base, sizeof(info_path));

return config_file_new(info_path);
}

void core_info_get_name(const char *path, char *s, size_t len)
{
size_t i;
Expand All @@ -184,35 +212,12 @@ void core_info_get_name(const char *path, char *s, size_t len)

for (i = 0; i < contents->size; i++)
{
config_file_t *conf = NULL;
char info_path_base[PATH_MAX_LENGTH] = {0};
char info_path[PATH_MAX_LENGTH] = {0};

core_info[i].path = strdup(contents->elems[i].data);

if (!core_info[i].path)
break;

if (!string_is_equal(core_info[i].path, path))
continue;
config_file_t *conf = NULL;

fill_pathname_base(info_path_base, contents->elems[i].data,
sizeof(info_path_base));
path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
char *substr = strrchr(info_path_base, '_');
if (substr)
*substr = '\0';
#endif

strlcat(info_path_base, ".info", sizeof(info_path_base));

fill_pathname_join(info_path, (*settings->libretro_info_path) ?
settings->libretro_info_path : settings->libretro_directory,
info_path_base, sizeof(info_path));

conf = config_file_new(info_path);
if (!string_is_equal(contents->elems[i].data, path))
continue;

conf = core_info_list_iterate(contents, i);

if (conf)
{
Expand All @@ -221,6 +226,8 @@ void core_info_get_name(const char *path, char *s, size_t len)
core_info[i].config_data = (void*)conf;
}

core_info[i].path = strdup(contents->elems[i].data);

strlcpy(s, core_info[i].core_name, len);
}

Expand All @@ -238,34 +245,6 @@ void core_info_get_name(const char *path, char *s, size_t len)
core_info_list_free(core_info_list);
}

static config_file_t *core_info_list_iterate(struct string_list *contents, size_t i)
{
char info_path_base[PATH_MAX_LENGTH];
char info_path[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
settings_t *settings = config_get_ptr();

if (!contents->elems[i].data)
return NULL;

fill_pathname_base(info_path_base, contents->elems[i].data,
sizeof(info_path_base));
path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
char *substr = strrchr(info_path_base, '_');
if (substr)
*substr = '\0';
#endif

strlcat(info_path_base, ".info", sizeof(info_path_base));

fill_pathname_join(info_path, (*settings->libretro_info_path) ?
settings->libretro_info_path : settings->libretro_directory,
info_path_base, sizeof(info_path));

return config_file_new(info_path);
}

static core_info_list_t *core_info_list_new(void)
{
Expand Down

0 comments on commit eb33197

Please sign in to comment.