summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/playlist.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/firmware/playlist.c b/firmware/playlist.c
index acea68cad6..16eab01cfe 100644
--- a/firmware/playlist.c
+++ b/firmware/playlist.c
@@ -24,7 +24,7 @@
24#include <string.h> 24#include <string.h>
25#include "playlist.h" 25#include "playlist.h"
26#include "debug.h" 26#include "debug.h"
27#include "disk.h" 27#include <file.h>
28 28
29/* 29/*
30 * load playlist info from disk 30 * load playlist info from disk
@@ -59,18 +59,13 @@ int reload_playlist_info( playlist_info_t *playlist )
59 */ 59 */
60void load_playlist( playlist_info_t *playlist, const char *filename ) { 60void load_playlist( playlist_info_t *playlist, const char *filename ) {
61 61
62 char *m3u_buf = NULL;
63
64 DEBUGF( "load_playlist( %s )\n", filename ); 62 DEBUGF( "load_playlist( %s )\n", filename );
65 63
66 /* read file */
67 read_file_into_buffer( &m3u_buf, filename );
68
69 /* store playlist filename */ 64 /* store playlist filename */
70 strncpy( playlist->filename, filename, sizeof(playlist->filename) ); 65 strncpy( playlist->filename, filename, sizeof(playlist->filename) );
71 66
72 /* add track indices to playlist data structure */ 67 /* add track indices to playlist data structure */
73 add_indices_to_playlist( m3u_buf, playlist ); 68 add_indices_to_playlist( playlist );
74} 69}
75 70
76/* 71/*
@@ -88,46 +83,43 @@ void empty_playlist( playlist_info_t *playlist ) {
88} 83}
89 84
90/* 85/*
91 * calculate track offsets within a playlist buffer 86 * calculate track offsets within a playlist file
92 */ 87 */
93void add_indices_to_playlist( char *buf, playlist_info_t *playlist ) 88void add_indices_to_playlist( playlist_info_t *playlist )
94{ 89{
95 char *p; 90 char *p;
96 int i = 0; 91 int i = 0;
92 unsigned char byte;
93 unsigned char lastbyte='\n';
94 int nread;
95
96 int fd;
97
98 fd = open(playlist->filename, O_RDONLY);
99 if(-1 == fd)
100 return; /* failure */
101
97 102
98 /*DEBUGF( "add_indices_to_playlist()\n" ); */ 103 /*DEBUGF( "add_indices_to_playlist()\n" ); */
99 104
100 p = buf; 105 p = &byte;
101 106
102 /* loop thru buffer, store index whenever we get a new line */ 107 /* loop thru buffer, store index whenever we get a new line */
103 108
104 while( p[i] != '\0' ) 109 while((nread = read(fd, &byte, 1)) == 1)
105 { 110 {
106 /* move thru (any) newlines */ 111 /* move thru (any) newlines */
107 112
108 while( ( p[i] != '\0' ) && ( ( p[i] == '\n' ) || ( p[i] == '\r' ) ) ) 113 if(( byte != '\n' ) && ( byte != '\r' ) &&
109 { 114 ((lastbyte == '\n') || (lastbyte == '\r')))
110 i++; 115 /* we're now at the start of a new track filename. store index */
111 } 116 extend_indices( playlist, i );
112 117
113 /* did we get to the end of the buffer? */ 118 lastbyte = byte;
114 119 i++;
115 if( p[i] == '\0' )
116 {
117 break;
118 }
119
120 /* we're now at the start of a new track filename. store index */
121
122 extend_indices( playlist, i );
123
124 /* we're now inside a track name. move to next newline */
125
126 while( ( p[i] != '\0' ) && ( ( p[i] != '\n' ) && ( p[i] != '\r' ) ) )
127 {
128 i++;
129 }
130 } 120 }
121
122 close(fd);
131} 123}
132 124
133/* 125/*