1
0
Fork 0
forked from len0rd/rockbox

plugin: search,sort: Handle UTF-8 BOM at the start of file.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24081 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-12-20 12:59:25 +00:00
parent 275d960b04
commit 0cbf210d76
4 changed files with 46 additions and 32 deletions

View file

@ -29,7 +29,7 @@ PLUGIN_HEADER
static int fd;
static int fdw;
static int file_size;
static int file_size, bomsize;
static int results = 0;
static char buffer[BUFFER_SIZE+1];
@ -57,13 +57,8 @@ static void fill_buffer(int pos){
int found = false ;
const char crlf = '\n';
if (pos>=file_size-BUFFER_SIZE)
pos = file_size-BUFFER_SIZE;
if (pos<0)
pos = 0;
rb->lseek(fd, pos, SEEK_SET);
numread = rb->read(fd, buffer, BUFFER_SIZE);
rb->lseek(fd, pos+bomsize, SEEK_SET);
numread = rb->read(fd, buffer, MIN(BUFFER_SIZE, file_size-pos));
buffer[numread] = 0;
line_end = 0;
@ -120,11 +115,15 @@ static bool search_init(const char* file){
if (!rb->kbd_input(search_string,sizeof search_string)){
clear_display();
rb->splash(0, "Searching...");
fd = rb->open(file, O_RDONLY);
fd = rb->open_utf8(file, O_RDONLY);
if (fd < 0)
return false;
fdw = rb->creat(resultfile);
bomsize = rb->lseek(fd, 0, SEEK_CUR);
if (bomsize)
fdw = rb->open_utf8(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
else
fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
if (fdw < 0) {
#ifdef HAVE_LCD_BITMAP
@ -136,7 +135,7 @@ static bool search_init(const char* file){
return false;
}
file_size = rb->lseek(fd, 0, SEEK_END);
file_size = rb->lseek(fd, 0, SEEK_END) - bomsize;
return true;
}
@ -177,7 +176,7 @@ enum plugin_status plugin_start(const void* parameter)
rb->splash(HZ, "Done");
rb->close(fdw);
rb->close(fd);
rb->reload_directory();
/* We fake a USB connection to force a reload of the file browser */
return PLUGIN_USB_CONNECTED;
return PLUGIN_OK;
}