summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2006-11-29 19:22:44 +0000
committerMagnus Holmgren <magnushol@gmail.com>2006-11-29 19:22:44 +0000
commita515b10d47218cf2cc4c79865ff2a34aea7ec3bc (patch)
treeceb7ce6a713ce8c9bf67fe0de48a62748aa12585
parent6ae46065b40691d5571252aeeb2ec5475e2f5e4c (diff)
downloadrockbox-a515b10d47218cf2cc4c79865ff2a34aea7ec3bc.tar.gz
rockbox-a515b10d47218cf2cc4c79865ff2a34aea7ec3bc.zip
Read .m3u playlist files using the default code page (unless they start with a BOM) rather than UTF-8. Change default playlist suffix to .m3u8 (playlists are always saved using UTF-8).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11626 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/playlist.c42
-rw-r--r--apps/playlist.h3
-rw-r--r--apps/playlist_menu.c4
3 files changed, 45 insertions, 4 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";
202static void empty_playlist(struct playlist_info* playlist, bool resume) 204static 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);
diff --git a/apps/playlist.h b/apps/playlist.h
index 4ad7587722..3270bc55fa 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -30,7 +30,7 @@
30#define PLAYLIST_ATTR_SKIPPED 0x04 30#define PLAYLIST_ATTR_SKIPPED 0x04
31#define PLAYLIST_MAX_CACHE 16 31#define PLAYLIST_MAX_CACHE 16
32 32
33#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u" 33#define DEFAULT_DYNAMIC_PLAYLIST_NAME "/dynamic.m3u8"
34 34
35enum playlist_command { 35enum playlist_command {
36 PLAYLIST_COMMAND_PLAYLIST, 36 PLAYLIST_COMMAND_PLAYLIST,
@@ -69,6 +69,7 @@ struct playlist_info
69 bool current; /* current playing playlist */ 69 bool current; /* current playing playlist */
70 char filename[MAX_PATH]; /* path name of m3u playlist on disk */ 70 char filename[MAX_PATH]; /* path name of m3u playlist on disk */
71 char control_filename[MAX_PATH]; /* full path of control file */ 71 char control_filename[MAX_PATH]; /* full path of control file */
72 bool utf8; /* playlist is in .m3u8 format */
72 int fd; /* descriptor of the open playlist file */ 73 int fd; /* descriptor of the open playlist file */
73 int control_fd; /* descriptor of the open control file */ 74 int control_fd; /* descriptor of the open control file */
74 bool control_created; /* has control file been created? */ 75 bool control_created; /* has control file been created? */
diff --git a/apps/playlist_menu.c b/apps/playlist_menu.c
index e23722160f..5e73621a22 100644
--- a/apps/playlist_menu.c
+++ b/apps/playlist_menu.c
@@ -85,8 +85,8 @@ int save_playlist_screen(struct playlist_info* playlist)
85 85
86 filename = playlist_get_name(playlist, temp, sizeof(temp)); 86 filename = playlist_get_name(playlist, temp, sizeof(temp));
87 87
88 if (!filename || (len=strlen(filename)) <= 4 || 88 if (!filename || (len=strlen(filename)) <= 5 ||
89 strcasecmp(&filename[len-4], ".m3u")) 89 strcasecmp(&filename[len-5], ".m3u8"))
90 strcpy(filename, DEFAULT_DYNAMIC_PLAYLIST_NAME); 90 strcpy(filename, DEFAULT_DYNAMIC_PLAYLIST_NAME);
91 91
92 if (!kbd_input(filename, sizeof(temp))) 92 if (!kbd_input(filename, sizeof(temp)))