Simplify conditionals

This commit is contained in:
twinaphex 2017-09-30 06:18:38 +02:00
parent eea7fe2dce
commit 1156d6cec5
3 changed files with 38 additions and 41 deletions

View File

@ -270,8 +270,7 @@ static void rgui_set_message(void *data, const char *message)
if (!rgui || !message || !*message) if (!rgui || !message || !*message)
return; return;
if (rgui->msgbox && if (!string_is_empty(rgui->msgbox))
!string_is_empty(rgui->msgbox))
free(rgui->msgbox); free(rgui->msgbox);
rgui->msgbox = strdup(message); rgui->msgbox = strdup(message);
rgui->force_redraw = true; rgui->force_redraw = true;
@ -625,7 +624,7 @@ static void rgui_render(void *data, bool is_idle)
entry_selected ? hover_color : normal_color); entry_selected ? hover_color : normal_color);
menu_entry_free(&entry); menu_entry_free(&entry);
if (entry_path && !string_is_empty(entry_path)) if (!string_is_empty(entry_path))
free(entry_path); free(entry_path);
} }
@ -638,7 +637,7 @@ static void rgui_render(void *data, bool is_idle)
rgui_render_messagebox(msg); rgui_render_messagebox(msg);
} }
if (rgui->msgbox && !string_is_empty(rgui->msgbox)) if (!string_is_empty(rgui->msgbox))
{ {
rgui_render_messagebox(rgui->msgbox); rgui_render_messagebox(rgui->msgbox);
free(rgui->msgbox); free(rgui->msgbox);

View File

@ -1573,7 +1573,7 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
fill_buf[0] = path_copy[0] = '\0'; fill_buf[0] = path_copy[0] = '\0';
if (info->path && !string_is_empty(info->path)) if (!string_is_empty(info->path))
strlcpy(path_copy, info->path, path_size); strlcpy(path_copy, info->path, path_size);
path = path_copy; path = path_copy;
@ -3995,9 +3995,9 @@ static bool menu_displaylist_push_internal(
filebrowser_clear_type(); filebrowser_clear_type();
info->type = 42; info->type = 42;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
if (info->label && !string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup( info->exts = strdup(
@ -4014,9 +4014,9 @@ static bool menu_displaylist_push_internal(
filebrowser_clear_type(); filebrowser_clear_type();
info->type = 42; info->type = 42;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
if (info->label && !string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup( info->exts = strdup(
@ -4033,9 +4033,9 @@ static bool menu_displaylist_push_internal(
filebrowser_clear_type(); filebrowser_clear_type();
info->type = 42; info->type = 42;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
if (info->label && !string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup( info->exts = strdup(
@ -4072,9 +4072,9 @@ static bool menu_displaylist_push_internal(
filebrowser_clear_type(); filebrowser_clear_type();
info->type = 42; info->type = 42;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
if (info->label && !string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->exts = strdup( info->exts = strdup(
@ -4099,7 +4099,7 @@ static bool menu_displaylist_push_internal(
} }
else else
{ {
if (info->path && !string_is_empty(info->path)) if (!string_is_empty(info->path))
free(info->path); free(info->path);
info->path = strdup(settings->paths.directory_playlist); info->path = strdup(settings->paths.directory_playlist);
@ -4460,9 +4460,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
if (!str_list) if (!str_list)
return false; return false;
if (info->path_b && !string_is_empty(info->path_b)) if (!string_is_empty(info->path_b))
free(info->path_b); free(info->path_b);
if (info->label && !string_is_empty(info->label)) if (!string_is_empty(info->label))
free(info->label); free(info->label);
info->path_b = strdup(str_list->elems[1].data); info->path_b = strdup(str_list->elems[1].data);
@ -4488,7 +4488,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
#else #else
ret = 0; ret = 0;
#endif #endif
if (info->path && !string_is_empty(info->path)) if (!string_is_empty(info->path))
free(info->path); free(info->path);
info->path = strdup(info->path_b); info->path = strdup(info->path_b);
@ -6664,7 +6664,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
filebrowser_clear_type(); filebrowser_clear_type();
info->type_default = FILE_TYPE_RDB; info->type_default = FILE_TYPE_RDB;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup( info->exts = strdup(
file_path_str(FILE_PATH_RDB_EXTENSION)); file_path_str(FILE_PATH_RDB_EXTENSION));
@ -6681,7 +6681,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_CURSOR; info->type_default = FILE_TYPE_CURSOR;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
if (info->path) if (info->path)
free(info->path); free(info->path);
@ -6692,7 +6692,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
filebrowser_clear_type(); filebrowser_clear_type();
info->type_default = FILE_TYPE_CONFIG; info->type_default = FILE_TYPE_CONFIG;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("cfg"); info->exts = strdup("cfg");
load_content = false; load_content = false;
@ -6724,7 +6724,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
string_list_append(str_list, "slangp", attr); string_list_append(str_list, "slangp", attr);
#endif #endif
string_list_join_concat(new_exts, sizeof(new_exts), str_list, "|"); string_list_join_concat(new_exts, sizeof(new_exts), str_list, "|");
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup(new_exts); info->exts = strdup(new_exts);
string_list_free(str_list); string_list_free(str_list);
@ -6758,7 +6758,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
string_list_append(str_list, "slang", attr); string_list_append(str_list, "slang", attr);
#endif #endif
string_list_join_concat(new_exts, sizeof(new_exts), str_list, "|"); string_list_join_concat(new_exts, sizeof(new_exts), str_list, "|");
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup(new_exts); info->exts = strdup(new_exts);
string_list_free(str_list); string_list_free(str_list);
@ -6771,7 +6771,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_VIDEOFILTER; info->type_default = FILE_TYPE_VIDEOFILTER;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("filt"); info->exts = strdup("filt");
break; break;
@ -6803,7 +6803,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
string_list_append(str_list, "tga", attr); string_list_append(str_list, "tga", attr);
#endif #endif
string_list_join_concat(new_exts, sizeof(new_exts), str_list, "|"); string_list_join_concat(new_exts, sizeof(new_exts), str_list, "|");
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup(new_exts); info->exts = strdup(new_exts);
string_list_free(str_list); string_list_free(str_list);
@ -6840,7 +6840,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_AUDIOFILTER; info->type_default = FILE_TYPE_AUDIOFILTER;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("dsp"); info->exts = strdup("dsp");
break; break;
@ -6850,7 +6850,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_CHEAT; info->type_default = FILE_TYPE_CHEAT;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("cht"); info->exts = strdup("cht");
break; break;
@ -6859,7 +6859,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
filebrowser_clear_type(); filebrowser_clear_type();
info->type_default = FILE_TYPE_PLAIN; info->type_default = FILE_TYPE_PLAIN;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("lpl"); info->exts = strdup("lpl");
break; break;
@ -6869,7 +6869,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_FONT; info->type_default = FILE_TYPE_FONT;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("ttf"); info->exts = strdup("ttf");
break; break;
@ -6879,7 +6879,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_OVERLAY; info->type_default = FILE_TYPE_OVERLAY;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("cfg"); info->exts = strdup("cfg");
break; break;
@ -6889,7 +6889,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_RECORD_CONFIG; info->type_default = FILE_TYPE_RECORD_CONFIG;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("cfg"); info->exts = strdup("cfg");
break; break;
@ -6899,7 +6899,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_REMAP; info->type_default = FILE_TYPE_REMAP;
load_content = false; load_content = false;
use_filebrowser = true; use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup("rmp"); info->exts = strdup("rmp");
break; break;
@ -6930,7 +6930,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->type_default = FILE_TYPE_PLAIN; info->type_default = FILE_TYPE_PLAIN;
if (frontend_driver_get_core_extension(ext_name, sizeof(ext_name))) if (frontend_driver_get_core_extension(ext_name, sizeof(ext_name)))
{ {
if (info->exts && !string_is_empty(info->exts)) if (!string_is_empty(info->exts))
free(info->exts); free(info->exts);
info->exts = strdup(ext_name); info->exts = strdup(ext_name);
} }

View File

@ -79,15 +79,15 @@ void menu_entry_free(menu_entry_t *entry)
{ {
if (!entry) if (!entry)
return; return;
if (entry->label && !string_is_empty(entry->label)) if (!string_is_empty(entry->label))
free(entry->label); free(entry->label);
if (entry->rich_label && !string_is_empty(entry->rich_label)) if (!string_is_empty(entry->rich_label))
free(entry->rich_label); free(entry->rich_label);
if (entry->sublabel && !string_is_empty(entry->sublabel)) if (!string_is_empty(entry->sublabel))
free(entry->sublabel); free(entry->sublabel);
if (entry->path && !string_is_empty(entry->path)) if (!string_is_empty(entry->path))
free(entry->path); free(entry->path);
if (entry->value && !string_is_empty(entry->value)) if (!string_is_empty(entry->value))
free(entry->value); free(entry->value);
entry->path = NULL; entry->path = NULL;
entry->label = NULL; entry->label = NULL;
@ -128,9 +128,7 @@ char *menu_entry_get_rich_label(menu_entry_t *entry)
char *menu_entry_get_sublabel(menu_entry_t *entry) char *menu_entry_get_sublabel(menu_entry_t *entry)
{ {
if (!entry) if (!entry || string_is_empty(entry->sublabel))
return NULL;
if (string_is_empty(entry->sublabel))
return NULL; return NULL;
return strdup(entry->sublabel); return strdup(entry->sublabel);
} }
@ -264,7 +262,7 @@ void menu_entry_reset(uint32_t i)
void menu_entry_get_value(menu_entry_t *entry, char *s, size_t len) void menu_entry_get_value(menu_entry_t *entry, char *s, size_t len)
{ {
if (!entry || !entry->value || string_is_empty(entry->value)) if (!entry || string_is_empty(entry->value))
return; return;
strlcpy(s, entry->value, len); strlcpy(s, entry->value, len);
} }