(menu_cbs_title.c) Cleanups

This commit is contained in:
twinaphex 2019-05-18 04:07:37 +02:00
parent 0fedbe837c
commit ce191672f1

View File

@ -30,29 +30,19 @@
cbs->action_get_title_ident = #name; cbs->action_get_title_ident = #name;
#endif #endif
static void sanitize_to_string(char *s, const char *label, size_t len) #define sanitize_to_string(s, label, len) \
{ char *pos = NULL; \
char *pos = NULL; strlcpy(s, label, len); \
while((pos = strchr(s, '_'))) \
strlcpy(s, label, len); *pos = ' '
/* replace characters */
while((pos = strchr(s, '_')))
*pos = ' ';
}
static int fill_title(char *s, const char *title, const char *path, size_t len)
{
if (!string_is_empty(path) && !string_is_empty(title))
fill_pathname_join_delim(s, title, path, ' ', len);
return 0;
}
static int action_get_title_action_generic(const char *path, const char *label, static int action_get_title_action_generic(const char *path, const char *label,
unsigned menu_type, char *s, size_t len) unsigned menu_type, char *s, size_t len)
{ {
if (s && !string_is_empty(label)) if (s && !string_is_empty(label))
{
sanitize_to_string(s, label, len); sanitize_to_string(s, label, len);
}
return 0; return 0;
} }
@ -61,14 +51,19 @@ static int action_get_title_action_generic(const char *path, const char *label,
{ \ { \
const char *str = msg_hash_to_str(lbl); \ const char *str = msg_hash_to_str(lbl); \
if (s && !string_is_empty(str)) \ if (s && !string_is_empty(str)) \
{ \
sanitize_to_string(s, str, len); \ sanitize_to_string(s, str, len); \
} \
return 0; \ return 0; \
} }
#define default_fill_title_macro(func_name, lbl) \ #define default_fill_title_macro(func_name, lbl) \
static int (func_name)(const char *path, const char *label, unsigned menu_type, char *s, size_t len) \ static int (func_name)(const char *path, const char *label, unsigned menu_type, char *s, size_t len) \
{ \ { \
return fill_title(s, msg_hash_to_str(lbl), path, len); \ const char *title = msg_hash_to_str(lbl); \
if (!string_is_empty(path) && !string_is_empty(title)) \
fill_pathname_join_delim(s, title, path, ' ', len); \
return 0; \
} }
#define default_title_copy_macro(func_name, lbl) \ #define default_title_copy_macro(func_name, lbl) \