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 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * 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 Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 16 | * |
| 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 Arnold | a36b1d4 | 2006-01-15 18:20:18 +0000 | [diff] [blame] | 26 | PLUGIN_HEADER |
| 27 | |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 28 | void *audio_bufferbase; |
| 29 | void *audio_bufferpointer; |
Michael Sevakis | 26d242a | 2007-04-21 18:38:25 +0000 | [diff] [blame] | 30 | size_t audio_buffer_free; |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 31 | const struct plugin_api* rb; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 32 | int w, h, y; |
| 33 | |
| 34 | void *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 Kolk | 6ca9500 | 2005-04-29 23:15:07 +0000 | [diff] [blame] | 42 | audio_bufferpointer+=3; |
Jens Arnold | b621de3 | 2006-03-02 01:37:54 +0000 | [diff] [blame] | 43 | audio_bufferpointer=(void *)(((long)audio_bufferpointer)&~3); |
Michiel Van Der Kolk | 872dd87 | 2005-04-29 23:33:55 +0000 | [diff] [blame] | 44 | audio_buffer_free-=audio_bufferpointer-audio_bufferbase; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 45 | } |
| 46 | if (size + 4 > audio_buffer_free) |
| 47 | return 0; |
| 48 | alloc = audio_bufferpointer; |
Michiel Van Der Kolk | 6ca9500 | 2005-04-29 23:15:07 +0000 | [diff] [blame] | 49 | audio_bufferpointer +=(size+3)&~3; // alignment |
| 50 | audio_buffer_free -= (size+3)&~3; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 51 | return alloc; |
| 52 | } |
| 53 | |
| 54 | void setmallocpos(void *pointer) |
| 55 | { |
| 56 | audio_bufferpointer = pointer; |
| 57 | audio_buffer_free = audio_bufferpointer - audio_bufferbase; |
| 58 | } |
| 59 | |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 60 | /* this is the plugin entry point */ |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 61 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 62 | { |
| 63 | unsigned char *result,buf[500]; |
Michiel Van Der Kolk | c099300 | 2005-04-28 16:39:41 +0000 | [diff] [blame] | 64 | int parsefd,hits; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 65 | /* 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 Arnold | a36b1d4 | 2006-01-15 18:20:18 +0000 | [diff] [blame] | 68 | |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 69 | audio_bufferbase=audio_bufferpointer=0; |
| 70 | audio_buffer_free=0; |
| 71 | |
| 72 | /* now go ahead and have fun! */ |
Michiel Van Der Kolk | c013936 | 2005-04-28 12:40:41 +0000 | [diff] [blame] | 73 | PUTS("SearchEngine v0.1"); |
Michiel Van Der Kolk | 29909a3 | 2005-04-28 14:48:12 +0000 | [diff] [blame] | 74 | parsefd=rb->open(parameter,O_RDONLY); |
| 75 | if(parsefd<0) { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 76 | rb->splash(2*HZ,"Unable to open search tokenstream"); |
Michiel Van Der Kolk | ec407a8 | 2005-04-29 21:02:17 +0000 | [diff] [blame] | 77 | return PLUGIN_ERROR; |
Michiel Van Der Kolk | 29909a3 | 2005-04-28 14:48:12 +0000 | [diff] [blame] | 78 | } |
| 79 | result=parse(parsefd); |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 80 | rb->snprintf(buf,250,"Retval: 0x%x",result); |
| 81 | PUTS(buf); |
Michiel Van Der Kolk | 29909a3 | 2005-04-28 14:48:12 +0000 | [diff] [blame] | 82 | rb->close(parsefd); |
Michiel Van Der Kolk | c099300 | 2005-04-28 16:39:41 +0000 | [diff] [blame] | 83 | hits=0; |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 84 | if(result!=0) { |
Michiel Van Der Kolk | ec407a8 | 2005-04-29 21:02:17 +0000 | [diff] [blame] | 85 | 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 Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 93 | } |
Michiel Van Der Kolk | c099300 | 2005-04-28 16:39:41 +0000 | [diff] [blame] | 94 | rb->snprintf(buf,250,"Hits: %d",hits); |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 95 | rb->splash(HZ*3,buf); |
Jonas Häggqvist | 68de258 | 2005-08-31 00:30:46 +0000 | [diff] [blame] | 96 | if (result!=0) { |
| 97 | /* Return PLUGIN_USB_CONNECTED to force a file-tree refresh */ |
| 98 | return PLUGIN_USB_CONNECTED; |
| 99 | } |
Michiel Van Der Kolk | 9369d48 | 2005-04-28 12:33:38 +0000 | [diff] [blame] | 100 | return PLUGIN_OK; |
| 101 | } |