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.tar.gz
rockbox-0cbf210d76dbc8f01a2da944e76f05fdb050003b.zip
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 d732c0282b..4f60c82d08 100644
--- a/apps/plugins/search.c
+++ b/apps/plugins/search.c
@@ -29,7 +29,7 @@ PLUGIN_HEADER
29static int fd; 29static int fd;
30static int fdw; 30static int fdw;
31 31
32static int file_size; 32static int file_size, bomsize;
33static int results = 0; 33static int results = 0;
34 34
35static char buffer[BUFFER_SIZE+1]; 35static char buffer[BUFFER_SIZE+1];
@@ -57,13 +57,8 @@ static void fill_buffer(int pos){
57 int found = false ; 57 int found = false ;
58 const char crlf = '\n'; 58 const char crlf = '\n';
59 59
60 if (pos>=file_size-BUFFER_SIZE) 60 rb->lseek(fd, pos+bomsize, SEEK_SET);
61 pos = file_size-BUFFER_SIZE; 61 numread = rb->read(fd, buffer, MIN(BUFFER_SIZE, file_size-pos));
62 if (pos<0)
63 pos = 0;
64
65 rb->lseek(fd, pos, SEEK_SET);
66 numread = rb->read(fd, buffer, BUFFER_SIZE);
67 62
68 buffer[numread] = 0; 63 buffer[numread] = 0;
69 line_end = 0; 64 line_end = 0;
@@ -120,11 +115,15 @@ static bool search_init(const char* file){
120 if (!rb->kbd_input(search_string,sizeof search_string)){ 115 if (!rb->kbd_input(search_string,sizeof search_string)){
121 clear_display(); 116 clear_display();
122 rb->splash(0, "Searching..."); 117 rb->splash(0, "Searching...");
123 fd = rb->open(file, O_RDONLY); 118 fd = rb->open_utf8(file, O_RDONLY);
124 if (fd < 0) 119 if (fd < 0)
125 return false; 120 return false;
126 121
127 fdw = rb->creat(resultfile); 122 bomsize = rb->lseek(fd, 0, SEEK_CUR);
123 if (bomsize)
124 fdw = rb->open_utf8(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
125 else
126 fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
128 127
129 if (fdw < 0) { 128 if (fdw < 0) {
130#ifdef HAVE_LCD_BITMAP 129#ifdef HAVE_LCD_BITMAP
@@ -136,7 +135,7 @@ static bool search_init(const char* file){
136 return false; 135 return false;
137 } 136 }
138 137
139 file_size = rb->lseek(fd, 0, SEEK_END); 138 file_size = rb->lseek(fd, 0, SEEK_END) - bomsize;
140 139
141 return true; 140 return true;
142 } 141 }
@@ -177,7 +176,7 @@ enum plugin_status plugin_start(const void* parameter)
177 rb->splash(HZ, "Done"); 176 rb->splash(HZ, "Done");
178 rb->close(fdw); 177 rb->close(fdw);
179 rb->close(fd); 178 rb->close(fd);
179 rb->reload_directory();
180 180
181 /* We fake a USB connection to force a reload of the file browser */ 181 return PLUGIN_OK;
182 return PLUGIN_USB_CONNECTED;
183} 182}