summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Ferrare <kevin@rockbox.org>2007-08-07 12:46:26 +0000
committerKevin Ferrare <kevin@rockbox.org>2007-08-07 12:46:26 +0000
commit9dddf3ba234055b95bf6a85746817e9a5bc09da0 (patch)
tree8096389711e7b34de92a9741d3bbf49001ac44d8
parent9d66a2876fc5906479a952a965c088378cfd3cf3 (diff)
downloadrockbox-9dddf3ba234055b95bf6a85746817e9a5bc09da0.tar.gz
rockbox-9dddf3ba234055b95bf6a85746817e9a5bc09da0.zip
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
-rw-r--r--apps/plugins/search.c105
1 files changed, 51 insertions, 54 deletions
diff --git a/apps/plugins/search.c b/apps/plugins/search.c
index 1705998607..2a50828da3 100644
--- a/apps/plugins/search.c
+++ b/apps/plugins/search.c
@@ -42,22 +42,20 @@ static int line_end; /* Index of the end of line */
42char resultfile[MAX_PATH]; 42char resultfile[MAX_PATH];
43char path[MAX_PATH]; 43char path[MAX_PATH];
44 44
45static int strpcasecmp(const char *s1, const char *s2) 45static int strpcasecmp(const char *s1, const char *s2){
46{ 46 while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) {
47 while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) { 47 s1++;
48 s1++; 48 s2++;
49 s2++; 49 }
50 } 50
51 51 return (*s1 == '\0');
52 return (*s1 == '\0') ;
53} 52}
54 53
55static void fill_buffer(int pos) 54static void fill_buffer(int pos){
56{
57 int numread; 55 int numread;
58 int i; 56 int i;
59 int found = false ; 57 int found = false ;
60 const char crlf = '\n'; 58 const char crlf = '\n';
61 59
62 if (pos>=file_size-BUFFER_SIZE) 60 if (pos>=file_size-BUFFER_SIZE)
63 pos = file_size-BUFFER_SIZE; 61 pos = file_size-BUFFER_SIZE;
@@ -71,57 +69,57 @@ static void fill_buffer(int pos)
71 line_end = 0; 69 line_end = 0;
72 70
73 for(i=0;i<numread;i++) { 71 for(i=0;i<numread;i++) {
74 switch(buffer[i]) { 72 switch(buffer[i]) {
75 case '\r': 73 case '\r':
76 buffer[i] = ' '; 74 buffer[i] = ' ';
77 break; 75 break;
78 case '\n': 76 case '\n':
79 buffer[i] = 0; 77 buffer[i] = 0;
80 buffer_pos = pos + i +1 ; 78 buffer_pos = pos + i +1 ;
81 79
82 if (found) 80 if (found){
83 { 81 /* write to playlist */
84 /* write to playlist */ 82 rb->write(fdw, &buffer[line_end],
85 rb->write(fdw, &buffer[line_end],
86 rb->strlen( &buffer[line_end] )); 83 rb->strlen( &buffer[line_end] ));
87 rb->write(fdw, &crlf, 1); 84 rb->write(fdw, &crlf, 1);
88 85
89 found = false ; 86 found = false ;
90 results++ ; 87 results++ ;
91 } 88 }
92 line_end = i +1 ; 89 line_end = i +1 ;
93 90
94 break; 91 break;
95 92
96 default: 93 default:
97 if (!found && tolower(buffer[i]) == tolower(search_string[0])) 94 if (!found && tolower(buffer[i]) == tolower(search_string[0]))
98 {
99 found = strpcasecmp(&search_string[0],&buffer[i]) ; 95 found = strpcasecmp(&search_string[0],&buffer[i]) ;
100 } 96 break;
101 break; 97 }
102 }
103 } 98 }
104 DEBUGF("\n-------------------\n"); 99 DEBUGF("\n-------------------\n");
105} 100}
106 101
107static void search_buffer(void) 102static void search_buffer(void){
108{
109 buffer_pos = 0; 103 buffer_pos = 0;
110 104
111 fill_buffer(0); 105 fill_buffer(0);
112 while ((buffer_pos+1) < file_size) { 106 while ((buffer_pos+1) < file_size)
113 fill_buffer(buffer_pos); 107 fill_buffer(buffer_pos);
108}
109
110static void clear_display(){
111 int i;
112 FOR_NB_SCREENS(i){
113 rb->screens[i]->clear_display();
114 } 114 }
115} 115}
116 116
117static bool search_init(char* file) 117static bool search_init(char* file){
118{
119 rb->memset(search_string, 0, sizeof(search_string)); 118 rb->memset(search_string, 0, sizeof(search_string));
120 119
121 if (!rb->kbd_input(search_string,sizeof search_string)) 120 if (!rb->kbd_input(search_string,sizeof search_string)){
122 { 121 clear_display();
123 rb->lcd_clear_display(); 122 rb->splash(0, "Searching...");
124 rb->splash(0, "Searching...");
125 fd = rb->open(file, O_RDONLY); 123 fd = rb->open(file, O_RDONLY);
126 if (fd==-1) 124 if (fd==-1)
127 return false; 125 return false;
@@ -136,12 +134,12 @@ static bool search_init(char* file)
136#endif 134#endif
137 return false; 135 return false;
138 } 136 }
139 137
140 file_size = rb->lseek(fd, 0, SEEK_END); 138 file_size = rb->lseek(fd, 0, SEEK_END);
141 139
142 return true; 140 return true;
143 } 141 }
144 142
145 return false ; 143 return false ;
146} 144}
147 145
@@ -163,19 +161,18 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
163 } 161 }
164 162
165 rb->strcpy(path, filename); 163 rb->strcpy(path, filename);
166 164
167 p = rb->strrchr(path, '/'); 165 p = rb->strrchr(path, '/');
168 if(p) 166 if(p)
169 *p = 0; 167 *p = 0;
170 168
171 rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path); 169 rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path);
172 ok = search_init(parameter); 170 ok = search_init(parameter);
173 if (!ok) { 171 if (!ok)
174 return PLUGIN_ERROR; 172 return PLUGIN_ERROR;
175 }
176 search_buffer(); 173 search_buffer();
177 174
178 rb->lcd_clear_display(); 175 clear_display();
179 rb->splash(HZ, "Done"); 176 rb->splash(HZ, "Done");
180 rb->close(fdw); 177 rb->close(fdw);
181 rb->close(fd); 178 rb->close(fd);