summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2006-08-23 08:41:18 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2006-08-23 08:41:18 +0000
commiteed923ec831646f1cd705118199814e0fe33efbf (patch)
tree40d698edc6f0ea62ce2f3fc9e073dff904859cce /apps
parent66c4bd6e63197297c44e94f0a3d887e25e675421 (diff)
downloadrockbox-eed923ec831646f1cd705118199814e0fe33efbf.tar.gz
rockbox-eed923ec831646f1cd705118199814e0fe33efbf.zip
Patch #5845 by Steve Bavin - Make tagtree.c use buffer_alloc()
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10713 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-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)
{
int fd;
char buf[256];
- int pos = 0;
-
- si_count = 0;
+ int rc;
+ int line_count;
fd = open(FILE_SEARCH_INSTRUCTIONS, O_RDONLY);
if (fd < 0)
@@ -475,48 +474,32 @@ void tagtree_init(void)
return ;
}
- si = (struct search_instruction *)(((long)audiobuf & ~0x03) + 0x04);
-
+ /* Pre-pass search instructions file to count how many entries */
+ line_count = 0;
while ( 1 )
{
- char *p;
- char *next = NULL;
- int rc;
-
- rc = read(fd, &buf[pos], sizeof(buf)-pos-1);
- if (rc >= 0)
- buf[pos+rc] = '\0';
-
- if ( (p = strchr(buf, '\r')) != NULL)
- {
- *p = '\0';
- next = ++p;
- }
- else
- p = buf;
-
- if ( (p = strchr(p, '\n')) != NULL)
- {
- *p = '\0';
- next = ++p;
- }
-
+ rc = read_line(fd, buf, sizeof(buf)-1);
+ if (rc <= 0)
+ break;
+ line_count++;
+ }
+
+ /* Allocate memory for searches */
+ si = (struct search_instruction *) buffer_alloc(sizeof(struct search_instruction) * line_count + 4);
+
+ /* Now read file for real, parsing into si */
+ lseek(fd, 0L, SEEK_SET);
+ while ( 1 )
+ {
+ rc = read_line(fd, buf, sizeof(buf)-1);
+ if (rc <= 0)
+ break;
if (!parse_search(si + si_count, buf))
break;
si_count++;
-
- if (next)
- {
- pos = sizeof(buf) - ((long)next - (long)buf) - 1;
- memmove(buf, next, pos);
- }
- else
- break ;
}
close(fd);
- audiobuf += sizeof(struct search_instruction) * si_count + 4;
-
audio_set_track_buffer_event(tagtree_buffer_event);
audio_set_track_unbuffer_event(tagtree_unbuffer_event);
}