# HG changeset patch # User giacomo # Date 1166227462 28800 # Node ID a416e188db64a3899b3996806e5cc41509546969 # Parent fb57249c8702dedb17b3ca66d7abdd91e46f2747 [svn] regex-powered jump to file - should be considerably faster than the old one diff -r fb57249c8702 -r a416e188db64 ChangeLog --- a/ChangeLog Fri Dec 15 11:22:42 2006 -0800 +++ b/ChangeLog Fri Dec 15 16:04:22 2006 -0800 @@ -1,3 +1,10 @@ +2006-12-15 19:22:42 +0000 Giacomo Lozito + revision [3265] + do not assume that a tuple field exists just cause the tuple does, regexec hates null strings + trunk/audacious/playlist.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + + 2006-12-15 19:14:46 +0000 Giacomo Lozito revision [3263] added a regex-based search option in playlist that allows to select playlist entries using multiple match criteria diff -r fb57249c8702 -r a416e188db64 audacious/mainwin.c --- a/audacious/mainwin.c Fri Dec 15 11:22:42 2006 -0800 +++ b/audacious/mainwin.c Fri Dec 15 16:04:22 2006 -0800 @@ -41,6 +41,9 @@ #include +#include +#include + #include "widgets/widgetcore.h" #include "mainwin.h" #include "pixmaps.h" @@ -1852,22 +1855,22 @@ } static gboolean -mainwin_jump_to_file_match(const gchar * song, gchar ** keys) +mainwin_jump_to_file_match(const gchar * song, GSList *regex_list) { gint i = 0; gboolean rv = TRUE; - while (keys[i]) { - gint len = strlen(keys[i]); - gint j = 0; - while (*(song + j)) { - if (!g_strncasecmp(song + j, keys[i], len)) - goto found; - j++; + if ( song == NULL ) + return FALSE; + + for ( ; regex_list ; regex_list = g_slist_next(regex_list) ) + { + regex_t *regex = regex_list->data; + if ( regexec( regex , song , 0 , NULL , 0 ) != 0 ) + { + rv = FALSE; + break; } - rv = FALSE; - found: - i++; } return rv; @@ -1940,9 +1943,20 @@ gboolean match = FALSE; - /* Chop the key string into ' '-separated key words */ + GSList *regex_list = NULL, *regex_list_tmp = NULL; + gint i = -1; + + /* Chop the key string into ' '-separated key regex-pattern strings */ words = g_strsplit(gtk_entry_get_text(entry), " ", 0); + /* create a list of regex using the regex-pattern strings */ + while ( words[++i] != NULL ) + { + regex_t *regex = g_malloc(sizeof(regex_t)); + if ( regcomp( regex , words[i] , REG_NOSUB | REG_ICASE ) == 0 ) + regex_list = g_slist_append( regex_list , regex ); + } + /* FIXME: Remove the connected signals before clearing * (row-selected will still eventually arrive once) */ store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); @@ -1967,8 +1981,8 @@ title = filename; } - /* Compare the key words to the string - if all the words - match, add to the ListStore */ + /* Compare the reg.expressions to the string - if all the + regexp in regex_list match, add to the ListStore */ /* * FIXME: The search string should be adapted to the @@ -1979,8 +1993,8 @@ * In any case the string to match should _never_ contain * something the user can't actually see in the playlist. */ - if (words[0] != NULL) - match = mainwin_jump_to_file_match(title, words); + if (regex_list != NULL) + match = mainwin_jump_to_file_match(title, regex_list); else match = TRUE; @@ -2000,6 +2014,17 @@ PLAYLIST_UNLOCK(); + if ( regex_list != NULL ) + { + regex_list_tmp = regex_list; + while ( regex_list != NULL ) + { + regex_t *regex = regex_list->data; + regfree( regex ); + regex_list = g_slist_next(regex_list); + } + g_slist_free( regex_list_tmp ); + } g_strfreev(words); if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {