Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Miika Pekkarinen |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 22 | /** |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 23 | * Basic structure on this file was copied from dbtree.c and modified to |
| 24 | * support the tag cache interface. |
| 25 | */ |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 26 | |
Jeffrey Goode | 9d84268 | 2009-11-03 16:25:03 +0000 | [diff] [blame] | 27 | /*#define LOGF_ENABLE*/ |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 28 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 29 | #include <stdio.h> |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 30 | #include <stdlib.h> |
Thomas Martitz | 50a6ca3 | 2010-05-06 21:04:40 +0000 | [diff] [blame] | 31 | #include "string-extra.h" |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 32 | #include "config.h" |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 33 | #include "system.h" |
| 34 | #include "kernel.h" |
| 35 | #include "splash.h" |
| 36 | #include "icons.h" |
| 37 | #include "tree.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 38 | #include "action.h" |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 39 | #include "settings.h" |
| 40 | #include "tagcache.h" |
| 41 | #include "tagtree.h" |
| 42 | #include "lang.h" |
| 43 | #include "logf.h" |
| 44 | #include "playlist.h" |
| 45 | #include "keyboard.h" |
| 46 | #include "gui/list.h" |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 47 | #include "core_alloc.h" |
Miika Pekkarinen | 29b9146 | 2006-08-09 07:28:48 +0000 | [diff] [blame] | 48 | #include "yesno.h" |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 49 | #include "misc.h" |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 50 | #include "filetypes.h" |
Jonathan Gordon | 1f415e2 | 2007-10-29 12:15:47 +0000 | [diff] [blame] | 51 | #include "audio.h" |
Jonathan Gordon | 71898e5 | 2008-10-16 10:38:03 +0000 | [diff] [blame] | 52 | #include "appevents.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 53 | #include "storage.h" |
Thomas Martitz | 6eaab4d | 2010-09-01 21:29:34 +0000 | [diff] [blame] | 54 | #include "dir.h" |
Michael Sevakis | 6510973 | 2011-02-23 14:31:13 +0000 | [diff] [blame] | 55 | #include "playback.h" |
Thomas Martitz | 84c7d61 | 2014-01-15 23:18:35 +0100 | [diff] [blame] | 56 | #include "strnatcmp.h" |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 57 | #include "panic.h" |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 58 | |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 59 | #define str_or_empty(x) (x ? x : "(NULL)") |
| 60 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 61 | #define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config" |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 62 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 63 | static int tagtree_play_folder(struct tree_context* c); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 64 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 65 | /* this needs to be same size as struct entry (tree.h) and name needs to be |
| 66 | * the first; so that they're compatible enough to walk arrays of both |
| 67 | * derefencing the name member*/ |
| 68 | struct tagentry { |
| 69 | char* name; |
| 70 | int newtable; |
| 71 | int extraseek; |
| 72 | }; |
| 73 | |
| 74 | static struct tagentry* tagtree_get_entry(struct tree_context *c, int id); |
| 75 | |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 76 | #define SEARCHSTR_SIZE 256 |
| 77 | |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 78 | enum table { |
| 79 | ROOT = 1, |
| 80 | NAVIBROWSE, |
| 81 | ALLSUBENTRIES, |
| 82 | PLAYTRACK, |
| 83 | }; |
| 84 | |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 85 | static const struct id3_to_search_mapping { |
| 86 | char *string; |
| 87 | size_t id3_offset; |
| 88 | } id3_to_search_mapping[] = { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 89 | { "", 0 }, /* offset n/a */ |
| 90 | { "#directory#", 0 }, /* offset n/a */ |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 91 | { "#title#", offsetof(struct mp3entry, title) }, |
| 92 | { "#artist#", offsetof(struct mp3entry, artist) }, |
| 93 | { "#album#", offsetof(struct mp3entry, album) }, |
| 94 | { "#genre#", offsetof(struct mp3entry, genre_string) }, |
| 95 | { "#composer#", offsetof(struct mp3entry, composer) }, |
| 96 | { "#albumartist#", offsetof(struct mp3entry, albumartist) }, |
| 97 | }; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 98 | enum variables { |
| 99 | var_sorttype = 100, |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 100 | var_limit, |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 101 | var_strip, |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 102 | var_menu_start, |
| 103 | var_include, |
| 104 | var_rootmenu, |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 105 | var_format, |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 106 | menu_next, |
| 107 | menu_load, |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 108 | menu_reload, |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 111 | /* Capacity 10 000 entries (for example 10k different artists) */ |
| 112 | #define UNIQBUF_SIZE (64*1024) |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 113 | static long uniqbuf[UNIQBUF_SIZE / sizeof(long)]; |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 114 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 115 | #define MAX_TAGS 5 |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 116 | #define MAX_MENU_ID_SIZE 32 |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 117 | |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 118 | #define RELOAD_TAGTREE (-1024) |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 119 | static bool sort_inverse; |
| 120 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 121 | /* |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 122 | * "%3d. %s" autoscore title %sort = "inverse" %limit = "100" |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 123 | * |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 124 | * valid = true |
| 125 | * formatstr = "%-3d. %s" |
| 126 | * tags[0] = tag_autoscore |
| 127 | * tags[1] = tag_title |
| 128 | * tag_count = 2 |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 129 | * |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 130 | * limit = 100 |
| 131 | * sort_inverse = true |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 132 | */ |
| 133 | struct display_format { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 134 | char name[32]; |
| 135 | struct tagcache_search_clause *clause[TAGCACHE_MAX_CLAUSES]; |
| 136 | int clause_count; |
| 137 | char *formatstr; |
| 138 | int group_id; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 139 | int tags[MAX_TAGS]; |
| 140 | int tag_count; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 141 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 142 | int limit; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 143 | int strip; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 144 | bool sort_inverse; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 147 | static struct display_format *formats[TAGMENU_MAX_FMTS]; |
| 148 | static int format_count; |
| 149 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 150 | struct menu_entry { |
| 151 | char name[64]; |
| 152 | int type; |
Thomas Martitz | 19d08c2 | 2011-06-20 19:32:52 +0000 | [diff] [blame] | 153 | struct search_instruction { |
| 154 | char name[64]; |
| 155 | int tagorder[MAX_TAGS]; |
| 156 | int tagorder_count; |
| 157 | struct tagcache_search_clause *clause[MAX_TAGS][TAGCACHE_MAX_CLAUSES]; |
| 158 | int format_id[MAX_TAGS]; |
| 159 | int clause_count[MAX_TAGS]; |
| 160 | int result_seek[MAX_TAGS]; |
| 161 | } si; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 162 | int link; |
| 163 | }; |
| 164 | |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 165 | struct menu_root { |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 166 | char title[64]; |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 167 | char id[MAX_MENU_ID_SIZE]; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 168 | int itemcount; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 169 | struct menu_entry *items[TAGMENU_MAX_ITEMS]; |
| 170 | }; |
| 171 | |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 172 | struct match |
| 173 | { |
| 174 | const char* str; |
| 175 | int symbol; |
| 176 | }; |
| 177 | |
Miika Pekkarinen | 6e8ab3d | 2006-09-25 19:52:38 +0000 | [diff] [blame] | 178 | /* Statusbar text of the current view. */ |
| 179 | static char current_title[MAX_TAGS][128]; |
| 180 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 181 | static struct menu_root * menus[TAGMENU_MAX_MENUS]; |
| 182 | static struct menu_root * menu; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 183 | static struct search_instruction *csi; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 184 | static const char *strp; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 185 | static int menu_count; |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 186 | static int rootmenu; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 187 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 188 | static int current_offset; |
| 189 | static int current_entry_count; |
| 190 | |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 191 | static struct tree_context *tc; |
| 192 | |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 193 | /* a few memory alloc helper */ |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 194 | static int tagtree_handle, lock_count; |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 195 | static size_t tagtree_bufsize, tagtree_buf_used; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 196 | |
| 197 | #define UPDATE(x, y) { x = (typeof(x))((char*)(x) + (y)); } |
| 198 | static int move_callback(int handle, void* current, void* new) |
| 199 | { |
| 200 | (void)handle; (void)current; (void)new; |
| 201 | ptrdiff_t diff = new - current; |
| 202 | |
| 203 | if (lock_count > 0) |
| 204 | return BUFLIB_CB_CANNOT_MOVE; |
| 205 | |
Michael Sevakis | 6436c6e | 2017-02-10 20:10:14 -0500 | [diff] [blame] | 206 | if (menu) |
| 207 | UPDATE(menu, diff); |
| 208 | |
| 209 | if (csi) |
| 210 | UPDATE(csi, diff); |
| 211 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 212 | /* loop over menus */ |
| 213 | for(int i = 0; i < menu_count; i++) |
| 214 | { |
| 215 | struct menu_root* menu = menus[i]; |
| 216 | /* then over the menu_entries of a menu */ |
| 217 | for(int j = 0; j < menu->itemcount; j++) |
| 218 | { |
| 219 | struct menu_entry* mentry = menu->items[j]; |
| 220 | /* then over the search_instructions of each menu_entry */ |
| 221 | for(int k = 0; k < mentry->si.tagorder_count; k++) |
| 222 | { |
| 223 | for(int l = 0; l < mentry->si.clause_count[k]; l++) |
| 224 | { |
| 225 | UPDATE(mentry->si.clause[k][l]->str, diff); |
| 226 | UPDATE(mentry->si.clause[k][l], diff); |
| 227 | } |
| 228 | } |
| 229 | UPDATE(menu->items[j], diff); |
| 230 | } |
| 231 | UPDATE(menus[i], diff); |
| 232 | } |
| 233 | |
| 234 | /* now the same game for formats */ |
| 235 | for(int i = 0; i < format_count; i++) |
| 236 | { |
| 237 | for(int j = 0; j < formats[i]->clause_count; j++) |
| 238 | { |
| 239 | UPDATE(formats[i]->clause[j]->str, diff); |
| 240 | UPDATE(formats[i]->clause[j], diff); |
| 241 | } |
| 242 | |
| 243 | if (formats[i]->formatstr) |
| 244 | UPDATE(formats[i]->formatstr, diff); |
| 245 | |
| 246 | UPDATE(formats[i], diff); |
| 247 | } |
| 248 | return BUFLIB_CB_OK; |
| 249 | } |
| 250 | #undef UPDATE |
| 251 | |
| 252 | static inline void tagtree_lock(void) |
| 253 | { |
| 254 | lock_count++; |
| 255 | } |
| 256 | |
| 257 | static inline void tagtree_unlock(void) |
| 258 | { |
| 259 | lock_count--; |
| 260 | } |
| 261 | |
| 262 | static struct buflib_callbacks ops = { |
| 263 | .move_callback = move_callback, |
| 264 | .shrink_callback = NULL, |
| 265 | }; |
| 266 | |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 267 | static void* tagtree_alloc(size_t size) |
| 268 | { |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 269 | size = ALIGN_UP(size, sizeof(void*)); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 270 | if (size > (tagtree_bufsize - tagtree_buf_used)) |
| 271 | return NULL; |
| 272 | |
| 273 | char* buf = core_get_data(tagtree_handle) + tagtree_buf_used; |
| 274 | |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 275 | tagtree_buf_used += size; |
| 276 | return buf; |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void* tagtree_alloc0(size_t size) |
| 280 | { |
| 281 | void* ret = tagtree_alloc(size); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 282 | if (ret) |
| 283 | memset(ret, 0, size); |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | static char* tagtree_strdup(const char* buf) |
| 288 | { |
| 289 | size_t len = strlen(buf) + 1; |
| 290 | char* dest = tagtree_alloc(len); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 291 | if (dest) |
| 292 | strcpy(dest, buf); |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 293 | return dest; |
| 294 | } |
| 295 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 296 | /* save to call without locking */ |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 297 | static int get_token_str(char *buf, int size) |
| 298 | { |
| 299 | /* Find the start. */ |
| 300 | while (*strp != '"' && *strp != '\0') |
| 301 | strp++; |
| 302 | |
| 303 | if (*strp == '\0' || *(++strp) == '\0') |
| 304 | return -1; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 305 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 306 | /* Read the data. */ |
| 307 | while (*strp != '"' && *strp != '\0' && --size > 0) |
| 308 | *(buf++) = *(strp++); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 309 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 310 | *buf = '\0'; |
| 311 | if (*strp != '"') |
| 312 | return -2; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 313 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 314 | strp++; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 315 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 319 | static int get_tag(int *tag) |
| 320 | { |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 321 | static const struct match get_tag_match[] = |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 322 | { |
| 323 | {"album", tag_album}, |
| 324 | {"artist", tag_artist}, |
| 325 | {"bitrate", tag_bitrate}, |
| 326 | {"composer", tag_composer}, |
| 327 | {"comment", tag_comment}, |
| 328 | {"albumartist", tag_albumartist}, |
| 329 | {"ensemble", tag_albumartist}, |
| 330 | {"grouping", tag_grouping}, |
| 331 | {"genre", tag_genre}, |
| 332 | {"length", tag_length}, |
| 333 | {"Lm", tag_virt_length_min}, |
| 334 | {"Ls", tag_virt_length_sec}, |
| 335 | {"Pm", tag_virt_playtime_min}, |
| 336 | {"Ps", tag_virt_playtime_sec}, |
| 337 | {"title", tag_title}, |
| 338 | {"filename", tag_filename}, |
Michael Hohmuth | eab7e74 | 2011-07-31 16:26:35 +0000 | [diff] [blame] | 339 | {"basename", tag_virt_basename}, |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 340 | {"tracknum", tag_tracknumber}, |
| 341 | {"discnum", tag_discnumber}, |
| 342 | {"year", tag_year}, |
| 343 | {"playcount", tag_playcount}, |
| 344 | {"rating", tag_rating}, |
| 345 | {"lastplayed", tag_lastplayed}, |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 346 | {"lastelapsed", tag_lastelapsed}, |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 347 | {"lastoffset", tag_lastoffset}, |
| 348 | {"commitid", tag_commitid}, |
| 349 | {"entryage", tag_virt_entryage}, |
| 350 | {"autoscore", tag_virt_autoscore}, |
| 351 | {"%sort", var_sorttype}, |
| 352 | {"%limit", var_limit}, |
| 353 | {"%strip", var_strip}, |
| 354 | {"%menu_start", var_menu_start}, |
| 355 | {"%include", var_include}, |
| 356 | {"%root_menu", var_rootmenu}, |
| 357 | {"%format", var_format}, |
| 358 | {"->", menu_next}, |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 359 | {"==>", menu_load}, |
| 360 | {"%reload", menu_reload} |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 361 | }; |
Miika Pekkarinen | 3b7111e | 2006-10-10 10:29:42 +0000 | [diff] [blame] | 362 | char buf[128]; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 363 | unsigned int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 364 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 365 | /* Find the start. */ |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 366 | while ((*strp == ' ' || *strp == '>') && *strp != '\0') |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 367 | strp++; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 368 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 369 | if (*strp == '\0' || *strp == '?') |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 370 | return 0; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 371 | |
| 372 | for (i = 0; i < sizeof(buf)-1; i++) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 373 | { |
| 374 | if (*strp == '\0' || *strp == ' ') |
| 375 | break ; |
| 376 | buf[i] = *strp; |
| 377 | strp++; |
| 378 | } |
| 379 | buf[i] = '\0'; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 380 | |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 381 | for (i = 0; i < ARRAYLEN(get_tag_match); i++) |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 382 | { |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 383 | if (!strcasecmp(buf, get_tag_match[i].str)) |
| 384 | { |
| 385 | *tag = get_tag_match[i].symbol; |
| 386 | return 1; |
| 387 | } |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 388 | } |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 389 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 390 | logf("NO MATCH: %s\n", buf); |
| 391 | if (buf[0] == '?') |
| 392 | return 0; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 393 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 394 | return -1; |
| 395 | } |
| 396 | |
| 397 | static int get_clause(int *condition) |
| 398 | { |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 399 | static const struct match get_clause_match[] = |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 400 | { |
| 401 | {"=", clause_is}, |
| 402 | {"==", clause_is}, |
| 403 | {"!=", clause_is_not}, |
| 404 | {">", clause_gt}, |
| 405 | {">=", clause_gteq}, |
| 406 | {"<", clause_lt}, |
| 407 | {"<=", clause_lteq}, |
| 408 | {"~", clause_contains}, |
| 409 | {"!~", clause_not_contains}, |
| 410 | {"^", clause_begins_with}, |
| 411 | {"!^", clause_not_begins_with}, |
| 412 | {"$", clause_ends_with}, |
| 413 | {"!$", clause_not_ends_with}, |
| 414 | {"@", clause_oneof} |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 415 | }; |
| 416 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 417 | char buf[4]; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 418 | unsigned int i; |
| 419 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 420 | /* Find the start. */ |
| 421 | while (*strp == ' ' && *strp != '\0') |
| 422 | strp++; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 423 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 424 | if (*strp == '\0') |
| 425 | return 0; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 426 | |
| 427 | for (i = 0; i < sizeof(buf)-1; i++) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 428 | { |
| 429 | if (*strp == '\0' || *strp == ' ') |
| 430 | break ; |
| 431 | buf[i] = *strp; |
| 432 | strp++; |
| 433 | } |
| 434 | buf[i] = '\0'; |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 435 | |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 436 | for (i = 0; i < ARRAYLEN(get_clause_match); i++) |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 437 | { |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 438 | if (!strcasecmp(buf, get_clause_match[i].str)) |
| 439 | { |
| 440 | *condition = get_clause_match[i].symbol; |
| 441 | return 1; |
| 442 | } |
Nils Wallménius | f42a305 | 2011-05-31 19:44:21 +0000 | [diff] [blame] | 443 | } |
Thomas Martitz | 1b7ff72 | 2011-07-18 18:57:50 +0000 | [diff] [blame] | 444 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 448 | static bool read_clause(struct tagcache_search_clause *clause) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 449 | { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 450 | char buf[SEARCHSTR_SIZE]; |
| 451 | unsigned int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 452 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 453 | if (get_tag(&clause->tag) <= 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 454 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 455 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 456 | if (get_clause(&clause->type) <= 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 457 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 458 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 459 | if (get_token_str(buf, sizeof buf) < 0) |
| 460 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 461 | |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 462 | for (i=0; i<ARRAYLEN(id3_to_search_mapping); i++) |
| 463 | { |
| 464 | if (!strcasecmp(buf, id3_to_search_mapping[i].string)) |
| 465 | break; |
| 466 | } |
| 467 | |
| 468 | if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */ |
| 469 | { |
| 470 | clause->source = source_runtime+i; |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 471 | clause->str = tagtree_alloc(SEARCHSTR_SIZE); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 472 | } |
| 473 | else |
Jonathan Gordon | 75eff7a | 2007-10-29 14:10:24 +0000 | [diff] [blame] | 474 | { |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 475 | clause->source = source_constant; |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 476 | clause->str = tagtree_strdup(buf); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 477 | } |
| 478 | |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 479 | if (!clause->str) |
| 480 | { |
| 481 | logf("tagtree failed to allocate %s", "clause string"); |
| 482 | return false; |
| 483 | } |
| 484 | else if (TAGCACHE_IS_NUMERIC(clause->tag)) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 485 | { |
| 486 | clause->numeric = true; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 487 | clause->numeric_data = atoi(clause->str); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 488 | } |
| 489 | else |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 490 | clause->numeric = false; |
Robert Kukla | c436657 | 2007-10-30 10:02:57 +0000 | [diff] [blame] | 491 | |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 492 | logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str); |
| 493 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 497 | static bool read_variable(char *buf, int size) |
| 498 | { |
| 499 | int condition; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 500 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 501 | if (!get_clause(&condition)) |
| 502 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 503 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 504 | if (condition != clause_is) |
| 505 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 506 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 507 | if (get_token_str(buf, size) < 0) |
| 508 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 509 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 510 | return true; |
| 511 | } |
| 512 | |
| 513 | /* "%3d. %s" autoscore title %sort = "inverse" %limit = "100" */ |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 514 | static int get_format_str(struct display_format *fmt) |
| 515 | { |
| 516 | int ret; |
Miika Pekkarinen | bba9de2 | 2006-10-11 04:32:33 +0000 | [diff] [blame] | 517 | char buf[128]; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 518 | int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 519 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 520 | memset(fmt, 0, sizeof(struct display_format)); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 521 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 522 | if (get_token_str(fmt->name, sizeof fmt->name) < 0) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 523 | return -10; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 524 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 525 | /* Determine the group id */ |
| 526 | fmt->group_id = 0; |
| 527 | for (i = 0; i < format_count; i++) |
| 528 | { |
| 529 | if (!strcasecmp(formats[i]->name, fmt->name)) |
| 530 | { |
| 531 | fmt->group_id = formats[i]->group_id; |
| 532 | break; |
| 533 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 534 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 535 | if (formats[i]->group_id > fmt->group_id) |
| 536 | fmt->group_id = formats[i]->group_id; |
| 537 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 538 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 539 | if (i == format_count) |
| 540 | fmt->group_id++; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 541 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 542 | logf("format: (%d) %s", fmt->group_id, fmt->name); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 543 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 544 | if (get_token_str(buf, sizeof buf) < 0) |
| 545 | return -10; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 546 | |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 547 | fmt->formatstr = tagtree_strdup(buf); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 548 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 549 | while (fmt->tag_count < MAX_TAGS) |
| 550 | { |
| 551 | ret = get_tag(&fmt->tags[fmt->tag_count]); |
| 552 | if (ret < 0) |
| 553 | return -11; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 554 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 555 | if (ret == 0) |
| 556 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 557 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 558 | switch (fmt->tags[fmt->tag_count]) { |
| 559 | case var_sorttype: |
| 560 | if (!read_variable(buf, sizeof buf)) |
| 561 | return -12; |
| 562 | if (!strcasecmp("inverse", buf)) |
| 563 | fmt->sort_inverse = true; |
| 564 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 565 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 566 | case var_limit: |
| 567 | if (!read_variable(buf, sizeof buf)) |
| 568 | return -13; |
| 569 | fmt->limit = atoi(buf); |
| 570 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 571 | |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 572 | case var_strip: |
| 573 | if (!read_variable(buf, sizeof buf)) |
| 574 | return -14; |
| 575 | fmt->strip = atoi(buf); |
| 576 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 577 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 578 | default: |
| 579 | fmt->tag_count++; |
| 580 | } |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 581 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 582 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 583 | return 1; |
| 584 | } |
| 585 | |
| 586 | static int add_format(const char *buf) |
| 587 | { |
Michael Hohmuth | 851cac8 | 2011-06-14 20:54:26 +0000 | [diff] [blame] | 588 | if (format_count >= TAGMENU_MAX_FMTS) |
| 589 | { |
| 590 | logf("too many formats"); |
| 591 | return -1; |
| 592 | } |
| 593 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 594 | strp = buf; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 595 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 596 | if (formats[format_count] == NULL) |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 597 | formats[format_count] = tagtree_alloc0(sizeof(struct display_format)); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 598 | if (!formats[format_count]) |
| 599 | { |
| 600 | logf("tagtree failed to allocate %s", "format string"); |
| 601 | return -2; |
| 602 | } |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 603 | if (get_format_str(formats[format_count]) < 0) |
| 604 | { |
| 605 | logf("get_format_str() parser failed!"); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 606 | if (formats[format_count]) |
| 607 | memset(formats[format_count], 0, sizeof(struct display_format)); |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 608 | return -4; |
| 609 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 610 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 611 | while (*strp != '\0' && *strp != '?') |
| 612 | strp++; |
| 613 | |
| 614 | if (*strp == '?') |
| 615 | { |
| 616 | int clause_count = 0; |
| 617 | strp++; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 618 | |
| 619 | tagtree_lock(); |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 620 | while (1) |
| 621 | { |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 622 | struct tagcache_search_clause *new_clause; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 623 | |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 624 | if (clause_count >= TAGCACHE_MAX_CLAUSES) |
| 625 | { |
| 626 | logf("too many clauses"); |
| 627 | break; |
| 628 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 629 | |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 630 | new_clause = tagtree_alloc(sizeof(struct tagcache_search_clause)); |
| 631 | if (!new_clause) |
| 632 | { |
| 633 | logf("tagtree failed to allocate %s", "search clause"); |
| 634 | return -3; |
| 635 | } |
| 636 | formats[format_count]->clause[clause_count] = new_clause; |
| 637 | if (!read_clause(new_clause)) |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 638 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 639 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 640 | clause_count++; |
| 641 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 642 | tagtree_unlock(); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 643 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 644 | formats[format_count]->clause_count = clause_count; |
| 645 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 646 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 647 | format_count++; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 648 | |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 649 | return 1; |
| 650 | } |
| 651 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 652 | static int get_condition(struct search_instruction *inst) |
| 653 | { |
Michael Hohmuth | 6a24a7a | 2011-05-10 10:25:41 +0000 | [diff] [blame] | 654 | struct tagcache_search_clause *new_clause; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 655 | int clause_count; |
Miika Pekkarinen | bba9de2 | 2006-10-11 04:32:33 +0000 | [diff] [blame] | 656 | char buf[128]; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 657 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 658 | switch (*strp) |
| 659 | { |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 660 | case '=': |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 661 | { |
| 662 | int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 663 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 664 | if (get_token_str(buf, sizeof buf) < 0) |
| 665 | return -1; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 666 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 667 | for (i = 0; i < format_count; i++) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 668 | { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 669 | if (!strcasecmp(formats[i]->name, buf)) |
| 670 | break; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 671 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 672 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 673 | if (i == format_count) |
| 674 | { |
| 675 | logf("format not found: %s", buf); |
| 676 | return -2; |
| 677 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 678 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 679 | inst->format_id[inst->tagorder_count] = formats[i]->group_id; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 680 | return 1; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 681 | } |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 682 | case '?': |
| 683 | case ' ': |
| 684 | case '&': |
| 685 | strp++; |
| 686 | return 1; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 687 | case '-': |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 688 | case '\0': |
| 689 | return 0; |
| 690 | } |
| 691 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 692 | clause_count = inst->clause_count[inst->tagorder_count]; |
| 693 | if (clause_count >= TAGCACHE_MAX_CLAUSES) |
| 694 | { |
| 695 | logf("Too many clauses"); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 696 | return -2; |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 697 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 698 | |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 699 | new_clause = tagtree_alloc(sizeof(struct tagcache_search_clause)); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 700 | if (!new_clause) |
| 701 | { |
| 702 | logf("tagtree failed to allocate %s", "search clause"); |
| 703 | return -3; |
| 704 | } |
| 705 | |
Michael Hohmuth | 6a24a7a | 2011-05-10 10:25:41 +0000 | [diff] [blame] | 706 | inst->clause[inst->tagorder_count][clause_count] = new_clause; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 707 | |
Michael Hohmuth | 6a24a7a | 2011-05-10 10:25:41 +0000 | [diff] [blame] | 708 | if (*strp == '|') |
| 709 | { |
| 710 | strp++; |
| 711 | new_clause->type = clause_logical_or; |
| 712 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 713 | else |
| 714 | { |
| 715 | tagtree_lock(); |
| 716 | bool ret = read_clause(new_clause); |
| 717 | tagtree_unlock(); |
| 718 | if (!ret) |
| 719 | return -1; |
| 720 | } |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 721 | inst->clause_count[inst->tagorder_count]++; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 722 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 723 | return 1; |
| 724 | } |
| 725 | |
| 726 | /* example search: |
| 727 | * "Best" artist ? year >= "2000" & title !^ "crap" & genre = "good genre" \ |
| 728 | * : album ? year >= "2000" : songs |
| 729 | * ^ begins with |
| 730 | * * contains |
| 731 | * $ ends with |
| 732 | */ |
| 733 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 734 | static bool parse_search(struct menu_entry *entry, const char *str) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 735 | { |
| 736 | int ret; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 737 | int type; |
Thomas Martitz | 19d08c2 | 2011-06-20 19:32:52 +0000 | [diff] [blame] | 738 | struct search_instruction *inst = &entry->si; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 739 | char buf[MAX_PATH]; |
| 740 | int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 741 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 742 | strp = str; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 743 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 744 | /* Parse entry name */ |
| 745 | if (get_token_str(entry->name, sizeof entry->name) < 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 746 | { |
| 747 | logf("No name found."); |
| 748 | return false; |
| 749 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 750 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 751 | /* Parse entry type */ |
| 752 | if (get_tag(&entry->type) <= 0) |
| 753 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 754 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 755 | if (entry->type == menu_load) |
| 756 | { |
| 757 | if (get_token_str(buf, sizeof buf) < 0) |
| 758 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 759 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 760 | /* Find the matching root menu or "create" it */ |
| 761 | for (i = 0; i < menu_count; i++) |
| 762 | { |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 763 | if (!strcasecmp(menus[i]->id, buf)) |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 764 | { |
| 765 | entry->link = i; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 766 | return true; |
| 767 | } |
| 768 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 769 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 770 | if (menu_count >= TAGMENU_MAX_MENUS) |
| 771 | { |
| 772 | logf("max menucount reached"); |
| 773 | return false; |
| 774 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 775 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 776 | /* Allocate a new menu unless link is found. */ |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 777 | menus[menu_count] = tagtree_alloc0(sizeof(struct menu_root)); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 778 | if (!menus[menu_count]) |
| 779 | { |
| 780 | logf("tagtree failed to allocate %s", "menu"); |
| 781 | return false; |
| 782 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 783 | strlcpy(menus[menu_count]->id, buf, MAX_MENU_ID_SIZE); |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 784 | entry->link = menu_count; |
| 785 | ++menu_count; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 786 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 787 | return true; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 788 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 789 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 790 | if (entry->type != menu_next) |
| 791 | return false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 792 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 793 | while (inst->tagorder_count < MAX_TAGS) |
| 794 | { |
| 795 | ret = get_tag(&inst->tagorder[inst->tagorder_count]); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 796 | if (ret < 0) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 797 | { |
| 798 | logf("Parse error #1"); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 799 | logf("%s", strp); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 800 | return false; |
| 801 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 802 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 803 | if (ret == 0) |
| 804 | break ; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 805 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 806 | logf("tag: %d", inst->tagorder[inst->tagorder_count]); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 807 | |
| 808 | tagtree_lock(); |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 809 | while ( (ret = get_condition(inst)) > 0 ) ; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 810 | tagtree_unlock(); |
| 811 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 812 | if (ret < 0) |
| 813 | return false; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 814 | |
| 815 | inst->tagorder_count++; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 816 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 817 | if (get_tag(&type) <= 0 || type != menu_next) |
| 818 | break; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 819 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 820 | |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 821 | return true; |
| 822 | } |
| 823 | |
Miika Pekkarinen | 44b76bc | 2006-03-30 12:07:32 +0000 | [diff] [blame] | 824 | static int compare(const void *p1, const void *p2) |
| 825 | { |
| 826 | struct tagentry *e1 = (struct tagentry *)p1; |
| 827 | struct tagentry *e2 = (struct tagentry *)p2; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 828 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 829 | if (sort_inverse) |
| 830 | return strncasecmp(e2->name, e1->name, MAX_PATH); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 831 | |
Miika Pekkarinen | 44b76bc | 2006-03-30 12:07:32 +0000 | [diff] [blame] | 832 | return strncasecmp(e1->name, e2->name, MAX_PATH); |
| 833 | } |
| 834 | |
Thomas Martitz | 84c7d61 | 2014-01-15 23:18:35 +0100 | [diff] [blame] | 835 | static int nat_compare(const void *p1, const void *p2) |
| 836 | { |
| 837 | struct tagentry *e1 = (struct tagentry *)p1; |
| 838 | struct tagentry *e2 = (struct tagentry *)p2; |
| 839 | |
| 840 | if (sort_inverse) |
| 841 | return strnatcasecmp(e2->name, e1->name); |
| 842 | |
| 843 | return strnatcasecmp(e1->name, e2->name); |
| 844 | } |
| 845 | |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 846 | static void tagtree_buffer_event(unsigned short id, void *ev_data) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 847 | { |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 848 | (void)id; |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 849 | struct tagcache_search tcs; |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 850 | struct mp3entry *id3 = ((struct track_event *)ev_data)->id3; |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 851 | |
| 852 | bool runtimedb = global_settings.runtimedb; |
| 853 | bool autoresume = global_settings.autoresume_enable; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 854 | |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 855 | /* Do not gather data unless proper setting has been enabled. */ |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 856 | if (!runtimedb && !autoresume) |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 857 | return; |
| 858 | |
Miika Pekkarinen | f98a0a9 | 2007-11-23 17:58:03 +0000 | [diff] [blame] | 859 | logf("be:%s", id3->path); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 860 | |
Dominik Riebeling | d2cc5ce | 2011-01-17 22:28:36 +0000 | [diff] [blame] | 861 | while (! tagcache_is_fully_initialized()) |
Jonathan Gordon | 7270e5e | 2010-11-16 13:17:37 +0000 | [diff] [blame] | 862 | yield(); |
| 863 | |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 864 | if (!tagcache_find_index(&tcs, id3->path)) |
| 865 | { |
| 866 | logf("tc stat: not found: %s", id3->path); |
| 867 | return; |
| 868 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 869 | |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 870 | if (runtimedb) |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 871 | { |
| 872 | id3->playcount = tagcache_get_numeric(&tcs, tag_playcount); |
| 873 | if (!id3->rating) |
| 874 | id3->rating = tagcache_get_numeric(&tcs, tag_rating); |
| 875 | id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); |
| 876 | id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10; |
| 877 | id3->playtime = tagcache_get_numeric(&tcs, tag_playtime); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 878 | |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 879 | logf("-> %ld/%ld", id3->playcount, id3->playtime); |
| 880 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 881 | |
| 882 | #if CONFIG_CODEC == SWCODEC |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 883 | if (autoresume) |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 884 | { |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 885 | /* Load current file resume info if not already defined (by |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 886 | another resume mechanism) */ |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 887 | if (id3->elapsed == 0) |
| 888 | { |
| 889 | id3->elapsed = tagcache_get_numeric(&tcs, tag_lastelapsed); |
| 890 | |
| 891 | logf("tagtree_buffer_event: Set elapsed for %s to %lX\n", |
| 892 | str_or_empty(id3->title), id3->elapsed); |
| 893 | } |
| 894 | |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 895 | if (id3->offset == 0) |
| 896 | { |
| 897 | id3->offset = tagcache_get_numeric(&tcs, tag_lastoffset); |
| 898 | |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 899 | logf("tagtree_buffer_event: Set offset for %s to %lX\n", |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 900 | str_or_empty(id3->title), id3->offset); |
| 901 | } |
| 902 | } |
Michael Giacomelli | cacc64a | 2011-01-02 03:48:40 +0000 | [diff] [blame] | 903 | #endif |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 904 | |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 905 | /* Store our tagcache index pointer. */ |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 906 | id3->tagcache_idx = tcs.idx_id+1; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 907 | |
Miika Pekkarinen | 890989d | 2006-08-26 16:06:54 +0000 | [diff] [blame] | 908 | tagcache_search_finish(&tcs); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 911 | static void tagtree_track_finish_event(unsigned short id, void *ev_data) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 912 | { |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 913 | (void)id; |
| 914 | struct track_event *te = (struct track_event *)ev_data; |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 915 | struct mp3entry *id3 = te->id3; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 916 | |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 917 | long tagcache_idx = id3->tagcache_idx; |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 918 | if (!tagcache_idx) |
Miika Pekkarinen | 9d756e2 | 2007-07-21 17:35:19 +0000 | [diff] [blame] | 919 | { |
| 920 | logf("No tagcache index pointer found"); |
| 921 | return; |
| 922 | } |
Robert Kukla | ad5610d | 2008-02-12 18:51:10 +0000 | [diff] [blame] | 923 | tagcache_idx--; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 924 | |
Michael Hohmuth | 4844142 | 2011-02-08 20:31:27 +0000 | [diff] [blame] | 925 | #if CONFIG_CODEC == SWCODEC /* HWCODEC doesn't have automatic_skip */ |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 926 | bool auto_skip = te->flags & TEF_AUTO_SKIP; |
Michael Hohmuth | 4844142 | 2011-02-08 20:31:27 +0000 | [diff] [blame] | 927 | #endif |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 928 | bool runtimedb = global_settings.runtimedb; |
| 929 | bool autoresume = global_settings.autoresume_enable; |
| 930 | |
| 931 | /* Don't process unplayed tracks, or tracks interrupted within the |
| 932 | first 15 seconds but always process autoresume point */ |
| 933 | if (runtimedb && (id3->elapsed == 0 |
| 934 | #if CONFIG_CODEC == SWCODEC |
| 935 | || (id3->elapsed < 15 * 1000 && !auto_skip) |
| 936 | #endif |
| 937 | )) |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 938 | { |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 939 | logf("not db logging unplayed or skipped track"); |
| 940 | runtimedb = false; |
| 941 | } |
| 942 | |
| 943 | #if CONFIG_CODEC == SWCODEC |
| 944 | /* 3s because that is the threshold the WPS uses to rewind instead |
| 945 | of skip backwards */ |
| 946 | if (autoresume && (id3->elapsed == 0 |
| 947 | || (id3->elapsed < 3 * 1000 && !auto_skip))) |
| 948 | { |
| 949 | logf("not logging autoresume"); |
| 950 | autoresume = false; |
| 951 | } |
| 952 | #endif |
| 953 | |
| 954 | /* Do not gather data unless proper setting has been enabled and at least |
| 955 | one is still slated to be recorded */ |
| 956 | if (!(runtimedb || autoresume)) |
| 957 | { |
| 958 | logf("runtimedb gathering and autoresume not enabled/ignored"); |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 959 | return; |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 960 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 961 | |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 962 | long lastplayed = tagcache_increase_serial(); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 963 | if (lastplayed < 0) |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 964 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 965 | logf("incorrect tc serial:%ld", lastplayed); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 966 | return; |
Miika Pekkarinen | d8ac607 | 2006-08-02 17:39:34 +0000 | [diff] [blame] | 967 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 968 | |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 969 | if (runtimedb) |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 970 | { |
| 971 | long playcount; |
| 972 | long playtime; |
Robert Kukla | a334bd2 | 2007-11-23 23:36:42 +0000 | [diff] [blame] | 973 | |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 974 | playcount = id3->playcount + 1; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 975 | |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 976 | /* Ignore the last 15s (crossfade etc.) */ |
| 977 | playtime = id3->playtime + MIN(id3->length, id3->elapsed + 15 * 1000); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 978 | |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 979 | logf("ube:%s", id3->path); |
| 980 | logf("-> %ld/%ld", playcount, playtime); |
| 981 | logf("-> %ld/%ld/%ld", id3->elapsed, id3->length, |
| 982 | MIN(id3->length, id3->elapsed + 15 * 1000)); |
| 983 | |
| 984 | /* Queue the updates to the tagcache system. */ |
| 985 | tagcache_update_numeric(tagcache_idx, tag_playcount, playcount); |
| 986 | tagcache_update_numeric(tagcache_idx, tag_playtime, playtime); |
| 987 | tagcache_update_numeric(tagcache_idx, tag_lastplayed, lastplayed); |
| 988 | } |
| 989 | |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 990 | #if CONFIG_CODEC == SWCODEC |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 991 | if (autoresume) |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 992 | { |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 993 | unsigned long elapsed = auto_skip ? 0 : id3->elapsed; |
Michael Sevakis | 023f6b6 | 2013-07-12 12:06:38 -0400 | [diff] [blame] | 994 | unsigned long offset = auto_skip ? 0 : id3->offset; |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 995 | tagcache_update_numeric(tagcache_idx, tag_lastelapsed, elapsed); |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 996 | tagcache_update_numeric(tagcache_idx, tag_lastoffset, offset); |
| 997 | |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 998 | logf("tagtree_track_finish_event: Save resume for %s: %lX %lX", |
| 999 | str_or_empty(id3->title), elapsed, offset); |
Michael Giacomelli | 66e8fc0 | 2011-01-02 02:49:13 +0000 | [diff] [blame] | 1000 | } |
Michael Giacomelli | cacc64a | 2011-01-02 03:48:40 +0000 | [diff] [blame] | 1001 | #endif |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1004 | int tagtree_export(void) |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1005 | { |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1006 | struct tagcache_search tcs; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1007 | |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 1008 | splash(0, str(LANG_CREATING)); |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1009 | if (!tagcache_create_changelog(&tcs)) |
| 1010 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 1011 | splash(HZ*2, ID2P(LANG_FAILED)); |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1012 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1013 | |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1014 | return 0; |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1017 | int tagtree_import(void) |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 1018 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 1019 | splash(0, ID2P(LANG_WAIT)); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 1020 | if (!tagcache_import_changelog()) |
| 1021 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 1022 | splash(HZ*2, ID2P(LANG_FAILED)); |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 1023 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1024 | |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1025 | return 0; |
Miika Pekkarinen | cb8c795 | 2006-07-20 12:19:31 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1028 | static bool parse_menu(const char *filename); |
| 1029 | |
Miika Pekkarinen | d0084ff | 2011-06-23 20:22:00 +0000 | [diff] [blame] | 1030 | static int parse_line(int n, char *buf, void *parameters) |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1031 | { |
| 1032 | char data[256]; |
| 1033 | int variable; |
| 1034 | static bool read_menu; |
| 1035 | int i; |
Miika Pekkarinen | d0084ff | 2011-06-23 20:22:00 +0000 | [diff] [blame] | 1036 | char *p; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1037 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1038 | (void)parameters; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1039 | |
Miika Pekkarinen | d0084ff | 2011-06-23 20:22:00 +0000 | [diff] [blame] | 1040 | /* Strip possible <CR> at end of line. */ |
| 1041 | p = strchr(buf, '\r'); |
| 1042 | if (p != NULL) |
| 1043 | *p = '\0'; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1044 | |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1045 | logf("parse:%d/%s", n, buf); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1046 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1047 | /* First line, do initialisation. */ |
| 1048 | if (n == 0) |
| 1049 | { |
| 1050 | if (strcasecmp(TAGNAVI_VERSION, buf)) |
| 1051 | { |
| 1052 | logf("Version mismatch"); |
| 1053 | return -1; |
| 1054 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1055 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1056 | read_menu = false; |
| 1057 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1058 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1059 | if (buf[0] == '#') |
| 1060 | return 0; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1061 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1062 | if (buf[0] == '\0') |
| 1063 | { |
| 1064 | if (read_menu) |
| 1065 | { |
| 1066 | /* End the menu */ |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1067 | read_menu = false; |
| 1068 | } |
| 1069 | return 0; |
| 1070 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1071 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1072 | if (!read_menu) |
| 1073 | { |
| 1074 | strp = buf; |
| 1075 | if (get_tag(&variable) <= 0) |
| 1076 | return 0; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1077 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1078 | switch (variable) |
| 1079 | { |
| 1080 | case var_format: |
| 1081 | if (add_format(strp) < 0) |
| 1082 | { |
| 1083 | logf("Format add fail: %s", data); |
| 1084 | } |
| 1085 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1086 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1087 | case var_include: |
| 1088 | if (get_token_str(data, sizeof(data)) < 0) |
| 1089 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 1090 | logf("%%include empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1091 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1092 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1093 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1094 | if (!parse_menu(data)) |
| 1095 | { |
| 1096 | logf("Load menu fail: %s", data); |
| 1097 | } |
| 1098 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1099 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1100 | case var_menu_start: |
| 1101 | if (menu_count >= TAGMENU_MAX_MENUS) |
| 1102 | { |
| 1103 | logf("max menucount reached"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1104 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1105 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1106 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 1107 | if (get_token_str(data, sizeof data) < 0) |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1108 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 1109 | logf("%%menu_start id empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1110 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1111 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1112 | |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 1113 | menu = NULL; |
| 1114 | for (i = 0; i < menu_count; i++) |
| 1115 | { |
| 1116 | if (!strcasecmp(menus[i]->id, data)) |
| 1117 | { |
| 1118 | menu = menus[i]; |
| 1119 | } |
| 1120 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1121 | |
| 1122 | if (menu == NULL) |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 1123 | { |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 1124 | menus[menu_count] = tagtree_alloc0(sizeof(struct menu_root)); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1125 | if (!menus[menu_count]) |
| 1126 | { |
| 1127 | logf("tagtree failed to allocate %s", "menu"); |
| 1128 | return -2; |
| 1129 | } |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 1130 | menu = menus[menu_count]; |
| 1131 | ++menu_count; |
Nils Wallménius | 3d4701a | 2009-07-14 13:57:45 +0000 | [diff] [blame] | 1132 | strlcpy(menu->id, data, MAX_MENU_ID_SIZE); |
Miika Pekkarinen | 6ecb06f | 2007-06-22 12:48:06 +0000 | [diff] [blame] | 1133 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1134 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1135 | if (get_token_str(menu->title, sizeof(menu->title)) < 0) |
| 1136 | { |
Magnus Holmgren | 01a010f | 2007-03-18 09:50:53 +0000 | [diff] [blame] | 1137 | logf("%%menu_start title empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1138 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1139 | } |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1140 | logf("menu: %s", menu->title); |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1141 | read_menu = true; |
| 1142 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1143 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1144 | case var_rootmenu: |
| 1145 | /* Only set root menu once. */ |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 1146 | if (rootmenu >= 0) |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1147 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1148 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1149 | if (get_token_str(data, sizeof(data)) < 0) |
| 1150 | { |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 1151 | logf("%%rootmenu empty"); |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1152 | return 0; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1153 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1154 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1155 | for (i = 0; i < menu_count; i++) |
| 1156 | { |
| 1157 | if (!strcasecmp(menus[i]->id, data)) |
| 1158 | { |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 1159 | rootmenu = i; |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | break; |
| 1163 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1164 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1167 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1168 | if (menu->itemcount >= TAGMENU_MAX_ITEMS) |
| 1169 | { |
| 1170 | logf("max itemcount reached"); |
| 1171 | return 0; |
| 1172 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1173 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1174 | /* Allocate */ |
| 1175 | if (menu->items[menu->itemcount] == NULL) |
Thomas Martitz | 316f9a0 | 2011-06-20 19:32:56 +0000 | [diff] [blame] | 1176 | menu->items[menu->itemcount] = tagtree_alloc0(sizeof(struct menu_entry)); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1177 | if (!menu->items[menu->itemcount]) |
| 1178 | { |
| 1179 | logf("tagtree failed to allocate %s", "menu items"); |
| 1180 | return -2; |
| 1181 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1182 | tagtree_lock(); |
| 1183 | if (parse_search(menu->items[menu->itemcount], buf)) |
| 1184 | menu->itemcount++; |
| 1185 | tagtree_unlock(); |
| 1186 | |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |
| 1189 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1190 | static bool parse_menu(const char *filename) |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1191 | { |
| 1192 | int fd; |
Miika Pekkarinen | 649fc77 | 2006-10-25 15:14:15 +0000 | [diff] [blame] | 1193 | char buf[1024]; |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1194 | int rc; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1195 | |
| 1196 | if (menu_count >= TAGMENU_MAX_MENUS) |
Miika Pekkarinen | 1dc3577 | 2006-09-21 17:16:35 +0000 | [diff] [blame] | 1197 | { |
| 1198 | logf("max menucount reached"); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1199 | return false; |
Miika Pekkarinen | 1dc3577 | 2006-09-21 17:16:35 +0000 | [diff] [blame] | 1200 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1201 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1202 | fd = open(filename, O_RDONLY); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1203 | if (fd < 0) |
| 1204 | { |
| 1205 | logf("Search instruction file not found."); |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1206 | return false; |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1207 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1208 | |
Linus Nielsen Feltzing | eed923e | 2006-08-23 08:41:18 +0000 | [diff] [blame] | 1209 | /* Now read file for real, parsing into si */ |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1210 | rc = fast_readline(fd, buf, sizeof buf, NULL, parse_line); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1211 | close(fd); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1212 | |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1213 | return (rc >= 0); |
| 1214 | } |
| 1215 | |
| 1216 | static void tagtree_unload(struct tree_context *c) |
| 1217 | { |
| 1218 | int i; |
| 1219 | tagtree_lock(); |
| 1220 | |
| 1221 | remove_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event); |
| 1222 | remove_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event); |
| 1223 | |
| 1224 | if (c) |
| 1225 | { |
| 1226 | tree_lock_cache(c); |
| 1227 | struct tagentry *dptr = core_get_data(c->cache.entries_handle); |
| 1228 | menu = menus[c->currextra]; |
| 1229 | if (!menu) |
| 1230 | { |
| 1231 | logf("tagtree menu doesn't exist"); |
| 1232 | return; |
| 1233 | } |
| 1234 | |
| 1235 | for (i = 0; i < menu->itemcount; i++) |
| 1236 | { |
| 1237 | dptr->name = NULL; |
| 1238 | dptr->newtable = 0; |
| 1239 | dptr->extraseek = 0; |
| 1240 | dptr++; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | for (i = 0; i < menu_count; i++) |
| 1245 | menus[i] = NULL; |
| 1246 | menu_count = 0; |
| 1247 | |
| 1248 | for (i = 0; i < format_count; i++) |
| 1249 | formats[i] = NULL; |
| 1250 | format_count = 0; |
| 1251 | |
| 1252 | core_free(tagtree_handle); |
| 1253 | tagtree_handle = 0; |
| 1254 | tagtree_buf_used = 0; |
| 1255 | tagtree_bufsize = 0; |
| 1256 | |
| 1257 | if (c) |
| 1258 | tree_unlock_cache(c); |
| 1259 | tagtree_unlock(); |
| 1260 | if (lock_count > 0) |
| 1261 | tagtree_unlock();/* second unlock to enable re-init */ |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | void tagtree_init(void) |
| 1265 | { |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1266 | format_count = 0; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1267 | menu_count = 0; |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 1268 | menu = NULL; |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 1269 | rootmenu = -1; |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1270 | tagtree_handle = core_alloc_maximum("tagtree", &tagtree_bufsize, &ops); |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1271 | if (!parse_menu(FILE_SEARCH_INSTRUCTIONS)) |
| 1272 | { |
| 1273 | tagtree_unload(NULL); |
| 1274 | return; |
| 1275 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1276 | |
| 1277 | /* safety check since tree.c needs to cast tagentry to entry */ |
| 1278 | if (sizeof(struct tagentry) != sizeof(struct entry)) |
| 1279 | panicf("tagentry(%zu) and entry mismatch(%zu)", |
| 1280 | sizeof(struct tagentry), sizeof(struct entry)); |
| 1281 | if (lock_count > 0) |
| 1282 | panicf("tagtree locked after parsing"); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1283 | |
Miika Pekkarinen | e6de6e5 | 2007-04-12 18:33:40 +0000 | [diff] [blame] | 1284 | /* If no root menu is set, assume it's the first single menu |
| 1285 | * we have. That shouldn't normally happen. */ |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 1286 | if (rootmenu < 0) |
| 1287 | rootmenu = 0; |
Miika Pekkarinen | 19c6e66 | 2008-03-16 13:55:16 +0000 | [diff] [blame] | 1288 | |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 1289 | add_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event); |
| 1290 | add_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event); |
Thomas Martitz | d0b72e2 | 2011-08-30 14:01:33 +0000 | [diff] [blame] | 1291 | |
| 1292 | core_shrink(tagtree_handle, core_get_data(tagtree_handle), tagtree_buf_used); |
Miika Pekkarinen | 4a63c09 | 2006-04-04 19:28:13 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 1295 | static bool show_search_progress(bool init, int count) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1296 | { |
| 1297 | static int last_tick = 0; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1298 | |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1299 | /* Don't show splashes for 1/2 second after starting search */ |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1300 | if (init) |
| 1301 | { |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1302 | last_tick = current_tick + HZ/2; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1303 | return true; |
| 1304 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1305 | |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1306 | /* Update progress every 1/10 of a second */ |
Thomas Martitz | 16983af | 2009-08-20 19:31:09 +0000 | [diff] [blame] | 1307 | if (TIME_AFTER(current_tick, last_tick + HZ/10)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1308 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 1309 | splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), count, str(LANG_OFF_ABORT)); |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 1310 | if (action_userabort(TIMEOUT_NOBLOCK)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1311 | return false; |
| 1312 | last_tick = current_tick; |
Miika Pekkarinen | 54ec1f5 | 2006-08-12 11:00:39 +0000 | [diff] [blame] | 1313 | yield(); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1314 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1315 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1316 | return true; |
| 1317 | } |
| 1318 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 1319 | static int format_str(struct tagcache_search *tcs, struct display_format *fmt, |
| 1320 | char *buf, int buf_size) |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1321 | { |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1322 | char fmtbuf[20]; |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1323 | bool read_format = false; |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1324 | unsigned fmtbuf_pos = 0; |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1325 | int parpos = 0; |
| 1326 | int buf_pos = 0; |
| 1327 | int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1328 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1329 | memset(buf, 0, buf_size); |
| 1330 | for (i = 0; fmt->formatstr[i] != '\0'; i++) |
| 1331 | { |
| 1332 | if (fmt->formatstr[i] == '%') |
| 1333 | { |
| 1334 | read_format = true; |
| 1335 | fmtbuf_pos = 0; |
| 1336 | if (parpos >= fmt->tag_count) |
| 1337 | { |
| 1338 | logf("too many format tags"); |
| 1339 | return -1; |
| 1340 | } |
| 1341 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1342 | |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1343 | char formatchar = fmt->formatstr[i]; |
| 1344 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1345 | if (read_format) |
| 1346 | { |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1347 | fmtbuf[fmtbuf_pos++] = formatchar; |
| 1348 | if (fmtbuf_pos >= sizeof fmtbuf) |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1349 | { |
| 1350 | logf("format parse error"); |
| 1351 | return -2; |
| 1352 | } |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1353 | |
| 1354 | if (formatchar == 's' || formatchar == 'd') |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1355 | { |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1356 | unsigned space_left = buf_size - buf_pos; |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1357 | char tmpbuf[MAX_PATH]; |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1358 | char *result; |
| 1359 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1360 | fmtbuf[fmtbuf_pos] = '\0'; |
| 1361 | read_format = false; |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1362 | |
| 1363 | switch (formatchar) |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1364 | { |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1365 | case 's': |
| 1366 | if (fmt->tags[parpos] == tcs->type) |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1367 | { |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1368 | result = tcs->result; |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1369 | } |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1370 | else |
| 1371 | { |
| 1372 | /* Need to fetch the tag data. */ |
| 1373 | int tag = fmt->tags[parpos]; |
| 1374 | |
| 1375 | if (!tagcache_retrieve(tcs, tcs->idx_id, |
| 1376 | (tag == tag_virt_basename ? |
| 1377 | tag_filename : tag), |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1378 | tmpbuf, sizeof tmpbuf)) |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1379 | { |
| 1380 | logf("retrieve failed"); |
| 1381 | return -3; |
| 1382 | } |
| 1383 | |
| 1384 | if (tag == tag_virt_basename |
| 1385 | && (result = strrchr(tmpbuf, '/')) != NULL) |
| 1386 | { |
| 1387 | result++; |
| 1388 | } |
| 1389 | else |
| 1390 | result = tmpbuf; |
| 1391 | } |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1392 | buf_pos += |
| 1393 | snprintf(&buf[buf_pos], space_left, fmtbuf, result); |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1394 | break; |
| 1395 | |
| 1396 | case 'd': |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1397 | buf_pos += |
| 1398 | snprintf(&buf[buf_pos], space_left, fmtbuf, |
| 1399 | tagcache_get_numeric(tcs, fmt->tags[parpos])); |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1400 | } |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1401 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1402 | parpos++; |
| 1403 | } |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1404 | } |
Michael Hohmuth | accea18 | 2011-07-31 16:26:31 +0000 | [diff] [blame] | 1405 | else |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1406 | buf[buf_pos++] = formatchar; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1407 | |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1408 | if (buf_pos >= buf_size - 1) /* need at least one more byte for \0 */ |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1409 | { |
| 1410 | logf("buffer overflow"); |
| 1411 | return -4; |
| 1412 | } |
| 1413 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1414 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1415 | buf[buf_pos++] = '\0'; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1416 | |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1417 | return 0; |
| 1418 | } |
| 1419 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1420 | static struct tagentry* get_entries(struct tree_context *tc) |
| 1421 | { |
| 1422 | return core_get_data(tc->cache.entries_handle); |
| 1423 | } |
| 1424 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1425 | static int retrieve_entries(struct tree_context *c, int offset, bool init) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1426 | { |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1427 | struct tagcache_search tcs; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1428 | struct display_format *fmt; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1429 | int i; |
| 1430 | int namebufused = 0; |
| 1431 | int total_count = 0; |
Miika Pekkarinen | f9bfd73 | 2006-04-19 18:56:59 +0000 | [diff] [blame] | 1432 | int special_entry_count = 0; |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1433 | int level = c->currextra; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1434 | int tag; |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1435 | bool sort = false; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1436 | int sort_limit; |
| 1437 | int strip; |
Thomas Martitz | 16983af | 2009-08-20 19:31:09 +0000 | [diff] [blame] | 1438 | |
| 1439 | /* Show search progress straight away if the disk needs to spin up, |
| 1440 | otherwise show it after the normal 1/2 second delay */ |
| 1441 | show_search_progress( |
Frank Gevaerts | 4657301 | 2008-10-07 19:37:33 +0000 | [diff] [blame] | 1442 | #ifdef HAVE_DISK_STORAGE |
Thomas Martitz | 16983af | 2009-08-20 19:31:09 +0000 | [diff] [blame] | 1443 | storage_disk_is_active() |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1444 | #else |
Thomas Martitz | 16983af | 2009-08-20 19:31:09 +0000 | [diff] [blame] | 1445 | true |
Barry Wardell | 3e4d79e | 2008-02-26 19:25:07 +0000 | [diff] [blame] | 1446 | #endif |
Thomas Martitz | 16983af | 2009-08-20 19:31:09 +0000 | [diff] [blame] | 1447 | , 0); |
| 1448 | |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1449 | if (c->currtable == ALLSUBENTRIES) |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1450 | { |
| 1451 | tag = tag_title; |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1452 | level--; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1453 | } |
| 1454 | else |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1455 | tag = csi->tagorder[level]; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1456 | |
William Wilgus | 501404d | 2019-07-29 20:49:41 -0500 | [diff] [blame^] | 1457 | if (tag == menu_reload) |
| 1458 | return RELOAD_TAGTREE; |
| 1459 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1460 | if (!tagcache_search(&tcs, tag)) |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1461 | return -1; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1462 | |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 1463 | /* Prevent duplicate entries in the search list. */ |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1464 | tagcache_search_set_uniqbuf(&tcs, uniqbuf, UNIQBUF_SIZE); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1465 | |
Andrew Mahone | 1248a0d | 2009-06-03 08:19:32 +0000 | [diff] [blame] | 1466 | if (level || csi->clause_count[0] || TAGCACHE_IS_NUMERIC(tag)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1467 | sort = true; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1468 | |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1469 | for (i = 0; i < level; i++) |
| 1470 | { |
Andrew Mahone | 1248a0d | 2009-06-03 08:19:32 +0000 | [diff] [blame] | 1471 | if (TAGCACHE_IS_NUMERIC(csi->tagorder[i])) |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1472 | { |
| 1473 | static struct tagcache_search_clause cc; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1474 | |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1475 | memset(&cc, 0, sizeof(struct tagcache_search_clause)); |
| 1476 | cc.tag = csi->tagorder[i]; |
| 1477 | cc.type = clause_is; |
| 1478 | cc.numeric = true; |
| 1479 | cc.numeric_data = csi->result_seek[i]; |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1480 | tagcache_search_add_clause(&tcs, &cc); |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1481 | } |
| 1482 | else |
| 1483 | { |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1484 | tagcache_search_add_filter(&tcs, csi->tagorder[i], |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1485 | csi->result_seek[i]); |
| 1486 | } |
| 1487 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1488 | |
| 1489 | /* because tagcache saves the clauses, we need to lock the buffer |
| 1490 | * for the entire duration of the search */ |
| 1491 | tagtree_lock(); |
Miika Pekkarinen | 93bbd44 | 2006-08-25 21:13:49 +0000 | [diff] [blame] | 1492 | for (i = 0; i <= level; i++) |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 1493 | { |
| 1494 | int j; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1495 | |
Miika Pekkarinen | e308064 | 2006-08-25 13:22:46 +0000 | [diff] [blame] | 1496 | for (j = 0; j < csi->clause_count[i]; j++) |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1497 | tagcache_search_add_clause(&tcs, csi->clause[i][j]); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1498 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1499 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1500 | current_offset = offset; |
| 1501 | current_entry_count = 0; |
| 1502 | c->dirfull = false; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1503 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1504 | fmt = NULL; |
| 1505 | for (i = 0; i < format_count; i++) |
| 1506 | { |
| 1507 | if (formats[i]->group_id == csi->format_id[level]) |
| 1508 | fmt = formats[i]; |
| 1509 | } |
| 1510 | |
| 1511 | if (fmt) |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1512 | { |
| 1513 | sort_inverse = fmt->sort_inverse; |
| 1514 | sort_limit = fmt->limit; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1515 | strip = fmt->strip; |
Robert Kukla | f9f2d6d | 2008-07-01 20:55:19 +0000 | [diff] [blame] | 1516 | sort = true; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | sort_inverse = false; |
| 1521 | sort_limit = 0; |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1522 | strip = 0; |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1523 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1524 | |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1525 | /* lock buflib out due to possible yields */ |
| 1526 | tree_lock_cache(c); |
| 1527 | struct tagentry *dptr = core_get_data(c->cache.entries_handle); |
| 1528 | |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1529 | if (tag != tag_title && tag != tag_filename) |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1530 | { |
| 1531 | if (offset == 0) |
| 1532 | { |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1533 | dptr->newtable = ALLSUBENTRIES; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1534 | dptr->name = str(LANG_TAGNAVI_ALL_TRACKS); |
| 1535 | dptr++; |
| 1536 | current_entry_count++; |
Michael Hohmuth | e7c2449 | 2011-08-04 10:21:52 +0000 | [diff] [blame] | 1537 | special_entry_count++; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1538 | } |
Steve Bavin | de741cd | 2007-12-21 13:31:50 +0000 | [diff] [blame] | 1539 | if (offset <= 1) |
| 1540 | { |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1541 | dptr->newtable = NAVIBROWSE; |
Steve Bavin | de741cd | 2007-12-21 13:31:50 +0000 | [diff] [blame] | 1542 | dptr->name = str(LANG_TAGNAVI_RANDOM); |
| 1543 | dptr->extraseek = -1; |
| 1544 | dptr++; |
| 1545 | current_entry_count++; |
Michael Hohmuth | e7c2449 | 2011-08-04 10:21:52 +0000 | [diff] [blame] | 1546 | special_entry_count++; |
Steve Bavin | de741cd | 2007-12-21 13:31:50 +0000 | [diff] [blame] | 1547 | } |
Michael Hohmuth | e7c2449 | 2011-08-04 10:21:52 +0000 | [diff] [blame] | 1548 | |
| 1549 | total_count += 2; |
Miika Pekkarinen | 991665b | 2006-04-19 11:03:37 +0000 | [diff] [blame] | 1550 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1551 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1552 | while (tagcache_get_next(&tcs)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1553 | { |
| 1554 | if (total_count++ < offset) |
| 1555 | continue; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1556 | |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1557 | dptr->newtable = NAVIBROWSE; |
Miika Pekkarinen | 0042201 | 2006-07-16 15:04:46 +0000 | [diff] [blame] | 1558 | if (tag == tag_title || tag == tag_filename) |
Miika Pekkarinen | 4294615 | 2006-08-30 18:18:37 +0000 | [diff] [blame] | 1559 | { |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1560 | dptr->newtable = PLAYTRACK; |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1561 | dptr->extraseek = tcs.idx_id; |
Miika Pekkarinen | 4294615 | 2006-08-30 18:18:37 +0000 | [diff] [blame] | 1562 | } |
| 1563 | else |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1564 | dptr->extraseek = tcs.result_seek; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1565 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1566 | fmt = NULL; |
| 1567 | /* Check the format */ |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1568 | tagtree_lock(); |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1569 | for (i = 0; i < format_count; i++) |
| 1570 | { |
| 1571 | if (formats[i]->group_id != csi->format_id[level]) |
| 1572 | continue; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1573 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1574 | if (tagcache_check_clauses(&tcs, formats[i]->clause, |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1575 | formats[i]->clause_count)) |
| 1576 | { |
| 1577 | fmt = formats[i]; |
| 1578 | break; |
| 1579 | } |
| 1580 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1581 | tagtree_unlock(); |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1582 | |
Michael Hohmuth | 05a1984 | 2011-06-01 08:00:37 +0000 | [diff] [blame] | 1583 | if (strcmp(tcs.result, UNTAGGED) == 0) |
| 1584 | { |
| 1585 | tcs.result = str(LANG_TAGNAVI_UNTAGGED); |
| 1586 | tcs.result_len = strlen(tcs.result); |
| 1587 | tcs.ramresult = true; |
| 1588 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1589 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1590 | if (!tcs.ramresult || fmt) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1591 | { |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1592 | dptr->name = core_get_data(c->cache.name_buffer_handle)+namebufused; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1593 | |
Miika Pekkarinen | b89b5ba | 2006-10-15 11:01:18 +0000 | [diff] [blame] | 1594 | if (fmt) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1595 | { |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1596 | int ret = format_str(&tcs, fmt, dptr->name, |
| 1597 | c->cache.name_buffer_size - namebufused); |
| 1598 | if (ret == -4) /* buffer full */ |
| 1599 | { |
| 1600 | logf("chunk mode #2: %d", current_entry_count); |
| 1601 | c->dirfull = true; |
| 1602 | sort = false; |
| 1603 | break ; |
| 1604 | } |
| 1605 | else if (ret < 0) |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1606 | { |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1607 | logf("format_str() failed"); |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1608 | tagcache_search_finish(&tcs); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1609 | tree_unlock_cache(c); |
| 1610 | tagtree_unlock(); |
Miika Pekkarinen | 02df5a8 | 2006-10-24 16:20:48 +0000 | [diff] [blame] | 1611 | return 0; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1612 | } |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1613 | else |
| 1614 | namebufused += strlen(dptr->name)+1; |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1615 | } |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1616 | else |
Miika Pekkarinen | 45dfe2a | 2006-07-15 17:36:25 +0000 | [diff] [blame] | 1617 | { |
Michael Hohmuth | 8207a4a | 2011-08-04 10:23:18 +0000 | [diff] [blame] | 1618 | namebufused += tcs.result_len; |
| 1619 | if (namebufused < c->cache.name_buffer_size) |
| 1620 | strcpy(dptr->name, tcs.result); |
| 1621 | else |
| 1622 | { |
| 1623 | logf("chunk mode #2a: %d", current_entry_count); |
| 1624 | c->dirfull = true; |
| 1625 | sort = false; |
| 1626 | break ; |
| 1627 | } |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | else |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1631 | dptr->name = tcs.result; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1632 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1633 | dptr++; |
| 1634 | current_entry_count++; |
| 1635 | |
Thomas Martitz | 9809697 | 2011-08-03 09:49:25 +0000 | [diff] [blame] | 1636 | if (current_entry_count >= c->cache.max_entries) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1637 | { |
| 1638 | logf("chunk mode #3: %d", current_entry_count); |
| 1639 | c->dirfull = true; |
| 1640 | sort = false; |
| 1641 | break ; |
| 1642 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1643 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1644 | if (init && !tcs.ramsearch) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1645 | { |
Barry Wardell | ca57699 | 2008-02-27 17:42:51 +0000 | [diff] [blame] | 1646 | if (!show_search_progress(false, total_count)) |
Thomas Martitz | 16983af | 2009-08-20 19:31:09 +0000 | [diff] [blame] | 1647 | { /* user aborted */ |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1648 | tagcache_search_finish(&tcs); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1649 | tree_unlock_cache(c); |
| 1650 | tagtree_unlock(); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1651 | return current_entry_count; |
| 1652 | } |
| 1653 | } |
| 1654 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1655 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1656 | if (sort) |
Thomas Martitz | 9809697 | 2011-08-03 09:49:25 +0000 | [diff] [blame] | 1657 | { |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1658 | struct tagentry *entries = get_entries(c); |
| 1659 | qsort(&entries[special_entry_count], |
Miika Pekkarinen | f9bfd73 | 2006-04-19 18:56:59 +0000 | [diff] [blame] | 1660 | current_entry_count - special_entry_count, |
Thomas Martitz | 84c7d61 | 2014-01-15 23:18:35 +0100 | [diff] [blame] | 1661 | sizeof(struct tagentry), |
| 1662 | global_settings.interpret_numbers ? nat_compare : compare); |
Thomas Martitz | 9809697 | 2011-08-03 09:49:25 +0000 | [diff] [blame] | 1663 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1664 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1665 | if (!init) |
| 1666 | { |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1667 | tagcache_search_finish(&tcs); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1668 | tree_unlock_cache(c); |
| 1669 | tagtree_unlock(); |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1670 | return current_entry_count; |
| 1671 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1672 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1673 | while (tagcache_get_next(&tcs)) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1674 | { |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1675 | if (!tcs.ramsearch) |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1676 | { |
| 1677 | if (!show_search_progress(false, total_count)) |
| 1678 | break; |
| 1679 | } |
| 1680 | total_count++; |
| 1681 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1682 | |
Miika Pekkarinen | 8e2bdca | 2009-06-20 16:17:54 +0000 | [diff] [blame] | 1683 | tagcache_search_finish(&tcs); |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1684 | tree_unlock_cache(c); |
| 1685 | tagtree_unlock(); |
| 1686 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1687 | if (!sort && (sort_inverse || sort_limit)) |
| 1688 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 1689 | splashf(HZ*4, ID2P(LANG_SHOWDIR_BUFFER_FULL), total_count); |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1690 | logf("Too small dir buffer"); |
| 1691 | return 0; |
| 1692 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1693 | |
Miika Pekkarinen | 4f1a252 | 2006-08-26 22:00:22 +0000 | [diff] [blame] | 1694 | if (sort_limit) |
| 1695 | total_count = MIN(total_count, sort_limit); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1696 | |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1697 | if (strip) |
| 1698 | { |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1699 | dptr = get_entries(c); |
Michael Hohmuth | e7c2449 | 2011-08-04 10:21:52 +0000 | [diff] [blame] | 1700 | for (i = special_entry_count; i < current_entry_count; i++, dptr++) |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1701 | { |
| 1702 | int len = strlen(dptr->name); |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1703 | |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1704 | if (len < strip) |
| 1705 | continue; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1706 | |
Miika Pekkarinen | 8d145f6 | 2006-09-26 18:59:16 +0000 | [diff] [blame] | 1707 | dptr->name = &dptr->name[strip]; |
| 1708 | } |
| 1709 | } |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1710 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1711 | return total_count; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1712 | |
Miika Pekkarinen | 75b6abb | 2006-04-15 13:57:15 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1715 | static int load_root(struct tree_context *c) |
| 1716 | { |
Thomas Martitz | baa070c | 2011-08-30 14:01:45 +0000 | [diff] [blame] | 1717 | struct tagentry *dptr = core_get_data(c->cache.entries_handle); |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1718 | int i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1719 | |
Miika Pekkarinen | 4e6c79b | 2006-07-25 07:41:00 +0000 | [diff] [blame] | 1720 | tc = c; |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1721 | c->currtable = ROOT; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1722 | if (c->dirlevel == 0) |
Thomas Martitz | 38d5175 | 2009-05-30 16:35:28 +0000 | [diff] [blame] | 1723 | c->currextra = rootmenu; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1724 | |
Miika Pekkarinen | 3ae1c10 | 2006-09-26 06:40:14 +0000 | [diff] [blame] | 1725 | menu = menus[c->currextra]; |
| 1726 | if (menu == NULL) |
| 1727 | return 0; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1728 | |
William Wilgus | 3e27705 | 2018-12-22 12:45:02 -0600 | [diff] [blame] | 1729 | if (menu->itemcount > c->cache.max_entries) |
| 1730 | panicf("%s tree_cache too small", __func__); |
| 1731 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1732 | for (i = 0; i < menu->itemcount; i++) |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1733 | { |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1734 | dptr->name = menu->items[i]->name; |
| 1735 | switch (menu->items[i]->type) |
| 1736 | { |
| 1737 | case menu_next: |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1738 | dptr->newtable = NAVIBROWSE; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1739 | dptr->extraseek = i; |
| 1740 | break; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1741 | |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1742 | case menu_load: |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] | 1743 | dptr->newtable = ROOT; |
Miika Pekkarinen | ba34c37 | 2006-09-19 11:54:33 +0000 | [diff] [blame] | 1744 | dptr->extraseek = menu->items[i]->link; |
| 1745 | break; |
| 1746 | } |
| 1747 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1748 | dptr++; |
| 1749 | } |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1750 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1751 | current_offset = 0; |
| 1752 | current_entry_count = i; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1753 | |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1754 | return i; |
| 1755 | } |
| 1756 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1757 | int tagtree_load(struct tree_context* c) |
| 1758 | { |
Miika Pekkarinen | 3b31346 | 2006-04-16 17:32:54 +0000 | [diff] [blame] | 1759 | int count; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1760 | int table = c->currtable; |
Michael Sevakis | ffa8626 | 2013-07-12 12:03:20 -0400 | [diff] [blame] | 1761 | |
Steve Bavin | e994774 | 2006-10-20 06:49:31 +0000 | [diff] [blame] | 1762 | c->dirsindir = 0; |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 1763 | |
| 1764 | if (!table) |
| 1765 | { |
| 1766 | c->dirfull = false; |
Thomas Martitz | fc502e0 | 2009-05-30 16:10:34 +0000 | [diff] [blame] |
|