summaryrefslogtreecommitdiff
path: root/apps/tagtree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r--apps/tagtree.c80
1 files changed, 38 insertions, 42 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 94bf726caa..c0d9f0f425 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -51,12 +51,14 @@
51 51
52static int tagtree_play_folder(struct tree_context* c); 52static int tagtree_play_folder(struct tree_context* c);
53 53
54#define SEARCHSTR_SIZE 128 54#define SEARCHSTR_SIZE 256
55static char searchstring[SEARCHSTR_SIZE]; 55
56static const struct id3_to_search_mapping { 56static const struct id3_to_search_mapping {
57 char *string; 57 char *string;
58 size_t id3_offset; 58 size_t id3_offset;
59} id3_to_search_mapping[] = { 59} id3_to_search_mapping[] = {
60 { "", 0 }, /* offset n/a */
61 { "#directory#", 0 }, /* offset n/a */
60 { "#title#", offsetof(struct mp3entry, title) }, 62 { "#title#", offsetof(struct mp3entry, title) },
61 { "#artist#", offsetof(struct mp3entry, artist) }, 63 { "#artist#", offsetof(struct mp3entry, artist) },
62 { "#album#", offsetof(struct mp3entry, album) }, 64 { "#album#", offsetof(struct mp3entry, album) },
@@ -288,7 +290,8 @@ static int get_clause(int *condition)
288 290
289static bool read_clause(struct tagcache_search_clause *clause) 291static bool read_clause(struct tagcache_search_clause *clause)
290{ 292{
291 char buf[256]; 293 char buf[SEARCHSTR_SIZE];
294 unsigned int i;
292 295
293 if (get_tag(&clause->tag) <= 0) 296 if (get_tag(&clause->tag) <= 0)
294 return false; 297 return false;
@@ -298,33 +301,24 @@ static bool read_clause(struct tagcache_search_clause *clause)
298 301
299 if (get_token_str(buf, sizeof buf) < 0) 302 if (get_token_str(buf, sizeof buf) < 0)
300 return false; 303 return false;
301 304
302 clause->str = buffer_alloc(strlen(buf)+1); 305 for (i=0; i<ARRAYLEN(id3_to_search_mapping); i++)
303 strcpy(clause->str, buf);
304
305 logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str);
306
307 if (*(clause->str) == '\0')
308 clause->source = source_input;
309 else if (!strcasecmp(clause->str, "#directory#"))
310 clause->source = source_current_path;
311 else
312 { 306 {
313 unsigned int i; 307 if (!strcasecmp(buf, id3_to_search_mapping[i].string))
314 bool found = false; 308 break;
315 for (i=0; !found && i<ARRAYLEN(id3_to_search_mapping); i++)
316 {
317 if (!strcasecmp(clause->str, id3_to_search_mapping[i].string))
318 {
319 found = true;
320 break;
321 }
322 }
323 if (found)
324 clause->source = source_current_id3+i;
325 else
326 clause->source = source_constant;
327 } 309 }
310
311 if (i<ARRAYLEN(id3_to_search_mapping)) /* runtime search operand found */
312 {
313 clause->source = source_runtime+i;
314 clause->str = buffer_alloc(SEARCHSTR_SIZE);
315 }
316 else
317 {
318 clause->source = source_constant;
319 clause->str = buffer_alloc(strlen(buf)+1);
320 strcpy(clause->str, buf);
321 }
328 322
329 if (tagcache_is_numeric_tag(clause->tag)) 323 if (tagcache_is_numeric_tag(clause->tag))
330 { 324 {
@@ -333,6 +327,8 @@ static bool read_clause(struct tagcache_search_clause *clause)
333 } 327 }
334 else 328 else
335 clause->numeric = false; 329 clause->numeric = false;
330
331 logf("got clause: %d/%d [%s]", clause->tag, clause->type, clause->str);
336 332
337 return true; 333 return true;
338} 334}
@@ -1419,14 +1415,17 @@ int tagtree_enter(struct tree_context* c)
1419 { 1415 {
1420 for (j = 0; j < csi->clause_count[i]; j++) 1416 for (j = 0; j < csi->clause_count[i]; j++)
1421 { 1417 {
1422 *searchstring='\0'; 1418 char* searchstring;
1423 source = csi->clause[i][j]->source; 1419 source = csi->clause[i][j]->source;
1424 1420
1425 if (source == source_constant) 1421 if (source == source_constant)
1426 continue; 1422 continue;
1427 1423
1424 searchstring=csi->clause[i][j]->str;
1425 *searchstring = '\0';
1426
1428 id3 = audio_current_track(); 1427 id3 = audio_current_track();
1429 1428
1430 if (source == source_current_path && id3) 1429 if (source == source_current_path && id3)
1431 { 1430 {
1432 char *e; 1431 char *e;
@@ -1435,11 +1434,11 @@ int tagtree_enter(struct tree_context* c)
1435 if (e) 1434 if (e)
1436 *e = '\0'; 1435 *e = '\0';
1437 } 1436 }
1438 1437 else if (source > source_runtime && id3)
1439 if (source >= source_current_id3 && id3)
1440 { 1438 {
1441 int i = source-source_current_id3; 1439
1442 int offset = id3_to_search_mapping[i].id3_offset; 1440 int k = source-source_runtime;
1441 int offset = id3_to_search_mapping[k].id3_offset;
1443 char **src = (char**)((char*)id3 + offset); 1442 char **src = (char**)((char*)id3 + offset);
1444 if (*src) 1443 if (*src)
1445 { 1444 {
@@ -1447,8 +1446,7 @@ int tagtree_enter(struct tree_context* c)
1447 searchstring[SEARCHSTR_SIZE-1] = '\0'; 1446 searchstring[SEARCHSTR_SIZE-1] = '\0';
1448 } 1447 }
1449 } 1448 }
1450 1449 else
1451 if((source == source_input) || (*searchstring=='\0'))
1452 { 1450 {
1453 rc = kbd_input(searchstring, SEARCHSTR_SIZE); 1451 rc = kbd_input(searchstring, SEARCHSTR_SIZE);
1454 if (rc == -1 || !searchstring[0]) 1452 if (rc == -1 || !searchstring[0])
@@ -1456,18 +1454,16 @@ int tagtree_enter(struct tree_context* c)
1456 tagtree_exit(c); 1454 tagtree_exit(c);
1457 return 0; 1455 return 0;
1458 } 1456 }
1457 if (csi->clause[i][j]->numeric)
1458 csi->clause[i][j]->numeric_data = atoi(searchstring);
1459 } 1459 }
1460 1460
1461 if (csi->clause[i][j]->numeric)
1462 csi->clause[i][j]->numeric_data = atoi(searchstring);
1463 1461
1464 /* existing bug: only one dynamic string per clause! */
1465 csi->clause[i][j]->str = searchstring;
1466 } 1462 }
1467 } 1463 }
1468 } 1464 }
1469 c->currtable = newextra; 1465 c->currtable = newextra;
1470 1466
1471 break; 1467 break;
1472 1468
1473 case navibrowse: 1469 case navibrowse: