summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/search.c180
-rw-r--r--apps/plugins/viewers.config1
2 files changed, 181 insertions, 0 deletions
diff --git a/apps/plugins/search.c b/apps/plugins/search.c
new file mode 100644
index 0000000000..611a48e0bc
--- /dev/null
+++ b/apps/plugins/search.c
@@ -0,0 +1,180 @@
1/***************************************************************************
2 *
3 * __________ __ ___.
4 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
5 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/
9 * $Id$
10 *
11 * Copyright (C) 2003 Stefan Meyer
12 *
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include "plugin.h"
21#include "ctype.h"
22
23static struct plugin_api* rb;
24
25#define BUFFER_SIZE 16384
26
27static int fd;
28static int fdw;
29
30static int file_size;
31static int results = 0;
32
33static char buffer[BUFFER_SIZE+1];
34static char search_string[60] ;
35
36static int buffer_pos; /* Position of the buffer in the file */
37
38static int line_end; /* Index of the end of line */
39
40char resultfile[MAX_PATH];
41char path[MAX_PATH];
42
43static int strpcasecmp(const char *s1, const char *s2)
44{
45 while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) {
46 s1++;
47 s2++;
48 }
49
50 return (*s1 == '\0') ;
51}
52
53static void fill_buffer(int pos)
54{
55 int numread;
56 int i;
57 int found = false ;
58 char crlf[2] = "\n\0";
59
60 if (pos>=file_size-BUFFER_SIZE)
61 pos = file_size-BUFFER_SIZE;
62 if (pos<0)
63 pos = 0;
64
65 rb->lseek(fd, pos, SEEK_SET);
66 numread = rb->read(fd, buffer, BUFFER_SIZE);
67
68 buffer[numread] = 0;
69 line_end = 0;
70
71 for(i=0;i<numread;i++) {
72 switch(buffer[i]) {
73 case '\r':
74 buffer[i] = ' ';
75 break;
76 case '\n':
77 buffer[i] = 0;
78 buffer_pos = pos + i +1 ;
79
80 if (found)
81 {
82 /* write to playlist */
83 rb->write(fdw, &buffer[line_end],
84 rb->strlen( &buffer[line_end] ));
85 rb->write(fdw, &crlf,1);
86
87 found = false ;
88 results++ ;
89 }
90 line_end = i +1 ;
91
92 break;
93
94 default:
95 if (!found && tolower(buffer[i]) == tolower(search_string[0]))
96 {
97 found = strpcasecmp(&search_string[0],&buffer[i]) ;
98 }
99 break;
100 }
101 }
102}
103
104static void search_buffer(void)
105{
106 buffer_pos = 0;
107
108 fill_buffer(0);
109 while ((buffer_pos+1) < file_size) {
110 fill_buffer(buffer_pos);
111 }
112}
113
114static bool search_init(char* file)
115{
116 if (!rb->kbd_input(search_string,sizeof search_string))
117 {
118 rb->lcd_clear_display();
119 rb->splash(0, true, "Searching...");
120 fd = rb->open(file, O_RDONLY);
121 if (fd==-1)
122 return false;
123
124 fdw = rb->creat(resultfile,0);
125
126 if (fdw < 0) {
127#ifdef HAVE_LCD_BITMAP
128 rb->splash(HZ, true, "Failed to create result file!");
129#else
130 rb->splash(HZ, true, "File creation failed");
131#endif
132 return false;
133 }
134
135 file_size = rb->lseek(fd, 0, SEEK_END);
136
137 return true;
138 }
139
140 return false ;
141}
142
143/* this is the plugin entry point */
144enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
145{
146 int ok;
147 char *filename = parameter;
148 char *p;
149
150 TEST_PLUGIN_API(api);
151
152 rb = api;
153
154 /* Check the extension. We only allow .m3u files. */
155 if(!strpcasecmp(&filename[rb->strlen(filename)-4], ".m3u")) {
156 rb->splash(HZ, true, "Not a .m3u file");
157 return PLUGIN_ERROR;
158 }
159
160 rb->strcpy(path, filename);
161
162 p = rb->strrchr(path, '/');
163 if(p)
164 *p = 0;
165
166 rb->snprintf(resultfile, MAX_PATH, "%s/search_result.m3u", path, p+1);
167 ok = search_init(parameter);
168 if (!ok) {
169 return PLUGIN_ERROR;
170 }
171 search_buffer();
172
173 rb->lcd_clear_display();
174 rb->splash(HZ, true, "Done");
175 rb->close(fdw);
176 rb->close(fd);
177
178 /* We fake a USB connection to force a reload of the file browser */
179 return PLUGIN_USB_CONNECTED;
180}
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config
index 2acbe17af3..2b1d52766b 100644
--- a/apps/plugins/viewers.config
+++ b/apps/plugins/viewers.config
@@ -4,3 +4,4 @@ jpg,jpeg.rock,18 24 3C 3C 24 18
4ucl,rockbox_flash.rock,2A 7F 41 41 7F 2A 4ucl,rockbox_flash.rock,2A 7F 41 41 7F 2A
5rvf,video.rock,5D 7F 5D 7F 5D 7F 5rvf,video.rock,5D 7F 5D 7F 5D 7F
6mp3,vbrfix.rock,10 08 58 38 04 02 6mp3,vbrfix.rock,10 08 58 38 04 02
7m3u,search.rock,00 00 00 00 00 00