diff options
Diffstat (limited to 'apps/playlist.c')
-rw-r--r-- | apps/playlist.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index 23d79a6476..4a3c37d584 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -68,6 +68,7 @@ | |||
68 | #include <stdio.h> | 68 | #include <stdio.h> |
69 | #include <stdlib.h> | 69 | #include <stdlib.h> |
70 | #include <string.h> | 70 | #include <string.h> |
71 | #include <ctype.h> | ||
71 | #include "playlist.h" | 72 | #include "playlist.h" |
72 | #include "file.h" | 73 | #include "file.h" |
73 | #include "action.h" | 74 | #include "action.h" |
@@ -97,6 +98,7 @@ | |||
97 | #include "lang.h" | 98 | #include "lang.h" |
98 | #include "talk.h" | 99 | #include "talk.h" |
99 | #include "splash.h" | 100 | #include "splash.h" |
101 | #include "rbunicode.h" | ||
100 | 102 | ||
101 | #define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control" | 103 | #define PLAYLIST_CONTROL_FILE ROCKBOX_DIR "/.playlist_control" |
102 | #define PLAYLIST_CONTROL_FILE_VERSION 2 | 104 | #define PLAYLIST_CONTROL_FILE_VERSION 2 |
@@ -202,6 +204,7 @@ static const char playlist_thread_name[] = "playlist cachectrl"; | |||
202 | static void empty_playlist(struct playlist_info* playlist, bool resume) | 204 | static void empty_playlist(struct playlist_info* playlist, bool resume) |
203 | { | 205 | { |
204 | playlist->filename[0] = '\0'; | 206 | playlist->filename[0] = '\0'; |
207 | playlist->utf8 = true; | ||
205 | 208 | ||
206 | if(playlist->fd >= 0) | 209 | if(playlist->fd >= 0) |
207 | /* If there is an already open playlist, close it. */ | 210 | /* If there is an already open playlist, close it. */ |
@@ -437,6 +440,10 @@ static void update_playlist_filename(struct playlist_info* playlist, | |||
437 | { | 440 | { |
438 | char *sep=""; | 441 | char *sep=""; |
439 | int dirlen = strlen(dir); | 442 | int dirlen = strlen(dir); |
443 | int filelen = strlen(file); | ||
444 | |||
445 | /* Default to utf8 unless explicitly told otherwise. */ | ||
446 | playlist->utf8 = !(filelen > 4 && strcasecmp(&file[filelen - 4], ".m3u") == 0); | ||
440 | 447 | ||
441 | /* If the dir does not end in trailing slash, we use a separator. | 448 | /* If the dir does not end in trailing slash, we use a separator. |
442 | Otherwise we don't. */ | 449 | Otherwise we don't. */ |
@@ -509,6 +516,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist, | |||
509 | nread -= 3; | 516 | nread -= 3; |
510 | p += 3; | 517 | p += 3; |
511 | i += 3; | 518 | i += 3; |
519 | playlist->utf8 = true; /* Override any earlier indication. */ | ||
512 | } | 520 | } |
513 | 521 | ||
514 | for(count=0; count < nread; count++,p++) { | 522 | for(count=0; count < nread; count++,p++) { |
@@ -1267,7 +1275,38 @@ static int get_filename(struct playlist_info* playlist, int index, int seek, | |||
1267 | if (lseek(fd, seek, SEEK_SET) != seek) | 1275 | if (lseek(fd, seek, SEEK_SET) != seek) |
1268 | max = -1; | 1276 | max = -1; |
1269 | else | 1277 | else |
1270 | max = read(fd, tmp_buf, buf_length); | 1278 | { |
1279 | max = read(fd, tmp_buf, MIN((size_t) buf_length, sizeof(tmp_buf))); | ||
1280 | |||
1281 | if ((max > 0) && !playlist->utf8) | ||
1282 | { | ||
1283 | char* end; | ||
1284 | int i = 0; | ||
1285 | |||
1286 | /* Locate EOL. */ | ||
1287 | while ((tmp_buf[i] != '\n') && (tmp_buf[i] != '\r') | ||
1288 | && (i < max)) | ||
1289 | { | ||
1290 | i++; | ||
1291 | } | ||
1292 | |||
1293 | /* Now work back killing white space. */ | ||
1294 | while ((i > 0) && isspace(tmp_buf[i - 1])) | ||
1295 | { | ||
1296 | i--; | ||
1297 | } | ||
1298 | |||
1299 | /* Borrow dir_buf a little... */ | ||
1300 | /* TODO: iso_decode can overflow dir_buf; it really | ||
1301 | * should take a dest size argument. | ||
1302 | */ | ||
1303 | end = iso_decode(tmp_buf, dir_buf, -1, i); | ||
1304 | *end = 0; | ||
1305 | strncpy(tmp_buf, dir_buf, sizeof(tmp_buf)); | ||
1306 | tmp_buf[sizeof(tmp_buf) - 1] = 0; | ||
1307 | max = strlen(tmp_buf); | ||
1308 | } | ||
1309 | } | ||
1271 | } | 1310 | } |
1272 | 1311 | ||
1273 | mutex_unlock(&playlist->control_mutex); | 1312 | mutex_unlock(&playlist->control_mutex); |
@@ -2697,6 +2736,7 @@ int playlist_set_current(struct playlist_info* playlist) | |||
2697 | strncpy(current_playlist.filename, playlist->filename, | 2736 | strncpy(current_playlist.filename, playlist->filename, |
2698 | sizeof(current_playlist.filename)); | 2737 | sizeof(current_playlist.filename)); |
2699 | 2738 | ||
2739 | current_playlist.utf8 = playlist->utf8; | ||
2700 | current_playlist.fd = playlist->fd; | 2740 | current_playlist.fd = playlist->fd; |
2701 | 2741 | ||
2702 | close(playlist->control_fd); | 2742 | close(playlist->control_fd); |