Small style nits and plain sense cleanups

This commit is contained in:
libretroadmin 2023-08-16 01:14:50 +02:00
parent 797c7ff381
commit c699e47534
4 changed files with 108 additions and 137 deletions

View file

@ -129,16 +129,13 @@ void disk_control_set_ext_callback(
bool disk_control_enabled(
disk_control_interface_t *disk_control)
{
if (!disk_control)
return false;
if (disk_control->cb.set_eject_state &&
disk_control->cb.get_eject_state &&
disk_control->cb.get_image_index &&
disk_control->cb.set_image_index &&
disk_control->cb.get_num_images)
if ( disk_control
&& disk_control->cb.set_eject_state
&& disk_control->cb.get_eject_state
&& disk_control->cb.get_image_index
&& disk_control->cb.set_image_index
&& disk_control->cb.get_num_images)
return true;
return false;
}
@ -155,7 +152,7 @@ bool disk_control_append_enabled(
disk_control_interface_t *disk_control)
{
if ( disk_control
&& disk_control->cb.replace_image_index
&& disk_control->cb.replace_image_index
&& disk_control->cb.add_image_index)
return true;
return false;
@ -166,7 +163,7 @@ bool disk_control_append_enabled(
*
* Leaf function.
*
* @return true if core supports image labels
* @return true if core supports image labels
* - get_image_label
**/
bool disk_control_image_label_enabled(
@ -187,7 +184,7 @@ bool disk_control_image_label_enabled(
bool disk_control_initial_image_enabled(
disk_control_interface_t *disk_control)
{
if ( disk_control
if ( disk_control
&& disk_control->cb.set_initial_image
&& disk_control->cb.get_image_path)
return true;
@ -309,7 +306,7 @@ static void disk_control_get_index_set_msg(
if (index < num_images)
{
size_t _len = strlcpy(msg,
success
success
? msg_hash_to_str(MSG_SETTING_DISK_IN_TRAY)
: msg_hash_to_str(MSG_FAILED_TO_SET_DISK), len);
if (has_label)
@ -324,7 +321,7 @@ static void disk_control_get_index_set_msg(
else
strlcpy(
msg,
success
success
? msg_hash_to_str(MSG_REMOVED_DISK_FROM_TRAY)
: msg_hash_to_str(MSG_FAILED_TO_REMOVE_DISK_FROM_TRAY),
len);
@ -351,7 +348,7 @@ bool disk_control_set_eject_state(
if (disk_control->cb.set_eject_state(eject))
strlcpy(
msg,
eject
eject
? msg_hash_to_str(MSG_DISK_EJECTED)
: msg_hash_to_str(MSG_DISK_CLOSED),
sizeof(msg));
@ -360,7 +357,7 @@ bool disk_control_set_eject_state(
error = true;
strlcpy(
msg,
eject
eject
? msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_EJECT)
: msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_CLOSE),
sizeof(msg));
@ -419,9 +416,9 @@ bool disk_control_set_index(
if (!disk_control)
return false;
if (!disk_control->cb.get_eject_state ||
!disk_control->cb.get_num_images ||
!disk_control->cb.set_image_index)
if ( !disk_control->cb.get_eject_state
|| !disk_control->cb.get_num_images
|| !disk_control->cb.set_image_index)
return false;
/* Ensure that disk is currently ejected */
@ -460,8 +457,8 @@ bool disk_control_set_index(
* index record (if enabled) */
if (!error && disk_control->record_enabled)
{
if (disk_control->cb.get_image_index &&
disk_control->cb.get_image_path)
if ( disk_control->cb.get_image_index
&& disk_control->cb.get_image_path)
{
char new_image_path[PATH_MAX_LENGTH] = {0};
/* Get current image index + path */
@ -498,8 +495,8 @@ bool disk_control_set_index_next(
if (!disk_control)
return false;
if (!disk_control->cb.get_num_images ||
!disk_control->cb.get_image_index)
if ( !disk_control->cb.get_num_images
|| !disk_control->cb.get_image_index)
return false;
num_images = disk_control->cb.get_num_images();
@ -538,8 +535,8 @@ bool disk_control_set_index_prev(
if (!disk_control)
return false;
if (!disk_control->cb.get_num_images ||
!disk_control->cb.get_image_index)
if ( !disk_control->cb.get_num_images
|| !disk_control->cb.get_image_index)
return false;
num_images = disk_control->cb.get_num_images();
@ -584,11 +581,11 @@ bool disk_control_append_image(
if (!disk_control)
return false;
if (!disk_control->cb.get_image_index ||
!disk_control->cb.get_num_images ||
!disk_control->cb.add_image_index ||
!disk_control->cb.replace_image_index ||
!disk_control->cb.get_eject_state)
if ( !disk_control->cb.get_image_index
|| !disk_control->cb.get_num_images
|| !disk_control->cb.add_image_index
|| !disk_control->cb.replace_image_index
|| !disk_control->cb.get_eject_state)
return false;
if (string_is_empty(image_path))
@ -705,10 +702,10 @@ bool disk_control_set_initial_index(
goto error;
/* Check that 'initial index' functionality is enabled */
if (!disk_control->cb.set_initial_image ||
!disk_control->cb.get_num_images ||
!disk_control->cb.get_image_index ||
!disk_control->cb.get_image_path)
if ( !disk_control->cb.set_initial_image
|| !disk_control->cb.get_num_images
|| !disk_control->cb.get_image_index
|| !disk_control->cb.get_image_path)
goto error;
/* Attempt to initialise disk index record (reading
@ -719,10 +716,10 @@ bool disk_control_set_initial_index(
/* If record is enabled and initial index is *not*
* zero, notify current core */
if (disk_control->record_enabled &&
(disk_control->index_record.image_index != 0))
if ( disk_control->record_enabled
&& (disk_control->index_record.image_index != 0))
{
if (!disk_control->cb.set_initial_image(
if ( !disk_control->cb.set_initial_image(
disk_control->index_record.image_index,
disk_control->index_record.image_path))
{
@ -773,10 +770,10 @@ bool disk_control_verify_initial_index(
return false;
/* Check that 'initial index' functionality is enabled */
if (!disk_control->cb.set_initial_image ||
!disk_control->cb.get_num_images ||
!disk_control->cb.get_image_index ||
!disk_control->cb.get_image_path)
if ( !disk_control->cb.set_initial_image
|| !disk_control->cb.get_num_images
|| !disk_control->cb.get_image_index
|| !disk_control->cb.get_image_path)
return false;
/* Cache initial number of images
@ -798,10 +795,10 @@ bool disk_control_verify_initial_index(
* read here (since this corresponds to a
* 'first run', where no existing disk index
* file was present) */
if ((image_index == disk_control->index_record.image_index) &&
(string_is_equal(image_path, disk_control->index_record.image_path) ||
((disk_control->index_record.image_index == 0) &&
string_is_empty(disk_control->index_record.image_path))))
if ( (image_index == disk_control->index_record.image_index)
&& (string_is_equal(image_path, disk_control->index_record.image_path)
|| ((disk_control->index_record.image_index == 0)
&& string_is_empty(disk_control->index_record.image_path))))
success = true;
}

View file

@ -98,18 +98,6 @@ static bool DCifJSONStringHandler(void* context, const char *pValue, size_t leng
/* Initialisation */
/******************/
/* Resets existing disk index record */
static void disk_index_file_reset(disk_index_file_t *disk_index_file)
{
if (!disk_index_file)
return;
disk_index_file->modified = false;
disk_index_file->image_index = 0;
disk_index_file->image_path[0] = '\0';
disk_index_file->file_path[0] = '\0';
}
/* Parses disk index file referenced by
* disk_index_file->file_path.
* Does nothing if disk index file does not exist. */
@ -127,8 +115,8 @@ static bool disk_index_file_read(disk_index_file_t *disk_index_file)
file_path = disk_index_file->file_path;
if ( string_is_empty(file_path) ||
!path_is_valid(file_path)
if ( string_is_empty(file_path)
|| !path_is_valid(file_path)
)
return false;
@ -147,8 +135,7 @@ static bool disk_index_file_read(disk_index_file_t *disk_index_file)
}
/* Initialise JSON parser */
parser = rjson_open_rfile(file);
if (!parser)
if (!(parser = rjson_open_rfile(file)))
{
RARCH_ERR("[disk index file] Failed to create JSON parser.\n");
goto end;
@ -221,7 +208,6 @@ bool disk_index_file_init(
const char *content_file = NULL;
char content_name[256];
char disk_index_file_dir[PATH_MAX_LENGTH];
char disk_index_file_path[PATH_MAX_LENGTH];
/* Sanity check */
if (!disk_index_file)
@ -269,33 +255,32 @@ bool disk_index_file_init(
/* > Generate final path */
len = fill_pathname_join_special(
disk_index_file_path, disk_index_file_dir,
content_name, sizeof(disk_index_file_path));
strlcpy(disk_index_file_path + len,
disk_index_file->file_path, disk_index_file_dir,
content_name, sizeof(disk_index_file->file_path));
strlcpy(disk_index_file->file_path + len,
".ldci",
sizeof(disk_index_file_path) - len);
if (string_is_empty(disk_index_file_path))
goto error;
sizeof(disk_index_file->file_path) - len);
/* All is well - reset disk_index_file_t and
* attempt to load values from file */
disk_index_file_reset(disk_index_file);
strlcpy(
disk_index_file->file_path,
disk_index_file_path,
sizeof(disk_index_file->file_path));
disk_index_file->modified = false;
disk_index_file->image_index = 0;
disk_index_file->image_path[0] = '\0';
/* > If file does not exist (or some other
* error occurs) then this is a new record
* - in this case, 'modified' flag should
* be set to 'true' */
if (!disk_index_file_read(disk_index_file))
disk_index_file->modified = true;
disk_index_file->modified = true;
return true;
error:
disk_index_file_reset(disk_index_file);
disk_index_file->modified = false;
disk_index_file->image_index = 0;
disk_index_file->image_path[0] = '\0';
disk_index_file->file_path[0] = '\0';
return false;
}
@ -315,8 +300,8 @@ void disk_index_file_set(
/* Check whether image index should be updated */
if (disk_index_file->image_index != image_index)
{
disk_index_file->image_index = image_index;
disk_index_file->modified = true;
disk_index_file->image_index = image_index;
disk_index_file->modified = true;
}
/* Check whether image path should be updated */
@ -327,7 +312,7 @@ void disk_index_file_set(
strlcpy(
disk_index_file->image_path, image_path,
sizeof(disk_index_file->image_path));
disk_index_file->modified = true;
disk_index_file->modified = true;
}
}
else if (!string_is_empty(disk_index_file->image_path))
@ -361,14 +346,14 @@ bool disk_index_file_save(disk_index_file_t *disk_index_file)
return true;
file_path = disk_index_file->file_path;
if (string_is_empty(file_path))
return false;
RARCH_LOG(
"[disk index file] Saving disk index file: %s\n",
file_path);
/* Attempt to open disk index file */
if (!(file = filestream_open(
file_path,

View file

@ -207,7 +207,7 @@ void manual_content_scan_scrub_system_name_custom(void)
* and/or violate the No-Intro filename standard:
* http://datomatic.no-intro.org/stuff/The%20Official%20No-Intro%20Convention%20(20071030).zip
* Replace these characters with underscores */
while ((scrub_char_pointer =
while ((scrub_char_pointer =
strpbrk(scan_settings.system_name_custom, "&*/:`\"<>?\\|")))
*scrub_char_pointer = '_';
}
@ -656,8 +656,8 @@ enum manual_content_scan_playlist_refresh_status
}
/* Set core path/name */
if (!string_is_empty(core_name) &&
!string_is_equal(core_name, FILE_PATH_DETECT))
if ( !string_is_empty(core_name)
&& !string_is_equal(core_name, FILE_PATH_DETECT))
core_type = MANUAL_CONTENT_SCAN_CORE_SET;
if (!manual_content_scan_set_menu_core_name(
@ -749,29 +749,28 @@ bool manual_content_scan_get_menu_content_dir(const char **content_dir)
* actual system name used when generating the playlist */
bool manual_content_scan_get_menu_system_name(const char **system_name)
{
if (!system_name)
return false;
switch (scan_settings.system_name_type)
if (system_name)
{
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_CONTENT_DIR:
*system_name = msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_SYSTEM_NAME_USE_CONTENT_DIR);
return true;
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_CUSTOM:
*system_name = msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_SYSTEM_NAME_USE_CUSTOM);
return true;
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_DATABASE:
if (string_is_empty(scan_settings.system_name_database))
return false;
else
{
*system_name = scan_settings.system_name_database;
switch (scan_settings.system_name_type)
{
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_CONTENT_DIR:
*system_name = msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_SYSTEM_NAME_USE_CONTENT_DIR);
return true;
}
default:
break;
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_CUSTOM:
*system_name = msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_SYSTEM_NAME_USE_CUSTOM);
return true;
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_DATABASE:
if (!string_is_empty(scan_settings.system_name_database))
{
*system_name = scan_settings.system_name_database;
return true;
}
break;
default:
break;
}
}
return false;
@ -781,25 +780,24 @@ bool manual_content_scan_get_menu_system_name(const char **system_name)
* Returns true if core name is valid. */
bool manual_content_scan_get_menu_core_name(const char **core_name)
{
if (!core_name)
return false;
switch (scan_settings.core_type)
if (core_name)
{
case MANUAL_CONTENT_SCAN_CORE_DETECT:
*core_name = msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_CORE_NAME_DETECT);
return true;
case MANUAL_CONTENT_SCAN_CORE_SET:
if (string_is_empty(scan_settings.core_name))
return false;
else
{
*core_name = scan_settings.core_name;
switch (scan_settings.core_type)
{
case MANUAL_CONTENT_SCAN_CORE_DETECT:
*core_name = msg_hash_to_str(
MENU_ENUM_LABEL_VALUE_MANUAL_CONTENT_SCAN_CORE_NAME_DETECT);
return true;
}
default:
break;
case MANUAL_CONTENT_SCAN_CORE_SET:
if (!string_is_empty(scan_settings.core_name))
{
*core_name = scan_settings.core_name;
return true;
}
break;
default:
break;
}
}
return false;
@ -925,8 +923,8 @@ struct string_list *manual_content_scan_get_menu_core_name_list(void)
if (core_info_list)
{
core_info_t *core_info = NULL;
size_t i;
core_info_t *core_info = NULL;
/* Sort cores alphabetically */
core_info_qsort(core_info_list, CORE_INFO_LIST_SORT_DISPLAY_NAME);
@ -934,10 +932,7 @@ struct string_list *manual_content_scan_get_menu_core_name_list(void)
/* Loop through cores */
for (i = 0; i < core_info_list->count; i++)
{
core_info = NULL;
core_info = core_info_get(core_info_list, i);
if (core_info)
if ((core_info = core_info_get(core_info_list, i)))
{
if (string_is_empty(core_info->display_name))
continue;
@ -1003,32 +998,26 @@ bool manual_content_scan_get_task_config(
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_CONTENT_DIR:
if (string_is_empty(scan_settings.system_name_content_dir))
return false;
strlcpy(
task_config->system_name,
scan_settings.system_name_content_dir,
sizeof(task_config->system_name));
break;
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_CUSTOM:
if (string_is_empty(scan_settings.system_name_custom))
return false;
strlcpy(
task_config->system_name,
scan_settings.system_name_custom,
sizeof(task_config->system_name));
break;
case MANUAL_CONTENT_SCAN_SYSTEM_NAME_DATABASE:
if (string_is_empty(scan_settings.system_name_database))
return false;
strlcpy(
task_config->system_name,
scan_settings.system_name_database,
sizeof(task_config->system_name));
break;
default:
return false;
@ -1143,9 +1132,9 @@ bool manual_content_scan_get_task_config(
struct string_list *manual_content_scan_get_content_list(
manual_content_scan_task_config_t *task_config)
{
struct string_list *dir_list = NULL;
bool filter_exts;
bool include_compressed;
struct string_list *dir_list = NULL;
/* Sanity check */
if (!task_config)
@ -1226,8 +1215,8 @@ static bool manual_content_scan_get_playlist_content_path(
/* Check whether this is an archive file
* requiring special attention... */
if ((content_type == RARCH_COMPRESSED_ARCHIVE) &&
task_config->search_archives)
if ( (content_type == RARCH_COMPRESSED_ARCHIVE)
&& task_config->search_archives)
{
bool filter_exts = !string_is_empty(task_config->file_exts);
const char *archive_file = NULL;
@ -1305,7 +1294,7 @@ static bool manual_content_scan_get_playlist_content_label(
/* In most cases, content label is just the
* filename without extension */
fill_pathname(content_label, path_basename(content_path),
fill_pathname(content_label, path_basename(content_path),
"", len);
if (string_is_empty(content_label))

View file

@ -1984,7 +1984,7 @@ static void ram_state_to_file(void)
enum rarch_content_type path_is_media_type(const char *path)
{
char ext_lower[128];
char ext_lower[16];
strlcpy(ext_lower, path_get_extension(path), sizeof(ext_lower));
string_to_lower(ext_lower);