Commit 8d272523 authored by Max Kellermann's avatar Max Kellermann

DatabaseCommands: merge duplicate search/find code

parent 08237111
...@@ -56,11 +56,11 @@ handle_lsinfo2(struct client *client, int argc, char *argv[]) ...@@ -56,11 +56,11 @@ handle_lsinfo2(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
enum command_return static enum command_return
handle_find(struct client *client, int argc, char *argv[]) handle_match(struct client *client, int argc, char *argv[], bool fold_case)
{ {
struct locate_item_list *list = 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) { if (list == NULL) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
...@@ -78,10 +78,22 @@ handle_find(struct client *client, int argc, char *argv[]) ...@@ -78,10 +78,22 @@ handle_find(struct client *client, int argc, char *argv[])
} }
enum command_return enum command_return
handle_findadd(struct client *client, int argc, char *argv[]) handle_find(struct client *client, int argc, char *argv[])
{
return handle_match(client, argc, argv, false);
}
enum command_return
handle_search(struct client *client, int argc, char *argv[])
{
return handle_match(client, argc, argv, true);
}
static enum command_return
handle_match_add(struct client *client, int argc, char *argv[], bool fold_case)
{ {
struct locate_item_list *list = 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) { if (list == NULL) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
...@@ -99,46 +111,15 @@ handle_findadd(struct client *client, int argc, char *argv[]) ...@@ -99,46 +111,15 @@ handle_findadd(struct client *client, int argc, char *argv[])
} }
enum command_return enum command_return
handle_search(struct client *client, int argc, char *argv[]) handle_findadd(struct client *client, int argc, char *argv[])
{ {
struct locate_item_list *list = return handle_match_add(client, argc, argv, false);
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;
} }
enum command_return enum command_return
handle_searchadd(struct client *client, int argc, char *argv[]) handle_searchadd(struct client *client, int argc, char *argv[])
{ {
struct locate_item_list *list = return handle_match_add(client, argc, argv, true);
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 =
findAddIn(client->player_control, "", list, &error)
? COMMAND_RETURN_OK
: print_error(client, error);
locate_item_list_free(list);
return ret;
} }
enum command_return enum command_return
......
...@@ -674,10 +674,11 @@ handle_playlistid(struct client *client, int argc, char *argv[]) ...@@ -674,10 +674,11 @@ handle_playlistid(struct client *client, int argc, char *argv[])
} }
static enum command_return 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 = 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) { if (list == NULL) {
command_error(client, ACK_ERROR_ARG, "incorrect arguments"); command_error(client, ACK_ERROR_ARG, "incorrect arguments");
...@@ -692,21 +693,15 @@ handle_playlistfind(struct client *client, int argc, char *argv[]) ...@@ -692,21 +693,15 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
} }
static enum command_return 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 = return handle_playlist_match(client, argc, argv, false);
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 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 static enum command_return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment