diff options
author | William Wilgus <wilgus.william@gmail.com> | 2024-11-03 13:40:05 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2024-11-03 13:59:29 -0500 |
commit | d60dee6188ee134ddd3019a219c41e39df1ae5ff (patch) | |
tree | ba277c909e970e75325ff063b02ed2c223163bc6 | |
parent | f3026cd07221b45079952546a94631e25908f4fc (diff) | |
download | rockbox-d60dee6188.tar.gz rockbox-d60dee6188.zip |
tagtree cleanup first letter menu code
no functional difference just some code shared and trimming of
unnecessary format strings
Change-Id: Ia6165508556790ea825e630a79946fbd2dafd9c1
-rw-r--r-- | apps/tagtree.c | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 4983231663..60f8a795e3 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -191,19 +191,12 @@ struct menu_entry { }; struct menu_root { - char title[64]; + char title[MENUENTRY_MAX_NAME]; char id[MAX_MENU_ID_SIZE]; int itemcount; struct menu_entry *items[TAGMENU_MAX_ITEMS]; }; -struct match -{ - const char* str; - uint16_t len; - uint16_t symbol; -}; - /* Statusbar text of the current view. */ static char current_title[MAX_TAGS][128]; @@ -355,12 +348,13 @@ static int get_token_str(char *buf, int size) static int get_tag(int *tag) { #define TAG_MATCH(str, tag) {str, sizeof(str) - 1, tag} + struct match {const char* str; uint16_t len; uint16_t symbol;}; static const struct match get_tag_match[] = { - TAG_MATCH("Lm", tag_virt_length_min), - TAG_MATCH("Ls", tag_virt_length_sec), - TAG_MATCH("Pm", tag_virt_playtime_min), - TAG_MATCH("Ps", tag_virt_playtime_sec), + TAG_MATCH("lm", tag_virt_length_min), + TAG_MATCH("ls", tag_virt_length_sec), + TAG_MATCH("pm", tag_virt_playtime_min), + TAG_MATCH("ps", tag_virt_playtime_sec), TAG_MATCH("->", menu_next), TAG_MATCH("~>", menu_shuffle_songs), @@ -383,7 +377,6 @@ static int get_tag(int *tag) TAG_MATCH("comment", tag_comment), TAG_MATCH("discnum", tag_discnumber), TAG_MATCH("%format", var_format), - TAG_MATCH("%byfirstletter", menu_byfirstletter), TAG_MATCH("%reload", menu_reload), TAG_MATCH("filename", tag_filename), @@ -407,13 +400,15 @@ static int get_tag(int *tag) TAG_MATCH("lastelapsed", tag_lastelapsed), TAG_MATCH("%menu_start", var_menu_start), + TAG_MATCH("%byfirstletter", menu_byfirstletter), TAG_MATCH("canonicalartist", tag_virt_canonicalartist), + TAG_MATCH("", 0) /* sentinel */ }; #undef TAG_MATCH const size_t max_cmd_sz = 32; /* needs to be >= to len of longest tagstr */ const char *tagstr; - unsigned int tagstr_len; + uint16_t tagstr_len; const struct match *match; /* Find the start. */ @@ -1059,10 +1054,11 @@ int tagtree_import(void) return 0; } -static bool parse_menu(const char *filename); - -static bool alloc_menu_item(void) +static bool alloc_menu_parse_buf(char *buf, int type) { + /* allocate a new menu item (if needed) initialize it with data parsed + from buf Note: allows setting menu type, type ignored when < 0 + */ /* Allocate */ if (menu->items[menu->itemcount] == NULL) menu->items[menu->itemcount] = tagtree_alloc0(sizeof(struct menu_entry)); @@ -1071,18 +1067,17 @@ static bool alloc_menu_item(void) logf("tagtree failed to allocate %s", "menu items"); return false; } - return true; -} -static void firstletter_parse_buf(char *buf) -{ + /* Initialize */ core_pin(tagtree_handle); if (parse_search(menu->items[menu->itemcount], buf)) { - menu->items[menu->itemcount]->type = menu_byfirstletter; + if (type >= 0) + menu->items[menu->itemcount]->type = type; menu->itemcount++; } - core_unpin(tagtree_handle);; + core_unpin(tagtree_handle); + return true; } static void build_firstletter_menu(char *buf, size_t bufsz) @@ -1092,32 +1087,32 @@ static void build_firstletter_menu(char *buf, size_t bufsz) buf+=l; bufsz-=l; - const char *showalbum = ""; - const char * const fmt ="\"%s\" -> %s ? %s %c \"%c\" -> %s title = \"fmt_title\""; - if (!alloc_menu_item()) - return; - - if (strcasestr(subitem, "artist") != NULL) - showalbum = "album ->"; /* album subitem for canonicalartist */ + const char * const fmt ="\"%s\"-> %s ? %s %c\"%c\"-> %s =\"fmt_title\""; + const char * const showsub = /* album subitem for canonicalartist */ + ((strcasestr(subitem, "artist") == NULL) ? "title" : "album -> title"); /* Numeric ex: "Numeric" -> album ? album < "A" -> title = "fmt_title" */ snprintf(buf, bufsz, fmt, - str(LANG_DISPLAY_NUMERIC), subitem, subitem,'<', 'A', showalbum); + str(LANG_DISPLAY_NUMERIC), subitem, subitem,'<', 'A', showsub); - firstletter_parse_buf(buf); + if (!alloc_menu_parse_buf(buf, menu_byfirstletter)) + { + return; + } for (int i = 0; i < 26; i++) { - if (!alloc_menu_item()) - return; - - snprintf(buf, bufsz, fmt, "#", subitem, subitem,'^', 'A' + i, showalbum); + snprintf(buf, bufsz, fmt, "#", subitem, subitem,'^', 'A' + i, showsub); buf[1] = 'A' + i; /* overwrite the placeholder # with the current letter */ /* ex: "A" -> title ? title ^ "A" -> title = "fmt_title" */ - firstletter_parse_buf(buf); + if (!alloc_menu_parse_buf(buf, menu_byfirstletter)) + { + return; + } } } +static bool parse_menu(const char *filename); static int parse_line(int n, char *buf, void *parameters) { char data[256]; @@ -1275,12 +1270,10 @@ static int parse_line(int n, char *buf, void *parameters) return 0; } - if (!alloc_menu_item()) + if (!alloc_menu_parse_buf(buf, -1)) + { return -2; - core_pin(tagtree_handle); - if (parse_search(menu->items[menu->itemcount], buf)) - menu->itemcount++; - core_unpin(tagtree_handle); + } return 0; } |