/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id: main_menu.c,v 1.55 2002/08/31 23:07:11 adiamas Exp $ * * Copyright (C) 2002 Bj%/1iso8859-15rn Stenberg * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #define MAX_BM_ARRAY 255 #include "search_string.h" //#include "../firmware/common/boyer-moore.c" #include int search_string(void) { int index_fin; char *indir="/ITM/";/*Well, I don't know yet how the UI will send current dir name to the function. So, for the moment, i put it bye hand.*/ struct db database; index_fin= sel_dirdb(&database,indir); database.handle_db=open("/db.db",O_RDONLY); load_db(0,&database); search_stringnext("maRsAlIs Blase",&database); return MENU_OK; } void search_stringnext(char *pattern, struct db *db ) { int i=0; char str[5]; char *delimitor = " ";/* would be nice to define a never-user char to do it so the user input interface would have a delimitor char, different from ' '*/ char token[strlen(pattern)]; char *token_ptr; char *end; struct dbentry entry; int token_size; unsigned char bm_first_array[strlen(pattern)]; unsigned char bm_second_array[BM_MAX_ARRAY]; bool not_wrong=true;/*Sorry, I'm a bad coder*/ bool done=false;/*Well, i'm really a bad coder*/ strcpy(token, pattern);// Needed because of the use of strtok token_ptr=strtok_r(token, delimitor,&end); debugf("token: %s\n",token); while (!done) // This loop scan files { i++; not_wrong=true; /*means that the file tested has not yet being identified as a wrong one*/ fill_entry(&entry,db); //We fill the id3 with the -euh- the id3... while ( not_wrong && (token_ptr != NULL))/* In This loop we scan the different tokens*/ { token_size=strlen(token_ptr); bm_init_array(token_ptr,bm_first_array,token_size-1,bm_second_array); debugf("Debug1: %d\n",token_size); not_wrong=false; if (entry.title!=NULL && !not_wrong) { if (bm(entry.title,strlen(entry.title),token_ptr,token_size)!=0 ) { token_ptr=strtok_r(NULL,delimitor,&end); not_wrong=true; } } if (entry.artist!=NULL && !not_wrong) { if (bm(entry.artist,strlen(entry.artist),token_ptr,token_size)!=0) { token_ptr=strtok_r(NULL,delimitor,&end); not_wrong=true; } } if (entry.album!=NULL && !not_wrong) { if (bm(entry.album,strlen(entry.album),token_ptr,token_size)!=0) { token_ptr=strtok_r(NULL,delimitor,&end); not_wrong=true; } } if (!not_wrong) { if (bm(entry.full_path,strlen(entry.full_path),token_ptr,token_size)!=0) { token_ptr=strtok_r(NULL,delimitor,&end); not_wrong=true; } } } if (token_ptr==NULL)/* the token-loop has ended, and the file is good!*/ { done= true; } else { strcpy(token,pattern);/*let's re-start from the beginning*/ token_ptr=strtok_r(token,delimitor,&end); } } /*Here we should add a user interface, wich would enable to play the file, or to search next one*/ lcd_clear_display(); lcd_puts(0,0,entry.full_path); lcd_puts(0,1,entry.title); lcd_puts(0,2,entry.artist); lcd_puts(0,3,entry.album); snprintf(str,5,"%d",i); lcd_puts(0,4,str); lcd_update(); sleep (500); };