Skip to content

Commit

Permalink
(core_updater_list) Remove more string_list usage
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jun 16, 2024
1 parent 9d56016 commit a3217df
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions core_updater_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,27 +682,16 @@ static void core_updater_list_add_entry(
const char *path_dir_libretro,
const char *path_libretro_info,
const char *network_buildbot_url,
struct string_list *network_core_entry_list)
const char *date_str,
const char *crc_str,
const char *filename_str)
{
const char *date_str = NULL;
const char *crc_str = NULL;
const char *filename_str = NULL;
const core_updater_list_entry_t *search_entry = NULL;
core_updater_list_entry_t entry = {0};

if (!core_list || !network_core_entry_list)
goto error;

/* > Listings must have 3 entries:
* [date] [crc] [filename] */
if (network_core_entry_list->size < 3)
if (!core_list)
goto error;

/* Get handles of the individual listing strings */
date_str = network_core_entry_list->elems[0].data;
crc_str = network_core_entry_list->elems[1].data;
filename_str = network_core_entry_list->elems[2].data;

if ( string_is_empty(date_str)
|| string_is_empty(crc_str)
|| string_is_empty(filename_str))
Expand Down Expand Up @@ -837,27 +826,44 @@ bool core_updater_list_parse_network_data(
for (tok = strtok_r(data_buf, "\n", &save); tok;
tok = strtok_r(NULL, "\n", &save))
{
struct string_list network_core_entry_list = {0};
char *tok2, *save2;
char *elem0 = NULL;
char *elem1 = NULL;
char *elem2 = NULL;
char *line_cpy = NULL;
const char *line = tok;

if (string_is_empty(line))
continue;

string_list_initialize(&network_core_entry_list);
line_cpy = strdup(line);

/* Split line into listings info components */
string_split_noalloc(&network_core_entry_list, line, " ");
if ((tok2 = strtok_r(line_cpy, " ", &save2)))
elem0 = strdup(tok2); /* date */
if ((tok2 = strtok_r(NULL, " ", &save2)))
elem1 = strdup(tok2); /* crc */
if ((tok2 = strtok_r(NULL, " ", &save2)))
elem2 = strdup(tok2); /* filename */

free(line_cpy);

/* Parse listings info and add to core updater
* list */
core_updater_list_add_entry(
core_list,
path_dir_libretro,
path_libretro_info,
network_buildbot_url,
&network_core_entry_list);
/* > Listings must have 3 entries:
* [date] [crc] [filename] */
if (elem0 && elem1 && elem2)
core_updater_list_add_entry(
core_list,
path_dir_libretro,
path_libretro_info,
network_buildbot_url,
elem0, elem1, elem2);

/* Clean up */
string_list_deinitialize(&network_core_entry_list);
free(elem0);
free(elem1);
free(elem2);
}

/* Temporary data buffer is no longer required */
Expand Down

0 comments on commit a3217df

Please sign in to comment.