1
0
Fork 0
forked from len0rd/rockbox

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:
Kevin Ferrare 2007-08-07 12:46:26 +00:00
parent 9d66a2876f
commit 9dddf3ba23

View file

@ -42,18 +42,16 @@ 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 ;
@ -71,56 +69,56 @@ 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)
@ -170,12 +168,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
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);