summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/search.c25
-rw-r--r--apps/plugins/sort.c24
2 files changed, 28 insertions, 21 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;
}
diff --git a/apps/plugins/sort.c b/apps/plugins/sort.c
index 1877831..2ae788e 100644
--- a/apps/plugins/sort.c
+++ b/apps/plugins/sort.c
@@ -65,6 +65,7 @@ static int num_entries;
static char **pointers;
static char *stringbuffer;
static char crlf[2] = "\r\n";
+static int bomsize;
/* Compare function for sorting backwards */
static int compare(const void* p1, const void* p2)
@@ -86,11 +87,14 @@ int read_buffer(int offset)
char *buf_ptr;
char *tmp_ptr;
int readsize;
-
- fd = rb->open(filename, O_RDONLY);
+
+ fd = rb->open_utf8(filename, O_RDONLY);
if(fd < 0)
return 10 * fd - 1;
+ bomsize = rb->lseek(fd, 0, SEEK_CUR);
+ offset += bomsize;
+
/* Fill the buffer from the file */
rb->lseek(fd, offset, SEEK_SET);
readsize = rb->read(fd, stringbuffer, buf_size);
@@ -127,7 +131,7 @@ int read_buffer(int offset)
num_entries++;
buf_ptr++;
} while(buf_ptr < stringbuffer + readsize);
-
+
return 0;
}
@@ -140,7 +144,11 @@ static int write_file(void)
/* Create a temporary file */
rb->snprintf(tmpfilename, MAX_PATH+1, "%s.tmp", filename);
- fd = rb->creat(tmpfilename);
+ if (bomsize)
+ fd = rb->open_utf8(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC);
+ else
+ fd = rb->open(tmpfilename, O_WRONLY|O_CREAT|O_TRUNC);
+
if(fd < 0)
return 10 * fd - 1;
@@ -191,16 +199,16 @@ enum plugin_status plugin_start(const void* parameter)
rb->lcd_clear_display();
rb->splash(0, "Loading...");
-
+
rc = read_buffer(0);
if(rc == 0) {
rb->lcd_clear_display();
rb->splash(0, "Sorting...");
sort_buffer();
-
+
rb->lcd_clear_display();
rb->splash(0, "Writing...");
-
+
rc = write_file();
if(rc < 0) {
rb->lcd_clear_display();
@@ -218,6 +226,6 @@ enum plugin_status plugin_start(const void* parameter)
rb->splash(HZ, "The file is too big");
}
}
-
+
return PLUGIN_OK;
}