blob: 5b4c5e275d2f8195b0b846e2fe22bdeaed192357 [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 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "searchengine.h"
22#include "parser.h"
23#include "token.h"
24#include "dbinterface.h"
25
Jens Arnolda36b1d42006-01-15 18:20:18 +000026PLUGIN_HEADER
27
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000028void *audio_bufferbase;
29void *audio_bufferpointer;
Michael Sevakis26d242a2007-04-21 18:38:25 +000030size_t audio_buffer_free;
Steve Bavin65265772008-05-13 09:57:56 +000031const struct plugin_api* rb;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000032int w, h, y;
33
34void *my_malloc(size_t size)
35{
36 void *alloc;
37
38 if (!audio_bufferbase)
39 {
40 audio_bufferbase = audio_bufferpointer
41 = rb->plugin_get_audio_buffer(&audio_buffer_free);
Michiel Van Der Kolk6ca95002005-04-29 23:15:07 +000042 audio_bufferpointer+=3;
Jens Arnoldb621de32006-03-02 01:37:54 +000043 audio_bufferpointer=(void *)(((long)audio_bufferpointer)&~3);
Michiel Van Der Kolk872dd872005-04-29 23:33:55 +000044 audio_buffer_free-=audio_bufferpointer-audio_bufferbase;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000045 }
46 if (size + 4 > audio_buffer_free)
47 return 0;
48 alloc = audio_bufferpointer;
Michiel Van Der Kolk6ca95002005-04-29 23:15:07 +000049 audio_bufferpointer +=(size+3)&~3; // alignment
50 audio_buffer_free -= (size+3)&~3;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000051 return alloc;
52}
53
54void setmallocpos(void *pointer)
55{
56 audio_bufferpointer = pointer;
57 audio_buffer_free = audio_bufferpointer - audio_bufferbase;
58}
59
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000060/* this is the plugin entry point */
Steve Bavin65265772008-05-13 09:57:56 +000061enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000062{
63 unsigned char *result,buf[500];
Michiel Van Der Kolkc0993002005-04-28 16:39:41 +000064 int parsefd,hits;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000065 /* if you are using a global api pointer, don't forget to copy it!
66 otherwise you will get lovely "I04: IllInstr" errors... :-) */
67 rb = api;
Jens Arnolda36b1d42006-01-15 18:20:18 +000068
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000069 audio_bufferbase=audio_bufferpointer=0;
70 audio_buffer_free=0;
71
72 /* now go ahead and have fun! */
Michiel Van Der Kolkc0139362005-04-28 12:40:41 +000073 PUTS("SearchEngine v0.1");
Michiel Van Der Kolk29909a32005-04-28 14:48:12 +000074 parsefd=rb->open(parameter,O_RDONLY);
75 if(parsefd<0) {
Jens Arnold4d6374c2007-03-16 21:56:08 +000076 rb->splash(2*HZ,"Unable to open search tokenstream");
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000077 return PLUGIN_ERROR;
Michiel Van Der Kolk29909a32005-04-28 14:48:12 +000078 }
79 result=parse(parsefd);
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000080 rb->snprintf(buf,250,"Retval: 0x%x",result);
81 PUTS(buf);
Michiel Van Der Kolk29909a32005-04-28 14:48:12 +000082 rb->close(parsefd);
Michiel Van Der Kolkc0993002005-04-28 16:39:41 +000083 hits=0;
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000084 if(result!=0) {
Michiel Van Der Kolkec407a82005-04-29 21:02:17 +000085 int fd=rb->open("/search.m3u", O_WRONLY|O_CREAT|O_TRUNC);
86 int i;
87 for(i=0;i<rb->tagdbheader->filecount;i++)
88 if(result[i]) {
89 hits++;
90 rb->fdprintf(fd,"%s\n",getfilename(i));
91 }
92 rb->close(fd);
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +000093 }
Michiel Van Der Kolkc0993002005-04-28 16:39:41 +000094 rb->snprintf(buf,250,"Hits: %d",hits);
Jens Arnold4d6374c2007-03-16 21:56:08 +000095 rb->splash(HZ*3,buf);
Jonas Häggqvist68de2582005-08-31 00:30:46 +000096 if (result!=0) {
97 /* Return PLUGIN_USB_CONNECTED to force a file-tree refresh */
98 return PLUGIN_USB_CONNECTED;
99 }
Michiel Van Der Kolk9369d482005-04-28 12:33:38 +0000100 return PLUGIN_OK;
101}