summaryrefslogtreecommitdiff
path: root/apps/plugins/search.c
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2009-12-20 12:59:25 +0000
committerTeruaki Kawashima <teru@rockbox.org>2009-12-20 12:59:25 +0000
commit0cbf210d76dbc8f01a2da944e76f05fdb050003b (patch)
tree217bde3bcd1fe6538c80c24e7e7927e753881b9c /apps/plugins/search.c
parent275d960b04ea74f45e97331408644c4ec4be6d8f (diff)
downloadrockbox-0cbf210d76dbc8f01a2da944e76f05fdb050003b.zip
rockbox-0cbf210d76dbc8f01a2da944e76f05fdb050003b.tar.gz
rockbox-0cbf210d76dbc8f01a2da944e76f05fdb050003b.tar.bz2
rockbox-0cbf210d76dbc8f01a2da944e76f05fdb050003b.tar.xz
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
Diffstat (limited to 'apps/plugins/search.c')
-rw-r--r--apps/plugins/search.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/apps/plugins/search.c b/apps/plugins/search.c
index d732c02..4f60c82 100644
--- a/apps/plugins/search.c
+++ b/apps/plugins/search.c
@@ -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;
}