2004-07-13 14:25:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Stefan Meyer
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-07-13 14:25:19 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <ctype.h>
|
2004-07-13 14:25:19 +00:00
|
|
|
|
2010-08-23 17:12:26 +00:00
|
|
|
PLUGIN_HEADER
|
2006-01-15 18:20:18 +00:00
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
#define BUFFER_SIZE 16384
|
|
|
|
|
|
|
|
static int fd;
|
|
|
|
static int fdw;
|
|
|
|
|
2009-12-20 12:59:25 +00:00
|
|
|
static int file_size, bomsize;
|
2004-07-13 14:25:19 +00:00
|
|
|
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];
|
|
|
|
|
2007-08-07 12:46:26 +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-26 23:28:37 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 12:46:26 +00:00
|
|
|
static void fill_buffer(int pos){
|
2004-07-13 14:25:19 +00:00
|
|
|
int numread;
|
|
|
|
int i;
|
|
|
|
int found = false ;
|
2007-08-07 12:46:26 +00:00
|
|
|
const char crlf = '\n';
|
2004-07-13 14:25:19 +00:00
|
|
|
|
2009-12-20 12:59:25 +00:00
|
|
|
rb->lseek(fd, pos+bomsize, SEEK_SET);
|
|
|
|
numread = rb->read(fd, buffer, MIN(BUFFER_SIZE, file_size-pos));
|
2004-07-13 14:25:19 +00:00
|
|
|
|
|
|
|
buffer[numread] = 0;
|
|
|
|
line_end = 0;
|
|
|
|
|
|
|
|
for(i=0;i<numread;i++) {
|
2007-08-07 12:46:26 +00:00
|
|
|
switch(buffer[i]) {
|
|
|
|
case '\r':
|
|
|
|
buffer[i] = ' ';
|
|
|
|
break;
|
2004-07-13 14:25:19 +00:00
|
|
|
case '\n':
|
2007-08-07 12:46:26 +00:00
|
|
|
buffer[i] = 0;
|
|
|
|
buffer_pos = pos + i +1 ;
|
2004-07-13 14:25:19 +00:00
|
|
|
|
2007-08-07 12:46:26 +00:00
|
|
|
if (found){
|
|
|
|
/* write to playlist */
|
|
|
|
rb->write(fdw, &buffer[line_end],
|
2004-07-13 14:25:19 +00:00
|
|
|
rb->strlen( &buffer[line_end] ));
|
2007-08-07 12:46:26 +00:00
|
|
|
rb->write(fdw, &crlf, 1);
|
|
|
|
|
|
|
|
found = false ;
|
|
|
|
results++ ;
|
|
|
|
}
|
|
|
|
line_end = i +1 ;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
default:
|
2007-08-07 12:46:26 +00:00
|
|
|
if (!found && tolower(buffer[i]) == tolower(search_string[0]))
|
2004-07-26 23:28:37 +00:00
|
|
|
found = strpcasecmp(&search_string[0],&buffer[i]) ;
|
2007-08-07 12:46:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-07-13 14:25:19 +00:00
|
|
|
}
|
2004-07-26 23:28:37 +00:00
|
|
|
DEBUGF("\n-------------------\n");
|
2004-07-13 14:25:19 +00:00
|
|
|
}
|
|
|
|
|
2007-08-07 12:46:26 +00:00
|
|
|
static void search_buffer(void){
|
2004-07-13 14:25:19 +00:00
|
|
|
buffer_pos = 0;
|
2007-08-07 12:46:26 +00:00
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
fill_buffer(0);
|
2007-08-07 12:46:26 +00:00
|
|
|
while ((buffer_pos+1) < file_size)
|
|
|
|
fill_buffer(buffer_pos);
|
|
|
|
}
|
|
|
|
|
2007-08-07 14:09:12 +00:00
|
|
|
static void clear_display(void){
|
2007-08-07 12:46:26 +00:00
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i){
|
|
|
|
rb->screens[i]->clear_display();
|
2004-07-13 14:25:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
static bool search_init(const char* file){
|
2004-07-26 23:28:37 +00:00
|
|
|
rb->memset(search_string, 0, sizeof(search_string));
|
2007-08-07 12:46:26 +00:00
|
|
|
|
|
|
|
if (!rb->kbd_input(search_string,sizeof search_string)){
|
|
|
|
clear_display();
|
|
|
|
rb->splash(0, "Searching...");
|
2009-12-20 12:59:25 +00:00
|
|
|
fd = rb->open_utf8(file, O_RDONLY);
|
2009-12-06 13:52:28 +00:00
|
|
|
if (fd < 0)
|
2004-07-13 14:25:19 +00:00
|
|
|
return false;
|
|
|
|
|
2009-12-20 12:59:25 +00:00
|
|
|
bomsize = rb->lseek(fd, 0, SEEK_CUR);
|
|
|
|
if (bomsize)
|
|
|
|
fdw = rb->open_utf8(resultfile, O_WRONLY|O_CREAT|O_TRUNC);
|
|
|
|
else
|
2010-05-06 17:35:13 +00:00
|
|
|
fdw = rb->open(resultfile, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
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
|
2009-12-06 13:52:28 +00:00
|
|
|
rb->close(fd);
|
2004-07-13 14:25:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-08-07 12:46:26 +00:00
|
|
|
|
2009-12-20 12:59:25 +00:00
|
|
|
file_size = rb->lseek(fd, 0, SEEK_END) - bomsize;
|
2004-07-13 14:25:19 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2007-08-07 12:46:26 +00:00
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the plugin entry point */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2004-07-13 14:25:19 +00:00
|
|
|
{
|
|
|
|
int ok;
|
2008-05-13 09:57:56 +00:00
|
|
|
const char *filename = parameter;
|
2004-07-13 14:25:19 +00:00
|
|
|
char *p;
|
2009-07-29 13:56:23 +00:00
|
|
|
if(!parameter) return PLUGIN_ERROR;
|
2004-07-13 14:25:19 +00:00
|
|
|
|
2007-03-17 09:54:28 +00:00
|
|
|
DEBUGF("%s - %s\n", (char *)parameter, &filename[rb->strlen(filename)-4]);
|
2004-07-13 14:25:19 +00:00
|
|
|
/* Check the extension. We only allow .m3u files. */
|
2009-12-06 13:52:28 +00:00
|
|
|
if (!(p = rb->strrchr(filename, '.')) ||
|
|
|
|
(rb->strcasecmp(p, ".m3u") && rb->strcasecmp(p, ".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);
|
2007-08-07 12:46:26 +00:00
|
|
|
|
2004-07-13 14:25:19 +00:00
|
|
|
p = rb->strrchr(path, '/');
|
|
|
|
if(p)
|
|
|
|
*p = 0;
|
|
|
|
|
2007-03-17 09:02:53 +00:00
|
|
|
rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path);
|
2004-07-13 14:25:19 +00:00
|
|
|
ok = search_init(parameter);
|
2007-08-07 12:46:26 +00:00
|
|
|
if (!ok)
|
|
|
|
return PLUGIN_ERROR;
|
2004-07-13 14:25:19 +00:00
|
|
|
search_buffer();
|
|
|
|
|
2007-08-07 12:46:26 +00:00
|
|
|
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);
|
2009-12-20 12:59:25 +00:00
|
|
|
rb->reload_directory();
|
2004-07-13 14:25:19 +00:00
|
|
|
|
2009-12-20 12:59:25 +00:00
|
|
|
return PLUGIN_OK;
|
2004-07-13 14:25:19 +00:00
|
|
|
}
|