Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Michiel Van Der Kolk | c013936 | 2005-04-28 12:40:41 +0000 | [diff] [blame] | 8 | * $Id$ |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 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 "searchengine.h" |
| 20 | #include "parser.h" |
| 21 | #include "token.h" |
| 22 | #include "dbinterface.h" |
| 23 | |
| 24 | void *audio_bufferbase; |
| 25 | void *audio_bufferpointer; |
| 26 | unsigned int audio_buffer_free; |
| 27 | struct plugin_api* rb; |
| 28 | int w, h, y; |
| 29 | |
| 30 | void *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 | |
| 47 | void setmallocpos(void *pointer) |
| 48 | { |
| 49 | audio_bufferpointer = pointer; |
| 50 | audio_buffer_free = audio_bufferpointer - audio_bufferbase; |
| 51 | } |
| 52 | |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 53 | /* this is the plugin entry point */ |
| 54 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
| 55 | { |
| 56 | unsigned char *result,buf[500]; |
Michiel Van Der Kolk | c099300 | 2005-04-28 16:39:41 +0000 | [diff] [blame] | 57 | int parsefd,hits; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 58 | /* 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 Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 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; |
| 66 | |
| 67 | audio_bufferbase=audio_bufferpointer=0; |
| 68 | audio_buffer_free=0; |
| 69 | |
| 70 | /* now go ahead and have fun! */ |
Michiel Van Der Kolk | c013936 | 2005-04-28 12:40:41 +0000 | [diff] [blame] | 71 | PUTS("SearchEngine v0.1"); |
Michiel Van Der Kolk | 29909a3 | 2005-04-28 14:48:12 +0000 | [diff] [blame] | 72 | parsefd=rb->open(parameter,O_RDONLY); |
| 73 | if(parsefd<0) { |
| 74 | rb->splash(2*HZ,true,"Unable to open search tokenstream"); |
Michiel Van Der Kolk | ec407a8 | 2005-04-29 21:02:17 +0000 | [diff] [blame^] | 75 | return PLUGIN_ERROR; |
Michiel Van Der Kolk | 29909a3 | 2005-04-28 14:48:12 +0000 | [diff] [blame] | 76 | } |
| 77 | result=parse(parsefd); |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 78 | rb->snprintf(buf,250,"Retval: 0x%x",result); |
| 79 | PUTS(buf); |
Michiel Van Der Kolk | 29909a3 | 2005-04-28 14:48:12 +0000 | [diff] [blame] | 80 | rb->close(parsefd); |
Michiel Van Der Kolk | c099300 | 2005-04-28 16:39:41 +0000 | [diff] [blame] | 81 | hits=0; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 82 | if(result!=0) { |
Michiel Van Der Kolk | ec407a8 | 2005-04-29 21:02:17 +0000 | [diff] [blame^] | 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)); |
| 89 | } |
| 90 | rb->close(fd); |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 91 | } |
Michiel Van Der Kolk | c099300 | 2005-04-28 16:39:41 +0000 | [diff] [blame] | 92 | rb->snprintf(buf,250,"Hits: %d",hits); |
Michiel Van Der Kolk | 238bea7 | 2005-04-28 18:49:23 +0000 | [diff] [blame] | 93 | rb->splash(HZ*3,true,buf); |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 94 | return PLUGIN_OK; |
| 95 | } |