summaryrefslogtreecommitdiff
path: root/apps
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
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')
-rw-r--r--apps/plugin.c1
-rw-r--r--apps/plugin.h28
-rw-r--r--apps/plugins/search.c25
-rw-r--r--apps/plugins/sort.c24
4 files changed, 46 insertions, 32 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index d2d6bc3896..7c7c7adf09 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -675,6 +675,7 @@ static const struct plugin_api rockbox_api = {
675 pcmbuf_beep, 675 pcmbuf_beep,
676#endif 676#endif
677 crc_32, 677 crc_32,
678 open_utf8,
678}; 679};
679 680
680int plugin_load(const char* plugin, const void* parameter) 681int plugin_load(const char* plugin, const void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index a302cc4241..8e5f474232 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -135,7 +135,7 @@ void* plugin_get_buffer(size_t *buffer_size);
135#define PLUGIN_MAGIC 0x526F634B /* RocK */ 135#define PLUGIN_MAGIC 0x526F634B /* RocK */
136 136
137/* increase this every time the api struct changes */ 137/* increase this every time the api struct changes */
138#define PLUGIN_API_VERSION 176 138#define PLUGIN_API_VERSION 177
139 139
140/* update this to latest version if a change to the api struct breaks 140/* update this to latest version if a change to the api struct breaks
141 backwards compatibility (and please take the opportunity to sort in any 141 backwards compatibility (and please take the opportunity to sort in any
@@ -329,24 +329,27 @@ struct plugin_api {
329 unsigned (*lcd_remote_get_foreground)(void); 329 unsigned (*lcd_remote_get_foreground)(void);
330 void (*lcd_remote_set_background)(unsigned background); 330 void (*lcd_remote_set_background)(unsigned background);
331 unsigned (*lcd_remote_get_background)(void); 331 unsigned (*lcd_remote_get_background)(void);
332 void (*lcd_remote_bitmap_part)(const fb_remote_data *src, int src_x, int src_y, 332 void (*lcd_remote_bitmap_part)(const fb_remote_data *src,
333 int stride, int x, int y, int width, int height); 333 int src_x, int src_y, int stride,
334 void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y, int width, 334 int x, int y, int width, int height);
335 int height); 335 void (*lcd_remote_bitmap)(const fb_remote_data *src, int x, int y,
336 int width, int height);
336#endif 337#endif
337 void (*viewport_set_defaults)(struct viewport *vp, enum screen_type screen); 338 void (*viewport_set_defaults)(struct viewport *vp,
339 const enum screen_type screen);
338 /* list */ 340 /* list */
339 void (*gui_synclist_init)(struct gui_synclist * lists, 341 void (*gui_synclist_init)(struct gui_synclist * lists,
340 list_get_name callback_get_item_name, void * data, 342 list_get_name callback_get_item_name, void * data,
341 bool scroll_all,int selected_size, 343 bool scroll_all,int selected_size,
342 struct viewport parent[NB_SCREENS]); 344 struct viewport parent[NB_SCREENS]);
343 void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items); 345 void (*gui_synclist_set_nb_items)(struct gui_synclist * lists, int nb_items);
344 void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists, list_get_icon icon_callback); 346 void (*gui_synclist_set_icon_callback)(struct gui_synclist * lists,
347 list_get_icon icon_callback);
345 int (*gui_synclist_get_nb_items)(struct gui_synclist * lists); 348 int (*gui_synclist_get_nb_items)(struct gui_synclist * lists);
346 int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists); 349 int (*gui_synclist_get_sel_pos)(struct gui_synclist * lists);
347 void (*gui_synclist_draw)(struct gui_synclist * lists); 350 void (*gui_synclist_draw)(struct gui_synclist * lists);
348 void (*gui_synclist_select_item)(struct gui_synclist * lists, 351 void (*gui_synclist_select_item)(struct gui_synclist * lists,
349 int item_number); 352 int item_number);
350 void (*gui_synclist_add_item)(struct gui_synclist * lists); 353 void (*gui_synclist_add_item)(struct gui_synclist * lists);
351 void (*gui_synclist_del_item)(struct gui_synclist * lists); 354 void (*gui_synclist_del_item)(struct gui_synclist * lists);
352 void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll); 355 void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
@@ -358,7 +361,7 @@ struct plugin_api {
358 const struct text_message * yes_message, 361 const struct text_message * yes_message,
359 const struct text_message * no_message); 362 const struct text_message * no_message);
360 void (*simplelist_info_init)(struct simplelist_info *info, char* title, 363 void (*simplelist_info_init)(struct simplelist_info *info, char* title,
361 int count, void* data); 364 int count, void* data);
362 bool (*simplelist_show_list)(struct simplelist_info *info); 365 bool (*simplelist_show_list)(struct simplelist_info *info);
363 366
364 /* button */ 367 /* button */
@@ -431,7 +434,8 @@ struct plugin_api {
431 void (*yield)(void); 434 void (*yield)(void);
432 volatile long* current_tick; 435 volatile long* current_tick;
433 long (*default_event_handler)(long event); 436 long (*default_event_handler)(long event);
434 long (*default_event_handler_ex)(long event, void (*callback)(void *), void *parameter); 437 long (*default_event_handler_ex)(long event,
438 void (*callback)(void *), void *parameter);
435 unsigned int (*create_thread)(void (*function)(void), void* stack, 439 unsigned int (*create_thread)(void (*function)(void), void* stack,
436 size_t stack_size, unsigned flags, 440 size_t stack_size, unsigned flags,
437 const char *name 441 const char *name
@@ -554,7 +558,8 @@ struct plugin_api {
554 const char * (*sound_unit)(int setting); 558 const char * (*sound_unit)(int setting);
555 int (*sound_val2phys)(int setting, int value); 559 int (*sound_val2phys)(int setting, int value);
556#ifndef SIMULATOR 560#ifndef SIMULATOR
557 void (*mp3_play_data)(const unsigned char* start, int size, void (*get_more)(unsigned char** start, size_t* size)); 561 void (*mp3_play_data)(const unsigned char* start, int size,
562 void (*get_more)(unsigned char** start, size_t* size));
558 void (*mp3_play_pause)(bool play); 563 void (*mp3_play_pause)(bool play);
559 void (*mp3_play_stop)(void); 564 void (*mp3_play_stop)(void);
560 bool (*mp3_is_playing)(void); 565 bool (*mp3_is_playing)(void);
@@ -849,6 +854,7 @@ struct plugin_api {
849 int amplitude); 854 int amplitude);
850#endif 855#endif
851 unsigned (*crc_32)(const void *src, unsigned len, unsigned crc32); 856 unsigned (*crc_32)(const void *src, unsigned len, unsigned crc32);
857 int (*open_utf8)(const char* pathname, int flags);
852}; 858};
853 859
854/* plugin header */ 860/* plugin header */
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}
diff --git a/apps/plugins/sort.c b/apps/plugins/sort.c
index 1877831815..2ae788ebbd 100644
--- a/apps/plugins/sort.c
+++ b/apps/plugins/sort.c
@@ -65,6 +65,7 @@ static int num_entries;
65static char **pointers; 65static char **pointers;
66static char *stringbuffer; 66static char *stringbuffer;
67static char crlf[2] = "\r\n"; 67static char crlf[2] = "\r\n";
68static int bomsize;
68 69
69/* Compare function for sorting backwards */ 70/* Compare function for sorting backwards */
70static int compare(const void* p1, const void* p2) 71static int compare(const void* p1, const void* p2)
@@ -86,11 +87,14 @@ int read_buffer(int offset)
86 char *buf_ptr; 87 char *buf_ptr;
87 char *tmp_ptr; 88 char *tmp_ptr;
88 int readsize; 89 int readsize;
89 90
90 fd = rb->open(filename, O_RDONLY); 91 fd = rb->open_utf8(filename, O_RDONLY);
91 if(fd < 0) 92 if(fd < 0)
92 return 10 * fd - 1; 93 return 10 * fd - 1;
93 94
95 bomsize = rb->lseek(fd, 0, SEEK_CUR);
96 offset += bomsize;
97
94 /* Fill the buffer from the file */ 98 /* Fill the buffer from the file */
95 rb->lseek(fd, offset, SEEK_SET); 99 rb->lseek(fd, offset, SEEK_SET);
96 readsize = rb->read(fd, stringbuffer, buf_size); 100 readsize = rb->read(fd, stringbuffer, buf_size);
@@ -127,7 +131,7 @@ int read_buffer(int offset)
127 num_entries++; 131 num_entries++;
128 buf_ptr++; 132 buf_ptr++;
129 } while(buf_ptr < stringbuffer + readsize); 133 } while(buf_ptr < stringbuffer + readsize);
130 134
131 return 0; 135 return 0;
132} 136}
133 137
@@ -140,7 +144,11 @@ static int write_file(void)
140 144
141 /* Create a temporary file */ 145 /* Create a temporary file */
142 rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename); 146 rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename);
143 fd = rb->creat(tmpfilename); 147 if (bomsize)
148 fd = rb->open_utf8(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC);
149 else
150 fd = rb->open(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC);
151
144 if(fd < 0) 152 if(fd < 0)
145 return 10 * fd - 1; 153 return 10 * fd - 1;
146 154
@@ -191,16 +199,16 @@ enum plugin_status plugin_start(const void* parameter)
191 199
192 rb->lcd_clear_display(); 200 rb->lcd_clear_display();
193 rb->splash(0, "Loading..."); 201 rb->splash(0, "Loading...");
194 202
195 rc = read_buffer(0); 203 rc = read_buffer(0);
196 if(rc == 0) { 204 if(rc == 0) {
197 rb->lcd_clear_display(); 205 rb->lcd_clear_display();
198 rb->splash(0, "Sorting..."); 206 rb->splash(0, "Sorting...");
199 sort_buffer(); 207 sort_buffer();
200 208
201 rb->lcd_clear_display(); 209 rb->lcd_clear_display();
202 rb->splash(0, "Writing..."); 210 rb->splash(0, "Writing...");
203 211
204 rc = write_file(); 212 rc = write_file();
205 if(rc < 0) { 213 if(rc < 0) {
206 rb->lcd_clear_display(); 214 rb->lcd_clear_display();
@@ -218,6 +226,6 @@ enum plugin_status plugin_start(const void* parameter)
218 rb->splash(HZ, "The file is too big"); 226 rb->splash(HZ, "The file is too big");
219 } 227 }
220 } 228 }
221 229
222 return PLUGIN_OK; 230 return PLUGIN_OK;
223} 231}