From d54097f3e14f38a3121e6fb2c7192955c486e31d Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Fri, 16 Jun 2023 14:56:52 +0200 Subject: [PATCH] (playlist.c) Cleanups --- playlist.c | 154 ++++++++++++++++++++++++++++------------------------- playlist.h | 4 -- 2 files changed, 80 insertions(+), 78 deletions(-) diff --git a/playlist.c b/playlist.c index f7f38ad17b..f5a048de07 100644 --- a/playlist.c +++ b/playlist.c @@ -314,9 +314,9 @@ static bool playlist_path_equal(const char *real_path, char entry_real_path[PATH_MAX_LENGTH]; /* Sanity check */ - if (string_is_empty(real_path) || - string_is_empty(entry_path) || - !config) + if ( string_is_empty(real_path) + || string_is_empty(entry_path) + || !config) return false; /* Get entry 'real' path */ @@ -403,9 +403,7 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id, struct playlist_entry *entry, const playlist_config_t *config) { /* Sanity check */ - if (!path_id || - !entry || - !config) + if (!path_id || !entry || !config) return false; /* Check whether entry contains a path ID cache */ @@ -416,13 +414,12 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id, } /* Ensure we have valid real_path strings */ - if (string_is_empty(path_id->real_path) || - string_is_empty(entry->path_id->real_path)) + if ( string_is_empty(path_id->real_path) + || string_is_empty(entry->path_id->real_path)) return false; /* First pass comparison */ - if (path_id->real_path_hash == - entry->path_id->real_path_hash) + if (path_id->real_path_hash == entry->path_id->real_path_hash) { #ifdef _WIN32 /* Handle case-insensitive operating systems*/ @@ -461,12 +458,11 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id, { /* Ensure we have valid parent archive path * strings */ - if (string_is_empty(path_id->archive_path) || - string_is_empty(entry->path_id->archive_path)) + if ( string_is_empty(path_id->archive_path) + || string_is_empty(entry->path_id->archive_path)) return false; - if (path_id->archive_path_hash == - entry->path_id->archive_path_hash) + if (path_id->archive_path_hash == entry->path_id->archive_path_hash) { #ifdef _WIN32 /* Handle case-insensitive operating systems*/ @@ -499,13 +495,14 @@ static bool playlist_core_path_equal(const char *real_core_path, const char *ent char entry_real_core_path[PATH_MAX_LENGTH]; /* Sanity check */ - if (string_is_empty(real_core_path) || string_is_empty(entry_core_path)) + if ( string_is_empty(real_core_path) + || string_is_empty(entry_core_path)) return false; /* Get entry 'real' core path */ strlcpy(entry_real_core_path, entry_core_path, sizeof(entry_real_core_path)); - if (!string_is_equal(entry_real_core_path, FILE_PATH_DETECT) && - !string_is_equal(entry_real_core_path, FILE_PATH_BUILTIN)) + if ( !string_is_equal(entry_real_core_path, FILE_PATH_DETECT) + && !string_is_equal(entry_real_core_path, FILE_PATH_BUILTIN)) playlist_resolve_path(PLAYLIST_SAVE, true, entry_real_core_path, sizeof(entry_real_core_path)); @@ -521,8 +518,8 @@ static bool playlist_core_path_equal(const char *real_core_path, const char *ent return true; #endif - if (config->autofix_paths && - core_info_core_file_id_is_equal(real_core_path, entry_core_path)) + if ( config->autofix_paths + && core_info_core_file_id_is_equal(real_core_path, entry_core_path)) return true; return false; @@ -951,8 +948,8 @@ bool playlist_push_runtime(playlist_t *playlist, /* Get 'real' core path */ strlcpy(real_core_path, entry->core_path, sizeof(real_core_path)); - if (!string_is_equal(real_core_path, FILE_PATH_DETECT) && - !string_is_equal(real_core_path, FILE_PATH_BUILTIN)) + if ( !string_is_equal(real_core_path, FILE_PATH_DETECT) + && !string_is_equal(real_core_path, FILE_PATH_BUILTIN)) playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path, sizeof(real_core_path)); @@ -966,8 +963,8 @@ bool playlist_push_runtime(playlist_t *playlist, for (i = 0; i < len; i++) { struct playlist_entry tmp; - bool equal_path = (string_is_empty(path_id->real_path) && - string_is_empty(playlist->entries[i].path)); + bool equal_path = (string_is_empty(path_id->real_path) + && string_is_empty(playlist->entries[i].path)); equal_path = equal_path || playlist_path_matches_entry( path_id, &playlist->entries[i], &playlist->config); @@ -1016,25 +1013,25 @@ bool playlist_push_runtime(playlist_t *playlist, memmove(playlist->entries + 1, playlist->entries, len * sizeof(struct playlist_entry)); - playlist->entries[0].path = NULL; - playlist->entries[0].core_path = NULL; + playlist->entries[0].path = NULL; + playlist->entries[0].core_path = NULL; if (!string_is_empty(path_id->real_path)) - playlist->entries[0].path = strdup(path_id->real_path); - playlist->entries[0].path_id = path_id; - path_id = NULL; + playlist->entries[0].path = strdup(path_id->real_path); + playlist->entries[0].path_id = path_id; + path_id = NULL; if (!string_is_empty(real_core_path)) - playlist->entries[0].core_path = strdup(real_core_path); + playlist->entries[0].core_path = strdup(real_core_path); - playlist->entries[0].runtime_status = entry->runtime_status; - playlist->entries[0].runtime_hours = entry->runtime_hours; - playlist->entries[0].runtime_minutes = entry->runtime_minutes; - playlist->entries[0].runtime_seconds = entry->runtime_seconds; - playlist->entries[0].last_played_year = entry->last_played_year; - playlist->entries[0].last_played_month = entry->last_played_month; - playlist->entries[0].last_played_day = entry->last_played_day; - playlist->entries[0].last_played_hour = entry->last_played_hour; + playlist->entries[0].runtime_status = entry->runtime_status; + playlist->entries[0].runtime_hours = entry->runtime_hours; + playlist->entries[0].runtime_minutes = entry->runtime_minutes; + playlist->entries[0].runtime_seconds = entry->runtime_seconds; + playlist->entries[0].last_played_year = entry->last_played_year; + playlist->entries[0].last_played_month = entry->last_played_month; + playlist->entries[0].last_played_day = entry->last_played_day; + playlist->entries[0].last_played_hour = entry->last_played_hour; playlist->entries[0].last_played_minute = entry->last_played_minute; playlist->entries[0].last_played_second = entry->last_played_second; @@ -1226,8 +1223,8 @@ bool playlist_push(playlist_t *playlist, /* Get 'real' core path */ strlcpy(real_core_path, entry->core_path, sizeof(real_core_path)); - if (!string_is_equal(real_core_path, FILE_PATH_DETECT) && - !string_is_equal(real_core_path, FILE_PATH_BUILTIN)) + if ( !string_is_equal(real_core_path, FILE_PATH_DETECT) + && !string_is_equal(real_core_path, FILE_PATH_BUILTIN)) playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path, sizeof(real_core_path)); @@ -1256,8 +1253,8 @@ bool playlist_push(playlist_t *playlist, for (i = 0; i < len; i++) { struct playlist_entry tmp; - bool equal_path = (string_is_empty(path_id->real_path) && - string_is_empty(playlist->entries[i].path)); + bool equal_path = (string_is_empty(path_id->real_path) + && string_is_empty(playlist->entries[i].path)); equal_path = equal_path || playlist_path_matches_entry( path_id, &playlist->entries[i], &playlist->config); @@ -2182,9 +2179,11 @@ static bool JSONEndObjectHandler(void *context) { JSONContext *pCtx = (JSONContext *)context; - if (pCtx->in_items && pCtx->object_depth == 2) + if ( pCtx->in_items + && pCtx->object_depth == 2) { - if ((pCtx->array_depth == 1) && !pCtx->capacity_exceeded) + if ( (pCtx->array_depth == 1) + && !pCtx->capacity_exceeded) RBUF_RESIZE(pCtx->playlist->entries, RBUF_LEN(pCtx->playlist->entries) + 1); } @@ -2274,9 +2273,9 @@ static bool JSONNumberHandler(void *context, const char *pValue, size_t length) if (pCtx->current_meta_label_display_mode_val) *pCtx->current_meta_label_display_mode_val = (enum playlist_label_display_mode)strtoul(pValue, NULL, 10); else if (pCtx->current_meta_thumbnail_mode_val) - *pCtx->current_meta_thumbnail_mode_val = (enum playlist_thumbnail_mode)strtoul(pValue, NULL, 10); + *pCtx->current_meta_thumbnail_mode_val = (enum playlist_thumbnail_mode)strtoul(pValue, NULL, 10); else if (pCtx->current_meta_sort_mode_val) - *pCtx->current_meta_sort_mode_val = (enum playlist_sort_mode)strtoul(pValue, NULL, 10); + *pCtx->current_meta_sort_mode_val = (enum playlist_sort_mode)strtoul(pValue, NULL, 10); } } } @@ -2293,10 +2292,10 @@ static bool JSONBoolHandler(void *context, bool value) { JSONContext *pCtx = (JSONContext *)context; - if (!pCtx->in_items && - (pCtx->object_depth == 1) && - (pCtx->array_depth == 0) && - pCtx->current_meta_bool_val) + if ( !pCtx->in_items + && (pCtx->object_depth == 1) + && (pCtx->array_depth == 0) + && pCtx->current_meta_bool_val) *pCtx->current_meta_bool_val = value; pCtx->current_meta_bool_val = NULL; @@ -2313,11 +2312,9 @@ static bool JSONObjectMemberHandler(void *context, const char *pValue, size_t le { if (pCtx->array_depth == 1) { + /* Something went wrong */ if (pCtx->current_string_val) - { - /* something went wrong */ return false; - } if (length && !pCtx->capacity_exceeded) { @@ -2464,7 +2461,7 @@ static bool playlist_read_file(playlist_t *playlist) { unsigned i; int test_char; - bool res = true; + bool res = true; #if defined(HAVE_ZLIB) /* Always use RZIP interface when reading playlists * > this will automatically handle uncompressed @@ -2652,8 +2649,8 @@ static bool playlist_read_file(playlist_t *playlist) /* > Populate default core path/name, if required * (if one is empty, the other should be ignored) */ - if (!string_is_empty(default_core_path) && - !string_is_empty(default_core_name)) + if ( !string_is_empty(default_core_path) + && !string_is_empty(default_core_name)) { playlist->default_core_path = strdup(default_core_path); playlist->default_core_name = strdup(default_core_name); @@ -2791,7 +2788,7 @@ bool playlist_init_cached(const playlist_config_t *config) **/ playlist_t *playlist_init(const playlist_config_t *config) { - playlist_t *playlist = (playlist_t*)malloc(sizeof(*playlist)); + playlist_t *playlist = (playlist_t*)malloc(sizeof(*playlist)); if (!playlist) goto error; @@ -2857,7 +2854,7 @@ playlist_t *playlist_init(const playlist_config_t *config) && (entry->subsystem_roms->size > 0)) { struct string_list* subsystem_roms_new_paths = string_list_new(); - union string_list_elem_attr attributes = { 0 }; + union string_list_elem_attr attributes = { 0 }; if (!subsystem_roms_new_paths) goto error; @@ -2871,8 +2868,10 @@ playlist_t *playlist_init(const playlist_config_t *config) tmp_entry_path[0] = '\0'; path_replace_base_path_and_convert_to_local_file_system( - tmp_entry_path, subsystem_rom_path, - playlist->base_content_directory, playlist->config.base_content_directory, + tmp_entry_path, + subsystem_rom_path, + playlist->base_content_directory, + playlist->config.base_content_directory, sizeof(tmp_entry_path)); string_list_append(subsystem_roms_new_paths, tmp_entry_path, attributes); } @@ -2887,8 +2886,10 @@ playlist_t *playlist_init(const playlist_config_t *config) { tmp_entry_path[0] = '\0'; path_replace_base_path_and_convert_to_local_file_system( - tmp_entry_path, playlist->scan_record.content_dir, - playlist->base_content_directory, playlist->config.base_content_directory, + tmp_entry_path, + playlist->scan_record.content_dir, + playlist->base_content_directory, + playlist->config.base_content_directory, sizeof(tmp_entry_path)); free(playlist->scan_record.content_dir); @@ -2900,8 +2901,10 @@ playlist_t *playlist_init(const playlist_config_t *config) { tmp_entry_path[0] = '\0'; path_replace_base_path_and_convert_to_local_file_system( - tmp_entry_path, playlist->scan_record.dat_file_path, - playlist->base_content_directory, playlist->config.base_content_directory, + tmp_entry_path, + playlist->scan_record.dat_file_path, + playlist->base_content_directory, + playlist->config.base_content_directory, sizeof(tmp_entry_path)); free(playlist->scan_record.dat_file_path); @@ -2953,7 +2956,8 @@ static int playlist_qsort_func(const struct playlist_entry *a, if (!string_is_empty(a->path)) fill_pathname(a_fallback_label, path_basename_nocompression(a->path), - "", PATH_MAX_LENGTH * sizeof(char)); + "", + PATH_MAX_LENGTH * sizeof(char)); /* If filename is also empty, use core name * instead -> this matches the behaviour of * menu_displaylist_parse_playlist() */ @@ -2975,7 +2979,8 @@ static int playlist_qsort_func(const struct playlist_entry *a, if (!string_is_empty(b->path)) fill_pathname(b_fallback_label, - path_basename_nocompression(b->path), "", + path_basename_nocompression(b->path), + "", PATH_MAX_LENGTH * sizeof(char)); else if (!string_is_empty(b->core_name)) strlcpy(b_fallback_label, b->core_name, PATH_MAX_LENGTH * sizeof(char)); @@ -3009,9 +3014,9 @@ void playlist_qsort(playlist_t *playlist) { /* Avoid inadvertent sorting if 'sort mode' * has been set explicitly to PLAYLIST_SORT_MODE_OFF */ - if (!playlist || - (playlist->sort_mode == PLAYLIST_SORT_MODE_OFF) || - !playlist->entries) + if ( !playlist + || !playlist->entries + || (playlist->sort_mode == PLAYLIST_SORT_MODE_OFF)) return; qsort(playlist->entries, RBUF_LEN(playlist->entries), @@ -3054,8 +3059,9 @@ bool playlist_index_is_valid(playlist_t *playlist, size_t idx, if (idx >= RBUF_LEN(playlist->entries)) return false; - return playlist_path_equal(path, playlist->entries[idx].path, &playlist->config) && - string_is_equal(path_basename_nocompression(playlist->entries[idx].core_path), path_basename_nocompression(core_path)); + return playlist_path_equal(path, playlist->entries[idx].path, &playlist->config) + && string_is_equal(path_basename_nocompression(playlist->entries[idx].core_path), + path_basename_nocompression(core_path)); } bool playlist_entries_are_equal( @@ -3093,8 +3099,8 @@ bool playlist_entries_are_equal( if (!string_is_empty(entry_a->core_path)) { strlcpy(real_core_path_a, entry_a->core_path, sizeof(real_core_path_a)); - if (!string_is_equal(real_core_path_a, FILE_PATH_DETECT) && - !string_is_equal(real_core_path_a, FILE_PATH_BUILTIN)) + if ( !string_is_equal(real_core_path_a, FILE_PATH_DETECT) + && !string_is_equal(real_core_path_a, FILE_PATH_BUILTIN)) playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path_a, sizeof(real_core_path_a)); } @@ -3278,8 +3284,8 @@ void playlist_set_default_core_path(playlist_t *playlist, /* Get 'real' core path */ strlcpy(real_core_path, core_path, sizeof(real_core_path)); - if (!string_is_equal(real_core_path, FILE_PATH_DETECT) && - !string_is_equal(real_core_path, FILE_PATH_BUILTIN)) + if ( !string_is_equal(real_core_path, FILE_PATH_DETECT) + && !string_is_equal(real_core_path, FILE_PATH_BUILTIN)) playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path, sizeof(real_core_path)); diff --git a/playlist.h b/playlist.h index facc5ce099..7f100c687b 100644 --- a/playlist.h +++ b/playlist.h @@ -71,10 +71,6 @@ enum playlist_sort_mode PLAYLIST_SORT_MODE_OFF }; -/* TODO/FIXME - since gfx_thumbnail_path.h has now - * been divorced from the menu code, perhaps jdgleaver - * can refactor this? */ - /* Note: We already have a left/right enum defined * in gfx_thumbnail_path.h - but we can't include * menu code here, so have to make a 'duplicate'... */