summaryrefslogtreecommitdiff
path: root/apps/tagtree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r--apps/tagtree.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c
index 405a1bbf34..eaee9b9fd1 100644
--- a/apps/tagtree.c
+++ b/apps/tagtree.c
@@ -464,9 +464,8 @@ void tagtree_init(void)
464{ 464{
465 int fd; 465 int fd;
466 char buf[256]; 466 char buf[256];
467 int pos = 0; 467 int rc;
468 468 int line_count;
469 si_count = 0;
470 469
471 fd = open(FILE_SEARCH_INSTRUCTIONS, O_RDONLY); 470 fd = open(FILE_SEARCH_INSTRUCTIONS, O_RDONLY);
472 if (fd < 0) 471 if (fd < 0)
@@ -475,48 +474,32 @@ void tagtree_init(void)
475 return ; 474 return ;
476 } 475 }
477 476
478 si = (struct search_instruction *)(((long)audiobuf & ~0x03) + 0x04); 477 /* Pre-pass search instructions file to count how many entries */
479 478 line_count = 0;
480 while ( 1 ) 479 while ( 1 )
481 { 480 {
482 char *p; 481 rc = read_line(fd, buf, sizeof(buf)-1);
483 char *next = NULL; 482 if (rc <= 0)
484 int rc; 483 break;
485 484 line_count++;
486 rc = read(fd, &buf[pos], sizeof(buf)-pos-1); 485 }
487 if (rc >= 0) 486
488 buf[pos+rc] = '\0'; 487 /* Allocate memory for searches */
489 488 si = (struct search_instruction *) buffer_alloc(sizeof(struct search_instruction) * line_count + 4);
490 if ( (p = strchr(buf, '\r')) != NULL) 489
491 { 490 /* Now read file for real, parsing into si */
492 *p = '\0'; 491 lseek(fd, 0L, SEEK_SET);
493 next = ++p; 492 while ( 1 )
494 } 493 {
495 else 494 rc = read_line(fd, buf, sizeof(buf)-1);
496 p = buf; 495 if (rc <= 0)
497 496 break;
498 if ( (p = strchr(p, '\n')) != NULL)
499 {
500 *p = '\0';
501 next = ++p;
502 }
503
504 if (!parse_search(si + si_count, buf)) 497 if (!parse_search(si + si_count, buf))
505 break; 498 break;
506 si_count++; 499 si_count++;
507
508 if (next)
509 {
510 pos = sizeof(buf) - ((long)next - (long)buf) - 1;
511 memmove(buf, next, pos);
512 }
513 else
514 break ;
515 } 500 }
516 close(fd); 501 close(fd);
517 502
518 audiobuf += sizeof(struct search_instruction) * si_count + 4;
519
520 audio_set_track_buffer_event(tagtree_buffer_event); 503 audio_set_track_buffer_event(tagtree_buffer_event);
521 audio_set_track_unbuffer_event(tagtree_unbuffer_event); 504 audio_set_track_unbuffer_event(tagtree_unbuffer_event);
522} 505}