Search viewer (plugin) : reindent correctly with spaces, add multiscreen support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14230 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9d66a2876f
commit
9dddf3ba23
1 changed files with 51 additions and 54 deletions
|
@ -42,22 +42,20 @@ static int line_end; /* Index of the end of line */
|
||||||
char resultfile[MAX_PATH];
|
char resultfile[MAX_PATH];
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
|
|
||||||
static int strpcasecmp(const char *s1, const char *s2)
|
static int strpcasecmp(const char *s1, const char *s2){
|
||||||
{
|
while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) {
|
||||||
while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) {
|
s1++;
|
||||||
s1++;
|
s2++;
|
||||||
s2++;
|
}
|
||||||
}
|
|
||||||
|
return (*s1 == '\0');
|
||||||
return (*s1 == '\0') ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fill_buffer(int pos)
|
static void fill_buffer(int pos){
|
||||||
{
|
|
||||||
int numread;
|
int numread;
|
||||||
int i;
|
int i;
|
||||||
int found = false ;
|
int found = false ;
|
||||||
const char crlf = '\n';
|
const char crlf = '\n';
|
||||||
|
|
||||||
if (pos>=file_size-BUFFER_SIZE)
|
if (pos>=file_size-BUFFER_SIZE)
|
||||||
pos = file_size-BUFFER_SIZE;
|
pos = file_size-BUFFER_SIZE;
|
||||||
|
@ -71,57 +69,57 @@ static void fill_buffer(int pos)
|
||||||
line_end = 0;
|
line_end = 0;
|
||||||
|
|
||||||
for(i=0;i<numread;i++) {
|
for(i=0;i<numread;i++) {
|
||||||
switch(buffer[i]) {
|
switch(buffer[i]) {
|
||||||
case '\r':
|
case '\r':
|
||||||
buffer[i] = ' ';
|
buffer[i] = ' ';
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
buffer[i] = 0;
|
buffer[i] = 0;
|
||||||
buffer_pos = pos + i +1 ;
|
buffer_pos = pos + i +1 ;
|
||||||
|
|
||||||
if (found)
|
if (found){
|
||||||
{
|
/* write to playlist */
|
||||||
/* write to playlist */
|
rb->write(fdw, &buffer[line_end],
|
||||||
rb->write(fdw, &buffer[line_end],
|
|
||||||
rb->strlen( &buffer[line_end] ));
|
rb->strlen( &buffer[line_end] ));
|
||||||
rb->write(fdw, &crlf, 1);
|
rb->write(fdw, &crlf, 1);
|
||||||
|
|
||||||
found = false ;
|
found = false ;
|
||||||
results++ ;
|
results++ ;
|
||||||
}
|
}
|
||||||
line_end = i +1 ;
|
line_end = i +1 ;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!found && tolower(buffer[i]) == tolower(search_string[0]))
|
if (!found && tolower(buffer[i]) == tolower(search_string[0]))
|
||||||
{
|
|
||||||
found = strpcasecmp(&search_string[0],&buffer[i]) ;
|
found = strpcasecmp(&search_string[0],&buffer[i]) ;
|
||||||
}
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DEBUGF("\n-------------------\n");
|
DEBUGF("\n-------------------\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void search_buffer(void)
|
static void search_buffer(void){
|
||||||
{
|
|
||||||
buffer_pos = 0;
|
buffer_pos = 0;
|
||||||
|
|
||||||
fill_buffer(0);
|
fill_buffer(0);
|
||||||
while ((buffer_pos+1) < file_size) {
|
while ((buffer_pos+1) < file_size)
|
||||||
fill_buffer(buffer_pos);
|
fill_buffer(buffer_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clear_display(){
|
||||||
|
int i;
|
||||||
|
FOR_NB_SCREENS(i){
|
||||||
|
rb->screens[i]->clear_display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool search_init(char* file)
|
static bool search_init(char* file){
|
||||||
{
|
|
||||||
rb->memset(search_string, 0, sizeof(search_string));
|
rb->memset(search_string, 0, sizeof(search_string));
|
||||||
|
|
||||||
if (!rb->kbd_input(search_string,sizeof search_string))
|
if (!rb->kbd_input(search_string,sizeof search_string)){
|
||||||
{
|
clear_display();
|
||||||
rb->lcd_clear_display();
|
rb->splash(0, "Searching...");
|
||||||
rb->splash(0, "Searching...");
|
|
||||||
fd = rb->open(file, O_RDONLY);
|
fd = rb->open(file, O_RDONLY);
|
||||||
if (fd==-1)
|
if (fd==-1)
|
||||||
return false;
|
return false;
|
||||||
|
@ -136,12 +134,12 @@ static bool search_init(char* file)
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size = rb->lseek(fd, 0, SEEK_END);
|
file_size = rb->lseek(fd, 0, SEEK_END);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,19 +161,18 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->strcpy(path, filename);
|
rb->strcpy(path, filename);
|
||||||
|
|
||||||
p = rb->strrchr(path, '/');
|
p = rb->strrchr(path, '/');
|
||||||
if(p)
|
if(p)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path);
|
rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path);
|
||||||
ok = search_init(parameter);
|
ok = search_init(parameter);
|
||||||
if (!ok) {
|
if (!ok)
|
||||||
return PLUGIN_ERROR;
|
return PLUGIN_ERROR;
|
||||||
}
|
|
||||||
search_buffer();
|
search_buffer();
|
||||||
|
|
||||||
rb->lcd_clear_display();
|
clear_display();
|
||||||
rb->splash(HZ, "Done");
|
rb->splash(HZ, "Done");
|
||||||
rb->close(fdw);
|
rb->close(fdw);
|
||||||
rb->close(fd);
|
rb->close(fd);
|
||||||
|
|
Loading…
Reference in a new issue