General housekeeping: Make plugin buffer functions take size_t * instead of int ...
[Rockbox.git] / apps / plugins / searchengine / searchengine.c
blob62d3a91fa70ee1dba14100fc263a87a79e7cf486
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Michiel van der Kolk
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "searchengine.h"
20 #include "parser.h"
21 #include "token.h"
22 #include "dbinterface.h"
24 PLUGIN_HEADER
26 void *audio_bufferbase;
27 void *audio_bufferpointer;
28 size_t audio_buffer_free;
29 struct plugin_api* rb;
30 int w, h, y;
32 void *my_malloc(size_t size)
34 void *alloc;
36 if (!audio_bufferbase)
38 audio_bufferbase = audio_bufferpointer
39 = rb->plugin_get_audio_buffer(&audio_buffer_free);
40 audio_bufferpointer+=3;
41 audio_bufferpointer=(void *)(((long)audio_bufferpointer)&~3);
42 audio_buffer_free-=audio_bufferpointer-audio_bufferbase;
44 if (size + 4 > audio_buffer_free)
45 return 0;
46 alloc = audio_bufferpointer;
47 audio_bufferpointer +=(size+3)&~3; // alignment
48 audio_buffer_free -= (size+3)&~3;
49 return alloc;
52 void setmallocpos(void *pointer)
54 audio_bufferpointer = pointer;
55 audio_buffer_free = audio_bufferpointer - audio_bufferbase;
58 /* this is the plugin entry point */
59 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
61 unsigned char *result,buf[500];
62 int parsefd,hits;
63 /* if you are using a global api pointer, don't forget to copy it!
64 otherwise you will get lovely "I04: IllInstr" errors... :-) */
65 rb = api;
67 audio_bufferbase=audio_bufferpointer=0;
68 audio_buffer_free=0;
70 /* now go ahead and have fun! */
71 PUTS("SearchEngine v0.1");
72 parsefd=rb->open(parameter,O_RDONLY);
73 if(parsefd<0) {
74 rb->splash(2*HZ,"Unable to open search tokenstream");
75 return PLUGIN_ERROR;
77 result=parse(parsefd);
78 rb->snprintf(buf,250,"Retval: 0x%x",result);
79 PUTS(buf);
80 rb->close(parsefd);
81 hits=0;
82 if(result!=0) {
83 int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC);
84 int i;
85 for(i=0;i<rb->tagdbheader->filecount;i++)
86 if(result[i]) {
87 hits++;
88 rb->fdprintf(fd,"%s\n",getfilename(i));
90 rb->close(fd);
92 rb->snprintf(buf,250,"Hits: %d",hits);
93 rb->splash(HZ*3,buf);
94 if (result!=0) {
95 /* Return PLUGIN_USB_CONNECTED to force a file-tree refresh */
96 return PLUGIN_USB_CONNECTED;
98 return PLUGIN_OK;