2004-07-13 14:25:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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"
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
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];
|
|
|
|
|
2004-07-26 23:28:37 +00:00
|
|
|
static int strpcasecmp(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) {
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (*s1 == '\0') ;
|
|
|
|
}
|
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
static void fill_buffer(int pos)
|
|
|
|
{
|
|
|
|
int numread;
|
|
|
|
int i;
|
|
|
|
int found = false ;
|
2004-07-13 19:22:07 +00:00
|
|
|
const char crlf = '\n';
|
2004-07-13 14:25:19 +00:00
|
|
|
|
|
|
|
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] ));
|
2004-07-13 19:22:07 +00:00
|
|
|
rb->write(fdw, &crlf, 1);
|
2004-07-13 14:25:19 +00:00
|
|
|
|
|
|
|
found = false ;
|
|
|
|
results++ ;
|
|
|
|
}
|
|
|
|
line_end = i +1 ;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!found && tolower(buffer[i]) == tolower(search_string[0]))
|
|
|
|
{
|
2004-07-26 23:28:37 +00:00
|
|
|
found = strpcasecmp(&search_string[0],&buffer[i]) ;
|
2004-07-13 14:25:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-07-26 23:28:37 +00:00
|
|
|
DEBUGF("\n-------------------\n");
|
2004-07-13 14:25:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2004-07-26 23:28:37 +00:00
|
|
|
rb->memset(search_string, 0, sizeof(search_string));
|
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
if (!rb->kbd_input(search_string,sizeof search_string))
|
|
|
|
{
|
|
|
|
rb->lcd_clear_display();
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(0, "Searching...");
|
2004-07-13 14:25:19 +00:00
|
|
|
fd = rb->open(file, O_RDONLY);
|
|
|
|
if (fd==-1)
|
|
|
|
return false;
|
|
|
|
|
2007-02-01 23:08:15 +00:00
|
|
|
fdw = rb->creat(resultfile);
|
2004-07-13 14:25:19 +00:00
|
|
|
|
|
|
|
if (fdw < 0) {
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Failed to create result file!");
|
2004-07-13 14:25:19 +00:00
|
|
|
#else
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "File creation failed");
|
2004-07-13 14:25:19 +00:00
|
|
|
#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;
|
|
|
|
|
|
|
|
rb = api;
|
|
|
|
|
2004-07-26 23:28:37 +00:00
|
|
|
DEBUGF("%s - %s\n", parameter, &filename[rb->strlen(filename)-4]);
|
2004-07-13 14:25:19 +00:00
|
|
|
/* Check the extension. We only allow .m3u files. */
|
2007-01-10 08:27:42 +00:00
|
|
|
if(rb->strcasecmp(&filename[rb->strlen(filename)-4], ".m3u") &&
|
|
|
|
rb->strcasecmp(&filename[rb->strlen(filename)-5], ".m3u8")) {
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Not a .m3u or .m3u8 file");
|
2004-07-13 14:25:19 +00:00
|
|
|
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();
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Done");
|
2004-07-13 14:25:19 +00:00
|
|
|
rb->close(fdw);
|
|
|
|
rb->close(fd);
|
|
|
|
|
|
|
|
/* We fake a USB connection to force a reload of the file browser */
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
}
|