aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-08 00:44:58 +0200
committerMax Kellermann <max@duempel.org>2012-08-08 00:49:07 +0200
commit8d2725234e6271434d87ecaac23ef882850e649a (patch)
treee40b96944927c6f64b1595b92c4fb11724cb59cc
parent0823711106912fc75f1bdb2461243b12ba670f8b (diff)
downloadmpd-8d2725234e6271434d87ecaac23ef882850e649a.tar.gz
mpd-8d2725234e6271434d87ecaac23ef882850e649a.tar.xz
mpd-8d2725234e6271434d87ecaac23ef882850e649a.zip
DatabaseCommands: merge duplicate search/find code
-rw-r--r--src/DatabaseCommands.cxx61
-rw-r--r--src/command.c25
2 files changed, 31 insertions, 55 deletions
diff --git a/src/DatabaseCommands.cxx b/src/DatabaseCommands.cxx
index f54f0498d..e0449e9c8 100644
--- a/src/DatabaseCommands.cxx
+++ b/src/DatabaseCommands.cxx
@@ -56,11 +56,11 @@ handle_lsinfo2(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_OK;
}
-enum command_return
-handle_find(struct client *client, int argc, char *argv[])
+static enum command_return
+handle_match(struct client *client, int argc, char *argv[], bool fold_case)
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1, false);
+ locate_item_list_parse(argv + 1, argc - 1, fold_case);
if (list == NULL) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
@@ -78,53 +78,22 @@ handle_find(struct client *client, int argc, char *argv[])
}
enum command_return
-handle_findadd(struct client *client, int argc, char *argv[])
+handle_find(struct client *client, int argc, char *argv[])
{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1, false);
- if (list == NULL) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret =
- findAddIn(client->player_control, "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
+ return handle_match(client, argc, argv, false);
}
enum command_return
handle_search(struct client *client, int argc, char *argv[])
{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1, true);
-
- if (list == NULL) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- GError *error = NULL;
- enum command_return ret = findSongsIn(client, "", list, &error)
- ? COMMAND_RETURN_OK
- : print_error(client, error);
-
- locate_item_list_free(list);
-
- return ret;
+ return handle_match(client, argc, argv, true);
}
-enum command_return
-handle_searchadd(struct client *client, int argc, char *argv[])
+static enum command_return
+handle_match_add(struct client *client, int argc, char *argv[], bool fold_case)
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1, true);
-
+ locate_item_list_parse(argv + 1, argc - 1, fold_case);
if (list == NULL) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR;
@@ -142,6 +111,18 @@ handle_searchadd(struct client *client, int argc, char *argv[])
}
enum command_return
+handle_findadd(struct client *client, int argc, char *argv[])
+{
+ return handle_match_add(client, argc, argv, false);
+}
+
+enum command_return
+handle_searchadd(struct client *client, int argc, char *argv[])
+{
+ return handle_match_add(client, argc, argv, true);
+}
+
+enum command_return
handle_searchaddpl(struct client *client, int argc, char *argv[])
{
const char *playlist = argv[1];
diff --git a/src/command.c b/src/command.c
index 8da5c76b9..adda734c9 100644
--- a/src/command.c
+++ b/src/command.c
@@ -674,10 +674,11 @@ handle_playlistid(struct client *client, int argc, char *argv[])
}
static enum command_return
-handle_playlistfind(struct client *client, int argc, char *argv[])
+handle_playlist_match(struct client *client, int argc, char *argv[],
+ bool fold_case)
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1, false);
+ locate_item_list_parse(argv + 1, argc - 1, fold_case);
if (list == NULL) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
@@ -692,21 +693,15 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
}
static enum command_return
-handle_playlistsearch(struct client *client, int argc, char *argv[])
+handle_playlistfind(struct client *client, int argc, char *argv[])
{
- struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1, true);
-
- if (list == NULL) {
- command_error(client, ACK_ERROR_ARG, "incorrect arguments");
- return COMMAND_RETURN_ERROR;
- }
-
- playlist_print_find(client, &g_playlist, list);
-
- locate_item_list_free(list);
+ return handle_playlist_match(client, argc, argv, false);
+}
- return COMMAND_RETURN_OK;
+static enum command_return
+handle_playlistsearch(struct client *client, int argc, char *argv[])
+{
+ return handle_playlist_match(client, argc, argv, true);
}
static enum command_return