diff options
| author | Linus Nielsen Feltzing <linus@haxx.se> | 2004-07-13 14:25:19 +0000 |
|---|---|---|
| committer | Linus Nielsen Feltzing <linus@haxx.se> | 2004-07-13 14:25:19 +0000 |
| commit | 6d84d3a691f51a6fe58a90207b5cab36f765d9b0 (patch) | |
| tree | 1af2e6625ca00cc9b5780f0f1855fc5e98ec7eb3 /apps/plugins | |
| parent | a96a130f5ac3753e4e882f2e2a4b8c41f221e704 (diff) | |
| download | rockbox-6d84d3a691f51a6fe58a90207b5cab36f765d9b0.zip rockbox-6d84d3a691f51a6fe58a90207b5cab36f765d9b0.tar.gz rockbox-6d84d3a691f51a6fe58a90207b5cab36f765d9b0.tar.bz2 rockbox-6d84d3a691f51a6fe58a90207b5cab36f765d9b0.tar.xz | |
New plugin, search.rock, by Stefan Meyer (Patch #723682)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4874 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
| -rw-r--r-- | apps/plugins/search.c | 180 | ||||
| -rw-r--r-- | apps/plugins/viewers.config | 1 |
2 files changed, 181 insertions, 0 deletions
diff --git a/apps/plugins/search.c b/apps/plugins/search.c new file mode 100644 index 0000000..611a48e --- /dev/null +++ b/apps/plugins/search.c @@ -0,0 +1,180 @@ +/*************************************************************************** + * + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2003 Stefan Meyer + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "plugin.h" +#include "ctype.h" + +static struct plugin_api* rb; + +#define BUFFER_SIZE 16384 + +static int fd; +static int fdw; + +static int file_size; +static int results = 0; + +static char buffer[BUFFER_SIZE+1]; +static char search_string[60] ; + +static int buffer_pos; /* Position of the buffer in the file */ + +static int line_end; /* Index of the end of line */ + +char resultfile[MAX_PATH]; +char path[MAX_PATH]; + +static int strpcasecmp(const char *s1, const char *s2) +{ + while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) { + s1++; + s2++; + } + + return (*s1 == '\0') ; +} + +static void fill_buffer(int pos) +{ + int numread; + int i; + int found = false ; + char crlf[2] = "\n\0"; + + 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); + + buffer[numread] = 0; + line_end = 0; + + for(i=0;i<numread;i++) { + switch(buffer[i]) { + case '\r': + buffer[i] = ' '; + break; + case '\n': + buffer[i] = 0; + buffer_pos = pos + i +1 ; + + if (found) + { + /* write to playlist */ + rb->write(fdw, &buffer[line_end], + rb->strlen( &buffer[line_end] )); + rb->write(fdw, &crlf,1); + + found = false ; + results++ ; + } + line_end = i +1 ; + + break; + + default: + if (!found && tolower(buffer[i]) == tolower(search_string[0])) + { + found = strpcasecmp(&search_string[0],&buffer[i]) ; + } + break; + } + } +} + +static void search_buffer(void) +{ + buffer_pos = 0; + + fill_buffer(0); + while ((buffer_pos+1) < file_size) { + fill_buffer(buffer_pos); + } +} + +static bool search_init(char* file) +{ + if (!rb->kbd_input(search_string,sizeof search_string)) + { + rb->lcd_clear_display(); + rb->splash(0, true, "Searching..."); + fd = rb->open(file, O_RDONLY); + if (fd==-1) + return false; + + fdw = rb->creat(resultfile,0); + + if (fdw < 0) { +#ifdef HAVE_LCD_BITMAP + rb->splash(HZ, true, "Failed to create result file!"); +#else + rb->splash(HZ, true, "File creation failed"); +#endif + return false; + } + + file_size = rb->lseek(fd, 0, SEEK_END); + + return true; + } + + return false ; +} + +/* this is the plugin entry point */ +enum plugin_status plugin_start(struct plugin_api* api, void* parameter) +{ + int ok; + char *filename = parameter; + char *p; + + TEST_PLUGIN_API(api); + + rb = api; + + /* Check the extension. We only allow .m3u files. */ + if(!strpcasecmp(&filename[rb->strlen(filename)-4], ".m3u")) { + rb->splash(HZ, true, "Not a .m3u file"); + return PLUGIN_ERROR; + } + + rb->strcpy(path, filename); + + p = rb->strrchr(path, '/'); + if(p) + *p = 0; + + rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path, p+1); + ok = search_init(parameter); + if (!ok) { + return PLUGIN_ERROR; + } + search_buffer(); + + rb->lcd_clear_display(); + rb->splash(HZ, true, "Done"); + rb->close(fdw); + rb->close(fd); + + /* We fake a USB connection to force a reload of the file browser */ + return PLUGIN_USB_CONNECTED; +} diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config index 2acbe17..2b1d527 100644 --- a/apps/plugins/viewers.config +++ b/apps/plugins/viewers.config @@ -4,3 +4,4 @@ jpg,jpeg.rock,18 24 3C 3C 24 18 ucl,rockbox_flash.rock,2A 7F 41 41 7F 2A rvf,video.rock,5D 7F 5D 7F 5D 7F mp3,vbrfix.rock,10 08 58 38 04 02 +m3u,search.rock,00 00 00 00 00 00 |