summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/SUBDIRS1
-rw-r--r--apps/plugins/databox/Makefile105
-rw-r--r--apps/plugins/databox/databox.c395
-rw-r--r--apps/plugins/databox/databox.h60
-rw-r--r--apps/plugins/databox/editparser.c205
-rw-r--r--apps/plugins/databox/editparser.h34
-rw-r--r--apps/plugins/databox/edittoken.c204
-rw-r--r--apps/plugins/databox/edittoken.h97
8 files changed, 0 insertions, 1101 deletions
diff --git a/apps/plugins/SUBDIRS b/apps/plugins/SUBDIRS
index 74e7fe36d8..c285a9e2d6 100644
--- a/apps/plugins/SUBDIRS
+++ b/apps/plugins/SUBDIRS
@@ -1,7 +1,6 @@
1#ifndef IRIVER_IFP7XX_SERIES 1#ifndef IRIVER_IFP7XX_SERIES
2 2
3/* For all targets */ 3/* For all targets */
4databox
5 4
6/* For various targets... */ 5/* For various targets... */
7#if (CONFIG_KEYPAD == RECORDER_PAD) || \ 6#if (CONFIG_KEYPAD == RECORDER_PAD) || \
diff --git a/apps/plugins/databox/Makefile b/apps/plugins/databox/Makefile
deleted file mode 100644
index 3e026757c4..0000000000
--- a/apps/plugins/databox/Makefile
+++ /dev/null
@@ -1,105 +0,0 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10INCLUDES = -I$(APPSDIR) -I.. -I. $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
11 -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR)
12CFLAGS = $(INCLUDES) $(GCCOPTS) -O3 $(TARGET) $(EXTRA_DEFINES) \
13 -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
14
15ifdef APPEXTRA
16 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
17endif
18
19LINKFILE := $(OBJDIR)/link.lds
20DEPFILE = $(OBJDIR)/dep-databox
21SRC = databox.c editparser.c edittoken.c
22
23SOURCES = $(SRC)
24OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
25DIRS = .
26
27LDS := ../plugin.lds
28OUTPUT = $(OUTDIR)/databox.rock
29
30all: $(OUTPUT)
31
32ifndef SIMVER
33$(OBJDIR)/databox.elf: $(OBJS) $(LINKFILE)
34 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $(OBJS) -L$(BUILDDIR) -lplugin -lgcc \
35 -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/databox.map
36
37$(OUTPUT): $(OBJDIR)/databox.elf
38 $(call PRINTS,OBJCOPY $(@F))$(OC) -O binary $< $@
39else
40
41ifeq ($(SIMVER), x11)
42###################################################
43# This is the X11 simulator version
44
45$(OUTPUT): $(OBJS)
46 $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin -o $@
47ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
48# 'x' must be kept or you'll have "Win32 error 5"
49# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
50# #define ERROR_ACCESS_DENIED 5L
51else
52 @chmod -x $@
53endif
54
55else # end of x11-simulator
56ifeq ($(SIMVER), sdl)
57###################################################
58# This is the SDL simulator version
59
60$(OUTPUT): $(OBJS)
61 $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin -o $@
62ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
63# 'x' must be kept or you'll have "Win32 error 5"
64# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
65# #define ERROR_ACCESS_DENIED 5L
66else
67 @chmod -x $@
68endif
69
70else # end of sdl-simulator
71###################################################
72# This is the win32 simulator version
73DLLTOOLFLAGS = --export-all
74DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin
75
76$(OUTPUT): $(OBJS)
77 $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $(OBJS)
78 $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $(OBJS) \
79 $(BUILDDIR)/libplugin.a -o $@
80ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN)
81# 'x' must be kept or you'll have "Win32 error 5"
82# $ fgrep 5 /usr/include/w32api/winerror.h | head -1
83# #define ERROR_ACCESS_DENIED 5L
84else
85 @chmod -x $@
86endif
87endif # end of win32-simulator
88endif
89endif # end of simulator section
90
91
92include $(TOOLSDIR)/make.inc
93
94# MEMORYSIZE should be passed on to this makefile with the chosen memory size
95# given in number of MB
96$(LINKFILE): $(LDS)
97 $(call PRINTS,build $(@F))cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) \
98 $(DEFINES) -E -P - >$@
99
100clean:
101 $(call PRINTS,cleaning databox)rm -rf $(OBJDIR)/databox
102 $(SILENT)rm -f $(OBJDIR)/databox.* $(DEPFILE)
103
104-include $(DEPFILE)
105
diff --git a/apps/plugins/databox/databox.c b/apps/plugins/databox/databox.c
deleted file mode 100644
index 25836a7f07..0000000000
--- a/apps/plugins/databox/databox.c
+++ /dev/null
@@ -1,395 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "databox.h"
20
21PLUGIN_HEADER
22
23/* variable button definitions */
24#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
25 (CONFIG_KEYPAD == IRIVER_H300_PAD)
26#define DBX_SELECT BUTTON_SELECT
27#define DBX_STOP BUTTON_OFF
28#elif CONFIG_KEYPAD == RECORDER_PAD
29#define DBX_SELECT BUTTON_PLAY
30#define DBX_STOP BUTTON_OFF
31#elif CONFIG_KEYPAD == ONDIO_PAD
32#define DBX_SELECT BUTTON_MENU
33#define DBX_STOP BUTTON_OFF
34#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
35 (CONFIG_KEYPAD == IPOD_3G_PAD)
36#define DBX_SELECT BUTTON_SELECT
37#define DBX_STOP BUTTON_MENU
38#elif CONFIG_KEYPAD == PLAYER_PAD
39#define DBX_SELECT BUTTON_PLAY
40#define DBX_STOP BUTTON_STOP
41#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
42#define DBX_SELECT BUTTON_SELECT
43#define DBX_STOP BUTTON_PLAY
44#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
45#define DBX_SELECT BUTTON_SELECT
46#define DBX_STOP BUTTON_PLAY
47#elif CONFIG_KEYPAD == GIGABEAT_PAD
48#define DBX_SELECT BUTTON_SELECT
49#define DBX_STOP BUTTON_A
50#elif CONFIG_KEYPAD == IRIVER_H10_PAD
51#define DBX_SELECT BUTTON_REW
52#define DBX_STOP BUTTON_PLAY
53#elif CONFIG_KEYPAD == SANSA_E200_PAD
54#define DBX_SELECT BUTTON_SELECT
55#define DBX_STOP BUTTON_POWER
56#endif
57
58#define MAX_TOKENS 70
59
60/* here is a global api struct pointer. while not strictly necessary,
61 it's nice not to have to pass the api pointer in all function calls
62 in the plugin */
63struct plugin_api* rb;
64struct token tokenbuf[MAX_TOKENS];
65
66struct print printing;
67struct editor editor;
68struct editing editing;
69
70extern int acceptedmask;
71
72void databox_init(void) {
73#ifdef HAVE_LCD_BITMAP
74 printing.fontfixed = rb->font_get(FONT_SYSFIXED);
75 rb->lcd_setfont(FONT_SYSFIXED);
76 printing.font_w = printing.fontfixed->maxwidth;
77 printing.font_h = printing.fontfixed->height;
78#endif
79 printing.line=0;
80 printing.position=0;
81 editor.editingmode = INVALID_MARK;
82 editor.token = tokenbuf;
83}
84
85#ifdef HAVE_LCD_BITMAP
86void print(char *word, int invert) {
87 int strlen=rb->strlen(word), newpos=printing.position+strlen+1;
88 if(newpos*printing.font_w>LCD_WIDTH) {
89 printing.line++;
90 printing.position=0;
91 newpos=printing.position+strlen+1;
92 }
93 /* Fixme: the display code needs to keep the current item visible instead of
94 * just displaying the first items. */
95 if (printing.font_h*printing.line >= LCD_HEIGHT)
96 return;
97 rb->lcd_putsxy(printing.font_w*printing.position,printing.font_h*printing.line,word);
98 if(invert) {
99 rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
100 rb->lcd_fillrect(printing.font_w*printing.position,printing.font_h*printing.line,printing.font_w*strlen,printing.font_h);
101 rb->lcd_set_drawmode(DRMODE_SOLID);
102 }
103 rb->lcd_update_rect(printing.font_w*printing.position,printing.font_h*printing.line,printing.font_w*strlen,printing.font_h);
104 printing.position=newpos;
105}
106#else /* HAVE_LCD_CHARCELLS */
107#define MARKER_LEFT 0x81
108#define MARKER_RIGHT 0x82
109void print(char *word, int invert) {
110 int strlen = rb->strlen(word);
111 int newpos = printing.position + strlen + (invert ? 3 : 1);
112 if (newpos > 11) {
113 printing.line++;
114 printing.position = 0;
115 newpos = printing.position + strlen + (invert ? 3 : 1);
116 }
117 /* Fixme: the display code needs to keep the current item visible instead of
118 * just displaying the first items. */
119 if (printing.line >= 2)
120 return;
121 if (invert) {
122 rb->lcd_putc(printing.position, printing.line, MARKER_LEFT);
123 rb->lcd_puts(printing.position + 1, printing.line, word);
124 rb->lcd_putc(printing.position + strlen + 1, printing.line, MARKER_RIGHT);
125 }
126 else
127 rb->lcd_puts(printing.position, printing.line, word);
128 printing.position = newpos;
129}
130#endif
131
132void displaytstream(struct token *token) {
133 int index=0;
134 while(token[index].kind!=TOKEN_EOF||index==editor.currentindex) {
135 if(editing.selecting&&index==editor.currentindex) {
136 print(tokentypetostring(editing.selection_candidates[editing.currentselection]),1);
137 }
138 else
139 print(tokentostring(&token[index]),index==editor.currentindex ? 1 : 0);
140 index++;
141 }
142}
143
144void buildchoices(int mask) {
145 int i;
146 for(i=0;i<20;i++)
147 editing.selection_candidates[i]=-1;
148 i=0;
149 if(editing.selecting&&
150 editing.old_token.kind!=TOKEN_EOF &&
151 editing.old_token.kind!=TOKEN_INVALID) {
152 editing.selection_candidates[i++]=TOKEN_EDIT;
153 }
154 if((mask&ACCEPT_EOF)&&editor.valid)
155 editing.selection_candidates[i++]=TOKEN_EOF;
156 if(mask&ACCEPT_NOT)
157 editing.selection_candidates[i++]=TOKEN_NOT;
158 if(mask&ACCEPT_BOOLOP) {
159 editing.selection_candidates[i++]=TOKEN_AND;
160 editing.selection_candidates[i++]=TOKEN_OR;
161 }
162 if(mask&ACCEPT_NUMOP) {
163 editing.selection_candidates[i++]=TOKEN_GT;
164 editing.selection_candidates[i++]=TOKEN_GTE;
165 editing.selection_candidates[i++]=TOKEN_LT;
166 editing.selection_candidates[i++]=TOKEN_LTE;
167 editing.selection_candidates[i++]=TOKEN_NE;
168 editing.selection_candidates[i++]=TOKEN_EQ;
169 }
170 if(mask&ACCEPT_STROP) {
171 editing.selection_candidates[i++]=TOKEN_CONTAINS;
172 editing.selection_candidates[i++]=TOKEN_EQUALS;
173 editing.selection_candidates[i++]=TOKEN_STARTSWITH;
174 editing.selection_candidates[i++]=TOKEN_ENDSWITH;
175 }
176 if(mask&ACCEPT_LPAREN) {
177 editing.selection_candidates[i++]=TOKEN_LPAREN;
178 }
179 if(mask&ACCEPT_RPAREN) {
180 editing.selection_candidates[i++]=TOKEN_RPAREN;
181 }
182 if(mask&ACCEPT_NUMARG) {
183 editing.selection_candidates[i++]=TOKEN_NUM;
184 editing.selection_candidates[i++]=TOKEN_YEAR;
185 editing.selection_candidates[i++]=TOKEN_RATING;
186 editing.selection_candidates[i++]=TOKEN_PLAYCOUNT;
187 editing.selection_candidates[i++]=TOKEN_AUTORATING;
188 editing.selection_candidates[i++]=TOKEN_TRACKNUM;
189 editing.selection_candidates[i++]=TOKEN_PLAYTIME;
190 editing.selection_candidates[i++]=TOKEN_SAMPLERATE;
191 editing.selection_candidates[i++]=TOKEN_BITRATE;
192 }
193 if(mask&ACCEPT_STRARG) {
194 editing.selection_candidates[i++]=TOKEN_STRING;
195 editing.selection_candidates[i++]=TOKEN_TITLE;
196 editing.selection_candidates[i++]=TOKEN_ARTIST;
197 editing.selection_candidates[i++]=TOKEN_ALBUM;
198 editing.selection_candidates[i++]=TOKEN_GENRE;
199 editing.selection_candidates[i++]=TOKEN_FILENAME;
200 }
201 editing.selectionmax=i;
202}
203
204/* returns tokencount or 0 if error */
205int readtstream(char *filename,struct token *token,int max) {
206 int tokencount=0;
207 int filelen,i;
208 int fd;
209 rb->memset(token,0,max*sizeof(struct token));
210 fd=rb->open(filename,O_RDONLY);
211 if(fd>=0) {
212 filelen=rb->filesize(fd);
213 if(filelen>0) {
214 if(filelen % sizeof(struct token)) {
215 rb->splash(HZ*2,true,"Filesize not a multiple of sizeof(struct token)");
216 rb->close(fd);
217 return 0;
218 }
219 tokencount=(filelen/sizeof(struct token))-1;
220 for(i=0;i<tokencount&&i<max;i++) {
221 rb->read(fd,&token[i],sizeof(struct token));
222 token[i].intvalue=BE32(token[i].intvalue);
223 }
224 }
225 rb->close(fd);
226 }
227 return tokencount;
228}
229
230int writetstream(char *filename,struct token *token) {
231 int fd,i;
232 fd=rb->open(filename,O_WRONLY|O_CREAT|O_TRUNC);
233 if(fd<0)
234 return 0;
235 i=0;
236 while(token[i].kind!=TOKEN_EOF) {
237 token[i].intvalue=BE32(token[i].intvalue);
238 rb->write(fd,&token[i++],sizeof(struct token));
239 }
240 token[i].intvalue=BE32(token[i].intvalue);
241 rb->write(fd,&token[i++],sizeof(struct token));
242 rb->close(fd);
243 return i;
244}
245
246/* this is the plugin entry point */
247enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
248{
249 int button,done=0,abort=0;
250 char filename[100],buf[100];
251 /* if you don't use the parameter, you can do like
252 this to avoid the compiler warning about it */
253 (void)parameter;
254
255 /* if you are using a global api pointer, don't forget to copy it!
256 otherwise you will get lovely "I04: IllInstr" errors... :-) */
257 rb = api;
258
259 /* now go ahead and have fun! */
260 rb->splash(HZ*2, true, "Databox! Enter filename ^.^");
261 databox_init();
262 filename[0] = '\0';
263 if(rb->kbd_input(filename, sizeof filename)) {
264 rb->splash(HZ*2, true, "Cancelled...");
265 return PLUGIN_OK;
266 }
267 /* add / in front if omitted */
268 if(filename[0]!='/') {
269 rb->strncpy(buf+1,filename,sizeof(filename)-1);
270 buf[0]='/';
271 rb->strcpy(filename,buf);
272 }
273 /* add extension if omitted */
274 if(rb->strncasecmp(filename+rb->strlen(filename)-4,".rsp",4)) {
275 rb->strcat(filename,".rsp");
276 }
277 editor.currentindex=editor.tokencount
278 =readtstream(filename,editor.token,MAX_TOKENS);
279 editing.currentselection=0;
280 editing.selecting=0;
281 if(editor.currentindex==0) {
282 editor.valid=check_tokenstream(editor.token,editor.editingmode);
283 check_accepted(editor.token,editor.currentindex);
284 editing.selecting=1;
285 buildchoices(acceptedmask);
286 rb->memset(&editing.old_token,0,sizeof(struct token));
287 }
288 do {
289#ifdef HAVE_LCD_BITMAP
290 rb->lcd_setfont(FONT_SYSFIXED);
291#endif
292 rb->lcd_clear_display();
293 printing.line=0;
294 printing.position=0;
295 displaytstream(editor.token);
296 editor.valid=check_tokenstream(editor.token,editor.editingmode);
297 check_accepted(editor.token,editor.currentindex);
298#ifdef HAVE_LCD_BITMAP
299 rb->lcd_update();
300#endif
301 button = rb->button_get(true);
302 switch (button) {
303 case BUTTON_LEFT:
304#ifdef BUTTON_DOWN
305 case BUTTON_DOWN:
306#endif
307 if (editing.selecting)
308 editing.currentselection = (editing.currentselection +
309 editing.selectionmax-1) % editing.selectionmax;
310 else
311 editor.currentindex = (editor.currentindex + editor.tokencount)
312 % (editor.tokencount+1);
313 break;
314
315 case BUTTON_RIGHT:
316#ifdef BUTTON_UP
317 case BUTTON_UP:
318#endif
319 if (editing.selecting)
320 editing.currentselection = (editing.currentselection+1)
321 % editing.selectionmax;
322 else
323 editor.currentindex = (editor.currentindex+1)
324 % (editor.tokencount+1);
325 break;
326
327 case DBX_SELECT:
328 if(editing.selecting) {
329 buildtoken(editing.selection_candidates[editing.currentselection],
330 &editor.token[editor.currentindex]);
331 editing.selecting=0;
332 if(editor.token[editor.currentindex].kind==TOKEN_EOF)
333 done=1;
334 else if(editor.currentindex==editor.tokencount) {
335 editor.tokencount++;
336 editor.currentindex++;
337 editor.valid=check_tokenstream(editor.token,editor.editingmode);
338 check_accepted(editor.token,editor.currentindex);
339 editing.selecting=1;
340 editing.currentselection=0;
341 buildchoices(acceptedmask);
342 rb->memcpy(&editing.old_token,&editor.token[editor.currentindex],
343 sizeof(struct token));
344 }
345 }
346 else {
347 editing.selecting=1;
348 editing.currentselection=0;
349 buildchoices(acceptedmask);
350 rb->memcpy(&editing.old_token,&editor.token[editor.currentindex],
351 sizeof(struct token));
352 }
353 break;
354
355 case DBX_STOP:
356 if(editing.selecting) {
357 rb->memcpy(&editor.token[editor.currentindex],&editing.old_token,
358 sizeof(struct token));
359 editing.selecting=0;
360 }
361 else
362 abort=1;
363 break;
364
365 default:
366 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
367#ifdef HAVE_LCD_BITMAP
368 rb->lcd_setfont(FONT_UI);
369#endif
370 return PLUGIN_USB_CONNECTED;
371 }
372 break;
373 }
374 } while (!done&&!abort);
375#ifdef HAVE_LCD_BITMAP
376 rb->lcd_setfont(FONT_UI);
377#endif
378 if(abort)
379 return PLUGIN_OK;
380
381 if(editor.valid&&editor.tokencount>0) {
382 if(writetstream(filename,editor.token)) {
383 rb->splash(HZ*2,true,"Wrote file succesfully ^.^");
384 return PLUGIN_OK;
385 }
386 else {
387 rb->splash(HZ*2,true,"Error while writing file :(");
388 return PLUGIN_ERROR;
389 }
390 }
391 else {
392 rb->splash(HZ*2,true,"Search query invalid, not saving.");
393 return PLUGIN_OK;
394 }
395}
diff --git a/apps/plugins/databox/databox.h b/apps/plugins/databox/databox.h
deleted file mode 100644
index 49f5891fb9..0000000000
--- a/apps/plugins/databox/databox.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Michiel van der Kolk
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef DATABOX_H
20#define DATABOX_H
21#include <stdio.h>
22#include <stdlib.h>
23#include <plugin.h>
24#include <database.h>
25
26#include "edittoken.h"
27#include "editparser.h"
28
29extern struct plugin_api* rb;
30
31struct print {
32#ifdef HAVE_LCD_BITMAP
33 struct font *fontfixed;
34 int font_w,font_h;
35#endif
36 int line;
37 int position;
38};
39
40struct editor {
41 struct token *token; /* tokenstream */
42 int currentindex; /* index of the token to change.(+1, 1=0 2=1 3=2 etc.) */
43 int tokencount; /* total amount of tokens */
44 int editingmode; /* defined in databox.h */
45 int valid; /* is the current tokenstream valid ? */
46};
47
48struct editing {
49 int selection_candidates[30]; /* possible options for this selecting */
50 struct token old_token; /* only set when selecting, stores old token */
51 int currentselection; /* current selection index */
52 int selectionmax;
53 int selecting; /* boolean */
54};
55
56extern struct print printing;
57extern struct editor editor;
58extern struct editing editing;
59
60#endif
diff --git a/apps/plugins/databox/editparser.c b/apps/plugins/databox/editparser.c
deleted file mode 100644
index 5ee9ffbd56..0000000000
--- a/apps/plugins/databox/editparser.c
+++ /dev/null
@@ -1,205 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Michiel van der Kolk
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "databox.h"
20#include "edittoken.h"
21#include "editparser.h"
22
23struct token *currenttoken,*lasttoken,*tokenstream;
24int currentindex;
25int lparencount,acceptedmask;
26int tokensleft;
27int invalid;
28int invalid_mode;
29
30void check_accepted(struct token *tstream, int count) {
31 parse_stream(tstream,count+1,INVALID_EXPERT);
32}
33
34void parse_stream(struct token *tstream, int count, int inv_mode) {
35 invalid_mode=inv_mode;
36 acceptedmask=0;
37 lparencount=0;
38 tokensleft=count;
39 currentindex=0;
40 invalid=0;
41 tokenstream=tstream;
42 currenttoken=&tokenstream[currentindex];
43 parseMExpr();
44}
45
46int check_tokenstream(struct token *tstream, int inv_mode) {
47 int inval=0;
48 int i;
49 parse_stream(tstream,-1,inv_mode);
50 inval=invalid;
51 while( (inv_mode==INVALID_STRIP||inv_mode==INVALID_MARK) && invalid)
52 parse_stream(tstream,-1,inv_mode);
53 i=0;
54 while(tstream[i].kind!=TOKEN_EOF)
55 if(tstream[i++].kind==TOKEN_INVALID) {
56 inval=1;
57 break;
58 }
59 return inval==0;
60}
61
62
63void parse_accept_rparen(void) {
64 if(!tokensleft) return;
65 if(lparencount) {
66 acceptedmask|=ACCEPT_RPAREN;
67 }
68}
69
70void parse_accept(int bitmask) {
71 if(!tokensleft) return;
72 acceptedmask|=bitmask;
73 if(lparencount) {
74 acceptedmask&=~ACCEPT_EOF;
75 }
76}
77
78void parse_checktoken() {
79 int ok=0;
80 if(!tokensleft) return;
81 lasttoken=currenttoken;
82 switch(lasttoken->kind) {
83 case TOKEN_EOF:
84 ok=acceptedmask&ACCEPT_EOF;
85 break;
86 case TOKEN_NOT:
87 ok=acceptedmask&ACCEPT_NOT;
88 break;
89 case TOKEN_AND:
90 case TOKEN_OR:
91 ok=acceptedmask&ACCEPT_BOOLOP;
92 break;
93 case TOKEN_GT:
94 case TOKEN_GTE:
95 case TOKEN_LT:
96 case TOKEN_LTE:
97 case TOKEN_NE:
98 case TOKEN_EQ:
99 ok=acceptedmask&ACCEPT_NUMOP;
100 break;
101 case TOKEN_EQUALS:
102 case TOKEN_CONTAINS:
103 case TOKEN_STARTSWITH:
104 case TOKEN_ENDSWITH:
105 ok=acceptedmask&ACCEPT_STROP;
106 break;
107 case TOKEN_STRING:
108 case TOKEN_STRINGIDENTIFIER:
109 ok=acceptedmask&ACCEPT_STRARG;
110 break;
111 case TOKEN_NUM:
112 case TOKEN_NUMIDENTIFIER:
113 ok=acceptedmask&ACCEPT_NUMARG;
114 break;
115 case TOKEN_LPAREN:
116 ok=acceptedmask&ACCEPT_LPAREN;
117 if(ok) lparencount++;
118 break;
119 case TOKEN_RPAREN:
120 ok=acceptedmask&ACCEPT_RPAREN;
121 if(ok) lparencount--;
122 break;
123 case TOKEN_INVALID:
124 if(invalid_mode!=INVALID_STRIP)
125 ok=1;
126 break;
127 }
128 tokensleft--;
129 if(lasttoken->kind==TOKEN_EOF)
130 tokensleft=0;
131 if(!ok&&tokensleft) {
132 // delete token
133 int i=currentindex;
134 //printf("Syntax error. accepted: 0x%x index:%d token: %d %s\n",acceptedmask,currentindex,currenttoken->kind,tokentostring(currenttoken));
135 switch (invalid_mode) {
136 case INVALID_STRIP:
137 do {
138 rb->memcpy(currenttoken,&tokenstream[++i],sizeof(struct token));;
139 currenttoken=&tokenstream[i];
140 } while (currenttoken->kind!=TOKEN_EOF);
141 currenttoken=&tokenstream[currentindex];
142 break;
143 case INVALID_MARK:
144 currenttoken->kind=TOKEN_INVALID;
145 break;
146 }
147 tokensleft=0;
148 invalid=1;
149 }
150 if(tokensleft) {
151 currenttoken=&tokenstream[++currentindex];
152 acceptedmask=0;
153 }
154}
155
156void parseCompareNum() {
157 parse_accept(ACCEPT_NUMOP);
158 parse_checktoken();
159 parse_accept(ACCEPT_NUMARG);
160 parse_checktoken();
161}
162
163void parseCompareString() {
164 parse_accept(ACCEPT_STROP);
165 parse_checktoken();
166 parse_accept(ACCEPT_STRARG);
167 parse_checktoken();
168}
169
170void parseExpr() {
171 if(!tokensleft) return;
172 parse_accept(ACCEPT_NOT|ACCEPT_LPAREN|ACCEPT_NUMARG|ACCEPT_STRARG);
173 parse_checktoken();
174 switch(lasttoken->kind) {
175 case TOKEN_NOT:
176 parseExpr();
177 break;
178 case TOKEN_LPAREN:
179 parseMExpr();
180 break;
181 case TOKEN_NUM:
182 case TOKEN_NUMIDENTIFIER:
183 parseCompareNum();
184 break;
185 case TOKEN_STRING:
186 case TOKEN_STRINGIDENTIFIER:
187 parseCompareString();
188 break;
189 }
190}
191
192void parseMExpr() {
193 parseExpr();
194 parse_accept_rparen();
195 parse_accept(ACCEPT_BOOLOP|ACCEPT_EOF);
196 parse_checktoken();
197 while(lasttoken->kind==TOKEN_OR || lasttoken->kind == TOKEN_AND) {
198 parseExpr();
199 parse_accept_rparen();
200 parse_accept(ACCEPT_BOOLOP|ACCEPT_EOF);
201 parse_checktoken();
202 if(!tokensleft)
203 return;
204 }
205}
diff --git a/apps/plugins/databox/editparser.h b/apps/plugins/databox/editparser.h
deleted file mode 100644
index 3a26cbca70..0000000000
--- a/apps/plugins/databox/editparser.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Michiel van der Kolk
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19extern int acceptedmask;
20
21#define INVALID_STRIP 1
22#define INVALID_MARK 2
23#define INVALID_EXPERT 3
24
25void check_accepted(struct token *tstream, int count);
26void parse_stream(struct token *tstream, int count, int inv_mode);
27int check_tokenstream(struct token *tstream, int inv_mode);
28void parser_accept_rparen(void);
29void parser_accept(int bitmask);
30void parse_checktoken(void);
31void parseCompareNum(void);
32void parseCompareString(void);
33void parseExpr(void);
34void parseMExpr(void);
diff --git a/apps/plugins/databox/edittoken.c b/apps/plugins/databox/edittoken.c
deleted file mode 100644
index e2e1c91818..0000000000
--- a/apps/plugins/databox/edittoken.c
+++ /dev/null
@@ -1,204 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Michiel van der Kolk
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "databox.h"
20#include "edittoken.h"
21
22char *tokentypetostring(int tokentype) {
23 switch(tokentype) {
24 case TOKEN_EOF: return "<END>";
25 case TOKEN_NOT: return "not";
26 case TOKEN_AND: return "and";
27 case TOKEN_OR: return "or";
28 case TOKEN_GT: return ">";
29 case TOKEN_GTE: return ">=";
30 case TOKEN_LT: return "<";
31 case TOKEN_LTE: return "<=";
32 case TOKEN_EQ: return "==";
33 case TOKEN_NE: return "!=";
34 case TOKEN_LPAREN: return "(";
35 case TOKEN_RPAREN: return ")";
36 case TOKEN_CONTAINS: return "contains";
37 case TOKEN_EQUALS: return "equals";
38 case TOKEN_STARTSWITH: return "starts with";
39 case TOKEN_ENDSWITH: return "ends with";
40 case TOKEN_NUM: return "<number>";
41 case TOKEN_NUMIDENTIFIER: return "<numberproperty>";
42 case TOKEN_STRING: return "<string>";
43 case TOKEN_STRINGIDENTIFIER: return "<stringproperty>";
44 case TOKEN_INVALID: return "<INVALID>";
45 case TOKEN_EDIT: return tokentostring(&editing.old_token);
46 case TOKEN_YEAR: return "year";
47 case TOKEN_RATING: return "rating";
48 case TOKEN_PLAYCOUNT: return "playcount";
49 case TOKEN_AUTORATING: return "autorating";
50 case TOKEN_TITLE: return "title";
51 case TOKEN_ARTIST: return "artist";
52 case TOKEN_ALBUM: return "album";
53 case TOKEN_GENRE: return "genre";
54 case TOKEN_FILENAME: return "filename";
55 case TOKEN_PLAYTIME: return "playtime";
56 case TOKEN_TRACKNUM: return "track number";
57 case TOKEN_SAMPLERATE: return "sample rate";
58 case TOKEN_BITRATE: return "bitrate";
59 }
60 return "tokentypeerror";
61}
62
63char *numidtostring(int numid) {
64 switch(numid) {
65 case INTVALUE_YEAR: return "<year>";
66 case INTVALUE_RATING: return "<rating>";
67 case INTVALUE_PLAYCOUNT: return "<playcount>";
68 case INTVALUE_AUTORATING: return "<autorating>";
69 case INTVALUE_PLAYTIME: return "<playtime>";
70 case INTVALUE_TRACKNUM: return "<track number>";
71 case INTVALUE_SAMPLERATE: return "<sample rate>";
72 case INTVALUE_BITRATE: return "<bitrate>";
73 }
74 return "numiderror";
75}
76
77char *stridtostring(int strid) {
78 switch(strid) {
79 case INTVALUE_TITLE: return "<title>";
80 case INTVALUE_ARTIST: return "<artist>";
81 case INTVALUE_ALBUM: return "<album>";
82 case INTVALUE_GENRE: return "<genre>";
83 case INTVALUE_FILENAME: return "<filename>";
84 }
85 return "striderror";
86}
87
88char bufbla[40];
89
90void buildtoken(int tokentype,struct token *token) {
91 // TODO
92 char buf[200];
93 rb->memset(token,0,sizeof(struct token));
94 rb->memset(buf,0,200);
95 token->kind=tokentype;
96 token->intvalue=0;
97 switch(token->kind) {
98 case TOKEN_STRING:
99 do {
100 rb->splash(HZ*2,true,"Enter String.");
101 } while(rb->kbd_input(token->spelling, SPELLING_LENGTH));
102 break;
103 case TOKEN_YEAR:
104 token->kind=TOKEN_NUMIDENTIFIER;
105 token->intvalue=INTVALUE_YEAR;
106 break;
107 case TOKEN_RATING:
108 token->kind=TOKEN_NUMIDENTIFIER;
109 token->intvalue=INTVALUE_RATING;
110 break;
111 case TOKEN_PLAYCOUNT:
112 token->kind=TOKEN_NUMIDENTIFIER;
113 token->intvalue=INTVALUE_PLAYCOUNT;
114 break;
115 case TOKEN_AUTORATING:
116 token->kind=TOKEN_NUMIDENTIFIER;
117 token->intvalue=INTVALUE_AUTORATING;
118 break;
119 case TOKEN_TITLE:
120 token->kind=TOKEN_STRINGIDENTIFIER;
121 token->intvalue=INTVALUE_TITLE;
122 break;
123 case TOKEN_ARTIST:
124 token->kind=TOKEN_STRINGIDENTIFIER;
125 token->intvalue=INTVALUE_ARTIST;
126 break;
127 case TOKEN_ALBUM:
128 token->kind=TOKEN_STRINGIDENTIFIER;
129 token->intvalue=INTVALUE_ALBUM;
130 break;
131 case TOKEN_GENRE:
132 token->kind=TOKEN_STRINGIDENTIFIER;
133 token->intvalue=INTVALUE_GENRE;
134 break;
135 case TOKEN_FILENAME:
136 token->kind=TOKEN_STRINGIDENTIFIER;
137 token->intvalue=INTVALUE_TITLE;
138 break;
139 case TOKEN_NUM:
140 do {
141 rb->splash(HZ*2,true,"Enter Number.");
142 } while(rb->kbd_input(buf, 199));
143 token->intvalue=rb->atoi(buf);
144 break;
145 case TOKEN_EDIT:
146 rb->memcpy(token,&editing.old_token,sizeof(struct token));
147 break;
148 }
149}
150
151void removetoken(struct token *token,int index) {
152 struct token *currenttoken;
153 currenttoken=&token[index];
154 do {
155 rb->memcpy(currenttoken,&token[++index],sizeof(struct token));
156 currenttoken=&token[index];
157 } while (currenttoken->kind!=TOKEN_EOF);
158}
159
160void inserttoken(struct token *token,int index,int tokentype) {
161 struct token *currenttoken;
162 int max,i;
163 currenttoken=&token[0];
164 for(i=1;currenttoken->kind!=TOKEN_EOF;i++)
165 currenttoken=&token[i];
166 max=i;
167 for(i=max;i>=index;i--) {
168 rb->memcpy(&token[i+1],&token[i],sizeof(struct token));
169 }
170 buildtoken(tokentype,&token[index]);
171}
172
173
174char *tokentostring(struct token *token) {
175 switch(token->kind) {
176 case TOKEN_INVALID:
177 case TOKEN_EOF:
178 case TOKEN_NOT:
179 case TOKEN_AND:
180 case TOKEN_OR:
181 case TOKEN_GT:
182 case TOKEN_GTE:
183 case TOKEN_LT:
184 case TOKEN_LTE:
185 case TOKEN_EQ:
186 case TOKEN_NE:
187 case TOKEN_LPAREN:
188 case TOKEN_RPAREN:
189 case TOKEN_CONTAINS:
190 case TOKEN_EQUALS:
191 case TOKEN_STARTSWITH:
192 case TOKEN_ENDSWITH:
193 return tokentypetostring(token->kind);
194 case TOKEN_NUM: rb->snprintf(bufbla,40,"%d",token->intvalue);
195 return bufbla;
196 case TOKEN_NUMIDENTIFIER:
197 return numidtostring(token->intvalue);
198 case TOKEN_STRING: return token->spelling;
199 case TOKEN_STRINGIDENTIFIER:
200 return stridtostring(token->intvalue);
201 case TOKEN_EDIT: return tokentostring(&editing.old_token);
202 default: return "unknown token";
203 }
204}
diff --git a/apps/plugins/databox/edittoken.h b/apps/plugins/databox/edittoken.h
deleted file mode 100644
index c1a33355a8..0000000000
--- a/apps/plugins/databox/edittoken.h
+++ /dev/null
@@ -1,97 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Michiel van der Kolk
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef EDITTOKEN_H
20#define EDITTOKEN_H
21
22#define TOKEN_INVALID -1
23#define TOKEN_EOF 0 // EOF
24#define TOKEN_NOT 1 // "not"
25#define TOKEN_AND 2 // "and"
26#define TOKEN_OR 3 // "or"
27#define TOKEN_GT 4 // '>'
28#define TOKEN_GTE 5 // '>='
29#define TOKEN_LT 6 // '<'
30#define TOKEN_LTE 7 // '<='
31#define TOKEN_EQ 8 // '=='
32#define TOKEN_NE 9 // '!='
33#define TOKEN_CONTAINS 10 // "contains"
34#define TOKEN_EQUALS 11 // "equals"
35#define TOKEN_STARTSWITH 12
36#define TOKEN_ENDSWITH 13
37#define TOKEN_LPAREN 14 // '('
38#define TOKEN_RPAREN 15 // ')'
39#define TOKEN_NUM 16 // (0..9)+
40#define TOKEN_NUMIDENTIFIER 17 // year, trackid, bpm, etc.
41#define TOKEN_STRING 18 // (?)+
42#define TOKEN_STRINGIDENTIFIER 19 // album, artist, title, genre ...
43#define TOKEN_SHUFFLE 20
44#define TOKEN_PLAYTIMELIMIT 21
45
46// pseudotokens..
47#define TOKEN_YEAR 118
48#define TOKEN_RATING 119
49#define TOKEN_PLAYCOUNT 120
50#define TOKEN_TITLE 121
51#define TOKEN_ARTIST 122
52#define TOKEN_ALBUM 123
53#define TOKEN_GENRE 124
54#define TOKEN_FILENAME 125
55#define TOKEN_EDIT 126
56#define TOKEN_AUTORATING 127
57#define TOKEN_PLAYTIME 128
58#define TOKEN_TRACKNUM 129
59#define TOKEN_SAMPLERATE 130
60#define TOKEN_BITRATE 131
61
62#define ACCEPT_EOF 0x1
63#define ACCEPT_BOOLOP 0x2
64#define ACCEPT_NUMOP 0x4
65#define ACCEPT_STROP 0x8
66#define ACCEPT_LPAREN 0x10
67#define ACCEPT_RPAREN 0x20
68#define ACCEPT_NUMARG 0x40
69#define ACCEPT_STRARG 0x80
70#define ACCEPT_NOT 0x100
71#define ACCEPT_DELETE 0x200
72
73#define INTVALUE_YEAR 1
74#define INTVALUE_RATING 2
75#define INTVALUE_PLAYCOUNT 3
76#define INTVALUE_AUTORATING 4
77#define INTVALUE_PLAYTIME 5
78#define INTVALUE_TRACKNUM 6
79#define INTVALUE_SAMPLERATE 7
80#define INTVALUE_BITRATE 8
81#define INTVALUE_TITLE 14
82#define INTVALUE_ARTIST 15
83#define INTVALUE_ALBUM 16
84#define INTVALUE_GENRE 17
85#define INTVALUE_FILENAME 18
86
87#define SPELLING_LENGTH 100
88
89struct token {
90 signed char kind;
91 char spelling[SPELLING_LENGTH + 3];
92 long intvalue;
93};
94char *tokentypetostring(int tokentype);
95char *tokentostring(struct token *token);
96void buildtoken(int tokentype,struct token *token);
97#endif