blob: 5a85af518480eb23910d6135bd9366bd0ec30117 [file] [log] [blame]
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Michiel Van Der Kolkc0139362005-04-28 12:40:41 +00008 * $Id$
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +00009 *
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 "searchengine.h"
20#include "parser.h"
21#include "token.h"
22#include "dbinterface.h"
23
24void *audio_bufferbase;
25void *audio_bufferpointer;
26unsigned int audio_buffer_free;
27struct plugin_api* rb;
28int w, h, y;
29
30void *my_malloc(size_t size)
31{
32 void *alloc;
33
34 if (!audio_bufferbase)
35 {
36 audio_bufferbase = audio_bufferpointer
37 = rb->plugin_get_audio_buffer(&audio_buffer_free);
38 }
39 if (size + 4 > audio_buffer_free)
40 return 0;
41 alloc = audio_bufferpointer;
42 audio_bufferpointer += size + 4;
43 audio_buffer_free -= size + 4;
44 return alloc;
45}
46
47void setmallocpos(void *pointer)
48{
49 audio_bufferpointer = pointer;
50 audio_buffer_free = audio_bufferpointer - audio_bufferbase;
51}
52
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000053/* this is the plugin entry point */
54enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
55{
56 unsigned char *result,buf[500];
Michiel Van Der Kolkc0993002005-04-28 16:39:41 +000057 int parsefd,hits;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000058 /* this macro should be called as the first thing you do in the plugin.
59 it test that the api version and model the plugin was compiled for
60 matches the machine it is running on */
61 TEST_PLUGIN_API(api);
62
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000063 /* 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;
66
67 audio_bufferbase=audio_bufferpointer=0;
68 audio_buffer_free=0;
69
70 /* now go ahead and have fun! */
Michiel Van Der Kolkc0139362005-04-28 12:40:41 +000071 PUTS("SearchEngine v0.1");
Michiel Van Der Kolk29909a32005-04-28 14:48:12 +000072 parsefd=rb->open(parameter,O_RDONLY);
73 if(parsefd<0) {
74 rb->splash(2*HZ,true,"Unable to open search tokenstream");
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000075 return PLUGIN_ERROR;
Michiel Van Der Kolk29909a32005-04-28 14:48:12 +000076 }
77 result=parse(parsefd);
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000078 rb->snprintf(buf,250,"Retval: 0x%x",result);
79 PUTS(buf);
Michiel Van Der Kolk29909a32005-04-28 14:48:12 +000080 rb->close(parsefd);
Michiel Van Der Kolkc0993002005-04-28 16:39:41 +000081 hits=0;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000082 if(result!=0) {
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000083 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));
89 }
90 rb->close(fd);
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000091 }
Michiel Van Der Kolkc0993002005-04-28 16:39:41 +000092 rb->snprintf(buf,250,"Hits: %d",hits);
Michiel Van Der Kolk238bea72005-04-28 18:49:23 +000093 rb->splash(HZ*3,true,buf);
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000094 return PLUGIN_OK;
95}